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

95
LINES

< > BotCompany Repo | #1027094 // "Unclear" List / "Multi-list" [list that varies by context]

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

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

1  
!7
2  
3  
// manage an "unclear" list (one that varies by context),
4  
// e.g. the list of known first names
5  
6  
srecord Entry(S name, S comment) {}
7  
8  
cmodule UnclearList > DynObjectTable<Entry> {
9  
  switchable S description = "First names"; // plural of what we are storing
10  
11  
  // mech list that may contain useful items for us
12  
  L<WithComment<S>> possibleMechLists = syncList();
13  
14  
  visual
15  
    jhsplit(withCenteredButtons(
16  
        jCenteredSection("Current items", super),
17  
        "Clear", rThreadEnter { quickBackup(); clear(); },
18  
        "Add...", rThreadEnter {
19  
          JTextField tfName = jTextField();
20  
          JTextField tfComment = jTextField();
21  
          
22  
          showFormTitled("Add " + itemDesc(),
23  
            itemDesc(), tfName,
24  
            "Comment", tfComment,
25  
            r { addItem(gtt(tfName), gtt(tfComment)) })
26  
        },
27  
        "Copy to clipboard", rThreadEnter { copyTextToClipboard(lines(collect name(list()))) },
28  
        jPopDownButton_noText(
29  
          "Edit...", rThreadEnter {
30  
            Entry e = selected();
31  
            if (e == null) ret;
32  
            JTextField tfName = jTextField(e.name);
33  
            JTextField tfComment = jTextField(e.comment);
34  
            
35  
            showFormTitled("Edit " + itemDesc(),
36  
              itemDesc(), tfName,
37  
              "Comment", tfComment,
38  
              r { e.name = gtt(tfName); e.comment = gtt(tfComment); fireDataChanged(); });
39  
          },
40  
          "Delete", rThreadEnter { remove(selected()) },
41  
          "Copy to clipboard as paragraphs", rThreadEnter { copyTextToClipboard(joinWithEmptyLines(collect name(list()))) },
42  
          "Upload as list...", rThreadEnter uploadAsList)
43  
        ),
44  
      withCenteredButtons(
45  
         jCenteredSection("Possible lists", dm_calculatedTextArea(() ->
46  
            lines(possibleMechLists))),
47  
            "Clear", rThreadEnter { quickBackup(); possibleMechLists.clear(); change(); },
48  
            "Add...", rThreadEnter {
49  
              dm_selectMechList("Mech list of " + description, voidfunc(S name) {
50  
                addPossibleMechList(name, "") // TODO: comment
51  
              });
52  
            }, "Load all lists", rThreadEnter loadAllPossibleLists));
53  
54  
  start {
55  
    dm_useFieldAsTitle description();
56  
    dm_vmBus_answerToMessage unclearListModuleOf(
57  
      func(S type) -> S { eqic(type, description) ? dm_moduleID(module()) : null });
58  
  }
59  
60  
  void uploadAsList {
61  
    inputText("List name to upload to", voidfunc(S listName) {
62  
      if (empty(listName = trim(listName))) ret;
63  
      infoBox(editMechList(listName, lines(collect name(list()))));
64  
    });
65  
  }
66  
  
67  
  // API
68  
69  
  void addItem(S name, S comment) {
70  
    add(new Entry(name, comment));
71  
  }
72  
73  
  void removeItem(S name) {
74  
    remove(objectWhere(list(), +name));
75  
  }
76  
77  
  void addPossibleMechList(S name, S comment) {
78  
    possibleMechLists.add(WithComment(comment, name));
79  
    change();
80  
  }
81  
82  
  Set<S> itemsSet() {
83  
    ret collectAsCISet name(list());
84  
  }
85  
86  
  void loadAllPossibleLists {
87  
    Set<S> known = itemsSet();
88  
    for (S listName : getAllVars(possibleMechLists))
89  
      addAll(mapNonNulls(mL(listName), x -> known.contains(x) ? null
90  
        : new Entry(x, "from " + quote(listName))));
91  
  }
92  
93  
  S itemDesc() { ret singular(description); }
94  
95  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027094
Snippet name: "Unclear" List / "Multi-list" [list that varies by context]
Eternal ID of this version: #1027094/31
Text MD5: e29cba31efac3da72752dae740226ad4
Transpilation MD5: d21088c21fa87e67ddcc7c78141db5b3
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-04-16 11:09:47
Source code size: 3285 bytes / 95 lines
Pitched / IR pitched: No / No
Views / Downloads: 240 / 959
Version history: 30 change(s)
Referenced in: [show references]