Ejemplo n.º 1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    BasePanel bp = frame.basePanel();
    if (bp == null) {
      return;
    }
    BibtexEntry[] entries = bp.getSelectedEntries();
    // Lazy creation of the dialog:
    if (diag == null) {
      createDialog();
    }
    cancelled = true;
    prepareDialog(entries.length > 0);
    Util.placeDialog(diag, frame);
    diag.setVisible(true);
    if (cancelled) {
      return;
    }

    Collection<BibtexEntry> entryList;
    // If all entries should be treated, change the entries array:
    if (all.isSelected()) {
      entryList = bp.database().getEntries();
    } else {
      entryList = Arrays.asList(entries);
    }
    String toSet = text.getText();
    if (toSet.isEmpty()) {
      toSet = null;
    }
    String[] fields = getFieldNames(field.getText().trim().toLowerCase());
    NamedCompound ce = new NamedCompound(Globals.lang("Set field"));
    if (rename.isSelected()) {
      if (fields.length > 1) {
        // TODO: message: can only rename a single field
      } else {
        ce.addEdit(
            Util.massRenameField(entryList, fields[0], renameTo.getText(), overwrite.isSelected()));
      }
    } else {
      for (String field1 : fields) {
        ce.addEdit(
            Util.massSetField(
                entryList, field1, set.isSelected() ? toSet : null, overwrite.isSelected()));
      }
    }
    ce.end();
    bp.undoManager.addEdit(ce);
    bp.markBaseChanged();
  }
Ejemplo n.º 2
0
  /**
   * This method performs the actual changes.
   *
   * @param panel
   * @param pr
   * @param fileDir The path to the file directory to set, or null if it should not be set.
   */
  private void makeChanges(
      BasePanel panel,
      ParserResult pr,
      boolean upgradePrefs,
      boolean upgradeDatabase,
      String fileDir) {

    if (upgradeDatabase) {
      // Update file links links in the database:
      NamedCompound ce =
          Util.upgradePdfPsToFile(pr.getDatabase(), FileLinksUpgradeWarning.FIELDS_TO_LOOK_FOR);
      panel.undoManager.addEdit(ce);
      panel.markBaseChanged();
    }

    if (fileDir != null) {
      Globals.prefs.put(GUIGlobals.FILE_FIELD + "Directory", fileDir);
    }

    if (upgradePrefs) {
      // Exchange table columns:
      Globals.prefs.putBoolean(JabRefPreferences.PDF_COLUMN, Boolean.FALSE);
      Globals.prefs.putBoolean(JabRefPreferences.FILE_COLUMN, Boolean.TRUE);

      // Modify General fields if necessary:
      // If we don't find the file field, insert it at the bottom of the first tab:
      if (!showsFileInGenFields()) {
        String gfs = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "0");
        // System.out.println(gfs);
        StringBuilder sb = new StringBuilder(gfs);
        if (gfs.length() > 0) {
          sb.append(";");
        }
        sb.append(GUIGlobals.FILE_FIELD);
        Globals.prefs.put(JabRefPreferences.CUSTOM_TAB_FIELDS + "0", sb.toString());
        Globals.prefs.updateEntryEditorTabList();
        panel.frame().removeCachedEntryEditors();
      }
      panel.frame().setupAllTables();
    }
  }
Ejemplo n.º 3
0
  private BibtexEntry createNewEntry() {

    // Find out what type is wanted.
    EntryTypeDialog etd = new EntryTypeDialog(frame);
    // We want to center the dialog, to make it look nicer.
    Util.placeDialog(etd, frame);
    etd.setVisible(true);
    BibtexEntryType type = etd.getChoice();

    if (type != null) { // Only if the dialog was not cancelled.
      String id = Util.createNeutralId();
      final BibtexEntry be = new BibtexEntry(id, type);
      try {
        panel.database().insertEntry(be);

        // Set owner/timestamp if options are enabled:
        ArrayList<BibtexEntry> list = new ArrayList<BibtexEntry>();
        list.add(be);
        Util.setAutomaticFields(list, true, true, false);

        // Create an UndoableInsertEntry object.
        panel.undoManager.addEdit(new UndoableInsertEntry(panel.database(), be, panel));
        panel.output(
            Globals.lang("Added new")
                + " '"
                + type.getName().toLowerCase()
                + "' "
                + Globals.lang("entry")
                + ".");

        // We are going to select the new entry. Before that, make sure that we are in
        // show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR
        // mode which makes sure the selection will trigger display of the entry editor
        // and adjustment of the splitter.
        if (panel.getMode() != panel.SHOWING_EDITOR) {
          panel.setMode(panel.WILL_SHOW_EDITOR);
        }

        /*int row = entryTable.findEntry(be);
        if (row >= 0)
            // Selects the entry. The selection listener will open the editor.
             if (row >= 0) {
                try{
                    entryTable.setRowSelectionInterval(row, row);
                }catch(IllegalArgumentException e){
                    System.out.println("RowCount: " + entryTable.getRowCount());
                }

                //entryTable.setActiveRow(row);
                entryTable.ensureVisible(row);
             }
        else {
            // The entry is not visible in the table, perhaps due to a filtering search
            // or group selection. Show the entry editor anyway:
            panel.showEntry(be);
        }   */
        panel.showEntry(be);
        panel.markBaseChanged(); // The database just changed.
        new FocusRequester(panel.getEntryEditor(be));
        return be;
      } catch (KeyCollisionException ex) {
        Util.pr(ex.getMessage());
      }
    }
    return null;
  }