/** * Shows a quit dialog for the specified editor. * * @param edit editor to be saved * @return {@code false} if confirmation was canceled */ private boolean confirm(final EditorArea edit) { if (edit.modified && (edit.opened() || edit.getText().length != 0)) { final Boolean ok = BaseXDialog.yesNoCancel(gui, Util.info(CLOSE_FILE_X, edit.file.name())); if (ok == null || ok && !save()) return false; } return true; }
/** Saves the displayed text. */ private void save() { final BaseXFileChooser fc = new BaseXFileChooser(SAVE_AS, gui.gopts.get(GUIOptions.WORKPATH), gui).suffix(IO.XMLSUFFIX); final IO file = fc.select(Mode.FSAVE); if (file == null) return; gui.gopts.set(GUIOptions.WORKPATH, file.path()); gui.cursor(CURSORWAIT, true); final MainOptions opts = gui.context.options; final int mh = opts.get(MainOptions.MAXHITS); opts.set(MainOptions.MAXHITS, -1); opts.set(MainOptions.CACHEQUERY, false); try (final PrintOutput out = new PrintOutput(file.toString())) { if (cmd != null) { cmd.execute(gui.context, out); } else if (ns != null) { ns.serialize(Serializer.get(out)); } else { final byte[] txt = text.getText(); for (final byte t : txt) if (t < 0 || t > ' ' || ws(t)) out.write(t); } } catch (final IOException ex) { BaseXDialog.error(gui, Util.info(FILE_NOT_SAVED_X, file)); } finally { opts.set(MainOptions.MAXHITS, mh); opts.set(MainOptions.CACHEQUERY, true); gui.cursor(CURSORARROW, true); } }
/** Open all selected files externally. */ private void openExternal() { for (final IOFile file : selectedValues()) { try { file.open(); } catch (final IOException ex) { BaseXDialog.error(project.gui, Util.info(FILE_NOT_OPENED_X, file)); } } }
/** * Performs a search. * * @param sc search context * @param jump jump to next hit */ final void search(final SearchContext sc, final boolean jump) { try { rend.search(sc); if (!sc.search.isEmpty()) gui.status.setText(Util.info(Text.STRINGS_FOUND_X, sc.nr())); if (jump) jump(SearchDir.CURRENT, false); } catch (final Exception ex) { final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", ""); gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg); } }
/** * Returns a keystroke for the specified string. * * @param cmd command * @return keystroke */ public static KeyStroke keyStroke(final GUICommand cmd) { final Object sc = cmd.shortcuts(); if (sc == null) return null; final String scut; if (sc instanceof BaseXKeys[]) { final BaseXKeys[] scs = (BaseXKeys[]) sc; if (scs.length == 0) return null; scut = scs[0].shortCut(); } else { scut = Util.info(sc, META); } final KeyStroke ks = KeyStroke.getKeyStroke(scut); if (ks == null) Util.errln("Could not assign shortcut: " + sc + " / " + scut); return ks; }