Пример #1
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);
   }
 }
Пример #2
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;
 }
Пример #3
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()));
    }
Пример #4
0
 /**
  * Returns the clipboard text.
  *
  * @return text
  */
 private static String clip() {
   // copy selection to clipboard
   final Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
   final Transferable tr = clip.getContents(null);
   if (tr != null) {
     final ArrayList<Object> contents = BaseXLayout.contents(tr);
     if (!contents.isEmpty()) return contents.get(0).toString();
   } else {
     Util.debug("Clipboard has no contents.");
   }
   return null;
 }
Пример #5
0
 /** Reads in the property file. */
 static {
   try {
     final String file = "/completions.properties";
     final InputStream is = TextPanel.class.getResourceAsStream(file);
     if (is == null) {
       Util.errln(file + " not found.");
     } else {
       try (final NewlineInput nli = new NewlineInput(is)) {
         for (String line; (line = nli.readLine()) != null; ) {
           final int i = line.indexOf('=');
           if (i == -1 || line.startsWith("#")) continue;
           final String key = line.substring(0, i), value = line.substring(i + 1);
           if (REPLACE.put(key, value.replace("\\n", "\n")) != null) {
             Util.errln(file + ": " + key + " was assigned twice");
           }
         }
       }
     }
   } catch (final IOException ex) {
     Util.errln(ex);
   }
 }
Пример #6
0
 /**
  * Replaces the text.
  *
  * @param rc replace context
  */
 final void replace(final ReplaceContext rc) {
   try {
     final int[] select = rend.replace(rc);
     if (rc.text != null) {
       final boolean sel = editor.selected();
       setText(rc.text);
       editor.select(select[0], select[sel ? 1 : 0]);
       release(Action.CHECK);
     }
     gui.status.setText(Text.STRINGS_REPLACED);
   } catch (final Exception ex) {
     final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", "");
     gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg);
   }
 }