Skip to content

Commit 99158b1

Browse files
romanpbmrok-povsic
authored andcommitted
Create ctrl+f, ctrl+h key-binds to find/replace actions
1 parent cfb7bab commit 99158b1

6 files changed

Lines changed: 1501 additions & 10 deletions

File tree

developer-addon/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ dependencies {
4141
// See here which is the latest version:
4242
// https://github.com/bobbylight/RSyntaxTextArea/releases
4343
fatJarLib group: 'com.fifesoft', name: 'rsyntaxtextarea', version: '3.3.2'
44+
// Find and replace toolbars in editor
45+
// https://github.com/bobbylight/RSTAUI/releases
46+
fatJarLib group: 'com.fifesoft', name: 'rstaui', version: '3.3.1'
4447
// https://mvnrepository.com/artifact/org.ow2.asm/asm
4548
fatJarLib group: 'org.ow2.asm', name: 'asm', version: '9.3'
4649
// https://mvnrepository.com/artifact/org.ow2.asm/asm-commons
@@ -49,8 +52,6 @@ dependencies {
4952
implementation group: 'com.bookmap.api', name: 'api-core', version: '7.3.0.26'
5053
implementation group: 'com.bookmap.api', name: 'api-simplified', version: '7.3.0.26'
5154

52-
implementation group: 'com.fifesoft', name: 'rstaui', version: '3.3.1'
53-
5455
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.4.2'
5556
}
5657

developer-addon/src/main/java/com/bookmap/python/api/addon/DeveloperAddon.java

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import com.bookmap.python.api.addon.settings.PythonApiSettings;
1212
import com.bookmap.python.api.addon.ui.ExecutablesFileFilter;
1313
import com.bookmap.python.api.addon.ui.JLabelLink;
14+
import com.bookmap.python.api.addon.ui.custom.CustomCollapsibleSectionPanel;
15+
import com.bookmap.python.api.addon.ui.custom.CustomFindToolBar;
16+
import com.bookmap.python.api.addon.ui.custom.CustomReplaceToolBar;
1417
import com.bookmap.python.api.addon.ui.filetree.JFileTree;
18+
import com.bookmap.python.api.addon.ui.listeners.EditorSearchListener;
1519
import com.bookmap.python.api.addon.ui.listeners.EditorStateListener;
1620
import com.bookmap.python.api.addon.ui.listeners.EditorTextFileTrackerListener;
1721
import com.bookmap.python.api.addon.ui.listeners.SavingTextEditorFileSelectionListener;
@@ -79,12 +83,16 @@
7983
import javax.swing.event.DocumentEvent;
8084
import javax.swing.event.DocumentListener;
8185
import javax.swing.text.JTextComponent;
86+
import org.fife.rsta.ui.search.FindToolBar;
87+
import org.fife.rsta.ui.search.ReplaceToolBar;
88+
import org.fife.rsta.ui.search.SearchListener;
8289
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
8390
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
8491
import org.fife.ui.rsyntaxtextarea.Theme;
8592
import org.fife.ui.rtextarea.FoldIndicatorStyle;
8693
import org.fife.ui.rtextarea.RTextArea;
8794
import org.fife.ui.rtextarea.RTextScrollPane;
95+
import org.fife.ui.rtextarea.SearchContext;
8896
import velox.api.layer1.Layer1ApiFinishable;
8997
import velox.api.layer1.Layer1ApiInstrumentSpecificEnabledStateProvider;
9098
import velox.api.layer1.Layer1ApiProvider;
@@ -153,6 +161,12 @@ public class DeveloperAddon
153161
private SettingsAccess settingsAccess;
154162
private PythonApiSettings pythonApiSettings;
155163
private RSyntaxTextArea textArea;
164+
private FindToolBar findToolBar;
165+
private ReplaceToolBar replaceToolBar;
166+
167+
private CustomCollapsibleSectionPanel collapsibleSectionPanel;
168+
169+
private SearchListener searchListener;
156170

157171
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
158172

@@ -312,6 +326,8 @@ private void initEditorFrame(JFrame jFrame, ActionListener newFileAction, File r
312326
textArea.setAnimateBracketMatching(pythonApiSettings.isBracketMatchingAnimationEnabled());
313327
textArea.setPaintTabLines(pythonApiSettings.isTabLinesEnabled());
314328

329+
initSearchDialogs();
330+
315331
loadNonDefaultTheme();
316332

317333
titleLabel = new JLabel("");
@@ -445,6 +461,21 @@ public void changedUpdate(DocumentEvent e) {}
445461
}
446462
};
447463

464+
collapsibleSectionPanel = new CustomCollapsibleSectionPanel(textArea);
465+
var collapsibleSectionPanelConstrains = new GridBagConstraints();
466+
collapsibleSectionPanelConstrains.anchor = GridBagConstraints.FIRST_LINE_START;
467+
collapsibleSectionPanelConstrains.fill = GridBagConstraints.HORIZONTAL;
468+
collapsibleSectionPanelConstrains.gridy = 1;
469+
collapsibleSectionPanelConstrains.gridx = 0;
470+
collapsibleSectionPanelConstrains.gridwidth = 4;
471+
collapsibleSectionPanelConstrains.ipady = 0;
472+
collapsibleSectionPanelConstrains.weightx = 0;
473+
collapsibleSectionPanelConstrains.insets = new Insets(5, 5, 5, 5);
474+
rightComponent.add(collapsibleSectionPanel, collapsibleSectionPanelConstrains);
475+
collapsibleSectionPanel.add(textEditorScrollPanel);
476+
collapsibleSectionPanel.addBottomComponent(findToolBar);
477+
collapsibleSectionPanel.addBottomComponent(replaceToolBar);
478+
448479
/*
449480
* Buttons.
450481
*/
@@ -615,6 +646,9 @@ public void changedUpdate(DocumentEvent e) {}
615646
editMenu.add(createMenuItem(RTextArea.getAction(RTextArea.PASTE_ACTION)));
616647
editMenu.add(createMenuItem(RTextArea.getAction(RTextArea.DELETE_ACTION)));
617648
editMenu.addSeparator();
649+
editMenu.add(new ShowFindToolBarAction(findToolBar));
650+
editMenu.add(new ShowReplaceToolBarAction(replaceToolBar));
651+
editMenu.addSeparator();
618652
editMenu.add(createMenuItem(RTextArea.getAction(RTextArea.SELECT_ALL_ACTION)));
619653
menuBar.add(editMenu);
620654

@@ -792,6 +826,22 @@ public void windowClosed(WindowEvent e) {
792826
jFrame.pack();
793827
}
794828

829+
/**
830+
* Creates our Find and Replace toolbars.
831+
*/
832+
private void initSearchDialogs() {
833+
searchListener = new EditorSearchListener(textArea);
834+
835+
// Create toolbars and tie their search contexts together also.
836+
findToolBar = new CustomFindToolBar(searchListener);
837+
replaceToolBar = new CustomReplaceToolBar(searchListener);
838+
839+
// This ties the properties of the two toolbars together (match case,
840+
// regex, etc.).
841+
SearchContext context = findToolBar.getSearchContext();
842+
replaceToolBar.setSearchContext(context);
843+
}
844+
795845
private JMenuItem createMenuItem(Action action) {
796846
JMenuItem item = new JMenuItem(action);
797847
item.setToolTipText(null); // Swing annoyingly adds tool tip text to the menu item.
@@ -1404,24 +1454,64 @@ public void actionPerformed(ActionEvent e) {
14041454
Log.error("Failed to build addon.", ex);
14051455
SwingUtilities.invokeLater(() -> {
14061456
JOptionPane.showMessageDialog(
1407-
jFrame,
1408-
String.format("Failed to build addon:\n%s", ex.getMessage())
1457+
jFrame,
1458+
String.format("Failed to build addon:\n%s", ex.getMessage())
14091459
);
14101460
});
14111461
return;
14121462
}
14131463

14141464
SwingUtilities.invokeLater(() -> {
14151465
JOptionPane.showMessageDialog(
1416-
jFrame,
1417-
"Build success.\n\n" +
1418-
"You can find your addon JAR file by opening 'File' -> 'Open build folder' here in the code editor.\n\n" +
1419-
"To load your addon, open the main Bookmap window, go under 'Settings' -> 'Configure addons' and add your addon JAR file.\n",
1420-
"Build",
1421-
JOptionPane.INFORMATION_MESSAGE
1466+
jFrame,
1467+
"Build success.\n\n" +
1468+
"You can find your addon JAR file by opening 'File' -> 'Open build folder' here in the code editor.\n\n" +
1469+
"To load your addon, open the main Bookmap window, go under 'Settings' -> 'Configure addons' and add your addon JAR file.\n",
1470+
"Build",
1471+
JOptionPane.INFORMATION_MESSAGE
14221472
);
14231473
});
14241474
});
14251475
}
14261476
}
1477+
1478+
/**
1479+
* Shows the Find toolbar.
1480+
*/
1481+
private class ShowFindToolBarAction extends AbstractAction {
1482+
1483+
private final FindToolBar findToolBar;
1484+
1485+
ShowFindToolBarAction(FindToolBar findToolBar) {
1486+
super("Find");
1487+
this.findToolBar = findToolBar;
1488+
int c = InputEvent.CTRL_DOWN_MASK;
1489+
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, c));
1490+
}
1491+
1492+
@Override
1493+
public void actionPerformed(ActionEvent e) {
1494+
collapsibleSectionPanel.showBottomComponent(findToolBar);
1495+
}
1496+
}
1497+
1498+
/**
1499+
* Shows the Replace toolbar.
1500+
*/
1501+
private class ShowReplaceToolBarAction extends AbstractAction {
1502+
1503+
private final ReplaceToolBar replaceToolBar;
1504+
1505+
ShowReplaceToolBarAction(ReplaceToolBar replaceToolBar) {
1506+
super("Replace");
1507+
this.replaceToolBar = replaceToolBar;
1508+
int c = InputEvent.CTRL_DOWN_MASK;
1509+
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_H, c));
1510+
}
1511+
1512+
@Override
1513+
public void actionPerformed(ActionEvent e) {
1514+
collapsibleSectionPanel.showBottomComponent(replaceToolBar);
1515+
}
1516+
}
14271517
}

0 commit comments

Comments
 (0)