Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[master]
- Feature: Ability to reorder the panels in the side pane
- Feature: Option to save selected entries as plain BibTex without JabRef metadata
2.11 beta
- Some UI updates (mainly removing unnecessary boundaries)
- Feature: Gridlines are now optional (and disabled by default)
Expand Down
66 changes: 38 additions & 28 deletions src/main/java/net/sf/jabref/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import net.sf.jabref.export.SaveDatabaseAction;
import net.sf.jabref.export.SaveException;
import net.sf.jabref.export.SaveSession;
import net.sf.jabref.export.FileActions.DatabaseSaveType;
import net.sf.jabref.export.layout.Layout;
import net.sf.jabref.export.layout.LayoutHelper;
import net.sf.jabref.external.AttachFileAction;
Expand Down Expand Up @@ -411,30 +412,10 @@ public void action() throws Throwable {
}
});

actions.put("saveSelectedAs", new BaseAction () {
public void action() throws Throwable {

String chosenFile = FileDialogs.getNewFile(frame, new File(Globals.prefs.get("workingDirectory")), ".bib",
JFileChooser.SAVE_DIALOG, false);
if (chosenFile != null) {
File expFile = new File(chosenFile);
if (!expFile.exists() ||
(JOptionPane.showConfirmDialog
(frame, "'"+expFile.getName()+"' "+
Globals.lang("exists. Overwrite file?"),
Globals.lang("Save database"), JOptionPane.OK_CANCEL_OPTION)
== JOptionPane.OK_OPTION)) {

saveDatabase(expFile, true, Globals.prefs.get("defaultEncoding"));
//runCommand("save");
frame.getFileHistory().newFile(expFile.getPath());
frame.output(Globals.lang("Saved selected to")+" '"
+expFile.getPath()+"'.");
}
}
}
});

actions.put("saveSelectedAs", new SaveSelectedAction(FileActions.DatabaseSaveType.DEFAULT));

actions.put("saveSelectedAsPlain", new SaveSelectedAction(FileActions.DatabaseSaveType.PLAIN_BIBTEX));

// The action for copying selected entries.
actions.put("copy", new BaseAction() {
public void action() {
Expand Down Expand Up @@ -1716,7 +1697,7 @@ public void runCommand(String _command) {
//}).start();
}

private boolean saveDatabase(File file, boolean selectedOnly, String encoding) throws SaveException {
private boolean saveDatabase(File file, boolean selectedOnly, String encoding, FileActions.DatabaseSaveType saveType) throws SaveException {
SaveSession session;
frame.block();
try {
Expand All @@ -1725,7 +1706,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, String encoding) t
Globals.prefs, false, false, encoding, false);
else
session = FileActions.savePartOfDatabase(database, metaData, file,
Globals.prefs, mainTable.getSelectedEntries(), encoding);
Globals.prefs, mainTable.getSelectedEntries(), encoding, saveType);

} catch (UnsupportedCharsetException ex2) {
JOptionPane.showMessageDialog(frame, Globals.lang("Could not save file. "
Expand Down Expand Up @@ -1775,7 +1756,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, String encoding) t
JOptionPane.QUESTION_MESSAGE, null, Globals.ENCODINGS, encoding);
if (choice != null) {
String newEncoding = (String)choice;
return saveDatabase(file, selectedOnly, newEncoding);
return saveDatabase(file, selectedOnly, newEncoding, saveType);
} else
commit = false;
} else if (answer == JOptionPane.CANCEL_OPTION)
Expand Down Expand Up @@ -3096,5 +3077,34 @@ public void setBackAndForwardEnabledState() {
frame.forward.setEnabled(nextEntries.size() > 0);
}


private class SaveSelectedAction extends BaseAction {

private DatabaseSaveType saveType;

public SaveSelectedAction(DatabaseSaveType saveType) {
this.saveType = saveType;
}

public void action() throws Throwable {

String chosenFile = FileDialogs.getNewFile(frame, new File(Globals.prefs.get("workingDirectory")), ".bib",
JFileChooser.SAVE_DIALOG, false);
if (chosenFile != null) {
File expFile = new File(chosenFile);
if (!expFile.exists() ||
(JOptionPane.showConfirmDialog
(frame, "'"+expFile.getName()+"' "+
Globals.lang("exists. Overwrite file?"),
Globals.lang("Save database"), JOptionPane.OK_CANCEL_OPTION)
== JOptionPane.OK_OPTION)) {

saveDatabase(expFile, true, Globals.prefs.get("defaultEncoding"), saveType);
//runCommand("save");
frame.getFileHistory().newFile(expFile.getPath());
frame.output(Globals.lang("Saved selected to")+" '"
+expFile.getPath()+"'.");
}
}
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jabref/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ void addAction(Action a) {
"Save selected as ...",
Globals.lang("Save selected as ..."),
GUIGlobals.getIconUrl("saveAs")),
saveSelectedAsPlain = new GeneralAction("saveSelectedAsPlain",
"Save selected as plain BibTeX ...",
Globals.lang("Save selected as plain BibTeX ..."),
GUIGlobals.getIconUrl("saveAs")),
exportAll = ExportFormats.getExportAction(this, false),
exportSelected = ExportFormats.getExportAction(this, true),
importCurrent = ImportFormats.getImportAction(this, false),
Expand Down Expand Up @@ -1291,6 +1295,7 @@ private void fillMenu() {
file.add(saveAs);
file.add(saveAll);
file.add(saveSelectedAs);
file.add(saveSelectedAsPlain);
file.addSeparator();
//file.add(importMenu);
//file.add(importNewMenu);
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/net/sf/jabref/export/FileActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
import ca.odell.glazedlists.SortedList;

public class FileActions {


public enum DatabaseSaveType {
DEFAULT, PLAIN_BIBTEX
}

private static Pattern refPat = Pattern.compile("(#[A-Za-z]+#)"); // Used to detect string references in strings
private static BibtexString.Type previousStringType;

Expand Down Expand Up @@ -357,7 +361,7 @@ private static List<Comparator<BibtexEntry>> getSaveComparators(boolean isSaveOp
* @return A List containing warnings, if any.
*/
public static SaveSession savePartOfDatabase(BibtexDatabase database, MetaData metaData,
File file, JabRefPreferences prefs, BibtexEntry[] bes, String encoding) throws SaveException {
File file, JabRefPreferences prefs, BibtexEntry[] bes, String encoding, DatabaseSaveType saveType) throws SaveException {

TreeMap<String, BibtexEntryType> types = new TreeMap<String, BibtexEntryType>(); // Map
// to
Expand All @@ -382,9 +386,11 @@ public static SaveSession savePartOfDatabase(BibtexDatabase database, MetaData m
// Define our data stream.
VerifyingWriter fw = session.getWriter();

// Write signature.
writeBibFileHeader(fw, encoding);

if (saveType != DatabaseSaveType.PLAIN_BIBTEX) {
// Write signature.
writeBibFileHeader(fw, encoding);
}

// Write preamble if there is one.
writePreamble(fw, database.getPreamble());

Expand Down Expand Up @@ -423,7 +429,7 @@ public static SaveSession savePartOfDatabase(BibtexDatabase database, MetaData m
}

// Write meta data.
if (metaData != null) {
if (saveType != DatabaseSaveType.PLAIN_BIBTEX && metaData != null) {
metaData.writeMetaData(fw);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/export/SaveDatabaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, String encoding) t
Globals.prefs, false, false, encoding, false);
else
session = FileActions.savePartOfDatabase(panel.database(), panel.metaData(), file,
Globals.prefs, panel.getSelectedEntries(), encoding);
Globals.prefs, panel.getSelectedEntries(), encoding, FileActions.DatabaseSaveType.DEFAULT);

} catch (UnsupportedCharsetException ex2) {
JOptionPane.showMessageDialog(frame, Globals.lang("Could not save file. "
Expand Down