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).

1  
!7
2  
3  
module SimpleSnippetSearch {
4  
  InputChooser inputChooser = new(this).setDelay(1000);
5  
  
6  
  bool fullTextSearch; // look at snippet texts too
7  
  bool searchInBackground;
8  
  // search when window is hidden
9  
  
10  
  transient int maxInputLength = 120;
11  
  transient int maxResults = 1000;
12  
  transient S query;
13  
  transient L<SS> result;
14  
  transient L<Snippet> snippetResults;
15  
  transient WaitForStableValue<S> waitForStableValue = new(1.0);
16  
  transient volatile bool calculating;
17  
  transient JTable table;
18  
  transient ReliableSingleThread rst;
19  
  transient SimpleLiveValue<S> lvQuery = stringLiveValue();
20  
  transient SimpleLiveValue<S> lvResultsTitle = stringLiveValue();
21  
22  
  visualize {
23  
    SimpleLiveValue<Bool> lvFullTextSearch = dm_fieldLiveValue('fullTextSearch);
24  
    lvFullTextSearch.onChange(r forceNewSearch);
25  
    table = sexyTable();
26  
    tablePopupMenuItemsThreaded_top(table,
27  
      "Edit", voidfunc(int i) enter {
28  
        Snippet s = _get(snippetResults, i);
29  
        dm_openSnippetInEditor(s.id);
30  
      },
31  
      "Show in browser", voidfunc(int i) enter {
32  
        Snippet s = _get(snippetResults, i);
33  
        openURLInBrowser("http://tinybrain.de/" + psI(s.id));
34  
      }, "Load Module", voidfunc(int i) enter {
35  
        Snippet s = _get(snippetResults, i);
36  
        dm_addDynamicModuleDialog2(s);
37  
      });
38  
    ret northAndCenter(wrap(inputChooser),
39  
      withRightAlignedButtons(
40  
      jLiveValueSection(lvResultsTitle,
41  
        dataToTable_uneditable(result, table)),
42  
      jLiveValueCheckBox("Full Text Search", lvFullTextSearch)));
43  
  }
44  
45  
  S switchableFields() { ret 'searchInBackground; }
46  
  
47  
  void forceNewSearch { setField(query := null); }
48  
  
49  
  start {
50  
    lvQuery.set(query);
51  
    doEvery(500, rstUpdate());
52  
  }
53  
  
54  
  void update {
55  
    inputChooser.update();
56  
    calc(inputChooser.input());
57  
  }
58  
  
59  
  void calc(S q) {
60  
    if (!allowedToSearch() || eq(query, q) || empty(q)) ret;
61  
    query = q; result = null;
62  
    lvQuery.set(q);
63  
    tempSetField(this, calculating := true);
64  
    tbSearch_v2_quick.set(!fullTextSearch);
65  
    tbSearch_v2_html.set("want"); // We want the HTML too
66  
    L<Snippet> l = tbSearch_v2(maxResults, q);
67  
    S html = tbSearch_v2_html!;
68  
    S desc = regexpExtractIC("Found (\\d+\\+?) snippets?", html);
69  
    lvResultsTitle.set(or(desc, "No snippet results") + " for " + quote(q) + (fullTextSearch ? " (full text search)" : ""));
70  
    snippetResults = l;
71  
    result = map(l, func(Snippet s) -> SS {
72  
      litorderedmap("ID + Title" := snippetWithTitle(s)
73  
        /*, "Type" := s.type*/
74  
    )});
75  
    JTable t = table;
76  
    if (t != null) dataToTable_uneditable(result, t);
77  
  }
78  
  
79  
  bool allowedToSearch() enter { ret searchInBackground || dm_isVisible(); }
80  
}

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: 574 / 4322
Version history: 35 change(s)
Referenced in: [show references]