| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -444,8 +444,10 @@ public void addErrorTable(EditorFooter ef) { | |||
| 444 | 444 | public EditorState getEditorState() { | |
| 445 | 445 | return state; | |
| 446 | 446 | } | |
| 447 | - | ||
| 448 | - | ||
| 447 | + | ||
| 448 | + public void extraSearch(Search search) { } // by default don't require anything | ||
| 449 | + | ||
| 450 | + | ||
| 449 | 451 | /** | |
| 450 | 452 | * Handles files dragged & dropped from the desktop and into the editor | |
| 451 | 453 | * window. Dragging files into the editor window is the same as using | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ | |||
| 29 | 29 | import javax.swing.event.*; | |
| 30 | 30 | import javax.swing.text.*; | |
| 31 | 31 | import java.awt.*; | |
| 32 | + import java.awt.Dimension; | ||
| 32 | 33 | import java.awt.event.*; | |
| 33 | 34 | import java.util.ArrayList; | |
| 34 | 35 | ||
@@ -92,7 +93,7 @@ public void mouseClicked(MouseEvent evt) { | |||
| 92 | 93 | public void insertUpdate(DocumentEvent e) { call(); } | |
| 93 | 94 | ||
| 94 | 95 | private void call() { | |
| 95 | - updateList(searchField.getText()); | ||
| 96 | + updateList(); | ||
| 96 | 97 | } | |
| 97 | 98 | }); | |
| 98 | 99 | searchField.addActionListener(e -> { | |
@@ -154,63 +155,78 @@ private void call() { | |||
| 154 | 155 | ||
| 155 | 156 | ||
| 156 | 157 | setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); | |
| 157 | - addWindowListener(new WindowAdapter() { | ||
| 158 | - public void windowClosing(WindowEvent e) { | ||
| 159 | - handleClose(); | ||
| 160 | - } | ||
| 161 | - }); | ||
| 162 | 158 | ||
| 163 | 159 | Toolkit.registerWindowCloseKeys(getRootPane(), actionEvent -> handleClose()); | |
| 164 | 160 | Toolkit.setIcon(this); | |
| 165 | 161 | ||
| 166 | - // hack to to get first field to focus properly on osx | ||
| 167 | 162 | addWindowListener(new WindowAdapter() { | |
| 163 | + // hack to to get first field to focus properly on osx | ||
| 168 | 164 | public void windowActivated(WindowEvent e) { | |
| 169 | 165 | searchField.requestFocusInWindow(); | |
| 170 | 166 | searchField.selectAll(); | |
| 171 | 167 | } | |
| 168 | + @Override public void windowDeactivated(WindowEvent e) { | ||
| 169 | + System.out.println(2);handleClose(); | ||
| 170 | + } | ||
| 171 | + @Override public void windowClosing(WindowEvent e) { | ||
| 172 | + System.out.println(3);handleClose(); | ||
| 173 | + } | ||
| 172 | 174 | }); | |
| 173 | 175 | pack(); | |
| 174 | 176 | setResizable(true); | |
| 175 | 177 | setLocationRelativeTo(null); | |
| 176 | 178 | ||
| 177 | - updateList(""); | ||
| 179 | + updateList(); | ||
| 178 | 180 | } | |
| 179 | 181 | ||
| 180 | - ArrayList<SearchResult> results; | ||
| 181 | - private void updateList(String search) { | ||
| 182 | - search = search.toLowerCase(); | ||
| 182 | + private ArrayList<SearchResult> results; | ||
| 183 | + private void updateList() { | ||
| 183 | 184 | results = new ArrayList<>(); | |
| 184 | 185 | for (SketchCode c : editor.sketch.getCode()) { | |
| 185 | - if (c.getFileName().toLowerCase().contains(search)) results.add(new SearchResult(c)); | ||
| 186 | + if (match(c.getFileName())) results.add(new FileSearchResult(c)); | ||
| 186 | 187 | } | |
| 188 | + | ||
| 189 | + editor.extraSearch(this); | ||
| 190 | + | ||
| 191 | + reModel(); | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + private void reModel() { | ||
| 187 | 195 | list.setModel(new AbstractListModel<SearchResult>() { | |
| 188 | 196 | @Override | |
| 189 | 197 | public int getSize() { | |
| 190 | 198 | return results.size(); | |
| 191 | 199 | } | |
| 192 | - | ||
| 200 | + | ||
| 193 | 201 | @Override | |
| 194 | 202 | public SearchResult getElementAt(int i) { | |
| 195 | 203 | return results.get(i); | |
| 196 | 204 | } | |
| 197 | 205 | }); | |
| 206 | + | ||
| 198 | 207 | if (results.size() > 0) list.setSelectedIndex(0); | |
| 199 | 208 | } | |
| 200 | 209 | ||
| 201 | - class SearchResult { | ||
| 210 | + public String getText() { | ||
| 211 | + return searchField.getText().toLowerCase(); | ||
| 212 | + } | ||
| 202 | 213 | ||
| 203 | - private final SketchCode tab; | ||
| 214 | + public void add(ArrayList<SearchResult> names) { | ||
| 215 | + results.addAll(names); | ||
| 216 | + EventQueue.invokeLater(this::reModel); // idk if invokeLater is needed but i did it so | ||
| 217 | + } | ||
| 204 | 218 | ||
| 205 | - public SearchResult(SketchCode tab) { | ||
| 219 | + class FileSearchResult extends SearchResult { | ||
| 220 | + private final SketchCode tab; | ||
| 221 | + | ||
| 222 | + FileSearchResult(SketchCode tab) { | ||
| 223 | + super(Search.this); | ||
| 206 | 224 | this.tab = tab; | |
| 207 | 225 | } | |
| 208 | - | ||
| 209 | 226 | @Override public String toString() { | |
| 210 | - return tab.getFileName(); | ||
| 227 | + return tab.getPrettyName(); | ||
| 211 | 228 | } | |
| 212 | - | ||
| 213 | - public void select() { | ||
| 229 | + @Override public void select() { | ||
| 214 | 230 | handleClose(); | |
| 215 | 231 | editor.sketch.setCurrentCode(tab); | |
| 216 | 232 | } | |
@@ -295,14 +311,9 @@ private boolean find(boolean wrap) { | |||
| 295 | 311 | } | |
| 296 | 312 | ||
| 297 | 313 | ||
| 314 | + public boolean match(String str) { | ||
| 315 | + return str.toLowerCase().contains(getText()); | ||
| 316 | + } | ||
| 298 | 317 | ||
| 299 | 318 | ||
| 300 | - | ||
| 301 | - /** | ||
| 302 | - * Returns true if find next/previous will work, for graying- | ||
| 303 | - * out of menu items. | ||
| 304 | - */ | ||
| 305 | - public boolean canFindNext() { | ||
| 306 | - return searchField.getText().length() != 0; | ||
| 307 | - } | ||
| 308 | - } | ||
| 319 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + package processing.app.ui; | ||
| 2 | + | ||
| 3 | + public abstract class SearchResult { | ||
| 4 | + | ||
| 5 | + private final Search s; | ||
| 6 | + | ||
| 7 | + public SearchResult(Search s) { | ||
| 8 | + this.s = s; | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + public abstract void select(); | ||
| 12 | + public void close() { | ||
| 13 | + s.handleClose(); | ||
| 14 | + } | ||
| 15 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,7 @@ | |||
| 16 | 16 | import javax.swing.text.BadLocationException; | |
| 17 | 17 | import javax.swing.text.Document; | |
| 18 | 18 | ||
| 19 | + import org.eclipse.jdt.core.dom.SimpleName; | ||
| 19 | 20 | import processing.core.PApplet; | |
| 20 | 21 | import processing.data.StringList; | |
| 21 | 22 | import processing.app.*; | |
@@ -1816,7 +1817,6 @@ protected void downloadImports() { | |||
| 1816 | 1817 | * Returns a list of AvailableContributions of those libraries that the user | |
| 1817 | 1818 | * wants imported, but that are not installed. | |
| 1818 | 1819 | * | |
| 1819 | - * @param importHeaders | ||
| 1820 | 1820 | */ | |
| 1821 | 1821 | private List<AvailableContribution> getNotInstalledAvailableLibs(ArrayList<String> importHeadersList) { | |
| 1822 | 1822 | Map<String, Contribution> importMap = | |
@@ -2812,4 +2812,10 @@ static private int howManyFloats(List<List<Handle>> handles) { | |||
| 2812 | 2812 | } | |
| 2813 | 2813 | return count; | |
| 2814 | 2814 | } | |
| 2815 | + | ||
| 2816 | + | ||
| 2817 | + | ||
| 2818 | + public void extraSearch(Search search) { | ||
| 2819 | + pdex.getSearcher().search(search, search::add); | ||
| 2820 | + } | ||
| 2815 | 2821 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ public class PDEX { | |||
| 19 | 19 | private ShowUsage usage; | |
| 20 | 20 | private Rename rename; | |
| 21 | 21 | private DebugTree debugTree; | |
| 22 | + private Searcher searcher; | ||
| 22 | 23 | ||
| 23 | 24 | private PreprocessingService pps; | |
| 24 | 25 | ||
@@ -29,8 +30,9 @@ public PDEX(JavaEditor editor, PreprocessingService pps) { | |||
| 29 | 30 | this.enabled = !editor.hasJavaTabs(); | |
| 30 | 31 | ||
| 31 | 32 | errorChecker = new ErrorChecker(editor, pps); | |
| 32 | - | ||
| 33 | + | ||
| 33 | 34 | usage = new ShowUsage(editor, pps); | |
| 35 | + searcher = new Searcher(editor, pps); | ||
| 34 | 36 | inspect = new InspectMode(editor, pps, usage); | |
| 35 | 37 | rename = new Rename(editor, pps, usage); | |
| 36 | 38 | ||
@@ -104,4 +106,8 @@ public void dispose() { | |||
| 104 | 106 | public void documentChanged(Document newDoc) { | |
| 105 | 107 | addDocumentListener(newDoc); | |
| 106 | 108 | } | |
| 109 | + | ||
| 110 | + public Searcher getSearcher() { | ||
| 111 | + return searcher; | ||
| 112 | + } | ||
| 107 | 113 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,58 @@ | |||
| 1 | + package processing.mode.java.pdex; | ||
| 2 | + | ||
| 3 | + import org.eclipse.jdt.core.dom.*; | ||
| 4 | + import processing.app.ui.*; | ||
| 5 | + import processing.mode.java.JavaEditor; | ||
| 6 | + | ||
| 7 | + import java.awt.*; | ||
| 8 | + import java.util.ArrayList; | ||
| 9 | + import java.util.function.Consumer; | ||
| 10 | + | ||
| 11 | + public class Searcher { | ||
| 12 | + private final JavaEditor editor; | ||
| 13 | + private final PreprocessingService pps; | ||
| 14 | + | ||
| 15 | + Searcher(JavaEditor editor, PreprocessingService pps) { | ||
| 16 | + | ||
| 17 | + this.editor = editor; | ||
| 18 | + this.pps = pps; | ||
| 19 | + } | ||
| 20 | + public void search(Search s, Consumer<ArrayList<SearchResult>> callback) { | ||
| 21 | + pps.whenDoneBlocking(ps -> handleSearch(ps, s, callback)); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + private void handleSearch(PreprocessedSketch ps, Search search, Consumer<ArrayList<SearchResult>> callback) { | ||
| 25 | + ArrayList<SearchResult> occurrences = new ArrayList<>(); | ||
| 26 | + ps.compilationUnit.getRoot().accept(new ASTVisitor() { | ||
| 27 | + @Override | ||
| 28 | + public boolean visit(TypeDeclaration name) { | ||
| 29 | + if (search.match(name.getName().getIdentifier())) occurrences.add(new SNSearchResult(search, name, ps)); | ||
| 30 | + return super.visit(name); | ||
| 31 | + } | ||
| 32 | + }); | ||
| 33 | + callback.accept(occurrences); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + class SNSearchResult extends SearchResult { | ||
| 37 | + | ||
| 38 | + private final TypeDeclaration item; | ||
| 39 | + private final PreprocessedSketch ps; | ||
| 40 | + | ||
| 41 | + SNSearchResult(Search s, TypeDeclaration item, PreprocessedSketch ps) { | ||
| 42 | + super(s); | ||
| 43 | + this.item = item; | ||
| 44 | + this.ps = ps; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public void select() { | ||
| 48 | + PreprocessedSketch.SketchInterval si = ps.mapJavaToSketch(item.getName()); | ||
| 49 | + if (!ps.inRange(si)) return; | ||
| 50 | + EventQueue.invokeLater(() -> editor.highlight(si.tabIndex, si.startTabOffset, si.stopTabOffset)); | ||
| 51 | + close(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override public String toString() { | ||
| 55 | + return item.getName().getIdentifier(); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments