/cwxeditor_src/cwx/editor/gui/dwt/areatable.d
D | 3121 lines | 3052 code | 58 blank | 11 comment | 478 complexity | 63095cde6e618b1a5cbda9fc2155e05c MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- module cwx.editor.gui.dwt.areatable;
- import cwx.flag;
- import cwx.area;
- import cwx.event;
- import cwx.utils;
- import cwx.summary;
- import cwx.background;
- import cwx.usecounter;
- import cwx.xml;
- import cwx.skin;
- import cwx.path;
- import cwx.structs;
- import cwx.menu;
- import cwx.types;
- import cwx.card;
- import cwx.system;
- import cwx.editor.gui.dwt.smalldialogs;
- import cwx.editor.gui.dwt.dprops;
- import cwx.editor.gui.dwt.dutils;
- import cwx.editor.gui.dwt.dskin;
- import cwx.editor.gui.dwt.flagtable;
- import cwx.editor.gui.dwt.areaview;
- import cwx.editor.gui.dwt.areawindow;
- import cwx.editor.gui.dwt.eventwindow;
- import cwx.editor.gui.dwt.summarydialog;
- import cwx.editor.gui.dwt.commons;
- import cwx.editor.gui.dwt.properties;
- import cwx.editor.gui.dwt.xmlbytestransfer;
- import cwx.editor.gui.dwt.undo;
- import cwx.editor.gui.dwt.dmenu;
- import cwx.editor.gui.dwt.customtable;
- import cwx.editor.gui.dwt.incsearch;
- import cwx.editor.gui.dwt.splitpane;
- import cwx.editor.gui.dwt.centerlayout;
- import std.algorithm : max, min;
- import std.array : split;
- import std.conv;
- import std.string : icmp, join, toLower;
- import org.eclipse.swt.all;
- import java.lang.all;
- /// ??????????????????????
- class AreaTable : TCPD {
- private:
- int compType(const Object o1, const Object o2) { mixin(S_TRACE);
- if (cast(const Summary) o1) return -1;
- if (cast(const Summary) o2) return 1;
- if (cast(const Area) o1) { mixin(S_TRACE);
- if (cast(const Battle) o2) return -1;
- if (cast(const Package) o2) return -1;
- }
- if (cast(const Battle) o1) { mixin(S_TRACE);
- if (cast(const Area) o2) return 1;
- if (cast(const Package) o2) return -1;
- }
- if (cast(const Package) o1) { mixin(S_TRACE);
- if (cast(const Area) o2) return 1;
- if (cast(const Battle) o2) return 1;
- }
- return 0;
- }
- bool compID(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o1, o2);
- if (c == 0) { mixin(S_TRACE);
- auto a1 = cast(const AbstractArea) o1;
- auto a2 = cast(const AbstractArea) o2;
- if (a1.id < a2.id) return true;
- if (a1.id > a2.id) return false;
- return false;
- }
- return c < 0;
- }
- bool compName(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o1, o2);
- if (c == 0) { mixin(S_TRACE);
- auto a1 = cast(const AbstractArea) o1;
- auto a2 = cast(const AbstractArea) o2;
- if (_prop.var.etc.logicalSort) { mixin(S_TRACE);
- c = incmp(a1.name, a2.name);
- } else { mixin(S_TRACE);
- c = icmp(a1.name, a2.name);
- }
- if (c == 0) return compID(o1, o2);
- }
- return c < 0;
- }
- bool compUC(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o1, o2);
- if (c == 0) { mixin(S_TRACE);
- int uc1 = 0;
- int uc2 = 0;
- auto a1 = cast(const Area) o1;
- auto a2 = cast(const Area) o2;
- if (a1 && a2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toAreaId(a1.id));
- uc2 = _summ.useCounter.get(toAreaId(a2.id));
- }
- auto b1 = cast(const Battle) o1;
- auto b2 = cast(const Battle) o2;
- if (b1 && b2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toBattleId(b1.id));
- uc2 = _summ.useCounter.get(toBattleId(b2.id));
- }
- auto p1 = cast(const Package) o1;
- auto p2 = cast(const Package) o2;
- if (p1 && p2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toPackageId(p1.id));
- uc2 = _summ.useCounter.get(toPackageId(p2.id));
- }
- if (uc1 < uc2) return true;
- if (uc1 > uc2) return false;
- return compID(o1, o2);
- }
- return c < 0;
- }
- bool revCompID(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o2, o1);
- if (c == 0) { mixin(S_TRACE);
- auto a1 = cast(const AbstractArea) o2;
- auto a2 = cast(const AbstractArea) o1;
- if (a1.id < a2.id) return true;
- if (a1.id > a2.id) return false;
- return false;
- }
- return 0 < c;
- }
- bool revCompName(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o2, o1);
- if (c == 0) { mixin(S_TRACE);
- auto a1 = cast(const AbstractArea) o2;
- auto a2 = cast(const AbstractArea) o1;
- if (_prop.var.etc.logicalSort) { mixin(S_TRACE);
- c = incmp(a2.name, a1.name);
- } else { mixin(S_TRACE);
- c = icmp(a2.name, a1.name);
- }
- if (c == 0) return revCompID(o1, o2);
- }
- return 0 < c;
- }
- bool revCompUC(const Object o1, const Object o2) { mixin(S_TRACE);
- auto c = compType(o2, o1);
- if (c == 0) { mixin(S_TRACE);
- int uc1 = 0;
- int uc2 = 0;
- auto a1 = cast(const Area) o2;
- auto a2 = cast(const Area) o1;
- if (a1 && a2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toAreaId(a1.id));
- uc2 = _summ.useCounter.get(toAreaId(a2.id));
- }
- auto b1 = cast(const Battle) o2;
- auto b2 = cast(const Battle) o1;
- if (b1 && b2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toBattleId(b1.id));
- uc2 = _summ.useCounter.get(toBattleId(b2.id));
- }
- auto p1 = cast(const Package) o2;
- auto p2 = cast(const Package) o1;
- if (p1 && p2) { mixin(S_TRACE);
- uc1 = _summ.useCounter.get(toPackageId(p1.id));
- uc2 = _summ.useCounter.get(toPackageId(p2.id));
- }
- if (uc1 < uc2) return true;
- if (uc1 > uc2) return false;
- return revCompID(o1, o2);
- }
- return 0 < c;
- }
- private static void saveIDs(Summary summ, out ulong[] areaIDs, out ulong[] battleIDs, out ulong[] packageIDs) { mixin(S_TRACE);
- areaIDs.length = 0;
- foreach (a; summ.areas) areaIDs ~= a.id;
- battleIDs.length = 0;
- foreach (a; summ.battles) battleIDs ~= a.id;
- packageIDs.length = 0;
- foreach (a; summ.packages) packageIDs ~= a.id;
- }
- static class ATUndo : Undo {
- protected AreaTable _v = null;
- protected Commons comm;
- protected Summary summ;
- protected bool one = true;
- protected AbstractArea[] calls, delCalls;
- private ulong[] _areaIDs;
- private ulong[] _areaIDsB;
- private ulong[] _battleIDs;
- private ulong[] _battleIDsB;
- private ulong[] _packageIDs;
- private ulong[] _packageIDsB;
- private ulong _sel;
- private TypeInfo _selType;
- private ulong _selB;
- private TypeInfo _selTypeB;
- private DirTree _dirs, _dirsB;
- this (AreaTable v, Commons comm, Summary summ) { mixin(S_TRACE);
- _v = v;
- this.comm = comm;
- this.summ = summ;
- saveIDs(v);
- }
- private void saveIDs(AreaTable v) { mixin(S_TRACE);
- AreaTable.saveIDs(summ, _areaIDs, _battleIDs, _packageIDs);
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- v.getSelectionInfo(_sel, _selType);
- }
- if (v) {
- _dirs = v._dirs.dup;
- }
- }
- abstract override void undo();
- abstract override void redo();
- abstract override void dispose();
- protected void udb(AreaTable v) { mixin(S_TRACE);
- _areaIDsB = _areaIDs.dup;
- _battleIDsB = _battleIDs.dup;
- _packageIDsB = _packageIDs.dup;
- _selB = _sel;
- _selTypeB = _selType;
- _dirsB = _dirs;
- saveIDs(v);
- if (!one) return;
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- .forceFocus(v._areas, false);
- }
- if (v._parent) v._parent.setRedraw(false);
- }
- private void resetID(alias ToID, A)(AreaTable v, A[] arr, ulong[] ids) { mixin(S_TRACE);
- ulong[] oldIDs;
- foreach (i, a; arr) { mixin(S_TRACE);
- auto oID = a.id;
- a.id = ulong.max - arr.length + i;
- summ.useCounter.change(ToID(oID), ToID(a.id));
- oldIDs ~= oID;
- }
- foreach (i, a; arr) { mixin(S_TRACE);
- auto oID = a.id;
- a.id = ids[i];
- summ.useCounter.change(ToID(oID), ToID(a.id));
- }
- foreach (i, a; arr) { mixin(S_TRACE);
- if (a.id != oldIDs[i] || calls.contains(a)) { mixin(S_TRACE);
- staticCallRefArea(v, comm, a);
- }
- }
- }
- protected ulong uid(ulong id, TypeInfo type) { mixin(S_TRACE);
- return id;
- }
- protected void uda(AreaTable v) { mixin(S_TRACE);
- resetID!toAreaId(v, summ.areas, _areaIDsB);
- resetID!toBattleId(v, summ.battles, _battleIDsB);
- resetID!toPackageId(v, summ.packages, _packageIDsB);
- foreach (area; delCalls) {
- auto a = cast(Area) area;
- if (a) { mixin(S_TRACE);
- comm.delArea.call(v, a);
- }
- auto b = cast(Battle) area;
- if (b) { mixin(S_TRACE);
- comm.delBattle.call(v, b);
- }
- auto p = cast(Package) area;
- if (p) { mixin(S_TRACE);
- comm.delPackage.call(v, p);
- }
- }
- calls = [];
- delCalls = [];
- if (!one) return;
- if (v) { mixin(S_TRACE);
- v._dirs = _dirsB.dup;
- v.refreshDirTree();
- }
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- v.refreshAreas();
- v.selectFromInfo(_selB, _selTypeB);
- v.refreshStatusLine();
- }
- comm.refUseCount.call();
- comm.refreshToolBar();
- if (v._parent) v._parent.setRedraw(true);
- }
- protected AreaTable view() { mixin(S_TRACE);
- return _v;
- }
- }
- static class ATUndoArr : Undo {
- private ATUndo[] _array;
- this (ATUndo[] array) { mixin(S_TRACE);
- _array = array;
- }
- void undo() { mixin(S_TRACE);
- foreach_reverse (i, u; _array) { mixin(S_TRACE);
- u.one = (i == 0);
- u.undo();
- }
- }
- void redo() { mixin(S_TRACE);
- foreach (i, u; _array) { mixin(S_TRACE);
- u.one = (i + 1 == _array.length);
- u.redo();
- }
- }
- void dispose() { mixin(S_TRACE);
- foreach (u; _array) u.dispose();
- }
- }
- void storeEmpty() { mixin(S_TRACE);
- _undo ~= new UndoIDs(this, _comm, _summ);
- }
- static class UndoIDs : ATUndo {
- this (AreaTable v, Commons comm, Summary summ) { mixin(S_TRACE);
- super (v, comm, summ);
- }
- override void undo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- }
- override void redo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- }
- override void dispose() {}
- }
- static class UndoEdit : ATUndo {
- private string _name;
- private ulong _id;
- private TypeInfo _type;
- static struct SummData {
- string scenarioName;
- string imagePath;
- string author;
- int levelMin, levelMax;
- string desc;
- string type;
- string[] rCoupons;
- uint rCouponNum;
- ulong startArea;
- Skin skin;
- this (Commons comm, Summary summ) { mixin(S_TRACE);
- scenarioName = summ.scenarioName;
- imagePath = summ.imagePath;
- author = summ.author;
- levelMin = summ.levelMin;
- levelMax = summ.levelMax;
- desc = summ.desc;
- type = summ.type;
- rCoupons = summ.rCoupons.dup;
- rCouponNum = summ.rCouponNum;
- startArea = summ.startArea;
- skin = comm.skin;
- }
- void toSummary(Commons comm, Summary summ) { mixin(S_TRACE);
- summ.scenarioName = scenarioName;
- summ.imagePath = imagePath;
- summ.author = author;
- summ.levelMin = levelMin;
- summ.levelMax = levelMax;
- summ.desc = desc;
- summ.type = type;
- summ.rCoupons = rCoupons;
- summ.rCouponNum = rCouponNum;
- summ.startArea = startArea;
- comm.skin = skin;
- }
- }
- private SummData _summData;
- this (AreaTable v, Commons comm, Summary summ, ulong id, TypeInfo type) { mixin(S_TRACE);
- super (v, comm, summ);
- if (0 == id) { mixin(S_TRACE);
- _summData = SummData(comm, summ);
- } else { mixin(S_TRACE);
- _name = areaFromInfo(summ, id, type).name;
- }
- _id = id;
- _type = type;
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- if (0 == _id) { mixin(S_TRACE);
- auto oldData = SummData(comm, summ);
- bool refSkin = oldData.skin !is _summData.skin;
- _summData.toSummary(comm, summ);
- _summData = oldData;
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- auto itm = v.getItemFrom(uid(_id, _type), _type);
- if (itm) itm.setText(NAME, summ.scenarioName);
- }
- comm.refScenarioName.call(v);
- if (refSkin) comm.refSkin.call();
- } else { mixin(S_TRACE);
- auto area = areaFromInfo(summ, uid(_id, _type), _type);
- string oldName = area.name;
- area.name = _name;
- _name = oldName;
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- auto itm = v.getItemFrom(uid(_id, _type), _type);
- if (itm) itm.setText(NAME, area.name);
- }
- calls ~= area;
- }
- comm.refUseCount.call();
- }
- override void undo() { mixin(S_TRACE);
- impl();
- }
- override void redo() { mixin(S_TRACE);
- impl();
- }
- override void dispose() {}
- }
- void storeEdit(int index) { mixin(S_TRACE);
- ulong id;
- TypeInfo type;
- getInfo(index, id, type);
- storeEdit(id, type);
- }
- void storeEdit(ulong id, TypeInfo type) { mixin(S_TRACE);
- _undo ~= new UndoEdit(this, _comm, _summ, id, type);
- }
- static class UndoMove : ATUndo {
- private int _removeIndex, _insertIndex;
- private TypeInfo _type;
- this (AreaTable v, Commons comm, Summary summ, int removeIndex, int insertIndex, TypeInfo type) { mixin(S_TRACE);
- super (v, comm, summ);
- _removeIndex = removeIndex;
- _insertIndex = insertIndex;
- if (_removeIndex < _insertIndex) _insertIndex--;
- _type = type;
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- int removeIndex = _removeIndex;
- int insertIndex = _insertIndex;
- if (insertIndex < removeIndex) removeIndex++;
- if (_type is typeid(Area)) { mixin(S_TRACE);
- auto a = summ.areas[insertIndex];
- summ.insert(removeIndex, a);
- } else if (_type is typeid(Battle)) { mixin(S_TRACE);
- auto a = summ.battles[insertIndex];
- summ.insert(removeIndex, a);
- } else if (_type is typeid(Package)) { mixin(S_TRACE);
- auto a = summ.packages[insertIndex];
- summ.insert(removeIndex, a);
- }
- std.algorithm.swap(_removeIndex, _insertIndex);
- }
- override void undo() { mixin(S_TRACE);
- impl();
- }
- override void redo() { mixin(S_TRACE);
- impl();
- }
- override void dispose() {}
- }
- void storeMove(int removeIndex, int insertIndex, TypeInfo type) { mixin(S_TRACE);
- assert (_areas.getSortColumn() is null || _areas.getSortColumn() is _idSorter.column);
- _undo ~= new UndoMove(this, _comm, _summ, removeIndex, insertIndex, type);
- }
- static class UndoSwap : ATUndo {
- private int _index1, _index2;
- this (AreaTable v, Commons comm, Summary summ, int index1, int index2) { mixin(S_TRACE);
- super (v, comm, summ);
- _index1 = index1;
- _index2 = index2;
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- auto area1 = areaFromIndex(summ, _index1);
- auto area2 = areaFromIndex(summ, _index2);
- auto a = cast(Area) area1;
- if (a) { mixin(S_TRACE);
- summ.swap!Area(toAreaIndex(summ, _index1), toAreaIndex(summ, _index2));
- }
- auto b = cast(Battle) area1;
- if (b) { mixin(S_TRACE);
- summ.swap!Battle(toBattleIndex(summ, _index1), toBattleIndex(summ, _index2));
- }
- auto p = cast(Package) area1;
- if (p) { mixin(S_TRACE);
- summ.swap!Package(toPackageIndex(summ, _index1), toPackageIndex(summ, _index2));
- }
- calls ~= area1;
- calls ~= area2;
- std.algorithm.swap(_index1, _index2);
- }
- override void undo() { mixin(S_TRACE);
- impl();
- }
- override void redo() { mixin(S_TRACE);
- impl();
- }
- override void dispose() {}
- }
- void storeSwap(int index1, int index2) { mixin(S_TRACE);
- assert (_areas.getSortColumn() is null || _areas.getSortColumn() is _idSorter.column);
- _undo ~= new UndoSwap(this, _comm, _summ, index1, index2);
- }
- static class UndoInsertDelete : ATUndo {
- private bool _insert;
- private ulong _id;
- private TypeInfo _type;
- private AbstractArea _area = null;
- private bool _isStartArea = false;
- private int _delIndex = -1;
- this (AreaTable v, Commons comm, Summary summ, ulong id, TypeInfo type, bool insert, ulong[] a, ulong[] b, ulong[] p) { mixin(S_TRACE);
- super (v, comm, summ);
- _insert = insert;
- _id = id;
- _type = type;
- if (insert) { mixin(S_TRACE);
- _areaIDs = a;
- _battleIDs = b;
- _packageIDs = p;
- } else { mixin(S_TRACE);
- initUndoDelete();
- }
- }
- private void initUndoDelete() { mixin(S_TRACE);
- auto area = areaFromInfo(summ, uid(_id, _type), _type);
- _delIndex = toIndexFrom(summ, uid(_id, _type), _type);
- _isStartArea = cast(Area) area && summ.startArea == area.id;
- _area = area.dup;
- _area.setUseCounter(summ.useCounter.sub);
- }
- private void undoInsert() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- _insert = false;
- initUndoDelete();
- if (v && v._areas && !v._areas.isDisposed()) { mixin(S_TRACE);
- auto itm = v.getItemFrom(uid(_id, _type), _type);
- if (itm) itm.dispose();
- }
- auto area = areaFromInfo(summ, uid(_id, _type), _type);
- delCalls ~= area;
- summ.remove(area);
- comm.refUseCount.call();
- }
- void undoDelete() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- scope (exit) _area = null;
- _insert = true;
- _area.removeUseCounter();
- auto a = cast(Area) _area;
- calls ~= _area;
- if (a) { mixin(S_TRACE);
- summ.insert(_delIndex, a);
- if (v && v._areas && !v._areas.isDisposed()) v.refreshAreas();
- if (_isStartArea) { mixin(S_TRACE);
- summ.startArea = a.id;
- _isStartArea = false;
- }
- return;
- }
- auto b = cast(Battle) _area;
- if (b) { mixin(S_TRACE);
- summ.insert(_delIndex, b);
- if (v && v._areas && !v._areas.isDisposed()) v.refreshAreas();
- return;
- }
- auto p = cast(Package) _area;
- if (p) { mixin(S_TRACE);
- summ.insert(_delIndex, p);
- if (v && v._areas && !v._areas.isDisposed()) v.refreshAreas();
- return;
- }
- assert (0);
- }
- override void undo() { mixin(S_TRACE);
- if (_insert) { mixin(S_TRACE);
- undoInsert();
- } else { mixin(S_TRACE);
- undoDelete();
- }
- }
- override void redo() { mixin(S_TRACE);
- undo();
- }
- override void dispose() { mixin(S_TRACE);
- if (_area) { mixin(S_TRACE);
- _area.removeUseCounter();
- }
- }
- }
- void storeInsert(ulong id, TypeInfo type, ulong[] a, ulong[] b, ulong[] p) { mixin(S_TRACE);
- _undo ~= new UndoInsertDelete(this, _comm, _summ, id, type, true, a, b, p);
- }
- void storeDelete(int index) { mixin(S_TRACE);
- ulong id;
- TypeInfo type;
- getInfo(index, id, type);
- _undo ~= new UndoInsertDelete(this, _comm, _summ, id, type, false, [], [], []);
- }
- static class UndoRenameDir : ATUndo {
- private string _oldPath, _newPath;
- this (AreaTable v, Commons comm, Summary summ, string oldPath, string newPath) { mixin(S_TRACE);
- super (v, comm, summ);
- _oldPath = oldPath;
- _newPath = newPath;
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- void put(AbstractArea area) { mixin(S_TRACE);
- if (area.dirName == _newPath) { mixin(S_TRACE);
- area.dirName = _oldPath;
- calls ~= area;
- }
- }
- foreach (a; summ.areas) put(a);
- foreach (a; summ.battles) put(a);
- foreach (a; summ.packages) put(a);
- std.algorithm.swap(_oldPath, _newPath);
- if (v && v._areas && !v._areas.isDisposed()) {
- auto itm = v.findDirTree(_oldPath);
- auto dir = cast(DirTree)itm.getData();
- dir.name = .split(_newPath, "\\")[$ - 1];
- v._dir = dir.path;
- v.refreshAreas();
- }
- }
- override void undo() { mixin(S_TRACE);
- impl();
- }
- override void redo() { mixin(S_TRACE);
- impl();
- }
- override void dispose() {}
- }
- void storeRenameDir(string oldPath, string newPath) {
- _undo ~= new UndoRenameDir(this, _comm, _summ, oldPath, newPath);
- }
- void dirEditEnd(TreeItem itm, Control ctrl) { mixin(S_TRACE);
- if (_readOnly) return;
- assert (_dirMode);
- auto t = cast(Text)ctrl;
- if (!t) return;
- auto newText = std.array.replace(t.getText(), "\\", "");
- if (newText == "") return;
- if (itm.getText() == newText) return;
- if (auto summ = cast(Summary)itm.getData()) { mixin(S_TRACE);
- storeEdit(0UL, null);
- summ.scenarioName = newText;
- itm.setText(newText);
- _comm.refScenarioName.call();
- } else { mixin(S_TRACE);
- auto dir = cast(DirTree)itm.getData();
- auto oldPath = dir.path;
- dir.name = createNewName(newText, (s) {
- foreach (n; dir.parent.subDirs) {
- if (n is dir) continue;
- if (0 == icmp(n.name, s)) {
- return false;
- }
- }
- return true;
- });
- auto path = dir.path;
- itm.setText(dir.name);
- storeRenameDir(oldPath, path);
- void put(AbstractArea area) {
- if (area.dirName == oldPath) {
- area.dirName = path;
- callRefArea(area);
- }
- }
- foreach (a; _summ.areas) put(a);
- foreach (a; _summ.battles) put(a);
- foreach (a; _summ.packages) put(a);
- sortDirTree();
- refreshDirTree();
- updateDirSel();
- }
- _comm.refreshToolBar();
- }
- void editEnd(TableItem itm, int column, string newText) { mixin(S_TRACE);
- if (_readOnly) return;
- assert (column == 1);
- if (!newText.length) return;
- if (auto summ = cast(Summary) itm.getData()) { mixin(S_TRACE);
- if (summ.scenarioName == newText) return;
- storeEdit(0UL, null);
- summ.scenarioName = newText;
- itm.setText(NAME, newText);
- _comm.refScenarioName.call();
- } else if (auto area = cast(AbstractArea) itm.getData()) { mixin(S_TRACE);
- assert (area !is null);
- if (_dirMode) { mixin(S_TRACE);
- newText = std.array.replace(newText, "\\", "");
- if (newText == "") return;
- if (area.baseName == newText) return;
- storeEdit(_areas.indexOf(itm));
- area.baseName = newText;
- } else { mixin(S_TRACE);
- if (area.name == newText) return;
- storeEdit(_areas.indexOf(itm));
- area.name = newText;
- }
- refreshAreas();
- callRefArea(area);
- }
- _comm.refreshToolBar();
- }
- private static const ID = 0;
- private static const NAME = 1;
- private static const UC = 2;
- int _readOnly = SWT.NONE;
- bool _dirMode = false;
- string _dir = "";
- Commons _comm;
- Props _prop;
- Composite _parent = null;
- FlagTable _flags = null;
- Summary _summ, _importTarget = null;
- TableSorter!Object _idSorter;
- TableSorter!Object _nameSorter;
- TableSorter!Object _ucSorter;
- Tree _dirTree = null;
- Table _areas;
- TableTextEdit _areasEdit;
- TreeEdit _areaDirEdit = null;
- DirTree _dirs = null;
- IncSearch _incSearch = null;
- private void incSearch() { mixin(S_TRACE);
- .forceFocus(_areas, true);
- _incSearch.startIncSearch();
- }
- UndoManager _undo;
- string _statusLine = "";
- void refreshStatusLine() { mixin(S_TRACE);
- string s = "";
- void put(lazy string name, size_t count) { mixin(S_TRACE);
- if (!count) return;
- if (s.length) s ~= " ";
- s ~= .tryFormat(_prop.msgs.areaStatus, name, count);
- }
- if (_summ) { mixin(S_TRACE);
- put(_prop.msgs.area, areaCount);
- put(_prop.msgs.battle, battleCount);
- put(_prop.msgs.cwPackage, packageCount);
- }
- _statusLine = s;
- _comm.setStatusLine(_areas, _statusLine);
- }
- size_t count(A)(A[] areas) { mixin(S_TRACE);
- if (_dirMode) { mixin(S_TRACE);
- size_t n = 0;
- foreach (a; areas) { mixin(S_TRACE);
- if (0 == icmp(a.dirName, _dir)) n++;
- }
- return n;
- } else { mixin(S_TRACE);
- return areas.length;
- }
- }
- @property
- size_t areaCount() { return count(_summ.areas); }
- @property
- size_t battleCount() { return count(_summ.battles); }
- @property
- size_t packageCount() { return count(_summ.packages); }
- void getSelectionInfo(out ulong id, out TypeInfo type) { mixin(S_TRACE);
- getInfo(_areas.getSelectionIndex(), id, type);
- }
- void getInfo(int index, out ulong id, out TypeInfo type) { mixin(S_TRACE);
- id = 0;
- type = null;
- if (0 <= index) { mixin(S_TRACE);
- auto d = _areas.getItem(index).getData();
- auto a = cast(AbstractArea)d;
- if (a)getInfoFromArea(a, id, type);
- }
- }
- void getInfoFromArea(in AbstractArea d, out ulong id, out TypeInfo type) { mixin(S_TRACE);
- auto a = cast(Area) d;
- if (a) { mixin(S_TRACE);
- id = a.id;
- type = typeid(Area);
- }
- auto b = cast(Battle) d;
- if (b) { mixin(S_TRACE);
- id = b.id;
- type = typeid(Battle);
- }
- auto p = cast(Package) d;
- if (p) { mixin(S_TRACE);
- id = p.id;
- type = typeid(Package);
- }
- }
- void selectFromInfo(ulong id, in TypeInfo type) { mixin(S_TRACE);
- if (type is typeid(Area)) { mixin(S_TRACE);
- select(_summ.area(id));
- } else if (type is typeid(Battle)) { mixin(S_TRACE);
- select(_summ.battle(id));
- } else if (type is typeid(Package)) { mixin(S_TRACE);
- select(_summ.cwPackage(id));
- } else { mixin(S_TRACE);
- if (_dirMode) { mixin(S_TRACE);
- _dirTree.setSelection([_dirTree.getItem(0)]);
- } else { mixin(S_TRACE);
- if (_areas.getItemCount()) _areas.select(0);
- }
- }
- }
- static AbstractArea areaFromInfo(Summary summ, ulong id, TypeInfo type) { mixin(S_TRACE);
- if (type is typeid(Area)) { mixin(S_TRACE);
- return summ.area(id);
- } else if (type is typeid(Battle)) { mixin(S_TRACE);
- return summ.battle(id);
- } else if (type is typeid(Package)) { mixin(S_TRACE);
- return summ.cwPackage(id);
- } else assert (0);
- }
- TableItem getItemFrom(ulong id, TypeInfo type) { mixin(S_TRACE);
- if (type is typeid(Area)) { mixin(S_TRACE);
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (cast(Area)itm.getData() && (cast(AbstractArea)itm.getData()).id == id) { mixin(S_TRACE);
- return itm;
- }
- }
- return null;
- } else if (type is typeid(Battle)) { mixin(S_TRACE);
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (cast(Battle)itm.getData() && (cast(AbstractArea)itm.getData()).id == id) { mixin(S_TRACE);
- return itm;
- }
- }
- return null;
- } else if (type is typeid(Package)) { mixin(S_TRACE);
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (cast(Package)itm.getData() && (cast(AbstractArea)itm.getData()).id == id) { mixin(S_TRACE);
- return itm;
- }
- }
- return null;
- }
- return showSummary ? _areas.getItem(0) : null;
- }
- static int toIndexFrom(Summary summ, ulong id, TypeInfo type) { mixin(S_TRACE);
- if (type is typeid(Area)) { mixin(S_TRACE);
- foreach (i, a; summ.areas) { mixin(S_TRACE);
- if (a.id == id) return i;
- }
- } else if (type is typeid(Battle)) { mixin(S_TRACE);
- foreach (i, a; summ.battles) { mixin(S_TRACE);
- if (a.id == id) return i;
- }
- } else if (type is typeid(Package)) { mixin(S_TRACE);
- foreach (i, a; summ.packages) { mixin(S_TRACE);
- if (a.id == id) return i;
- }
- } else assert (0);
- return -1;
- }
- static int indexFrom(A)(Summary summ, int index) { mixin(S_TRACE);
- static if (is(A : Area)) {
- return index;
- } else static if (is(A : Battle)) {
- return index + summ.areas.length;
- } else static if (is(A : Package)) {
- return index + summ.areas.length + summ.battles.length;
- } else static assert (0);
- }
- static int toIndex(A)(Summary summ, int index) { mixin(S_TRACE);
- static if (is(A : Area)) {
- return index;
- } else static if (is(A : Battle)) {
- return index - summ.areas.length;
- } else static if (is(A : Package)) {
- return index - (summ.areas.length + summ.battles.length);
- } else static assert (0);
- }
- alias toIndex!Area toAreaIndex;
- alias toIndex!Battle toBattleIndex;
- alias toIndex!Package toPackageIndex;
- static AbstractArea areaFromIndex(Summary summ, int index) { mixin(S_TRACE);
- if (summ.areas.length + summ.battles.length <= index) { mixin(S_TRACE);
- return summ.packages[toPackageIndex(summ, index)];
- }
- if (summ.areas.length <= index) { mixin(S_TRACE);
- return summ.battles[toBattleIndex(summ, index)];
- }
- if (0 <= index) { mixin(S_TRACE);
- return summ.areas[toAreaIndex(summ, index)];
- }
- return null;
- }
- AbstractArea getSelectionArea() { mixin(S_TRACE);
- auto i = _areas.getSelectionIndex();
- if (0 <= i) { mixin(S_TRACE);
- return cast(AbstractArea) _areas.getItem(i).getData();
- }
- return null;
- }
- AbstractArea[] getSelectionAreas() { mixin(S_TRACE);
- AbstractArea[] areas;
- foreach (itm; _areas.getSelection()) { mixin(S_TRACE);
- if (auto a = cast(AbstractArea)itm.getData()) { mixin(S_TRACE);
- areas ~= a;
- }
- }
- return areas;
- }
- void refArea(Object sender, Area a) { mixin(S_TRACE);
- if (_readOnly) return;
- if (sender is this) return;
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (itm.getData() is a) refData(a, itm);
- }
- }
- void refBattle(Object sender, Battle a) { mixin(S_TRACE);
- if (_readOnly) return;
- if (sender is this) return;
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (itm.getData() is a) refData(a, itm);
- }
- }
- void refPackage(Object sender, Package a) { mixin(S_TRACE);
- if (_readOnly) return;
- if (sender is this) return;
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- if (itm.getData() is a) refData(a, itm);
- }
- }
- static void staticCallRefArea(AreaTable v, Commons comm, AbstractArea area) { mixin(S_TRACE);
- auto a = cast(Area)area;
- if (a) { mixin(S_TRACE);
- comm.refArea.call(v, a);
- return;
- }
- auto b = cast(Battle)area;
- if (b) { mixin(S_TRACE);
- comm.refBattle.call(v, b);
- return;
- }
- auto p = cast(Package)area;
- if (p) { mixin(S_TRACE);
- comm.refPackage.call(v, p);
- return;
- }
- }
- void callRefArea(AbstractArea area) { mixin(S_TRACE);
- if (_readOnly) return;
- staticCallRefArea(this, _comm, area);
- }
- void refreshIDs(bool callRef) { mixin(S_TRACE);
- if (_readOnly) return;
- if (!_areas || _areas.isDisposed()) return;
- if (callRef) _incSearch.close();
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- auto area = cast(AbstractArea) itm.getData();
- if (!area) continue;
- auto str = to!(string)(area.id);
- if (callRef && str != itm.getText(ID)) callRefArea(area);
- itm.setText(ID, str);
- }
- }
- void sort() { mixin(S_TRACE);
- if (_areas.getSortColumn() is null || _areas.getSortColumn() is _idSorter.column) { mixin(S_TRACE);
- _idSorter.doSort(_areas.getSortDirection());
- } else if (_areas.getSortColumn() is _nameSorter.column) { mixin(S_TRACE);
- _nameSorter.doSort(_areas.getSortDirection());
- } else if (_areas.getSortColumn() is _ucSorter.column) { mixin(S_TRACE);
- _ucSorter.doSort(_areas.getSortDirection());
- } else assert (0);
- }
- @property
- bool showSummary() { mixin(S_TRACE);
- if (!_areas || _areas.isDisposed()) return false;
- return 0 < _areas.getItemCount() && cast(Summary)_areas.getItem(0).getData();
- }
- @property
- int countAllAreas() { mixin(S_TRACE);
- auto c = areaCount + battleCount + packageCount;
- if (showSummary) { mixin(S_TRACE);
- return 1 + c;
- }
- return c;
- }
- class DragDir : DragSourceAdapter {
- override void dragStart(DragSourceEvent e) { mixin(S_TRACE);
- e.doit = false;
- auto tree = cast(Tree)(cast(DragSource) e.getSource()).getControl();
- if (!tree) return;
- if (!tree.isFocusControl()) return;
- auto sels = tree.getSelection();
- if (!sels.length) return;
- auto dir = cast(DirTree)sels[0].getData();
- if (!dir) return;
- if (!dir.parent) return;
- e.doit = true;
- }
- override void dragSetData(DragSourceEvent e) { mixin(S_TRACE);
- if (XMLBytesTransfer.getInstance().isSupportedType(e.dataType)) { mixin(S_TRACE);
- auto tree = cast(Tree)(cast(DragSource) e.getSource()).getControl();
- auto dir = cast(DirTree)tree.getSelection()[0].getData();
- auto doc = XNode.create("TablePath", dir.path);
- doc.newAttr("summaryId", _summ.id);
- e.data = bytesFromXML(doc.text);
- }
- }
- override void dragFinished(DragSourceEvent e) { mixin(S_TRACE);
- // ????
- }
- }
- class DropDir : DropTargetAdapter {
- private void move(DropTargetEvent e) { mixin(S_TRACE);
- e.detail = (!_readOnly && e.item !is null && cast(TreeItem)e.item && cast(DirTree)(cast(TreeItem)e.item).getData()) ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- override void dragEnter(DropTargetEvent e){ mixin(S_TRACE);
- move(e);
- }
- override void dragOver(DropTargetEvent e){ mixin(S_TRACE);
- move(e);
- }
- override void drop(DropTargetEvent e){ mixin(S_TRACE);
- if (_readOnly) return;
- if (!isXMLBytes(e.data)) return;
- string xml = bytesToXML(e.data);
- e.detail = DND.DROP_NONE;
- try { mixin(S_TRACE);
- // ??????
- auto node = XNode.parse(xml);
- auto itm = cast(TreeItem)e.item;
- auto dir = cast(DirTree)itm.getData();
- auto path = dir.path;
- if (node.name == "TablePath") {
- if (_summ.id != AbstractArea.summaryId(node)) return;
- auto oldPath = node.value;
- auto removePath = node.value;
- if (oldPath == "") return;
- if (0 == icmp(path, oldPath)) return;
- auto nDir = oldPath.split("\\")[$ - 1];
- oldPath ~= "\\";
- if (istartsWith(path, oldPath)) return; // ????????????????
- // ?????????????
- foreach (sub; dir.subDirs) {
- if (0 == icmp(sub.name, nDir)) return;
- }
- ATUndo[] undos;
- void put(AbstractArea area) {
- if (area.name.istartsWith(oldPath)) {
- ulong id;
- TypeInfo type;
- getInfoFromArea(area, id, type);
- undos ~= new UndoEdit(this.outer, _comm, _summ, id, type);
- auto p = path;
- if (p != "") p ~= "\\";
- area.name = p ~ nDir ~ "\\" ~ area.name[oldPath.length .. $];
- callRefArea(area);
- }
- }
- foreach (a; _summ.areas) put(a);
- foreach (a; _summ.battles) put(a);
- foreach (a; _summ.packages) put(a);
- if (!undos.length) {
- undos ~= new UndoIDs(this.outer, _comm, _summ);
- }
- auto removeItm = findDirTree(removePath);
- auto removeDir = cast(DirTree)removeItm.getData();
- removeDir.parent.subDirs.remove(removeDir);
- new DirTree(dir, removeItm.getText());
- sortDirTree();
- refreshDirTree();
- _undo ~= new ATUndoArr(undos);
- } else if (_summ.id == AbstractArea.summaryId(node)) {
- auto area = getSelectionArea();
- ulong id;
- TypeInfo type;
- getInfoFromArea(area, id, type);
- storeEdit(id, type);
- area.dirName = dir.path;
- callRefArea(area);
- } else {
- _dirTree.setSelection([itm]);
- updateDirSel();
- pasteImpl(node);
- }
- refreshAreas();
- sort();
- refreshStatusLine();
- _comm.refreshToolBar();
- } catch (Exception e) { mixin (S_TRACE);
- debugln(e);
- }
- }
- }
- class DragArea : DragSourceAdapter {
- AbstractArea _data;
- override void dragStart(DragSourceEvent e) { mixin(S_TRACE);
- auto tbl = cast(Table) (cast(DragSource) e.getSource()).getControl();
- e.doit = tbl.isFocusControl() && 0 <= tbl.getSelectionIndex() && cast(AbstractArea)tbl.getSelection()[0].getData();
- }
- override void dragSetData(DragSourceEvent e) { mixin(S_TRACE);
- if (XMLBytesTransfer.getInstance().isSupportedType(e.dataType)) { mixin(S_TRACE);
- auto tbl = cast(Table) (cast(DragSource) e.getSource()).getControl();
- int i = tbl.getSelectionIndex();
- assert (0 <= i);
- _data = cast(AbstractArea)tbl.getItem(i).getData();
- assert (_data !is null);
- e.data = bytesFromXML(_data.toXML(new XMLOption(_prop.sys), _summ.id));
- }
- }
- override void dragFinished(DragSourceEvent e) { mixin(S_TRACE);
- if (_readOnly) return;
- if (e.detail == DND.DROP_MOVE) { mixin(S_TRACE);
- auto area = _data;
- _summ.remove(area);
- delItem(area);
- if (cast(Area) area) { mixin(S_TRACE);
- _comm.delArea.call(cast(Area) area);
- } else if (cast(Battle) area) { mixin(S_TRACE);
- _comm.delBattle.call(cast(Battle) area);
- } else { mixin(S_TRACE);
- assert (cast(Package) area);
- _comm.delPackage.call(cast(Package) area);
- }
- refreshStatusLine();
- _comm.refreshToolBar();
- }
- }
- }
- class DropArea : DropTargetAdapter {
- override void dragEnter(DropTargetEvent e){ mixin(S_TRACE);
- e.detail = !_readOnly && _areas.getItemCount() == countAllAreas ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- override void dragOver(DropTargetEvent e){ mixin(S_TRACE);
- e.detail = !_readOnly && _areas.getItemCount() == countAllAreas ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- override void drop(DropTargetEvent e){ mixin(S_TRACE);
- if (_readOnly) return;
- if (!isXMLBytes(e.data)) return;
- e.detail = DND.DROP_NONE;
- string xml = bytesToXML(e.data);
- try { mixin(S_TRACE);
- scope node = XNode.parse(xml);
- TypeInfo tid;
- if (node.name == Area.XML_NAME) { mixin(S_TRACE);
- tid = typeid(Area);
- } else if (node.name == Battle.XML_NAME) { mixin(S_TRACE);
- tid = typeid(Battle);
- } else if (node.name == Package.XML_NAME) { mixin(S_TRACE);
- tid = typeid(Package);
- } else { mixin(S_TRACE);
- return;
- }
- bool sortedID = _areas.getSortColumn() is null || _areas.getSortColumn() is _idSorter.column;
- auto tbl = cast(Table) (cast(DropTarget) e.getSource()).getControl();
- auto toItm = tbl.getItem(tbl.toControl(e.x, e.y));
- Object toData = toItm ? toItm.getData() : null;
- int getIndex(AbstractArea area) { mixin(S_TRACE);
- int index;
- if (auto a = cast(Area)area) { mixin(S_TRACE);
- if (toItm && cast(Summary)toData) { mixin(S_TRACE);
- index = 0;
- } else if (!toItm || cast(Battle)toData || cast(Package)toData) { mixin(S_TRACE);
- index = _summ.areas.length;
- } else { mixin(S_TRACE);
- index = _summ.indexOf(cast(Area)toData);
- }
- } else if (auto a = cast(Battle)area) { mixin(S_TRACE);
- if (toItm && (cast(Summary)toData || cast(Area)toData)) { mixin(S_TRACE);
- index = 0;
- } else if (!toItm || cast(Package)toData) { mixin(S_TRACE);
- index = _summ.battles.length;
- } else { mixin(S_TRACE);
- index = _summ.indexOf(cast(Battle)toData);
- }
- } else if (auto a = cast(Package)area) { mixin(S_TRACE);
- if (toItm && (cast(Summary)toData || cast(Area)toData || cast(Battle)toData)) { mixin(S_TRACE);
- index = 0;
- } else if (!toItm) { mixin(S_TRACE);
- index = _summ.packages.length;
- } else { mixin(S_TRACE);
- index = _summ.indexOf(cast(Package)toData);
- }
- } else assert (0);
- return index;
- }
- if (_summ.id == AbstractArea.summaryId(node)) { mixin(S_TRACE);
- // ?????????
- if (!sortedID) return;
- int fromIndex = tbl.getSelectionIndex();
- if (showSummary && fromIndex < 1) return;
- auto area = cast(AbstractArea)tbl.getItem(fromIndex).getData();
- int index = getIndex(area);
- void put(A)(A a) { mixin(S_TRACE);
- int moveIndex = _summ.indexOf(a);
- if (moveIndex == index) return;
- storeMove(moveIndex, index, typeid(typeof(a)));
- _summ.insert(index, a);
- }
- if (auto a = cast(Area)area) { mixin(S_TRACE);
- put(a);
- } else if (auto a = cast(Battle)area) { mixin(S_TRACE);
- put(a);
- } else if (auto a = cast(Package)area) { mixin(S_TRACE);
- put(a);
- } else assert (0);
- callRefArea(area);
- refreshAreas();
- sort();
- select(area);
- refreshStatusLine();
- _comm.refreshToolBar();
- e.detail = DND.DROP_NONE;
- } else { mixin(S_TRACE);
- // ???????????
- AbstractArea area;
- auto ver = new XMLInfo(_prop.sys, LATEST_VERSION);
- ulong[] a, b, p;
- saveIDs(_summ, a, b, p);
- if (tid == typeid(Area)) { mixin(S_TRACE);
- area = Area.createFromNode(node, ver);
- if (_dirMode) area.dirName = _dir;
- int index = getIndex(area);
- _summ.insert(index, cast(Area) area);
- storeInsert(area.id, tid, a, b, p);
- index = _summ.indexOf(cast(Area) area);
- newAreaItem(index);
- } else if (tid == typeid(Battle)) { mixin(S_TRACE);
- area = Battle.createFromNode(node, ver);
- if (_dirMode) area.dirName = _dir;
- int index = getIndex(area);
- _summ.insert(index, cast(Battle) area);
- storeInsert(area.id, tid, a, b, p);
- index = _summ.indexOf(cast(Battle) area);
- newBattleItem(index);
- } else { mixin(S_TRACE);
- assert (tid == typeid(Package));
- area = Package.createFromNode(node, ver);
- if (_dirMode) area.dirName = _dir;
- int index = getIndex(area);
- _summ.insert(index, cast(Package) area);
- storeInsert(area.id, tid, a, b, p);
- index = _summ.indexOf(cast(Package) area);
- newPackageItem(index);
- }
- e.detail = DND.DROP_NONE;
- refreshIDs(true);
- sort();
- select(area);
- _comm.refUseCount.call();
- refreshStatusLine();
- _comm.refreshToolBar();
- }
- } catch (Exception e) { mixin (S_TRACE);
- debugln(e);
- }
- }
- }
- int indexOf(in AbstractArea area) { mixin(S_TRACE);
- foreach (i, itm; _areas.getItems()) { mixin(S_TRACE);
- if (itm.getData() is area) { mixin(S_TRACE);
- return i;
- }
- }
- return -1;
- }
- void __refreshUseCount() { mixin(S_TRACE);
- foreach (itm; _areas.getItems()) { mixin(S_TRACE);
- auto element = itm.getData();
- if (cast(Area) element) { mixin(S_TRACE);
- itm.setText(2, to!(string)(_summ.useCounter.area.get(toAreaId((cast(AbstractArea) element).id))));
- } else if (cast(Battle) element) { mixin(S_TRACE);
- itm.setText(2, to!(string)(_summ.useCounter.battle.get(toBattleId((cast(AbstractArea) element).id))));
- } else if (cast(Package) element) { mixin(S_TRACE);
- itm.setText(2, to!(string)(_summ.useCounter.packages.get(toPackageId((cast(AbstractArea) element).id))));
- }
- }
- }
- class TreeMListener : MouseAdapter {
- public override void mouseDoubleClick(MouseEvent e) { mixin(S_TRACE);
- if (_dirTree.isFocusControl() && e.button == 1) { mixin(S_TRACE);
- auto itm = _dirTree.getItem(new Point(e.x, e.y));
- if (itm && cast(Summary)itm.getData()) { mixin(S_TRACE);
- editSummary();
- }
- }
- }
- }
- class TreeKListener : KeyAdapter {
- public override void keyPressed(KeyEvent e) { mixin(S_TRACE);
- if (_dirTree.isFocusControl() && e.character == SWT.CR) { mixin(S_TRACE);
- auto sels = _dirTree.getSelection();
- if (!sels.length) return;
- auto sel = sels[0];
- if (cast(Summary)sel.getData()) { mixin(S_TRACE);
- editSummary();
- }
- }
- }
- }
- class MListener : MouseAdapter {
- public override void mouseUp(MouseEvent e) { mixin(S_TRACE);
- if (e.button == 2) { mixin(S_TRACE);
- auto itm = _areas.getItem(new Point(e.x, e.y));
- if (itm && cast(Summary)itm.getData()) { mixin(S_TRACE);
- editSummary();
- } else { mixin(S_TRACE);
- if (_prop.var.etc.clickIsOpenEvent) { mixin(S_TRACE);
- openAreaScene(e.x, e.y, true);
- } else { mixin(S_TRACE);
- openAreaEvent(e.x, e.y, true);
- }
- }
- }
- }
- public override void mouseDoubleClick(MouseEvent e) { mixin(S_TRACE);
- if (_areas.isFocusControl() && e.button == 1) { mixin(S_TRACE);
- auto itm = _areas.getItem(new Point(e.x, e.y));
- if (itm && cast(Summary)itm.getData()) { mixin(S_TRACE);
- editSummary();
- } else { mixin(S_TRACE);
- bool shift = 0 != (e.stateMask & SWT.SHIFT);
- if (_prop.var.etc.clickIsOpenEvent) shift = !shift;
- if (shift) { mixin(S_TRACE);
- openAreaEvent(true);
- } else { mixin(S_TRACE);
- openAreaScene(true);
- }
- }
- }
- }
- }
- class KListener : KeyAdapter {
- public override void keyPressed(KeyEvent e) { mixin(S_TRACE);
- if (_areas.isFocusControl() && e.character == SWT.CR) { mixin(S_TRACE);
- auto sel = _areas.getSelectionIndex();
- if (sel == -1) return;
- if (cast(Summary)_areas.getItem(sel).getData()) { mixin(S_TRACE);
- editSummary();
- } else { mixin(S_TRACE);
- bool shift = 0 != (e.stateMask & SWT.SHIFT);
- if (_prop.var.etc.clickIsOpenEvent) shift = !shift;
- if (shift) { mixin(S_TRACE);
- openAreaEvent(true);
- } else { mixin(S_TRACE);
- openAreaScene(true);
- }
- }
- }
- }
- }
- class ADListener : DisposeListener {
- override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
- _dirs = null;
- _dir = "";
- _areas = null;
- _dirTree = null;
- if (!_readOnly) {
- _comm.refArea.remove(&refArea);
- _comm.refBattle.remove(&refBattle);
- _comm.refPackage.remove(&refPackage);
- _comm.refUseCount.remove(&__refreshUseCount);
- _comm.replText.remove(&replText);
- _comm.replText.remove(&refresh);
- _comm.refScenario.remove(&refScenario);
- _comm.refScenarioName.remove(&refScenarioName);
- _comm.refUndoMax.remove(&refUndoMax);
- }
- _comm.refAreaTable.remove(&refreshAreas);
- }
- }
- static class DirTree {
- DirTree parent;
- string name;
- DirTree[] subDirs;
- this (DirTree parent, string name) { mixin (S_TRACE);
- this.parent = parent;
- this.name = name;
- if (parent) { mixin (S_TRACE);
- parent.subDirs ~= this;
- }
- }
- @property
- const
- string path() { mixin (S_TRACE);
- if (!parent) return name;
- auto path = parent.path;
- return path == "" ? name : path ~ "\\" ~ name;
- }
- @property
- const
- DirTree dup() { mixin (S_TRACE);
- DirTree recurse(DirTree parent, in DirTree dir) { mixin (S_TRACE);
- auto dir2 = new DirTree(parent, dir.name);
- foreach (sub; dir.subDirs) { mixin (S_TRACE);
- recurse(dir2, sub);
- }
- return dir2;
- }
- return recurse(null, this);
- }
- }
- private void delDirTree(string path) {
- if (_readOnly) return;
- if (path == "") return;
- auto itm = findDirTree(path);
- auto dir = cast(DirTree)itm.getData();
- assert (dir !is null);
- assert (dir.parent !is null);
- dir.parent.subDirs.remove(dir);
- itm.dispose();
- }
- private void replText() {
- if (_readOnly) return;
- constructDirTree(false);
- }
- private void constructDirTree(bool add) { mixin(S_TRACE);
- string[] stored;
- if (add && _dirs) { mixin(S_TRACE);
- void store(DirTree dir) { mixin(S_TRACE);
- stored ~= dir.path;
- foreach (sub; dir.subDirs) store(sub);
- }
- store(_dirs);
- }
- _dirs = new DirTree(null, "");
- DirTree[string] itmTable;
- itmTable[""] = _dirs;
- void put(string dirName) { mixin (S_TRACE);
- auto dirs = .split(dirName, "\\");
- auto itm = _dirs;
- foreach (i, dir; dirs) { mixin (S_TRACE);
- auto fPath = dirs[0 .. i + 1].join("\\");
- auto path = fPath.toLower();
- auto p = path in itmTable;
- if (p) { mixin (S_TRACE);
- itm = *p;
- } else { mixin (S_TRACE);
- auto sub = new DirTree(itm, dir);
- itm = sub;
- itmTable[path] = sub;
- }
- }
- }
- foreach (a; _summ.areas) put(a.dirName);
- foreach (a; _summ.battles) put(a.dirName);
- foreach (a; _summ.packages) put(a.dirName);
- foreach (s; stored) put(s);
- sortDirTree();
- }
- private string putDir(DirTree parent, string dirName) { mixin (S_TRACE);
- auto dirs = .split(dirName, "\\");
- foreach (i, dir; dirs) { mixin (S_TRACE);
- bool exists = false;
- foreach (sub; parent.subDirs) { mixin (S_TRACE);
- if (0 == icmp(sub.name, dir)) { mixin (S_TRACE);
- parent = sub;
- exists = true;
- break;
- }
- }
- if (!exists) {
- parent = new DirTree(parent, dir);
- }
- }
- return parent.path;
- }
- private void sortDirTree() {
- void recurse(DirTree dir) { mixin(S_TRACE);
- if (_prop.var.etc.logicalSort) { mixin(S_TRACE);
- .sortDlg(dir.subDirs, (DirTree a, DirTree b) => incmp(a.name, b.name) < 0);
- } else { mixin(S_TRACE);
- .sortDlg(dir.subDirs, (DirTree a, DirTree b) => icmp(a.name, b.name) < 0);
- }
- foreach (sub; dir.subDirs) recurse(sub);
- }
- recurse(_dirs);
- }
- private TreeItem findDirTree(string path) { mixin(S_TRACE);
- auto dirs = .split(path, "\\");
- auto itm = rootDir;
- foreach (i, dir; dirs) { mixin(S_TRACE);
- foreach (sub; itm.getItems()) { mixin(S_TRACE);
- auto ds = cast(DirTree)sub.getData();
- if (0 == icmp(ds.name, dir)) { mixin(S_TRACE);
- itm = sub;
- break;
- }
- }
- }
- return itm;
- }
- private void refreshDirTree() { mixin(S_TRACE);
- if (!_dirTree) return;
- if (_areaDirEdit) _areaDirEdit.cancel();
- bool selSummary = false;
- auto sel = "";
- auto sels = _dirTree.getSelection();
- if (sels.length) { mixin (S_TRACE);
- auto path = cast(DirTree)sels[0].getData();
- if (path) { mixin (S_TRACE);
- sel = path.path;
- } else { mixin (S_TRACE);
- assert (cast(Summary)sels[0].getData() !is null);
- selSummary = true;
- }
- }
- _dirTree.removeAll();
- if (!_summ) return;
- if (_prop.var.etc.showSummaryInAreaTable) { mixin (S_TRACE);
- auto itm = new TreeItem(_dirTree, SWT.NONE);
- itm.setImage(_prop.images.summary);
- itm.setText(_summ.scenarioName);
- itm.setData(_summ);
- if (selSummary) { mixin (S_TRACE);
- _dirTree.setSelection([itm]);
- }
- }
- void recurse(T)(T tree, DirTree dir) { mixin (S_TRACE);
- auto itm = new TreeItem(tree, SWT.NONE);
- static if (is(T:Tree)) {
- itm.setText(_prop.msgs.areaDirRoot);
- } else {
- itm.setText(dir.name);
- }
- itm.setImage(_prop.images.areaDir);
- itm.setData(dir);
- if (!selSummary && 0 == icmp(sel, dir.path)) { mixin (S_TRACE);
- _dirTree.setSelection([itm]);
- } else if (!_dirTree.getSelection().length) { mixin (S_TRACE);
- _dirTree.setSelection([itm]);
- }
- foreach (sub; dir.subDirs) { mixin (S_TRACE);
- recurse(itm, sub);
- }
- }
- recurse(_dirTree, _dirs);
- _dirTree.treeExpandedAll();
- _dirTree.showSelection();
- }
- private Image areaImage(in Area a) {
- return _summ.startArea == a.id ? _prop.images.startArea : _prop.images.area;
- }
- private void updateDirSel() { mixin(S_TRACE);
- auto sels = _dirTree.getSelection();
- if (!sels.length) return;
- auto sel = cast(DirTree)sels[0].getData();
- if (!sel) return;
- _dir = sel.path;
- refreshAreasImpl(true);
- }
- private void refreshAreas() { mixin(S_TRACE);
- refreshAreasImpl(false);
- }
- private void refreshAreasImpl(bool selDir) { mixin(S_TRACE);
- if (!_areas || _areas.isDisposed()) return;
- _parent.setRedraw(false);
- scope (exit) _parent.setRedraw(true);
- if (!selDir) refreshDirTree();
- int topIndex = _areas.getTopIndex();
- auto sel = _areas.getSelectionIndex();
- if (_summ) { mixin(S_TRACE);
- size_t i = 0;
- if (!_dirMode && _prop.var.etc.showSummaryInAreaTable) { mixin(S_TRACE);
- refSummary();
- i++;
- }
- void put(AbstractArea a) { mixin(S_TRACE);
- if (_dirMode) { mixin(S_TRACE);
- if (0 != icmp(a.dirName, _dir)) return;
- if (!_incSearch.match(a.baseName, a)) return;
- } else { mixin(S_TRACE);
- if (!_incSearch.match(a.name, a)) return;
- }
- refData2(a, i < _areas.getItemCount() ? _areas.getItem(i) : new TableItem(_areas, SWT.NONE));
- i++;
- }
- foreach (a; _summ.areas) { mixin(S_TRACE);
- put(a);
- }
- foreach (a; _summ.battles) { mixin(S_TRACE);
- put(a);
- }
- foreach (a; _summ.packages) { mixin(S_TRACE);
- put(a);
- }
- while (i < _areas.getItemCount()) { mixin(S_TRACE);
- _areas.getItem(i).dispose();
- }
- sort();
- } else { mixin(S_TRACE);
- _areas.removeAll();
- }
- _areas.setTopIndex(topIndex);
- if (sel < 0 || _areas.getItemCount() <= sel) { mixin(S_TRACE);
- _areas.select(.min(_areas.getItemCount() - 1, sel));
- }
- _areas.showSelection();
- refreshStatusLine();
- _comm.refreshToolBar();
- }
- void refSummary() { mixin(S_TRACE);
- if (!_summ) return;
- TableItem itm;
- if (_areas.getItemCount()) { mixin(S_TRACE);
- if (!showSummary) return;
- itm = _areas.getItem(0);
- } else { mixin(S_TRACE);
- itm = new TableItem(_areas, SWT.NONE, 0);
- }
- itm.setImage(0, _prop.images.summary);
- itm.setText(ID, "-");
- itm.setText(NA…
Large files files are truncated, but you can click here to view the full file