Пример #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
  @Override
  public void action(final Object comp) {
    final boolean valid = general.action(comp, true);
    ft.action(ftxindex.isSelected());

    // ...must be located before remaining checks
    if (comp == general.browse || comp == general.input) dbname.setText(general.dbname);

    final String nm = dbname.getText().trim();
    ok = valid && !nm.isEmpty();

    String inf = valid ? ok ? null : ENTER_DB_NAME : RES_NOT_FOUND;
    Msg icon = Msg.ERROR;
    if (ok) {
      ok = Databases.validName(nm);
      if (ok) gui.gopts.set(GUIOptions.DBNAME, nm);

      if (!ok) {
        // name of database is invalid
        inf = Util.info(INVALID_X, NAME);
      } else if (general.input.getText().trim().isEmpty()) {
        // database will be empty
        inf = EMPTY_DB;
        icon = Msg.WARN;
      } else if (db.contains(nm)) {
        // old database will be overwritten
        inf = OVERWRITE_DB;
        icon = Msg.WARN;
      }
    }

    general.info.setText(inf, icon);
    enableOK(buttons, B_OK, ok);
  }
Пример #3
0
  /** 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);
    }
  }
Пример #4
0
  /** Notifies all views of a data reference change. */
  public void init() {
    final Data data = initHistory(gui.context);
    if (data != null) {
      // if a large database is opened, the user is asked if complex
      /// visualizations should be closed first
      final long size = data.meta.dbsize();
      boolean open = false;
      for (final View v : view) open |= v.visible() && v.db();
      if (open
          && size > LARGEDB
          && BaseXDialog.confirm(gui, Util.info(H_LARGE_DB, Performance.format(size)))) {
        for (final View v : view) if (v.visible() && v.db()) v.visible(false);
      }
    } else {
      // database closed: close open dialogs
      for (final Window w : gui.getOwnedWindows()) {
        if (w.isVisible() && w instanceof BaseXDialog) ((BaseXDialog) w).cancel();
      }
    }

    gui.context.focused = -1;
    for (final View v : view) v.refreshInit();
    gui.layoutViews();
    gui.setTitle(data != null ? data.meta.name : null);
  }
Пример #5
0
    @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()));
    }
Пример #6
0
 /** 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));
     }
   }
 }
Пример #7
0
 /**
  * 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);
   }
 }
Пример #8
0
  /**
   * 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;
  }