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

38
LINES

< > BotCompany Repo | #1017780 // Standard Function/Class Name Auto-Complete [operates on focused component]

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

Libraryless. Click here for Pure Java version (17364L/125K).

1  
!7
2  
3  
sclass SFAutoComplete extends DynObjectTable<S> {
4  
  transient WeakReference<JTextComponent> tc;
5  
  int maxEntries = 100;
6  
  
7  
  start {
8  
    dontPersist();
9  
    doEveryAndNow(1000, r {
10  
      if (!isVisible()) ret;
11  
      JTextComponent c = optCast(JTextComponent, getFocusOwner());
12  
      if (c == null) ret;
13  
      tc = weakRef(c);
14  
      int i = getCaretPosition(c);
15  
      S word = tok_lastTokenIfNoSpaceAfter(takeFirst(getText(c), i));
16  
      new LS list;
17  
      if (nempty(word)) {
18  
        list.addAll(containingIC(standardClassNames_sorted(), word));
19  
        list.addAll(containingIC(standardFunctionNames_sorted(), word));
20  
        list = takeFirst(maxEntries, list);
21  
      }
22  
      setData(list);
23  
    });
24  
  }
25  
  
26  
  void onDoubleClick(S s) ctex {
27  
    final JTextComponent c = getWeakRef(tc);
28  
    if (c != null) {
29  
      int i = getCaretPosition(c);
30  
      Document doc = c.getDocument();
31  
      S word = tok_lastTokenIfNoSpaceAfter(takeFirst(getText(c), i));
32  
      if (swic(s, word))
33  
        doc.remove(i -= l(word), l(word));
34  
      doc.insertString(i, s, null);
35  
      awt { focusComponent(c); } // TODO: doesn't work?
36  
    }
37  
  }
38  
}

Author comment

Began life as a copy of #1017235

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: #1017780
Snippet name: Standard Function/Class Name Auto-Complete [operates on focused component]
Eternal ID of this version: #1017780/17
Text MD5: f6b20e940d9ecd02c2d2469b80752bd4
Transpilation MD5: 35498e7fe885271cdc366dee34a6c618
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: 2019-04-14 18:40:47
Source code size: 1160 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 382 / 23370
Version history: 16 change(s)
Referenced in: [show references]