Executes a "replace" operation in the active editor. @param context The search context to use. The context shared between all of the find/replace dialogs will be used if this is null. This is here as a means for callers to override what search is performed to be diffe
(SearchContext context)
| 289 | * @see #findNext(SearchContext) |
| 290 | */ |
| 291 | public void replaceNext(SearchContext context) { |
| 292 | |
| 293 | AbstractMainView mainView = rtext.getMainView(); |
| 294 | if (context == null) { |
| 295 | context = mainView.searchContext; |
| 296 | } |
| 297 | |
| 298 | // If it's nothing (ie, they haven't searched yet), bring up the |
| 299 | // Replace dialog. |
| 300 | String searchString = context.getSearchFor(); |
| 301 | if (searchString==null || searchString.isEmpty()) { |
| 302 | switch (searchingMode) { |
| 303 | case DIALOGS -> { |
| 304 | ensureSearchDialogsCreated(); |
| 305 | replaceDialog.setVisible(true); |
| 306 | } |
| 307 | case TOOLBARS -> { |
| 308 | ensureToolbarsCreated(); |
| 309 | rtext.getCollapsibleSectionPanel(). |
| 310 | showBottomComponent(replaceToolBar); |
| 311 | } |
| 312 | } |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | // Otherwise, repeat the last Replace action. |
| 317 | RTextEditorPane textArea = mainView.getCurrentTextArea(); |
| 318 | |
| 319 | try { |
| 320 | handleSearchResult(context, SearchEngine.replace(textArea, context)); |
| 321 | } catch (PatternSyntaxException pse) { |
| 322 | // There was a problem with the user's regex search string. |
| 323 | // Won't usually happen; should be caught earlier. |
| 324 | JOptionPane.showMessageDialog(rtext, |
| 325 | "Invalid regular expression:\n" + pse + |
| 326 | "\nPlease check your regular expression search string.", |
| 327 | "Error", JOptionPane.ERROR_MESSAGE); |
| 328 | } catch (IndexOutOfBoundsException ioobe) { |
| 329 | // The user's regex replacement string referenced an |
| 330 | // invalid group. |
| 331 | JOptionPane.showMessageDialog(rtext, |
| 332 | "Invalid group reference in replacement string:\n" + |
| 333 | ioobe.getMessage(), |
| 334 | "Error", JOptionPane.ERROR_MESSAGE); |
| 335 | } |
| 336 | |
| 337 | } |
| 338 | |
| 339 | |
| 340 | /** |
no test coverage detected