/** * 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 specified editor contents. * * @param file file to write * @return {@code false} if confirmation was canceled */ private boolean save(final IOFile file) { try { final EditorArea edit = getEditor(); file.write(edit.getText()); edit.file(file); return true; } catch (final IOException ex) { BaseXDialog.error(gui, FILE_NOT_SAVED); return false; } }
/** * Opens the specified query file. * * @param file query file * @return opened editor */ public EditorArea open(final IOFile file) { if (!visible()) GUICommands.C_SHOWEDITOR.execute(gui); EditorArea edit = find(file, true); try { if (edit != null) { // display open file tabs.setSelectedComponent(edit); edit.reopen(true); } else { // get current editor edit = getEditor(); // create new tab if current text is stored on disk or has been modified if (edit.opened() || edit.modified) edit = addTab(); edit.initText(file.read()); edit.file(file); } } catch (final IOException ex) { BaseXDialog.error(gui, FILE_NOT_OPENED); } return edit; }