Пример #1
0
 @Override
 public void update() {
   if (cancelled) {
     frame.unblock();
     return;
   }
   if (unsuccessfulRenames > 0) { // Rename failed for at least one entry
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang(
             "File rename failed for %0 entries.", Integer.toString(unsuccessfulRenames)),
         Localization.lang("Autogenerate PDF Names"),
         JOptionPane.INFORMATION_MESSAGE);
   }
   if (modifiedEntriesCount > 0) {
     panel.updateEntryEditorIfShowing();
     panel.markBaseChanged();
   }
   String message;
   switch (modifiedEntriesCount) {
     case 0:
       message = Localization.lang("No entry needed a clean up");
       break;
     case 1:
       message = Localization.lang("One entry needed a clean up");
       break;
     default:
       message =
           Localization.lang(
               "%0 entries needed a clean up", Integer.toString(modifiedEntriesCount));
       break;
   }
   panel.output(message);
   frame.unblock();
 }
 private void updateTables() {
   if (frame.getTabbedPane().getTabCount() == 0) {
     return;
   }
   for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
     frame.getTabbedPane().getComponentAt(i);
   }
 }
Пример #3
0
 @Override
 public void actionPerformed(ActionEvent e) {
   databases = frame.getTabbedPane().getTabCount();
   saved = 0;
   frame.output(Localization.lang("Saving all databases..."));
   Spin.off(this);
   run();
   frame.output(Localization.lang("Save all finished."));
 }
Пример #4
0
 @Override
 public void run() {
   for (int i = 0; i < databases; i++) {
     if (i < frame.getTabbedPane().getTabCount()) {
       // System.out.println("Base "+i);
       BasePanel panel = frame.baseAt(i);
       if (panel.getFile() == null) {
         frame.showBaseAt(i);
       }
       panel.runCommand("save");
       // TODO: can we find out whether the save was actually done or not?
       saved++;
     }
   }
 }
  /**
   * Cycle through all databases, and make sure everything is updated with the new type
   * customization. This includes making sure all entries have a valid type, that no obsolete entry
   * editors are around, and that the right-click menus' change type menu is up-to-date.
   */
  private void updateTypesForEntries(String typeName) {
    if (frame.getTabbedPane().getTabCount() == 0) {
      return;
    }
    for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
      BasePanel bp = (BasePanel) frame.getTabbedPane().getComponentAt(i);

      // Invalidate associated cached entry editor
      bp.entryEditors.remove(typeName);

      for (BibtexEntry entry : bp.database().getEntries()) {
        entry.updateType();
      }
    }
  }
Пример #6
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();
  }
Пример #7
0
 @Override
 public void init() {
   cancelled = false;
   modifiedEntriesCount = 0;
   int numSelected = panel.getSelectedEntries().length;
   if (numSelected == 0) { // None selected. Inform the user to select entries first.
     JOptionPane.showMessageDialog(
         frame,
         Localization.lang("First select entries to clean up."),
         Localization.lang("Cleanup entry"),
         JOptionPane.INFORMATION_MESSAGE);
     cancelled = true;
     return;
   }
   frame.block();
   panel.output(
       Localization.lang("Doing a cleanup for %0 entries...", Integer.toString(numSelected)));
 }
Пример #8
0
  public void actionPerformed(ActionEvent event) {
    int selected = editor.getSelectedRow();
    if (selected == -1) return;
    FileListEntry flEntry = editor.getTableModel().getEntry(selected);
    // Check if the current file exists:
    String ln = flEntry.getLink();
    boolean httpLink = ln.toLowerCase().startsWith("http");
    if (httpLink) {
      // TODO: notify that this operation cannot be done on remote links

    }

    // Get an absolute path representation:
    String dir = frame.basePanel().metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
    if ((dir == null) || (dir.trim().length() == 0) || !(new File(dir)).exists()) {
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("File_directory_is_not_set_or_does_not_exist!"),
          Globals.lang("Move/Rename file"),
          JOptionPane.ERROR_MESSAGE);
      return;
    }
    File file = new File(ln);
    if (!file.isAbsolute()) {
      file = Util.expandFilename(ln, new String[] {dir});
    }
    if ((file != null) && file.exists()) {
      // Ok, we found the file. Now get a new name:
      String extension = null;
      if (flEntry.getType() != null) extension = "." + flEntry.getType().getExtension();

      File newFile = null;
      boolean repeat = true;
      while (repeat) {
        repeat = false;
        String chosenFile;
        if (toFileDir) {
          String suggName = eEditor.getEntry().getCiteKey() + extension;
          CheckBoxMessage cbm =
              new CheckBoxMessage(
                  Globals.lang("Move file to file directory?"),
                  Globals.lang("Rename to '%0'", suggName),
                  Globals.prefs.getBoolean("renameOnMoveFileToFileDir"));
          int answer;
          // Only ask about renaming file if the file doesn't have the proper name already:
          if (!suggName.equals(file.getName()))
            answer =
                JOptionPane.showConfirmDialog(
                    frame, cbm, Globals.lang("Move/Rename file"), JOptionPane.YES_NO_OPTION);
          else
            answer =
                JOptionPane.showConfirmDialog(
                    frame,
                    Globals.lang("Move file to file directory?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.YES_NO_OPTION);
          if (answer != JOptionPane.YES_OPTION) return;
          Globals.prefs.putBoolean("renameOnMoveFileToFileDir", cbm.isSelected());
          StringBuilder sb = new StringBuilder(dir);
          if (!dir.endsWith(File.separator)) sb.append(File.separator);
          if (cbm.isSelected()) {
            // Rename:
            sb.append(suggName);
          } else {
            // Do not rename:
            sb.append(file.getName());
          }
          chosenFile = sb.toString();
        } else {
          chosenFile =
              FileDialogs.getNewFile(frame, file, extension, JFileChooser.SAVE_DIALOG, false);
        }
        if (chosenFile == null) {
          return; // cancelled
        }
        newFile = new File(chosenFile);
        // Check if the file already exists:
        if (newFile.exists()
            && (JOptionPane.showConfirmDialog(
                    frame,
                    "'" + newFile.getName() + "' " + Globals.lang("exists. Overwrite file?"),
                    Globals.lang("Move/Rename file"),
                    JOptionPane.OK_CANCEL_OPTION)
                != JOptionPane.OK_OPTION)) {
          if (!toFileDir) repeat = true;
          else return;
        }
      }

      if (!newFile.equals(file)) {
        try {
          boolean success = file.renameTo(newFile);
          if (!success) {
            success = Util.copyFile(file, newFile, true);
          }
          if (success) {
            // Remove the original file:
            file.delete();
            // Relativise path, if possible.
            String canPath = (new File(dir)).getCanonicalPath();
            if (newFile.getCanonicalPath().startsWith(canPath)) {
              if ((newFile.getCanonicalPath().length() > canPath.length())
                  && (newFile.getCanonicalPath().charAt(canPath.length()) == File.separatorChar))
                flEntry.setLink(newFile.getCanonicalPath().substring(1 + canPath.length()));
              else flEntry.setLink(newFile.getCanonicalPath().substring(canPath.length()));

            } else flEntry.setLink(newFile.getCanonicalPath());
            eEditor.updateField(editor);
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("File moved"),
                Globals.lang("Move/Rename file"),
                JOptionPane.INFORMATION_MESSAGE);
          } else {
            JOptionPane.showMessageDialog(
                frame,
                Globals.lang("Move file failed"),
                Globals.lang("Move/Rename file"),
                JOptionPane.ERROR_MESSAGE);
          }

        } catch (SecurityException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        } catch (IOException ex) {
          ex.printStackTrace();
          JOptionPane.showMessageDialog(
              frame,
              Globals.lang("Could not move file") + ": " + ex.getMessage(),
              Globals.lang("Move/Rename file"),
              JOptionPane.ERROR_MESSAGE);
        }
      }
    } else {

      // File doesn't exist, so we can't move it.
      JOptionPane.showMessageDialog(
          frame,
          Globals.lang("Could not find file '%0'.", flEntry.getLink()),
          Globals.lang("File not found"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
  @Override
  public void run() {
    BasePanel panel = frame.basePanel();
    if (panel == null) {
      return;
    }
    if (panel.getSelectedEntries().length == 0) {
      message = Localization.lang("No entries selected.");
      getCallBack().update();
      return;
    }

    Map<String, IExportFormat> m = ExportFormats.getExportFormats();
    IExportFormat[] formats = new ExportFormat[m.size()];
    String[] array = new String[formats.length];

    int piv = 0;
    for (IExportFormat format : m.values()) {
      formats[piv] = format;
      array[piv] = format.getDisplayName();
      piv++;
    }

    JList list = new JList(array);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.setSelectionInterval(0, 0);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    int answer =
        JOptionPane.showOptionDialog(
            frame,
            list,
            Localization.lang("Select format"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            new String[] {Localization.lang("Ok"), Localization.lang("Cancel")},
            Localization.lang("Ok"));

    if (answer == JOptionPane.NO_OPTION) {
      return;
    }

    IExportFormat format = formats[list.getSelectedIndex()];

    // Set the global variable for this database's file directory before exporting,
    // so formatters can resolve linked files correctly.
    // (This is an ugly hack!)
    Globals.prefs.fileDirForDatabase =
        frame.basePanel().metaData().getFileDirectory(GUIGlobals.FILE_FIELD);
    // Also store the database's file in a global variable:
    Globals.prefs.databaseFile = frame.basePanel().metaData().getFile();

    /*final boolean custom = (list.getSelectedIndex() >= Globals.STANDARD_EXPORT_COUNT);
    String dir = null;
    if (custom) {
        int index = list.getSelectedIndex() - Globals.STANDARD_EXPORT_COUNT;
        dir = (String) (Globals.prefs.customExports.getElementAt(index)[1]);
        File f = new File(dir);
        lfName = f.getName();
        lfName = lfName.substring(0, lfName.indexOf("."));
        // Remove file name - we want the directory only.
        dir = f.getParent() + System.getProperty("file.separator");
    }
    final String format = lfName,
            directory = dir;
    */
    File tmp = null;
    Reader reader = null;
    try {
      // To simplify the exporter API we simply do a normal export to a temporary
      // file, and read the contents afterwards:
      tmp = File.createTempFile("jabrefCb", ".tmp");
      tmp.deleteOnExit();
      BibtexEntry[] bes = panel.getSelectedEntries();
      HashSet<String> entries = new HashSet<String>(bes.length);
      for (BibtexEntry be : bes) {
        entries.add(be.getId());
      }

      // Write to file:
      format.performExport(database, panel.metaData(), tmp.getPath(), panel.getEncoding(), entries);
      // Read the file and put the contents on the clipboard:
      StringBuilder sb = new StringBuilder();
      reader = new InputStreamReader(new FileInputStream(tmp), panel.getEncoding());
      int s;
      while ((s = reader.read()) != -1) {
        sb.append((char) s);
      }
      ClipboardOwner owner =
          new ClipboardOwner() {

            @Override
            public void lostOwnership(Clipboard clipboard, Transferable content) {}
          };
      // StringSelection ss = new StringSelection(sw.toString());
      RtfSelection rs = new RtfSelection(sb.toString());
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(rs, owner);
      message = Localization.lang("Entries exported to clipboard") + ": " + bes.length;

    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
      message = Localization.lang("Error exporting to clipboard");
    } finally {
      // Clean up:
      if (tmp != null) {
        tmp.delete();
      }
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Пример #10
0
 @Override
 public void update() {
   frame.output(message);
 }