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

146
LINES

< > BotCompany Repo | #1014780 // Snippet Editor v1 [too slow, shouldn't use]

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

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

!7

sS snippetID;
sS savedText, remoteText;
static EditorFrame e;

import org.fife.ui.autocomplete.*;

p-substance {
  autoRestart();
  load('savedText);
  
  e = new EditorFrame;
  print("Input map: " + className(e.getTextArea().getInputMap());
  e._setFont(deriveFont(e._getFont(), 16));
  thread { installAutoComplete(); }
  
  e.setText(savedText);
  showFrame(e);
  frameIcon(e, #1101185 /*#1004655*/);
  
  addMenu(e, "New", "New text", f newText);

  addMenu(e, "Load", "Load snippet...", r {
    selectSnippetID(vf1(f _loadSnippet));
  });
  
  addMenu(e, "Save", "Save snippet", r { saveSnippetThen(null) });
  
  addMenu(e, "Transpile",
    "Save & Quick Transpile", r { transpile(false) },
    "Save & Medium Transpile", r { transpile(true) });
  addMenu(e, "Activate", "Butter-Reload", f _butterReload);
  
  S snippetID = cast readPersistentVar('snippetID);
  if (snippetID != null) _loadSnippet(snippetID);

  hideConsole();
  
  awtCalcEvery(e, 1000, f update);
  onFrameDeactivated(e, f fullUpdate);
}

svoid update { update(windowActive(e)); }
svoid fullUpdate { update(true); }
svoid update(bool full) {
  S text = e.getText();
  setAndSaveIfChanged(savedText := text);
    
  if (!full) ret;
  
  Pair<Int, S> p = testBracketHygieneExt(text);
  S status = "";
  if (remoteText != null && neq(remoteText, text))
    status = "Changes. ";
  if (p == null)
    status += "Hygienic";
  else {
    status += p.b;
    //setCaretPosition(ta, p.a);
  }
  silentStatus(trim(status));
}

svoid status(S s) {
  silentStatus(infoBoxAndReturn(s));
}

svoid silentStatus(S s) {
  e.setStatus(s);
}

svoid saveSnippetThen(final Runnable next) {
  if (empty(snippetID)) ret;
  fS text = getText(e.textArea);
  status("Saving...");
  thread {
    fS page = editSnippet(snippetID, text);
    remoteText = text; // TODO: check save result
    status("Saved snippet: " + page);
    awtCallF(next);
  }
}

svoid _butterReload() {
  time { butterReload(snippetID); }
  infoBox("Reloaded in " + lastTiming_format100ms());
}

svoid transpile(final bool medium) {
  saveSnippetThen(r { _transpile(medium) });
}

svoid _transpile(final bool medium) {
  status("Transpiling...");
  //jdisable(btnEleuReload);
  
  thread "Transpiling" {
    try {
      final Pair<Bool, S> p = transpileOnServer(snippetID, medium ? "medium" : "quick");
      awt {
        if (p.a)
          status("Transpiled OK!");
        else {
          status("Transpilation error. " + p.b);
          showText("Transpilation Error", p.b);
        }
      }
    } catch print e {
      status("Transpilation problem. " + e);
    }
    //jenable(btnEleuReload);
  }
}

svoid _loadSnippet(S snippetID) {
  e.textArea.setText(remoteText = loadSnippet(snippetID));
  setAndSave('snippetID, snippetID);
  frameTitle(e, snippetID + " - " + snippetTitle(snippetID));
}

svoid newText {
  setAndSave(snippetID := null);
  remoteText = null;
  S lastText = e.getText();
  if (nempty(lastText)) logQuotedWithDate("saved-texts.log", lastText);
  e.setText("");
  frameTitle(e, programTitle());
}

svoid cleanMeUp {
  setAndSaveIfChanged(savedText := e.getText());
}

svoid installAutoComplete {
  final new DefaultCompletionProvider provider;
  loading "Loading AutoComplete data" {
    for (S s : concatLists(
      allJavaKeywords(), standardFunctionNames()))
        provider.addCompletion(new BasicCompletion(provider, s));
  }

  swing {
    new AutoCompletion(provider).install(e.textArea);
  }
}

Author comment

Began life as a copy of #1004353

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1014780
Snippet name: Snippet Editor v1 [too slow, shouldn't use]
Eternal ID of this version: #1014780/53
Text MD5: e3b15be5c08be3c747dc4b9f3a42b976
Transpilation MD5: 6120569c2098f46730bca4f4bd47b141
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 13:04:46
Source code size: 3601 bytes / 146 lines
Pitched / IR pitched: No / No
Views / Downloads: 611 / 33141
Version history: 52 change(s)
Referenced in: #1014799 - Try to make a JavaX tokenizer for RSTA [dev.]
#1015549 - Snippet Editor v2 [OK]