Пример #1
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);
    }
  }
 /**
  * Handles key down events. Cursor keys are handled by the view the other key events are
  * delegated to the currently active tool.
  */
 public void keyPressed(KeyEvent e) {
   int code = e.getKeyCode();
   if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_DELETE)) {
     if (deleteCmd.isExecutable()) {
       deleteCmd.execute();
       //					deleteCmd.viewSelectionChanged(this);
     }
   } else if ((code == KeyEvent.VK_DOWN)
       || (code == KeyEvent.VK_UP)
       || (code == KeyEvent.VK_RIGHT)
       || (code == KeyEvent.VK_LEFT)) {
     handleCursorKey(code);
   } else {
     tool().keyDown(e, code);
   }
   checkDamage();
 }