Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * Choose a unique tab file.
  *
  * @return io reference
  */
 private IOFile newTabFile() {
   // collect numbers of existing files
   final BoolList bl = new BoolList();
   for (final EditorArea edit : editors()) {
     if (edit.opened()) continue;
     final String n = edit.file.name().substring(FILE.length());
     bl.set(n.isEmpty() ? 1 : Integer.parseInt(n), true);
   }
   // find first free file number
   int c = 0;
   while (++c < bl.size() && bl.get(c)) ;
   // create io reference
   return new IOFile(gui.gprop.get(GUIProp.WORKPATH), FILE + (c == 1 ? "" : c));
 }
Esempio n. 3
0
  /**
   * 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;
  }
Esempio n. 4
0
 /**
  * Finds the editor that contains the specified file.
  *
  * @param file file to be found
  * @param opened considers only opened files
  * @return editor
  */
 EditorArea find(final IO file, final boolean opened) {
   for (final EditorArea edit : editors()) {
     if (edit.file.eq(file) && (!opened || edit.opened())) return edit;
   }
   return null;
 }
Esempio n. 5
0
 /**
  * Checks if the current text can be saved or reverted.
  *
  * @param rev revert flag
  * @return result of check
  */
 public boolean modified(final boolean rev) {
   final EditorArea edit = getEditor();
   return edit.modified || !rev && !edit.opened();
 }
Esempio n. 6
0
 /**
  * Saves the contents of the currently opened editor.
  *
  * @return {@code false} if operation was canceled
  */
 public boolean save() {
   final EditorArea edit = getEditor();
   return edit.opened() ? save(edit.file) : saveAs();
 }