Uses 911K of libraries. Click here for Pure Java version (6163L/29K).
!7 sclass Tab { S name, moduleID; } compact module Tabs { transient NotifyingList<Tab> tabs; transient JComponent grid; S libID = "#1016118/SFEditor"; int gapBelow = 0; start { if (dm_bounds() == null) dm_setBounds(100, 25, dm_desktopWidth()-200, 70); tabs = notifyingList(r change + r updateTabs); 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); } visualize { grid = hgridWithSpacing(); updateTabs(); ret centerAndEastWithMargins(grid, jbutton("+", rThread dm_newEditor)); } void updateTabs q { if (grid == null) ret; replaceComponentsOfHGrid(grid, map(cloneList(tabs), func(final Tab tab) -> JComponent { componentPopupMenuItems_top(onLeftClick( setOpaqueBackground(toColor("E0E0E0"), addInnerMargin(3, 0, jcenteredlabel(tab.name))), r { showModule(tab.moduleID) }), "Close Tab", rThread { dm_deleteModule(tab.moduleID) }) })); selectModule(dm_activeModule()); } void addTabForModule(S moduleID) { if (eq(dm_moduleLibID(moduleID), libID) && !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) dm_setBounds(module, me.x, me.y2()+gapBelow, me.w, r.h); } }
Began life as a copy of #1020860
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020872 |
Snippet name: | Editor Tabs [arranges all opened editors in tabs] |
Eternal ID of this version: | #1020872/29 |
Text MD5: | b6ecc1c9ba7fb3ab165283159c09368b |
Transpilation MD5: | b05b90e20c8bd98c2283912a8095687c |
Author: | stefan |
Category: | javax / stefan's os |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-01-06 17:28:09 |
Source code size: | 2617 bytes / 70 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 388 / 2422 |
Version history: | 28 change(s) |
Referenced in: | [show references] |