/cwxeditor_src/cwx/editor/gui/dwt/dockingfolder.d
D | 1480 lines | 1322 code | 47 blank | 111 comment | 286 complexity | 33415c8e31422d5f81c4c6db7075d6d4 MD5 | raw file
Possible License(s): LGPL-2.1
- module cwx.editor.gui.dwt.dockingfolder;
- import cwx.utils;
- import cwx.xml;
- import cwx.editor.gui.dwt.splitpane;
- import cwx.editor.gui.dwt.centerlayout;
- import org.eclipse.swt.all;
- import java.lang.all;
- import std.algorithm;
- import std.file;
- import std.string;
- import std.conv;
- import std.ascii;
- alias DockingFolder!(CTabFolder, SWT.BORDER | SWT.FLAT | SWT.CLOSE) DockingFolderCTC;
- /// ???
- enum Dir {
- N, /// ??
- E, /// ??
- S, /// ??
- W /// ??
- }
- private string dirToString(Dir dir) { mixin(S_TRACE);
- final switch (dir) {
- case Dir.N: return "north";
- case Dir.E: return "east";
- case Dir.S: return "south";
- case Dir.W: return "west";
- }
- }
- private Dir stringToDir(string s) { mixin(S_TRACE);
- switch (.toLower(s)) {
- case "north": return Dir.N;
- case "east": return Dir.E;
- case "south": return Dir.S;
- case "west": return Dir.W;
- default: return Dir.N;
- }
- }
- /// Control???????????????????????
- enum NewCtrlLocation {
- Right, /// ?????????????
- Last /// ?????????
- }
- /// ??????????????????
- private struct CtrlMemory {
- string pane;
- string pairPane;
- Dir dir;
- int lWeight = 1;
- int rWeight = 1;
- }
- /// ???????????????
- private struct PaneMemory {
- string pairPane;
- Dir dir;
- int lWeight = 1;
- int rWeight = 1;
- }
- class DockingFolder(TabF, int Style) {
- static if (is(TabF == TabFolder)) {
- alias TabItem Tab;
- } else static if (is(TabF == CTabFolder)) {
- alias CTabItem Tab;
- } else static assert (0);
- private static const CLOSE = Style & SWT.CLOSE;
- private enum DPos {N, E, S, W, C, NONE}
- private Composite _comp, _area;
- private string[Control] _ctrls;
- private Control[string] _keys;
- private string[TabF] _tabfs;
- private TabF[string] _tKeys;
- private TabF[] _tabfList;
- private string[SplitPane] _sashs;
- private SplitPane[string] _sKeys;
- private CtrlMemory[string] _cMemories;
- private PaneMemory[string] _pMemories;
- private Canvas _canvas;
- private FocusL _fl;
- private this (Composite parent, int style, bool createTabf, string firstPaneKey = "") { mixin(S_TRACE);
- _comp = new Composite(parent, SWT.NONE);
- _comp.setLayout(new CenterLayout(SWT.HORIZONTAL | SWT.VERTICAL, 0));
- _canvas = new Canvas(_comp, SWT.TRANSPARENT | SWT.NO_BACKGROUND);
- _canvas.setLayoutData(new CenterLayoutData(true, true));
- _canvas.setVisible(false);
- auto drop = new DropTarget(_canvas, DND.DROP_MOVE);
- drop.setTransfer([TextTransfer.getInstance()]);
- drop.addDropListener(new DTL);
- _canvas.addPaintListener(new PL);
- _area = new Composite(_comp, style);
- _area.addListener(SWT.Dispose, new DListener);
- _area.setLayoutData(new CenterLayoutData(true, true));
- _area.setLayout(new FillLayout);
- if (createTabf) newTabf(_area, firstPaneKey);
- _fl = new FocusL;
- Display.getCurrent().addFilter(SWT.FocusIn, _fl);
- }
- private bool _canSave = true;
- private class DListener : Listener {
- override void handleEvent(Event e) { mixin(S_TRACE);
- Display.getCurrent().removeFilter(SWT.FocusIn, _fl);
- if (_canSave) { mixin(S_TRACE);
- try { mixin(S_TRACE);
- saveTree();
- } catch (Exception e) {
- debugln(e);
- }
- }
- }
- }
- /// ???????????
- /// firstPaneKey?""????????????key???????
- this (Composite parent, int style, string firstPaneKey = "") { mixin(S_TRACE);
- this (parent, style, true, firstPaneKey);
- }
- /// key???????????????
- private static string prefix(string key) { mixin(S_TRACE);
- while (key.length && (.isDigit(key[$ - 1]) || '_' == key[$ - 1])) { mixin(S_TRACE);
- auto u = '_' == key[$ - 1];
- key = key[0 .. $ - 1];
- if (u) break;
- }
- return key;
- } unittest { mixin(S_TRACE);
- assert (prefix("abc_123") == "abc");
- assert (prefix("ab_c_123") == "ab_c");
- assert (prefix("abc") == "abc");
- }
- /// ???????key????????
- string newPaneKey(string prefix) { mixin(S_TRACE);
- int i = 0;
- string key = prefix;
- while (key in _tKeys && key in _sKeys) { mixin(S_TRACE);
- i++;
- key = .format("%s_%s", prefix, i);
- }
- return key;
- }
- /// ???Control?key????????
- string newCtrlKey(string prefix) { mixin(S_TRACE);
- int i = 0;
- string key = prefix;
- while (key in _keys) { mixin(S_TRACE);
- i++;
- key = .format("%s_%s", prefix, i);
- }
- return key;
- }
- /// Control????????????????????delegate?
- /// null??????????????
- /// ctrlKey??????Control?key??dropPaneKey??????
- /// key??????????????????dropPaneKey?""????
- bool delegate (string ctrlKey, string dropPaneKey) canMove = null;
- /// ????????????????????????????
- /// ???????delegate?
- /// ""??????????????
- string delegate (string ctrlKey, string basePane, Dir dir) newPaneName = null;
- private string newTabfKey(string prefix = "t") { mixin(S_TRACE);
- string key;
- int i = _tabfs.length;
- do { mixin(S_TRACE);
- key = .format("%s_%d", prefix, i);
- i++;
- } while (key in _tKeys);
- return key;
- }
- /// ??????????
- @property
- Composite[] panes() {return cast(Composite[]) _tabfList;}
- /// ditto
- @property
- string[] paneKeys() {return _tKeys.keys;}
- /// key????????????
- /// ????????null????
- Composite pane(string key) { mixin(S_TRACE);
- auto p = key in _tKeys;
- return p ? *p : null;
- }
- /// ????key????
- /// ???????????""????
- string key(Composite pane) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane;
- if (!tabf) throw new Exception("Invalid composite");
- auto p = tabf in _tabfs;
- return p ? *p : "";
- }
- /// paneKey?????????????Control?key????
- /// ?????????""????
- string selectedCtrl(string paneKey) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane(paneKey);
- if (!tabf) return "";
- auto sel = selected(tabf);
- if (!sel) return "";
- return _ctrls[sel.getControl()];
- }
- /// paneKey???????(?????????)?????
- /// Control???????key????
- /// ????????""????
- string control(string paneKey, int x, int y) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane(paneKey);
- if (!tabf) return "";
- auto itm = tabf.getItem(tabf.toControl(x, y));
- if (!itm) return "";
- return _ctrls[itm.getControl()];
- }
- /// key?????Control????
- /// ????????null????
- Control control(string key) { mixin(S_TRACE);
- auto p = key in _keys;
- return p ? *p : null;
- }
- /// Control?key????
- /// ????Control????""????
- string keyFromCtrl(Control ctrl) { mixin(S_TRACE);
- auto p = ctrl in _ctrls;
- return p ? *p : "";
- }
- /// ???Control????
- @property
- Control[] allControls() {return _ctrls.keys;}
- /// ditto
- @property
- string[] controlKeys() {return _keys.keys;}
- /// ?????????????Control????
- Control[] controls(string key) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane(key);
- if (!tabf) return [];
- Control[] r;
- foreach (tab; tabf.getItems()) { mixin(S_TRACE);
- r ~= tab.getControl();
- }
- return r;
- }
- /// ditto
- string[] controlKeys(string key) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane(key);
- if (!tabf) return [];
- string[] r;
- foreach (tab; tabf.getItems()) { mixin(S_TRACE);
- r ~= _ctrls[tab.getControl()];
- }
- return r;
- }
- /// ?????????????Control???
- /// ????????????0????
- int controlCount(string key) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane(key);
- if (!tabf) return 0;
- return tabf.getItemCount();
- }
- /// ???????????????????
- @property
- Control[] showingControls() { mixin(S_TRACE);
- Control[] r;
- foreach (tabf; _tabfList) { mixin(S_TRACE);
- auto tab = selected(tabf);
- if (tab) r ~= tab.getControl();
- }
- return r;
- }
- private Tab tab(string key) { mixin(S_TRACE);
- auto p = key in _keys;
- if (!p) return null;
- foreach (tab; (cast(TabF) p.getParent()).getItems()) { mixin(S_TRACE);
- if (tab.getControl() is *p) { mixin(S_TRACE);
- return tab;
- }
- }
- assert (0, "dockingfolder#tab");
- }
- /// key?????Control?????????????
- /// ????Control????????false????
- bool tabText(string key, string text) { mixin(S_TRACE);
- auto t = tab(key);
- if (t) { mixin(S_TRACE);
- t.setText(text);
- return true;
- }
- return false;
- }
- /// key?????Control???????????
- /// ????Control????????null????
- string tabText(string key) { mixin(S_TRACE);
- auto t = tab(key);
- return t ? t.getText() : null;
- }
- /// key?????Control?????????????
- /// ????Control????????false????
- bool tabImage(string key, Image image) { mixin(S_TRACE);
- auto t = tab(key);
- if (t) { mixin(S_TRACE);
- t.setImage(image);
- return true;
- }
- return false;
- }
- /// key?????Control???????????
- /// ???????????????
- /// ????Control????????null????
- Image tabText(string key) { mixin(S_TRACE);
- auto t = tab(key);
- return t ? t.getImage() : null;
- }
- /// ????????
- @property
- Composite first() {return panes[0];}
- /// ditto
- @property
- string firstKey() {return _tabfs[cast(TabF) first];}
- /// ???????????Composite?
- @property
- Composite area() {return _comp;}
- private bool vanish(string key) { mixin(S_TRACE);
- return canVanish ? canVanish(key) : true;
- }
- /// ????????????????????????????
- /// false????????????
- bool delegate(string key) closeTabWithMiddleClick = null;
- /// key???????????????????
- /// false???????????????????????
- bool delegate(string key) canVanish = null;
- /// ?????????????????????????true????
- bool delegate(string key) memoryControl = null;
- /// ditto
- bool delegate(string key) memoryPane = null;
- /// ???base?????dir????????????
- /// Param:
- /// lWeight, rWeight = ?????????????
- /// key = ???????key?""??????????????????
- /// ????????????"t"+??("t%d")???????
- /// Returns: ?????????
- Composite addPane(string base, Dir dir, int lWeight = 1, int rWeight = 1, string key = "") { mixin(S_TRACE);
- return addPane(pane(base), dir, lWeight, rWeight, key);
- }
- /// ditto
- Composite addPane(Composite base, Dir dir, int lWeight = 1, int rWeight = 1, string key = "") { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- if (key in _tKeys || key in _sKeys) throw new Exception("invalid key");
- int style = dir == Dir.N || dir == Dir.S ? SWT.VERTICAL : SWT.HORIZONTAL;
- bool before = dir == Dir.N || dir == Dir.W;
- if (!key.length) key = newTabfKey("t");
- auto r = newSash(base, style, before, lWeight, rWeight, key);
- _area.layout(true);
- return r;
- }
- /// key??????????????????????
- /// key?????????????????????????????????????
- /// ????????base1???base2????????????????
- Composite addPaneFromMemory(string base1, string base2, Dir dir, int lWeight, int rWeight, string key) { mixin(S_TRACE);
- auto s = findPane2(key);
- if (s) return s;
- auto preKey = prefix(key);
- auto memory = preKey in _pMemories;
- scope (exit) {
- if (memory) _pMemories.remove(preKey);
- }
- auto base = base1;
- if (memory) { mixin(S_TRACE);
- dir = memory.dir;
- base = memory.pairPane;
- lWeight = memory.lWeight;
- rWeight = memory.rWeight;
- }
- auto pair = findPane2(base);
- if (!pair) { mixin(S_TRACE);
- auto panes = findPane(base1);
- if (!panes.length) { mixin(S_TRACE);
- panes = findPane(base2);
- }
- pair = this.pane(panes[0]);
- }
- return addPane(pair, dir, lWeight, rWeight, newPaneKey(key));
- }
- /// key???????Control???????????????
- /// key???????Control??????????????????????????
- /// Control???????????????????????????????????
- Composite addPaneFromCtrlMemory(string base, Dir dir, int lWeight, int rWeight, string paneKey, string ctrlKey) { mixin(S_TRACE);
- auto s = findPane2(paneKey);
- if (s) return s;
- auto cs = findCtrl(ctrlKey);
- if (cs.length) { mixin(S_TRACE);
- return tab(cs[0]).getParent();
- }
- auto preKey = prefix(ctrlKey);
- auto memory = preKey in _cMemories;
- scope (exit) {
- if (memory) _cMemories.remove(preKey);
- }
- if (memory) { mixin(S_TRACE);
- paneKey = memory.pane;
- dir = memory.dir;
- base = memory.pairPane;
- lWeight = memory.lWeight;
- rWeight = memory.rWeight;
- }
- auto pane = findPane2(paneKey);
- if (pane) return pane;
- return addPaneFromMemory(base, base, dir, lWeight, rWeight, paneKey);
- }
- /// Control??????
- /// ctrl???????????????????????????????
- void add(Control ctrl, string tabText, string key, bool select = false, NewCtrlLocation loc = NewCtrlLocation.Last) { mixin(S_TRACE);
- add(ctrl, tabText, null, key, select);
- }
- /// ditto
- void add(Control ctrl, string tabText, Image tabImage, string key, bool select = false, NewCtrlLocation loc = NewCtrlLocation.Last) { mixin(S_TRACE);
- if (!key.length || (key in _keys)) throw new Exception("invalid key: " ~ key);
- auto tabf = cast(TabF) ctrl.getParent();
- if (!tabf) throw new Exception("no tabfolder");
- Tab tab;
- final switch (loc) {
- case NewCtrlLocation.Right:
- auto sel = selected(tabf);
- if (!sel) goto case NewCtrlLocation.Last;
- tab = new Tab(tabf, SWT.NONE, tabf.indexOf(sel) + 1);
- break;
- case NewCtrlLocation.Last:
- tab = new Tab(tabf, SWT.NONE);
- break;
- }
- tab.setText(tabText);
- tab.setImage(tabImage);
- tab.setControl(ctrl);
- _ctrls[ctrl] = key;
- _keys[key] = ctrl;
- if (select) { mixin(S_TRACE);
- this.select(key);
- }
- }
- /// ?????Control???????????????????????
- /// ?????????????pane?????????????
- /// pane?????pairPane????????????????????????
- void addFromMemory(Control delegate(Composite) createControl, string tabText, Image tabImage, string key, string pane, string pairPane, Dir dir, bool select = false, NewCtrlLocation loc = NewCtrlLocation.Last) { mixin(S_TRACE);
- if (!key.length || (key in _keys)) throw new Exception("invalid key: " ~ key);
- Composite p;
- auto memory = key in _cMemories;
- scope (exit) {
- if (memory) _cMemories.remove(key);
- }
- string tPane = pairPane;
- pane = newPaneKey(pane);
- if (memory) { mixin(S_TRACE);
- pane = memory.pane;
- dir = memory.dir;
- pairPane = memory.pairPane;
- }
- p = findPane2(pane);
- if (!p) { mixin(S_TRACE);
- int l, r;
- if (memory) { mixin(S_TRACE);
- l = memory.lWeight;
- r = memory.rWeight;
- } else { mixin(S_TRACE);
- if (dir == Dir.N || dir == Dir.W) { mixin(S_TRACE);
- l = 1;
- r = dir == Dir.N ? 3 : 4;
- } else { mixin(S_TRACE);
- l = dir == Dir.S ? 3 : 4;
- r = 1;
- }
- }
- p = addPaneFromMemory(pairPane, tPane, dir, l, r, pane);
- }
- auto c = createControl(p);
- if (!c) throw new Exception("No control: " ~ key);
- this.add(c, tabText, tabImage, key, select, loc);
- }
- /// key?????????menu??????
- void setMenu(string key, Menu menu) { mixin(S_TRACE);
- auto p = pane(key);
- if (p) p.setMenu(menu);
- }
- /// prefix?????????key??????
- string[] findPane(string prefix) { mixin(S_TRACE);
- string[] r;
- foreach (key, pane; _tKeys) { mixin(S_TRACE);
- if (std.string.startsWith(key, prefix)) { mixin(S_TRACE);
- r ~= key;
- }
- }
- return r;
- }
- /// prefix????????????????sash????
- private Composite findPane2(string prefix) { mixin(S_TRACE);
- auto p = prefix in _sKeys;
- if (p) return *p;
- auto p2 = prefix in _tKeys;
- if (p2) return *p2;
- auto panes = findPane(prefix);
- return panes.length ? pane(panes[0]) : null;
- }
- /// prefix?????Control?key??????
- string[] findCtrl(string prefix) { mixin(S_TRACE);
- string[] r;
- foreach (key, ctrl; _keys) { mixin(S_TRACE);
- if (std.string.startsWith(key, prefix)) { mixin(S_TRACE);
- r ~= key;
- }
- }
- return r;
- }
- /// key?Control??????
- bool select(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- tab.getParent().setSelection(tab);
- return true;
- }
- /// key???Control??????
- bool walkLeft(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- auto tabf = tab.getParent();
- int count = tabf.getItemCount();
- if (count <= 1) return false;
- int index = tabf.indexOf(tab);
- index = index == 0 ? count - 1 : index - 1;
- return select(keyFromCtrl(tabf.getItem(index).getControl()));
- }
- /// key???Control??????
- bool walkRight(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- auto tabf = tab.getParent();
- int count = tabf.getItemCount();
- if (count <= 1) return false;
- int index = tabf.indexOf(tab);
- index = index + 1 == count ? 0 : index + 1;
- return select(keyFromCtrl(tabf.getItem(index).getControl()));
- }
- /// Control?????????????????Control????????false????
- bool close(string key) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- auto t = tab(key);
- if (t) { mixin(S_TRACE);
- close(t);
- t.dispose();
- return true;
- }
- return false;
- }
- /// key??????Control?????
- bool hasEtc(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- return tab.getParent().getItems().length > 1;
- }
- /// key??????Control?????
- void closeEtc(string key) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- auto tab = this.tab(key);
- if (!tab) return;
- foreach (i, t; tab.getParent().getItems()) { mixin(S_TRACE);
- if (t !is tab) { mixin(S_TRACE);
- close(t);
- t.dispose();
- }
- }
- }
- /// key????Control?????
- bool hasLeft(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- auto i = tab.getParent().indexOf(tab);
- if (-1 == i) return false;
- return 0 < i;
- }
- /// key????Control?????
- void closeLeft(string key) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- auto tab = this.tab(key);
- if (!tab) return;
- auto i = tab.getParent().indexOf(tab);
- if (i <= 0) return;
- foreach (t; tab.getParent().getItems()[0 .. i]) { mixin(S_TRACE);
- close(t);
- t.dispose();
- }
- }
- /// key????Control?????
- bool hasRight(string key) { mixin(S_TRACE);
- auto tab = this.tab(key);
- if (!tab) return false;
- auto i = tab.getParent().indexOf(tab);
- if (-1 == i) return false;
- return i + 1 < tab.getParent().getItemCount();
- }
- /// key????Control?????
- void closeRight(string key) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- auto tab = this.tab(key);
- if (!tab) return;
- auto i = tab.getParent().indexOf(tab);
- if (i >= tab.getParent().getItemCount() - 1) return;
- foreach (t; tab.getParent().getItems()[i + 1 .. $]) { mixin(S_TRACE);
- close(t);
- t.dispose();
- }
- }
- /// key??????????Control?????
- void closeAll(string key) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- auto tab = this.tab(key);
- if (!tab) return;
- foreach (t; tab.getParent().getItems()) { mixin(S_TRACE);
- close(t);
- t.dispose();
- }
- }
- /// ???????????????key??????????
- void delegate(string)[] createPaneEvent;
- /// createPaneEvent???????
- /// ???????????????????????????
- void addCreatePaneEvent(void delegate(string) createPaneEvent) { mixin(S_TRACE);
- this.createPaneEvent ~= createPaneEvent;
- foreach (key; _tabfs) { mixin(S_TRACE);
- createPaneEvent(key);
- }
- }
- /// Control??????????Control?key??????????
- void delegate(string)[] selectEvent;
- /// Control??????????Control?key??????????
- /// false?????????????
- bool delegate(string)[] closeCtrlEvent;
- private TabF newTabf(Composite parent, string key) { mixin(S_TRACE);
- if (!key.length) key = newTabfKey("t");
- auto tabf = new TabF(parent, Style | SWT.NO_MERGE_PAINTS);
- _tKeys[key] = tabf;
- _tabfs[tabf] = key;
- _tabfList ~= tabf;
- static if (CLOSE) {
- static if (is(TabF : CTabFolder)) {
- tabf.addCTabFolderListener(new CTFL);
- }
- }
- tabf.addSelectionListener(new SelTab);
- tabf.addMouseListener(new ClickTab);
- auto drag = new DragSource(tabf, DND.DROP_MOVE);
- drag.setTransfer([TextTransfer.getInstance()]);
- drag.addDragListener(new DSL(tabf));
- foreach (dlg; createPaneEvent) { mixin(S_TRACE);
- dlg(key);
- }
- return tabf;
- }
- private Tab _dragItm = null;
- private DPos _dropPos = DPos.NONE;
- private DPos _drawPos = DPos.NONE;
- private TabF _drawTabf = null;
- private void removeTabf(TabF tabf, bool memory) { mixin(S_TRACE);
- if (memory && memoryPane && memoryPane(_tabfs[tabf])) { mixin(S_TRACE);
- PaneMemory m;
- m.pairPane = pairKey(tabf, m.dir, m.lWeight, m.rWeight);
- if ("" != m.pairPane) { mixin(S_TRACE);
- _pMemories[prefix(_tabfs[tabf])] = m;
- }
- }
- tabf.dispose();
- _tabfList = cwx.utils.remove!("a is b")(_tabfList, tabf);
- auto key = _tabfs[tabf];
- _tKeys.remove(key);
- _tabfs.remove(tabf);
- reconstruct();
- }
- private class CTFL : CTabFolderListener {
- void itemClosed(CTabFolderEvent e) { mixin(S_TRACE);
- _comp.setRedraw(false);
- scope (exit) _comp.setRedraw(true);
- close(cast(Tab) e.item);
- }
- }
- /// tabf????????????????????tabf???????
- /// ???????""????
- private string pairKey(TabF tabf, out Dir dir, out int lWeight, out int rWeight) { mixin(S_TRACE);
- auto comp = cast(SplitPane) tabf.getParent();
- if (comp) { mixin(S_TRACE);
- auto ws = comp.getWeights();
- lWeight = ws[0];
- rWeight = ws[1];
- auto cs = comp.getChildren();
- if (comp.getStyle() & SWT.VERTICAL) { mixin(S_TRACE);
- dir = cs[0] is tabf ? Dir.N : Dir.S;
- } else { mixin(S_TRACE);
- dir = cs[0] is tabf ? Dir.W : Dir.E;
- }
- Control pair;
- if (cs[0] is tabf) { mixin(S_TRACE);
- pair = cs[1];
- } else { mixin(S_TRACE);
- pair = cs[0];
- }
- return cast(TabF) pair ? _tabfs[cast(TabF) pair] : _sashs[cast(SplitPane) pair];
- }
- return "";
- }
- private void close(Tab tab) { mixin(S_TRACE);
- auto ctrl = tab.getControl();
- auto ctrlKey = keyFromCtrl(ctrl);
- foreach (evt; closeCtrlEvent) { mixin(S_TRACE);
- if (!evt(ctrlKey)) return;
- }
- auto tabf = tab.getParent();
- auto key = _tabfs[tabf];
- auto van = vanish(key);
- // ??
- if (van && memoryControl && memoryControl(ctrlKey)) { mixin(S_TRACE);
- CtrlMemory memory;
- memory.pairPane = pairKey(tabf, memory.dir, memory.lWeight, memory.rWeight);
- if ("" != memory.pairPane) { mixin(S_TRACE);
- memory.pane = _tabfs[tabf];
- _cMemories[ctrlKey] = memory;
- }
- }
- // ??
- _ctrls.remove(tab.getControl());
- _keys.remove(ctrlKey);
- tab.getControl().dispose();
- if (tabf.getItemCount() == 1 && _area.getChildren()[0] !is tabf) { mixin(S_TRACE);
- if (van) { mixin(S_TRACE);
- removeTabf(tabf, true);
- _area.layout(true);
- }
- }
- }
- @property
- private string newSashKey() { mixin(S_TRACE);
- int i = 0;
- while (true) { mixin(S_TRACE);
- string sKey = .format("sash_%d", i);
- if (sKey !in _sKeys && sKey !in _tKeys) return sKey;
- i++;
- }
- }
- private void putSashTable(SplitPane sash, string sKey) { mixin(S_TRACE);
- _sKeys[sKey] = sash;
- _sashs[sash] = sKey;
- sash.addDisposeListener(new class DisposeListener {
- override void widgetDisposed(DisposeEvent e) { mixin(S_TRACE);
- _sKeys.remove(sKey);
- _sashs.remove(sash);
- }
- });
- }
- /// Control????????
- private void reconstruct() { mixin(S_TRACE);
- void tree(Control ctrl) { mixin(S_TRACE);
- auto comp = cast(SplitPane) ctrl;
- if (!comp) return;
- Control[] children;
- foreach (ch; comp.getChildren()) { mixin(S_TRACE);
- if (!ch.isDisposed() && !(cast(Sash) ch)) { mixin(S_TRACE);
- children ~= ch;
- }
- }
- if (children.length == 1) { mixin(S_TRACE);
- auto aft = afters(comp);
- children[0].setParent(comp.getParent());
- addAfters(aft);
- comp.dispose();
- tree(children[0]);
- } else if (children.length == 2) { mixin(S_TRACE);
- // _area.layout(true)???????????
- // SplitPane?????????????
- auto aft = afters(comp);
- auto weights = comp.getWeights();
- auto sash = new SplitPane(comp.getParent(), comp.getStyle());
- auto key = _sashs[comp];
- addAfters(aft);
- foreach (c; children) { mixin(S_TRACE);
- c.setParent(sash);
- }
- comp.dispose();
- putSashTable(sash, key);
- foreach (child; children) tree(child);
- sash.setWeights(weights);
- } else { mixin(S_TRACE);
- assert (!children.length, "dockingfolder#reconstruct");
- comp.dispose();
- }
- }
- tree(_area.getChildren()[0]);
- }
- private void drawDropMark(GC gc, int x, int y, int w, int h) { mixin(S_TRACE);
- auto d = Display.getCurrent();
- gc.setBackground(d.getSystemColor(SWT.COLOR_BLACK));
- gc.setAlpha(0xff / 2);
- gc.setLineWidth(5);
- final switch (_drawPos) {
- case DPos.C: gc.fillRectangle(x, y, w, h); break;
- case DPos.N: gc.fillRectangle(x, y, w, h / 2); break;
- case DPos.E: gc.fillRectangle(x + w / 2, y, w / 2, h); break;
- case DPos.S: gc.fillRectangle(x, y + h / 2, w, h / 2); break;
- case DPos.W: gc.fillRectangle(x, y, w / 2, h); break;
- case DPos.NONE: break;
- }
- }
- private bool canDrop(TabF tabf) { mixin(S_TRACE);
- if (!_dragItm) return false;
- if (_dropPos == DPos.NONE) return false;
- if (canMove) { mixin(S_TRACE);
- auto p = _dragItm.getControl() in _ctrls;
- if (!p) return false;
- auto ctrlKey = *p;
- auto dropPaneKey = _dropPos == DPos.C ? _tabfs[tabf] : "";
- return canMove(ctrlKey, dropPaneKey);
- }
- return true;
- }
- private class PL : PaintListener {
- override void paintControl(PaintEvent e) { mixin(S_TRACE);
- if (!_drawTabf) return;
- if (!canDrop(_drawTabf)) return;
- auto pos = boundsOnCanvas(_drawTabf);
- auto ca = _drawTabf.getClientArea();
- drawDropMark(e.gc, pos.x + ca.x, pos.y + ca.y, ca.width, ca.height);
- }
- }
- private class DSL : DragSourceListener {
- private TabF _tabf;
- this (TabF tabf) {_tabf = tabf;}
- override void dragStart(DragSourceEvent e) { mixin(S_TRACE);
- e.doit = false;
- auto itm = _tabf.getItem(new Point(e.x, e.y));
- if (itm) { mixin(S_TRACE);
- _dragItm = itm;
- e.doit = true;
- _canvas.setVisible(true);
- }
- }
- override void dragSetData(DragSourceEvent e) { mixin(S_TRACE);
- if (_dragItm) { mixin(S_TRACE);
- e.data = new ArrayWrapperString(_dragItm.getText());
- }
- }
- override void dragFinished(DragSourceEvent e) { mixin(S_TRACE);
- _drawTabf = null;
- _canvas.setVisible(false);
- _comp.layout(true);
- if (e.detail == DND.DROP_MOVE) { mixin(S_TRACE);
- auto tabf = _dragItm.getParent();
- _dragItm.dispose();
- _dragItm = null;
- if (tabf.getItemCount() == 0 && vanish(_tabfs[tabf])) { mixin(S_TRACE);
- removeTabf(tabf, false);
- }
- _area.layout(true);
- }
- }
- }
- private static Control[] afters(Control targ) { mixin(S_TRACE);
- auto pcs = targ.getParent().getChildren();
- int pi = .cCountUntil!("a is b")(pcs, targ);
- assert (pi != -1, "dockingfolder#afters");
- return pcs[pi + 1 .. $];
- }
- private static void addAfters(Control[] afters) { mixin(S_TRACE);
- foreach (ac; afters) { mixin(S_TRACE);
- auto par = ac.getParent();
- ac.setParent(ac.getParent().getParent());
- ac.setParent(par);
- }
- }
- private static void setInsertMark(TabF tabf, Tab tab, bool after) { mixin(S_TRACE);
- static if (is(typeof(tabf.setInsertMark(tab, after)))) {
- tabf.setInsertMark(tab, after);
- }
- }
- private static Tab selected(TabF tabf) { mixin(S_TRACE);
- static if (is(typeof(tabf.getSelection()) == Tab)) {
- return tabf.getSelection();
- } else { mixin(S_TRACE);
- auto tabs = tabf.getSelection();
- return tabs && tabs.length ? tabs[0] : null;
- }
- }
- private Rectangle boundsOnDisplay(Control ctrl) { mixin(S_TRACE);
- auto p = ctrl.toDisplay(0, 0);
- auto s = ctrl.getSize();
- return new Rectangle(p.x, p.y, s.x, s.y);
- }
- private Rectangle boundsOnCanvas(Control ctrl) { mixin(S_TRACE);
- auto cvp = _canvas.toDisplay(0, 0);
- auto cp = ctrl.toDisplay(0, 0);
- auto s = ctrl.getSize();
- return new Rectangle(cp.x - cvp.x, cp.y - cvp.y, s.x, s.y);
- }
- private class DTL : DropTargetAdapter {
- override void dragEnter(DropTargetEvent e) { mixin(S_TRACE);
- dragOver(e);
- }
- override void dragLeave(DropTargetEvent e) { mixin(S_TRACE);
- e.detail = DND.DROP_NONE;
- _drawPos = DPos.NONE;
- _drawTabf = null;
- _canvas.redraw();
- }
- private TabF getTabf(int x, int y) { mixin(S_TRACE);
- foreach (t; _tabfList) { mixin(S_TRACE);
- if (boundsOnDisplay(t).contains(x, y)) { mixin(S_TRACE);
- return t;
- }
- }
- return null;
- }
- override void dragOver(DropTargetEvent e) { mixin(S_TRACE);
- auto drawTabf = _drawTabf;
- auto dropPos = _dropPos;
- _dropPos = DPos.NONE;
- e.detail = DND.DROP_NONE;
- auto tabf = getTabf(e.x, e.y);
- _drawTabf = tabf;
- if (tabf) { mixin(S_TRACE);
- auto p = tabf.toControl(e.x, e.y);
- auto itm = tabf.getItem(p);
- if (itm) { mixin(S_TRACE);
- setInsertMark(tabf, itm, false);
- _dropPos = DPos.C;
- } else { mixin(S_TRACE);
- setInsertMark(tabf, null, false);
- auto ca = tabf.getClientArea();
- auto size = tabf.getSize();
- int x = p.x, y = p.y;
- int w = size.x, h = size.y;
- int xn = w - x, yn = h - y;
- if (y < ca.y || (tabf is _dragItm.getParent() && tabf.getItemCount() == 1)) { mixin(S_TRACE);
- _dropPos = DPos.C;
- if (tabf.getItemCount() > 0) { mixin(S_TRACE);
- int index = tabf.getItemCount() - 1;
- setInsertMark(tabf, tabf.getItem(index), true);
- }
- } else if (y <= x && y <= xn && y < h / 3) { mixin(S_TRACE);
- _dropPos = DPos.N;
- } else if (xn <= y && xn <= yn && x > w - w / 3) { mixin(S_TRACE);
- _dropPos = DPos.E;
- } else if (yn <= x && yn <= xn && y > h - h / 3) { mixin(S_TRACE);
- _dropPos = DPos.S;
- } else if (x <= y && x <= yn && x < w / 3) { mixin(S_TRACE);
- _dropPos = DPos.W;
- } else if (0 <= x && 0 <= y && x < w && y < h) { mixin(S_TRACE);
- _dropPos = DPos.C;
- }
- }
- if (!canDrop(tabf)) _dropPos = DPos.NONE;
- if (_dropPos != DPos.NONE) e.detail = DND.DROP_MOVE;
- }
- if (_dropPos != dropPos || _drawTabf !is drawTabf) { mixin(S_TRACE);
- _drawPos = _dropPos;
- _canvas.redraw();
- }
- }
- override void drop(DropTargetEvent e) { mixin(S_TRACE);
- e.detail = DND.DROP_NONE;
- scope (exit) {
- _drawTabf = null;
- _drawPos = DPos.NONE;
- _dropPos = DPos.NONE;
- }
- if (_dropPos == DPos.NONE || !e.data || !_dragItm) return;
- auto dropTarg = getTabf(e.x, e.y);
- if (!dropTarg) return;
- if (!canDrop(dropTarg)) return;
- auto sash = dropTarg.getParent();
- void newTab(TabF tabf, int index) { mixin(S_TRACE);
- auto tab = index != -1
- ? new Tab(tabf, _dragItm.getStyle(), index)
- : new Tab(tabf, _dragItm.getStyle());
- auto c = _dragItm.getControl();
- c.setParent(tabf);
- { mixin(S_TRACE);
- _onNewTab = true;
- scope (exit) _onNewTab = false;
- _dragItm.setControl(null);
- }
- tab.setControl(c);
- tab.setText(_dragItm.getText());
- tab.setImage(_dragItm.getImage());
- tabf.setSelection(tab);
- if (tabf.getShell() is tabf.getDisplay().getActiveShell()) { mixin(S_TRACE);
- tabf.setFocus();
- }
- }
- int putCenter() { mixin(S_TRACE);
- auto dropItm = dropTarg.getItem(dropTarg.toControl(e.x, e.y));
- if (dropItm is _dragItm) return DND.DROP_NONE;
- int i1 = dropItm ? .cCountUntil!("a is b")(dropTarg.getItems(), dropItm) : dropTarg.getItemCount();
- if (dropTarg is _dragItm.getParent()) { mixin(S_TRACE);
- int i2 = .cCountUntil!("a is b")(dropTarg.getItems(), _dragItm);
- if (i2 + 1 == i1) return DND.DROP_NONE;
- }
- newTab(dropTarg, dropItm ? i1 : -1);
- return DND.DROP_MOVE;
- }
- int nSash(int style, bool before) { mixin(S_TRACE);
- if (dropTarg is _dragItm.getParent() && dropTarg.getItemCount() == 1) { mixin(S_TRACE);
- return DND.DROP_NONE;
- }
- if (newPaneName) { mixin(S_TRACE);
- auto ctrlKey = _ctrls[_dragItm.getControl()];
- Dir dir;
- switch (_dropPos) {
- case DPos.N: dir = Dir.N; break;
- case DPos.E: dir = Dir.E; break;
- case DPos.S: dir = Dir.S; break;
- case DPos.W: dir = Dir.W; break;
- default: assert (0);
- }
- }
- string newKey = newTabfKey(prefix(key(_dragItm.getParent())));
- auto tabf = newSash(dropTarg, style, before, 1, 1, newKey);
- newTab(tabf, -1);
- if (tabf.getShell() is tabf.getDisplay().getActiveShell()) { mixin(S_TRACE);
- tabf.setFocus();
- }
- return DND.DROP_MOVE;
- }
- switch (_dropPos) {
- case DPos.N: { mixin(S_TRACE);
- e.detail = nSash(SWT.VERTICAL, true);
- } break;
- case DPos.E: { mixin(S_TRACE);
- e.detail = nSash(SWT.HORIZONTAL, false);
- } break;
- case DPos.S: { mixin(S_TRACE);
- e.detail = nSash(SWT.VERTICAL, false);
- } break;
- case DPos.W: { mixin(S_TRACE);
- e.detail = nSash(SWT.HORIZONTAL, true);
- } break;
- case DPos.C: { mixin(S_TRACE);
- e.detail = putCenter();
- } break;
- default: break;
- }
- }
- }
- private bool _onNewTab = false;
- private class SelTab : SelectionAdapter {
- override void widgetSelected(SelectionEvent e) { mixin(S_TRACE);
- auto tabf = cast(TabF) e.widget;
- if (tabf.isFocusControl()) selectTab(tabf);
- }
- }
- private class ClickTab : MouseAdapter {
- override void mouseDown(MouseEvent e) { mixin(S_TRACE);
- auto tabf = cast(TabF) e.widget;
- if (tabf.getShell() is tabf.getDisplay().getActiveShell()) { mixin(S_TRACE);
- tabf.setFocus();
- }
- }
- override void mouseUp(MouseEvent e) { mixin(S_TRACE);
- if (e.button != 2) return;
- auto tabf = cast(TabF)e.widget;
- auto ca = tabf.getClientArea();
- if (ca.y <= e.y) return;
- auto tab = tabf.getItem(new Point(e.x, e.y));
- if (!tab) return;
- auto ctrl = tab.getControl();
- if (!ctrl) return;
- auto key = keyFromCtrl(ctrl);
- if (!key) return;
- if (closeTabWithMiddleClick && !closeTabWithMiddleClick(key)) return;
- close(key);
- }
- }
- private class FocusL : Listener {
- override void handleEvent(Event e) { mixin(S_TRACE);
- void control(Control ctrl) { mixin(S_TRACE);
- if (ctrl.getShell() !is area.getShell()) return;
- auto pane = cast(Composite) ctrl;
- if (!pane) pane = ctrl.getParent();
- while (pane) { mixin(S_TRACE);
- auto tabf = cast(TabF) pane;
- if (tabf && tabf in _tabfs) { mixin(S_TRACE);
- selectTab(tabf);
- break;
- }
- pane = pane.getParent();
- }
- }
- auto ctrl = Display.getCurrent().getFocusControl();
- if (ctrl) { mixin(S_TRACE);
- control(ctrl);
- } else { mixin(S_TRACE);
- _oldSel = "";
- }
- }
- }
- private string _oldSel = "";
- private void selectTab(TabF tabf) { mixin(S_TRACE);
- if (_onNewTab) return;
- auto tab = selected(tabf);
- if (!tab) return;
- if (tab.isDisposed()) return;
- auto ctrl = tab.getControl();
- auto key = keyFromCtrl(ctrl);
- if (!key.length) return;
- if (_oldSel != key) { mixin(S_TRACE);
- _oldSel = key;
- foreach (ls; selectEvent) { mixin(S_TRACE);
- ls(_ctrls[ctrl]);
- }
- }
- }
- private TabF newSash(Composite targ, int style, bool before, int lWeight, int rWeight, string key) { mixin(S_TRACE);
- auto parent = targ.getParent();
- int[] weights;
- auto sashf = cast(SplitPane) parent;
- if (sashf) weights = sashf.getWeights();
- scope (exit) if(sashf) sashf.setWeights(weights);
- auto aft = afters(targ);
- auto nSash = new SplitPane(parent, style);
- putSashTable(nSash, newSashKey);
- addAfters(aft);
- TabF r;
- if (before) { mixin(S_TRACE);
- r = newTabf(nSash, key);
- targ.setParent(nSash);
- } else { mixin(S_TRACE);
- targ.setParent(nSash);
- r = newTabf(nSash, key);
- }
- nSash.setWeights([lWeight, rWeight]);
- return r;
- }
- private static struct Tabf {
- string key;
- int select;
- Tabi[] tabs;
- }
- private static struct Tabi {
- string key;
- string name;
- }
- private static struct Sashf {
- string key;
- bool vertical;
- int lWeight;
- int rWeight;
- Sashf* lSash;
- Tabf* lTabf;
- Sashf* rSash;
- Tabf* rTabf;
- }
- private static struct Area {
- Sashf* sash;
- Tabf* tabf;
- }
- private Area* _tree = null;
- private void saveTree() { mixin(S_TRACE);
- auto area = new Area;
- saveTree(_area.getChildren()[0], area.sash, area.tabf);
- assert ((area.sash || area.tabf) && !(area.sash && area.tabf), "dockingfolder#saveTree 1");
- _tree = area;
- }
- private void saveTree(Control c, out Sashf* sa, out Tabf* ta) { mixin(S_TRACE);
- auto sash = cast(SplitPane) c;
- if (sash) { mixin(S_TRACE);
- sa = new Sashf;
- ta = null;
- sa.key = _sashs[sash];
- sa.vertical = (sash.getStyle() & SWT.VERTICAL) != 0;
- auto weights = sash.getWeights();
- sa.lWeight = weights[0];
- sa.rWeight = weights[1];
- bool left = true;
- assert (sash.getChildren().length == 3, "dockingfolder#saveTree 2");
- foreach (child; sash.getChildren()) { mixin(S_TRACE);
- if (!(cast(Sash) child)) { mixin(S_TRACE);
- if (left) { mixin(S_TRACE);
- saveTree(child, sa.lSash, sa.lTabf);
- left = false;
- } else { mixin(S_TRACE);
- saveTree(child, sa.rSash, sa.rTabf);
- break;
- }
- }
- }
- assert ((sa.lSash || sa.lTabf) && !(sa.lSash && sa.lTabf), "dockingfolder#saveTree 3");
- assert ((sa.rSash || sa.rTabf) && !(sa.rSash && sa.rTabf), "dockingfolder#saveTree 4");
- } else { mixin(S_TRACE);
- ta = new Tabf;
- sa = null;
- auto tabf = cast(TabF) c;
- assert (tabf, "dockingfolder#saveTree 5");
- ta.key = _tabfs[tabf];
- ta.select = tabf.getSelectionIndex();
- ta.tabs.length = tabf.getItemCount();
- foreach (i, tab; tabf.getItems()) { mixin(S_TRACE);
- ta.tabs[i].key = _ctrls[tab.getControl()];
- ta.tabs[i].name = tab.getText();
- }
- }
- }
- /// XML?????????dispose????????
- /// exclude???????????????????????
- XNode toNode(string[] exclude = []) { mixin(S_TRACE);
- auto r = XNode.create("dockingFolder");
- toNodeImpl(r, exclude);
- return r;
- }
- /// ditto
- XNode toNode(ref XNode parent, string[] exclude = []) { mixin(S_TRACE);
- auto r = parent.newElement("dockingFolder");
- toNodeImpl(r, exclude);
- return r;
- }
- private XNode toNodeImpl(ref XNode r, string[] exclude) { mixin(S_TRACE);
- if (!_area.isDisposed()) { mixin(S_TRACE);
- saveTree();
- }
- if (_cMemories.length) { mixin(S_TRACE);
- auto ctrlM = r.newElement("controlMemories");
- foreach (key, memory; _cMemories) { mixin(S_TRACE);
- auto e = ctrlM.newElement("controlMemory", key);
- e.newAttr("pane", memory.pane);
- e.newAttr("pairPane", memory.pairPane);
- e.newAttr("dir", dirToString(memory.dir));
- e.newAttr("lWeight", memory.lWeight);
- e.newAttr("rWeight", memory.rWeight);
- }
- }
- if (_pMemories.length) { mixin(S_TRACE);
- auto paneM = r.newElement("paneMemories");
- foreach (key, memory; _pMemories) { mixin(S_TRACE);
- auto e = paneM.newElement("paneMemory", key);
- e.newAttr("pairPane", memory.pairPane);
- e.newAttr("dir", dirToString(memory.dir));
- e.newAttr("lWeight", memory.lWeight);
- e.newAttr("rWeight", memory.rWeight);
- }
- }
- assert (_tree, "dockingfolder#toNodeImpl");
- if (_tree.sash) { mixin(S_TRACE);
- return toNodeImpl(r, _tree.sash, exclude);
- } else { mixin(S_TRACE);
- return toNodeImpl(r, _tree.tabf, exclude);
- }
- }
- private XNode toNodeImpl(ref XNode parent, Sashf* sa, string[] exclude) { mixin(S_TRACE);
- auto r = parent.newElement("sash");
- r.newAttr("key", sa.key);
- r.newAttr("type", sa.vertical ? VERTICAL : HORIZONTAL);
- r.newAttr("lWeight", sa.lWeight);
- r.newAttr("rWeight", sa.rWeight);
- void n(Sashf* sa, Tabf* ta) { mixin(S_TRACE);
- if (sa) { mixin(S_TRACE);
- toNodeImpl(r, sa, exclude);
- } else { mixin(S_TRACE);
- toNodeImpl(r, ta, exclude);
- }
- }
- n(sa.lSash, sa.lTabf);
- n(sa.rSash, sa.rTabf);
- return r;
- }
- private XNode toNodeImpl(ref XNode parent, Tabf* ta, string[] exclude) { mixin(S_TRACE);
- auto r = parent.newElement("tabs");
- if (ta.select >= 0) r.newAttr("select", ta.select);
- r.newAttr("key", ta.key);
- bool sc(string name) { mixin(S_TRACE);
- foreach (ex; exclude) { mixin(S_TRACE);
- if (std.string.startsWith(name, ex)) return true;
- }
- return false;
- }
- foreach (tab; ta.tabs) { mixin(S_TRACE);
- if (sc(tab.key)) continue;
- auto t = r.newElement("tab");
- t.newAttr("key", tab.key);
- t.newAttr("name", tab.name);
- }
- return r;
- }
- private static const HORIZONTAL = "horizontal";
- private static const VERTICAL = "vertical";
- private static struct Proc {
- DockingFolder r;
- Composite par;
- Control delegate(Composite, string) create;
- void delegate(string, TabF) addRemoveList;
- void sash(ref XNode node) { mixin(S_TRACE);
- string dStr = .text(__LINE__);
- try { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- string type = node.attr("type", true);
- /// FIXME: ??? type == VERTICAL ??????????????
- dStr ~= " - " ~ .text(__LINE__);
- auto sash = new SplitPane(par, type == VERTICAL ? SWT.VERTICAL : SWT.HORIZONTAL);
- r.putSashTable(sash, node.attr("key", false, r.newSashKey));
- dStr ~= " - " ~ .text(__LINE__);
- Proc proc;
- proc.r = r;
- proc.par = sash;
- proc.create = create;
- proc.addRemoveList = addRemoveList;
- node.onTag["sash"] = &proc.sash;
- node.onTag["tabs"] = &proc.tabs;
- dStr ~= " - " ~ .text(__LINE__);
- node.parse();
- dStr ~= " - " ~ .text(__LINE__);
- sash.setWeights([node.attr!(int)("lWeight", true), node.attr!(int)("rWeight", true)]);
- dStr ~= " - " ~ .text(__LINE__);
- } catch (Throwable e) {
- fdebugln(dStr);
- fdebugln(e);
- throw new Exception(dStr, __FILE__, __LINE__);
- }
- }
- void tabs(ref XNode node) { mixin(S_TRACE);
- string dStr = .text(__LINE__);
- try { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- auto key = node.attr("key", true);
- dStr ~= " - " ~ key ~ " - " ~ .text(__LINE__);
- auto tabf = r.newTabf(par, key);
- dStr ~= " - " ~ .text(__LINE__);
- node.onTag["tab"] = (ref XNode node) { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- auto key = node.attr("key", true);
- dStr ~= " - " ~ .text(__LINE__);
- auto v = create(tabf, key);
- dStr ~= " - " ~ .text(__LINE__);
- if (v) r.add(v, node.attr("name", true), key);
- dStr ~= " - " ~ .text(__LINE__);
- };
- dStr ~= " - " ~ .text(__LINE__);
- node.parse();
- dStr ~= " - " ~ .text(__LINE__);
- auto i = node.attr!(int)("select", false, -1);
- if (0 < tabf.getItemCount()) { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- i = std.algorithm.max(i, 0);
- i = std.algorithm.min(i, tabf.getItemCount() - 1);
- tabf.setSelection(i);
- } else { mixin(S_TRACE);
- addRemoveList(key, tabf);
- }
- dStr ~= " - " ~ .text(__LINE__);
- } catch (Throwable e) {
- fdebugln(dStr);
- fdebugln(e);
- throw new Exception(dStr, __FILE__, __LINE__);
- }
- }
- }
- /// XML????????????
- /// Param:
- /// create = XML?????Control?key????????
- /// ?????Control???????delegate?
- static DockingFolder fromNode(ref XNode node, Composite parent, int style,
- bool delegate(typeof(this), string) canVanish,
- Control delegate(Composite, string) create,
- void delegate(string) createPaneEvent = null) { mixin(S_TRACE);
- string dStr = .text(__LINE__);
- try { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- assert (node.name == "dockingFolder", "dockingfolder#fromNode");
- DockingFolder r = null;
- try { mixin(S_TRACE);
- r = new DockingFolder(parent, style, false);
- node.onTag["controlMemories"] = (ref XNode node) { mixin(S_TRACE);
- node.onTag["controlMemory"] = (ref XNode e) { mixin(S_TRACE);
- string key = e.value;
- CtrlMemory memory;
- memory.pane = e.attr("pane", false);
- memory.pairPane = e.attr("pairPane", false);
- memory.dir = stringToDir(e.attr("dir", false));
- string lw = e.attr("lWeight", false);
- string rw = e.attr("rWeight", false);
- if (lw.length && isNumeric(lw)) memory.lWeight = .parse!int(lw);
- if (rw.length && isNumeric(rw)) memory.rWeight = .parse!int(rw);
- r._cMemories[key] = memory;
- };
- node.parse();
- };
- node.onTag["paneMemories"] = (ref XNode node) { mixin(S_TRACE);
- node.onTag["paneMemory"] = (ref XNode e) { mixin(S_TRACE);
- string key = e.value;
- PaneMemory memory;
- memory.pairPane = e.attr("pairPane", false);
- memory.dir = stringToDir(e.attr("dir", false));
- string lw = e.attr("lWeight", false);
- string rw = e.attr("rWeight", false);
- if (lw.length && isNumeric(lw)) memory.lWeight = .parse!int(lw);
- if (rw.length && isNumeric(rw)) memory.rWeight = .parse!int(rw);
- r._pMemories[key] = memory;
- };
- node.parse();
- };
- dStr ~= " - " ~ .text(__LINE__);
- if (createPaneEvent) r.createPaneEvent ~= createPaneEvent;
- TabF[] removeList;
- Proc proc;
- proc.r = r;
- proc.par = r._area;
- proc.create = create;
- proc.addRemoveList = (string key, TabF tabf) { mixin(S_TRACE);
- if (!canVanish || canVanish(r, key)) { mixin(S_TRACE);
- removeList ~= tabf;
- }
- };
- node.onTag["sash"] = &proc.sash;
- node.onTag["tabs"] = &proc.tabs;
- dStr ~= " - " ~ .text(__LINE__);
- node.parse();
- dStr ~= " - " ~ .text(__LINE__);
- foreach (tabf; removeList) { mixin(S_TRACE);
- r.removeTabf(tabf, true);
- }
- dStr ~= " - " ~ .text(__LINE__);
- return r;
- } catch (Exception e) {
- dStr ~= " - " ~ .text(__LINE__);
- if (r && r.area) { mixin(S_TRACE);
- dStr ~= " - " ~ .text(__LINE__);
- r._canSave = false;
- r.area.dispose();
- }
- dStr ~= " - " ~ .text(__LINE__);
- throw e;
- }
- dStr ~= " - " ~ .text(__LINE__);
- } catch (Throwable e) {
- fdebugln(dStr);
- fdebugln(e);
- throw new Exception(dStr, __FILE__, __LINE__);
- }
- }
- }