Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

70
LINES

< > BotCompany Repo | #1020872 // Editor Tabs [arranges all opened editors in tabs]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6163L/29K).

1  
!7
2  
3  
sclass Tab { S name, moduleID; }
4  
5  
compact module Tabs {
6  
  transient NotifyingList<Tab> tabs;
7  
  transient JComponent grid;
8  
  S libID = "#1016118/SFEditor";
9  
  int gapBelow = 0;
10  
  
11  
  start {
12  
    if (dm_bounds() == null) dm_setBounds(100, 25, dm_desktopWidth()-200, 70);
13  
    tabs = notifyingList(r change + r updateTabs);
14  
    dm_vmBus_onMessage_q('moduleStarted, voidfunc(S moduleID) { addTabForModule(moduleID) });
15  
    dm_vmBus_onMessage_q('deletingModule, voidfunc(O module) { removeTabForModule(dm_moduleID(module)) });
16  
    dm_vmBus_onMessage_q('moduleNameChange, voidfunc(O module, S oldName, S newName) { updateTabForModule(dm_moduleID(module)) });
17  
    dm_q(r { for (S moduleID : dm_listModuleIDs()) addTabForModule(moduleID) });
18  
    dm_vmBus_onMessage_q('newActiveModule, vf<O> selectModule);
19  
  }
20  
21  
  visualize {
22  
    grid = hgridWithSpacing(); updateTabs();
23  
    ret centerAndEastWithMargins(grid, jbutton("+", rThread dm_newEditor));
24  
  }
25  
  
26  
  void updateTabs q {
27  
    if (grid == null) ret;
28  
    replaceComponentsOfHGrid(grid, map(cloneList(tabs), func(final Tab tab) -> JComponent {
29  
      componentPopupMenuItems_top(onLeftClick(
30  
        setOpaqueBackground(toColor("E0E0E0"), addInnerMargin(3, 0, jcenteredlabel(tab.name))), r { showModule(tab.moduleID) }),
31  
        "Close Tab", rThread { dm_deleteModule(tab.moduleID) })
32  
    }));
33  
    selectModule(dm_activeModule());
34  
  }
35  
36  
  void addTabForModule(S moduleID) {
37  
    if (eq(dm_moduleLibID(moduleID), libID) && !containsWhere(tabs, +moduleID)) {
38  
      tabs.add(nu(Tab, name := moduleName(moduleID), +moduleID));
39  
      if (dm_isVisible(moduleID)) placeUnderMe(moduleID);
40  
    }
41  
  }
42  
  
43  
  void removeTabForModule(S moduleID) { removeWhere(tabs, +moduleID); }
44  
  
45  
  void updateTabForModule(S moduleID) {
46  
    Tab tab = firstWhere(tabs, +moduleID);
47  
    if (tab != null) { tab.name = moduleName(moduleID); tabs.change(); }
48  
  }
49  
  
50  
  S moduleName(O module) {
51  
    ret dropPrefix("Editing: ", dm_moduleName(module));
52  
  }
53  
  
54  
  void selectModule(O module) {
55  
    if (module == null || dm_isMe(module) || !dm_isVisible()) ret;
56  
    int idx = indexOfWhere(tabs, moduleID := dm_moduleID(module));
57  
    for i over tabs: {
58  
      JComponent c = cast getComponentAtIndex(grid, i);
59  
      if (i == idx) makeBold(c); else makeNonBold(c);
60  
    }
61  
  }
62  
  
63  
  void showModule(O module) { dm_showModule(module); placeUnderMe(module); }
64  
  
65  
  void placeUnderMe(O module) {
66  
    if (!dm_isVisible()) ret;
67  
    Rect r = dm_bounds(module), me = dm_bounds();
68  
    if (me != null) dm_setBounds(module, me.x, me.y2()+gapBelow, me.w, r.h);
69  
  }
70  
}

Author comment

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: 332 / 2351
Version history: 28 change(s)
Referenced in: [show references]