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

80
LINES

< > BotCompany Repo | #1016199 // Snippet Search

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

Libraryless. Click here for Pure Java version (16346L/120K).

!7

module SimpleSnippetSearch {
  InputChooser inputChooser = new(this).setDelay(1000);
  
  bool fullTextSearch; // look at snippet texts too
  bool searchInBackground;
  // search when window is hidden
  
  transient int maxInputLength = 120;
  transient int maxResults = 1000;
  transient S query;
  transient L<SS> result;
  transient L<Snippet> snippetResults;
  transient WaitForStableValue<S> waitForStableValue = new(1.0);
  transient volatile bool calculating;
  transient JTable table;
  transient ReliableSingleThread rst;
  transient SimpleLiveValue<S> lvQuery = stringLiveValue();
  transient SimpleLiveValue<S> lvResultsTitle = stringLiveValue();

  visualize {
    SimpleLiveValue<Bool> lvFullTextSearch = dm_fieldLiveValue('fullTextSearch);
    lvFullTextSearch.onChange(r forceNewSearch);
    table = sexyTable();
    tablePopupMenuItemsThreaded_top(table,
      "Edit", voidfunc(int i) enter {
        Snippet s = _get(snippetResults, i);
        dm_openSnippetInEditor(s.id);
      },
      "Show in browser", voidfunc(int i) enter {
        Snippet s = _get(snippetResults, i);
        openURLInBrowser("http://tinybrain.de/" + psI(s.id));
      }, "Load Module", voidfunc(int i) enter {
        Snippet s = _get(snippetResults, i);
        dm_addDynamicModuleDialog2(s);
      });
    ret northAndCenter(wrap(inputChooser),
      withRightAlignedButtons(
      jLiveValueSection(lvResultsTitle,
        dataToTable_uneditable(result, table)),
      jLiveValueCheckBox("Full Text Search", lvFullTextSearch)));
  }

  S switchableFields() { ret 'searchInBackground; }
  
  void forceNewSearch { setField(query := null); }
  
  start {
    lvQuery.set(query);
    doEvery(500, rstUpdate());
  }
  
  void update {
    inputChooser.update();
    calc(inputChooser.input());
  }
  
  void calc(S q) {
    if (!allowedToSearch() || eq(query, q) || empty(q)) ret;
    query = q; result = null;
    lvQuery.set(q);
    tempSetField(this, calculating := true);
    tbSearch_v2_quick.set(!fullTextSearch);
    tbSearch_v2_html.set("want"); // We want the HTML too
    L<Snippet> l = tbSearch_v2(maxResults, q);
    S html = tbSearch_v2_html!;
    S desc = regexpExtractIC("Found (\\d+\\+?) snippets?", html);
    lvResultsTitle.set(or(desc, "No snippet results") + " for " + quote(q) + (fullTextSearch ? " (full text search)" : ""));
    snippetResults = l;
    result = map(l, func(Snippet s) -> SS {
      litorderedmap("ID + Title" := snippetWithTitle(s)
        /*, "Type" := s.type*/
    )});
    JTable t = table;
    if (t != null) dataToTable_uneditable(result, t);
  }
  
  bool allowedToSearch() enter { ret searchInBackground || dm_isVisible(); }
}

Author comment

Began life as a copy of #1015891

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

-
Snippet ID: #1016199
Snippet name: Snippet Search
Eternal ID of this version: #1016199/36
Text MD5: d5ecb9bd642cd987f8ae9f2bb03b8f2c
Transpilation MD5: d12128a6fdad8aac969d424415ae570f
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-12-18 15:18:50
Source code size: 2750 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 573 / 4319
Version history: 35 change(s)
Referenced in: