Transpiled version (9533L) is out of date.
1 | !7 |
2 | |
3 | abstract sclass DynTabs extends DynModule { |
4 | sclass Tab { S name, moduleID; } |
5 | |
6 | transient NotifyingList<Tab> tabs; |
7 | transient JComponent grid; |
8 | Set<S> tabbableLibIDs = syncTreeSet(); |
9 | int gapBelow = 0; |
10 | transient O isTabbableModule; // func(module) -> bool |
11 | |
12 | bool isTabbableModule(O mod) { |
13 | if (isTabbableModule != null) ret isTrue(callF(isTabbableModule, mod)); |
14 | ret contains(tabbableLibIDs, dm_moduleLibID(mod)); |
15 | } |
16 | |
17 | void start2 {} |
18 | |
19 | start { |
20 | initialBounds(); |
21 | tabs = notifyingList(r change + r updateTabs); |
22 | start2(); |
23 | dm_vmBus_onMessage_q('moduleStarted, voidfunc(S moduleID) { addTabForModule(moduleID) }); |
24 | dm_vmBus_onMessage_q('deletingModule, voidfunc(O module) { removeTabForModule(dm_moduleID(module)) }); |
25 | dm_vmBus_onMessage_q('moduleNameChange, voidfunc(O module, S oldName, S newName) { updateTabForModule(dm_moduleID(module)) }); |
26 | dm_q(r { for (S moduleID : dm_listModuleIDs()) addTabForModule(moduleID) }); |
27 | dm_vmBus_onMessage_q('newActiveModule, vf<O> selectModule); |
28 | } |
29 | |
30 | void initialBounds { |
31 | if (dm_bounds() == null) dm_setBounds(100, 25, dm_desktopWidth()-200, 70); |
32 | } |
33 | |
34 | visualize { |
35 | grid = hgridWithSpacing(); updateTabs(); |
36 | new L l; |
37 | for (fS libID : tabbableLibIDs) |
38 | addAll(l, libID, rThread { dm_showNewModule(libID) }); |
39 | ret centerAndEastWithMargins(grid, jPopDownButton("+", toObjectArray(l))); |
40 | } |
41 | |
42 | void updateTabs q { |
43 | if (grid == null) ret; |
44 | replaceComponentsOfHGrid(grid, map(cloneList(tabs), func(final Tab tab) -> JComponent { |
45 | JLabel lbl = setOpaqueBackground(toColor("E0E0E0"), addInnerMargin(3, 0, jcenteredlabel(tab.name))); |
46 | onLeftClick(lbl, r { showModule(tab.moduleID) }); |
47 | componentPopupMenuItems_top(lbl, |
48 | "Close Tab", rThread { dm_deleteModule(tab.moduleID) }, |
49 | disableMenuItemTextIf(tab == first(tabs), "Move Left"), rThread { syncMoveElementLeft(tabs, tab) }, |
50 | disableMenuItemTextIf(tab == last(tabs), "Move Right"), rThread { syncMoveElementRight(tabs, tab) }); |
51 | ret lbl; |
52 | })); |
53 | selectModule(dm_activeModule()); |
54 | } |
55 | |
56 | void addTabForModule(S moduleID) { |
57 | if (isTabbableModule(moduleID) && !containsWhere(tabs, +moduleID)) { |
58 | tabs.add(nu Tab(name := moduleName(moduleID), +moduleID)); |
59 | if (dm_isVisible(moduleID)) placeUnderMe(moduleID); |
60 | } |
61 | } |
62 | |
63 | void removeTabForModule(S moduleID) { removeWhere(tabs, +moduleID); } |
64 | |
65 | void updateTabForModule(S moduleID) { |
66 | Tab tab = firstWhere(tabs, +moduleID); |
67 | if (tab != null) { tab.name = moduleName(moduleID); tabs.change(); } |
68 | } |
69 | |
70 | S moduleName(O module) { |
71 | ret dropPrefix("Editing: ", dm_moduleName(module)); |
72 | } |
73 | |
74 | void selectModule(O module) { |
75 | if (module == null || dm_isMe(module) || !dm_isVisible()) ret; |
76 | int idx = indexOfWhere(tabs, moduleID := dm_moduleID(module)); |
77 | for i over tabs: { |
78 | JComponent c = cast getComponentAtIndex(grid, i); |
79 | if (i == idx) makeBold(c); else makeNonBold(c); |
80 | } |
81 | } |
82 | |
83 | void showModule(O module) { dm_showModule(module); placeUnderMe(module); } |
84 | |
85 | void placeUnderMe(O module) { |
86 | if (!dm_isVisible()) ret; |
87 | Rect r = dm_bounds(module), me = dm_bounds(); |
88 | if (me != null && r != null) dm_setBounds(module, me.x, me.y2()+gapBelow, me.w, r.h); |
89 | } |
90 | } |
Began life as a copy of #1020872
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1021504 |
Snippet name: | DynTabs [arranges certain modules in tabs] |
Eternal ID of this version: | #1021504/10 |
Text MD5: | f7853f06ad935db93f4314053af8dd08 |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-02-19 15:51:36 |
Source code size: | 3354 bytes / 90 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 335 / 857 |
Version history: | 9 change(s) |
Referenced in: | [show references] |