Transpiled version (9533L) is out of date.
!7 abstract sclass DynTabs extends DynModule { sclass Tab { S name, moduleID; } transient NotifyingList<Tab> tabs; transient JComponent grid; Set<S> tabbableLibIDs = syncTreeSet(); int gapBelow = 0; transient O isTabbableModule; // func(module) -> bool bool isTabbableModule(O mod) { if (isTabbableModule != null) ret isTrue(callF(isTabbableModule, mod)); ret contains(tabbableLibIDs, dm_moduleLibID(mod)); } void start2 {} start { initialBounds(); tabs = notifyingList(r change + r updateTabs); start2(); dm_vmBus_onMessage_q('moduleStarted, voidfunc(S moduleID) { addTabForModule(moduleID) }); dm_vmBus_onMessage_q('deletingModule, voidfunc(O module) { removeTabForModule(dm_moduleID(module)) }); dm_vmBus_onMessage_q('moduleNameChange, voidfunc(O module, S oldName, S newName) { updateTabForModule(dm_moduleID(module)) }); dm_q(r { for (S moduleID : dm_listModuleIDs()) addTabForModule(moduleID) }); dm_vmBus_onMessage_q('newActiveModule, vf<O> selectModule); } void initialBounds { if (dm_bounds() == null) dm_setBounds(100, 25, dm_desktopWidth()-200, 70); } visualize { grid = hgridWithSpacing(); updateTabs(); new L l; for (fS libID : tabbableLibIDs) addAll(l, libID, rThread { dm_showNewModule(libID) }); ret centerAndEastWithMargins(grid, jPopDownButton("+", toObjectArray(l))); } void updateTabs q { if (grid == null) ret; replaceComponentsOfHGrid(grid, map(cloneList(tabs), func(final Tab tab) -> JComponent { JLabel lbl = setOpaqueBackground(toColor("E0E0E0"), addInnerMargin(3, 0, jcenteredlabel(tab.name))); onLeftClick(lbl, r { showModule(tab.moduleID) }); componentPopupMenuItems_top(lbl, "Close Tab", rThread { dm_deleteModule(tab.moduleID) }, disableMenuItemTextIf(tab == first(tabs), "Move Left"), rThread { syncMoveElementLeft(tabs, tab) }, disableMenuItemTextIf(tab == last(tabs), "Move Right"), rThread { syncMoveElementRight(tabs, tab) }); ret lbl; })); selectModule(dm_activeModule()); } void addTabForModule(S moduleID) { if (isTabbableModule(moduleID) && !containsWhere(tabs, +moduleID)) { tabs.add(nu Tab(name := moduleName(moduleID), +moduleID)); if (dm_isVisible(moduleID)) placeUnderMe(moduleID); } } void removeTabForModule(S moduleID) { removeWhere(tabs, +moduleID); } void updateTabForModule(S moduleID) { Tab tab = firstWhere(tabs, +moduleID); if (tab != null) { tab.name = moduleName(moduleID); tabs.change(); } } S moduleName(O module) { ret dropPrefix("Editing: ", dm_moduleName(module)); } void selectModule(O module) { if (module == null || dm_isMe(module) || !dm_isVisible()) ret; int idx = indexOfWhere(tabs, moduleID := dm_moduleID(module)); for i over tabs: { JComponent c = cast getComponentAtIndex(grid, i); if (i == idx) makeBold(c); else makeNonBold(c); } } void showModule(O module) { dm_showModule(module); placeUnderMe(module); } void placeUnderMe(O module) { if (!dm_isVisible()) ret; Rect r = dm_bounds(module), me = dm_bounds(); if (me != null && r != null) dm_setBounds(module, me.x, me.y2()+gapBelow, me.w, r.h); } }
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: | 334 / 856 |
Version history: | 9 change(s) |
Referenced in: | [show references] |