PageRenderTime 94ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 1ms

/cwxeditor_src/cwx/editor/gui/dwt/replacedialog.d

https://bitbucket.org/k4nagatsuki/cwxeditor
D | 4172 lines | 3962 code | 140 blank | 70 comment | 734 complexity | db2c64d38f688f2071e9751bd1eb210b MD5 | raw file
Possible License(s): LGPL-2.1
  1. module cwx.editor.gui.dwt.replacedialog;
  2. import cwx.area;
  3. import cwx.summary;
  4. import cwx.event;
  5. import cwx.coupon;
  6. import cwx.utils;
  7. import cwx.card;
  8. import cwx.motion;
  9. import cwx.flag;
  10. import cwx.usecounter;
  11. import cwx.types;
  12. import cwx.path;
  13. import cwx.background;
  14. import cwx.skin;
  15. import cwx.msgutils;
  16. import cwx.menu;
  17. import cwx.jpy;
  18. import cwx.cab;
  19. import cwx.features;
  20. import cwx.textholder;
  21. import cwx.system;
  22. import cwx.warning;
  23. import cwx.editor.gui.dwt.dprops;
  24. import cwx.editor.gui.dwt.dutils;
  25. import cwx.editor.gui.dwt.centerlayout;
  26. import cwx.editor.gui.dwt.customtable;
  27. import cwx.editor.gui.dwt.commons;
  28. import cwx.editor.gui.dwt.dskin;
  29. import cwx.editor.gui.dwt.splitpane;
  30. import cwx.editor.gui.dwt.undo;
  31. import cwx.editor.gui.dwt.dmenu;
  32. import cwx.editor.gui.dwt.chooser;
  33. import cwx.editor.gui.dwt.incsearch;
  34. import std.ascii;
  35. import std.conv;
  36. import std.array;
  37. import std.string;
  38. import std.file;
  39. import std.path;
  40. import std.regex : Regex, regex, RegexMatch, match;
  41. import std.utf;
  42. import std.algorithm : uniq, swap;
  43. import std.traits;
  44. import std.typecons : Tuple;
  45. import org.eclipse.swt.all;
  46. import java.lang.all;
  47. private class CWXPathString {
  48. string scPath;
  49. CWXPath path;
  50. string array;
  51. this (string scPath, CWXPath path, string array) { mixin(S_TRACE);
  52. this.scPath = scPath;
  53. this.path = path;
  54. this.array = array;
  55. }
  56. }
  57. private class FilePathString {
  58. string scPath;
  59. string array;
  60. this (string scPath, string array) { mixin(S_TRACE);
  61. this.scPath = scPath;
  62. this.array = array;
  63. }
  64. }
  65. private class FKeyCodesUndo : TUndo!(FKeyCode[]) {
  66. this (FKeyCode[] old, FKeyCode[] n, void delegate(FKeyCode[]) set) { mixin(S_TRACE);
  67. super (old.dup, n.dup, set, (FKeyCode[] v) {return v.dup;});
  68. }
  69. }
  70. /// ??????????????
  71. class ReplaceDialog {
  72. private:
  73. class UndoRepl : UndoArr {
  74. this (Undo[] array, bool rev = true) { mixin(S_TRACE);
  75. super (array, rev);
  76. }
  77. override void undo() { mixin(S_TRACE);
  78. reset(false);
  79. super.undo();
  80. refContentText();
  81. _status.setText(.tryFormat(_prop.msgs.replaceUndo, .formatNum(_result.getItemCount())));
  82. _comm.replText.call();
  83. }
  84. override void redo() { mixin(S_TRACE);
  85. reset(false);
  86. super.redo();
  87. refContentText();
  88. _status.setText(.tryFormat(_prop.msgs.replaceRedo, .formatNum(_result.getItemCount())));
  89. _comm.replText.call();
  90. }
  91. }
  92. class RUndo : Undo {
  93. private CWXPath _path = null;
  94. private string _filePath = null;
  95. private Undo[] _uArr;
  96. this (CWXPath path, Undo[] uArr) { mixin(S_TRACE);
  97. _path = path;
  98. _uArr = uArr;
  99. }
  100. this (string filePath, Undo[] uArr) { mixin(S_TRACE);
  101. _filePath = filePath;
  102. _uArr = uArr;
  103. }
  104. void undo() { mixin(S_TRACE);
  105. size_t dmy = 0;
  106. foreach_reverse (u; _uArr) u.undo();
  107. if (_path) addResult(_path, dmy);
  108. if (_filePath) addResult(_filePath, dmy);
  109. }
  110. void redo() { mixin(S_TRACE);
  111. size_t dmy = 0;
  112. foreach_reverse (u; _uArr) u.redo();
  113. if (_path) addResult(_path, dmy);
  114. if (_filePath) addResult(_filePath, dmy);
  115. }
  116. void dispose() { mixin(S_TRACE);
  117. foreach (u; _uArr) u.dispose();
  118. }
  119. }
  120. void store(string filePath, Undo[] uArr) { mixin(S_TRACE);
  121. _rUndo ~= new RUndo(filePath, uArr);
  122. }
  123. void store(CWXPath path, Undo[] uArr) { mixin(S_TRACE);
  124. _rUndo ~= new RUndo(path, uArr);
  125. }
  126. void store(CWXPath path, string o, string n, void delegate(string) set) { mixin(S_TRACE);
  127. _rUndo ~= new RUndo(path, [new StrUndo(o, n, set)]);
  128. }
  129. void store(CWXPath path, string[] o, string[] n, void delegate(string[]) set) { mixin(S_TRACE);
  130. _rUndo ~= new RUndo(path, [new StrArrUndo(o, n, set)]);
  131. }
  132. void store(CWXPath path, FKeyCode[] o, FKeyCode[] n, void delegate(FKeyCode[]) set) { mixin(S_TRACE);
  133. _rUndo ~= new RUndo(path, [new FKeyCodesUndo(o, n, set)]);
  134. }
  135. void storeID(User, Id)(CWXPath path, User u, Id from, Id to, void delegate(Id) set) { mixin(S_TRACE);
  136. _rUndo ~= new RUndo(path, [new TUndo!Id(from, to, set)]);
  137. }
  138. bool _inProc = false;
  139. bool _inUndo = false;
  140. Undo[] _rUndo;
  141. void delegate()[] _after;
  142. core.thread.Thread _uiThread;
  143. Commons _comm;
  144. Props _prop;
  145. Summary _summ;
  146. UndoManager _undo;
  147. Summary _grepSumm = null;
  148. int _grepCount = -1;
  149. Skin _grepSkin = null;
  150. string _grepFile = "";
  151. bool _inGrep = false;
  152. bool _cancel = false;
  153. Shell _win;
  154. Composite _parent;
  155. CTabFolder _tabf;
  156. CTabItem _tabText;
  157. CTabItem _tabID;
  158. CTabItem _tabPath;
  159. CTabItem _tabContents;
  160. CTabItem _tabCoupon;
  161. CTabItem _tabUnuse;
  162. CTabItem _tabError;
  163. CTabItem _tabGrep;
  164. CTabItem _lastFind = null;
  165. Button _find;
  166. Button _replace;
  167. Button _close;
  168. Button _rangeAllCheck;
  169. bool ignoreMod = false;
  170. Composite _textGrp1, _textGrp2, _textFromComp, _grepFromComp;
  171. Combo _from;
  172. Combo _to;
  173. IncSearch _fromIncSearch = null;
  174. IncSearch _toIncSearch = null;
  175. Combo _idKind;
  176. Combo _fromID;
  177. Composite _fromIDComp;
  178. Spinner _fromIDVal;
  179. ulong[int] _fromIDTbl;
  180. Combo _toID;
  181. Composite _toIDComp;
  182. Spinner _toIDVal;
  183. ulong[int] _toIDTbl;
  184. IncSearch _fromIDIncSearch = null;
  185. IncSearch _toIDIncSearch = null;
  186. Combo _fromPath;
  187. Combo _toPath;
  188. IncSearch _fromPathIncSearch = null;
  189. IncSearch _toPathIncSearch = null;
  190. Combo _grepDir;
  191. Button _grepSubDir;
  192. Button _notIgnoreCase;
  193. Button _useRegex;
  194. Button _useWildcard;
  195. Button _exact;
  196. Button _ignoreReturnCode;
  197. class SelRegex : SelectionAdapter {
  198. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  199. if (_useRegex.getSelection()) { mixin(S_TRACE);
  200. _useWildcard.setSelection(false);
  201. }
  202. }
  203. }
  204. class SelWildcard : SelectionAdapter {
  205. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  206. if (_useWildcard.getSelection()) { mixin(S_TRACE);
  207. _useRegex.setSelection(false);
  208. }
  209. }
  210. }
  211. class SelIgnoreReturnCode : SelectionAdapter {
  212. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  213. _comm.refreshToolBar();
  214. }
  215. }
  216. @property
  217. const
  218. bool catchMod() {return !ignoreMod;}
  219. /// ???
  220. Button _summary;
  221. /// ????????
  222. Button _rCoupon;
  223. /// ?????
  224. Button _msg;
  225. /// ????
  226. Button _cardName;
  227. /// ?????
  228. Button _cardDesc;
  229. /// ????????
  230. Button _event;
  231. /// ?????
  232. Button _start;
  233. /// ???/????
  234. Button _flag;
  235. /// ????
  236. Button _coupon;
  237. /// ????
  238. Button _gossip;
  239. /// ???
  240. Button _end;
  241. /// ???/???/??????
  242. Button _area;
  243. /// ?????
  244. Button _keyCode;
  245. /// ????
  246. Button _file;
  247. /// ????
  248. Button _comment;
  249. /// JPTX????
  250. Button _jptx;
  251. Button[] _noSummText;
  252. Button _unuseFlag;
  253. Button _unuseStep;
  254. Button _unuseArea;
  255. Button _unuseBattle;
  256. Button _unusePackage;
  257. Button _unuseCast;
  258. Button _unuseSkill;
  259. Button _unuseItem;
  260. Button _unuseBeast;
  261. Button _unuseInfo;
  262. Button _unuseStart;
  263. Button _unusePath;
  264. Button _cCoupon;
  265. Button _cGossip;
  266. Button _cEnd;
  267. Button _cKeyCode;
  268. // FIXME: CardWirth 1.60 ????
  269. /+ Button _cCellName;
  270. +/
  271. Table _result;
  272. TableTextEdit _edit;
  273. Tree _range;
  274. Composite[CTabItem] _comps;
  275. ToolItem[CType] _contents;
  276. Label _status;
  277. bool _notIgnoreCaseSel;
  278. bool _exactSel;
  279. bool _ignoreReturnCodeSel;
  280. bool _summarySel;
  281. bool _msgSel;
  282. bool _cardNameSel;
  283. bool _cardDescSel;
  284. bool _eventSel;
  285. bool _startSel;
  286. bool _flagSel;
  287. bool _couponSel;
  288. bool _gossipSel;
  289. bool _endSel;
  290. bool _areaSel;
  291. bool _keyCodeSel;
  292. bool _fileSel;
  293. bool _commentSel;
  294. bool _jptxSel;
  295. string _fromText;
  296. string _toText;
  297. bool _flagDirOnRange = false;
  298. bool _resultRedraw = true;
  299. void resultRedraw(bool val) { mixin(S_TRACE);
  300. if (!_win || _win.isDisposed()) return;
  301. if (_resultRedraw !is val) { mixin(S_TRACE);
  302. _resultRedraw = val;
  303. _result.setRedraw(val);
  304. }
  305. }
  306. class AddResultPath : Runnable {
  307. size_t count = 0;
  308. string path;
  309. string desc;
  310. void run() { mixin(S_TRACE);
  311. if (cancel) return;
  312. if (!_win || _win.isDisposed()) return;
  313. if (_inProc && !_prop.var.etc.searchResultRealtime) resultRedraw(false);
  314. auto itm = new TableItem(_result, SWT.NONE);
  315. auto summ = _grepSumm ? _grepSumm : _summ;
  316. auto fullPath = std.path.buildPath(summ.scenarioPath, path);
  317. if (_grepSumm) { mixin(S_TRACE);
  318. if (!_grepSkin) _grepSkin = findSkin(_comm, _prop, summ);
  319. itm.setImage(fimage(fullPath, _grepSkin));
  320. } else { mixin(S_TRACE);
  321. itm.setImage(fimage(fullPath, _comm.skin));
  322. }
  323. string scPath = null;
  324. string text = encodePath(path);
  325. itm.setText(0, text);
  326. if (desc.length) { mixin(S_TRACE);
  327. itm.setText(2, desc);
  328. itm.setImage(2, _prop.images.warning);
  329. }
  330. if (_grepSumm) { mixin(S_TRACE);
  331. scPath = _grepSumm.useTemp ? _grepSumm.zipName : _grepSumm.scenarioPath;
  332. text = .tryFormat(_prop.msgs.grepScenario, _grepSumm.scenarioName, scPath);
  333. itm.setText(2, text);
  334. itm.setImage(2, _prop.images.summary);
  335. }
  336. itm.setData(new FilePathString(scPath, path));
  337. refResultStatus(count, false);
  338. }
  339. }
  340. class AddResultCWXPath : Runnable {
  341. CWXPath path;
  342. int index;
  343. string desc;
  344. size_t count = 0;
  345. void run() { mixin(S_TRACE);
  346. if (cancel) return;
  347. if (!_win || _win.isDisposed()) return;
  348. if (_inProc && !_prop.var.etc.searchResultRealtime) resultRedraw(false);
  349. auto itm = new TableItem(_result, SWT.NONE, -1 == index ? _result.getItemCount() : index);
  350. string text1, text2;
  351. Image img1, img2;
  352. getPathParams(path, text1, text2, img1, img2);
  353. itm.setImage(0, img1);
  354. itm.setText(0, text1);
  355. itm.setImage(1, img2);
  356. itm.setText(1, text2);
  357. if (desc.length) { mixin(S_TRACE);
  358. itm.setText(2, desc);
  359. itm.setImage(2, _prop.images.warning);
  360. }
  361. string scPath = null;
  362. if (_grepSumm) { mixin(S_TRACE);
  363. scPath = _grepSumm.useTemp ? _grepSumm.zipName : _grepSumm.scenarioPath;
  364. itm.setText(2, .tryFormat(_prop.msgs.grepScenario, _grepSumm.scenarioName, scPath));
  365. itm.setImage(2, _prop.images.summary);
  366. }
  367. itm.setData(new CWXPathString(scPath, _grepSumm ? null : path, path.cwxPath(true)));
  368. refResultStatus(count, false);
  369. }
  370. }
  371. class AddResultMsg : Runnable {
  372. string name;
  373. Image delegate() image;
  374. int index;
  375. size_t count = 0;
  376. void run() { mixin(S_TRACE);
  377. if (cancel) return;
  378. if (!_win || _win.isDisposed()) return;
  379. if (_inProc && !_prop.var.etc.searchResultRealtime) resultRedraw(false);
  380. auto itm = new TableItem(_result, SWT.NONE, -1 == index ? _result.getItemCount() : index);
  381. itm.setText(name);
  382. itm.setImage(image());
  383. refResultStatus(count, false);
  384. }
  385. }
  386. class AddResultUse : Runnable {
  387. string name;
  388. uint use;
  389. Image delegate() image;
  390. int index;
  391. size_t count = 0;
  392. void run() { mixin(S_TRACE);
  393. if (cancel) return;
  394. if (!_win || _win.isDisposed()) return;
  395. if (_inProc && !_prop.var.etc.searchResultRealtime) resultRedraw(false);
  396. auto itm = new TableItem(_result, SWT.NONE, -1 == index ? _result.getItemCount() : index);
  397. itm.setText(0, name);
  398. itm.setImage(0, image());
  399. itm.setText(1, .text(use));
  400. refResultStatus(count, false);
  401. }
  402. }
  403. Display _display;
  404. class ML : MouseAdapter {
  405. public override void mouseDoubleClick(MouseEvent e) { mixin(S_TRACE);
  406. if (_result.isFocusControl() && e.button == 1) { mixin(S_TRACE);
  407. openPath();
  408. }
  409. }
  410. }
  411. class KL : KeyAdapter {
  412. public override void keyPressed(KeyEvent e) { mixin(S_TRACE);
  413. if (_result.isFocusControl() && e.character == SWT.CR) { mixin(S_TRACE);
  414. openPath();
  415. }
  416. }
  417. }
  418. static const ID_AREA = 0;
  419. static const ID_BATTLE = 1;
  420. static const ID_PACKAGE = 2;
  421. static const ID_CAST = 3;
  422. static const ID_SKILL = 4;
  423. static const ID_ITEM = 5;
  424. static const ID_BEAST = 6;
  425. static const ID_INFO = 7;
  426. static const ID_FLAG = 8;
  427. static const ID_STEP = 9;
  428. static const ID_COUPON = 10;
  429. static const ID_GOSSIP = 11;
  430. static const ID_COMPLETE_STAMP = 12;
  431. static const ID_KEY_CODE = 13;
  432. // FIXME: CardWirth 1.60 ????
  433. /+ static const ID_CELL_NAME = 14;
  434. +/ private void setupIDsImpl2(T)(T[] arr, Combo combo, Spinner spn, ref ulong[int] tbl, bool clear, IncSearch incSearch) { mixin(S_TRACE);
  435. ulong[int] tbl2;
  436. string oldSel = clear ? "" : combo.getText();
  437. combo.removeAll();
  438. static if (is(T:Flag) || is(T:Step)) {
  439. auto set = new HashSet!string;
  440. if (_summ) { mixin(S_TRACE);
  441. static if (is(T:Flag)) {
  442. foreach (key; _summ.useCounter.flag.keys) { mixin(S_TRACE);
  443. if (_prop.sys.randomValue == cast(string)key) continue;
  444. if (!incSearch.match(cast(string)key)) continue;
  445. set.add(cast(string)key);
  446. }
  447. } else static if (is(T:Step)) {
  448. foreach (key; _summ.useCounter.step.keys) { mixin(S_TRACE);
  449. if (_prop.sys.randomValue == cast(string)key) continue;
  450. if (!incSearch.match(cast(string)key)) continue;
  451. set.add(cast(string)key);
  452. }
  453. } else static assert (0);
  454. }
  455. foreach (i, a; arr) { mixin(S_TRACE);
  456. auto p = a.path;
  457. if (p == "") continue;
  458. if (!incSearch.match(p)) continue;
  459. combo.add(p);
  460. set.remove(p);
  461. }
  462. bool delegate(string a, string b) cmps;
  463. if (_prop.var.etc.logicalSort) { mixin(S_TRACE);
  464. cmps = (a, b) => incmp(a, b) < 0;
  465. } else { mixin(S_TRACE);
  466. cmps = (a, b) => icmp(a, b) < 0;
  467. }
  468. foreach (p; .sortDlg(set.array(), cmps)) { mixin(S_TRACE);
  469. if (p == "") continue;
  470. if (!incSearch.match(p)) continue;
  471. combo.add(p);
  472. }
  473. combo.setText(oldSel);
  474. if (combo.getText() == "" && combo.getItemCount()) { mixin(S_TRACE);
  475. combo.select(0);
  476. }
  477. spn.setEnabled(false);
  478. } else static if (is(T:CouponId) || is(T:GossipId) || is(T:CompleteStampId) || is(T:KeyCodeId) || is(T:CellNameId)) {
  479. string[] arr2;
  480. static if (is(T:CouponId)) {
  481. arr2 = .allCoupons(_comm, _summ, CouponComboType.AllCoupons);
  482. } else static if (is(T:GossipId)) {
  483. arr2 = .allGossips(_comm, _summ);
  484. } else static if (is(T:CompleteStampId)) {
  485. arr2 = .allCompleteStamps(_comm, _summ);
  486. } else static if (is(T:KeyCodeId)) {
  487. arr2 = .allKeyCodes(_comm, _summ);
  488. } else static if (is(T:CellNameId)) {
  489. arr2 = .allCellNames(_comm, _summ);
  490. } else static assert (0);
  491. foreach (a; arr2) {
  492. if (!incSearch.match(a)) continue;
  493. combo.add(a);
  494. }
  495. combo.setText(oldSel);
  496. if (combo.getText() == "" && combo.getItemCount()) { mixin(S_TRACE);
  497. combo.select(0);
  498. }
  499. spn.setEnabled(false);
  500. } else {
  501. combo.add(_prop.msgs.replSetID);
  502. foreach (i, a; arr) { mixin(S_TRACE);
  503. if (!incSearch.match(a.name)) continue;
  504. combo.add(to!(string)(a.id) ~ "." ~ a.name);
  505. tbl2[i + 1] = a.id;
  506. }
  507. combo.select(1 < combo.getItemCount() ? 1 : 0);
  508. if (oldSel) { mixin(S_TRACE);
  509. auto i = combo.indexOf(oldSel);
  510. if (i >= 0) combo.select(i);
  511. }
  512. spn.setEnabled(combo.getSelectionIndex() == 0);
  513. }
  514. tbl = tbl2;
  515. }
  516. private void setupIDsImpl1(T)(T[] arr, bool clear, bool from, bool to) { mixin(S_TRACE);
  517. if (from) setupIDsImpl2(arr, _fromID, _fromIDVal, _fromIDTbl, clear, _fromIDIncSearch);
  518. if (to) setupIDsImpl2(arr, _toID, _toIDVal, _toIDTbl, clear, _toIDIncSearch);
  519. }
  520. private void setupIDs(bool clear, bool from, bool to) { mixin(S_TRACE);
  521. if (!_summ) { mixin(S_TRACE);
  522. _fromID.removeAll();
  523. _fromID.setEnabled(false);
  524. _fromIDVal.setEnabled(false);
  525. _toID.removeAll();
  526. _toID.setEnabled(false);
  527. _toIDVal.setEnabled(false);
  528. return;
  529. }
  530. if (from) _fromID.setEnabled(true);
  531. if (to) _toID.setEnabled(true);
  532. switch (_idKind.getSelectionIndex()) {
  533. case ID_AREA: setupIDsImpl1(_summ.areas, clear, from, to); break;
  534. case ID_BATTLE: setupIDsImpl1(_summ.battles, clear, from, to); break;
  535. case ID_PACKAGE: setupIDsImpl1(_summ.packages, clear, from, to); break;
  536. case ID_CAST: setupIDsImpl1(_summ.casts, clear, from, to); break;
  537. case ID_SKILL: setupIDsImpl1(_summ.skills, clear, from, to); break;
  538. case ID_ITEM: setupIDsImpl1(_summ.items, clear, from, to); break;
  539. case ID_BEAST: setupIDsImpl1(_summ.beasts, clear, from, to); break;
  540. case ID_INFO: setupIDsImpl1(_summ.infos, clear, from, to); break;
  541. case ID_FLAG: setupIDsImpl1(_summ.flagDirRoot.allFlags, clear, from, to); break;
  542. case ID_STEP: setupIDsImpl1(_summ.flagDirRoot.allSteps, clear, from, to); break;
  543. case ID_COUPON: setupIDsImpl1(_summ.useCounter.coupon.keys, clear, from, to); break;
  544. case ID_GOSSIP: setupIDsImpl1(_summ.useCounter.gossip.keys, clear, from, to); break;
  545. case ID_COMPLETE_STAMP: setupIDsImpl1(_summ.useCounter.completeStamp.keys, clear, from, to); break;
  546. case ID_KEY_CODE: setupIDsImpl1(_summ.useCounter.keyCode.keys, clear, from, to); break;
  547. // FIXME: CardWirth 1.60 ????
  548. /+ case ID_CELL_NAME: setupIDsImpl1(_summ.useCounter.cellName.keys, clear, from, to); break;
  549. +/ default: assert (0);
  550. }
  551. }
  552. private void fromIDIncSearch() { mixin(S_TRACE);
  553. .forceFocus(_fromID, true);
  554. _fromIDIncSearch.startIncSearch();
  555. }
  556. private void toIDIncSearch() { mixin(S_TRACE);
  557. .forceFocus(_toID, true);
  558. _toIDIncSearch.startIncSearch();
  559. }
  560. private string[] _lastMaterialPaths;
  561. private string[] allMaterials(bool scenarioOnly) { mixin(S_TRACE);
  562. if (!_summ) return [];
  563. return _summ.allMaterials(_comm.skin, _prop.var.etc.ignorePaths, _prop.var.etc.logicalSort, scenarioOnly);
  564. }
  565. private void setupPaths() { mixin(S_TRACE);
  566. bool oldIgnoreMod = ignoreMod;
  567. ignoreMod = true;
  568. scope (exit) ignoreMod = oldIgnoreMod;
  569. _lastMaterialPaths = [""] ~ allMaterials(false);
  570. setupPathsImpl(true, true);
  571. }
  572. private void setupPathsImpl(bool from, bool to) {
  573. void setPaths(Combo combo, IncSearch incSearch) { mixin(S_TRACE);
  574. auto old = combo.getText();
  575. combo.removeAll();
  576. foreach (path; _lastMaterialPaths) {
  577. if (!incSearch.match(path)) continue;
  578. combo.add(path);
  579. }
  580. combo.setText(old);
  581. }
  582. if (from) setPaths(_fromPath, _fromPathIncSearch);
  583. if (to) setPaths(_toPath, _toPathIncSearch);
  584. }
  585. class SListener : ShellAdapter {
  586. override void shellActivated(ShellEvent e) { mixin(S_TRACE);
  587. setupIDs(false, true, true);
  588. setupPaths();
  589. _comm.refreshToolBar();
  590. }
  591. }
  592. class SelID : SelectionAdapter {
  593. private Spinner _spn;
  594. this (Spinner spn) {_spn = spn;}
  595. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  596. auto combo = cast(Combo) e.widget;
  597. _spn.setEnabled(combo.getSelectionIndex() == 0);
  598. _comm.refreshToolBar();
  599. }
  600. }
  601. class SelIDKind : SelectionAdapter {
  602. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  603. selIDKind();
  604. }
  605. }
  606. void selIDKind() {
  607. updateIDCombo();
  608. setupIDs(true, true, true);
  609. _prop.var.etc.searchIDKind = _idKind.getSelectionIndex();
  610. _comm.refreshToolBar();
  611. }
  612. @property
  613. private bool idKindIsString() {
  614. auto index = _idKind.getSelectionIndex();
  615. // FIXME: CardWirth 1.60 ???? ????
  616. /+ return index == ID_FLAG || index == ID_STEP || index == ID_COUPON || index == ID_GOSSIP || index == ID_COMPLETE_STAMP || index == ID_KEY_CODE || index == ID_CELL_NAME;
  617. +/ return index == ID_FLAG || index == ID_STEP || index == ID_COUPON || index == ID_GOSSIP || index == ID_COMPLETE_STAMP || index == ID_KEY_CODE;
  618. // FIXME: CardWirth 1.60 ???? ????
  619. }
  620. private void updateIDCombo() { mixin(S_TRACE);
  621. if (idKindIsString) { mixin(S_TRACE);
  622. if (_fromID && !(_fromID.getStyle() & SWT.READ_ONLY)) return;
  623. if (_fromID) { mixin(S_TRACE);
  624. _fromID.dispose();
  625. _toID.dispose();
  626. }
  627. _fromID = new Combo(_fromIDComp, SWT.BORDER | SWT.DROP_DOWN);
  628. _fromID.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  629. _toID = new Combo(_toIDComp, SWT.BORDER | SWT.DROP_DOWN);
  630. _toID.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  631. } else { mixin(S_TRACE);
  632. if (_fromID && (_fromID.getStyle() & SWT.READ_ONLY)) return;
  633. if (_fromID) { mixin(S_TRACE);
  634. _fromID.dispose();
  635. _toID.dispose();
  636. }
  637. _fromID = new Combo(_fromIDComp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  638. _fromID.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  639. _fromID.addSelectionListener(new SelID(_fromIDVal));
  640. _toID = new Combo(_toIDComp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  641. _toID.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  642. _toID.addSelectionListener(new SelID(_toIDVal));
  643. }
  644. auto fMenu = new Menu(_win, SWT.POP_UP);
  645. _fromID.setMenu(fMenu);
  646. createMenuItem(_comm, fMenu, MenuID.IncSearch, &fromIDIncSearch, null);
  647. new MenuItem(fMenu, SWT.SEPARATOR);
  648. createTextMenu!Combo(_comm, _prop, _fromID, &catchMod);
  649. auto tMenu = new Menu(_win, SWT.POP_UP);
  650. _toID.setMenu(tMenu);
  651. createMenuItem(_comm, tMenu, MenuID.IncSearch, &toIDIncSearch, null);
  652. new MenuItem(tMenu, SWT.SEPARATOR);
  653. createTextMenu!Combo(_comm, _prop, _toID, &catchMod);
  654. _fromIDIncSearch = new IncSearch(_comm, _fromID);
  655. _fromIDIncSearch.modEvent ~= () => setupIDs(false, true, false);
  656. _toIDIncSearch = new IncSearch(_comm, _toID);
  657. _toIDIncSearch.modEvent ~= () => setupIDs(false, false, true);
  658. _fromIDComp.layout();
  659. _toIDComp.layout();
  660. }
  661. private void tabChanged() { mixin(S_TRACE);
  662. auto sel = _tabf.getSelection();
  663. if (!sel) return;
  664. _parent.setRedraw(false);
  665. scope (exit) _parent.setRedraw(true);
  666. _prop.var.etc.searchPlan = _tabf.getSelectionIndex();
  667. if (sel is _tabText || sel is _tabGrep) { mixin(S_TRACE);
  668. auto comp = _comps[sel is _tabGrep ? _tabGrep : _tabText];
  669. if (_textGrp1.getParent() !is comp) _textGrp1.setParent(comp);
  670. if (_textGrp2.getParent() !is comp) _textGrp2.setParent(comp);
  671. auto fromComp = sel is _tabGrep ? _grepFromComp : _textFromComp;
  672. if (_from.getParent() !is fromComp) { mixin(S_TRACE);
  673. _from.setParent(fromComp);
  674. }
  675. }
  676. foreach (tab, comp; _comps) { mixin(S_TRACE);
  677. auto gd = cast(GridData) comp.getLayoutData();
  678. if (tab is sel) { mixin(S_TRACE);
  679. gd.heightHint= SWT.DEFAULT;
  680. } else { mixin(S_TRACE);
  681. gd.heightHint= 0;
  682. }
  683. }
  684. _parent.layout(true);
  685. _replace.setEnabled(!(sel is _tabText && _ignoreReturnCode.getSelection()) && sel !is _tabContents && sel !is _tabCoupon && sel !is _tabUnuse && sel !is _tabError);
  686. _range.setEnabled(sel !is _tabUnuse && sel !is _tabGrep);
  687. _rangeAllCheck.setEnabled(_range.getEnabled());
  688. _comm.refreshToolBar();
  689. }
  690. class TSListener : SelectionAdapter {
  691. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  692. tabChanged();
  693. }
  694. }
  695. LCheck[] _checked;
  696. class LCheck : SelectionAdapter {
  697. Widget[] buttons;
  698. private Button _all = null;
  699. private void setSelection(Widget b, bool s) { mixin(S_TRACE);
  700. auto button = cast(Button) b;
  701. if (button) button.setSelection(s);
  702. auto ti = cast(ToolItem) b;
  703. if (ti) ti.setSelection(s);
  704. }
  705. private bool getSelection(Widget b) { mixin(S_TRACE);
  706. auto button = cast(Button) b;
  707. if (button) return button.getSelection();
  708. auto ti = cast(ToolItem) b;
  709. if (ti) return ti.getSelection();
  710. assert (0);
  711. }
  712. class AllCheck : SelectionAdapter {
  713. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  714. foreach (b; buttons) { mixin(S_TRACE);
  715. setSelection(b, _all.getSelection());
  716. }
  717. }
  718. }
  719. void check() { mixin(S_TRACE);
  720. bool checked = true;
  721. foreach (b; buttons) { mixin(S_TRACE);
  722. checked &= getSelection(b);
  723. }
  724. _all.setSelection(checked);
  725. }
  726. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  727. assert (_all);
  728. check();
  729. }
  730. void createAlls(Composite parent, string text) { mixin(S_TRACE);
  731. _all = new Button(parent, SWT.CHECK);
  732. _all.setText(text);
  733. _all.addSelectionListener(new AllCheck);
  734. check();
  735. }
  736. }
  737. Composite addButtonLine(Composite grp) { mixin(S_TRACE);
  738. auto comp = new Composite(grp, SWT.NONE);
  739. comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  740. auto rl = new RowLayout(SWT.HORIZONTAL);
  741. rl.wrap = true;
  742. rl.pack = false;
  743. comp.setLayout(rl);
  744. return comp;
  745. }
  746. void constructText(CTabFolder tabf) { mixin(S_TRACE);
  747. auto comp = new Composite(tabf, SWT.NONE);
  748. comp.setLayout(new GridLayout(1, true));
  749. auto comp2 = new Composite(comp, SWT.NONE);
  750. auto comp2gl = windowGridLayout(1, true);
  751. comp2gl.marginWidth = 0;
  752. comp2gl.marginHeight = 0;
  753. comp2.setLayout(comp2gl);
  754. { mixin(S_TRACE);
  755. auto grp = new Group(comp2, SWT.NONE);
  756. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  757. grp.setText(_prop.msgs.replText);
  758. grp.setLayout(new GridLayout(2, false));
  759. auto fl = new Label(grp, SWT.NONE);
  760. fl.setText(_prop.msgs.replFrom);
  761. _textFromComp = new Composite(grp, SWT.NONE);
  762. _textFromComp.setLayout(new FillLayout);
  763. _from = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN);
  764. _from.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  765. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  766. gd.widthHint = _prop.var.etc.nameWidth;
  767. _textFromComp.setLayoutData(gd);
  768. auto lt = new Label(grp, SWT.NONE);
  769. lt.setText(_prop.msgs.replTo);
  770. _to = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN);
  771. _to.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  772. _to.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  773. auto fMenu = new Menu(_win, SWT.POP_UP);
  774. _from.setMenu(fMenu);
  775. createMenuItem(_comm, fMenu, MenuID.IncSearch, {
  776. .forceFocus(_from, true);
  777. _fromIncSearch.startIncSearch();
  778. }, null);
  779. new MenuItem(fMenu, SWT.SEPARATOR);
  780. createTextMenu!Combo(_comm, _prop, _from, &catchMod);
  781. auto tMenu = new Menu(_win, SWT.POP_UP);
  782. _to.setMenu(tMenu);
  783. createMenuItem(_comm, tMenu, MenuID.IncSearch, {
  784. .forceFocus(_to, true);
  785. _toIncSearch.startIncSearch();
  786. }, null);
  787. new MenuItem(tMenu, SWT.SEPARATOR);
  788. createTextMenu!Combo(_comm, _prop, _to, &catchMod);
  789. _fromIncSearch = new IncSearch(_comm, _from);
  790. _fromIncSearch.modEvent ~= &updateFromHistory;
  791. _toIncSearch = new IncSearch(_comm, _to);
  792. _toIncSearch.modEvent ~= &updateToHistory;
  793. }
  794. { mixin(S_TRACE);
  795. auto grp = new Group(comp2, SWT.NONE);
  796. _textGrp1 = grp;
  797. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  798. gd.widthHint = _prop.var.etc.searchResultTableWidth;
  799. grp.setLayoutData(gd);
  800. grp.setText(_prop.msgs.replCond);
  801. grp.setLayout(new GridLayout(3, false));
  802. _notIgnoreCase = new Button(grp, SWT.CHECK);
  803. _notIgnoreCase.setText(_prop.msgs.replNotIgnoreCase);
  804. _exact = new Button(grp, SWT.CHECK);
  805. _exact.setText(_prop.msgs.replExactMatch);
  806. _ignoreReturnCode = new Button(grp, SWT.CHECK);
  807. _ignoreReturnCode.setText(_prop.msgs.replIgnoreReturnCode);
  808. _ignoreReturnCode.addSelectionListener(new SelIgnoreReturnCode);
  809. _useWildcard = new Button(grp, SWT.CHECK);
  810. _useWildcard.setText(_prop.msgs.replWildcard);
  811. _useWildcard.addSelectionListener(new SelWildcard);
  812. auto gdw = new GridData;
  813. gdw.horizontalSpan = 3;
  814. _useWildcard.setLayoutData(gdw);
  815. _useRegex = new Button(grp, SWT.CHECK);
  816. _useRegex.setText(_prop.msgs.replRegExp);
  817. _useRegex.addSelectionListener(new SelRegex);
  818. auto gdr = new GridData;
  819. gdr.horizontalSpan = 3;
  820. _useRegex.setLayoutData(gdr);
  821. }
  822. { mixin(S_TRACE);
  823. auto grp = new Group(comp2, SWT.NONE);
  824. _textGrp2 = grp;
  825. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  826. gd.widthHint = _prop.var.etc.searchResultTableWidth;
  827. grp.setLayoutData(gd);
  828. grp.setText(_prop.msgs.replTextTarget);
  829. grp.setLayout(zeroGridLayout(1, true));
  830. auto checked = new LCheck;
  831. _checked ~= checked;
  832. { mixin(S_TRACE);
  833. auto btns = addButtonLine(grp);
  834. Button createB(string text, char accr, bool summ = false) { mixin(S_TRACE);
  835. auto b = new Button(btns, SWT.CHECK);
  836. b.setText(text ~ "(&" ~ accr ~ ")");
  837. checked.buttons ~= b;
  838. b.addSelectionListener(checked);
  839. if (!summ) _noSummText ~= b;
  840. return b;
  841. }
  842. _summary = createB(_prop.msgs.replTextSummary, '1', true);
  843. _msg = createB(_prop.msgs.replTextMessage, '2');
  844. _cardName = createB(_prop.msgs.replTextCardName, '3');
  845. _cardDesc = createB(_prop.msgs.replTextCardDesc, '4');
  846. _event = createB(_prop.msgs.replTextEventText, '5');
  847. _start = createB(_prop.msgs.replTextStart, '6');
  848. _flag = createB(_prop.msgs.replTextFlagAndStep, '7');
  849. _coupon = createB(_prop.msgs.replTextCoupon, '8');
  850. _gossip = createB(_prop.msgs.replTextGossip, '9');
  851. _end = createB(_prop.msgs.replTextEndScenario, 'A');
  852. _area = createB(_prop.msgs.replTextAreaName, 'B');
  853. _keyCode = createB(_prop.msgs.replTextKeyCode, 'D');
  854. _file = createB(_prop.msgs.replTextFile, 'E');
  855. _comment = createB(_prop.msgs.replTextComment, 'G');
  856. _jptx = createB(_prop.msgs.replTextJptx, 'H');
  857. }
  858. auto sep = new Label(grp, SWT.SEPARATOR | SWT.HORIZONTAL);
  859. sep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  860. { mixin(S_TRACE);
  861. auto btns = addButtonLine(grp);
  862. checked.createAlls(btns, _prop.msgs.allCheck);
  863. }
  864. }
  865. auto tab = new CTabItem(tabf, SWT.NONE);
  866. tab.setText(_prop.msgs.replForText);
  867. tab.setControl(comp);
  868. _tabText = tab;
  869. auto gd = new GridData(GridData.FILL_BOTH);
  870. comp2.setLayoutData(gd);
  871. _comps[tab] = comp2;
  872. }
  873. void constructID(CTabFolder tabf) { mixin(S_TRACE);
  874. auto comp = new Composite(tabf, SWT.NONE);
  875. comp.setLayout(new GridLayout(1, true));
  876. auto comp2 = new Composite(comp, SWT.NONE);
  877. comp2.setLayout(zeroGridLayout(1, true));
  878. { mixin(S_TRACE);
  879. auto grp = new Group(comp2, SWT.NONE);
  880. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  881. grp.setText(_prop.msgs.replID);
  882. grp.setLayout(new GridLayout(3, false));
  883. { mixin(S_TRACE);
  884. auto l = new Label(grp, SWT.NONE);
  885. l.setText(_prop.msgs.replIDKind);
  886. _idKind = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
  887. _idKind.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  888. _idKind.add(_prop.msgs.replIDArea);
  889. _idKind.add(_prop.msgs.replIDBattle);
  890. _idKind.add(_prop.msgs.replIDPackage);
  891. _idKind.add(_prop.msgs.replIDCast);
  892. _idKind.add(_prop.msgs.replIDSkill);
  893. _idKind.add(_prop.msgs.replIDItem);
  894. _idKind.add(_prop.msgs.replIDBeast);
  895. _idKind.add(_prop.msgs.replIDInfo);
  896. _idKind.add(_prop.msgs.replIDFlag);
  897. _idKind.add(_prop.msgs.replIDStep);
  898. _idKind.add(_prop.msgs.replIDCoupon);
  899. _idKind.add(_prop.msgs.replIDGossip);
  900. _idKind.add(_prop.msgs.replIDCompleteStamp);
  901. _idKind.add(_prop.msgs.replIDKeyCode);
  902. // FIXME: CardWirth 1.60 ????
  903. /+ _idKind.add(_prop.msgs.replIDCellName);
  904. +/ _idKind.select(0);
  905. if (0 <= _prop.var.etc.searchIDKind && _prop.var.etc.searchIDKind < _idKind.getItemCount()) { mixin(S_TRACE);
  906. _idKind.select(_prop.var.etc.searchIDKind);
  907. }
  908. auto gd = new GridData;
  909. gd.horizontalSpan = 2;
  910. _idKind.setLayoutData(gd);
  911. _idKind.addSelectionListener(new SelIDKind);
  912. }
  913. { mixin(S_TRACE);
  914. auto sep = new Label(grp, SWT.SEPARATOR | SWT.HORIZONTAL);
  915. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  916. gd.horizontalSpan = 3;
  917. sep.setLayoutData(gd);
  918. }
  919. void setupID(string text, ref Composite comboComp, ref Spinner spn) { mixin(S_TRACE);
  920. auto l = new Label(grp, SWT.NONE);
  921. l.setText(text);
  922. comboComp = new Composite(grp, SWT.NONE);
  923. auto cl = new CenterLayout(SWT.HORIZONTAL | SWT.VERTICAL, 0);
  924. cl.fillHorizontal = true;
  925. cl.fillVertical = true;
  926. comboComp.setLayout(cl);
  927. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  928. gd.widthHint = _prop.var.etc.nameWidth;
  929. comboComp.setLayoutData(gd);
  930. spn = new Spinner(grp, SWT.BORDER);
  931. initSpinner(spn);
  932. spn.setMinimum(1);
  933. spn.setMaximum(_prop.looks.idMax);
  934. }
  935. setupID(_prop.msgs.replFrom, _fromIDComp, _fromIDVal);
  936. setupID(_prop.msgs.replTo, _toIDComp, _toIDVal);
  937. updateIDCombo();
  938. }
  939. auto tab = new CTabItem(tabf, SWT.NONE);
  940. tab.setText(_prop.msgs.replForID);
  941. tab.setControl(comp);
  942. _tabID = tab;
  943. auto gd = new GridData(GridData.FILL_BOTH);
  944. gd.heightHint = 0;
  945. comp2.setLayoutData(gd);
  946. _comps[tab] = comp2;
  947. }
  948. void constructPath(CTabFolder tabf) { mixin(S_TRACE);
  949. auto comp = new Composite(tabf, SWT.NONE);
  950. comp.setLayout(new GridLayout(1, true));
  951. auto comp2 = new Composite(comp, SWT.NONE);
  952. comp2.setLayout(zeroGridLayout(1, true));
  953. { mixin(S_TRACE);
  954. auto grp = new Group(comp2, SWT.NONE);
  955. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  956. grp.setText(_prop.msgs.replPath);
  957. grp.setLayout(new GridLayout(2, false));
  958. Combo setupPath(string text, ref IncSearch incSearch) { mixin(S_TRACE);
  959. auto l = new Label(grp, SWT.NONE);
  960. l.setText(text);
  961. auto combo = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN);
  962. combo.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  963. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  964. gd.widthHint = _prop.var.etc.nameWidth;
  965. combo.setLayoutData(gd);
  966. auto menu = new Menu(_win, SWT.POP_UP);
  967. combo.setMenu(menu);
  968. createMenuItem(_comm, menu, MenuID.IncSearch, {
  969. .forceFocus(combo, true);
  970. incSearch.startIncSearch();
  971. }, null);
  972. new MenuItem(menu, SWT.SEPARATOR);
  973. createTextMenu!Combo(_comm, _prop, combo, &catchMod);
  974. incSearch = new IncSearch(_comm, combo);
  975. return combo;
  976. }
  977. _fromPath = setupPath(_prop.msgs.replFrom, _fromPathIncSearch);
  978. _fromPathIncSearch.modEvent ~= () => setupPathsImpl(true, false);
  979. _toPath = setupPath(_prop.msgs.replTo, _toPathIncSearch);
  980. _fromPathIncSearch.modEvent ~= () => setupPathsImpl(false, true);
  981. }
  982. auto tab = new CTabItem(tabf, SWT.NONE);
  983. tab.setText(_prop.msgs.replForPath);
  984. tab.setControl(comp);
  985. _tabPath = tab;
  986. auto gd = new GridData(GridData.FILL_BOTH);
  987. gd.heightHint = 0;
  988. comp2.setLayoutData(gd);
  989. _comps[tab] = comp2;
  990. }
  991. void constructContents(CTabFolder tabf) { mixin(S_TRACE);
  992. auto comp = new Composite(tabf, SWT.NONE);
  993. comp.setLayout(new GridLayout(1, true));
  994. auto comp2 = new Composite(comp, SWT.NONE);
  995. comp2.setLayout(zeroGridLayout(1, true));
  996. { mixin(S_TRACE);
  997. auto grp = new Group(comp2, SWT.NONE);
  998. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  999. gd.widthHint = _prop.var.etc.searchResultTableWidth;
  1000. grp.setLayoutData(gd);
  1001. grp.setText(_prop.msgs.searchRange);
  1002. grp.setLayout(zeroGridLayout(1, true));
  1003. auto checked = new LCheck;
  1004. _checked ~= checked;
  1005. auto comp3 = new Composite(grp, SWT.NONE);
  1006. comp3.setLayoutData(new GridData(GridData.FILL_BOTH));
  1007. comp3.setLayout(windowGridLayout(1, true));
  1008. auto bar = new ToolBar(comp3, SWT.HORIZONTAL | SWT.FLAT | SWT.WRAP);
  1009. _comm.put(bar);
  1010. bar.setLayoutData(new GridData(GridData.FILL_BOTH));
  1011. foreach (cGrp, cs; CTYPE_GROUP) { mixin(S_TRACE);
  1012. foreach (cType; cs) { mixin(S_TRACE);
  1013. auto text = _prop.msgs.contentName(cType);
  1014. auto img = _prop.images.content(cType);
  1015. void delegate() func = null;
  1016. auto ti = createToolItem2(_comm, bar, text, img, func, null, SWT.CHECK);
  1017. _contents[cType] = ti;
  1018. checked.buttons ~= ti;
  1019. ti.addSelectionListener(checked);
  1020. }
  1021. if (cGrp < CTypeGroup.max) { mixin(S_TRACE);
  1022. new ToolItem(bar, SWT.SEPARATOR);
  1023. }
  1024. }
  1025. auto sep = new Label(grp, SWT.SEPARATOR | SWT.HORIZONTAL);
  1026. sep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1027. auto btns = addButtonLine(grp);
  1028. checked.createAlls(btns, _prop.msgs.allSelect);
  1029. }
  1030. auto tab = new CTabItem(tabf, SWT.NONE);
  1031. tab.setText(_prop.msgs.replContents);
  1032. tab.setControl(comp);
  1033. _tabContents = tab;
  1034. auto gd = new GridData(GridData.FILL_BOTH);
  1035. gd.heightHint = 0;
  1036. comp2.setLayoutData(gd);
  1037. _comps[tab] = comp2;
  1038. }
  1039. void constructCoupon(CTabFolder tabf) { mixin(S_TRACE);
  1040. auto comp = new Composite(tabf, SWT.NONE);
  1041. comp.setLayout(new GridLayout(1, true));
  1042. auto comp2 = new Composite(comp, SWT.NONE);
  1043. auto comp2gl = windowGridLayout(1, true);
  1044. comp2gl.marginWidth = 0;
  1045. comp2gl.marginHeight = 0;
  1046. comp2.setLayout(comp2gl);
  1047. { mixin(S_TRACE);
  1048. auto grp = new Group(comp2, SWT.NONE);
  1049. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  1050. gd.widthHint = _prop.var.etc.searchResultTableWidth;
  1051. grp.setLayoutData(gd);
  1052. grp.setText(_prop.msgs.searchRange);
  1053. grp.setLayout(zeroGridLayout(1, true));
  1054. auto checked = new LCheck;
  1055. _checked ~= checked;
  1056. { mixin(S_TRACE);
  1057. auto btns = addButtonLine(grp);
  1058. Button createB(string text, char accr) { mixin(S_TRACE);
  1059. auto b = new Button(btns, SWT.CHECK);
  1060. b.setText(text ~ "(&" ~ accr ~ ")");
  1061. checked.buttons ~= b;
  1062. b.addSelectionListener(checked);
  1063. return b;
  1064. }
  1065. _cCoupon = createB(_prop.msgs.replTextCoupon, '1');
  1066. _cGossip = createB(_prop.msgs.replTextGossip, '2');
  1067. _cEnd = createB(_prop.msgs.replTextEndScenario, '3');
  1068. _cKeyCode = createB(_prop.msgs.replTextKeyCode, '4');
  1069. // FIXME: CardWirth 1.60 ????
  1070. /+ _cCellName = createB(_prop.msgs.replTextCellName, '5');
  1071. +/ }
  1072. auto sep = new Label(grp, SWT.SEPARATOR | SWT.HORIZONTAL);
  1073. sep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1074. { mixin(S_TRACE);
  1075. auto btns = addButtonLine(grp);
  1076. checked.createAlls(btns, _prop.msgs.allCheck);
  1077. }
  1078. }
  1079. auto tab = new CTabItem(tabf, SWT.NONE);
  1080. tab.setText(_prop.msgs.replForCoupon);
  1081. tab.setControl(comp);
  1082. _tabCoupon = tab;
  1083. auto gd = new GridData(GridData.FILL_BOTH);
  1084. comp2.setLayoutData(gd);
  1085. _comps[tab] = comp2;
  1086. }
  1087. void constructUnuse(CTabFolder tabf) { mixin(S_TRACE);
  1088. auto comp = new Composite(tabf, SWT.NONE);
  1089. comp.setLayout(new GridLayout(1, true));
  1090. auto comp2 = new Composite(comp, SWT.NONE);
  1091. comp2.setLayout(zeroGridLayout(1, true));
  1092. { mixin(S_TRACE);
  1093. auto grp = new Group(comp2, SWT.NONE);
  1094. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1095. grp.setText(_prop.msgs.replUnuseTarget);
  1096. grp.setLayout(zeroGridLayout(1, true));
  1097. auto checked = new LCheck;
  1098. _checked ~= checked;
  1099. { mixin(S_TRACE);
  1100. auto btns = addButtonLine(grp);
  1101. Button createB(string text, char accr) { mixin(S_TRACE);
  1102. auto b = new Button(btns, SWT.CHECK);
  1103. b.setText(text ~ "(&" ~ accr ~ ")");
  1104. checked.buttons ~= b;
  1105. b.addSelectionListener(checked);
  1106. return b;
  1107. }
  1108. _unuseFlag = createB(_prop.msgs.replUnuseFlag, '1');
  1109. _unuseStep = createB(_prop.msgs.replUnuseStep, '2');
  1110. _unuseArea = createB(_prop.msgs.replUnuseArea, '3');
  1111. _unuseBattle = createB(_prop.msgs.replUnuseBattle, '4');
  1112. _unusePackage = createB(_prop.msgs.replUnusePackage, '5');
  1113. _unuseCast = createB(_prop.msgs.replUnuseCast, '6');
  1114. _unuseSkill = createB(_prop.msgs.replUnuseSkill, '7');
  1115. _unuseItem = createB(_prop.msgs.replUnuseItem, '8');
  1116. _unuseBeast = createB(_prop.msgs.replUnuseBeast, '9');
  1117. _unuseInfo = createB(_prop.msgs.replUnuseInfo, 'A');
  1118. _unuseStart = createB(_prop.msgs.replUnuseStart, 'B');
  1119. _unusePath = createB(_prop.msgs.replUnusePath, 'C');
  1120. }
  1121. auto sep = new Label(grp, SWT.SEPARATOR | SWT.HORIZONTAL);
  1122. sep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1123. { mixin(S_TRACE);
  1124. auto btns = addButtonLine(grp);
  1125. checked.createAlls(btns, _prop.msgs.allCheck);
  1126. }
  1127. }
  1128. auto tab = new CTabItem(tabf, SWT.NONE);
  1129. tab.setText(_prop.msgs.replForUnuse);
  1130. tab.setControl(comp);
  1131. _tabUnuse = tab;
  1132. auto gd = new GridData(GridData.FILL_BOTH);
  1133. gd.heightHint = 0;
  1134. comp2.setLayoutData(gd);
  1135. _comps[tab] = comp2;
  1136. }
  1137. void constructError(CTabFolder tabf) { mixin(S_TRACE);
  1138. auto comp = new Composite(tabf, SWT.NONE);
  1139. comp.setLayout(new GridLayout(1, true));
  1140. auto comp2 = new Composite(comp, SWT.NONE);
  1141. comp2.setLayout(zeroGridLayout(1, true));
  1142. { mixin(S_TRACE);
  1143. auto l = new Label(comp2, SWT.WRAP);
  1144. l.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1145. l.setText(_prop.msgs.replError);
  1146. }
  1147. auto tab = new CTabItem(tabf, SWT.NONE);
  1148. tab.setText(_prop.msgs.replForError);
  1149. tab.setControl(comp);
  1150. _tabError = tab;
  1151. auto gd = new GridData(GridData.FILL_BOTH);
  1152. gd.heightHint = 0;
  1153. comp2.setLayoutData(gd);
  1154. _comps[tab] = comp2;
  1155. }
  1156. void constructGrep(CTabFolder tabf) { mixin(S_TRACE);
  1157. auto comp = new Composite(tabf, SWT.NONE);
  1158. comp.setLayout(new GridLayout(1, true));
  1159. auto comp2 = new Composite(comp, SWT.NONE);
  1160. auto comp2gl = windowGridLayout(1, true);
  1161. comp2gl.marginWidth = 0;
  1162. comp2gl.marginHeight = 0;
  1163. comp2.setLayout(comp2gl);
  1164. { mixin(S_TRACE);
  1165. auto grp = new Group(comp2, SWT.NONE);
  1166. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1167. grp.setText(_prop.msgs.grepText);
  1168. grp.setLayout(new GridLayout(2, false));
  1169. auto fl = new Label(grp, SWT.NONE);
  1170. fl.setText(_prop.msgs.grepFrom);
  1171. _grepFromComp = new Composite(grp, SWT.NONE);
  1172. _grepFromComp.setLayout(new FillLayout);
  1173. auto gd = new GridData(GridData.FILL_HORIZONTAL);
  1174. gd.widthHint = _prop.var.etc.nameWidth;
  1175. _grepFromComp.setLayoutData(gd);
  1176. }
  1177. { mixin(S_TRACE);
  1178. auto grp = new Group(comp2, SWT.NONE);
  1179. grp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1180. grp.setText(_prop.msgs.grepTarget);
  1181. grp.setLayout(new GridLayout(4, false));
  1182. _grepDir = new Combo(grp, SWT.BORDER | SWT.DROP_DOWN);
  1183. _grepDir.setVisibleItemCount(_prop.var.etc.comboVisibleItemCount);
  1184. createTextMenu!Combo(_comm, _prop, _grepDir, &catchMod);
  1185. _grepDir.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1186. auto grepDirRef = new Button(grp, SWT.PUSH);
  1187. grepDirRef.setText(_prop.msgs.reference);
  1188. .listener(grepDirRef, SWT.Selection, { mixin(S_TRACE);
  1189. selectDir(_prop, _grepDir, _prop.msgs.grepDir, _prop.msgs.grepDirDesc, _grepDir.getText());
  1190. });
  1191. createOpenButton(_comm, grp, {return _prop.toAppAbs(_grepDir.getText());}, true);
  1192. auto grepCurrent = new Button(grp, SWT.PUSH);
  1193. grepCurrent.setText(_prop.msgs.grepCurrent);
  1194. .listener(grepCurrent, SWT.Selection, &setGrepCurrentDir);
  1195. _grepSubDir = new Button(grp, SWT.CHECK);
  1196. auto gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
  1197. gd.horizontalSpan = 4;
  1198. _grepSubDir.setLayoutData(gd);
  1199. _grepSubDir.setText(_prop.msgs.grepSubDir);
  1200. .listener(_grepDir, SWT.Modify, { mixin(S_TRACE);
  1201. if (ignoreMod) return;
  1202. _prop.var.etc.grepDir = _grepDir.getText();
  1203. });
  1204. .listener(_grepSubDir, SWT.Selection, { mixin(S_TRACE);
  1205. if (ignoreMod) return;
  1206. _prop.var.etc.grepSubDir = _grepSubDir.getSelection();
  1207. });
  1208. }
  1209. auto tab = new CTabItem(tabf, SWT.NONE);
  1210. tab.setText(_prop.msgs.replGrep);
  1211. tab.setControl(comp);
  1212. _tabGrep = tab;
  1213. auto gd = new GridData(GridData.FILL_BOTH);
  1214. comp2.setLayoutData(gd);
  1215. _comps[tab] = comp2;
  1216. }
  1217. void setGrepCurrentDir() { mixin(S_TRACE);
  1218. if (_summ) { mixin(S_TRACE);
  1219. auto sc = _summ.scenarioPath.dirName();
  1220. if (_summ.useTemp) sc = _summ.zipName.dirName();
  1221. _grepDir.setText(sc);
  1222. }
  1223. }
  1224. void refFunc(bool Del, A : CWXPath)(A a) { mixin(S_TRACE);
  1225. bool recurse(TreeItem itm) { mixin(S_TRACE);
  1226. if (a is itm.getData()) { mixin(S_TRACE);
  1227. static if (Del) {
  1228. itm.dispose();
  1229. } else { mixin(S_TRACE);
  1230. itm.setText(a.name);
  1231. }
  1232. return true;
  1233. } else { mixin(S_TRACE);
  1234. foreach (child; itm.getItems()) { mixin(S_TRACE);
  1235. if (recurse(child)) { mixin(S_TRACE);
  1236. return true;
  1237. }
  1238. }
  1239. return false;
  1240. }
  1241. }
  1242. foreach (child; _range.getItems()) { mixin(S_TRACE);
  1243. if (recurse(child)) { mixin(S_TRACE);
  1244. return;
  1245. }
  1246. }
  1247. static if (!Del) {
  1248. // ??
  1249. refreshRangeTree();
  1250. }
  1251. }
  1252. void delArea(Area a) { mixin(S_TRACE);
  1253. refFunc!true(a);
  1254. }
  1255. void delBattle(Battle a) { mixin(S_TRACE);
  1256. refFunc!true(a);
  1257. }
  1258. void delPackage(Package a) { mixin(S_TRACE);
  1259. refFunc!true(a);
  1260. }
  1261. void delCast(CastCard a) { mixin(S_TRACE);
  1262. refFunc!true(a);
  1263. }
  1264. void delSkill(SkillCard a) { mixin(S_TRACE);
  1265. refFunc!true(a);
  1266. }
  1267. void delItem(ItemCard a) { mixin(S_TRACE);
  1268. refFunc!true(a);
  1269. }
  1270. void delBeast(BeastCard a) { mixin(S_TRACE);
  1271. refFunc!true(a);
  1272. }
  1273. void delInfo(InfoCard a) { mixin(S_TRACE);
  1274. refFunc!true(a);
  1275. }
  1276. void refArea(Area a) { mixin(S_TRACE);
  1277. if (_prop.var.etc.showAreaDirTree) {
  1278. refreshRangeTree();
  1279. } else {
  1280. refFunc!false(a);
  1281. }
  1282. }
  1283. void refBattle(Battle a) { mixin(S_TRACE);
  1284. if (_prop.var.etc.showAreaDirTree) {
  1285. refreshRangeTree();
  1286. } else {
  1287. refFunc!false(a);
  1288. }
  1289. }
  1290. void refPackage(Package a) { mixin(S_TRACE);
  1291. if (_prop.var.etc.showAreaDirTree) {
  1292. refreshRangeTree();
  1293. } else {
  1294. refFunc!false(a);
  1295. }
  1296. }
  1297. void refCast(CastCard a) { mixin(S_TRACE);
  1298. refFunc!false(a);
  1299. }
  1300. void refSkill(SkillCard a) { mixin(S_TRACE);
  1301. refFunc!false(a);
  1302. }
  1303. void refItem(ItemCard a) { mixin(S_TRACE);
  1304. refFunc!false(a);
  1305. }
  1306. void refBeast(BeastCard a) { mixin(S_TRACE);
  1307. refFunc!false(a);
  1308. }
  1309. void refInfo(InfoCard a) { mixin(S_TRACE);
  1310. refFunc!false(a);
  1311. }
  1312. static CWXPath[] rangeTree(Summary summ) { mixin(S_TRACE);
  1313. CWXPath[] r;
  1314. r ~= summ;
  1315. r ~= summ.flagDirRoot;
  1316. foreach (a; summ.areas) r ~= a;
  1317. foreach (a; summ.battles) r ~= a;
  1318. foreach (a; summ.packages) r ~= a;
  1319. foreach (a; summ.casts) { mixin(S_TRACE);
  1320. r ~= a;
  1321. foreach (c; a.skills) { mixin(S_TRACE);
  1322. if (0 != c.linkId) continue;
  1323. r ~= c;
  1324. }
  1325. foreach (c; a.items) { mixin(S_TRACE);
  1326. if (0 != c.linkId) continue;
  1327. r ~= c;
  1328. }
  1329. foreach (c; a.beasts) { mixin(S_TRACE);
  1330. if (0 != c.linkId) continue;
  1331. r ~= c;
  1332. }
  1333. }
  1334. foreach (a; summ.skills) r ~= a;
  1335. foreach (a; summ.items) r ~= a;
  1336. foreach (a; summ.beasts) r ~= a;
  1337. foreach (a; summ.infos) r ~= a;
  1338. return r;
  1339. }
  1340. void refreshRangeTree() { mixin(S_TRACE);
  1341. _range.setRedraw(false);
  1342. scope (exit) _range.setRedraw(true);
  1343. if (!_summ) { mixin(S_TRACE);
  1344. _range.removeAll();
  1345. return;
  1346. }
  1347. CWXPath sel = null;
  1348. auto selItm = _range.getSelection();
  1349. if (selItm.length) { mixin(S_TRACE);
  1350. sel = cast(CWXPath)selItm[0].getData();
  1351. }
  1352. _range.removeAll();
  1353. TreeItem add(TreeItem par, string name, CWXPath path) { mixin(S_TRACE);
  1354. TreeItem itm;
  1355. if (par) { mixin(S_TRACE);
  1356. itm = new TreeItem(par, SWT.NONE);
  1357. } else { mixin(S_TRACE);
  1358. itm = new TreeItem(_range, SWT.NONE);
  1359. }
  1360. string text1, text2;
  1361. Image img1, img2;
  1362. getPathParams(path, text1, text2, img1, img2, false);
  1363. itm.setText(name);
  1364. itm.setImage(img1);
  1365. itm.setData(cast(Object) path);
  1366. itm.setChecked(true);
  1367. if (sel is path) { mixin(S_TRACE);
  1368. _range.setSelection([itm]);
  1369. }
  1370. return itm;
  1371. }
  1372. add(null, _prop.msgs.summary, _summ);
  1373. add(null, _prop.msgs.flagsAndSteps, _summ.flagDirRoot);
  1374. if (_prop.var.etc.showAreaDirTree) { mixin(S_TRACE);
  1375. TreeItem[string] itmTable;
  1376. auto dirSet = new HashSet!string;
  1377. auto dirSet2 = new HashSet!string;
  1378. void put1(string dirName) { mixin(S_TRACE);
  1379. auto l = dirName.toLower();
  1380. if (dirSet2.contains(l)) return;
  1381. dirSet.add(dirName);
  1382. dirSet2.add(l);
  1383. }
  1384. foreach (a; _summ.areas) put1(a.dirName);
  1385. foreach (a; _summ.battles) put1(a.dirName);
  1386. foreach (a; _summ.packages) put1(a.dirName);
  1387. bool delegate(string, string) cmps;
  1388. if (_prop.var.etc.logicalSort) {
  1389. cmps = (a, b) => incmp(a, b) < 0;
  1390. } else {
  1391. cmps = (a, b) => icmp(a, b) < 0;
  1392. }
  1393. foreach (dirName; .sortDlg(dirSet.toArray(), cmps)) { mixin (S_TRACE);
  1394. auto dirs = .split(dirName, "\\");
  1395. TreeItem itm = null;
  1396. foreach (i, dir; dirs) { mixin (S_TRACE);
  1397. auto fPath = dirs[0 .. i + 1].join("\\");
  1398. auto path = fPath.toLower();
  1399. auto p = path in itmTable;
  1400. if (p) { mixin (S_TRACE);
  1401. itm = *p;
  1402. } else { mixin (S_TRACE);
  1403. TreeItem sub;
  1404. if (itm) { mixin (S_TRACE);
  1405. sub = new TreeItem(itm, SWT.NONE);
  1406. } else { mixin (S_TRACE);
  1407. sub = new TreeItem(_range, SWT.NONE);
  1408. }
  1409. sub.setText(dir);
  1410. sub.setImage(_prop.images.areaDir);
  1411. sub.setChecked(true);
  1412. itm = sub;
  1413. itmTable[path] = sub;
  1414. }
  1415. }
  1416. itmTable[dirName.toLower()] = itm;
  1417. }
  1418. void put(A)(A[] arr) { mixin (S_TRACE);
  1419. foreach (a; arr) { mixin (S_TRACE);
  1420. add(itmTable[a.dirName.toLower()], .tryFormat("%s.%s", a.id, a.baseName), a);
  1421. }
  1422. }
  1423. put(_summ.areas);
  1424. put(_summ.battles);
  1425. put(_summ.packages);
  1426. } else { mixin(S_TRACE);
  1427. foreach (a; _summ.areas) add(null, a.name, a);
  1428. foreach (a; _summ.battles) add(null, a.name, a);
  1429. foreach (a; _summ.packages) add(null, a.name, a);
  1430. }
  1431. foreach (a; _summ.casts) { mixin(S_TRACE);
  1432. auto par = add(null, .tryFormat("%s.%s", a.id, a.name), a);
  1433. foreach (c; a.skills) { mixin(S_TRACE);
  1434. if (0 != c.linkId) continue;
  1435. add(par, .tryFormat("%s.%s", c.id, c.name), c);
  1436. }
  1437. foreach (c; a.items) { mixin(S_TRACE);
  1438. if (0 != c.linkId) continue;
  1439. add(par, .tryFormat("%s.%s", c.id, c.name), c);
  1440. }
  1441. foreach (c; a.beasts) { mixin(S_TRACE);
  1442. if (0 != c.linkId) continue;
  1443. add(par, .tryFormat("%s.%s", c.id, c.name), c);
  1444. }
  1445. }
  1446. foreach (a; _summ.skills) { mixin(S_TRACE);
  1447. add(null, .tryFormat("%s.%s", a.id, a.name), a);
  1448. }
  1449. foreach (a; _summ.items) { mixin(S_TRACE);
  1450. add(null, .tryFormat("%s.%s", a.id, a.name), a);
  1451. }
  1452. foreach (a; _summ.beasts) { mixin(S_TRACE);
  1453. add(null, .tryFormat("%s.%s", a.id, a.name), a);
  1454. }
  1455. foreach (a; _summ.infos) { mixin(S_TRACE);
  1456. add(null, .tryFormat("%s.%s", a.id, a.name), a);
  1457. }
  1458. _range.treeExpandedAll();
  1459. _range.showSelection();
  1460. _comm.refreshToolBar();
  1461. }
  1462. void refreshRangeAllCheck() { mixin(S_TRACE);
  1463. bool recurse(TreeItem itm) { mixin(S_TRACE);
  1464. if (!itm.getChecked()) { mixin(S_TRACE);
  1465. return true;
  1466. } else { mixin(S_TRACE);
  1467. foreach (child; itm.getItems()) { mixin(S_TRACE);
  1468. if (recurse(child)) { mixin(S_TRACE);
  1469. return true;
  1470. }
  1471. }
  1472. return false;
  1473. }
  1474. }
  1475. foreach (child; _range.getItems()) { mixin(S_TRACE);
  1476. if (recurse(child)) { mixin(S_TRACE);
  1477. _rangeAllCheck.setSelection(false);
  1478. return;
  1479. }
  1480. }
  1481. _rangeAllCheck.setSelection(true);
  1482. }
  1483. class RefRangeAllCheck : SelectionAdapter {
  1484. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  1485. if (SWT.CHECK != e.detail) return;
  1486. auto par = (cast(TreeItem)e.item);
  1487. // ????????????????
  1488. // ??????????????????
  1489. if (par && !par.getData()) { mixin(S_TRACE);
  1490. void recurse(TreeItem itm) { mixin(S_TRACE);
  1491. itm.setChecked(par.getChecked());
  1492. foreach (child; itm.getItems()) recurse(child);
  1493. }
  1494. foreach (itm; par.getItems()) { mixin(S_TRACE);
  1495. recurse(itm);
  1496. }
  1497. }
  1498. // ??????????????????
  1499. // ?????????????????????????
  1500. while (par && par.getParentItem() && !par.getParentItem().getData()) { mixin(S_TRACE);
  1501. bool same = true;
  1502. void recurse2(TreeItem itm) { mixin(S_TRACE);
  1503. if (itm.getChecked() != par.getChecked()) { mixin(S_TRACE);
  1504. same = false;
  1505. return;
  1506. }
  1507. foreach (child; itm.getItems()) recurse2(child);
  1508. }
  1509. foreach (itm; par.getParentItem().getItems()) { mixin(S_TRACE);
  1510. recurse2(itm);
  1511. }
  1512. if (!same) break;
  1513. par.getParentItem().setChecked(par.getChecked());
  1514. par = par.getParentItem();
  1515. }
  1516. refreshRangeAllCheck();
  1517. }
  1518. }
  1519. class RangeAllCheck : SelectionAdapter {
  1520. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  1521. void recurse(TreeItem itm) { mixin(S_TRACE);
  1522. itm.setChecked(_rangeAllCheck.getSelection());
  1523. foreach (child; itm.getItems()) { mixin(S_TRACE);
  1524. recurse(child);
  1525. }
  1526. }
  1527. foreach (child; _range.getItems()) { mixin(S_TRACE);
  1528. recurse(child);
  1529. }
  1530. }
  1531. }
  1532. void refUndoMax() { mixin(S_TRACE);
  1533. _undo.max = _prop.var.etc.undoMaxReplace;
  1534. }
  1535. public:
  1536. this (Commons comm, Props prop, Shell shell, Summary summ) { mixin(S_TRACE);
  1537. _uiThread = core.thread.Thread.getThis();
  1538. _comm = comm;
  1539. _prop = prop;
  1540. _summ = summ;
  1541. _undo = new UndoManager(_prop.var.etc.undoMaxReplace);
  1542. _win = new Shell(shell, SWT.SHELL_TRIM);
  1543. _win.setText(_prop.msgs.dlgTitReplaceText);
  1544. _win.setImage(prop.images.menu(MenuID.Find));
  1545. _display = shell.getDisplay();
  1546. setup();
  1547. _win.open();
  1548. _win.setActive();
  1549. }
  1550. @property
  1551. Shell widget() { mixin(S_TRACE);
  1552. return _win;
  1553. }
  1554. @property
  1555. void summary(Summary summ) { mixin(S_TRACE);
  1556. if (_win.isDisposed()) return;
  1557. if (!summ) { mixin(S_TRACE);
  1558. _win.close();
  1559. } else { mixin(S_TRACE);
  1560. _summ = summ;
  1561. reset();
  1562. refreshRangeTree();
  1563. setupIDs(true, true, true);
  1564. }
  1565. _undo.reset();
  1566. _comm.refreshToolBar();
  1567. }
  1568. void open() { mixin(S_TRACE);
  1569. reset();
  1570. tabChanged();
  1571. auto tab = _tabf.getSelection();
  1572. if (tab is _tabText) { mixin(S_TRACE);
  1573. _from.setFocus();
  1574. } else if (tab is _tabID) { mixin(S_TRACE);
  1575. _idKind.setFocus();
  1576. } else if (tab is _tabPath) { mixin(S_TRACE);
  1577. _fromPath.setFocus();
  1578. } else if (tab is _tabContents) { mixin(S_TRACE);
  1579. // Nothing
  1580. } else if (tab is _tabCoupon) { mixin(S_TRACE);
  1581. // Nothing
  1582. } else if (tab is _tabUnuse) { mixin(S_TRACE);
  1583. // Nothing
  1584. } else if (tab is _tabError) { mixin(S_TRACE);
  1585. // Nothing
  1586. } else if (tab is _tabGrep) { mixin(S_TRACE);
  1587. _from.setFocus();
  1588. } else assert (0);
  1589. }
  1590. void replaceText(string from, bool start = false) { mixin(S_TRACE);
  1591. reset();
  1592. _from.setText(from);
  1593. _to.setText("");
  1594. _tabf.setSelection(_tabText);
  1595. tabChanged();
  1596. _from.setFocus();
  1597. if (start) { mixin(S_TRACE);
  1598. search();
  1599. }
  1600. }
  1601. void replacePath(string from, bool start = false) { mixin(S_TRACE);
  1602. reset();
  1603. _fromPath.setText(from);
  1604. _toPath.setText("");
  1605. _tabf.setSelection(_tabPath);
  1606. tabChanged();
  1607. _fromPath.setFocus();
  1608. if (start) { mixin(S_TRACE);
  1609. search();
  1610. }
  1611. }
  1612. void replaceID(ID)(ID from, bool start = false) { mixin(S_TRACE);
  1613. reset();
  1614. static if (is(ID:AreaId)) {
  1615. _idKind.select(ID_AREA);
  1616. } else static if (is(ID:BattleId)) {
  1617. _idKind.select(ID_BATTLE);
  1618. } else static if (is(ID:PackageId)) {
  1619. _idKind.select(ID_PACKAGE);
  1620. } else static if (is(ID:CastId)) {
  1621. _idKind.select(ID_CAST);
  1622. } else static if (is(ID:SkillId)) {
  1623. _idKind.select(ID_SKILL);
  1624. } else static if (is(ID:ItemId)) {
  1625. _idKind.select(ID_ITEM);
  1626. } else static if (is(ID:BeastId)) {
  1627. _idKind.select(ID_BEAST);
  1628. } else static if (is(ID:InfoId)) {
  1629. _idKind.select(ID_INFO);
  1630. } else static if (is(ID:FlagId)) {
  1631. _idKind.select(ID_FLAG);
  1632. } else static if (is(ID:StepId)) {
  1633. _idKind.select(ID_STEP);
  1634. } else static if (is(ID:CouponId)) {
  1635. _idKind.select(ID_COUPON);
  1636. } else static if (is(ID:GossipId)) {
  1637. _idKind.select(ID_GOSSIP);
  1638. } else static if (is(ID:CompleteStampId)) {
  1639. _idKind.select(ID_COMPLETE_STAMP);
  1640. } else static if (is(ID:KeyCodeId)) {
  1641. _idKind.select(ID_KEY_CODE);
  1642. } else static if (is(ID:CellNameId)) {
  1643. // FIXME: CardWirth 1.60 ????
  1644. /+ _idKind.select(ID_CELL_NAME);
  1645. +/ } else static assert (0);
  1646. selIDKind();
  1647. static if (is(typeof(from.id):ulong)) {
  1648. bool sel = false;
  1649. foreach (index, id; _fromIDTbl) { mixin(S_TRACE);
  1650. if (id == from.id) { mixin(S_TRACE);
  1651. _fromID.select(index);
  1652. sel = true;
  1653. break;
  1654. }
  1655. }
  1656. if (!sel) return;
  1657. } else {
  1658. _fromID.setText(cast(string)from);
  1659. }
  1660. _tabf.setSelection(_tabID);
  1661. tabChanged();
  1662. _fromID.setFocus();
  1663. if (start) { mixin(S_TRACE);
  1664. search();
  1665. }
  1666. }
  1667. private void openRangePath() { mixin(S_TRACE);
  1668. auto sels = _range.getSelection();
  1669. if (!sels.length) return;
  1670. auto data = cast(CWXPath)sels[0].getData();
  1671. if (!data) return;
  1672. string path = data.cwxPath(true);
  1673. path = cpaddattr(path, "shallow");
  1674. auto r = _comm.openCWXPath(path, false);
  1675. if (!r) { mixin(S_TRACE);
  1676. MessageBox.showWarning(.tryFormat(_prop.msgs.cwxPathOpenError, path), _prop.msgs.dlgTitWarning, _win);
  1677. }
  1678. }
  1679. private class OpenPath : MouseAdapter, KeyListener {
  1680. override void mouseDoubleClick(MouseEvent e) { mixin(S_TRACE);
  1681. if (1 == e.button) { mixin(S_TRACE);
  1682. openRangePath();
  1683. }
  1684. }
  1685. override void keyReleased(KeyEvent e) {}
  1686. override void keyPressed(KeyEvent e) { mixin(S_TRACE);
  1687. if (SWT.CR == e.character) openRangePath();
  1688. }
  1689. }
  1690. private void setup() { mixin(S_TRACE);
  1691. _win.addShellListener(new SListener);
  1692. _win.setLayout(zeroGridLayout(1, true));
  1693. auto area = new Composite(_win, SWT.NONE);
  1694. area.setLayoutData(new GridData(GridData.FILL_BOTH));
  1695. area.setLayout(windowGridLayout(2, false));
  1696. auto sash = new SplitPane(area, SWT.HORIZONTAL);
  1697. sash.setLayoutData(new GridData(GridData.FILL_BOTH));
  1698. auto left = new Composite(sash, SWT.NONE);
  1699. left.setLayout(windowGridLayout(1, true));
  1700. _parent = left;
  1701. auto right = new Composite(sash, SWT.NONE);
  1702. right.setLayout(windowGridLayout(1, true));
  1703. _tabf = new CTabFolder(left, SWT.BORDER);
  1704. { mixin(S_TRACE);
  1705. _tabf.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1706. constructText(_tabf);
  1707. constructID(_tabf);
  1708. constructPath(_tabf);
  1709. constructContents(_tabf);
  1710. constructCoupon(_tabf);
  1711. constructUnuse(_tabf);
  1712. constructError(_tabf);
  1713. constructGrep(_tabf);
  1714. _tabf.addSelectionListener(new TSListener);
  1715. }
  1716. { mixin(S_TRACE);
  1717. _result = new Table(left, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.VIRTUAL);
  1718. auto gd = new GridData(GridData.FILL_BOTH);
  1719. gd.widthHint = _prop.var.etc.searchResultTableWidth;
  1720. gd.heightHint = _prop.var.etc.searchResultTableHeight;
  1721. _result.setLayoutData(gd);
  1722. _result.addMouseListener(new ML);
  1723. _result.addKeyListener(new KL);
  1724. auto menu = new Menu(_win, SWT.POP_UP);
  1725. createMenuItem(_comm, menu, MenuID.Undo, &undo, &_undo.canUndo);
  1726. createMenuItem(_comm, menu, MenuID.Redo, &redo, &_undo.canRedo);
  1727. new MenuItem(menu, SWT.SEPARATOR);
  1728. createMenuItem(_comm, menu, MenuID.CopyAsText, &copyResult, () => _result.getSelectionIndex() != -1);
  1729. new MenuItem(menu, SWT.SEPARATOR);
  1730. createMenuItem(_comm, menu, MenuID.SelectAll, &_result.selectAll, () => _result.getItemCount() > 0);
  1731. new MenuItem(menu, SWT.SEPARATOR);
  1732. createMenuItem(_comm, menu, MenuID.OpenAtView, &openPath, &canOpenPath);
  1733. _result.setMenu(menu);
  1734. _edit = new TableTextEdit(_comm, _prop, _result, 0, &couponEditEnd, &canCouponEdit);
  1735. }
  1736. { mixin(S_TRACE);
  1737. auto comp = new Composite(left, SWT.NONE);
  1738. comp.setLayout(zeroMarginGridLayout(2, false));
  1739. comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  1740. auto realtime = new Button(comp, SWT.CHECK);
  1741. realtime.setText(_prop.msgs.searchResultRealtime);
  1742. realtime.setSelection(_prop.var.etc.searchResultRealtime);
  1743. .listener(realtime, SWT.Selection, { mixin(S_TRACE);
  1744. _prop.var.etc.searchResultRealtime = realtime.getSelection();
  1745. if (_prop.var.etc.searchResultRealtime) { mixin(S_TRACE);
  1746. resultRedraw(true);
  1747. } else if (_inProc) { mixin(S_TRACE);
  1748. resultRedraw(false);
  1749. }
  1750. });
  1751. auto openDlg = new Button(comp, SWT.CHECK);
  1752. openDlg.setText(_prop.msgs.searchOpenDialog);
  1753. openDlg.setSelection(_prop.var.etc.searchOpenDialog);
  1754. openDlg.addSelectionListener(new class SelectionAdapter {
  1755. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  1756. _prop.var.etc.searchOpenDialog = openDlg.getSelection();
  1757. }
  1758. });
  1759. }
  1760. { mixin(S_TRACE);
  1761. auto grp = new Group(right, SWT.NONE);
  1762. grp.setText(_prop.msgs.searchRange);
  1763. grp.setLayoutData(new GridData(GridData.FILL_BOTH));
  1764. grp.setLayout(new GridLayout(1, true));
  1765. _range = new Tree(grp, SWT.SINGLE | SWT.BORDER | SWT.VIRTUAL | SWT.CHECK);
  1766. initTree(_comm, _range, false);
  1767. _range.addSelectionListener(new RefRangeAllCheck);
  1768. _range.setLayoutData(new GridData(GridData.FILL_BOTH));
  1769. refreshRangeTree();
  1770. _rangeAllCheck = new Button(grp, SWT.CHECK);
  1771. _rangeAllCheck.setText(_prop.msgs.allCheckRange);
  1772. refreshRangeAllCheck();
  1773. _rangeAllCheck.addSelectionListener(new RangeAllCheck);
  1774. auto openPath = new OpenPath;
  1775. _range.addKeyListener(openPath);
  1776. _range.addMouseListener(openPath);
  1777. auto menu = new Menu(_win, SWT.POP_UP);
  1778. createMenuItem(_comm, menu, MenuID.OpenAtView, &openRangePath, () => _range.getSelection().length > 0 && cast(CWXPath)_range.getSelection()[0].getData());
  1779. _range.setMenu(menu);
  1780. }
  1781. { mixin(S_TRACE);
  1782. auto sep = new Label(_win, SWT.SEPARATOR | SWT.HORIZONTAL);
  1783. sep.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1784. }
  1785. { mixin(S_TRACE);
  1786. auto bArea = new Composite(_win, SWT.NONE);
  1787. bArea.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1788. bArea.setLayout(new GridLayout(2, false));
  1789. _status = new Label(bArea, SWT.NONE);
  1790. _status.setText(_prop.msgs.searchResultEmpty);
  1791. _status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1792. auto comp = new Composite(bArea, SWT.NONE);
  1793. comp.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
  1794. auto gl = new GridLayout(4, true);
  1795. gl.marginWidth = 0;
  1796. gl.marginHeight = 0;
  1797. comp.setLayout(gl);
  1798. Button createButton(string text, void delegate() push) { mixin(S_TRACE);
  1799. auto b = new Button(comp, SWT.PUSH);
  1800. b.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  1801. b.setText(text);
  1802. auto sa = new class SelectionAdapter {
  1803. private void delegate() push;
  1804. override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
  1805. push();
  1806. }
  1807. };
  1808. sa.push = push;
  1809. b.addSelectionListener(sa);
  1810. return b;
  1811. }
  1812. _find = createButton(_prop.msgs.search, &search);
  1813. _comm.put(_find, &canFind);
  1814. _replace = createButton(_prop.msgs.replace, &replace);
  1815. _comm.put(_replace, &canReplace);
  1816. _close = createButton(_prop.msgs.dlgTextClose, &exit);
  1817. auto cancel = createButton(_prop.msgs.searchCancel, { mixin(S_TRACE);
  1818. _cancel = true;
  1819. resultRedraw(true);
  1820. });
  1821. _comm.put(cancel, &canCancel);
  1822. }
  1823. auto d = _tabf.getDisplay();
  1824. auto keyFilter = new class Listener {
  1825. override void handleEvent(Event e) { mixin(S_TRACE);
  1826. auto fc = d.getFocusControl();
  1827. if (!fc || !_tabf.isDescendant(fc)) return;
  1828. if (e.character == SWT.CR) { mixin(S_TRACE);
  1829. search();
  1830. }
  1831. }
  1832. };
  1833. d.addFilter(SWT.KeyDown, keyFilter);
  1834. .listener(_tabf, SWT.Dispose, { mixin(S_TRACE);
  1835. d.removeFilter(SWT.KeyDown, keyFilter);
  1836. });
  1837. ignoreMod = true;
  1838. scope (exit) ignoreMod = false;
  1839. setComboItems(_from, _prop.var.etc.searchHistories.dup);
  1840. setComboItems(_to, _prop.var.etc.replaceHistories.dup);
  1841. setComboItems(_grepDir, _prop.var.etc.grepDirHistories.dup);
  1842. _notIgnoreCase.setSelection(_prop.var.etc.replaceTextNotIgnoreCase);
  1843. _exact.setSelection(_prop.var.etc.replaceTextExactMatch);
  1844. _ignoreReturnCode.setSelection(_prop.var.etc.replaceTextIgnoreReturnCode);
  1845. _useRegex.setSelection(_prop.var.etc.replaceTextRegExp);
  1846. _useWildcard.setSelection(_prop.var.etc.replaceTextWildcard);
  1847. _summary.setSelection(_prop.var.etc.replaceTextSummary);
  1848. _msg.setSelection(_prop.var.etc.replaceTextMessage);
  1849. _cardName.setSelection(_prop.var.etc.replaceTextCardName);
  1850. _cardDesc.setSelection(_prop.var.etc.replaceTextCardDescription);
  1851. _event.setSelection(_prop.var.etc.replaceTextEventText);
  1852. _flag.setSelection(_prop.var.etc.replaceTextFlagAndStep);
  1853. _start.setSelection(_prop.var.etc.replaceTextStart);
  1854. _coupon.setSelection(_prop.var.etc.replaceTextCoupon);
  1855. _gossip.setSelection(_prop.var.etc.replaceTextGossip);
  1856. _end.setSelection(_prop.var.etc.replaceTextEndScenario);
  1857. _area.setSelection(_prop.var.etc.replaceTextAreaName);
  1858. _keyCode.setSelection(_prop.var.etc.replaceTextKeyCode);
  1859. _file.setSelection(_prop.var.etc.replaceTextFile);
  1860. _comment.setSelection(_prop.var.etc.replaceTextComment);
  1861. _jptx.setSelection(_prop.var.etc.replaceTextJptx);
  1862. if (_prop.var.etc.grepDir.length) { mixin(S_TRACE);
  1863. _grepDir.setText(_prop.var.etc.grepDir);
  1864. } else { mixin(S_TRACE);
  1865. setGrepCurrentDir();
  1866. }
  1867. _grepSubDir.setSelection(_prop.var.etc.grepSubDir);
  1868. _contents[CType.START].setSelection(_prop.var.etc.searchContentsStart);
  1869. _contents[CType.START_BATTLE].setSelection(_prop.var.etc.searchContentsStartBattle);
  1870. _contents[CType.END].setSelection(_prop.var.etc.searchContentsEnd);
  1871. _contents[CType.END_BAD_END].setSelection(_prop.var.etc.searchContentsEndBadEnd);
  1872. _contents[CType.CHANGE_AREA].setSelection(_prop.var.etc.searchContentsChangeArea);
  1873. _contents[CType.CHANGE_BG_IMAGE].setSelection(_prop.var.etc.searchContentsChangeBgImage);
  1874. _contents[CType.EFFECT].setSelection(_prop.var.etc.searchContentsEffect);
  1875. _contents[CType.EFFECT_BREAK].setSelection(_prop.var.etc.searchContentsEffectBreak);
  1876. _contents[CType.LINK_START].setSelection(_prop.var.etc.searchContentsLinkStart);
  1877. _contents[CType.LINK_PACKAGE].setSelection(_prop.var.etc.searchContentsLinkPackage);
  1878. _contents[CType.TALK_MESSAGE].setSelection(_prop.var.etc.searchContentsTalkMessage);
  1879. _contents[CType.TALK_DIALOG].setSelection(_prop.var.etc.searchContentsTalkDialog);
  1880. _contents[CType.PLAY_BGM].setSelection(_prop.var.etc.searchContentsPlayBgm);
  1881. _contents[CType.PLAY_SOUND].setSelection(_prop.var.etc.searchContentsPlaySound);
  1882. _contents[CType.WAIT].setSelection(_prop.var.etc.searchContentsWait);
  1883. _contents[CType.ELAPSE_TIME].setSelection(_prop.var.etc.searchContentsElapseTime);
  1884. _contents[CType.CALL_START].setSelection(_prop.var.etc.searchContentsCallStart);
  1885. _contents[CType.CALL_PACKAGE].setSelection(_prop.var.etc.searchContentsCallPackage);
  1886. _contents[CType.BRANCH_FLAG].setSelection(_prop.var.etc.searchContentsBranchFlag);
  1887. _contents[CType.BRANCH_MULTI_STEP].setSelection(_prop.var.etc.searchContentsBranchMultiStep);
  1888. _contents[CType.BRANCH_STEP].setSelection(_prop.var.etc.searchContentsBranchStep);
  1889. _contents[CType.BRANCH_SELECT].setSelection(_prop.var.etc.searchContentsBranchSelect);
  1890. _contents[CType.BRANCH_ABILITY].setSelection(_prop.var.etc.searchContentsBranchAbility);
  1891. _contents[CType.BRANCH_RANDOM].setSelection(_prop.var.etc.searchContentsBranchRandom);
  1892. _contents[CType.BRANCH_LEVEL].setSelection(_prop.var.etc.searchContentsBranchLevel);
  1893. _contents[CType.BRANCH_STATUS].setSelection(_prop.var.etc.searchContentsBranchStatus);
  1894. _contents[CType.BRANCH_PARTY_NUMBER].setSelection(_prop.var.etc.searchContentsBranchPartyNumber);
  1895. _contents[CType.BRANCH_AREA].setSelection(_prop.var.etc.searchContentsBranchArea);
  1896. _contents[CType.BRANCH_BATTLE].setSelection(_prop.var.etc.searchContentsBranchBattle);
  1897. _contents[CType.BRANCH_IS_BATTLE].setSelection(_prop.var.etc.searchContentsBranchIsBattle);
  1898. _contents[CType.BRANCH_CAST].setSelection(_prop.var.etc.searchContentsBranchCast);
  1899. _contents[CType.BRANCH_ITEM].setSelection(_prop.var.etc.searchContentsBranchItem);
  1900. _contents[CType.BRANCH_SKILL].setSelection(_prop.var.etc.searchContentsBranchSkill);
  1901. _contents[CType.BRANCH_INFO].setSelection(_prop.var.etc.searchContentsBranchInfo);
  1902. _contents[CType.BRANCH_BEAST].setSelection(_prop.var.etc.searchContentsBranchBeast);
  1903. _contents[CType.BRANCH_MONEY].setSelection(_prop.var.etc.searchContentsBranchMoney);
  1904. _contents[CType.BRANCH_COUPON].setSelection(_prop.var.etc.searchContentsBranchCoupon);
  1905. _contents[CType.BRANCH_COMPLETE_STAMP].setSelection(_prop.var.etc.searchContentsBranchCompleteStamp);
  1906. _contents[CType.BRANCH_GOSSIP].setSelection(_prop.var.etc.searchContentsBranchGossip);
  1907. _contents[CType.SET_FLAG].setSelection(_prop.var.etc.searchContentsSetFlag);
  1908. _contents[CType.SET_STEP].setSelection(_prop.var.etc.searchContentsSetStep);
  1909. _contents[CType.SET_STEP_UP].setSelection(_prop.var.etc.searchContentsSetStepUp);
  1910. _contents[CType.SET_STEP_DOWN].setSelection(_prop.var.etc.searchContentsSetStepDown);
  1911. _contents[CType.REVERSE_FLAG].setSelection(_prop.var.etc.searchContentsReverseFlag);
  1912. _contents[CType.CHECK_FLAG].setSelection(_prop.var.etc.searchContentsCheckFlag);
  1913. _contents[CType.GET_CAST].setSelection(_prop.var.etc.searchContentsGetCast);
  1914. _contents[CType.GET_ITEM].setSelection(_prop.var.etc.searchContentsGetItem);
  1915. _contents[CType.GET_SKILL].setSelection(_prop.var.etc.searchContentsGetSkill);
  1916. _contents[CType.GET_INFO].setSelection(_prop.var.etc.searchContentsGetInfo);
  1917. _contents[CType.GET_BEAST].setSelection(_prop.var.etc.searchContentsGetBeast);
  1918. _contents[CType.GET_MONEY].setSelection(_prop.var.etc.searchContentsGetMoney);
  1919. _contents[CType.GET_COUPON].setSelection(_prop.var.etc.searchContentsGetCoupon);
  1920. _contents[CType.GET_COMPLETE_STAMP].setSelection(_prop.var.etc.searchContentsGetCompleteStamp);
  1921. _contents[CType.GET_GOSSIP].setSelection(_prop.var.etc.searchContentsGetGossip);
  1922. _contents[CType.LOSE_CAST].setSelection(_prop.var.etc.searchContentsLoseCast);
  1923. _contents[CType.LOSE_ITEM].setSelection(_prop.var.etc.searchContentsLoseItem);
  1924. _contents[CType.LOSE_SKILL].setSelection(_prop.var.etc.searchContentsLoseSkill);
  1925. _contents[CType.LOSE_INFO].setSelection(_prop.var.etc.searchContentsLoseInfo);
  1926. _contents[CType.LOSE_BEAST].setSelection(_prop.var.etc.searchContentsLoseBeast);
  1927. _contents[CType.LOSE_MONEY].setSelection(_prop.var.etc.searchContentsLoseMoney);
  1928. _contents[CType.LOSE_COUPON].setSelection(_prop.var.etc.searchContentsLoseCoupon);
  1929. _contents[CType.LOSE_COMPLETE_STAMP].setSelection(_prop.var.etc.searchContentsLoseCompleteStamp);
  1930. _contents[CType.LOSE_GOSSIP].setSelection(_prop.var.etc.searchContentsLoseGossip);
  1931. _contents[CType.SHOW_PARTY].setSelection(_prop.var.etc.searchContentsShowParty);
  1932. _contents[CType.HIDE_PARTY].setSelection(_prop.var.etc.searchContentsHideParty);
  1933. _contents[CType.REDISPLAY].setSelection(_prop.var.etc.searchContentsRedisplay);
  1934. _contents[CType.SUBSTITUTE_STEP].setSelection(_prop.var.etc.searchContentsSubstituteStep);
  1935. _contents[CType.SUBSTITUTE_FLAG].setSelection(_prop.var.etc.searchContentsSubstituteFlag);
  1936. _contents[CType.BRANCH_STEP_CMP].setSelection(_prop.var.etc.searchContentsBranchStepCmp);
  1937. _contents[CType.BRANCH_FLAG_CMP].setSelection(_prop.var.etc.searchContentsBranchFlagCmp);
  1938. _contents[CType.BRANCH_RANDOM_SELECT].setSelection(_prop.var.etc.searchContentsBranchRandomSelect);
  1939. _contents[CType.BRANCH_KEY_CODE].setSelection(_prop.var.etc.searchContentsBranchKeyCode);
  1940. _contents[CType.CHECK_STEP].setSelection(_prop.var.etc.searchContentsCheckStep);
  1941. _contents[CType.BRANCH_ROUND].setSelection(_prop.var.etc.searchContentsBranchRound);
  1942. _cCoupon.setSelection(_prop.var.etc.replaceNameCoupon);
  1943. _cGossip.setSelection(_prop.var.etc.replaceNameGossip);
  1944. _cEnd.setSelection(_prop.var.etc.replaceNameEndScenario);
  1945. _cKeyCode.setSelection(_prop.var.etc.replaceNameKeyCode);
  1946. // FIXME: CardWirth 1.60 ????
  1947. /+ _cCellName.setSelection(_prop.var.etc.replaceNameCellName);
  1948. +/
  1949. _unuseFlag.setSelection(_prop.var.etc.searchUnusedFlag);
  1950. _unuseStep.setSelection(_prop.var.etc.searchUnusedStep);
  1951. _unuseArea.setSelection(_prop.var.etc.searchUnusedArea);
  1952. _unuseBattle.setSelection(_prop.var.etc.searchUnusedBattle);
  1953. _unusePackage.setSelection(_prop.var.etc.searchUnusedPackage);
  1954. _unuseCast.setSelection(_prop.var.etc.searchUnusedCast);
  1955. _unuseSkill.setSelection(_prop.var.etc.searchUnusedSkill);
  1956. _unuseItem.setSelection(_prop.var.etc.searchUnusedItem);
  1957. _unuseBeast.setSelection(_prop.var.etc.searchUnusedBeast);
  1958. _unuseInfo.setSelection(_prop.var.etc.searchUnusedInfo);
  1959. _unuseStart.setSelection(_prop.var.etc.searchUnusedStart);
  1960. _unusePath.setSelection(_prop.var.etc.searchUnusedPath);
  1961. foreach (l; _checked) { mixin(S_TRACE);
  1962. l.check();
  1963. }
  1964. _tabf.setSelection(0);
  1965. if (0 <= _prop.var.etc.searchPlan && _prop.var.etc.searchPlan < _tabf.getItemCount()) { mixin(S_TRACE);
  1966. _tabf.setSelection(_prop.var.etc.searchPlan);
  1967. }
  1968. sash.addDisposeListener(new SashDispose);
  1969. sash.setWeights([_prop.var.etc.replaceRangeSashL, _prop.var.etc.replaceRangeSashR]);
  1970. _comm.refTableViewStyle.add(&refreshRangeTree);
  1971. _comm.refArea.add(&refArea);
  1972. _comm.refBattle.add(&refBattle);
  1973. _comm.refPackage.add(&refPackage);
  1974. _comm.refCast.add(&refCast);
  1975. _comm.refSkill.add(&refSkill);
  1976. _comm.refItem.add(&refItem);
  1977. _comm.refBeast.add(&refBeast);
  1978. _comm.refInfo.add(&refInfo);
  1979. _comm.delArea.add(&delArea);
  1980. _comm.delBattle.add(&delBattle);
  1981. _comm.delPackage.add(&delPackage);
  1982. _comm.delCast.add(&delCast);
  1983. _comm.delSkill.add(&delSkill);
  1984. _comm.delItem.add(&delItem);
  1985. _comm.delBeast.add(&delBeast);
  1986. _comm.delInfo.add(&delInfo);
  1987. _comm.refSearchHistories.add(&refSearchHistories);
  1988. _comm.refContentText.add(&refContentText);
  1989. _comm.refUndoMax.add(&refUndoMax);
  1990. _comm.changed.add(&changed);
  1991. _comm.refScenario.add(&summary);
  1992. _win.addDisposeListener(new DL);
  1993. auto cs = _win.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  1994. auto size = _prop.var.replaceDlg;
  1995. if (size.width != SWT.DEFAULT) cs.x = size.width;
  1996. if (size.height != SWT.DEFAULT) cs.y = size.height;
  1997. _win.setSize(cs);
  1998. auto winProps = _prop.var.replaceDlg;
  1999. _win.setMaximized(winProps.maximized);
  2000. scope wp = _win.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  2001. int width = winProps.width == SWT.DEFAULT ? wp.x : winProps.width;
  2002. int height = winProps.height == SWT.DEFAULT ? wp.y : winProps.height;
  2003. int x = winProps.x == SWT.DEFAULT ? _win.getBounds().x : winProps.x + _win.getParent().getBounds().x;
  2004. int y = winProps.y == SWT.DEFAULT ? _win.getBounds().y : winProps.y + _win.getParent().getBounds().y;
  2005. intoDisplay(x, y, width, height);
  2006. _win.setBounds(x, y, width, height);
  2007. }
  2008. private void saveWin() { mixin(S_TRACE);
  2009. auto winProps = _prop.var.replaceDlg;
  2010. if (!_win.getMaximized()) { mixin(S_TRACE);
  2011. winProps.width = _win.getSize().x;
  2012. winProps.height = _win.getSize().y;
  2013. winProps.x = _win.getBounds().x - _win.getParent().getBounds().x;
  2014. winProps.y = _win.getBounds().y - _win.getParent().getBounds().y;
  2015. }
  2016. winProps.maximized = _win.getMaximized();
  2017. }
  2018. private class SashDispose : DisposeListener {
  2019. override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
  2020. auto sash = cast(SplitPane) e.widget;
  2021. auto ws = sash.getWeights();
  2022. _prop.var.etc.replaceRangeSashL = ws[0];
  2023. _prop.var.etc.replaceRangeSashR = ws[1];
  2024. }
  2025. }
  2026. private class DL : DisposeListener {
  2027. override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
  2028. _cancel = true;
  2029. _comm.changed.remove(&changed);
  2030. _comm.refScenario.remove(&summary);
  2031. saveWin();
  2032. _prop.var.etc.replaceTextNotIgnoreCase = _notIgnoreCase.getSelection();
  2033. _prop.var.etc.replaceTextExactMatch = _exact.getSelection();
  2034. _prop.var.etc.replaceTextIgnoreReturnCode = _ignoreReturnCode.getSelection();
  2035. _prop.var.etc.replaceTextRegExp = _useRegex.getSelection();
  2036. _prop.var.etc.replaceTextWildcard = _useWildcard.getSelection();
  2037. _prop.var.etc.replaceTextSummary = _summary.getSelection();
  2038. _prop.var.etc.replaceTextMessage = _msg.getSelection();
  2039. _prop.var.etc.replaceTextCardName = _cardName.getSelection();
  2040. _prop.var.etc.replaceTextCardDescription = _cardDesc.getSelection();
  2041. _prop.var.etc.replaceTextEventText = _event.getSelection();
  2042. _prop.var.etc.replaceTextStart = _start.getSelection();
  2043. _prop.var.etc.replaceTextFlagAndStep = _flag.getSelection();
  2044. _prop.var.etc.replaceTextCoupon = _coupon.getSelection();
  2045. _prop.var.etc.replaceTextGossip = _gossip.getSelection();
  2046. _prop.var.etc.replaceTextEndScenario = _end.getSelection();
  2047. _prop.var.etc.replaceTextAreaName = _area.getSelection();
  2048. _prop.var.etc.replaceTextKeyCode = _keyCode.getSelection();
  2049. _prop.var.etc.replaceTextFile = _file.getSelection();
  2050. _prop.var.etc.replaceTextComment = _comment.getSelection();
  2051. _prop.var.etc.replaceTextJptx = _jptx.getSelection();
  2052. _prop.var.etc.searchContentsStart = _contents[CType.START].getSelection();
  2053. _prop.var.etc.searchContentsStartBattle = _contents[CType.START_BATTLE].getSelection();
  2054. _prop.var.etc.searchContentsEnd = _contents[CType.END].getSelection();
  2055. _prop.var.etc.searchContentsEndBadEnd = _contents[CType.END_BAD_END].getSelection();
  2056. _prop.var.etc.searchContentsChangeArea = _contents[CType.CHANGE_AREA].getSelection();
  2057. _prop.var.etc.searchContentsChangeBgImage = _contents[CType.CHANGE_BG_IMAGE].getSelection();
  2058. _prop.var.etc.searchContentsEffect = _contents[CType.EFFECT].getSelection();
  2059. _prop.var.etc.searchContentsEffectBreak = _contents[CType.EFFECT_BREAK].getSelection();
  2060. _prop.var.etc.searchContentsLinkStart = _contents[CType.LINK_START].getSelection();
  2061. _prop.var.etc.searchContentsLinkPackage = _contents[CType.LINK_PACKAGE].getSelection();
  2062. _prop.var.etc.searchContentsTalkMessage = _contents[CType.TALK_MESSAGE].getSelection();
  2063. _prop.var.etc.searchContentsTalkDialog = _contents[CType.TALK_DIALOG].getSelection();
  2064. _prop.var.etc.searchContentsPlayBgm = _contents[CType.PLAY_BGM].getSelection();
  2065. _prop.var.etc.searchContentsPlaySound = _contents[CType.PLAY_SOUND].getSelection();
  2066. _prop.var.etc.searchContentsWait = _contents[CType.WAIT].getSelection();
  2067. _prop.var.etc.searchContentsElapseTime = _contents[CType.ELAPSE_TIME].getSelection();
  2068. _prop.var.etc.searchContentsCallStart = _contents[CType.CALL_START].getSelection();
  2069. _prop.var.etc.searchContentsCallPackage = _contents[CType.CALL_PACKAGE].getSelection();
  2070. _prop.var.etc.searchContentsBranchFlag = _contents[CType.BRANCH_FLAG].getSelection();
  2071. _prop.var.etc.searchContentsBranchMultiStep = _contents[CType.BRANCH_MULTI_STEP].getSelection();
  2072. _prop.var.etc.searchContentsBranchStep = _contents[CType.BRANCH_STEP].getSelection();
  2073. _prop.var.etc.searchContentsBranchSelect = _contents[CType.BRANCH_SELECT].getSelection();
  2074. _prop.var.etc.searchContentsBranchAbility = _contents[CType.BRANCH_ABILITY].getSelection();
  2075. _prop.var.etc.searchContentsBranchRandom = _contents[CType.BRANCH_RANDOM].getSelection();
  2076. _prop.var.etc.searchContentsBranchLevel = _contents[CType.BRANCH_LEVEL].getSelection();
  2077. _prop.var.etc.searchContentsBranchStatus = _contents[CType.BRANCH_STATUS].getSelection();
  2078. _prop.var.etc.searchContentsBranchPartyNumber = _contents[CType.BRANCH_PARTY_NUMBER].getSelection();
  2079. _prop.var.etc.searchContentsBranchArea = _contents[CType.BRANCH_AREA].getSelection();
  2080. _prop.var.etc.searchContentsBranchBattle = _contents[CType.BRANCH_BATTLE].getSelection();
  2081. _prop.var.etc.searchContentsBranchIsBattle = _contents[CType.BRANCH_IS_BATTLE].getSelection();
  2082. _prop.var.etc.searchContentsBranchCast = _contents[CType.BRANCH_CAST].getSelection();
  2083. _prop.var.etc.searchContentsBranchItem = _contents[CType.BRANCH_ITEM].getSelection();
  2084. _prop.var.etc.searchContentsBranchSkill = _contents[CType.BRANCH_SKILL].getSelection();
  2085. _prop.var.etc.searchContentsBranchInfo = _contents[CType.BRANCH_INFO].getSelection();
  2086. _prop.var.etc.searchContentsBranchBeast = _contents[CType.BRANCH_BEAST].getSelection();
  2087. _prop.var.etc.searchContentsBranchMoney = _contents[CType.BRANCH_MONEY].getSelection();
  2088. _prop.var.etc.searchContentsBranchCoupon = _contents[CType.BRANCH_COUPON].getSelection();
  2089. _prop.var.etc.searchContentsBranchCompleteStamp = _contents[CType.BRANCH_COMPLETE_STAMP].getSelection();
  2090. _prop.var.etc.searchContentsBranchGossip = _contents[CType.BRANCH_GOSSIP].getSelection();
  2091. _prop.var.etc.searchContentsSetFlag = _contents[CType.SET_FLAG].getSelection();
  2092. _prop.var.etc.searchContentsSetStep = _contents[CType.SET_STEP].getSelection();
  2093. _prop.var.etc.searchContentsSetStepUp = _contents[CType.SET_STEP_UP].getSelection();
  2094. _prop.var.etc.searchContentsSetStepDown = _contents[CType.SET_STEP_DOWN].getSelection();
  2095. _prop.var.etc.searchContentsReverseFlag = _contents[CType.REVERSE_FLAG].getSelection();
  2096. _prop.var.etc.searchContentsCheckFlag = _contents[CType.CHECK_FLAG].getSelection();
  2097. _prop.var.etc.searchContentsGetCast = _contents[CType.GET_CAST].getSelection();
  2098. _prop.var.etc.searchContentsGetItem = _contents[CType.GET_ITEM].getSelection();
  2099. _prop.var.etc.searchContentsGetSkill = _contents[CType.GET_SKILL].getSelection();
  2100. _prop.var.etc.searchContentsGetInfo = _contents[CType.GET_INFO].getSelection();
  2101. _prop.var.etc.searchContentsGetBeast = _contents[CType.GET_BEAST].getSelection();
  2102. _prop.var.etc.searchContentsGetMoney = _contents[CType.GET_MONEY].getSelection();
  2103. _prop.var.etc.searchContentsGetCoupon = _contents[CType.GET_COUPON].getSelection();
  2104. _prop.var.etc.searchContentsGetCompleteStamp = _contents[CType.GET_COMPLETE_STAMP].getSelection();
  2105. _prop.var.etc.searchContentsGetGossip = _contents[CType.GET_GOSSIP].getSelection();
  2106. _prop.var.etc.searchContentsLoseCast = _contents[CType.LOSE_CAST].getSelection();
  2107. _prop.var.etc.searchContentsLoseItem = _contents[CType.LOSE_ITEM].getSelection();
  2108. _prop.var.etc.searchContentsLoseSkill = _contents[CType.LOSE_SKILL].getSelection();
  2109. _prop.var.etc.searchContentsLoseInfo = _contents[CType.LOSE_INFO].getSelection();
  2110. _prop.var.etc.searchContentsLoseBeast = _contents[CType.LOSE_BEAST].getSelection();
  2111. _prop.var.etc.searchContentsLoseMoney = _contents[CType.LOSE_MONEY].getSelection();
  2112. _prop.var.etc.searchContentsLoseCoupon = _contents[CType.LOSE_COUPON].getSelection();
  2113. _prop.var.etc.searchContentsLoseCompleteStamp = _contents[CType.LOSE_COMPLETE_STAMP].getSelection();
  2114. _prop.var.etc.searchContentsLoseGossip = _contents[CType.LOSE_GOSSIP].getSelection();
  2115. _prop.var.etc.searchContentsShowParty = _contents[CType.SHOW_PARTY].getSelection();
  2116. _prop.var.etc.searchContentsHideParty = _contents[CType.HIDE_PARTY].getSelection();
  2117. _prop.var.etc.searchContentsRedisplay = _contents[CType.REDISPLAY].getSelection();
  2118. _prop.var.etc.searchContentsSubstituteStep = _contents[CType.SUBSTITUTE_STEP].getSelection();
  2119. _prop.var.etc.searchContentsSubstituteFlag = _contents[CType.SUBSTITUTE_FLAG].getSelection();
  2120. _prop.var.etc.searchContentsBranchStepCmp = _contents[CType.BRANCH_STEP_CMP].getSelection();
  2121. _prop.var.etc.searchContentsBranchFlagCmp = _contents[CType.BRANCH_FLAG_CMP].getSelection();
  2122. _prop.var.etc.searchContentsBranchRandomSelect = _contents[CType.BRANCH_RANDOM_SELECT].getSelection();
  2123. _prop.var.etc.searchContentsBranchKeyCode = _contents[CType.BRANCH_KEY_CODE].getSelection();
  2124. _prop.var.etc.searchContentsCheckStep = _contents[CType.CHECK_STEP].getSelection();
  2125. _prop.var.etc.searchContentsBranchRound = _contents[CType.BRANCH_ROUND].getSelection();
  2126. _prop.var.etc.replaceNameCoupon = _cCoupon.getSelection();
  2127. _prop.var.etc.replaceNameGossip = _cGossip.getSelection();
  2128. _prop.var.etc.replaceNameEndScenario = _cEnd.getSelection();
  2129. _prop.var.etc.replaceNameKeyCode = _cKeyCode.getSelection();
  2130. // FIXME: CardWirth 1.60 ????
  2131. /+ _prop.var.etc.replaceNameCellName = _cCellName.getSelection();
  2132. +/
  2133. _prop.var.etc.searchUnusedFlag = _unuseFlag.getSelection();
  2134. _prop.var.etc.searchUnusedStep = _unuseStep.getSelection();
  2135. _prop.var.etc.searchUnusedArea = _unuseArea.getSelection();
  2136. _prop.var.etc.searchUnusedBattle = _unuseBattle.getSelection();
  2137. _prop.var.etc.searchUnusedPackage = _unusePackage.getSelection();
  2138. _prop.var.etc.searchUnusedCast = _unuseCast.getSelection();
  2139. _prop.var.etc.searchUnusedSkill = _unuseSkill.getSelection();
  2140. _prop.var.etc.searchUnusedItem = _unuseItem.getSelection();
  2141. _prop.var.etc.searchUnusedBeast = _unuseBeast.getSelection();
  2142. _prop.var.etc.searchUnusedInfo = _unuseInfo.getSelection();
  2143. _prop.var.etc.searchUnusedStart = _unuseStart.getSelection();
  2144. _prop.var.etc.searchUnusedPath = _unusePath.getSelection();
  2145. _comm.refTableViewStyle.remove(&refreshRangeTree);
  2146. _comm.refArea.remove(&refArea);
  2147. _comm.refBattle.remove(&refBattle);
  2148. _comm.refPackage.remove(&refPackage);
  2149. _comm.refCast.remove(&refCast);
  2150. _comm.refSkill.remove(&refSkill);
  2151. _comm.refItem.remove(&refItem);
  2152. _comm.refBeast.remove(&refBeast);
  2153. _comm.refInfo.remove(&refInfo);
  2154. _comm.delArea.remove(&delArea);
  2155. _comm.delBattle.remove(&delBattle);
  2156. _comm.delPackage.remove(&delPackage);
  2157. _comm.delCast.remove(&delCast);
  2158. _comm.delSkill.remove(&delSkill);
  2159. _comm.delItem.remove(&delItem);
  2160. _comm.delBeast.remove(&delBeast);
  2161. _comm.delInfo.remove(&delInfo);
  2162. _comm.refSearchHistories.remove(&refSearchHistories);
  2163. _comm.refContentText.remove(&refContentText);
  2164. _comm.refUndoMax.remove(&refUndoMax);
  2165. }
  2166. }
  2167. private void changed() { mixin(S_TRACE);
  2168. if (!_inUndo && !_inProc) { mixin(S_TRACE);
  2169. _undo.reset();
  2170. }
  2171. auto thr = core.thread.Thread.getThis();
  2172. if (&_uiThread !is &thr) return;
  2173. if (_inGrep) return;
  2174. if (_inUndo) return;
  2175. if (_inProc) { mixin(S_TRACE);
  2176. _cancel = true;
  2177. } else { mixin(S_TRACE);
  2178. _comm.refreshToolBar();
  2179. }
  2180. }
  2181. private void undo() { mixin(S_TRACE);
  2182. if (!_undo.canUndo) return;
  2183. scope (exit) {
  2184. _comm.refreshToolBar();
  2185. }
  2186. _inProc = true;
  2187. scope (exit) _inProc = false;
  2188. _inUndo = true;
  2189. scope (exit) _inUndo = false;
  2190. resultRedraw(false);
  2191. scope (exit) resultRedraw(true);
  2192. _undo.undo();
  2193. _comm.updateJpy1Files();
  2194. }
  2195. private void redo() { mixin(S_TRACE);
  2196. if (!_undo.canRedo) return;
  2197. scope (exit) {
  2198. _comm.refreshToolBar();
  2199. }
  2200. _inProc = true;
  2201. scope (exit) _inProc = false;
  2202. _inUndo = true;
  2203. scope (exit) _inUndo = false;
  2204. resultRedraw(false);
  2205. scope (exit) resultRedraw(true);
  2206. _undo.redo();
  2207. _comm.updateJpy1Files();
  2208. }
  2209. private void search() { mixin(S_TRACE);
  2210. auto c = _win.getDisplay().getFocusControl();
  2211. _replMode = false;
  2212. replaceImpl();
  2213. if (c) .forceFocus(c, false);
  2214. }
  2215. private void replace() { mixin(S_TRACE);
  2216. auto c = _win.getDisplay().getFocusControl();
  2217. _replMode = true;
  2218. replaceImpl();
  2219. if (c) .forceFocus(_replace, false);
  2220. }
  2221. private void reset(bool removeColumns = true) { mixin(S_TRACE);
  2222. if (!_inUndo && !_inProc) { mixin(S_TRACE);
  2223. _undo.reset();
  2224. }
  2225. _result.removeAll();
  2226. _grepCount = -1;
  2227. if (removeColumns && _result.getColumnCount()) { mixin(S_TRACE);
  2228. foreach (column; _result.getColumns()) { mixin(S_TRACE);
  2229. column.dispose();
  2230. }
  2231. _result.setHeaderVisible(false);
  2232. }
  2233. if (_replMode) { mixin(S_TRACE);
  2234. _status.setText(_prop.msgs.replResultEmpty);
  2235. } else { mixin(S_TRACE);
  2236. _status.setText(_prop.msgs.searchResultEmpty);
  2237. }
  2238. _lastFind = null;
  2239. _comm.refreshToolBar();
  2240. }
  2241. @property
  2242. private bool canFind() { mixin(S_TRACE);
  2243. if (_inProc) return false;
  2244. if (!_tabf || _tabf.isDisposed()) return false;
  2245. auto sel = _tabf.getSelection();
  2246. if (!sel) return false;
  2247. if (sel is _tabText) { mixin(S_TRACE);
  2248. return _summ && _from.getText().length > 0;
  2249. } else if (sel is _tabID) { mixin(S_TRACE);
  2250. return _summ && canReplID();
  2251. } else if (sel is _tabPath) { mixin(S_TRACE);
  2252. return _summ && _fromPath.getText().length > 0;
  2253. } else if (sel is _tabContents) { mixin(S_TRACE);
  2254. return _summ !is null;
  2255. } else if (sel is _tabCoupon) { mixin(S_TRACE);
  2256. return _summ !is null;
  2257. } else if (sel is _tabUnuse) { mixin(S_TRACE);
  2258. return _summ !is null;
  2259. } else if (sel is _tabError) { mixin(S_TRACE);
  2260. return _summ !is null;
  2261. } else if (sel is _tabGrep) { mixin(S_TRACE);
  2262. return true;
  2263. } else assert (0);
  2264. }
  2265. @property
  2266. private bool canReplace() { mixin(S_TRACE);
  2267. if (_inProc) return false;
  2268. if (!_tabf || _tabf.isDisposed()) return false;
  2269. auto sel = _tabf.getSelection();
  2270. if (!sel) return false;
  2271. if (!_summ) return false;
  2272. return canFind && ((sel is _tabText && !_ignoreReturnCode.getSelection()) || sel is _tabID || sel is _tabPath);
  2273. }
  2274. private bool canCancel() { mixin(S_TRACE);
  2275. return _inProc;
  2276. }
  2277. private void replaceImpl() { mixin(S_TRACE);
  2278. if (_inProc) return;
  2279. _rUndo.length = 0;
  2280. _after.length = 0;
  2281. _notIgnoreCaseSel = _notIgnoreCase.getSelection();
  2282. _exactSel = _exact.getSelection();
  2283. _ignoreReturnCodeSel = _ignoreReturnCode.getSelection();
  2284. _summarySel = _summary.getSelection();
  2285. _msgSel = _msg.getSelection();
  2286. _cardNameSel = _cardName.getSelection();
  2287. _cardDescSel = _cardDesc.getSelection();
  2288. _eventSel = _event.getSelection();
  2289. _startSel = _start.getSelection();
  2290. _flagSel = _flag.getSelection();
  2291. _couponSel = _coupon.getSelection();
  2292. _gossipSel = _gossip.getSelection();
  2293. _endSel = _end.getSelection();
  2294. _areaSel = _area.getSelection();
  2295. _keyCodeSel = _keyCode.getSelection();
  2296. _fileSel = _file.getSelection();
  2297. _commentSel = _comment.getSelection();
  2298. _jptxSel = _jptx.getSelection();
  2299. _fromText = _from.getText();
  2300. _toText = _to.getText();
  2301. _flagDirOnRange = false;
  2302. foreach (itm; _range.getItems()) { mixin(S_TRACE);
  2303. if (itm.getChecked()) { mixin(S_TRACE);
  2304. auto root = cast(FlagDir) itm.getData();
  2305. if (root) { mixin(S_TRACE);
  2306. _flagDirOnRange = true;
  2307. break;
  2308. }
  2309. }
  2310. }
  2311. _cancel = false;
  2312. if (_tabf.getSelection() is _tabText) { mixin(S_TRACE);
  2313. replaceTextImpl();
  2314. } else if (_tabf.getSelection() is _tabID) { mixin(S_TRACE);
  2315. replaceIDImpl();
  2316. } else if (_tabf.getSelection() is _tabPath) { mixin(S_TRACE);
  2317. replacePathImpl();
  2318. } else if (_tabf.getSelection() is _tabContents) { mixin(S_TRACE);
  2319. searchContents();
  2320. } else if (_tabf.getSelection() is _tabCoupon) { mixin(S_TRACE);
  2321. searchCoupon();
  2322. } else if (_tabf.getSelection() is _tabUnuse) { mixin(S_TRACE);
  2323. searchUnuseImpl();
  2324. } else if (_tabf.getSelection() is _tabError) { mixin(S_TRACE);
  2325. searchErrorImpl();
  2326. } else if (_tabf.getSelection() is _tabGrep) { mixin(S_TRACE);
  2327. grepImpl();
  2328. } else assert (0);
  2329. }
  2330. private bool cautionReplace(string name1, string name2) { mixin(S_TRACE);
  2331. if (_replMode && _prop.var.etc.cautionBeforeReplace) { mixin(S_TRACE);
  2332. auto dlg = new MessageBox(_win, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
  2333. dlg.setMessage(.tryFormat(_prop.msgs.cautionOfReplace, name1, name2));
  2334. dlg.setText(_prop.msgs.dlgTitQuestion);
  2335. return SWT.YES == dlg.open();
  2336. }
  2337. return true;
  2338. }
  2339. private void after() { mixin(S_TRACE);
  2340. foreach (a; _after) a();
  2341. if (_after.length) { mixin(S_TRACE);
  2342. refContentText();
  2343. if (_replMode) _comm.replText.call();
  2344. }
  2345. if (_replMode && _rUndo.length) { mixin(S_TRACE);
  2346. _undo ~= new UndoRepl(_rUndo, false);
  2347. }
  2348. _rUndo = [];
  2349. _after = [];
  2350. _comm.refreshToolBar();
  2351. }
  2352. @property
  2353. private CWXPath[] searchRange() { mixin(S_TRACE);
  2354. CWXPath[] r;
  2355. void recurse(TreeItem itm) { mixin(S_TRACE);
  2356. auto data = cast(CWXPath)itm.getData();
  2357. if (data) r ~= data;
  2358. foreach (child; itm.getItems()) { mixin(S_TRACE);
  2359. if (child.getChecked()) { mixin(S_TRACE);
  2360. recurse(child);
  2361. }
  2362. }
  2363. }
  2364. foreach (itm; _range.getItems()) { mixin(S_TRACE);
  2365. if (itm.getChecked()) { mixin(S_TRACE);
  2366. recurse(itm);
  2367. }
  2368. }
  2369. return r;
  2370. }
  2371. private void searchAll(CWXPath path, ref uint count,
  2372. void delegate(CWXPath path, ref uint count) dlg) { mixin(S_TRACE);
  2373. if (cancel) return;
  2374. dlg(path, count);
  2375. // _range???????????????????
  2376. auto fdir = cast(FlagDir) path;
  2377. if (fdir) { mixin(S_TRACE);
  2378. foreach (o; fdir.flags) searchAll(o, count, dlg);
  2379. foreach (o; fdir.steps) searchAll(o, count, dlg);
  2380. foreach (o; fdir.subDirs) searchAll(o, count, dlg);
  2381. }
  2382. auto eto = cast(EventTreeOwner) path;
  2383. if (eto) { mixin(S_TRACE);
  2384. foreach (o; eto.trees) searchAll(o, count, dlg);
  2385. }
  2386. auto et = cast(EventTree) path;
  2387. if (et) { mixin(S_TRACE);
  2388. foreach (o; et.starts) searchAll(o, count, dlg);
  2389. }
  2390. auto c = cast(Content) path;
  2391. if (c) { mixin(S_TRACE);
  2392. foreach (o; c.backs) searchAll(o, count, dlg);
  2393. foreach (o; c.next) searchAll(o, count, dlg);
  2394. }
  2395. auto area = cast(Area) path;
  2396. if (area) { mixin(S_TRACE);
  2397. foreach (o; area.cards) searchAll(o, count, dlg);
  2398. foreach (o; area.backs) searchAll(o, count, dlg);
  2399. }
  2400. auto battle = cast(Battle) path;
  2401. if (battle) { mixin(S_TRACE);
  2402. foreach (o; battle.cards) searchAll(o, count, dlg);
  2403. }
  2404. auto mo = cast(MotionOwner) path;
  2405. if (mo) { mixin(S_TRACE);
  2406. foreach (m; mo.motions) { mixin(S_TRACE);
  2407. if (m.beast && 0 == m.beast.linkId) { mixin(S_TRACE);
  2408. searchAll(m.beast, count, dlg);
  2409. }
  2410. }
  2411. }
  2412. }
  2413. @property
  2414. private bool cancel() { mixin(S_TRACE);
  2415. return _cancel;
  2416. }
  2417. private void setResultStatus(uint count) { mixin(S_TRACE);
  2418. if (count > 0) { mixin(S_TRACE);
  2419. if (_replMode && _summ) { mixin(S_TRACE);
  2420. _summ.changed();
  2421. _comm.refUseCount.call();
  2422. }
  2423. }
  2424. _inProc = false;
  2425. resultRedraw(true);
  2426. refResultStatus(count, true);
  2427. }
  2428. private void refResultStatus(uint count, bool force) { mixin(S_TRACE);
  2429. if (!_prop.var.etc.searchResultRealtime) { mixin(S_TRACE);
  2430. if (!force && 0 != (count % _prop.var.etc.searchResultRefreshCount)) return;
  2431. }
  2432. _display.syncExec(new class Runnable {
  2433. void run() { mixin(S_TRACE);
  2434. if (!_win || _win.isDisposed()) return;
  2435. if (!_tabf.getSelection()) return;
  2436. string text;
  2437. string num = .formatNum(count);
  2438. if (_replMode) { mixin(S_TRACE);
  2439. string kind = _tabf.getSelection().getText();
  2440. text = .tryFormat(_prop.msgs.replResult, num, kind);
  2441. } else { mixin(S_TRACE);
  2442. if (_grepSumm) { mixin(S_TRACE);
  2443. text = .tryFormat(_prop.msgs.searchResultGrep2, _grepCount, num, _grepFile);
  2444. } else if (_grepFile.length) { mixin(S_TRACE);
  2445. text = .tryFormat(_prop.msgs.searchResultGrep1, _grepCount, num, _grepFile);
  2446. } else if (0 <= _grepCount) { mixin(S_TRACE);
  2447. string kind = _tabf.getSelection().getText();
  2448. text = .tryFormat(_prop.msgs.searchResultGrep3, _grepCount, num, kind);
  2449. } else { mixin(S_TRACE);
  2450. string kind = _tabf.getSelection().getText();
  2451. text = .tryFormat(_prop.msgs.searchResult, num, kind);
  2452. }
  2453. }
  2454. _status.setText(text);
  2455. }
  2456. });
  2457. }
  2458. @property
  2459. private bool[CWXPath] rangeTable() { mixin(S_TRACE);
  2460. bool[CWXPath] range;
  2461. void recurse(TreeItem itm) { mixin(S_TRACE);
  2462. auto data = cast(CWXPath)itm.getData();
  2463. if (data) range[data] = itm.getChecked();
  2464. foreach (cItm; itm.getItems()) { mixin(S_TRACE);
  2465. recurse(cItm);
  2466. }
  2467. }
  2468. foreach (itm; _range.getItems()) { mixin(S_TRACE);
  2469. recurse(itm);
  2470. }
  2471. return range;
  2472. }
  2473. private bool dec(CWXPath path, in bool[CWXPath] range) { mixin(S_TRACE);
  2474. assert (path);
  2475. auto p = path in range;
  2476. if (p) { mixin(S_TRACE);
  2477. return *p;
  2478. }
  2479. return dec(path.cwxParent, range);
  2480. }
  2481. private void replaceIDImpl2(ID)(ID from, ID to) { mixin(S_TRACE);
  2482. if (!_summ) return;
  2483. reset();
  2484. _lastFind = _tabf.getSelection();
  2485. _result.setHeaderVisible(true);
  2486. auto mainColumn = new TableColumn(_result, SWT.NONE);
  2487. mainColumn.setText(_prop.msgs.searchResultColumnMain);
  2488. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  2489. auto subColumn = new TableColumn(_result, SWT.NONE);
  2490. subColumn.setText(_prop.msgs.searchResultColumnParent);
  2491. saveColumnWidth!("prop.var.etc.searchResultColumnParent")(_prop, subColumn);
  2492. auto range = rangeTable;
  2493. auto uc = _summ.useCounter;
  2494. auto users = uc.values(from);
  2495. _inProc = true;
  2496. scope (exit) _inProc = false;
  2497. size_t count = 0;
  2498. auto cursors = setWaitCursors(_win);
  2499. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  2500. auto exit = new class Runnable {
  2501. override void run() { mixin(S_TRACE);
  2502. _inProc = false;
  2503. setResultStatus(count);
  2504. if (count) { mixin(S_TRACE);
  2505. _comm.replID.call();
  2506. }
  2507. resetCursors(cursors);
  2508. after();
  2509. }
  2510. };
  2511. scope (exit) _display.syncExec(exit);
  2512. try { mixin(S_TRACE);
  2513. foreach (u; users) { mixin(S_TRACE);
  2514. if (!dec(u.owner, range)) continue;
  2515. if (_replMode) { mixin(S_TRACE);
  2516. static if (is(ID:FlagId)) {
  2517. u.flag = cast(string)to;
  2518. storeID(u.owner, u, cast(string)from, cast(string)to, &u.flag);
  2519. } else static if (is(ID:StepId)) {
  2520. u.step = cast(string)to;
  2521. storeID(u.owner, u, cast(string)from, cast(string)to, &u.step);
  2522. } else static if (is(ID:CouponId)) {
  2523. u.coupon = cast(string)to;
  2524. storeID(u.owner, u, cast(string)from, cast(string)to, &u.coupon);
  2525. } else static if (is(ID:GossipId)) {
  2526. u.gossip = cast(string)to;
  2527. storeID(u.owner, u, cast(string)from, cast(string)to, &u.gossip);
  2528. } else static if (is(ID:CompleteStampId)) {
  2529. u.completeStamp = cast(string)to;
  2530. storeID(u.owner, u, cast(string)from, cast(string)to, &u.completeStamp);
  2531. } else static if (is(ID:KeyCodeId)) {
  2532. u.keyCode = cast(string)to;
  2533. storeID(u.owner, u, cast(string)from, cast(string)to, &u.keyCode);
  2534. // FIXME: CardWirth 1.60 ????
  2535. /+ } else static if (is(ID:CellNameId)) {
  2536. u.cellName = cast(string)to;
  2537. storeID(u.owner, u, cast(string)from, cast(string)to, &u.cellName);
  2538. +/ } else {
  2539. u.id = to;
  2540. storeID(u.owner, u, from, to, &u.id);
  2541. }
  2542. }
  2543. addResult(u.owner, count);
  2544. }
  2545. } catch (Throwable e) {
  2546. debugln(e);
  2547. }
  2548. });
  2549. thr.start();
  2550. }
  2551. private bool canReplID() {
  2552. if (idKindIsString) {
  2553. return _fromID.getText() != "";
  2554. } else {
  2555. return getID(_fromID, _fromIDVal, _fromIDTbl) !is 0;
  2556. }
  2557. }
  2558. private ulong getID(Combo combo, Spinner spn, ulong[int] tbl) { mixin(S_TRACE);
  2559. if (!_summ) return 0;
  2560. if (combo.getSelectionIndex() == 0) { mixin(S_TRACE);
  2561. return spn.getSelection();
  2562. } else { mixin(S_TRACE);
  2563. auto p = combo.getSelectionIndex() in tbl;
  2564. if (!p) return 0;
  2565. return *p;
  2566. }
  2567. }
  2568. private string getIDName(Combo combo, Spinner spn) { mixin(S_TRACE);
  2569. if (combo.getSelectionIndex() == 0) { mixin(S_TRACE);
  2570. auto id = spn.getSelection();
  2571. string objName = _idKind.getText();
  2572. return .tryFormat(_prop.msgs.idValue, id, objName);
  2573. } else { mixin(S_TRACE);
  2574. return .tryFormat(_prop.msgs.replaceValue, combo.getText());
  2575. }
  2576. }
  2577. private void replaceIDImpl() { mixin(S_TRACE);
  2578. if (!_summ) return;
  2579. int index = _idKind.getSelectionIndex();
  2580. if (idKindIsString) {
  2581. string from = _fromID.getText();
  2582. string to = _toID.getText();
  2583. if (from == "") return;
  2584. if (from == to) _replMode = false;
  2585. if (!cautionReplace(from, to)) return;
  2586. switch (_idKind.getSelectionIndex()) {
  2587. case ID_FLAG: replaceIDImpl2(toFlagId(from), toFlagId(to)); break;
  2588. case ID_STEP: replaceIDImpl2(toStepId(from), toStepId(to)); break;
  2589. case ID_COUPON: replaceIDImpl2(toCouponId(from), toCouponId(to)); break;
  2590. case ID_GOSSIP: replaceIDImpl2(toGossipId(from), toGossipId(to)); break;
  2591. case ID_COMPLETE_STAMP: replaceIDImpl2(toCompleteStampId(from), toCompleteStampId(to)); break;
  2592. case ID_KEY_CODE: replaceIDImpl2(toKeyCodeId(from), toKeyCodeId(to)); break;
  2593. // FIXME: CardWirth 1.60 ????
  2594. /+ case ID_CELL_NAME: replaceIDImpl2(toCellNameId(from), toCellNameId(to)); break;
  2595. +/ default: assert (0);
  2596. }
  2597. } else {
  2598. ulong from = getID(_fromID, _fromIDVal, _fromIDTbl);
  2599. ulong to = getID(_toID, _toIDVal, _toIDTbl);
  2600. if (0 == from) return;
  2601. if (from == to) _replMode = false;
  2602. if (!cautionReplace(getIDName(_fromID, _fromIDVal), getIDName(_toID, _toIDVal))) return;
  2603. switch (_idKind.getSelectionIndex()) {
  2604. case ID_AREA: replaceIDImpl2(toAreaId(from), toAreaId(to)); break;
  2605. case ID_BATTLE: replaceIDImpl2(toBattleId(from), toBattleId(to)); break;
  2606. case ID_PACKAGE: replaceIDImpl2(toPackageId(from), toPackageId(to)); break;
  2607. case ID_CAST: replaceIDImpl2(toCastId(from), toCastId(to)); break;
  2608. case ID_SKILL: replaceIDImpl2(toSkillId(from), toSkillId(to)); break;
  2609. case ID_ITEM: replaceIDImpl2(toItemId(from), toItemId(to)); break;
  2610. case ID_BEAST: replaceIDImpl2(toBeastId(from), toBeastId(to)); break;
  2611. case ID_INFO: replaceIDImpl2(toInfoId(from), toInfoId(to)); break;
  2612. default: assert (0);
  2613. }
  2614. }
  2615. }
  2616. private void replacePathImpl() { mixin(S_TRACE);
  2617. if (!_summ) return;
  2618. if (!_fromPath.getText().length) return;
  2619. string toText = _toPath.getText();
  2620. string fromName = .tryFormat(_prop.msgs.replaceValue, _fromPath.getText());
  2621. string toName = toText.length ? .tryFormat(_prop.msgs.replaceValue, toText) : _prop.msgs.emptyPath;
  2622. if (!cautionReplace(fromName, toName)) return;
  2623. auto from = toPathId(_fromPath.getText());
  2624. auto to = toPathId(_toPath.getText());
  2625. if (from == to) _replMode = false;
  2626. reset();
  2627. _lastFind = _tabf.getSelection();
  2628. new FullTableColumn(_result, SWT.NONE);
  2629. auto range = rangeTable;
  2630. auto uc = _summ.useCounter;
  2631. _inProc = true;
  2632. scope (exit) _inProc = false;
  2633. size_t count = 0;
  2634. auto cursors = setWaitCursors(_win);
  2635. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  2636. string[2][] fromTos;
  2637. auto exit = new class Runnable {
  2638. override void run() { mixin(S_TRACE);
  2639. _inProc = false;
  2640. setResultStatus(count);
  2641. if (count) { mixin(S_TRACE);
  2642. foreach (fromTo; std.algorithm.uniq(fromTos)) { mixin(S_TRACE);
  2643. _comm.replPath.call(fromTo[0], fromTo[1]);
  2644. }
  2645. }
  2646. _comm.updateJpy1Files();
  2647. resetCursors(cursors);
  2648. after();
  2649. }
  2650. };
  2651. scope (exit) _display.syncExec(exit);
  2652. try { mixin(S_TRACE);
  2653. auto wildcard = Wildcard((cast(string)from).encodePath(), 0 == filenameCharCmp('A', 'a'));
  2654. foreach (key; uc.path.keys) { mixin(S_TRACE);
  2655. if (wildcard.match((cast(string)key).encodePath())) { mixin(S_TRACE);
  2656. foreach (u; uc.path.values(key)) { mixin(S_TRACE);
  2657. if (!cast(Jpy1Sec)u && !dec(u.owner, range)) continue;
  2658. if (_replMode) { mixin(S_TRACE);
  2659. auto id = u.path;
  2660. u.path = cast(string)to;
  2661. storeID(u.owner, u, cast(string)id, cast(string)to, (string id) { mixin(S_TRACE);
  2662. u.path = id;
  2663. });
  2664. fromTos ~= [cast(string)id, cast(string)to];
  2665. }
  2666. addResult(u.owner, count);
  2667. }
  2668. }
  2669. }
  2670. } catch (Throwable e) {
  2671. debugln(e);
  2672. }
  2673. });
  2674. thr.start();
  2675. }
  2676. private void couponEditEnd(TableItem itm, int column, string text) { mixin(S_TRACE);
  2677. auto uc = _summ.useCounter;
  2678. if (itm.getImage() is _prop.images.couponNormal) { mixin(S_TRACE);
  2679. renameCoupon(itm, toCouponId(itm.getText()), toCouponId(text), uc.coupon);
  2680. _comm.refCoupons.call();
  2681. } else if (itm.getImage() is _prop.images.gossip) { mixin(S_TRACE);
  2682. renameCoupon(itm, toGossipId(itm.getText()), toGossipId(text), uc.gossip);
  2683. _comm.refGossips.call();
  2684. } else if (itm.getImage() is _prop.images.endScenario) { mixin(S_TRACE);
  2685. renameCoupon(itm, toCompleteStampId(itm.getText()), toCompleteStampId(text), uc.completeStamp);
  2686. _comm.refCompleteStamps.call();
  2687. } else if (itm.getImage() is _prop.images.keyCode) { mixin(S_TRACE);
  2688. renameCoupon(itm, toKeyCodeId(itm.getText()), toKeyCodeId(text), uc.keyCode);
  2689. _comm.refKeyCodes.call();
  2690. } else { mixin(S_TRACE);
  2691. // FIXME: CardWirth 1.60 ????
  2692. /+ renameCoupon(itm, toCellNameId(itm.getText()), toCellNameId(text), uc.cellName);
  2693. _comm.refCellNames.call();
  2694. +/ }
  2695. _comm.replText.call();
  2696. }
  2697. private bool canCouponEdit(TableItem itm, int column) { mixin(S_TRACE);
  2698. return _lastFind is _tabCoupon;
  2699. }
  2700. struct CouponParams {
  2701. Image image;
  2702. string name;
  2703. uint count;
  2704. }
  2705. class CouponUndo(User, KeyType) : Undo {
  2706. private CouponParams[] _results;
  2707. private KeyType _oldVal, _newVal;
  2708. private UCCont!(KeyType, User) _uc;
  2709. User[] users;
  2710. this (KeyType oldVal, KeyType newVal, UCCont!(KeyType, User) uc) { mixin(S_TRACE);
  2711. _oldVal = oldVal;
  2712. _newVal = newVal;
  2713. _uc = uc;
  2714. save();
  2715. }
  2716. private void save() { mixin(S_TRACE);
  2717. _results = [];
  2718. foreach (itm; _result.getItems()) { mixin(S_TRACE);
  2719. _results ~= CouponParams(itm.getImage(), itm.getText(), itm.getText(1).to!uint());
  2720. }
  2721. }
  2722. private void impl() { mixin(S_TRACE);
  2723. resultRedraw(false);
  2724. scope(exit) resultRedraw(true);
  2725. auto results = _results;
  2726. save();
  2727. foreach (u; users) { mixin(S_TRACE);
  2728. _uc.remove(_newVal, u);
  2729. u.change(_oldVal);
  2730. _uc.add(_oldVal, u);
  2731. }
  2732. foreach (i, r; results) { mixin(S_TRACE);
  2733. auto itm = i < _result.getItemCount() ? _result.getItem(i) : new TableItem(_result, SWT.NONE);
  2734. itm.setImage(r.image);
  2735. itm.setText(r.name);
  2736. itm.setText(1, r.count.text());
  2737. }
  2738. while (results.length < _result.getItemCount()) { mixin(S_TRACE);
  2739. _result.getItem(results.length).dispose();
  2740. }
  2741. .swap(_oldVal, _newVal);
  2742. refResultStatus(_result.getItemCount(), false);
  2743. _comm.replText.call();
  2744. _summ.changed();
  2745. }
  2746. void undo() { mixin(S_TRACE);
  2747. impl();
  2748. }
  2749. void redo() { mixin(S_TRACE);
  2750. impl();
  2751. }
  2752. void dispose() { }
  2753. }
  2754. private void renameCoupon(KeyType, UC)(TableItem itm, KeyType oldVal, KeyType newVal, UC uc) { mixin(S_TRACE);
  2755. if (cast(string)oldVal == cast(string)newVal) return;
  2756. if (cast(string)newVal == "") return;
  2757. _inProc = true;
  2758. scope (exit) _inProc = false;
  2759. auto rangeT = rangeTable;
  2760. auto undo = new CouponUndo!(ForeachType!(typeof(uc.values(oldVal))), KeyType)(oldVal, newVal, uc);
  2761. foreach (u; uc.values(oldVal)) { mixin(S_TRACE);
  2762. if (dec(u.owner, rangeT)) { mixin(S_TRACE);
  2763. uc.remove(oldVal, u);
  2764. u.change(newVal);
  2765. uc.add(newVal, u);
  2766. undo.users ~= u;
  2767. itm.setText(0, cast(string)newVal);
  2768. }
  2769. }
  2770. _undo ~= undo;
  2771. // ?????????????????????????
  2772. foreach (i, itm2; _result.getItems()) { mixin(S_TRACE);
  2773. if (itm is itm2) continue;
  2774. if (itm.getImage() !is itm2.getImage()) continue;
  2775. if (itm.getText() == itm2.getText()) { mixin(S_TRACE);
  2776. _result.select(i);
  2777. _result.showSelection();
  2778. itm2.setText(1, uc.get(newVal).text());
  2779. itm.dispose();
  2780. break;
  2781. }
  2782. }
  2783. _summ.changed();
  2784. }
  2785. private void searchCouponImpl(KeyType)(in KeyType[] keys, UseCounter uc, in bool[CWXPath] rangeT, Image delegate() image, ref uint count) { mixin(S_TRACE);
  2786. foreach (key; keys.dup.sort) { mixin(S_TRACE);
  2787. if (cancel) break;
  2788. uint use = 0;
  2789. foreach (u; uc.values(key)) { mixin(S_TRACE);
  2790. if (dec(u.owner, rangeT)) { mixin(S_TRACE);
  2791. use++;
  2792. }
  2793. }
  2794. if (use) { mixin(S_TRACE);
  2795. addResult(key, use, image, count);
  2796. }
  2797. }
  2798. }
  2799. private void searchCoupon() { mixin(S_TRACE);
  2800. if (!_summ) return;
  2801. uint count = 0;
  2802. reset();
  2803. _lastFind = _tabf.getSelection();
  2804. _result.setHeaderVisible(true);
  2805. auto mainColumn = new TableColumn(_result, SWT.NONE);
  2806. mainColumn.setText(_prop.msgs.searchResultColumnCoupon);
  2807. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  2808. auto subColumn = new TableColumn(_result, SWT.NONE);
  2809. subColumn.setText(_prop.msgs.searchResultColumnCouponCount);
  2810. saveColumnWidth!("prop.var.etc.searchResultColumnCouponCount")(_prop, subColumn);
  2811. bool cCouponSel = _cCoupon.getSelection();
  2812. bool cKeyCodeSel = _cKeyCode.getSelection();
  2813. bool cGossipSel = _cGossip.getSelection();
  2814. bool cEndSel = _cEnd.getSelection();
  2815. // FIXME: CardWirth 1.60 ????
  2816. /+ bool cCellName = _cCellName.getSelection();
  2817. +/
  2818. auto rangeT = rangeTable;
  2819. auto uc = _summ.useCounter;
  2820. void search() { mixin(S_TRACE);
  2821. if (cCouponSel) { mixin(S_TRACE);
  2822. searchCouponImpl(uc.coupon.keys, uc, rangeT, &_prop.images.couponNormal, count);
  2823. }
  2824. if (cGossipSel) { mixin(S_TRACE);
  2825. searchCouponImpl(uc.gossip.keys, uc, rangeT, &_prop.images.gossip, count);
  2826. }
  2827. if (cEndSel) { mixin(S_TRACE);
  2828. searchCouponImpl(uc.completeStamp.keys, uc, rangeT, &_prop.images.endScenario, count);
  2829. }
  2830. if (cKeyCodeSel) { mixin(S_TRACE);
  2831. searchCouponImpl(uc.keyCode.keys, uc, rangeT, &_prop.images.keyCode, count);
  2832. }
  2833. // FIXME: CardWirth 1.60 ????
  2834. /+ if (cCellName) { mixin(S_TRACE);
  2835. searchCouponImpl(uc.cellName.keys, uc, rangeT, &_prop.images.backs, count);
  2836. }
  2837. +/ }
  2838. _inProc = true;
  2839. _comm.refreshToolBar();
  2840. auto cursors = setWaitCursors(_win);
  2841. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  2842. auto exit = new class Runnable {
  2843. override void run() { mixin(S_TRACE);
  2844. _inProc = false;
  2845. setResultStatus(count);
  2846. resetCursors(cursors);
  2847. after();
  2848. }
  2849. };
  2850. scope (exit) _display.syncExec(exit);
  2851. try { mixin(S_TRACE);
  2852. search();
  2853. } catch (Throwable e) {
  2854. debugln(e);
  2855. }
  2856. });
  2857. thr.start();
  2858. }
  2859. private void searchContents() { mixin(S_TRACE);
  2860. if (!_summ) return;
  2861. uint count = 0;
  2862. reset();
  2863. _lastFind = _tabf.getSelection();
  2864. _result.setHeaderVisible(true);
  2865. auto mainColumn = new TableColumn(_result, SWT.NONE);
  2866. mainColumn.setText(_prop.msgs.searchResultColumnMain);
  2867. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  2868. auto subColumn = new TableColumn(_result, SWT.NONE);
  2869. subColumn.setText(_prop.msgs.searchResultColumnParent);
  2870. saveColumnWidth!("prop.var.etc.searchResultColumnParent")(_prop, subColumn);
  2871. auto range = searchRange;
  2872. _inProc = true;
  2873. _comm.refreshToolBar();
  2874. auto cursors = setWaitCursors(_win);
  2875. bool[CType] contents;
  2876. foreach (type; EnumMembers!CType) { mixin(S_TRACE);
  2877. // FIXME: CardWirth 1.60 ????
  2878. switch (type) {
  2879. case CType.MOVE_BG_IMAGE: /// ?????(CardWirth 1.60)?
  2880. case CType.REPLACE_BG_IMAGE: /// ????(CardWirth 1.60)?
  2881. case CType.LOSE_BG_IMAGE: /// ????(CardWirth 1.60)?
  2882. continue;
  2883. default:
  2884. break;
  2885. }
  2886. // FIXME: CardWirth 1.60 ????
  2887. contents[type] = _contents[type].getSelection();
  2888. }
  2889. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  2890. auto exit = new class Runnable {
  2891. override void run() { mixin(S_TRACE);
  2892. _inProc = false;
  2893. setResultStatus(count);
  2894. resetCursors(cursors);
  2895. after();
  2896. }
  2897. };
  2898. scope (exit) _display.syncExec(exit);
  2899. try { mixin(S_TRACE);
  2900. foreach (path; range) { mixin(S_TRACE);
  2901. searchAll(path, count, (CWXPath path, ref uint count) { mixin(S_TRACE);
  2902. if (cancel) return;
  2903. auto c = cast(Content) path;
  2904. if (!c) return;
  2905. assert (c.type in _contents);
  2906. if (!contents[c.type]) return;
  2907. addResult(path, count);
  2908. });
  2909. }
  2910. } catch (Throwable e) {
  2911. debugln(e);
  2912. }
  2913. });
  2914. thr.start();
  2915. }
  2916. private void searchUnuseImpl2(string ToId, T)(T[] all, ref uint count) { mixin(S_TRACE);
  2917. if (!_summ) return;
  2918. foreach (o; all) { mixin(S_TRACE);
  2919. if (cancel) break;
  2920. if (_summ.useCounter.get(mixin (ToId)) == 0) { mixin(S_TRACE);
  2921. addResult(o, count);
  2922. }
  2923. }
  2924. }
  2925. private void searchUnuseImpl() { mixin(S_TRACE);
  2926. if (!_summ) return;
  2927. _replMode = false;
  2928. uint count = 0;
  2929. reset();
  2930. _lastFind = _tabf.getSelection();
  2931. new FullTableColumn(_result, SWT.NONE);
  2932. auto range = searchRange();
  2933. bool unuseFlagSel = _unuseFlag.getSelection();
  2934. bool unuseStepSel = _unuseStep.getSelection();
  2935. bool unuseAreaSel = _unuseArea.getSelection();
  2936. bool unuseBattleSel = _unuseBattle.getSelection();
  2937. bool unusePackageSel = _unusePackage.getSelection();
  2938. bool unuseCastSel = _unuseCast.getSelection();
  2939. bool unuseSkillSel = _unuseSkill.getSelection();
  2940. bool unuseItemSel = _unuseItem.getSelection();
  2941. bool unuseBeastSel = _unuseBeast.getSelection();
  2942. bool unuseInfoSel = _unuseInfo.getSelection();
  2943. bool unuseStartSel = _unuseStart.getSelection();
  2944. bool unusePathSel = _unusePath.getSelection();
  2945. void search() { mixin(S_TRACE);
  2946. if (unuseFlagSel) { mixin(S_TRACE);
  2947. searchUnuseImpl2!("toFlagId(o.path)")(_summ.flagDirRoot.allFlags, count);
  2948. }
  2949. if (unuseStepSel) { mixin(S_TRACE);
  2950. searchUnuseImpl2!("toStepId(o.path)")(_summ.flagDirRoot.allSteps, count);
  2951. }
  2952. if (unuseAreaSel) { mixin(S_TRACE);
  2953. searchUnuseImpl2!("toAreaId(o.id)")(_summ.areas, count);
  2954. }
  2955. if (unuseBattleSel) { mixin(S_TRACE);
  2956. searchUnuseImpl2!("toBattleId(o.id)")(_summ.battles, count);
  2957. }
  2958. if (unusePackageSel) { mixin(S_TRACE);
  2959. searchUnuseImpl2!("toPackageId(o.id)")(_summ.packages, count);
  2960. }
  2961. if (unuseCastSel) { mixin(S_TRACE);
  2962. searchUnuseImpl2!("toCastId(o.id)")(_summ.casts, count);
  2963. }
  2964. if (unuseSkillSel) { mixin(S_TRACE);
  2965. searchUnuseImpl2!("toSkillId(o.id)")(_summ.skills, count);
  2966. }
  2967. if (unuseItemSel) { mixin(S_TRACE);
  2968. searchUnuseImpl2!("toItemId(o.id)")(_summ.items, count);
  2969. }
  2970. if (unuseBeastSel) { mixin(S_TRACE);
  2971. searchUnuseImpl2!("toBeastId(o.id)")(_summ.beasts, count);
  2972. }
  2973. if (unuseInfoSel) { mixin(S_TRACE);
  2974. searchUnuseImpl2!("toInfoId(o.id)")(_summ.infos, count);
  2975. }
  2976. if (unuseStartSel) { mixin(S_TRACE);
  2977. foreach (path; range) { mixin(S_TRACE);
  2978. searchAll(path, count, (CWXPath path, ref uint count) { mixin(S_TRACE);
  2979. if (cancel) return;
  2980. auto et = cast(EventTree) path;
  2981. if (et) { mixin(S_TRACE);
  2982. foreach (s; et.starts[1 .. $]) { mixin(S_TRACE);
  2983. if (et.startUseCounter.get(toStartId(s.name)) == 0) { mixin(S_TRACE);
  2984. addResult(s, count);
  2985. }
  2986. }
  2987. }
  2988. });
  2989. }
  2990. }
  2991. if (unusePathSel) { mixin(S_TRACE);
  2992. auto files = _summ.notUsedFiles(_comm.skin, _prop.var.etc.ignorePaths, _prop.var.etc.logicalSort);
  2993. foreach (file; files) { mixin(S_TRACE);
  2994. if (cancel) break;
  2995. addResult(encodePath(file), count);
  2996. }
  2997. }
  2998. }
  2999. _inProc = true;
  3000. _comm.refreshToolBar();
  3001. auto cursors = setWaitCursors(_win);
  3002. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  3003. auto exit = new class Runnable {
  3004. override void run() { mixin(S_TRACE);
  3005. _inProc = false;
  3006. setResultStatus(count);
  3007. resetCursors(cursors);
  3008. after();
  3009. }
  3010. };
  3011. scope (exit) _display.syncExec(exit);
  3012. try { mixin(S_TRACE);
  3013. search();
  3014. } catch (Throwable e) {
  3015. debugln(e);
  3016. }
  3017. });
  3018. thr.start();
  3019. }
  3020. private void searchErrorImpl() { mixin(S_TRACE);
  3021. if (!_summ) return;
  3022. uint count = 0;
  3023. auto froot = _summ.flagDirRoot;
  3024. auto sPath = _summ.scenarioPath;
  3025. auto skin = _comm.skin;
  3026. auto targVer = _prop.var.etc.targetVersion;
  3027. reset();
  3028. _lastFind = _tabf.getSelection();
  3029. _result.setHeaderVisible(true);
  3030. auto mainColumn = new TableColumn(_result, SWT.NONE);
  3031. mainColumn.setText(_prop.msgs.searchResultColumnError);
  3032. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  3033. auto subColumn = new TableColumn(_result, SWT.NONE);
  3034. subColumn.setText(_prop.msgs.searchResultColumnParent);
  3035. saveColumnWidth!("prop.var.etc.searchResultColumnParent")(_prop, subColumn);
  3036. auto descColumn = new TableColumn(_result, SWT.NONE);
  3037. descColumn.setText(_prop.msgs.searchResultColumnErrorDesc);
  3038. saveColumnWidth!("prop.var.etc.searchResultColumnErrorDesc")(_prop, descColumn);
  3039. auto range = searchRange;
  3040. void search(CWXPath path) { mixin(S_TRACE);
  3041. searchAll(path, count, (CWXPath path, ref uint count) { mixin(S_TRACE);
  3042. if (cancel) return;
  3043. auto warnings = .warnings(_prop.parent, skin, _summ, path, targVer);
  3044. foreach (warning; warnings) { mixin(S_TRACE);
  3045. addResult(path, count, warning);
  3046. }
  3047. });
  3048. }
  3049. void searchFileErrors() { mixin(S_TRACE);
  3050. string sPath = _summ.scenarioPath;
  3051. string[string] digests;
  3052. void recurse(string file) { mixin(S_TRACE);
  3053. try { mixin(S_TRACE);
  3054. bool dir = .isDir(file);
  3055. if (_summ.isSystemFile(file, dir)) return;
  3056. if (containsPath(_prop.var.etc.ignorePaths, file.baseName())) return;
  3057. if (dir) { mixin(S_TRACE);
  3058. foreach (string sub; clistdir(file)) { mixin(S_TRACE);
  3059. recurse(file.buildPath(sub));
  3060. }
  3061. } else { mixin(S_TRACE);
  3062. auto size = file.getSize();
  3063. if (!size) { mixin(S_TRACE);
  3064. addResult(abs2rel(file, sPath), count, _prop.msgs.searchErrorEmptyFile);
  3065. return;
  3066. }
  3067. auto digest = file.fileToMD5Digest();
  3068. if (!digest.length) return;
  3069. digest = .format("%s-%s", digest, size);
  3070. auto p = digest in digests;
  3071. if (!p) { mixin(S_TRACE);
  3072. digests[digest] = file;
  3073. return;
  3074. }
  3075. addResult(abs2rel(file, sPath), count, .tryFormat(_prop.msgs.searchErrorDupFile, abs2rel(*p, sPath)));
  3076. }
  3077. } catch (Exception e) {
  3078. debugln(e);
  3079. }
  3080. }
  3081. recurse(sPath);
  3082. }
  3083. _inProc = true;
  3084. _comm.refreshToolBar();
  3085. auto cursors = setWaitCursors(_win);
  3086. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  3087. auto exit = new class Runnable {
  3088. override void run() { mixin(S_TRACE);
  3089. _inProc = false;
  3090. setResultStatus(count);
  3091. resetCursors(cursors);
  3092. after();
  3093. }
  3094. };
  3095. scope (exit) _display.syncExec(exit);
  3096. try { mixin(S_TRACE);
  3097. foreach (path; range) { mixin(S_TRACE);
  3098. search(path);
  3099. }
  3100. searchFileErrors();
  3101. } catch (Throwable e) {
  3102. debugln(e);
  3103. }
  3104. });
  3105. thr.start();
  3106. }
  3107. private void replaceTextImpl(CWXPath c, ref size_t count) { mixin(S_TRACE);
  3108. if (cancel) return;
  3109. bool oldIgnoreMod = ignoreMod;
  3110. ignoreMod = true;
  3111. scope (exit) ignoreMod = oldIgnoreMod;
  3112. size_t dmy = 0;
  3113. auto summ = cast(Summary) c;
  3114. if (summ) { mixin(S_TRACE);
  3115. bool sr = false;
  3116. Undo[] uArr;
  3117. if (_summarySel) { mixin(S_TRACE);
  3118. sr |= repl(null, summ.scenarioName, &summ.scenarioName, count, uArr);
  3119. sr |= repl(null, summ.desc, &summ.desc, count, uArr);
  3120. }
  3121. if (_couponSel) { mixin(S_TRACE);
  3122. sr |= replRqCoupons(null, summ, count, uArr);
  3123. }
  3124. if (sr) { mixin(S_TRACE);
  3125. if (_replMode) store(summ, uArr);
  3126. addResult(summ, dmy);
  3127. }
  3128. }
  3129. auto cc = cast(CastCard) c;
  3130. if (cc) { mixin(S_TRACE);
  3131. Undo[] uArr;
  3132. bool r = replCard!(CastCard)(null, cc, count, uArr);
  3133. if (_couponSel) { mixin(S_TRACE);
  3134. Coupon[] coupons = null;
  3135. if (_replMode) coupons = new Coupon[cc.coupons.length];
  3136. foreach (i, cp; cc.coupons) { mixin(S_TRACE);
  3137. Coupon cp2 = null;
  3138. r |= repl(null, cp.name,
  3139. (string t) {cp2 = new Coupon(t, cp.value);}, count, uArr);
  3140. if (_replMode) coupons[i] = cp2 ? cp2 : new Coupon(cp);
  3141. }
  3142. if (_replMode) cc.coupons = coupons;
  3143. }
  3144. if (r) { mixin(S_TRACE);
  3145. if (_replMode) store(cc, uArr);
  3146. addResult(cc, dmy);
  3147. }
  3148. }
  3149. Undo[] nArr;
  3150. auto eff = cast(EffectCard) c;
  3151. if (eff) { mixin(S_TRACE);
  3152. replCard(eff, eff, count, nArr);
  3153. }
  3154. auto info = cast(InfoCard) c;
  3155. if (info) { mixin(S_TRACE);
  3156. replCard(info, info, count, nArr);
  3157. }
  3158. auto a = cast(AbstractArea) c;
  3159. if (a) { mixin(S_TRACE);
  3160. if (_areaSel) { mixin(S_TRACE);
  3161. repl(a, a.name, &a.name, count, nArr);
  3162. }
  3163. }
  3164. auto menu = cast(MenuCard) c;
  3165. if (menu) { mixin(S_TRACE);
  3166. replCard(menu, menu, count, nArr);
  3167. }
  3168. auto back = cast(BgImage) c;
  3169. if (back) { mixin(S_TRACE);
  3170. replBgImage(back, back, count, nArr);
  3171. }
  3172. auto f = cast(Flag) c;
  3173. if (f && _flagSel) { mixin(S_TRACE);
  3174. Undo[] uArr = new Undo[0];
  3175. bool r = replFlagName!Flag(f.parent, f, count, uArr);
  3176. r |= repl(null, f.on, &f.on, count, uArr);
  3177. r |= repl(null, f.off, &f.off, count, uArr);
  3178. if (r) { mixin(S_TRACE);
  3179. if (_replMode) store(f, uArr);
  3180. addResult(f, dmy);
  3181. }
  3182. }
  3183. auto s = cast(Step) c;
  3184. if (s && _flagSel) { mixin(S_TRACE);
  3185. Undo[] uArr;
  3186. bool r = replFlagName!Step(s.parent, s, count, uArr);
  3187. foreach (i, v; s.values) { mixin(S_TRACE);
  3188. r |= repl(null, v, (string t) {s.setValue(i, t);}, count, uArr);
  3189. }
  3190. if (r) { mixin(S_TRACE);
  3191. if (_replMode) store(s, uArr);
  3192. addResult(s, dmy);
  3193. }
  3194. }
  3195. auto et = cast(EventTree) c;
  3196. if (et) { mixin(S_TRACE);
  3197. replFKeyCode(et, et, count, nArr);
  3198. }
  3199. auto content = cast(Content) c;
  3200. if (content) { mixin(S_TRACE);
  3201. replContent(content, count);
  3202. }
  3203. }
  3204. private void initText(string from, string to) { mixin(S_TRACE);
  3205. if (_useRegex.getSelection()) { mixin(S_TRACE);
  3206. try { mixin(S_TRACE);
  3207. _regex = .regex!(dstring)(toUTF32(from), _notIgnoreCase.getSelection() ? "gm" : "gim");
  3208. _regexTarg = true;
  3209. _toTemp = toUTF32(to);
  3210. } catch (Exception e) {
  3211. MessageBox.showWarning
  3212. (_prop.msgs.regexError ~ "\n" ~ e.msg,
  3213. _prop.msgs.dlgTitWarning, _win);
  3214. return;
  3215. }
  3216. } else if (_useWildcard.getSelection()) { mixin(S_TRACE);
  3217. _wildcard = Wildcard(from, !_notIgnoreCase.getSelection());
  3218. } else { mixin(S_TRACE);
  3219. if (from == to) _replMode = false;
  3220. }
  3221. }
  3222. private void exitText() { mixin(S_TRACE);
  3223. if (!_win || _win.isDisposed()) return;
  3224. _wildcard = null;
  3225. _regex = typeof(_regex).init;
  3226. _regexTarg = false;
  3227. _toTemp = ""d;
  3228. }
  3229. private static void addHist(Combo combo, void delegate(string[]) set,
  3230. string[] delegate() get, int max, string text) { mixin(S_TRACE);
  3231. if (text.length) { mixin(S_TRACE);
  3232. string[] list = get();
  3233. if (.contains(list, text)) { mixin(S_TRACE);
  3234. list = cwx.utils.remove(list, text);
  3235. }
  3236. list = [text] ~ list;
  3237. if (list.length > max) { mixin(S_TRACE);
  3238. list = list[0 .. $ - 1];
  3239. }
  3240. set(list);
  3241. setComboItems(combo, list);
  3242. combo.select(0);
  3243. }
  3244. }
  3245. private void replaceTextImpl() { mixin(S_TRACE);
  3246. if (!_summ) return;
  3247. string from = _from.getText();
  3248. string to = _to.getText();
  3249. if (!from.length) return;
  3250. string fromName = from.length ? .tryFormat(_prop.msgs.replaceValue, from) : _prop.msgs.emptyText;
  3251. string toName = to.length ? .tryFormat(_prop.msgs.replaceValue, to) : _prop.msgs.emptyText;
  3252. if (!cautionReplace(fromName, toName)) return;
  3253. initText(from, to);
  3254. size_t count = 0;
  3255. reset();
  3256. _lastFind = _tabf.getSelection();
  3257. _result.setHeaderVisible(true);
  3258. auto mainColumn = new TableColumn(_result, SWT.NONE);
  3259. mainColumn.setText(_prop.msgs.searchResultColumnMain);
  3260. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  3261. auto subColumn = new TableColumn(_result, SWT.NONE);
  3262. subColumn.setText(_prop.msgs.searchResultColumnParent);
  3263. saveColumnWidth!("prop.var.etc.searchResultColumnParent")(_prop, subColumn);
  3264. auto range = searchRange;
  3265. _inProc = true;
  3266. _comm.refreshToolBar();
  3267. addHist(_from, (string[] s) {_prop.var.etc.searchHistories = s;},
  3268. {return _prop.var.etc.searchHistories.dup;},
  3269. _prop.var.etc.searchHistoryMax, from);
  3270. if (_replMode) { mixin(S_TRACE);
  3271. addHist(_to, (string[] s) {_prop.var.etc.replaceHistories = s;},
  3272. {return _prop.var.etc.replaceHistories.dup;},
  3273. _prop.var.etc.searchHistoryMax, to);
  3274. }
  3275. _comm.refSearchHistories.call(this);
  3276. void search() { mixin(S_TRACE);
  3277. foreach (path; range) { mixin(S_TRACE);
  3278. searchAll(path, count, &replaceTextImpl);
  3279. }
  3280. if (_jptxSel) { mixin(S_TRACE);
  3281. foreach (string file; .dirEntries(_summ.scenarioPath, SpanMode.depth, false)) { mixin(S_TRACE);
  3282. if (cancel) break;
  3283. if (cfnmatch(.extension(file), ".jptx")) { mixin(S_TRACE);
  3284. try { mixin(S_TRACE);
  3285. bool isSJIS;
  3286. auto errInfo = new EffectBoosterError;
  3287. string value = readJPYFile(file, _prop.parent, errInfo, isSJIS);
  3288. auto jText = jptxText(value);
  3289. Undo[] uArr;
  3290. string file2 = file;
  3291. bool r = repl(null, jText, (string jText) { mixin(S_TRACE);
  3292. string value = jptxText(value, jText);
  3293. try { mixin(S_TRACE);
  3294. writeJPYFile(file2, value, isSJIS);
  3295. } catch (Exception e) {
  3296. debugln(e);
  3297. }
  3298. }, count, uArr, true);
  3299. if (r) { mixin(S_TRACE);
  3300. file = abs2rel(file, _summ.scenarioPath);
  3301. size_t dmy = 0;
  3302. addResult(file, dmy);
  3303. store(file, uArr);
  3304. }
  3305. } catch (Exception e) {
  3306. debugln(e);
  3307. }
  3308. }
  3309. }
  3310. }
  3311. }
  3312. auto cursors = setWaitCursors(_win);
  3313. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  3314. auto exit = new class Runnable {
  3315. override void run() { mixin(S_TRACE);
  3316. _inProc = false;
  3317. setResultStatus(count);
  3318. exitText();
  3319. if (_replMode && !_after.length) _comm.replText.call();
  3320. resetCursors(cursors);
  3321. after();
  3322. }
  3323. };
  3324. scope (exit) _display.syncExec(exit);
  3325. try { mixin(S_TRACE);
  3326. search();
  3327. } catch (Throwable e) {
  3328. debugln(e);
  3329. }
  3330. });
  3331. thr.start();
  3332. }
  3333. private void grepImpl() { mixin(S_TRACE);
  3334. string from = _from.getText();
  3335. auto dirBase = _grepDir.getText();
  3336. auto dir = _prop.toAppAbs(dirBase);
  3337. initText(from, "");
  3338. _replMode = false;
  3339. size_t count = 0;
  3340. reset();
  3341. _grepCount = 0;
  3342. _lastFind = _tabf.getSelection();
  3343. _result.setHeaderVisible(true);
  3344. auto mainColumn = new TableColumn(_result, SWT.NONE);
  3345. mainColumn.setText(_prop.msgs.searchResultColumnMain);
  3346. saveColumnWidth!("prop.var.etc.searchResultColumnMain")(_prop, mainColumn);
  3347. auto subColumn = new TableColumn(_result, SWT.NONE);
  3348. subColumn.setText(_prop.msgs.searchResultColumnParent);
  3349. saveColumnWidth!("prop.var.etc.searchResultColumnParent")(_prop, subColumn);
  3350. auto scColumn = new TableColumn(_result, SWT.NONE);
  3351. scColumn.setText(_prop.msgs.searchResultColumnScenario);
  3352. saveColumnWidth!("prop.var.etc.searchResultColumnScenario")(_prop, scColumn);
  3353. if (!dir.exists()) return;
  3354. LoadOption opt;
  3355. opt.doubleIO = _prop.var.etc.doubleIO;
  3356. opt.cardOnly = false;
  3357. opt.textOnly = true;
  3358. opt.expandXMLs = false;
  3359. opt.summaryOnly = true;
  3360. foreach (b; _noSummText) { mixin(S_TRACE);
  3361. if (b.getSelection()) { mixin(S_TRACE);
  3362. opt.summaryOnly = false;
  3363. break;
  3364. }
  3365. }
  3366. if (0 == from.length) { mixin(S_TRACE);
  3367. opt.summaryOnly = true;
  3368. }
  3369. bool subDir = _grepSubDir.getSelection();
  3370. void findSumm(string summFile) { mixin(S_TRACE);
  3371. if (cancel) return;
  3372. _grepFile = summFile;
  3373. scope (exit) _grepFile = "";
  3374. refResultStatus(count, true);
  3375. auto summ = Summary.loadScenarioFromFile(_prop.parent, opt, summFile, _prop.tempPath);
  3376. if (!summ) return;
  3377. _grepSumm = summ;
  3378. _grepCount++;
  3379. scope (exit) {
  3380. summ.delTemp();
  3381. _grepSkin = null;
  3382. destroy(summ);
  3383. _grepSumm = null;
  3384. core.memory.GC.collect();
  3385. core.memory.GC.minimize();
  3386. }
  3387. if (!_fromText.length) { mixin(S_TRACE);
  3388. addResult(summ, count);
  3389. return;
  3390. }
  3391. refResultStatus(count, true);
  3392. auto range = rangeTree(summ);
  3393. foreach (path; range) { mixin(S_TRACE);
  3394. if (cancel) return;
  3395. searchAll(path, count, &replaceTextImpl);
  3396. }
  3397. if (_jptxSel) { mixin(S_TRACE);
  3398. foreach (string file; .dirEntries(summ.scenarioPath, SpanMode.depth, false)) { mixin(S_TRACE);
  3399. if (cancel) break;
  3400. if (cfnmatch(.extension(file), ".jptx")) { mixin(S_TRACE);
  3401. bool isSJIS;
  3402. auto errInfo = new EffectBoosterError;
  3403. try { mixin(S_TRACE);
  3404. string value = readJPYFile(file, _prop.parent, errInfo, isSJIS);
  3405. auto jText = jptxText(value);
  3406. Undo[] uArr;
  3407. string file2 = file;
  3408. bool r = repl(null, jText, null, count, uArr, true);
  3409. if (r) { mixin(S_TRACE);
  3410. file = abs2rel(file, summ.scenarioPath);
  3411. size_t dmy = 0;
  3412. addResult(file, dmy);
  3413. }
  3414. } catch (Exception e) {
  3415. debugln(e);
  3416. }
  3417. }
  3418. }
  3419. }
  3420. refResultStatus(count, true);
  3421. }
  3422. void recurse(string dir, uint rec) { mixin(S_TRACE);
  3423. if (cancel) return;
  3424. if (dir.buildPath("Summary.xml").exists() || dir.buildPath("Summary.wsm").exists()) { mixin(S_TRACE);
  3425. try { mixin(S_TRACE);
  3426. findSumm(dir);
  3427. } catch (Exception e) {
  3428. debugln(e);
  3429. }
  3430. }
  3431. foreach (file; clistdir(dir)) { mixin(S_TRACE);
  3432. if (cancel) break;
  3433. try { mixin(S_TRACE);
  3434. file = dir.buildPath(file);
  3435. if (file.isDir()) { mixin(S_TRACE);
  3436. if (subDir || 0 == rec) recurse(file, rec + 1);
  3437. } else { mixin(S_TRACE);
  3438. auto ext = file.extension();
  3439. if (cfnmatch(ext, ".wsn") || cfnmatch(ext, ".zip") || (canUncab && cfnmatch(ext, ".cab"))) { mixin(S_TRACE);
  3440. findSumm(file);
  3441. }
  3442. }
  3443. } catch (Exception e) {
  3444. debugln(e);
  3445. }
  3446. }
  3447. }
  3448. _inProc = true;
  3449. _inGrep = true;
  3450. _comm.refreshToolBar();
  3451. addHist(_from, (string[] s) {_prop.var.etc.searchHistories = s;},
  3452. {return _prop.var.etc.searchHistories.dup;},
  3453. _prop.var.etc.searchHistoryMax, from);
  3454. addHist(_grepDir, (string[] s) {_prop.var.etc.grepDirHistories = s;},
  3455. {return _prop.var.etc.grepDirHistories.dup;},
  3456. _prop.var.etc.searchHistoryMax, dirBase);
  3457. _comm.refSearchHistories.call(this);
  3458. auto cursors = setWaitCursors(_win);
  3459. auto thr = new core.thread.Thread({ mixin(S_TRACE);
  3460. auto exit = new class Runnable {
  3461. override void run() { mixin(S_TRACE);
  3462. _inProc = false;
  3463. _inGrep = false;
  3464. exitText();
  3465. setResultStatus(count);
  3466. resetCursors(cursors);
  3467. after();
  3468. }
  3469. };
  3470. scope (exit) _display.syncExec(exit);
  3471. try { mixin(S_TRACE);
  3472. recurse(dir, 0);
  3473. } catch (Throwable e) {
  3474. debugln(e);
  3475. }
  3476. });
  3477. thr.start();
  3478. }
  3479. private void refSearchHistories(Object sender) { mixin(S_TRACE);
  3480. if (sender is this) return;
  3481. updateFromHistory();
  3482. updateToHistory();
  3483. setComboItems(_grepDir, _prop.var.etc.grepDirHistories.dup);
  3484. }
  3485. private void updateFromHistory() {
  3486. string ft = _from.getText();
  3487. _from.removeAll();
  3488. foreach (hist; _prop.var.etc.searchHistories) {
  3489. if (!_fromIncSearch.match(hist)) continue;
  3490. _from.add(hist);
  3491. }
  3492. _from.setText(ft);
  3493. }
  3494. private void updateToHistory() {
  3495. string tt = _to.getText();
  3496. _to.removeAll();
  3497. foreach (hist; _prop.var.etc.replaceHistories) {
  3498. if (!_toIncSearch.match(hist)) continue;
  3499. _to.add(hist);
  3500. }
  3501. _to.setText(tt);
  3502. }
  3503. private Regex!(dchar) _regex;
  3504. private bool _regexTarg = false;
  3505. private Wildcard _wildcard = null;
  3506. private dstring _toTemp = ""d;
  3507. private string fTextRepl(string s) { mixin(S_TRACE);
  3508. if (_regexTarg) { mixin(S_TRACE);
  3509. return toUTF8(std.regex.replace(toUTF32(s), _regex, _toTemp));
  3510. }
  3511. string to = _toText;
  3512. if (_wildcard) { mixin(S_TRACE);
  3513. return _wildcard.replace(s, to);
  3514. }
  3515. string from = _fromText;
  3516. if (_notIgnoreCaseSel) { mixin(S_TRACE);
  3517. if (_exactSel) { mixin(S_TRACE);
  3518. return 0 == cmp(s, from) ? to : from;
  3519. } else { mixin(S_TRACE);
  3520. return .replace(s, from, to);
  3521. }
  3522. } else { mixin(S_TRACE);
  3523. if (_exactSel) { mixin(S_TRACE);
  3524. return 0 == icmp(s, from) ? to : from;
  3525. } else { mixin(S_TRACE);
  3526. return .ireplace(s, from, to);
  3527. }
  3528. }
  3529. }
  3530. private size_t fTextCount(string s) { mixin(S_TRACE);
  3531. if (_ignoreReturnCodeSel) s = .singleLine(s);
  3532. if (_regexTarg) { mixin(S_TRACE);
  3533. size_t c = 0;
  3534. try { mixin(S_TRACE);
  3535. foreach (m; std.regex.match(toUTF32(s), _regex)) { mixin(S_TRACE);
  3536. c++;
  3537. }
  3538. } catch (Throwable e) {
  3539. debugln(_fromText, " -> ", s);
  3540. throw e;
  3541. }
  3542. return c;
  3543. }
  3544. if (_wildcard) { mixin(S_TRACE);
  3545. return _wildcard.count(s);
  3546. }
  3547. string from = _fromText;
  3548. if (_notIgnoreCaseSel) { mixin(S_TRACE);
  3549. if (_exactSel) { mixin(S_TRACE);
  3550. return 0 == cmp(s, from) ? 1 : 0;
  3551. } else { mixin(S_TRACE);
  3552. return std.algorithm.count(s, from);
  3553. }
  3554. } else { mixin(S_TRACE);
  3555. if (_exactSel) { mixin(S_TRACE);
  3556. return 0 == icmp(s, from) ? 1 : 0;
  3557. } else { mixin(S_TRACE);
  3558. return .icount(s, from);
  3559. }
  3560. }
  3561. }
  3562. private void exit() { mixin(S_TRACE);
  3563. _win.close();
  3564. }
  3565. private bool _replMode = false;
  3566. private bool canOpenPath() { mixin(S_TRACE);
  3567. auto sels = _result.getSelection();
  3568. if (!sels.length) return false;
  3569. foreach (itm; sels) { mixin(S_TRACE);
  3570. auto d = itm.getData();
  3571. if (cast(CWXPathString) d !is null || cast(FilePathString) d !is null) { mixin(S_TRACE);
  3572. return true;
  3573. }
  3574. }
  3575. return false;
  3576. }
  3577. private void openPath() { mixin(S_TRACE);
  3578. auto i = _result.getSelectionIndex();
  3579. if (-1 == i) return;
  3580. foreach (itm; [_result.getItem(i)] ~ _result.getItems()) { mixin(S_TRACE);
  3581. auto d = itm.getData();
  3582. auto rp = cast(CWXPathString) d;
  3583. if (rp) { mixin(S_TRACE);
  3584. auto path = rp.array;
  3585. if (_prop.var.etc.searchOpenDialog) { mixin(S_TRACE);
  3586. path = cpaddattr(path, "opendialog");
  3587. }
  3588. if (rp.scPath !is null) { mixin(S_TRACE);
  3589. exec(_prop.parent.appPath ~ " " ~ rp.scPath ~ " " ~ path);
  3590. return;
  3591. }
  3592. if (!_summ) return;
  3593. try { mixin(S_TRACE);
  3594. if (_comm.openCWXPath(path, false)) { mixin(S_TRACE);
  3595. if (!_prop.var.etc.searchOpenDialog) _win.setActive();
  3596. return;
  3597. }
  3598. } catch (Exception e) {
  3599. debugln(e);
  3600. }
  3601. MessageBox.showWarning(.tryFormat(_prop.msgs.cwxPathOpenError, path), _prop.msgs.dlgTitWarning, _win);
  3602. return;
  3603. }
  3604. if (!_summ) return;
  3605. auto p = cast(FilePathString) d;
  3606. if (p) { mixin(S_TRACE);
  3607. auto path = nabs(std.path.buildPath(_summ.scenarioPath, p.array));
  3608. if (p.scPath !is null) { mixin(S_TRACE);
  3609. exec(_prop.parent.appPath ~ " -selectfile " ~ p.array ~ " " ~ p.scPath);
  3610. return;
  3611. }
  3612. if (_comm.openFilePath(path, false)) { mixin(S_TRACE);
  3613. _win.setActive();
  3614. return;
  3615. }
  3616. MessageBox.showWarning(.tryFormat(_prop.msgs.filePathOpenError, path), _prop.msgs.dlgTitWarning, _win);
  3617. return;
  3618. }
  3619. }
  3620. }
  3621. Image fimage(string file, Skin skin) { mixin(S_TRACE);
  3622. return .fimage(_prop, file, skin);
  3623. }
  3624. private void copyResult() { mixin(S_TRACE);
  3625. string[] t;
  3626. foreach (itm; _result.getSelection()) { mixin(S_TRACE);
  3627. string[] line;
  3628. foreach (i; 0 .. _result.getColumnCount()) { mixin(S_TRACE);
  3629. line ~= itm.getText(i).replace("\n", .newline);
  3630. }
  3631. t ~= std.string.join(line, "\t");
  3632. }
  3633. if (!t.length) return;
  3634. auto text = new ArrayWrapperString(std.string.join(t, .newline));
  3635. _comm.clipboard.setContents([text], [TextTransfer.getInstance()]);
  3636. _comm.refreshToolBar();
  3637. }
  3638. private void addResult(string path, ref size_t count, string desc = "") { mixin(S_TRACE);
  3639. if (cancel) return;
  3640. count++;
  3641. auto addResultPath = new AddResultPath;
  3642. addResultPath.path = path;
  3643. addResultPath.desc = desc;
  3644. addResultPath.count = count;
  3645. _display.syncExec(addResultPath);
  3646. }
  3647. private void refContentText() { mixin(S_TRACE);
  3648. foreach (itm; _result.getItems()) { mixin(S_TRACE);
  3649. auto c = cast(CWXPathString) itm.getData();
  3650. if (c) { mixin(S_TRACE);
  3651. string text1, text2;
  3652. Image img1, img2;
  3653. getPathParams(c.path, text1, text2, img1, img2);
  3654. itm.setImage(0, img1);
  3655. itm.setText(0, text1);
  3656. itm.setImage(1, img2);
  3657. itm.setText(1, text2);
  3658. }
  3659. }
  3660. }
  3661. private void getPathParams(CWXPath path, out string text, out string text2, out Image img, out Image img2, bool par = false) { mixin(S_TRACE);
  3662. if (!path) return;
  3663. auto summ = _grepSumm ? _grepSumm : _summ;
  3664. getSymbols(_comm, summ, path, text, text2, img, img2, par);
  3665. }
  3666. private void addResult(CWXPath path, ref size_t count, string desc = "", int index = -1) { mixin(S_TRACE);
  3667. if (cancel) return;
  3668. count++;
  3669. auto addResultCWXPath = new AddResultCWXPath;
  3670. addResultCWXPath.path = path;
  3671. addResultCWXPath.index = index;
  3672. addResultCWXPath.desc = desc;
  3673. addResultCWXPath.count = count;
  3674. _display.syncExec(addResultCWXPath);
  3675. }
  3676. private void addResult(string name, Image delegate() image, ref size_t count, int index = -1) { mixin(S_TRACE);
  3677. if (cancel) return;
  3678. count++;
  3679. auto addResultMsg = new AddResultMsg;
  3680. addResultMsg.name = name;
  3681. addResultMsg.image = image;
  3682. addResultMsg.index = index;
  3683. addResultMsg.count = count;
  3684. _display.syncExec(addResultMsg);
  3685. }
  3686. private void addResult(string name, uint use, Image delegate() image, ref size_t count, int index = -1) { mixin(S_TRACE);
  3687. if (cancel) return;
  3688. count++;
  3689. auto addResultUse = new AddResultUse;
  3690. addResultUse.name = name;
  3691. addResultUse.use = use;
  3692. addResultUse.image = image;
  3693. addResultUse.index = index;
  3694. addResultUse.count = count;
  3695. _display.syncExec(addResultUse);
  3696. }
  3697. private bool repl(CWXPath path, string text, void delegate(string) set, ref size_t count, ref Undo[] uArr, bool storeToArr = false) { mixin(S_TRACE);
  3698. auto c = fTextCount(text);
  3699. count += c;
  3700. if (c > 0) { mixin(S_TRACE);
  3701. string n;
  3702. if (_replMode && set) { mixin(S_TRACE);
  3703. n = fTextRepl(text);
  3704. if (!path || storeToArr) uArr ~= new StrUndo(text, n, set);
  3705. set(n);
  3706. }
  3707. if (path) { mixin(S_TRACE);
  3708. if (_replMode && set && !storeToArr) store(path, text, n, set);
  3709. size_t dmy = 0;
  3710. addResult(path, dmy);
  3711. }
  3712. return true;
  3713. }
  3714. return false;
  3715. }
  3716. private bool replFilePath(string text, void delegate(string) set, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3717. auto c = fTextCount(encodePath(text));
  3718. count += c;
  3719. if (c > 0) { mixin(S_TRACE);
  3720. if (_replMode) { mixin(S_TRACE);
  3721. auto o = decodePath(text);
  3722. string n = fTextRepl(o);
  3723. uArr ~= new StrUndo(o, n, set);
  3724. set(n);
  3725. }
  3726. return true;
  3727. }
  3728. return false;
  3729. }
  3730. private bool replFlagName(F)(FlagDir parent, F flag, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3731. string text = flag.name;
  3732. auto c = fTextCount(text);
  3733. count += c;
  3734. if (c > 0) { mixin(S_TRACE);
  3735. if (_replMode) { mixin(S_TRACE);
  3736. string oldPath = flag.path;
  3737. string n = fTextRepl(text);
  3738. uArr ~= new StrUndo(text, n, (string name) { mixin(S_TRACE);
  3739. auto parent = flag.parent;
  3740. if (parent) { mixin(S_TRACE);
  3741. flag.name = parent.validName(name);
  3742. } else { mixin(S_TRACE);
  3743. flag.name = name;
  3744. }
  3745. });
  3746. flag.name = parent.validName(n);
  3747. _after ~= { mixin(S_TRACE);
  3748. string newPath = flag.path;
  3749. auto oldID = F.toID(oldPath);
  3750. auto newID = F.toID(newPath);
  3751. foreach (v; _summ.useCounter.values(oldID)) { mixin(S_TRACE);
  3752. v.id = newID;
  3753. storeID(null, v, oldID, newID, &v.id);
  3754. }
  3755. };
  3756. }
  3757. return true;
  3758. }
  3759. return false;
  3760. }
  3761. private bool replRqCoupons(C)(CWXPath path, C targ, ref size_t count, ref Undo[] uArr, bool storeToArr = false) { mixin(S_TRACE);
  3762. string[] coupons = targ.rCoupons;
  3763. string[] old = coupons.dup;
  3764. bool r = false;
  3765. foreach (i, cp; coupons) { mixin(S_TRACE);
  3766. Undo[] nArr;
  3767. r |= repl(null, cp, (string t) {cp = t;}, count, nArr);
  3768. if (_replMode) coupons[i] = cp;
  3769. }
  3770. if (r) { mixin(S_TRACE);
  3771. if (_replMode) { mixin(S_TRACE);
  3772. if (!path || storeToArr) uArr ~= new StrArrUndo(old, coupons.dup, &targ.rCoupons);
  3773. targ.rCoupons = coupons;
  3774. }
  3775. if (path) { mixin(S_TRACE);
  3776. if (_replMode && !storeToArr) store(path, old, coupons.dup, &targ.rCoupons);
  3777. size_t dmy = 0;
  3778. addResult(targ, dmy);
  3779. }
  3780. return true;
  3781. }
  3782. return false;
  3783. }
  3784. private bool replKeyCode(C)(CWXPath path, C targ, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3785. if (_keyCodeSel) { mixin(S_TRACE);
  3786. auto kcs = targ.keyCodes.dup;
  3787. auto old = targ.keyCodes.dup;
  3788. bool r = false;
  3789. Undo[] nArr;
  3790. foreach (i, kc; kcs) { mixin(S_TRACE);
  3791. r |= repl(null, kc, (string t) {kc = t;}, count, nArr);
  3792. if (_replMode) kcs[i] = kc;
  3793. }
  3794. if (r) { mixin(S_TRACE);
  3795. if (_replMode) { mixin(S_TRACE);
  3796. if (!path) uArr ~= new StrArrUndo(old, kcs.dup, &targ.keyCodes);
  3797. targ.keyCodes = kcs;
  3798. }
  3799. if (path) { mixin(S_TRACE);
  3800. if (_replMode) store(path, old, kcs.dup, &targ.keyCodes);
  3801. size_t dmy = 0;
  3802. addResult(path, dmy);
  3803. }
  3804. return true;
  3805. }
  3806. }
  3807. return false;
  3808. }
  3809. private bool replFKeyCode(C)(CWXPath path, C targ, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3810. if (_keyCodeSel) { mixin(S_TRACE);
  3811. auto kcs = targ.keyCodes.dup;
  3812. auto old = targ.keyCodes.dup;
  3813. bool r = false;
  3814. Undo[] nArr;
  3815. foreach (i, fkc; kcs) { mixin(S_TRACE);
  3816. auto kc = _prop.sys.convFireKeyCode(fkc);
  3817. r |= repl(null, kc, (string t) {kc = t;}, count, nArr);
  3818. if (_replMode) kcs[i] = _prop.sys.toFKeyCode(kc);
  3819. }
  3820. if (r) { mixin(S_TRACE);
  3821. if (_replMode) { mixin(S_TRACE);
  3822. if (!path) uArr ~= new FKeyCodesUndo(old, kcs.dup, (FKeyCode[] fkc) {targ.keyCodes = fkc;});
  3823. targ.keyCodes = kcs;
  3824. }
  3825. if (path) { mixin(S_TRACE);
  3826. if (_replMode) store(path, old, kcs.dup, (FKeyCode[] fkc) {targ.keyCodes = fkc;});
  3827. size_t dmy = 0;
  3828. addResult(path, dmy);
  3829. }
  3830. return true;
  3831. }
  3832. }
  3833. return false;
  3834. }
  3835. private bool replBgImage(CWXPath path, BgImage back, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3836. bool r = false;
  3837. Undo[] uArr2;
  3838. if (_flagSel) { mixin(S_TRACE);
  3839. if (_flagDirOnRange) { mixin(S_TRACE);
  3840. r |= repl(null, back.flag, null, count, uArr2);
  3841. } else { mixin(S_TRACE);
  3842. r |= repl(null, back.flag, &back.flag, count, uArr2);
  3843. }
  3844. }
  3845. auto ic = cast(ImageCell) back;
  3846. if (ic && _fileSel) { mixin(S_TRACE);
  3847. r |= replFilePath(ic.path, &ic.path, count, uArr2);
  3848. }
  3849. auto tc = cast(TextCell) back;
  3850. if (tc) { mixin(S_TRACE);
  3851. if (_jptxSel) { mixin(S_TRACE);
  3852. r |= repl(null, tc.text, &tc.text, count, uArr2, true);
  3853. }
  3854. r |= replFlagsInText(tc, count, uArr2);
  3855. }
  3856. if (r && path) { mixin(S_TRACE);
  3857. if (_replMode) store(path, uArr2);
  3858. size_t dmy = 0;
  3859. addResult(path, dmy);
  3860. } else { mixin(S_TRACE);
  3861. uArr ~= uArr2;
  3862. }
  3863. return r;
  3864. }
  3865. private bool replCard(C)(CWXPath path, C card, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3866. bool r = false;
  3867. static if (is(typeof(card.linkId))) {
  3868. if (card.linkId != 0) return r;
  3869. }
  3870. Undo[] uArr2;
  3871. if (_cardNameSel) { mixin(S_TRACE);
  3872. r |= repl(null, card.name, &card.name, count, uArr2);
  3873. }
  3874. if (_cardDescSel) { mixin(S_TRACE);
  3875. r |= repl(null, card.desc, &card.desc, count, uArr2);
  3876. }
  3877. if (_flagSel) { mixin(S_TRACE);
  3878. static if (is (C : IFlagUser)) {
  3879. if (_flagDirOnRange) { mixin(S_TRACE);
  3880. r |= repl(null, card.flag, null, count, uArr2);
  3881. } else { mixin(S_TRACE);
  3882. r |= repl(null, card.flag, &card.flag, count, uArr2);
  3883. }
  3884. }
  3885. }
  3886. if (_fileSel) { mixin(S_TRACE);
  3887. r |= replFilePath(card.path, &card.path, count, uArr2);
  3888. }
  3889. static if (is (C : EffectCard)) {
  3890. r |= replKeyCode!(C)(null, card, count, uArr2);
  3891. }
  3892. if (r && path) { mixin(S_TRACE);
  3893. if (_replMode) store(path, uArr2);
  3894. size_t dmy = 0;
  3895. addResult(path, dmy);
  3896. } else { mixin(S_TRACE);
  3897. uArr ~= uArr2;
  3898. }
  3899. return r;
  3900. }
  3901. bool replFontsInText(ITextHolder th, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3902. Undo[] nArr;
  3903. bool r = false;
  3904. string old = th.text;
  3905. if (_fileSel) { mixin(S_TRACE);
  3906. auto ps = th.fontsInText;
  3907. foreach (i, p; ps) { mixin(S_TRACE);
  3908. auto c = decodeFontPath(p);
  3909. string ext = .extension(p);
  3910. r |= repl(null, .to!string(c), (string s) { mixin(S_TRACE);
  3911. dstring ds = .to!dstring(s);
  3912. if (!ds.length) return;
  3913. th.changeInText(i, toPathId(encodeFontPath(ds[0], ext)));
  3914. }, count, nArr);
  3915. }
  3916. uArr ~= new StrUndo(old, th.text, &th.text);
  3917. }
  3918. return r;
  3919. }
  3920. bool replFlagsInText(ISimpleTextHolder th, ref size_t count, ref Undo[] uArr) { mixin(S_TRACE);
  3921. Undo[] nArr;
  3922. bool r = false;
  3923. if (_flagSel && !_msgSel) { mixin(S_TRACE);
  3924. if (_flagDirOnRange) { mixin(S_TRACE);
  3925. // Flag/Step?????UseCounter????????
  3926. auto fps = th.flagsInText;
  3927. foreach (i, p; fps) { mixin(S_TRACE);
  3928. r |= repl(null, p, null, count, nArr);
  3929. }
  3930. auto sps = th.stepsInText;
  3931. foreach (i, p; sps) { mixin(S_TRACE);
  3932. r |= repl(null, p, null, count, nArr);
  3933. }
  3934. } else { mixin(S_TRACE);
  3935. auto fps = th.flagsInText;
  3936. foreach (i, p; fps) { mixin(S_TRACE);
  3937. r |= repl(null, p, (string n) {th.changeInText(i, toFlagId(p));}, count, nArr);
  3938. }
  3939. auto sps = th.stepsInText;
  3940. foreach (i, p; sps) { mixin(S_TRACE);
  3941. r |= repl(null, p, (string n) {th.changeInText(i, toStepId(p));}, count, nArr);
  3942. }
  3943. }
  3944. }
  3945. return r;
  3946. }
  3947. void replContent(Content e, ref size_t count) { mixin(S_TRACE);
  3948. auto eo = e.parent;
  3949. assert (!eo || eo.detail.owner);
  3950. bool r = false;
  3951. Undo[] uArr2;
  3952. if (_eventSel && eo && eo.detail.nextType == CNextType.TEXT) { mixin(S_TRACE);
  3953. r |= repl(null, e.name, &e.name, count, uArr2);
  3954. }
  3955. if (_flagSel) { mixin(S_TRACE);
  3956. if (_flagDirOnRange) { mixin(S_TRACE);
  3957. // Flag/Step?????UseCounter????????
  3958. r |= repl(null, e.flag, null, count, uArr2);
  3959. r |= repl(null, e.step, null, count, uArr2);
  3960. r |= repl(null, e.flag2, null, count, uArr2);
  3961. r |= repl(null, e.step2, null, count, uArr2);
  3962. } else { mixin(S_TRACE);
  3963. r |= repl(null, e.flag, &e.flag, count, uArr2);
  3964. r |= repl(null, e.step, &e.step, count, uArr2);
  3965. r |= repl(null, e.flag2, &e.flag, count, uArr2);
  3966. r |= repl(null, e.step2, &e.step, count, uArr2);
  3967. }
  3968. }
  3969. if (_startSel) { mixin(S_TRACE);
  3970. r |= repl(null, e.start, &e.start, count, uArr2);
  3971. if (e.type == CType.START) { mixin(S_TRACE);
  3972. r |= repl(null, e.name, &e.name, count, uArr2);
  3973. }
  3974. }
  3975. if (_couponSel) { mixin(S_TRACE);
  3976. r |= repl(null, e.coupon, &e.coupon, count, uArr2);
  3977. }
  3978. if (_gossipSel) { mixin(S_TRACE);
  3979. r |= repl(null, e.gossip, &e.gossip, count, uArr2);
  3980. }
  3981. if (_endSel) { mixin(S_TRACE);
  3982. r |= repl(null, e.completeStamp, &e.completeStamp, count, uArr2);
  3983. }
  3984. if (_msgSel) { mixin(S_TRACE);
  3985. r |= repl(null, e.text, &e.text, count, uArr2);
  3986. }
  3987. r |= replFontsInText(e, count, uArr2);
  3988. r |= replFlagsInText(e, count, uArr2);
  3989. bool rDlg = false;
  3990. if (_msgSel || _couponSel || _fileSel || _flagSel) { mixin(S_TRACE);
  3991. auto dlgs = e.dialogs;
  3992. foreach (dlg; dlgs) { mixin(S_TRACE);
  3993. Undo[] uArrDlg;
  3994. auto put = dlg;
  3995. if (_msgSel && repl(dlg, dlg.text, &dlg.text, count, uArrDlg, true)) { mixin(S_TRACE);
  3996. rDlg = true;
  3997. put = null;
  3998. }
  3999. if (_couponSel && replRqCoupons!(typeof(dlg))(put, dlg, count, uArrDlg, true)) { mixin(S_TRACE);
  4000. rDlg = true;
  4001. put = null;
  4002. }
  4003. bool dr = replFontsInText(dlg, count, uArrDlg);
  4004. dr |= replFlagsInText(dlg, count, uArrDlg);
  4005. if (dr) { mixin(S_TRACE);
  4006. size_t dmy = 0;
  4007. if (put) addResult(put, dmy);
  4008. rDlg = true;
  4009. put = null;
  4010. }
  4011. if (_replMode && !put) { mixin(S_TRACE);
  4012. store(dlg, uArrDlg);
  4013. }
  4014. }
  4015. }
  4016. if (_fileSel) { mixin(S_TRACE);
  4017. r |= replFilePath(e.cardPath, &e.cardPath, count, uArr2);
  4018. r |= replFilePath(e.bgmPath, &e.bgmPath, count, uArr2);
  4019. r |= replFilePath(e.soundPath, &e.soundPath, count, uArr2);
  4020. }
  4021. if (_commentSel) { mixin(S_TRACE);
  4022. r |= repl(null, e.comment, &e.comment, count, uArr2);
  4023. }
  4024. if (r) { mixin(S_TRACE);
  4025. if (_replMode) { mixin(S_TRACE);
  4026. store(e, uArr2);
  4027. }
  4028. size_t dmy = 0;
  4029. addResult(e, dmy);
  4030. }
  4031. }
  4032. }