示例#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;
 }
示例#2
0
 /**
  * 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;
   }
 }
示例#3
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));
 }
示例#4
0
  /**
   * Refreshes the query modification flag.
   *
   * @param force action
   */
  void refreshControls(final boolean force) {
    // update modification flag
    final EditorArea edit = getEditor();
    final boolean oe = edit.modified;
    edit.modified = edit.hist != null && edit.hist.modified();
    if (edit.modified == oe && !force) return;

    // update tab title
    String title = edit.file.name();
    if (edit.modified) title += '*';
    edit.label.setText(title);

    // update components
    gui.refreshControls();
    posCode.invokeLater();
  }
示例#5
0
  /**
   * Adds a new editor tab.
   *
   * @return editor reference
   */
  EditorArea addTab() {
    final EditorArea edit = new EditorArea(this, newTabFile());
    edit.setFont(GUIConstants.mfont);

    final BaseXBack tab = new BaseXBack(new BorderLayout(10, 0)).mode(Fill.NONE);
    tab.add(edit.label, BorderLayout.CENTER);

    final BaseXButton close = tabButton("e_close");
    close.setRolloverIcon(BaseXLayout.icon("e_close2"));
    close.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            close(edit);
          }
        });
    tab.add(close, BorderLayout.EAST);

    tabs.add(edit, tab, tabs.getComponentCount() - 2);
    return edit;
  }
示例#6
0
 /** Jumps to a specific line. */
 public void gotoLine() {
   final EditorArea edit = getEditor();
   final int ll = edit.last.length;
   final int cr = edit.getCaret();
   int l = 1;
   for (int e = 0; e < ll && e < cr; e += cl(edit.last, e)) {
     if (edit.last[e] == '\n') ++l;
   }
   final DialogLine dl = new DialogLine(gui, l);
   if (!dl.ok()) return;
   final int el = dl.line();
   int p = 0;
   l = 1;
   for (int e = 0; e < ll && l < el; e += cl(edit.last, e)) {
     if (edit.last[e] != '\n') continue;
     p = e + 1;
     ++l;
   }
   edit.setCaret(p);
   posCode.invokeLater();
 }
示例#7
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;
  }
示例#8
0
  /**
   * Handles info messages resulting from a query execution.
   *
   * @param msg info message
   * @return true if error was found
   */
  private boolean error(final String msg) {
    final String line = msg.replaceAll("[\\r\\n].*", "");
    Matcher m = XQERROR.matcher(line);
    int el, ec = 2;
    if (!m.matches()) {
      m = XMLERROR.matcher(line);
      if (!m.matches()) return true;
      el = Integer.parseInt(m.group(1));
      errFile = getEditor().file.path();
    } else {
      el = Integer.parseInt(m.group(1));
      ec = Integer.parseInt(m.group(2));
      errFile = m.group(3);
    }

    final EditorArea edit = find(IO.get(errFile), false);
    if (edit == null) return true;

    // find approximate error position
    final int ll = edit.last.length;
    int ep = ll;
    for (int e = 1, l = 1, c = 1; e < ll; ++c, e += cl(edit.last, e)) {
      if (l > el || l == el && c == ec) {
        ep = e;
        break;
      }
      if (edit.last[e] == '\n') {
        ++l;
        c = 0;
      }
    }
    if (ep < ll && Character.isLetterOrDigit(cp(edit.last, ep))) {
      while (ep > 0 && Character.isLetterOrDigit(cp(edit.last, ep - 1))) ep--;
    }
    edit.error(ep);
    errPos = ep;
    return true;
  }
示例#9
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;
 }
示例#10
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();
 }
示例#11
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();
 }
示例#12
0
 @Override
 public void refreshLayout() {
   header.setFont(GUIConstants.lfont);
   for (final EditorArea edit : editors()) edit.setFont(GUIConstants.mfont);
   search.refreshLayout();
 }