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

160
LINES

< > BotCompany Repo | #1015549 // Snippet Editor v2 [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 6678K of libraries. Click here for Pure Java version (11289L/82K).

1  
!7
2  
3  
sS snippetID;
4  
sS savedText, remoteText;
5  
static EditorFrame e;
6  
static int caretPos;
7  
static SimpleLiveValue<S> lvSnippetID = new(S.class);
8  
static int fontSize = 16;
9  
static AutoCompletion autoCompletion;
10  
static ReliableSingleThread rstAutoComplete = new(f installAutoComplete);
11  
sbool installAutoComplete_first;
12  
static Set<S> autoComplete_lastSet;
13  
14  
p-substance {
15  
  autoRestart();
16  
  load('savedText);
17  
  load('fontSize);
18  
  
19  
  e = new EditorFrame;
20  
  e._setFontSize(fontSize);
21  
  rstAutoComplete.trigger();
22  
  onChange(e.textArea, rTrigger(rstAutoComplete));
23  
  
24  
  e.setText(savedText);
25  
  load('caretPos);
26  
  setCaretPosition(e.textArea, caretPos);
27  
  showFrame(e);
28  
  frameIcon(e, #1101185 /*#1004655*/);
29  
  
30  
  addMenu(e, "New", "New text", f newText);
31  
32  
  addMenu(e, "Load", "Load snippet...", r {
33  
    selectSnippetID(vf1(f _loadSnippet));
34  
  });
35  
  
36  
  addMenu(e, "Save", mapLiveValue(func(S s) -> S { "Save snippet " + s }, S.class, lvSnippetID) /*"Save snippet"*/, r { saveSnippetThen(null) });
37  
  
38  
  addMenu(e, "Transpile",
39  
    "Save & Quick Transpile", r { transpile(false) },
40  
    "Save & Medium Transpile", r { transpile(true) });
41  
  addMenu(e, "Activate", "Butter-Reload", f _butterReload);
42  
  
43  
  addMenu(e, "View",
44  
    "Bigger font", r { e._setFontSize(setAndSave(fontSize := e._getFontSize()+1)) },
45  
    "Smaller font", r { e._setFontSize(setAndSave(fontSize := max(1, e._getFontSize()-1))) });
46  
  
47  
  S snippetID = cast readPersistentVar('snippetID);
48  
  if (snippetID != null) _loadSnippet_noSet(snippetID);
49  
50  
  hideConsole();
51  
  
52  
  awtCalcEvery(e, 1000, f update);
53  
  onFrameDeactivated(e, f fullUpdate);
54  
}
55  
56  
svoid update { update(windowActive(e)); }
57  
svoid fullUpdate { update(true); }
58  
svoid update(bool full) {
59  
  S text = e.getText();
60  
  setAndSaveIfChanged(savedText := text);
61  
  setAndSaveIfChanged(caretPos := getCaretPosition(e.textArea));
62  
    
63  
  if (!full) ret;
64  
  S status = remoteText != null && neq(remoteText, text) ? "Changes. " : "";
65  
  Pair<Int, S> p = testBracketHygieneExt(text);
66  
  status += p == null ? "Hygienic" : p.b;
67  
  silentStatus(trim(status));
68  
}
69  
70  
svoid status(S s) { silentStatus(infoBoxAndReturn(s)); }
71  
svoid silentStatus(S s) { e.setStatus(s); }
72  
73  
svoid saveSnippetThen(final Runnable next) {
74  
  if (empty(snippetID)) ret;
75  
  fS text = getText(e.textArea);
76  
  status("Saving...");
77  
  thread {
78  
    fS page = editSnippet(snippetID, text);
79  
    remoteText = text; // TODO: check save result
80  
    status("Saved snippet: " + page);
81  
    awtCallF(next);
82  
  }
83  
}
84  
85  
svoid _butterReload() {
86  
  time { butterReload(snippetID); }
87  
  infoBox("Reloaded in " + lastTiming_format100ms());
88  
}
89  
90  
svoid transpile(final bool medium) { saveSnippetThen(r { _transpile(medium) }); }
91  
92  
svoid _transpile(final bool medium) {
93  
  status("Transpiling...");
94  
  //jdisable(btnEleuReload);
95  
  
96  
  thread "Transpiling" {
97  
    try {
98  
      final Pair<Bool, S> p = transpileOnServer(snippetID, medium ? "medium" : "quick");
99  
      awt {
100  
        if (p.a)
101  
          status("Transpiled OK!");
102  
        else {
103  
          status("Transpilation error. " + p.b);
104  
          showText("Transpilation Error", p.b);
105  
        }
106  
      }
107  
    } catch print e {
108  
      status("Transpilation problem. " + e);
109  
    }
110  
    //jenable(btnEleuReload);
111  
  }
112  
}
113  
114  
svoid _loadSnippet(S snippetID) {
115  
  _loadSnippet_noSet(snippetID);
116  
  e.textArea.setText(remoteText);
117  
}
118  
119  
svoid _loadSnippet_noSet(S snippetID) {
120  
  remoteText = loadSnippet(snippetID);
121  
  setAndSave('snippetID, snippetID);
122  
  lvSnippetID.set(snippetID);
123  
  frameTitle(e, snippetID + " - " + snippetTitle(snippetID));
124  
}
125  
126  
svoid newText {
127  
  setAndSave(snippetID := null);
128  
  lvSnippetID.set(snippetID);
129  
  remoteText = null;
130  
  S lastText = e.getText();
131  
  if (nempty(lastText)) logQuotedWithDate("saved-texts.log", lastText);
132  
  e.setText("");
133  
  frameTitle(e, programTitle());
134  
}
135  
136  
svoid cleanMeUp { update(false); }
137  
138  
svoid installAutoComplete {
139  
  if (installAutoComplete_first) installAutoComplete_first = false;
140  
  else sleep(500); // don't update too often
141  
  
142  
  printWithTime("Updating auto-complete");
143  
  temp tempMiniLoadingAnim();
144  
145  
  Set<S> set = concatListsToSet(allJavaKeywords(), standardFunctionNames(), deepWords(getText(e.textArea)));
146  
    
147  
  if (eq(set, autoComplete_lastSet)) ret;
148  
  autoComplete_lastSet = set;
149  
  
150  
  final new DefaultCompletionProvider provider;
151  
  provider.addCompletions(map(func(S s) { new BasicCompletion(provider, s) }, set));
152  
    
153  
  swing {
154  
    if (autoCompletion == null) {
155  
      (autoCompletion = new AutoCompletion(provider)).install(e.textArea);
156  
      call(autoCompletion, 'setHideOnCompletionProviderChange, false);
157  
    } else
158  
      autoCompletion.setCompletionProvider(provider);
159  
  }
160  
}

Author comment

Began life as a copy of #1014780

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1015549
Snippet name: Snippet Editor v2 [OK]
Eternal ID of this version: #1015549/31
Text MD5: a50f9bc2da58d371c61884c99a40389b
Transpilation MD5: e914d730df3efed2150339321cfe16b9
Author: stefan
Category: javax / gui
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-17 16:02:46
Source code size: 4750 bytes / 160 lines
Pitched / IR pitched: No / No
Views / Downloads: 509 / 1502
Version history: 30 change(s)
Referenced in: [show references]