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).

!7

// manage an "unclear" list (one that varies by context),
// e.g. the list of known first names

srecord Entry(S name, S comment) {}

cmodule UnclearList > DynObjectTable<Entry> {
  switchable S description = "First names"; // plural of what we are storing

  // mech list that may contain useful items for us
  L<WithComment<S>> possibleMechLists = syncList();

  visual
    jhsplit(withCenteredButtons(
        jCenteredSection("Current items", super),
        "Clear", rThreadEnter { quickBackup(); clear(); },
        "Add...", rThreadEnter {
          JTextField tfName = jTextField();
          JTextField tfComment = jTextField();
          
          showFormTitled("Add " + itemDesc(),
            itemDesc(), tfName,
            "Comment", tfComment,
            r { addItem(gtt(tfName), gtt(tfComment)) })
        },
        "Copy to clipboard", rThreadEnter { copyTextToClipboard(lines(collect name(list()))) },
        jPopDownButton_noText(
          "Edit...", rThreadEnter {
            Entry e = selected();
            if (e == null) ret;
            JTextField tfName = jTextField(e.name);
            JTextField tfComment = jTextField(e.comment);
            
            showFormTitled("Edit " + itemDesc(),
              itemDesc(), tfName,
              "Comment", tfComment,
              r { e.name = gtt(tfName); e.comment = gtt(tfComment); fireDataChanged(); });
          },
          "Delete", rThreadEnter { remove(selected()) },
          "Copy to clipboard as paragraphs", rThreadEnter { copyTextToClipboard(joinWithEmptyLines(collect name(list()))) },
          "Upload as list...", rThreadEnter uploadAsList)
        ),
      withCenteredButtons(
         jCenteredSection("Possible lists", dm_calculatedTextArea(() ->
            lines(possibleMechLists))),
            "Clear", rThreadEnter { quickBackup(); possibleMechLists.clear(); change(); },
            "Add...", rThreadEnter {
              dm_selectMechList("Mech list of " + description, voidfunc(S name) {
                addPossibleMechList(name, "") // TODO: comment
              });
            }, "Load all lists", rThreadEnter loadAllPossibleLists));

  start {
    dm_useFieldAsTitle description();
    dm_vmBus_answerToMessage unclearListModuleOf(
      func(S type) -> S { eqic(type, description) ? dm_moduleID(module()) : null });
  }

  void uploadAsList {
    inputText("List name to upload to", voidfunc(S listName) {
      if (empty(listName = trim(listName))) ret;
      infoBox(editMechList(listName, lines(collect name(list()))));
    });
  }
  
  // API

  void addItem(S name, S comment) {
    add(new Entry(name, comment));
  }

  void removeItem(S name) {
    remove(objectWhere(list(), +name));
  }

  void addPossibleMechList(S name, S comment) {
    possibleMechLists.add(WithComment(comment, name));
    change();
  }

  Set<S> itemsSet() {
    ret collectAsCISet name(list());
  }

  void loadAllPossibleLists {
    Set<S> known = itemsSet();
    for (S listName : getAllVars(possibleMechLists))
      addAll(mapNonNulls(mL(listName), x -> known.contains(x) ? null
        : new Entry(x, "from " + quote(listName))));
  }

  S itemDesc() { ret singular(description); }

}

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: 238 / 955
Version history: 30 change(s)
Referenced in: