/** * 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); } }
@Override public void execute(final GUI gui) { final DialogExport dialog = new DialogExport(gui); if (!dialog.ok()) return; final IOFile root = new IOFile(dialog.path()); // check if existing files will be overwritten if (root.exists()) { IO file = null; boolean overwrite = false; final Data d = gui.context.data(); final IntList il = d.resources.docs(); final int is = il.size(); for (int i = 0; i < is; i++) { file = root.merge(Token.string(d.text(il.get(i), true))); if (file.exists()) { if (overwrite) { // more than one file will be overwritten; check remaining tests file = null; break; } overwrite = true; } } if (overwrite) { // show message for overwriting files or directories final String msg = file == null ? FILES_REPLACE_X : FILE_EXISTS_X; if (file == null) file = root; if (!BaseXDialog.confirm(gui, Util.info(msg, file))) return; } } DialogProgress.execute(gui, new Export(root.path())); }
/** * Serializes the specified nodes. * * @param n nodes to display */ private void setText(final DBNodes n) { if (visible()) { try { final ArrayOutput ao = new ArrayOutput(); ao.setLimit(gui.gopts.get(GUIOptions.MAXTEXT)); if (n != null) n.serialize(Serializer.get(ao)); setText(ao); cmd = null; ns = ao.finished() ? n : null; } catch (final IOException ex) { Util.debug(ex); } } else { home.setEnabled(gui.context.data() != null); } }