/cwxeditor_src/cwx/editor/gui/dwt/eventtreeview.d
D | 4480 lines | 4321 code | 119 blank | 40 comment | 947 complexity | c54f495b05096e1b3e361e95702bf5da 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.eventtreeview;
- import cwx.event;
- import cwx.summary;
- import cwx.flag;
- import cwx.area;
- import cwx.card;
- import cwx.utils;
- import cwx.types;
- import cwx.skin;
- import cwx.usecounter;
- import cwx.background;
- import cwx.path;
- import cwx.script;
- import cwx.structs;
- import cwx.menu;
- import cwx.types;
- import cwx.xml;
- import cwx.msgutils;
- import cwx.system;
- import cwx.warning;
- import cwx.editor.gui.dwt.dutils;
- import cwx.editor.gui.dwt.dprops;
- import cwx.editor.gui.dwt.dskin;
- import cwx.editor.gui.dwt.commons;
- import cwx.editor.gui.dwt.eventdialog;
- import cwx.editor.gui.dwt.messageutils;
- import cwx.editor.gui.dwt.xmlbytestransfer;
- import cwx.editor.gui.dwt.undo;
- import cwx.editor.gui.dwt.properties;
- import cwx.editor.gui.dwt.absdialog;
- import cwx.editor.gui.dwt.centerlayout;
- import cwx.editor.gui.dwt.scripterrordialog;
- import cwx.editor.gui.dwt.textdialog;
- import cwx.editor.gui.dwt.dmenu;
- import cwx.editor.gui.dwt.smalldialogs;
- import cwx.editor.gui.dwt.eventeditor;
- import std.ascii;
- import std.algorithm;
- import std.conv;
- import std.string;
- import std.datetime;
- import org.eclipse.swt.all;
- import java.lang.all;
- public:
- struct Warning {
- Rectangle rect;
- string[] warnings;
- }
- /// ?????????????
- class EventTreeView : TCPD {
- private:
- string _id = "";
- Composite _contentsBoxArea;
- Composite _comp;
- TreeViewWrapper _tree;
- Color _grayFont;
- int _readOnly = 0;
- Props _prop;
- Commons _comm;
- Summary _summ;
- EventTree _et;
- ContentsToolBox _box;
- Menu _createM = null;
- Menu _convM = null;
- Menu _evTemplM = null;
- Converter[CType] _conts;
- bool _showEventTreeDetail = false;
- void delegate(size_t[]) _forceSel;
- void delegate() _refreshTopStart;
- Warning[] _warningRects;
- string _statusLine;
- Item _clickStart = null;
- bool _arrowMode = true;
- CType _cType = CType.START;
- Skin _summSkin;
- @property
- Skin summSkin() { mixin(S_TRACE);
- return _summSkin ? _summSkin : _comm.skin;
- }
- private void initConvMenu() { mixin(S_TRACE);
- if (!_conts.length) return;
- if (!_createM) return;
- if (!_convM) return;
- foreach (cGrp, cs; CTYPE_GROUP) { mixin(S_TRACE);
- auto create = cTypeGroupMenu(_createM, cGrp);
- auto conv = cTypeGroupMenu(_convM, cGrp);
- foreach (i, cType; cs) { mixin(S_TRACE);
- string mnemonic;
- if (i + 1 < 10) {
- mnemonic = .format("%s", i + 1);
- } else {
- mnemonic = .format("%s", cast(char)('A' + (i + 1 - 10)));
- }
- auto text = MenuProps.buildMenu(_prop.msgs.contentName(cType), mnemonic, "", false);
- auto img = _prop.images.content(cType);
- initCreateMenu(cType, create, text, img);
- initConvMenu(cType, cType is CType.START ? _convM : conv, text, img);
- }
- }
- refreshConvMenu();
- }
- private void initCreateMenu(CType type, Menu menu, string text, Image img) {
- createMenuItem2(_comm, menu, text, img, {
- if (!_box) return;
- auto itm = selection;
- bool insert = _box && _box._shiftDown;
- auto oldType = _box._cType;
- _box._cType = type;
- scope (exit) _box._cType = oldType;
- auto oldMode = _box._putMode;
- _box._putMode = MenuID.PutQuick;
- scope (exit) _box._putMode = oldMode;
- create(insert ? itm : null);
- }, () => _et !is null);
- }
- private void initConvMenu(CType type, Menu convMenu, string text, Image img) { mixin(S_TRACE);
- auto ce = _conts[type];
- if (type != CType.START) { mixin(S_TRACE);
- ce.convMenuItem = createMenuItem2(_comm, convMenu, text, img, &ce.convert, null);
- ce.convMenuItem.setEnabled(false);
- }
- }
- private bool canConvTerminal() { mixin(S_TRACE);
- auto itm = selection;
- if (!itm) return false;
- auto evt = cast(Content) itm.getData();
- return !evt.next.length;
- }
- private Menu cTypeGroupMenu(Menu menu, CTypeGroup g) { mixin(S_TRACE);
- void delegate() dlg = null;
- auto mi = createMenuItem(_comm, menu, cTypeGroupToMenuID(g), dlg, g is CTypeGroup.Terminal ? &canConvTerminal : null, SWT.CASCADE);
- auto m = new Menu(_tree.control.getShell(), SWT.DROP_DOWN);
- mi.setMenu(m);
- return m;
- }
- private void refreshConvMenu() { mixin(S_TRACE);
- if (_readOnly) return;
- if (!_et || !selection) { mixin(S_TRACE);
- foreach (ce; _conts.values) { mixin(S_TRACE);
- if (ce.convMenuItem) ce.convMenuItem.setEnabled(false);
- }
- } else { mixin(S_TRACE);
- auto c = cast(Content) selection.getData();
- foreach (ce; _conts.values) { mixin(S_TRACE);
- if (ce.convMenuItem) ce.convMenuItem.setEnabled(c.canConvert(ce.type));
- }
- }
- }
- private class Converter {
- CType type;
- MenuItem convMenuItem;
- Cursor cursor;
- this (CType type) { mixin(S_TRACE);
- this.type = type;
- this.cursor = _prop.images.cursor(type);
- }
- void convert() { mixin(S_TRACE);
- auto sel = selection;
- if (!sel) return;
- auto c = cast(Content) sel.getData();
- if (c.type == type) return;
- store(c);
- _comm.delContent.call(c);
- assert (c.canConvert(type), "convert menu item enabled");
- auto oldd = c.detail;
- c.convertType(type, _prop.parent);
- auto newd = c.detail;
- if (newd.use(CArg.BG_IMAGES) && !oldd.use(CArg.BG_IMAGES)) { mixin(S_TRACE);
- c.backs = createBgImages(summSkin, _prop.var.etc.bgImagesDefault);
- }
- if (newd.use(CArg.DIALOGS) && !oldd.use(CArg.DIALOGS)) { mixin(S_TRACE);
- c.dialogs = [new SDialog];
- }
- sel.setImage(_prop.images.content(type));
- foreach (itm; _tree.getItems(sel)) { mixin(S_TRACE);
- itm.setText(eventText(c, cast(Content) itm.getData()));
- procTreeItem(itm);
- }
- procTreeItem(sel);
- refreshStatusLine();
- redraw();
- _comm.refUseCount.call();
- _comm.refreshToolBar();
- }
- }
- @property
- Item selection() { mixin(S_TRACE);
- if (!_tree.control || _tree.control.isDisposed()) return null;
- auto sels = _tree.getSelection();
- if (sels.length > 0) { mixin(S_TRACE);
- return sels[0];
- }
- return null;
- }
- class EditL : MouseAdapter, KeyListener {
- private void __edit() { mixin(S_TRACE);
- if (_readOnly) return;
- edit();
- }
- override void keyPressed(KeyEvent e) { mixin(S_TRACE);
- if (e.character == SWT.CR) { mixin(S_TRACE);
- __edit();
- }
- }
- override void keyReleased(KeyEvent e) {}
- override void mouseDoubleClick(MouseEvent e) { mixin(S_TRACE);
- if (e.button == 1 && !_tree.control.getCursor()) { mixin(S_TRACE);
- __edit();
- }
- }
- override void mouseUp(MouseEvent e) { mixin(S_TRACE);
- if (e.button == 1 && _clickStart) { mixin(S_TRACE);
- __edit();
- }
- }
- }
- class CreateL : MouseAdapter {
- override void mouseUp(MouseEvent e) { mixin(S_TRACE);
- if (!_box) return;
- if (_readOnly) return;
- if (_box._putMode is MenuID.PutQuick) return;
- if (e.button == 1) { mixin(S_TRACE);
- create(null);
- } else if (e.button == 2 && !_box._arrowMode) { mixin(S_TRACE);
- auto itm = _tree.getItem(new Point(e.x, e.y));
- if (itm && CDetail.fromType(_box._cType).owner) { mixin(S_TRACE);
- auto c = cast(Content) itm.getData();
- if (c.parent) { mixin(S_TRACE);
- _tree.setSelection([itm]);
- create(itm);
- _comm.refreshToolBar();
- }
- }
- } else if (e.button == 3) { mixin(S_TRACE);
- _box.arrow();
- _comm.refreshToolBar();
- }
- }
- }
- class MouseMove : MouseTrackAdapter, MouseMoveListener {
- override void mouseMove(MouseEvent e) { mixin(S_TRACE);
- if (!_box) return;
- _clickStart = null;
- if (!_readOnly && _box._arrowMode && _prop.var.etc.clickIconIsStartEdit) { mixin(S_TRACE);
- auto itm = _tree.getItem(new Point(e.x, e.y));
- if (itm) { mixin(S_TRACE);
- auto c = cast(Content)itm.getData();
- auto d = _tree.control.getDisplay();
- auto hand = d.getSystemCursor(SWT.CURSOR_HAND);
- if (_tree.getImageBounds(itm).contains(e.x, e.y) && hasDialog(c.type) && checkOpenDialog(c.type)) { mixin(S_TRACE);
- _clickStart = itm;
- if (_tree.editor) { mixin(S_TRACE);
- _tree.control.setCursor(hand);
- }
- } else { mixin(S_TRACE);
- if (_tree.editor && _tree.control.getCursor() is hand) { mixin(S_TRACE);
- _tree.control.setCursor(null);
- }
- }
- }
- }
- updateToolTip();
- }
- override void mouseExit(MouseEvent e) { mixin(S_TRACE);
- clearClickStart();
- }
- }
- void clearClickStart() { mixin(S_TRACE);
- auto d = _tree.control.getDisplay();
- auto hand = d.getSystemCursor(SWT.CURSOR_HAND);
- if (_clickStart && _tree.editor && _tree.editor && _tree.control.getCursor() is hand) { mixin(S_TRACE);
- _tree.control.setCursor(null);
- }
- }
- void updateToolTip() { mixin(S_TRACE);
- if (!_tree.tree) return;
- auto p = _tree.control.getDisplay().getCursorLocation();
- p = _tree.control.toControl(p);
- string toolTip = "";
- if (_tree.control.getClientArea().contains(p)) { mixin(S_TRACE);
- foreach (warn; _warningRects) { mixin(S_TRACE);
- if (warn.rect.contains(p)) { mixin(S_TRACE);
- toolTip = std.string.join(warn.warnings, .newline);
- break;
- }
- }
- }
- if (_tree.control.getToolTipText() != toolTip) { mixin(S_TRACE);
- _tree.control.setToolTipText(toolTip);
- }
- }
- UndoManager _undo;
- abstract static class ETVUndo : Undo {
- private size_t[] _etPath;
- private size_t[] _selPath = null, _selPath2 = null;
- protected EventTree et;
- protected Commons comm;
- protected Props prop;
- protected Summary summ;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et) { mixin(S_TRACE);
- this.et = et;
- this.comm = comm;
- this.prop = prop;
- this.summ = summ;
- _etPath = et.areaPath;
- if (v) { mixin(S_TRACE);
- auto sel = v.selection;
- _selPath = sel ? (cast(Content) sel.getData()).ctPath : null;
- }
- }
- void udb(EventTreeView v) { mixin(S_TRACE);
- if (!v) return;
- .forceFocus(v._tree.control, false);
- v._forceSel(_etPath);
- auto sel = v.selection;
- _selPath2 = sel ? (cast(Content) sel.getData()).ctPath : null;
- }
- void uda(EventTreeView v) { mixin(S_TRACE);
- scope (exit) comm.refreshToolBar();
- if (!v) return;
- if (_selPath) v._tree.select(v.fromPath(_selPath));
- _selPath = _selPath2;
- v.refreshStatusLine();
- }
- EventTreeView view() { mixin(S_TRACE);
- return comm.eventTreeViewFrom(et.cwxPath(true), false);
- }
- abstract override void undo();
- abstract override void redo();
- abstract override void dispose();
- }
- private static void insertStart(EventTreeView v, Commons comm, EventTree et, int index, Content c) { mixin(S_TRACE);
- if (v) v._tree.control.setRedraw(false);
- scope (exit) if (v) v._tree.control.setRedraw(true);
- bool empty = et.owner.isEmpty;
- scope (exit) {
- if (empty != et.owner.isEmpty) comm.refEventTree.call(et);
- }
- et.insert(index, c);
- if (v) { mixin(S_TRACE);
- if (v._tree.tree) { mixin(S_TRACE);
- auto itm = createTreeItem(v._tree.tree, c, c.name, v._prop.images.content(c.type), index);
- v.createChilds(itm, c);
- v._tree.setExpanded(itm, true);
- } else { mixin(S_TRACE);
- v._tree.editor.updateEventTree();
- }
- v.refreshStatusLine();
- v._refreshTopStart();
- v.redraw();
- }
- comm.refContent.call(c);
- comm.refUseCount.call();
- }
- static class UndoContent : ETVUndo {
- private size_t[][] _path;
- private Content[] _c;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, Content[] cs) { mixin(S_TRACE);
- super (v, comm, prop, summ, et);
- foreach (c; cs) { mixin(S_TRACE);
- _path ~= c.ctPath;
- _c ~= c.dup;
- _c[$ - 1].setUseCounter(summ.useCounter.sub);
- }
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- bool empty = et.owner.isEmpty;
- scope (exit) {
- if (empty != et.owner.isEmpty) comm.refEventTree.call(et);
- }
- foreach (i, c; _c.dup) { mixin(S_TRACE);
- int index = _path[i][$ - 1];
- auto tc = et.fromPath(_path[i]);
- if (c.type == CType.START) { mixin(S_TRACE);
- et.startUseCounter.change(tc.name, c.name);
- }
- _c[i] = tc.dup;
- _c[i].setUseCounter(summ.useCounter.sub);
- auto pc = tc.parent;
- string text;
- if (pc) { mixin(S_TRACE);
- pc.insert(prop.parent, index, c);
- text = .eventText(comm, summ, pc, c, false);
- } else { mixin(S_TRACE);
- et.insert(index, c);
- text = c.name;
- }
- if (v) v._tree.control.setRedraw(false);
- scope (exit) if (v) v._tree.control.setRedraw(true);
- if (v) { mixin(S_TRACE);
- if (v._tree.tree) { mixin(S_TRACE);
- auto now = cast(TreeItem)v.fromPath(_path[i]);
- auto par = now.getParentItem();
- TreeItem itm;
- if (par) { mixin(S_TRACE);
- itm = createTreeItem(par, c, text, prop.images.content(c.type), index);
- } else { mixin(S_TRACE);
- itm = createTreeItem(v._tree.tree, c, text, prop.images.content(c.type), index);
- }
- v.procTreeItem(itm);
- v.createChilds(itm, c);
- v._tree.setExpanded(itm, true);
- } else { mixin(S_TRACE);
- v._tree.editor.updateEventTree();
- }
- }
- delImpl(v, comm, et, tc);
- if (v && !pc) { mixin(S_TRACE);
- v._refreshTopStart();
- }
- }
- if (v) v.refreshStatusLine();
- comm.refUseCount.call();
- }
- override void undo() {impl();}
- override void redo() {impl();}
- override void dispose() { mixin(S_TRACE);
- foreach (c; _c) { mixin(S_TRACE);
- c.removeUseCounter();
- }
- }
- }
- void store(Content[] evt ...) { mixin(S_TRACE);
- _undo ~= new UndoContent(this, _comm, _prop, _summ, _et, evt);
- }
- static class UndoSwap : ETVUndo {
- private int _upIndex;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, int swapIndex1, int swapIndex2) { mixin(S_TRACE);
- super (v, comm, prop, summ, et);
- _upIndex = swapIndex1 > swapIndex2 ? swapIndex1 : swapIndex2;
- }
- private void impl() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- udImpl!(-1)(v, comm, et, et.starts[_upIndex], false);
- }
- override void undo() {impl();}
- override void redo() {impl();}
- override void dispose() {}
- }
- void storeSwap(int swapIndex1, int swapIndex2) { mixin(S_TRACE);
- _undo ~= new UndoSwap(this, _comm, _prop, _summ, _et, swapIndex1, swapIndex2);
- }
- static class UndoInsert : ETVUndo {
- private int _index;
- private size_t _count;
- private Content[] _c;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, int index, size_t count) { mixin(S_TRACE);
- super (v, comm, prop, summ, et);
- _index = index;
- _count = count;
- }
- override void undo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- if (v) v._tree.control.setRedraw(false);
- scope (exit) if (v) v._tree.control.setRedraw(true);
- for (size_t i = 0; i < _count; i++) { mixin(S_TRACE);
- auto node = et.starts[_index].toNode(new XMLOption(prop.sys));
- auto ver = new XMLInfo(prop.sys, LATEST_VERSION);
- auto c = Content.createFromNode(node, ver);
- c.setUseCounter(summ.useCounter.sub);
- _c ~= c;
- delImpl(v, comm, et, et.starts[_index]);
- }
- comm.refUseCount.call();
- if (v) { mixin(S_TRACE);
- v.refreshStatusLine();
- v._refreshTopStart();
- }
- }
- override void redo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- foreach_reverse (c; _c) { mixin(S_TRACE);
- insertStart(v, comm, et, _index, c);
- }
- _c = [];
- }
- override void dispose() { mixin(S_TRACE);
- foreach (c; _c) { mixin(S_TRACE);
- c.removeUseCounter();
- }
- }
- }
- void storeInsert(int insertIndex, size_t count = 1) { mixin(S_TRACE);
- _undo ~= new UndoInsert(this, _comm, _prop, _summ, _et, insertIndex, count);
- }
- static class UndoDelete : ETVUndo {
- private int _index;
- private Content _c;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, int index, Content del) { mixin(S_TRACE);
- super (v, comm, prop, summ, et);
- _index = index;
- auto node = del.toNode(new XMLOption(prop.sys));
- auto ver = new XMLInfo(prop.sys, LATEST_VERSION);
- _c = Content.createFromNode(node, ver);
- _c.setUseCounter(summ.useCounter.sub);
- }
- override void undo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- insertStart(v, comm, et, _index, _c);
- }
- override void redo() { mixin(S_TRACE);
- auto v = view();
- udb(v);
- scope (exit) uda(v);
- if (v) v._tree.control.setRedraw(false);
- scope (exit) if (v) v._tree.control.setRedraw(true);
- delImpl(v, comm, et, et.starts[_index]);
- comm.refUseCount.call();
- if (v) { mixin(S_TRACE);
- v.refreshStatusLine();
- v._refreshTopStart();
- }
- }
- override void dispose() { mixin(S_TRACE);
- _c.removeUseCounter();
- }
- }
- void storeDelete(int index, Content del) { mixin(S_TRACE);
- _undo ~= new UndoDelete(this, _comm, _prop, _summ, _et, index, del);
- }
- private Item fromPath(string cwxPath) { mixin(S_TRACE);
- return fromPathImpl(_tree, cwxPath);
- }
- private Item fromPathImpl(T)(T tree, string cwxPath) { mixin(S_TRACE);
- if (cpempty(cwxPath)) return null;
- string cate = cpcategory(cwxPath);
- while ("" != cate) { mixin(S_TRACE);
- cwxPath = cpbottom(cwxPath);
- if (cpempty(cwxPath)) return null;
- cate = cpcategory(cwxPath);
- }
- auto itm = _tree.getItem(tree, cpindex(cwxPath));
- cwxPath = cpbottom(cwxPath);
- if (cpempty(cwxPath)) return itm;
- return fromPathImpl(itm, cwxPath);
- }
- private Item fromPath(size_t[] path) { mixin(S_TRACE);
- return fromPathImpl(_tree, path);
- }
- private Item fromPathImpl(T)(T tree, size_t[] path) { mixin(S_TRACE);
- if (!path.length) return null;
- auto itm = _tree.getItem(tree, path[0]);
- if (path.length == 1) return itm;
- return fromPathImpl(itm, path[1 .. $]);
- }
- static class UndoCP : Undo {
- private UndoContent _undoC;
- private UndoDelete _undoD;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, Content[] conts, int index, Content start) { mixin(S_TRACE);
- _undoC = new UndoContent(v, comm, prop, summ, et, conts);
- _undoD = new UndoDelete(v, comm, prop, summ, et, index, start);
- }
- override void undo() { mixin(S_TRACE);
- _undoD.undo();
- _undoC.undo();
- }
- override void redo() { mixin(S_TRACE);
- _undoC.redo();
- _undoD.redo();
- }
- override void dispose() { mixin(S_TRACE);
- _undoC.dispose();
- _undoD.dispose();
- }
- }
- static class UndoContentAndInsert : ETVUndo {
- private UndoContent _undoC;
- private UndoInsert _undoI;
- this (EventTreeView v, Commons comm, Props prop, Summary summ, EventTree et, Content owner, int insertIndex, int count) { mixin(S_TRACE);
- super (v, comm, prop, summ, et);
- _undoC = new UndoContent(v, comm, prop, summ, et, [owner]);
- _undoI = new UndoInsert(v, comm, prop, summ, et, insertIndex, count);
- }
- override void undo() { mixin(S_TRACE);
- _undoI.undo();
- _undoC.undo();
- }
- override void redo() { mixin(S_TRACE);
- _undoC.redo();
- _undoI.redo();
- }
- override void dispose() { mixin(S_TRACE);
- _undoC.dispose();
- _undoI.dispose();
- }
- }
- void storeContentAndInsert(Content owner, int insertIndex, int count) { mixin(S_TRACE);
- _undo ~= new UndoContentAndInsert(this, _comm, _prop, _summ, _et, owner, insertIndex, count);
- }
- private EventDialog[Content] _editDlgs;
- void appliedEdit(UndoContent undo, Content c) { mixin(S_TRACE);
- _undo ~= undo;
- auto itm = fromPath(c.cwxPath(true));
- assert (c is itm.getData());
- foreach (childItm; _tree.getItems(itm)) { mixin(S_TRACE);
- auto par = cast(Content)itm.getData();
- assert (par.detail.owner);
- childItm.setText(eventText(par, cast(Content) childItm.getData()));
- procTreeItem(childItm);
- }
- procTreeItem(itm);
- _tree.select(itm);
- .forceFocus(_tree.control, false);
- redraw();
- _comm.refContent.call(c);
- _comm.refUseCount.call();
- refreshStatusLine();
- _comm.refreshToolBar();
- }
- void editM() {edit();}
- public EventDialog edit() { mixin(S_TRACE);
- if (_readOnly) return null;
- auto sels = _tree.getSelection();
- if (sels.length > 0) { mixin(S_TRACE);
- auto c = cast(Content) sels[0].getData();
- return edit(c);
- }
- return null;
- }
- void create(Item insertTo) { mixin(S_TRACE);
- if (!_box) return;
- if (_readOnly) return;
- if (!_tree.getItemCount()) return;
- if (!_box._arrowMode || _box._putMode is MenuID.PutQuick) { mixin(S_TRACE);
- _tree.control.setRedraw(false);
- scope (exit) _tree.control.setRedraw(true);
- if (_box._cType == CType.START) { mixin(S_TRACE);
- if (insertTo) return;
- create(null, _box._cType, "", (Content evt) { mixin(S_TRACE);
- assert (evt);
- bool empty = _et.owner.isEmpty;
- scope (exit) {
- if (empty != _et.owner.isEmpty) _comm.refEventTree.call(_et);
- }
- auto sel = selection;
- int index;
- if (sel) { mixin(S_TRACE);
- index = _tree.indexOf(_tree.topItem(sel)) + 1;
- } else { mixin(S_TRACE);
- index = -1;
- }
- storeInsert(index);
- _et.insert(index, cast(Content)evt);
- Item sItm;
- if (_tree.tree) { mixin(S_TRACE);
- sItm = createTreeItem(_tree.tree, evt, evt.name, _prop.images.content(CType.START), index);
- } else { mixin(S_TRACE);
- _tree.editor.updateEventTree();
- sItm = EventEditorItem.valueOf(_tree.editor, evt);
- }
- _tree.select(sItm);
- _tree.showSelection();
- .forceFocus(_tree.control, false);
- _comm.refContent.call(evt);
- refreshStatusLine();
- if (_box._putMode !is MenuID.PutContinue) _box.arrow();
- _comm.refreshToolBar();
- });
- } else { mixin(S_TRACE);
- if (insertTo && !CDetail.fromType(_box._cType).owner) return;
- auto sel = selection;
- if (!sel) return;
- if (!insertTo && sel && !(cast(Content)sel.getData()).detail.owner) { mixin(S_TRACE);
- sel = _tree.getParentItem(sel);
- if (!sel) return;
- }
- if (insertTo || (sel && (cast(Content)sel.getData()).detail.owner)) { mixin(S_TRACE);
- Item oItm;
- int insertIndex = -1;
- if (insertTo) { mixin(S_TRACE);
- oItm = _tree.getParentItem(insertTo);
- if (!oItm) return;
- insertIndex = _tree.indexOf(oItm, insertTo);
- } else { mixin(S_TRACE);
- oItm = sel;
- }
- auto owner = cast(Content) oItm.getData();
- void applied(Content evt) { mixin(S_TRACE);
- bool empty = _et.owner.isEmpty;
- scope (exit) {
- if (empty != _et.owner.isEmpty) _comm.refEventTree.call(_et);
- }
- store(owner);
- if (insertIndex == -1) { mixin(S_TRACE);
- if (_box._insertFirst) { mixin(S_TRACE);
- owner.insert(_prop.parent, 0, evt);
- } else { mixin(S_TRACE);
- owner.add(_prop.parent, evt);
- }
- } else { mixin(S_TRACE);
- owner.insert(_prop.parent, insertIndex, evt);
- }
- Item itm;
- if (_tree.tree) { mixin(S_TRACE);
- itm = createTreeItem(cast(TreeItem)oItm, evt, eventText(owner, evt), _prop.images.content(evt.type), insertIndex);
- _tree.setExpanded(oItm, true);
- } else { mixin(S_TRACE);
- _tree.editor.updateEventTree();
- itm = EventEditorItem.valueOf(_tree.editor, evt);
- }
- _tree.setSelection([itm]);
- if (insertTo) { mixin(S_TRACE);
- auto ic = cast(Content) insertTo.getData();
- _comm.delContent.call(ic);
- ic.parent.remove(ic);
- if (_prop.var.etc.adjustContentName) { mixin(S_TRACE);
- ic.setName(_prop.parent, "");
- }
- if (_box._insertFirst) { mixin(S_TRACE);
- evt.insert(_prop.parent, 0, ic);
- } else { mixin(S_TRACE);
- evt.add(_prop.parent, ic);
- }
- insertTo.dispose();
- createChilds(itm, evt);
- _tree.setExpanded(itm, true);
- }
- procTreeItem(itm);
- _tree.showSelection();
- .forceFocus(_tree.control, false);
- _comm.refContent.call(evt);
- _comm.refUseCount.call();
- refreshStatusLine();
- if (_box._putMode !is MenuID.PutContinue) _box.arrow();
- _comm.refreshToolBar();
- }
- if (insertTo) { mixin(S_TRACE);
- create(owner, _box._cType, (cast(Content) insertTo.getData()).name, &applied);
- } else { mixin(S_TRACE);
- create(owner, _box._cType, "", &applied);
- }
- }
- }
- }
- }
- bool hasDialog(CType type) { mixin(S_TRACE);
- switch (type) {
- case CType.START:
- case CType.END_BAD_END:
- case CType.EFFECT_BREAK:
- case CType.ELAPSE_TIME:
- case CType.BRANCH_AREA:
- case CType.BRANCH_BATTLE:
- case CType.BRANCH_IS_BATTLE:
- case CType.SHOW_PARTY:
- case CType.HIDE_PARTY:
- return false;
- default:
- return true;
- }
- }
- bool checkOpenDialog(CType type) { mixin(S_TRACE);
- if (_readOnly) return false;
- switch (type) {
- case CType.START_BATTLE: { mixin(S_TRACE);
- return _summ.battles.length > 0;
- } case CType.CHANGE_AREA: { mixin(S_TRACE);
- return _summ.areas.length > 0;
- } case CType.LINK_PACKAGE, CType.CALL_PACKAGE: { mixin(S_TRACE);
- return _summ.packages.length > 0;
- } case CType.BRANCH_FLAG, CType.SET_FLAG, CType.REVERSE_FLAG, CType.CHECK_FLAG, CType.SUBSTITUTE_FLAG, CType.BRANCH_FLAG_CMP: { mixin(S_TRACE);
- return _summ.flagDirRoot.allFlags.length > 0;
- } case CType.BRANCH_MULTI_STEP, CType.BRANCH_STEP, CType.SET_STEP, CType.SET_STEP_UP, CType.SET_STEP_DOWN, CType.SUBSTITUTE_STEP, CType.BRANCH_STEP_CMP: { mixin(S_TRACE);
- return _summ.flagDirRoot.allSteps.length > 0;
- } case CType.BRANCH_CAST, CType.GET_CAST, CType.LOSE_CAST: { mixin(S_TRACE);
- return _summ.casts.length > 0;
- } case CType.BRANCH_ITEM, CType.GET_ITEM, CType.LOSE_ITEM: { mixin(S_TRACE);
- return _summ.items.length > 0;
- } case CType.BRANCH_SKILL, CType.GET_SKILL, CType.LOSE_SKILL: { mixin(S_TRACE);
- return _summ.skills.length > 0;
- } case CType.BRANCH_INFO, CType.GET_INFO, CType.LOSE_INFO: { mixin(S_TRACE);
- return _summ.infos.length > 0;
- } case CType.BRANCH_BEAST, CType.GET_BEAST, CType.LOSE_BEAST: { mixin(S_TRACE);
- return _summ.beasts.length > 0;
- } case CType.REDISPLAY: { mixin(S_TRACE);
- return !_summ.legacy;
- } default: { mixin(S_TRACE);
- return true;
- }
- }
- }
- void create(Content parent, CType type, string name, void delegate(Content) applied) { mixin(S_TRACE);
- if (!_box) return;
- if (_readOnly) return;
- assert (parent is null || parent.detail.owner);
- if (_box._putMode !is MenuID.PutContinue) { mixin(S_TRACE);
- _box.arrow();
- _comm.refreshToolBar();
- }
- void initial(Content c) { mixin(S_TRACE);
- if (type is CType.CHANGE_BG_IMAGE) { mixin(S_TRACE);
- c.backs = createBgImages(summSkin, _prop.var.etc.bgImagesDefault);
- } else if (type is CType.TALK_DIALOG) { mixin(S_TRACE);
- c.dialogs = [new SDialog];
- } else if (type is CType.BRANCH_SKILL || type is CType.BRANCH_ITEM || type is CType.BRANCH_BEAST) { mixin(S_TRACE);
- c.range = Range.FIELD;
- } else if (type is CType.LOSE_SKILL || type is CType.LOSE_ITEM || type is CType.LOSE_BEAST) { mixin(S_TRACE);
- c.range = Range.FIELD;
- }
- }
- if (hasDialog(type)) { mixin(S_TRACE);
- if (!_box._autoOpen || !checkOpenDialog(type)) { mixin(S_TRACE);
- auto c = new Content(type, name);
- initial(c);
- applied(c);
- return;
- }
- } else { mixin(S_TRACE);
- if (type is CType.START) { mixin(S_TRACE);
- string startName = _prop.msgs.defaultStartName;
- auto sel = selection;
- if (_prop.var.etc.useCurrentStartName && sel) { mixin(S_TRACE);
- if (auto s = (cast(Content)sel.getData()).parentStart) { mixin(S_TRACE);
- startName = s.name;
- }
- }
- name = createNewName(startName, (string name) { mixin(S_TRACE);
- foreach (start; _et.starts) { mixin(S_TRACE);
- if (icmp(start.name, name) == 0) return false;
- }
- return true;
- });
- }
- applied(new Content(type, name));
- return;
- }
- auto evt = new Content(type, name);
- initial(evt);
- auto dlg = createEventDialog(evt, parent, true);
- assert (applied);
- dlg.appliedEvent ~= { mixin(S_TRACE);
- auto evt = dlg.event;
- applied(evt);
- auto undo = new UndoContent(this, _comm, _prop, _summ, _et, [evt]);
- dlg.appliedEvent.length = 0;
- dlg.appliedEvent ~= { mixin(S_TRACE);
- appliedEdit(undo, evt);
- undo = new UndoContent(this, _comm, _prop, _summ, _et, [evt]);
- };
- };
- _editDlgs[evt] = dlg;
- dlg.closeEvent ~= { mixin(S_TRACE);
- _editDlgs.remove(evt);
- };
- dlg.open();
- }
- @property
- public bool canEdit() { mixin(S_TRACE);
- if (_readOnly) return false;
- auto itm = selection;
- if (!itm) return false;
- auto evt = cast(Content) itm.getData();
- return hasDialog(evt.type) && checkOpenDialog(evt.type);
- }
- EventDialog edit(Content evt) { mixin(S_TRACE);
- if (_readOnly) return null;
- if (!hasDialog(evt.type) || !checkOpenDialog(evt.type)) return null;
- auto p = evt in _editDlgs;
- if (p) { mixin(S_TRACE);
- p.active();
- return *p;
- }
- auto dlg = createEventDialog(evt, evt.parent, false);
- auto undo = new UndoContent(this, _comm, _prop, _summ, _et, [evt]);
- dlg.appliedEvent ~= { mixin(S_TRACE);
- appliedEdit(undo, evt);
- undo = new UndoContent(this, _comm, _prop, _summ, _et, [evt]);
- };
- _editDlgs[evt] = dlg;
- dlg.closeEvent ~= { mixin(S_TRACE);
- _editDlgs.remove(evt);
- };
- dlg.open();
- return dlg;
- }
- EventDialog createEventDialog(Content evt, Content parent, bool create) {
- EventDialog dlg;
- switch (evt.type) {
- case CType.START_BATTLE: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.START_BATTLE, Battle, "summary.battles")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.END: { mixin(S_TRACE);
- dlg = new ClearEventDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.CHANGE_AREA: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.CHANGE_AREA, Area, "summary.areas")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.CHANGE_BG_IMAGE: { mixin(S_TRACE);
- if (create) { mixin(S_TRACE);
- evt.backs = createBgImages(summSkin, _prop.var.etc.bgImagesDefault);
- }
- dlg = new BgImagesDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, refTarget, CType.CHANGE_BG_IMAGE);
- break;
- } case CType.EFFECT: { mixin(S_TRACE);
- dlg = new EffectDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LINK_START: { mixin(S_TRACE);
- dlg = new StartSelectDialog!(CType.LINK_START)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LINK_PACKAGE: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.LINK_PACKAGE, Package, "summary.packages")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.TALK_MESSAGE: { mixin(S_TRACE);
- dlg = new MessageDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.TALK_DIALOG: { mixin(S_TRACE);
- dlg = new SpeakDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.PLAY_BGM: { mixin(S_TRACE);
- dlg = new BgmDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.PLAY_SOUND: { mixin(S_TRACE);
- dlg = new SeDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.WAIT: { mixin(S_TRACE);
- dlg = new WaitEventDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.CALL_START: { mixin(S_TRACE);
- dlg = new StartSelectDialog!(CType.CALL_START)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.CALL_PACKAGE: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.CALL_PACKAGE, Package, "summary.packages")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_FLAG: { mixin(S_TRACE);
- dlg = new BrFlagDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_MULTI_STEP: { mixin(S_TRACE);
- dlg = new BrStepNDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_STEP: { mixin(S_TRACE);
- dlg = new BrStepULDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_SELECT: { mixin(S_TRACE);
- dlg = new BrMemberDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_ABILITY: { mixin(S_TRACE);
- dlg = new BrPowerDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_RANDOM: { mixin(S_TRACE);
- dlg = new BrRandomEventDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_LEVEL: { mixin(S_TRACE);
- dlg = new BrLevelDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_STATUS: { mixin(S_TRACE);
- dlg = new BrStateDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_PARTY_NUMBER: { mixin(S_TRACE);
- dlg = new BrNumEventDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_CAST: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.BRANCH_CAST, CastCard, "summary.casts")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_ITEM: { mixin(S_TRACE);
- dlg = new BrItemDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_SKILL: { mixin(S_TRACE);
- dlg = new BrSkillDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_INFO: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.BRANCH_INFO, InfoCard, "summary.infos")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_BEAST: { mixin(S_TRACE);
- dlg = new BrBeastDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_MONEY: { mixin(S_TRACE);
- dlg = new MoneyEventDialog!(CType.BRANCH_MONEY)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_COUPON: { mixin(S_TRACE);
- dlg = new BranchCouponDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_COMPLETE_STAMP: { mixin(S_TRACE);
- dlg = new EndEventDialog!(CType.BRANCH_COMPLETE_STAMP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_GOSSIP: { mixin(S_TRACE);
- dlg = new GossipEventDialog!(CType.BRANCH_GOSSIP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.SET_FLAG: { mixin(S_TRACE);
- dlg = new FlagSetDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.SET_STEP: { mixin(S_TRACE);
- dlg = new StepSetDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.SET_STEP_UP: { mixin(S_TRACE);
- dlg = new StepPlusDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.SET_STEP_DOWN: { mixin(S_TRACE);
- dlg = new StepMinusDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.REVERSE_FLAG: { mixin(S_TRACE);
- dlg = new FlagRDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.CHECK_FLAG: { mixin(S_TRACE);
- dlg = new FlagJudgeDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.GET_CAST: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.GET_CAST, CastCard, "summary.casts")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_ITEM: { mixin(S_TRACE);
- dlg = new GetItemDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_SKILL: { mixin(S_TRACE);
- dlg = new GetSkillDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_INFO: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.GET_INFO, InfoCard, "summary.infos")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_BEAST: { mixin(S_TRACE);
- dlg = new GetBeastDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_MONEY: { mixin(S_TRACE);
- dlg = new MoneyEventDialog!(CType.GET_MONEY)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_COUPON: { mixin(S_TRACE);
- dlg = new GetCouponDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_COMPLETE_STAMP: { mixin(S_TRACE);
- dlg = new EndEventDialog!(CType.GET_COMPLETE_STAMP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.GET_GOSSIP: { mixin(S_TRACE);
- dlg = new GossipEventDialog!(CType.GET_GOSSIP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_CAST: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.LOSE_CAST, CastCard, "summary.casts")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_ITEM: { mixin(S_TRACE);
- dlg = new LostItemDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_SKILL: { mixin(S_TRACE);
- dlg = new LostSkillDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_INFO: { mixin(S_TRACE);
- dlg = new AreaSelectDialog!(CType.LOSE_INFO, InfoCard, "summary.infos")
- (_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_BEAST: { mixin(S_TRACE);
- dlg = new LostBeastDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_MONEY: { mixin(S_TRACE);
- dlg = new MoneyEventDialog!(CType.LOSE_MONEY)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_COUPON: { mixin(S_TRACE);
- dlg = new LoseCouponDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_COMPLETE_STAMP: { mixin(S_TRACE);
- dlg = new EndEventDialog!(CType.LOSE_COMPLETE_STAMP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.LOSE_GOSSIP: { mixin(S_TRACE);
- dlg = new GossipEventDialog!(CType.LOSE_GOSSIP)(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.REDISPLAY: { mixin(S_TRACE);
- dlg = new RefreshDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.SUBSTITUTE_STEP: { mixin(S_TRACE);
- dlg = new SubstituteStepDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.SUBSTITUTE_FLAG: { mixin(S_TRACE);
- dlg = new SubstituteFlagDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_STEP_CMP: { mixin(S_TRACE);
- dlg = new BrStepCmpDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_FLAG_CMP: { mixin(S_TRACE);
- dlg = new BrFlagCmpDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_RANDOM_SELECT: { mixin(S_TRACE);
- dlg = new BrRandomSelectDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.BRANCH_KEY_CODE: { mixin(S_TRACE);
- dlg = new BrKeyCodeDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.CHECK_STEP: { mixin(S_TRACE);
- dlg = new CheckStepDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, _summ.flagDirRoot);
- break;
- } case CType.BRANCH_ROUND: { mixin(S_TRACE);
- dlg = new BranchRoundDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.MOVE_BG_IMAGE: { mixin(S_TRACE);
- dlg = new MoveBgImageDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } case CType.REPLACE_BG_IMAGE: { mixin(S_TRACE);
- dlg = new BgImagesDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt, refTarget, CType.REPLACE_BG_IMAGE);
- break;
- } case CType.LOSE_BG_IMAGE: { mixin(S_TRACE);
- dlg = new LoseBgImageDialog(_comm, _prop, _tree.control.getShell(), _summ, parent, evt);
- break;
- } default: assert (0);
- }
- return dlg;
- }
- @property
- AbstractArea refTarget() { mixin(S_TRACE);
- if (_et && _et.owner) { mixin(S_TRACE);
- auto a = cast(Area) _et.owner;
- if (a) return a;
- auto b = cast(Battle) _et.owner;
- if (b) return b;
- auto m = cast(MenuCard) _et.owner;
- if (m) return m.owner;
- auto e = cast(EnemyCard) _et.owner;
- if (e) return e.owner;
- }
- return null;
- }
- void refreshStatusLine() { mixin(S_TRACE);
- auto itm = selection;
- if (itm) { mixin(S_TRACE);
- _statusLine = .contentText(_comm, cast(Content) itm.getData());
- } else { mixin(S_TRACE);
- _statusLine = "";
- }
- _comm.setStatusLine(_tree.control, _statusLine);
- }
- class TListener : TreeListener {
- override void treeCollapsed(TreeEvent e) { mixin(S_TRACE);
- _comm.refreshToolBar();
- }
- override void treeExpanded(TreeEvent e) { mixin(S_TRACE);
- _comm.refreshToolBar();
- }
- }
- class SListener : SelectionAdapter {
- public override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
- assert (cast(Content) e.item.getData());
- refreshStatusLine();
- _comm.refreshToolBar();
- }
- }
- private Item _dragItm = null;
- class EventDragSource : DragSourceListener {
- private:
- Item _parItm;
- Item _targ;
- public:
- override void dragStart(DragSourceEvent e) { mixin(S_TRACE);
- auto itm = selection;
- e.doit = !_readOnly && itm && (cast(Content) itm.getData()).type != CType.START
- && (cast(DragSource) e.getSource()).getControl().isFocusControl();
- if (e.doit) { mixin(S_TRACE);
- _targ = itm;
- _parItm = _tree.getParentItem(itm);
- _dragItm = _targ;
- }
- }
- override void dragSetData(DragSourceEvent e) { mixin(S_TRACE);
- auto itm = selection;
- if (itm && XMLBytesTransfer.getInstance().isSupportedType(e.dataType)) { mixin(S_TRACE);
- e.data = bytesFromXML(toXML((cast(Content)itm.getData())));
- }
- }
- override void dragFinished(DragSourceEvent e) { mixin(S_TRACE);
- _dragItm = null;
- auto itm = _targ;
- if (itm && e.detail == DND.DROP_MOVE) { mixin(S_TRACE);
- bool empty = _et.owner.isEmpty;
- scope (exit) {
- if (empty != _et.owner.isEmpty) _comm.refEventTree.call(_et);
- }
- auto c = cast(Content) itm.getData();
- _comm.delContent.call(c);
- if (_parItm) { mixin(S_TRACE);
- assert (_parItm.getData());
- assert (itm.getData());
- assert ((cast(Content) _parItm.getData()).detail.owner);
- assert (cast(Content) itm.getData());
- (cast(Content) _parItm.getData()).remove(c);
- } else { mixin(S_TRACE);
- _et.remove(c);
- }
- _tree.control.setRedraw(false);
- itm.dispose();
- if (_tree.editor) { mixin(S_TRACE);
- _tree.editor.updateEventTree();
- }
- _tree.control.setRedraw(true);
- _comm.refUseCount.call();
- _comm.refreshToolBar();
- }
- }
- }
- class EventDropTarget : DropTargetAdapter {
- private:
- void move(DropTargetEvent e) { mixin(S_TRACE);
- if (_readOnly) { mixin(S_TRACE);
- e.detail = DND.DROP_NONE;
- return;
- }
- if (_tree.tree) { mixin(S_TRACE);
- e.detail = e.item ? DND.DROP_MOVE : DND.DROP_NONE;
- } else { mixin(S_TRACE);
- auto p = _tree.editor.toControl(new Point(e.x, e.y));
- auto c = _tree.editor.getContent(p.x, p.y);
- _tree.editor.updateLightup();
- e.detail = c ? DND.DROP_MOVE : DND.DROP_NONE;
- }
- }
- public:
- 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;
- e.detail = DND.DROP_NONE;
- if (!isXMLBytes(e.data)) return;
- if (!_tree.tree) { mixin(S_TRACE);
- auto p = _tree.editor.toControl(new Point(e.x, e.y));
- auto c = _tree.editor.getContent(p.x, p.y);
- if (!c) return;
- e.item = EventEditorItem.valueOf(_tree.editor, c);
- }
- assert (cast(Item)e.item);
- auto ti = cast(Item)e.item;
- if (!(cast(Content)ti.getData()).detail.owner) { mixin(S_TRACE);
- ti = _tree.getParentItem(ti);
- if (!ti) return;
- }
- if ((cast(Content)ti.getData()).detail.owner) { mixin(S_TRACE);
- try { mixin(S_TRACE);
- auto node = XNode.parse(bytesToXML(e.data));
- bool samePane = _id == node.attr("paneId", false, "");
- string id = node.attr("contentId", false, "");
- string lastNextType = node.attr("lastNextType", false, "");
- auto ver = new XMLInfo(_prop.sys, LATEST_VERSION);
- auto evt = Content.createFromNode(node, ver);
- if (evt) { mixin(S_TRACE);
- auto owner = cast(Content)ti.getData();
- assert (owner.detail.owner);
- auto sp = selParent(ti);
- if (!sp || sp.eventId != id) { mixin(S_TRACE);
- // ???????????????????????
- bool empty = _et.owner.isEmpty;
- scope (exit) {
- if (empty != _et.owner.isEmpty) _comm.refEventTree.call(_et);
- }
- if (_dragItm) { mixin(S_TRACE);
- auto top = _tree.topItem(ti);
- if (top == _tree.topItem(_dragItm)) { mixin(S_TRACE);
- store(cast(Content)top.getData());
- } else { mixin(S_TRACE);
- store(cast(Content)_tree.getParentItem(_dragItm).getData(), owner);
- }
- } else { mixin(S_TRACE);
- store(owner);
- }
- if (cast(Content)_tree.getParentItem(_dragItm).getData() !is owner) { mixin(S_TRACE);
- adjustText(owner, evt, lastNextType);
- }
- if (_box._insertFirst) { mixin(S_TRACE);
- owner.insert(_prop.parent, 0, evt);
- } else { mixin(S_TRACE);
- owner.add(_prop.parent, evt);
- }
- _comm.refContent.call(evt);
- _tree.control.setRedraw(false);
- Item itm;
- if (_tree.tree) { mixin(S_TRACE);
- itm = createTreeItem(cast(TreeItem)ti, evt, eventText(owner, evt), _prop.images.content(evt.type));
- } else { mixin(S_TRACE);
- _tree.editor.updateEventTree();
- itm = EventEditorItem.valueOf(_tree.editor, evt);
- }
- procTreeItem(itm);
- _tree.setSelection([itm]);
- refreshStatusLine();
- _comm.refUseCount.call();
- if (evt.detail.owner) { mixin(S_TRACE);
- createChilds(itm, evt);
- _tree.setExpanded(itm, true);
- }
- _tree.control.setRedraw(true);
- refreshStatusLine();
- e.detail = samePane ? DND.DROP_MOVE : DND.DROP_COPY;
- _comm.refreshToolBar();
- }
- }
- } catch (Exception e) {
- debugln(e);
- }
- }
- }
- private Content selParent(Item targ) { mixin(S_TRACE);
- auto itm = selection;
- if (itm) { mixin(S_TRACE);
- while (targ) { mixin(S_TRACE);
- if (itm == targ) { mixin(S_TRACE);
- return cast(Content)itm.getData();
- }
- targ = _tree.getParentItem(targ);
- }
- }
- return null;
- }
- }
- private void adjustText(in Content owner, Content evt, string lastNextType) { mixin(S_TRACE);
- if (_readOnly) return;
- if (!_prop.var.etc.adjustContentName) return;
- if (lastNextType != "" && owner.detail.nextType !is toCNextType(lastNextType)) { mixin(S_TRACE);
- // ???????????????????????
- evt.setName(_prop.parent, "");
- } else if (owner.detail.nextType !is CNextType.TEXT) { mixin(S_TRACE);
- foreach (ct; owner.next) { mixin(S_TRACE);
- if (ct.name == evt.name) { mixin(S_TRACE);
- // ??????????????????????
- // ????????????
- evt.setName(_prop.parent, "");
- break;
- }
- }
- }
- }
- void redraw() { mixin(S_TRACE);
- if (_tree.editor) { mixin(S_TRACE);
- _tree.editor.updateEventTree();
- } else { mixin(S_TRACE);
- _tree.control.redraw();
- }
- }
- class TRDListener : DisposeListener {
- override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
- if (!_readOnly) { mixin(S_TRACE);
- _comm.refSkin.remove(&refSkin);
- _comm.refCast.remove(&__refreshCast);
- _comm.delCast.remove(&__refreshCast);
- _comm.refSkill.remove(&__refreshSkill);
- _comm.delSkill.remove(&__refreshSkill);
- _comm.refItem.remove(&__refreshItem);
- _comm.delItem.remove(&__refreshItem);
- _comm.refBeast.remove(&__refreshBeast);
- _comm.delBeast.remove(&__refreshBeast);
- _comm.refInfo.remove(&__refreshInfo);
- _comm.delInfo.remove(&__refreshInfo);
- _comm.refArea.remove(&__refreshArea);
- _comm.delArea.remove(&__refreshArea);
- _comm.refBattle.remove(&__refreshBattle);
- _comm.delBattle.remove(&__refreshBattle);
- _comm.refPackage.remove(&__refreshPackage);
- _comm.delPackage.remove(&__refreshPackage);
- _comm.refFlagAndStep.remove(&__refreshFlagAndStep);
- _comm.delFlagAndStep.remove(&__refreshFlagAndStep);
- _comm.refPath.remove(&__refreshPath);
- _comm.refPaths.remove(&__refreshPaths);
- _comm.delPaths.remove(&__deletePaths);
- _comm.replPath.remove(&__replacePaths);
- _comm.replText.remove(&__refreshCard);
- _comm.replText.remove(&__refreshEventText);
- _comm.replID.remove(&__refreshCard);
- _comm.refContentText.remove(&refreshStatusLine);
- _comm.refPreviewValues.remove(&__refreshEventText);
- _comm.selContentTool.remove(&selContentTool);
- _comm.refEventTemplates.remove(&refreshTemplates);
- }
- _comm.refTargetVersion.remove(&redraw);
- _comm.refEventTreeViewStyle.remove(&refEventTreeViewStyle);
- if (_grayFont) _grayFont.dispose();
- foreach (dlg; _editDlgs.values) { mixin(S_TRACE);
- dlg.forceCancel();
- }
- foreach (dlg; _commentDlgs.values) { mixin(S_TRACE);
- dlg.forceCancel();
- }
- _prop.var.etc.showEventTreeDetail = _showEventTreeDetail;
- }
- }
- /// ?????????????????
- void drawStartInfo(PaintEvent e, Color lineColor, Color fontColor) { mixin(S_TRACE);
- if (!_et) return;
- assert (_tree.tree !is null);
- if (!_prop.var.etc.drawCountOfUseOfStart && !_prop.var.etc.drawContentTreeLine) return;
- auto d = _tree.control.getDisplay();
- auto ca = _tree.control.getClientArea();
- auto suc = _et.startUseCounter;
- auto fore = e.gc.getForeground();
- auto back = e.gc.getBackground();
- auto counts = new string[_tree.getItemCount()];
- auto ucExtent = e.gc.textExtent(_prop.msgs.startUseCount);
- int maxW = 0;
- int h = e.gc.getFontMetrics().getHeight();
- if (_prop.var.etc.drawCountOfUseOfStart) { mixin(S_TRACE);
- foreach (i, itm; _tree.tree.getItems()) { mixin(S_TRACE);
- auto c = cast(Content)itm.get…
Large files files are truncated, but you can click here to view the full file