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

68
LINES

< > BotCompany Repo | #1021235 // Dialog Editor

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

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

!7

cmodule DialogEditor {
  L<TypeAndText> entries = synchroList();
  S globalID = aGlobalID();
  
  transient JPanel stack;
  transient JTextArea taRaw;
  transient ReliableSingleThread rstFromRaw;

  start {
    rstFromRaw = dm_rstWithDelay(500, r { if (taRaw != null) fromRaw(getText(taRaw)) });
    onChangeAndNow(r {
      if (taRaw != null)
        setText(taRaw, toRaw());
      if (empty(entries) || nempty(last(entries).text)) {
        new TypeAndText e;
        entries.add(e); change();
        if (stack != null) addAndValidate(stack, makeLine(e));
      }
    });
  }
  
  visualize {
    stack = dynamicVStack2();
    fillStack();
    taRaw = jTypeWriterTextArea(toRaw());
    main.onChange(taRaw, rstFromRaw);
    ret centerAndSouthWithMargins(jtabs(
      "Dialog" := jscroll_trackWidth(withRightMargin(stack)),
      "Raw" := withMargin(taRaw)),
      centerAndEastWithMargin(
        withLabel("Dialog ID:", dm_textField('globalID)),
        jbutton("Save", r save));
  }
  
  void fillStack {
    if (stack == null) ret;
    removeAllComponents(stack);
    for (TypeAndText e : cloneList(entries))
      addAndValidate(stack, makeLine(e));
  }
  
  JPanel makeLine(final TypeAndText e) {
    final JComboBox cb = jcombobox(ai_lineTypes(), e.type);
    final JTextField tf = jtextfield(e.text);
    main.onChange(cb, r { e.type = selectedItem(cb); change(); });
    main.onChange(tf, r { e.text = gtt(tf); change(); });
    ret westAndCenterWithMargin(cb, tf);
  }
  
  S toRaw() {
    ret lines(nempties(map(entries, func(TypeAndText e) -> S {
      bothEmpty(e.text, e.type) ? "" : or2(e.type, "?") + ": " + unnull(e.text)
    })));
  }
  
  void fromRaw(S raw) {
    L<TypeAndText> entries = asSynchroList(ai_parseTypedDialog(raw));
    if (empty(entries) || nempty(last(entries).text)) entries.add(new TypeAndText);
    if (setField(+entries)) fillStack();
  }
  
  void save {
    if (emptyAfterTrim(globalID)) setField(globalID := aGlobalID());
    dm_requireAndCallModule("#1021238/DialogsCRUD", 'saveDialog, globalID, toRaw());
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1021235
Snippet name: Dialog Editor
Eternal ID of this version: #1021235/34
Text MD5: cc70176fedf057473773b96c0caa5239
Transpilation MD5: 7c693e2fdc923a636fac4c5800321f9f
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-05 14:23:59
Source code size: 2128 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 333 / 1039
Version history: 33 change(s)
Referenced in: [show references]