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

86
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 803K of libraries. Click here for Pure Java version (14236L/75K).

!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()))) })
        ),
      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 });
  }

  // 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   

Travelled to 3 computer(s): mqqgnosmbjvj, tvejysmllsmz, 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/30
Text MD5: 85a1a6de478e925cdd0a31a8c54f7a91
Transpilation MD5: e63f17c413910e1ae04fbff5efa3bb3c
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-23 12:01:10
Source code size: 3009 bytes / 86 lines
Pitched / IR pitched: No / No
Views / Downloads: 29 / 594
Version history: 29 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1027094 & http://1027094.tinybrain.de