From a0061be3221d87436051a018847717627fcd45d4 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Oct 2015 15:02:35 +0200 Subject: [PATCH 01/10] Moved PushToXXX.java to external.push --- .../sf/jabref/external/{ => push}/PushToApplication.java | 2 +- .../external/{ => push}/PushToApplicationAction.java | 2 +- .../external/{ => push}/PushToApplicationButton.java | 2 +- .../net/sf/jabref/external/{ => push}/PushToEmacs.java | 2 +- .../sf/jabref/external/{ => push}/PushToLatexEditor.java | 3 ++- .../net/sf/jabref/external/{ => push}/PushToLyx.java | 2 +- .../sf/jabref/external/{ => push}/PushToTeXstudio.java | 3 ++- .../sf/jabref/external/{ => push}/PushToTexmaker.java | 3 ++- .../net/sf/jabref/external/{ => push}/PushToVim.java | 2 +- .../net/sf/jabref/external/{ => push}/PushToWinEdt.java | 3 ++- src/main/java/net/sf/jabref/gui/JabRefFrame.java | 2 +- .../java/net/sf/jabref/gui/preftabs/ExternalTab.java | 9 +++++++++ .../java/net/sf/jabref/openoffice/OpenOfficePanel.java | 2 +- 13 files changed, 25 insertions(+), 12 deletions(-) rename src/main/java/net/sf/jabref/external/{ => push}/PushToApplication.java (98%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToApplicationAction.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToApplicationButton.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToEmacs.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToLatexEditor.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToLyx.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToTeXstudio.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToTexmaker.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToVim.java (99%) rename src/main/java/net/sf/jabref/external/{ => push}/PushToWinEdt.java (99%) diff --git a/src/main/java/net/sf/jabref/external/PushToApplication.java b/src/main/java/net/sf/jabref/external/push/PushToApplication.java similarity index 98% rename from src/main/java/net/sf/jabref/external/PushToApplication.java rename to src/main/java/net/sf/jabref/external/push/PushToApplication.java index 0ffe95976e2..72767a8e1c1 100644 --- a/src/main/java/net/sf/jabref/external/PushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplication.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.model.database.BibtexDatabase; diff --git a/src/main/java/net/sf/jabref/external/PushToApplicationAction.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToApplicationAction.java rename to src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java index 1de2ccc914a..d3c42c7744e 100644 --- a/src/main/java/net/sf/jabref/external/PushToApplicationAction.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.awt.event.ActionEvent; diff --git a/src/main/java/net/sf/jabref/external/PushToApplicationButton.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToApplicationButton.java rename to src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java index 443bafe92c4..9e7c934213e 100644 --- a/src/main/java/net/sf/jabref/external/PushToApplicationButton.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import com.jgoodies.forms.builder.ButtonBarBuilder; diff --git a/src/main/java/net/sf/jabref/external/PushToEmacs.java b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToEmacs.java rename to src/main/java/net/sf/jabref/external/push/PushToEmacs.java index 6c5a5d8f420..e5d09e657b6 100644 --- a/src/main/java/net/sf/jabref/external/PushToEmacs.java +++ b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/net/sf/jabref/external/PushToLatexEditor.java b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToLatexEditor.java rename to src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java index 51f73ce9e4c..ac23068a096 100644 --- a/src/main/java/net/sf/jabref/external/PushToLatexEditor.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java @@ -13,13 +13,14 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.IOException; import javax.swing.*; import net.sf.jabref.*; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.gui.BasePanel; diff --git a/src/main/java/net/sf/jabref/external/PushToLyx.java b/src/main/java/net/sf/jabref/external/push/PushToLyx.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToLyx.java rename to src/main/java/net/sf/jabref/external/push/PushToLyx.java index 273e47d8860..5df2ccb9038 100644 --- a/src/main/java/net/sf/jabref/external/PushToLyx.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLyx.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.BufferedWriter; import java.io.File; diff --git a/src/main/java/net/sf/jabref/external/PushToTeXstudio.java b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToTeXstudio.java rename to src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java index a87ac8e5c71..339ca957b1f 100644 --- a/src/main/java/net/sf/jabref/external/PushToTeXstudio.java +++ b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.IOException; import java.io.InputStream; @@ -21,6 +21,7 @@ import javax.swing.*; import net.sf.jabref.*; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.gui.BasePanel; diff --git a/src/main/java/net/sf/jabref/external/PushToTexmaker.java b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToTexmaker.java rename to src/main/java/net/sf/jabref/external/push/PushToTexmaker.java index e9284a110e1..4885a37a114 100644 --- a/src/main/java/net/sf/jabref/external/PushToTexmaker.java +++ b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java @@ -13,13 +13,14 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.IOException; import javax.swing.*; import net.sf.jabref.*; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.gui.BasePanel; diff --git a/src/main/java/net/sf/jabref/external/PushToVim.java b/src/main/java/net/sf/jabref/external/push/PushToVim.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToVim.java rename to src/main/java/net/sf/jabref/external/push/PushToVim.java index 3515ca4ef38..a043b9b0db3 100644 --- a/src/main/java/net/sf/jabref/external/PushToVim.java +++ b/src/main/java/net/sf/jabref/external/push/PushToVim.java @@ -13,7 +13,7 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; diff --git a/src/main/java/net/sf/jabref/external/PushToWinEdt.java b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java similarity index 99% rename from src/main/java/net/sf/jabref/external/PushToWinEdt.java rename to src/main/java/net/sf/jabref/external/push/PushToWinEdt.java index 981681115bd..48e85cdfb4e 100644 --- a/src/main/java/net/sf/jabref/external/PushToWinEdt.java +++ b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java @@ -13,13 +13,14 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.jabref.external; +package net.sf.jabref.external.push; import java.io.IOException; import javax.swing.*; import net.sf.jabref.*; + import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.gui.BasePanel; diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index a6132827000..cb75bac418f 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -73,7 +73,7 @@ import net.sf.jabref.exporter.SaveAllAction; import net.sf.jabref.exporter.SaveDatabaseAction; import net.sf.jabref.external.ExternalFileTypeEditor; -import net.sf.jabref.external.PushToApplicationButton; +import net.sf.jabref.external.push.PushToApplicationButton; import net.sf.jabref.groups.EntryTableTransferHandler; import net.sf.jabref.groups.GroupSelector; import net.sf.jabref.gui.menus.help.ForkMeOnGitHubAction; diff --git a/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java b/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java index 505b29f3f3e..0a1207e1f01 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java @@ -27,6 +27,15 @@ import net.sf.jabref.*; import net.sf.jabref.external.*; +import net.sf.jabref.external.push.PushToApplication; +import net.sf.jabref.external.push.PushToApplicationButton; +import net.sf.jabref.external.push.PushToEmacs; +import net.sf.jabref.external.push.PushToLatexEditor; +import net.sf.jabref.external.push.PushToLyx; +import net.sf.jabref.external.push.PushToTeXstudio; +import net.sf.jabref.external.push.PushToTexmaker; +import net.sf.jabref.external.push.PushToVim; +import net.sf.jabref.external.push.PushToWinEdt; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; diff --git a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java index 0e81a1c356c..3fb303ab8bf 100644 --- a/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java +++ b/src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java @@ -21,7 +21,7 @@ import net.sf.jabref.*; import net.sf.jabref.exporter.layout.Layout; import net.sf.jabref.exporter.layout.LayoutHelper; -import net.sf.jabref.external.PushToApplication; +import net.sf.jabref.external.push.PushToApplication; import net.sf.jabref.gui.*; import net.sf.jabref.gui.worker.AbstractWorker; import net.sf.jabref.gui.actions.BrowseAction; From 3c7eaa7774a9133cafd5d6b8abc896770d83667f Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Oct 2015 17:53:46 +0200 Subject: [PATCH 02/10] Draft AbstractPushToApplication.java and PushToTexMaker.java using the former --- .../push/AbstractPushToApplication.java | 142 ++++++++++++++++++ .../jabref/external/push/PushToTexmaker.java | 109 +------------- 2 files changed, 150 insertions(+), 101 deletions(-) create mode 100644 src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java diff --git a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java new file mode 100644 index 00000000000..5dd719fd76b --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -0,0 +1,142 @@ +/* Copyright (C) 2015 JabRef contributors. + Copyright (C) 2015 Oscar Gustafsson. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +package net.sf.jabref.external.push; + +import java.io.IOException; + +import javax.swing.*; + +import net.sf.jabref.*; + +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.layout.FormLayout; +import net.sf.jabref.gui.BasePanel; +import net.sf.jabref.gui.actions.BrowseAction; +import net.sf.jabref.logic.l10n.Localization; +import net.sf.jabref.model.database.BibtexDatabase; +import net.sf.jabref.model.entry.BibtexEntry; + +/** + * Class for pushing entries into TexMaker. + */ +public abstract class AbstractPushToApplication implements PushToApplication { + + protected boolean couldNotCall = false; + protected boolean notDefined = false; + protected JPanel settings; + protected final JTextField Path = new JTextField(30); + protected String searchPath = null; + protected String searchPathPreferenceKey = null; + protected String citeCommand = Globals.prefs.get(JabRefPreferences.CITE_COMMAND); + + @Override + public String getName() { + return Localization.menuTitle("Insert selected citations into %d", getApplicationName()); + } + + @Override + public String getTooltip() { + return Localization.lang("Push to %0", getApplicationName()); + } + + + @Override + public String getKeyStrokeName() { + return null; + } + + @Override + public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { + + couldNotCall = false; + notDefined = false; + + initParameters(); + searchPath = Globals.prefs.get(searchPathPreferenceKey); + + if ((searchPath == null) || searchPath.trim().isEmpty()) { + notDefined = true; + return; + } + + try { + Runtime.getRuntime().exec(getCommandLine(keyString)); + + } + + catch (IOException excep) { + couldNotCall = true; + excep.printStackTrace(); + } + } + + + @Override + public void operationCompleted(BasePanel panel) { + if (notDefined) { + // @formatter:off + panel.output(Localization.lang("Error") + ": " + + Localization.lang("Path to %0 not defined", getApplicationName()) + "."); + } else if (couldNotCall) { + panel.output(Localization.lang("Error") + ": " + + Localization.lang("Could not call executable") + " '" + searchPath + "'."); + // @formatter:on + } else { + panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); + } + } + + @Override + public boolean requiresBibtexKeys() { + return true; + } + + protected String getCommandLine(String keyString) { + return null; + } + + @Override + public JPanel getSettingsPanel() { + initParameters(); + searchPath = Globals.prefs.get(searchPathPreferenceKey); + if (settings == null) { + initSettingsPanel(); + } + Path.setText(searchPath); + return settings; + } + + protected void initParameters() { + searchPathPreferenceKey = null; + } + + private void initSettingsPanel() { + FormBuilder builder = FormBuilder.create(); + builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); + builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); + builder.add(Path).xy(3, 1); + BrowseAction action = BrowseAction.buildForFile(Path); + JButton browse = new JButton(Localization.lang("Browse")); + browse.addActionListener(action); + settings = builder.build(); + } + + @Override + public void storeSettings() { + Globals.prefs.put(searchPathPreferenceKey, Path.getText()); + } +} diff --git a/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java index 4885a37a114..37521d394dd 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java +++ b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java @@ -1,4 +1,5 @@ -/* Copyright (C) 2003-2015 JabRef contributors. +/* Copyright (C) 2015 JabRef contributors. + Copyright (C) 2015 Oscar Gustafsson. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -15,129 +16,35 @@ */ package net.sf.jabref.external.push; -import java.io.IOException; - import javax.swing.*; import net.sf.jabref.*; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.database.BibtexDatabase; -import net.sf.jabref.model.entry.BibtexEntry; +import net.sf.jabref.external.push.AbstractPushToApplication; /** * Class for pushing entries into TexMaker. */ -public class PushToTexmaker implements PushToApplication { - - private boolean couldNotCall; - private boolean notDefined; - private JPanel settings; - private final JTextField texmakerPath = new JTextField(30); - private final JTextField citeCommand = new JTextField(30); - - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0", getApplicationName()); - } +public class PushToTexmaker extends AbstractPushToApplication { @Override public String getApplicationName() { return "Texmaker"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("texmaker"); } @Override - public String getKeyStrokeName() { - return null; + protected String getCommandLine(String keyString) { + return searchPath + " " + "-insert " + citeCommand + "{" + keyString + "}"; } - @Override - public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { - - couldNotCall = false; - notDefined = false; - - String texMaker = Globals.prefs.get(JabRefPreferences.TEXMAKER_PATH); - - if ((texMaker == null) || texMaker.trim().isEmpty()) { - notDefined = true; - return; - } - - try { - Runtime.getRuntime().exec(texMaker + " " + "-insert " + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_TEXMAKER) + "{" + keyString + "}"); - - } - - catch (IOException excep) { - couldNotCall = true; - excep.printStackTrace(); - } - } - - @Override - public void operationCompleted(BasePanel panel) { - if (notDefined) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " - + Localization.lang("Path to %0 not defined", getApplicationName()) + "."); - } else if (couldNotCall) { - panel.output(Localization.lang("Error") + ": " - + Localization.lang("Could not call executable") + " '" + Globals.prefs.get(JabRefPreferences.TEXMAKER_PATH) + "'."); - // @formatter:on - } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); - } - } - - @Override - public boolean requiresBibtexKeys() { - return true; + protected void initParameters() { + searchPathPreferenceKey = JabRefPreferences.TEXMAKER_PATH; } - @Override - public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - texmakerPath.setText(Globals.prefs.get(JabRefPreferences.TEXMAKER_PATH)); - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_TEXMAKER)); - return settings; - } - - private void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); - builder.add(texmakerPath).xy(3, 1); - BrowseAction action = BrowseAction.buildForFile(texmakerPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5, 1); - builder.add(Localization.lang("Cite command") + ":").xy(1, 3); - builder.add(citeCommand).xy(3, 3); - settings = builder.build(); - } - - @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.TEXMAKER_PATH, texmakerPath.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_TEXMAKER, citeCommand.getText()); - } } From 2ce65681723fad257fbffdfb5ae45633c4eb65ed Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Oct 2015 21:35:29 +0200 Subject: [PATCH 03/10] Added function to guess command path depending on operating system --- .../java/net/sf/jabref/JabRefPreferences.java | 23 +++++-------------- .../java/net/sf/jabref/logic/util/OS.java | 20 ++++++++++++++++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/sf/jabref/JabRefPreferences.java b/src/main/java/net/sf/jabref/JabRefPreferences.java index 57e1fe152f5..e20d49d83b5 100644 --- a/src/main/java/net/sf/jabref/JabRefPreferences.java +++ b/src/main/java/net/sf/jabref/JabRefPreferences.java @@ -294,12 +294,6 @@ public class JabRefPreferences { public static final String FILECHOOSER_DISABLE_RENAME = "filechooserDisableRename"; public static final String USE_NATIVE_FILE_DIALOG_ON_MAC = "useNativeFileDialogOnMac"; public static final String FLOAT_MARKED_ENTRIES = "floatMarkedEntries"; - public static final String CITE_COMMAND_LED = "citeCommandLed"; - public static final String CITE_COMMAND_WIN_EDT = "citeCommandWinEdt"; - public static final String CITE_COMMAND_EMACS = "citeCommandEmacs"; - public static final String CITE_COMMAND_TEXMAKER = "citeCommandTexmaker"; - public static final String CITE_COMMAND_VIM = "citeCommandVim"; - public static final String CITE_COMMAND_TEXSTUDIO = "citeCommandTeXstudio"; public static final String CITE_COMMAND = "citeCommand"; public static final String EXTERNAL_JOURNAL_LISTS = "externalJournalLists"; public static final String PERSONAL_JOURNAL_LIST = "personalJournalList"; @@ -430,6 +424,11 @@ private JabRefPreferences() { // load user preferences prefs = Preferences.userNodeForPackage(JabRef.class); + defaults.put(TEXMAKER_PATH, OS.guessProgramPath("texmaker", "Texmaker")); + defaults.put(WIN_EDT_PATH, OS.guessProgramPath("WinEdt", "WinEdt Team\\WinEdt")); + defaults.put(LATEX_EDITOR_PATH, OS.guessProgramPath("LEd", "LEd")); + defaults.put(TEXSTUDIO_PATH, OS.guessProgramPath("texstudio", "TeXstudio")); + if (OS.OS_X) { //defaults.put("pdfviewer", "/Applications/Preview.app"); //defaults.put("psviewer", "/Applications/Preview.app"); @@ -444,9 +443,6 @@ private JabRefPreferences() { //defaults.put("psviewer", "cmd.exe /c start /b"); //defaults.put("htmlviewer", "cmd.exe /c start /b"); defaults.put(WIN_LOOK_AND_FEEL, "com.jgoodies.looks.windows.WindowsLookAndFeel"); - defaults.put(WIN_EDT_PATH, "C:\\Program Files\\WinEdt Team\\WinEdt\\WinEdt.exe"); - defaults.put(LATEX_EDITOR_PATH, "C:\\Program Files\\LEd\\LEd.exe"); - defaults.put(TEXMAKER_PATH, "C:\\Program Files\\Texmaker\\texmaker.exe"); defaults.put(EMACS_PATH, "emacsclient.exe"); defaults.put(EMACS_23, true); defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-n -e"); @@ -463,7 +459,6 @@ private JabRefPreferences() { defaults.put(EMACS_PATH, "gnuclient"); defaults.put(EMACS_23, false); defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-batch -eval"); - defaults.put(TEXMAKER_PATH, "texmaker"); } defaults.put(USE_PROXY, Boolean.FALSE); @@ -755,13 +750,7 @@ private JabRefPreferences() { defaults.put(PERSONAL_JOURNAL_LIST, null); defaults.put(EXTERNAL_JOURNAL_LISTS, null); - defaults.put(CITE_COMMAND, "cite"); // obsoleted by the app-specific ones - defaults.put(CITE_COMMAND_VIM, "\\cite"); - defaults.put(CITE_COMMAND_EMACS, "\\cite"); - defaults.put(CITE_COMMAND_WIN_EDT, "\\cite"); - defaults.put(CITE_COMMAND_TEXSTUDIO, "\\cite"); - defaults.put(CITE_COMMAND_LED, "\\cite"); - defaults.put(CITE_COMMAND_TEXMAKER, "\\cite"); + defaults.put(CITE_COMMAND, "\\cite"); // obsoleted by the app-specific ones (not any more?) defaults.put(FLOAT_MARKED_ENTRIES, Boolean.TRUE); defaults.put(USE_NATIVE_FILE_DIALOG_ON_MAC, Boolean.FALSE); diff --git a/src/main/java/net/sf/jabref/logic/util/OS.java b/src/main/java/net/sf/jabref/logic/util/OS.java index ca5909c1eb4..52d242660d2 100644 --- a/src/main/java/net/sf/jabref/logic/util/OS.java +++ b/src/main/java/net/sf/jabref/logic/util/OS.java @@ -11,4 +11,24 @@ public class OS { public static final boolean LINUX = osName.startsWith("linux"); public static final boolean WINDOWS = osName.startsWith("win"); public static final boolean OS_X = osName.startsWith("mac"); + + public static final String guessProgramPath(String programName, String windowsDirectory) { + if (OS.WINDOWS) { + String progFiles = System.getenv("ProgramFiles(x86)"); + if (progFiles == null) { + progFiles = System.getenv("ProgramFiles"); + } + if (windowsDirectory != null) { + return progFiles + "\\" + windowsDirectory + "\\" + programName + ".exe"; + } else { + return progFiles + "\\" + programName + ".exe"; + } + } else { + return programName; + } + } + + public static final String guessProgramPath(String programName) { + return guessProgramPath(programName); + } } From f01df4724bd26d712159c9f4eb6b9c6c4d470109 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Oct 2015 21:37:34 +0200 Subject: [PATCH 04/10] Updated and used AbstractPushToApplication for all external pushing --- .../push/AbstractPushToApplication.java | 54 +++--- .../external/push/PushToApplication.java | 35 ++-- .../push/PushToApplicationAction.java | 11 +- .../sf/jabref/external/push/PushToEmacs.java | 115 +++++------- .../external/push/PushToLatexEditor.java | 109 +----------- .../sf/jabref/external/push/PushToLyx.java | 50 +----- .../jabref/external/push/PushToTeXstudio.java | 167 +----------------- .../jabref/external/push/PushToTexmaker.java | 13 +- .../sf/jabref/external/push/PushToVim.java | 55 ++---- .../sf/jabref/external/push/PushToWinEdt.java | 109 +----------- 10 files changed, 145 insertions(+), 573 deletions(-) diff --git a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java index 5dd719fd76b..c04e2c3d809 100644 --- a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -31,7 +31,7 @@ import net.sf.jabref.model.entry.BibtexEntry; /** - * Class for pushing entries into TexMaker. + * Abstract class for pushing entries into different editors. */ public abstract class AbstractPushToApplication implements PushToApplication { @@ -39,10 +39,11 @@ public abstract class AbstractPushToApplication implements PushToApplication { protected boolean notDefined = false; protected JPanel settings; protected final JTextField Path = new JTextField(30); - protected String searchPath = null; - protected String searchPathPreferenceKey = null; + protected String commandPath = null; + protected String commandPathPreferenceKey = null; protected String citeCommand = Globals.prefs.get(JabRefPreferences.CITE_COMMAND); + @Override public String getName() { return Localization.menuTitle("Insert selected citations into %d", getApplicationName()); @@ -53,29 +54,27 @@ public String getTooltip() { return Localization.lang("Push to %0", getApplicationName()); } - @Override public String getKeyStrokeName() { - return null; + return Localization.lang("Push to %0", getApplicationName()); } - + @Override public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { couldNotCall = false; notDefined = false; - + initParameters(); - searchPath = Globals.prefs.get(searchPathPreferenceKey); + commandPath = Globals.prefs.get(commandPathPreferenceKey); - if ((searchPath == null) || searchPath.trim().isEmpty()) { + if ((commandPath == null) || commandPath.trim().isEmpty()) { notDefined = true; return; } try { Runtime.getRuntime().exec(getCommandLine(keyString)); - } catch (IOException excep) { @@ -84,7 +83,6 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k } } - @Override public void operationCompleted(BasePanel panel) { if (notDefined) { @@ -93,7 +91,7 @@ public void operationCompleted(BasePanel panel) { + Localization.lang("Path to %0 not defined", getApplicationName()) + "."); } else if (couldNotCall) { panel.output(Localization.lang("Error") + ": " - + Localization.lang("Could not call executable") + " '" + searchPath + "'."); + + Localization.lang("Could not call executable") + " '" + commandPath + "'."); // @formatter:on } else { panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); @@ -104,39 +102,51 @@ public void operationCompleted(BasePanel panel) { public boolean requiresBibtexKeys() { return true; } - - protected String getCommandLine(String keyString) { + + protected String[] getCommandLine(String keyString) { + return null; + } + + protected String getCommandName() { return null; } @Override public JPanel getSettingsPanel() { initParameters(); - searchPath = Globals.prefs.get(searchPathPreferenceKey); + commandPath = Globals.prefs.get(commandPathPreferenceKey); if (settings == null) { initSettingsPanel(); } - Path.setText(searchPath); + Path.setText(commandPath); return settings; } protected void initParameters() { - searchPathPreferenceKey = null; + commandPathPreferenceKey = null; } - - private void initSettingsPanel() { + + protected void initSettingsPanel() { FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); + builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p")); + String label = Localization.lang("Path to %0", getApplicationName()); + // In case the application name and the actual command is not the same, add the command in brackets + if (getCommandName() != null) { + label += " (" + getCommandName() + "):"; + } else { + label += ":"; + } + builder.add(label).xy(1, 1); builder.add(Path).xy(3, 1); BrowseAction action = BrowseAction.buildForFile(Path); JButton browse = new JButton(Localization.lang("Browse")); browse.addActionListener(action); + builder.add(browse).xy(5, 1); settings = builder.build(); } @Override public void storeSettings() { - Globals.prefs.put(searchPathPreferenceKey, Path.getText()); + Globals.prefs.put(commandPathPreferenceKey, Path.getText()); } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplication.java b/src/main/java/net/sf/jabref/external/push/PushToApplication.java index 72767a8e1c1..428151b7b6a 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplication.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2011 JabRef contributors. +/* Copyright (C) 2003-2015 JabRef contributors. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -23,8 +23,7 @@ import javax.swing.*; /** - * Class that defines interaction with an external application in the form of - * "pushing" selected entries to it. + * Class that defines interaction with an external application in the form of "pushing" selected entries to it. */ public interface PushToApplication { @@ -39,28 +38,26 @@ public interface PushToApplication { String getKeyStrokeName(); /** - * This method asks the implementing class to return a JPanel populated - * with the imlementation's options panel, if necessary. If the JPanel - * is shown to the user, and the user indicates that settings should - * be stored, the implementation's storeSettings() method will be called. - * This method must make sure all widgets in the panel are in the correct - * selection states. + * This method asks the implementing class to return a JPanel populated with the imlementation's options panel, if + * necessary. If the JPanel is shown to the user, and the user indicates that settings should be stored, the + * implementation's storeSettings() method will be called. This method must make sure all widgets in the panel are + * in the correct selection states. * * @return a JPanel containing options, or null if options are not needed. */ JPanel getSettingsPanel(); /** - * This method is called to indicate that the settings panel returned from - * the getSettingsPanel() method has been shown to the user and that the - * user has indicated that the settings should be stored. This method must - * store the state of the widgets in the settings panel to Globals.prefs. + * This method is called to indicate that the settings panel returned from the getSettingsPanel() method has been + * shown to the user and that the user has indicated that the settings should be stored. This method must store the + * state of the widgets in the settings panel to Globals.prefs. */ void storeSettings(); /** - * The actual operation. This method will not be called on the event dispatch - * thread, so it should not do GUI operations without utilizing invokeLater(). + * The actual operation. This method will not be called on the event dispatch thread, so it should not do GUI + * operations without utilizing invokeLater(). + * * @param database * @param entries * @param metaData @@ -68,14 +65,14 @@ public interface PushToApplication { void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData); /** - * Reporting etc., this method is called on the event dispatch thread after - * pushEntries() returns. + * Reporting etc., this method is called on the event dispatch thread after pushEntries() returns. */ void operationCompleted(BasePanel panel); /** - * Check whether this operation requires BibTeX keys to be set for the entries. - * If true is returned an error message will be displayed if keys are missing. + * Check whether this operation requires BibTeX keys to be set for the entries. If true is returned an error message + * will be displayed if keys are missing. + * * @return true if BibTeX keys are required for this operation. */ boolean requiresBibtexKeys(); diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java index d3c42c7744e..f8762ae64dc 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2011 JabRef contributors. +/* Copyright (C) 2003-2015 JabRef contributors. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -33,6 +33,7 @@ */ class PushToApplicationAction extends AbstractAction implements Runnable { + private static final long serialVersionUID = 9008115216029319314L; private final PushToApplication operation; private final JabRefFrame frame; private BasePanel panel; @@ -62,8 +63,7 @@ public void actionPerformed(ActionEvent e) { // Check if any entries are selected: entries = panel.getSelectedEntries(); if (entries.length == 0) { - JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), - (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); return; } @@ -71,8 +71,7 @@ public void actionPerformed(ActionEvent e) { if (operation.requiresBibtexKeys()) { for (BibtexEntry entry : entries) { if (entry.getCiteKey() == null || entry.getCiteKey().trim().isEmpty()) { - JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires all selected entries to have BibTex keys defined."), - (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires all selected entries to have BibTex keys defined."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE); return; } } @@ -99,7 +98,7 @@ public void run() { private String getKeyString(BibtexEntry[] entries) { StringBuilder result = new StringBuilder(); - String citeKey;//, message = ""; + String citeKey; boolean first = true; for (BibtexEntry bes : entries) { citeKey = bes.getField(BibtexEntry.KEY_FIELD); diff --git a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java index e5d09e657b6..d8909756e91 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java +++ b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java @@ -33,55 +33,34 @@ import net.sf.jabref.model.entry.BibtexEntry; /** - * Created by IntelliJ IDEA. - * User: alver - * Date: Jan 14, 2006 - * Time: 4:55:23 PM + * Created by IntelliJ IDEA. User: alver Date: Jan 14, 2006 Time: 4:55:23 PM */ -public class PushToEmacs implements PushToApplication { +public class PushToEmacs extends AbstractPushToApplication implements PushToApplication { - private JPanel settings; - private final JTextField citeCommand = new JTextField(30); - private final JTextField emacsPath = new JTextField(30); private final JTextField additionalParams = new JTextField(30); private final JCheckBox useEmacs23 = new JCheckBox(); private boolean couldNotConnect; - private boolean couldNotRunClient; - - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0" ,getApplicationName()); - } - + @Override public String getApplicationName() { return "Emacs"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("emacs"); } - @Override - public String getKeyStrokeName() { - return "Push to Emacs"; - } - @Override public JPanel getSettingsPanel() { + initParameters(); + commandPath = Globals.prefs.get(commandPathPreferenceKey); + if (settings == null) { initSettingsPanel(); } - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS)); - emacsPath.setText(Globals.prefs.get(JabRefPreferences.EMACS_PATH)); + Path.setText(commandPath); additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); useEmacs23.setSelected(Globals.prefs.getBoolean(JabRefPreferences.EMACS_23)); return settings; @@ -89,27 +68,24 @@ public JPanel getSettingsPanel() { @Override public void storeSettings() { - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_EMACS, citeCommand.getText()); - Globals.prefs.put(JabRefPreferences.EMACS_PATH, emacsPath.getText()); + Globals.prefs.put(commandPathPreferenceKey, Path.getText()); Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText()); Globals.prefs.putBoolean(JabRefPreferences.EMACS_23, useEmacs23.isSelected()); } - private void initSettingsPanel() { + protected void initSettingsPanel() { FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p, 2dlu, p")); + builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p")); builder.add(Localization.lang("Path to gnuclient or emacsclient") + ":").xy(1, 1); - builder.add(emacsPath).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(emacsPath); + builder.add(Path).xy(3, 1); + BrowseAction action = BrowseAction.buildForFile(Path); JButton browse = new JButton(Localization.lang("Browse")); browse.addActionListener(action); - builder.add(browse).xy(5,1); + builder.add(browse).xy(5, 1); builder.add(Localization.lang("Additional parameters") + ":").xy(1, 3); - builder.add(additionalParams).xy(3,3); + builder.add(additionalParams).xy(3, 3); builder.add(Localization.lang("Use EMACS 23 insertion string") + ":").xy(1, 5); - builder.add(useEmacs23).xy(3,5); - builder.add(Localization.lang("Cite command") + ":").xy(1, 7); - builder.add(citeCommand).xy(3,7); + builder.add(useEmacs23).xy(3, 5); settings = builder.build(); } @@ -117,12 +93,15 @@ private void initSettingsPanel() { public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, MetaData metaData) { couldNotConnect = false; - couldNotRunClient = false; - String command = Globals.prefs.get(JabRefPreferences.EMACS_PATH); + couldNotCall = false; + + initParameters(); + + commandPath = Globals.prefs.get(commandPathPreferenceKey); String[] addParams = Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS).split(" "); try { String[] com = new String[addParams.length + 2]; - com[0] = command; + com[0] = commandPath; System.arraycopy(addParams, 0, com, 1, addParams.length); String prefix; String suffix; @@ -135,19 +114,16 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k } com[com.length - 1] = OS.WINDOWS ? - // Windows gnuclient escaping: - // java string: "(insert \\\"\\\\cite{Blah2001}\\\")"; - // so cmd receives: (insert \"\\cite{Blah2001}\") - // so emacs receives: (insert "\cite{Blah2001}") - prefix.concat("\\\"\\" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS).replaceAll("\\\\", "\\\\\\\\") + - "{" + keys + "}\\\"").concat(suffix) - : - // Linux gnuclient escaping: - // java string: "(insert \"\\\\cite{Blah2001}\")" - // so sh receives: (insert "\\cite{Blah2001}") - // so emacs receives: (insert "\cite{Blah2001}") - prefix.concat("\"" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS).replaceAll("\\\\", "\\\\\\\\") + - "{" + keys + "}\"").concat(suffix); + // Windows gnuclient escaping: + // java string: "(insert \\\"\\\\cite{Blah2001}\\\")"; + // so cmd receives: (insert \"\\cite{Blah2001}\") + // so emacs receives: (insert "\cite{Blah2001}") + prefix.concat("\\\"\\" + citeCommand.replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\\\"").concat(suffix) : + // Linux gnuclient escaping: + // java string: "(insert \"\\\\cite{Blah2001}\")" + // so sh receives: (insert "\\cite{Blah2001}") + // so emacs receives: (insert "\cite{Blah2001}") + prefix.concat("\"" + citeCommand.replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\"").concat(suffix); final Process p = Runtime.getRuntime().exec(com); @@ -179,7 +155,7 @@ public void run() { }; JabRefExecutorService.INSTANCE.executeAndWait(errorListener); } catch (IOException excep) { - couldNotRunClient = true; + couldNotCall = true; } } @@ -187,27 +163,26 @@ public void run() { @Override public void operationCompleted(BasePanel panel) { if (couldNotConnect) { - JOptionPane.showMessageDialog( - panel.frame(), - "" + - Localization.lang("Could not connect to a running gnuserv process. Make sure that " - + "Emacs or XEmacs is running,
and that the server has been started " - + "(by running the command 'server-start'/'gnuserv-start').") - + "", + // @formatter:off + JOptionPane.showMessageDialog(panel.frame(), "" + + Localization.lang("Could not connect to a running gnuserv process. Make sure that " + + "Emacs or XEmacs is running,
and that the server has been started " + + "(by running the command 'server-start'/'gnuserv-start').") + "", Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - } else if (couldNotRunClient) { - JOptionPane.showMessageDialog( - panel.frame(), + } else if (couldNotCall) { + JOptionPane.showMessageDialog(panel.frame(), Localization.lang("Could not run the gnuclient/emacsclient program. Make sure you have " - + "the emacsclient/gnuclient program installed and available in the PATH."), + + "the emacsclient/gnuclient program installed and available in the PATH."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); + // @formatter:on } else { panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); } } - + @Override - public boolean requiresBibtexKeys() { - return true; + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.EMACS_PATH; } + } diff --git a/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java index ac23068a096..8597d9996ae 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java @@ -15,132 +15,39 @@ */ package net.sf.jabref.external.push; -import java.io.IOException; - import javax.swing.*; -import net.sf.jabref.*; - -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import net.sf.jabref.gui.BasePanel; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.database.BibtexDatabase; -import net.sf.jabref.model.entry.BibtexEntry; /** * Class for pushing entries into LatexEditor. */ -public class PushToLatexEditor implements PushToApplication { - - private boolean couldNotCall; - private boolean notDefined; - private JPanel settings; - private final JTextField ledPath = new JTextField(30); - private final JTextField citeCommand = new JTextField(30); - - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0" ,getApplicationName()); - } +public class PushToLatexEditor extends AbstractPushToApplication implements PushToApplication { @Override public String getApplicationName() { return "LatexEditor"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("edit"); } @Override - public String getKeyStrokeName() { - return null; - } - - @Override - public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { - - couldNotCall = false; - notDefined = false; - - String led = Globals.prefs.get(JabRefPreferences.LATEX_EDITOR_PATH); - - if (led == null || led.trim().isEmpty()) { - notDefined = true; - return; - } - - try { - Runtime.getRuntime().exec(led + " " + "-i " + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_LED) + "{" + keyString + "}"); - - } - - catch (IOException excep) { - couldNotCall = true; - excep.printStackTrace(); - } + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "-i", citeCommand + "{" + keyString + "}"}; } @Override - public void operationCompleted(BasePanel panel) { - if (notDefined) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " + - Localization.lang("Path to %0 not defined", getApplicationName()) + "."); - // @formatter:on - } else if (couldNotCall) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " + - Localization.lang("Could not call executable") + " '" - + Globals.prefs.get(JabRefPreferences.LATEX_EDITOR_PATH) + "'."); - // @formatter:on - } else { - Localization.lang("Pushed citations to %0", "LatexEditor"); - } + protected String getCommandName() { + return "LEd.exe"; } @Override - public boolean requiresBibtexKeys() { - return true; + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.LATEX_EDITOR_PATH; } - @Override - public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - ledPath.setText(Globals.prefs.get(JabRefPreferences.LATEX_EDITOR_PATH)); - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_LED)); - return settings; - } - - private void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - builder.add(Localization.lang("Path to LatexEditor (LEd.exe)") + ":").xy(1, 1); // Note the LEd.exe part - builder.add(ledPath).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(ledPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5,1); - builder.add(Localization.lang("Cite command") + ":").xy(1, 3); - builder.add(citeCommand).xy(3,3); - settings = builder.build(); - } - - @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.LATEX_EDITOR_PATH, ledPath.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_LED, citeCommand.getText()); - } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToLyx.java b/src/main/java/net/sf/jabref/external/push/PushToLyx.java index 5df2ccb9038..3153865ddb9 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToLyx.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLyx.java @@ -29,20 +29,15 @@ import net.sf.jabref.model.database.BibtexDatabase; import net.sf.jabref.model.entry.BibtexEntry; -public class PushToLyx implements PushToApplication { - - private final JTextField lyxPipe = new JTextField(30); - private JPanel settings; +public class PushToLyx extends AbstractPushToApplication implements PushToApplication { private boolean couldNotFindPipe; - private boolean couldNotWrite; - @Override public void pushEntries(BibtexDatabase database, final BibtexEntry[] entries, final String keyString, MetaData metaData) { couldNotFindPipe = false; - couldNotWrite = false; + couldNotCall = false; String lyxpipeSetting = Globals.prefs.get(JabRefPreferences.LYXPIPE); if (!lyxpipeSetting.endsWith(".in")) { @@ -75,37 +70,22 @@ public void run() { lyx_out.close(); } catch (IOException excep) { - couldNotWrite = true; + couldNotCall = true; } } }); } - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0" ,getApplicationName()); - } - @Override public String getApplicationName() { return "LyX/Kile"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0",getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("lyx"); } - @Override - public String getKeyStrokeName() { - return "Push to LyX"; - } - @Override public void operationCompleted(BasePanel panel) { if (couldNotFindPipe) { @@ -113,7 +93,7 @@ public void operationCompleted(BasePanel panel) { panel.output(Localization.lang("Error") + ": " + Localization.lang("verify that LyX is running and that the lyxpipe is valid") + ". [" + Globals.prefs.get(JabRefPreferences.LYXPIPE) + "]"); - } else if (couldNotWrite) { + } else if (couldNotCall) { panel.output(Localization.lang("Error") + ": " + Localization.lang("unable to write to") + " " + Globals.prefs.get(JabRefPreferences.LYXPIPE) + ".in"); @@ -125,28 +105,14 @@ public void operationCompleted(BasePanel panel) { } @Override - public boolean requiresBibtexKeys() { - return true; - } - - @Override - public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - lyxPipe.setText(Globals.prefs.get(JabRefPreferences.LYXPIPE)); - return settings; - } - - @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.LYXPIPE, lyxPipe.getText()); + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.LYXPIPE; } - private void initSettingsPanel() { + protected void initSettingsPanel() { settings = new JPanel(); settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); - settings.add(lyxPipe); + settings.add(Path); } /*class Timeout extends javax.swing.Timer { diff --git a/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java index 339ca957b1f..99dee113984 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java +++ b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java @@ -15,189 +15,34 @@ */ package net.sf.jabref.external.push; -import java.io.IOException; -import java.io.InputStream; - import javax.swing.*; -import net.sf.jabref.*; - -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.util.OS; -import net.sf.jabref.model.database.BibtexDatabase; -import net.sf.jabref.model.entry.BibtexEntry; +import net.sf.jabref.JabRefPreferences; /** * Created by IntelliJ IDEA. User: alver Date: Jan 14, 2006 Time: 4:55:23 PM To change this template use File | Settings * | File Templates. */ -public class PushToTeXstudio implements PushToApplication { - - private JPanel settings; - private final JTextField citeCommand = new JTextField(30); - private final JTextField progPath = new JTextField(30); - - private boolean couldNotConnect; - private boolean couldNotRunClient; - - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0", getApplicationName()); - } +public class PushToTeXstudio extends AbstractPushToApplication implements PushToApplication { @Override public String getApplicationName() { return "TeXstudio"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("texstudio"); } @Override - public String getKeyStrokeName() { - return "Push to TeXstudio"; - } - - private String defaultProgramPath() { - if (OS.WINDOWS) { - String progFiles = System.getenv("ProgramFiles(x86)"); - if (progFiles == null) { - progFiles = System.getenv("ProgramFiles"); - } - return progFiles + "\\texstudio\\texstudio.exe"; - } else { - return "texstudio"; - } - } - - @Override - public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - String citeCom = Globals.prefs.get(JabRefPreferences.CITE_COMMAND_TEXSTUDIO); - citeCommand.setText(citeCom); - - String programPath = Globals.prefs.get(JabRefPreferences.TEXSTUDIO_PATH); - if (programPath == null) { - programPath = defaultProgramPath(); - } - progPath.setText(programPath); - return settings; - } - - @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_TEXSTUDIO, citeCommand.getText().trim()); - Globals.prefs.put(JabRefPreferences.TEXSTUDIO_PATH, progPath.getText().trim()); - } - - private void initSettingsPanel() { - - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - - builder.addLabel(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); - builder.add(progPath).xy(3, 1); - BrowseAction action = BrowseAction.buildForFile(progPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5, 1); - builder.addLabel(Localization.lang("Cite command") + ":").xy(1, 3); - builder.add(citeCommand).xy(3, 3); - settings = builder.build(); - } - - @Override - public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, MetaData metaData) { - - couldNotConnect = false; - couldNotRunClient = false; - String citeCom = Globals.prefs.get(JabRefPreferences.CITE_COMMAND_TEXSTUDIO); - String programPath = Globals.prefs.get(JabRefPreferences.TEXSTUDIO_PATH); - if (programPath == null) { - programPath = defaultProgramPath(); - } - try { - String[] com = OS.WINDOWS ? - // No additional escaping is needed for TeXstudio: - new String[] {programPath, "--insert-cite", citeCom + "{" + keys + "}"} : new String[] {programPath, "--insert-cite", citeCom + "{" + keys + "}"}; - - /*for (int i = 0; i < com.length; i++) { - String s = com[i]; - System.out.print(s + " "); - } - System.out.println("");*/ - - final Process p = Runtime.getRuntime().exec(com); - System.out.println(keys); - Runnable errorListener = new Runnable() { - - @Override - public void run() { - InputStream out = p.getErrorStream(); - int c; - StringBuilder sb = new StringBuilder(); - try { - while ((c = out.read()) != -1) { - sb.append((char) c); - } - } catch (IOException e) { - e.printStackTrace(); - } - // Error stream has been closed. See if there were any errors: - if (!sb.toString().trim().isEmpty()) { - //System.out.println(sb.toString()); - couldNotConnect = true; - } - } - }; - JabRefExecutorService.INSTANCE.executeAndWait(errorListener); - } catch (IOException excep) { - couldNotRunClient = true; - } - - } - - @Override - public void operationCompleted(BasePanel panel) { - if (couldNotConnect) { - // @formatter:off - JOptionPane.showMessageDialog(panel.frame(), - "TeXstudio: could not connect", - Localization.lang("Error"), - JOptionPane.ERROR_MESSAGE); - // @formatter:on - } else if (couldNotRunClient) { - String programPath = Globals.prefs.get(JabRefPreferences.TEXSTUDIO_PATH); - if (programPath == null) { - programPath = defaultProgramPath(); - } - JOptionPane.showMessageDialog(panel.frame(), - // @formatter:off - "TeXstudio: " + Localization.lang("Program '%0' not found", programPath), - Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - // @formatter:on - } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); - } + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "--insert-cite", keyString}; } @Override - public boolean requiresBibtexKeys() { - return true; + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.TEXSTUDIO_PATH; } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java index 37521d394dd..9849acbcd51 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java +++ b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java @@ -18,15 +18,13 @@ import javax.swing.*; -import net.sf.jabref.*; - +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.external.push.AbstractPushToApplication; /** * Class for pushing entries into TexMaker. */ -public class PushToTexmaker extends AbstractPushToApplication { +public class PushToTexmaker extends AbstractPushToApplication implements PushToApplication { @Override public String getApplicationName() { @@ -39,12 +37,13 @@ public Icon getIcon() { } @Override - protected String getCommandLine(String keyString) { - return searchPath + " " + "-insert " + citeCommand + "{" + keyString + "}"; + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "-insert", citeCommand + "{" + keyString + "}"}; } + @Override protected void initParameters() { - searchPathPreferenceKey = JabRefPreferences.TEXMAKER_PATH; + commandPathPreferenceKey = JabRefPreferences.TEXMAKER_PATH; } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToVim.java b/src/main/java/net/sf/jabref/external/push/PushToVim.java index a043b9b0db3..006ced3e4fd 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToVim.java +++ b/src/main/java/net/sf/jabref/external/push/PushToVim.java @@ -36,73 +36,49 @@ * Time: 6:55:56 PM * To change this template use File | Settings | File Templates. */ -public class PushToVim implements PushToApplication { +public class PushToVim extends AbstractPushToApplication implements PushToApplication { - private JPanel settings; - private final JTextField vimPath = new JTextField(30); private final JTextField vimServer = new JTextField(30); - private final JTextField citeCommand = new JTextField(30); - + private boolean couldNotConnect; - private boolean couldNotRunClient; - - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0" ,getApplicationName()); - } - + @Override public String getApplicationName() { return "Vim"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("vim"); } - @Override - public String getKeyStrokeName() { - return null; - } - @Override public JPanel getSettingsPanel() { if (settings == null) { initSettingsPanel(); } - vimPath.setText(Globals.prefs.get(JabRefPreferences.VIM)); + Path.setText(Globals.prefs.get(JabRefPreferences.VIM)); vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM)); return settings; } @Override public void storeSettings() { - Globals.prefs.put(JabRefPreferences.VIM, vimPath.getText()); + Globals.prefs.put(JabRefPreferences.VIM, Path.getText()); Globals.prefs.put(JabRefPreferences.VIM_SERVER, vimServer.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_VIM, citeCommand.getText()); } - private void initSettingsPanel() { + protected void initSettingsPanel() { FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p")); + builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); - builder.add(vimPath).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(vimPath); + builder.add(Path).xy(3,1); + BrowseAction action = BrowseAction.buildForFile(Path); JButton browse = new JButton(Localization.lang("Browse")); browse.addActionListener(action); builder.add(browse).xy(5,1); builder.add(Localization.lang("Vim Server Name") + ":").xy(1, 3); builder.add(vimServer).xy(3,3); - builder.add(Localization.lang("Cite command") + ":").xy(1, 5); - builder.add(citeCommand).xy(3,5); settings = builder.build(); } @@ -111,12 +87,12 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k MetaData metaData) { couldNotConnect = false; - couldNotRunClient = false; + couldNotCall = false; try { // @formatter:off String[] com = new String[] {Globals.prefs.get(JabRefPreferences.VIM), "--servername", Globals.prefs.get(JabRefPreferences.VIM_SERVER), "--remote-send", - "a" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM) + + "a" + citeCommand + "{" + keys + "}"}; // @formatter:on @@ -146,7 +122,7 @@ public void run() { }; JabRefExecutorService.INSTANCE.executeAndWait(errorListener); } catch (IOException excep) { - couldNotRunClient = true; + couldNotCall = true; } } @@ -161,7 +137,7 @@ public void operationCompleted(BasePanel panel) { + "Vim is running
with correct server name.") + "", Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - } else if (couldNotRunClient) { + } else if (couldNotCall) { JOptionPane.showMessageDialog( panel.frame(), Localization.lang("Could not run the 'vim' program."), @@ -170,9 +146,4 @@ public void operationCompleted(BasePanel panel) { panel.output(Localization.lang("Pushed citations to %0",getApplicationName())); } } - - @Override - public boolean requiresBibtexKeys() { - return true; - } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java index 48e85cdfb4e..fae4ec65e9f 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java +++ b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java @@ -15,127 +15,30 @@ */ package net.sf.jabref.external.push; -import java.io.IOException; - import javax.swing.*; -import net.sf.jabref.*; - -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; -import net.sf.jabref.gui.BasePanel; +import net.sf.jabref.JabRefPreferences; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; -import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.model.database.BibtexDatabase; -import net.sf.jabref.model.entry.BibtexEntry; - -public class PushToWinEdt implements PushToApplication { - - private boolean couldNotCall; - private boolean notDefined; - private JPanel settings; - private final JTextField winEdtPath = new JTextField(30); - private final JTextField citeCommand = new JTextField(30); - - @Override - public String getName() { - return Localization.lang("Insert selected citations into %0", getApplicationName()); - } +public class PushToWinEdt extends AbstractPushToApplication implements PushToApplication { @Override public String getApplicationName() { return "WinEdt"; } - @Override - public String getTooltip() { - return Localization.lang("Push to %0", getApplicationName()); - } - @Override public Icon getIcon() { return IconTheme.getImage("winedt"); } @Override - public String getKeyStrokeName() { - return "Push to WinEdt"; - } - - @Override - public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { - - couldNotCall = false; - notDefined = false; - - String winEdt = Globals.prefs.get(JabRefPreferences.WIN_EDT_PATH); - if (winEdt == null || winEdt.trim().isEmpty()) { - notDefined = true; - return; - } - - try { - Runtime.getRuntime().exec(new String[] {winEdt, "\"[InsText('" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_WIN_EDT) + "{" + keyString.replaceAll("'", "''") + "}');]\""}); - } - - catch (IOException excep) { - couldNotCall = true; - excep.printStackTrace(); - } - - } - - @Override - public void operationCompleted(BasePanel panel) { - if (notDefined) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " - + Localization.lang("Path to %0 not defined", getApplicationName()) + "."); - // @formatter:on - } else if (couldNotCall) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " - + Localization.lang("Could not call executable") + " '" + Globals.prefs.get(JabRefPreferences.WIN_EDT_PATH) + "'."); - // @formatter:on - } else { - Localization.lang("Pushed citations to %0", getApplicationName()); - } - } - - @Override - public boolean requiresBibtexKeys() { - return true; - } - - @Override - public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - winEdtPath.setText(Globals.prefs.get(JabRefPreferences.WIN_EDT_PATH)); - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_WIN_EDT)); - return settings; - } - - private void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); - builder.add(winEdtPath).xy(3, 1); - BrowseAction action = BrowseAction.buildForFile(winEdtPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5, 1); - builder.add(Localization.lang("Cite command") + ":").xy(1, 3); - builder.add(citeCommand).xy(3, 3); - settings = builder.build(); + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "\"[InsText('" + citeCommand + "{" + keyString.replaceAll("'", "''") + "}');]\""}; } @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.WIN_EDT_PATH, winEdtPath.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_WIN_EDT, citeCommand.getText()); + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.WIN_EDT_PATH; } } From 6676f3d76c66ab2f1de791d89b50b6550b04380c Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Wed, 7 Oct 2015 22:14:09 +0200 Subject: [PATCH 05/10] Added cite command configuration --- .../sf/jabref/gui/preftabs/ExternalTab.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java b/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java index 0a1207e1f01..eb66f522554 100644 --- a/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java +++ b/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java @@ -26,16 +26,8 @@ import javax.swing.event.ChangeListener; import net.sf.jabref.*; -import net.sf.jabref.external.*; -import net.sf.jabref.external.push.PushToApplication; -import net.sf.jabref.external.push.PushToApplicationButton; -import net.sf.jabref.external.push.PushToEmacs; -import net.sf.jabref.external.push.PushToLatexEditor; -import net.sf.jabref.external.push.PushToLyx; -import net.sf.jabref.external.push.PushToTeXstudio; -import net.sf.jabref.external.push.PushToTexmaker; -import net.sf.jabref.external.push.PushToVim; -import net.sf.jabref.external.push.PushToWinEdt; +import net.sf.jabref.external.ExternalFileTypeEditor; +import net.sf.jabref.external.push.*; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.gui.JabRefFrame; @@ -58,6 +50,7 @@ class ExternalTab extends JPanel implements PrefsTab { private final JTextField fileDir; private final JTextField psDir; private final JTextField emailSubject; + private final JTextField citeCommand; private final JCheckBox bibLocationAsFileDir; private final JCheckBox bibLocAsPrimaryDir; @@ -93,10 +86,12 @@ public void stateChanged(ChangeEvent changeEvent) { JButton editFileTypes = new JButton(Localization.lang("Manage external file types")); runAutoFileSearch = new JCheckBox(Localization.lang("When opening file link, search for matching file if no link is defined")); allowFileAutoOpenBrowse = new JCheckBox(Localization.lang("Automatically open browse dialog when creating new file link")); + citeCommand = new JTextField(25); regExpTextField = new JTextField(25); useRegExpComboBox = new JRadioButton(Localization.lang("Use Regular Expression Search")); ItemListener regExpListener = new ItemListener() { + @Override public void itemStateChanged(ItemEvent e) { regExpTextField.setEditable(useRegExpComboBox.isSelected()); @@ -213,6 +208,12 @@ public void itemStateChanged(ItemEvent e) { builder.append(new JPanel()); builder.append(butpan, 3); + builder.nextLine(); + lab = new JLabel(Localization.lang("Cite command") + ':'); + builder.append(pan); + builder.append(lab); + builder.append(citeCommand); + builder.nextLine(); builder.append(pan); builder.append(editFileTypes); @@ -251,6 +252,8 @@ public void setValues() { emailSubject.setText(prefs.get(JabRefPreferences.EMAIL_SUBJECT)); openFoldersOfAttachedFiles.setSelected(prefs.getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES)); + citeCommand.setText(prefs.get(JabRefPreferences.CITE_COMMAND)); + if (prefs.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) { useRegExpComboBox.setSelected(true); } else if (prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY)) { @@ -279,6 +282,7 @@ public void storeSettings() { prefs.putBoolean(JabRefPreferences.ALLOW_FILE_AUTO_OPEN_BROWSE, allowFileAutoOpenBrowse.isSelected()); prefs.put(JabRefPreferences.EMAIL_SUBJECT, emailSubject.getText()); prefs.putBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES, openFoldersOfAttachedFiles.isSelected()); + prefs.put(JabRefPreferences.CITE_COMMAND, citeCommand.getText()); } @Override From 4f8cbca27d0848de26dd79989319316893435ac9 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 8 Oct 2015 00:18:41 +0200 Subject: [PATCH 06/10] Extracted more functionality from Emacs, LyX, and Vim pushers --- .../push/AbstractPushToApplication.java | 41 ++++++++---- .../sf/jabref/external/push/PushToEmacs.java | 49 +++++++-------- .../sf/jabref/external/push/PushToLyx.java | 59 +++++++++-------- .../sf/jabref/external/push/PushToVim.java | 63 +++++++++---------- 4 files changed, 115 insertions(+), 97 deletions(-) diff --git a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java index c04e2c3d809..bbe2a5e98d8 100644 --- a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -35,13 +35,15 @@ */ public abstract class AbstractPushToApplication implements PushToApplication { - protected boolean couldNotCall = false; - protected boolean notDefined = false; + protected boolean couldNotCall; + protected boolean couldNotConnect; + protected boolean notDefined; protected JPanel settings; protected final JTextField Path = new JTextField(30); - protected String commandPath = null; - protected String commandPathPreferenceKey = null; + protected String commandPath; + protected String commandPathPreferenceKey; protected String citeCommand = Globals.prefs.get(JabRefPreferences.CITE_COMMAND); + protected FormBuilder builder; @Override @@ -62,6 +64,7 @@ public String getKeyStrokeName() { @Override public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { + couldNotConnect = false; couldNotCall = false; notDefined = false; @@ -89,12 +92,13 @@ public void operationCompleted(BasePanel panel) { // @formatter:off panel.output(Localization.lang("Error") + ": " + Localization.lang("Path to %0 not defined", getApplicationName()) + "."); - } else if (couldNotCall) { - panel.output(Localization.lang("Error") + ": " - + Localization.lang("Could not call executable") + " '" + commandPath + "'."); // @formatter:on + } else if (couldNotCall) { + panel.output(getCouldNotCall()); + } else if (couldNotConnect) { + panel.output(getCouldNotConnect()); } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); + panel.output(Localization.lang("Pushed citations to %0", getApplicationName()) + "."); } } @@ -122,12 +126,10 @@ public JPanel getSettingsPanel() { return settings; } - protected void initParameters() { - commandPathPreferenceKey = null; - } + abstract protected void initParameters(); protected void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); + builder = FormBuilder.create(); builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p")); String label = Localization.lang("Path to %0", getApplicationName()); // In case the application name and the actual command is not the same, add the command in brackets @@ -149,4 +151,19 @@ protected void initSettingsPanel() { public void storeSettings() { Globals.prefs.put(commandPathPreferenceKey, Path.getText()); } + + protected String getCouldNotCall() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("Could not call executable") + " '" + commandPath + "'."; + // @formatter:on + } + + protected String getCouldNotConnect() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("Could not connect to ") + getApplicationName() + "."; + // @formatter:on + } + } diff --git a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java index d8909756e91..38f5f54d2ec 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java +++ b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java @@ -22,11 +22,8 @@ import net.sf.jabref.*; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.logic.util.OS; import net.sf.jabref.model.database.BibtexDatabase; @@ -40,8 +37,7 @@ public class PushToEmacs extends AbstractPushToApplication implements PushToAppl private final JTextField additionalParams = new JTextField(30); private final JCheckBox useEmacs23 = new JCheckBox(); - private boolean couldNotConnect; - + @Override public String getApplicationName() { return "Emacs"; @@ -54,34 +50,22 @@ public Icon getIcon() { @Override public JPanel getSettingsPanel() { - initParameters(); - commandPath = Globals.prefs.get(commandPathPreferenceKey); - - if (settings == null) { - initSettingsPanel(); - } - Path.setText(commandPath); additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS)); useEmacs23.setSelected(Globals.prefs.getBoolean(JabRefPreferences.EMACS_23)); - return settings; + return super.getSettingsPanel(); } @Override public void storeSettings() { - Globals.prefs.put(commandPathPreferenceKey, Path.getText()); + super.storeSettings(); Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText()); Globals.prefs.putBoolean(JabRefPreferences.EMACS_23, useEmacs23.isSelected()); } + @Override protected void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p")); - builder.add(Localization.lang("Path to gnuclient or emacsclient") + ":").xy(1, 1); - builder.add(Path).xy(3, 1); - BrowseAction action = BrowseAction.buildForFile(Path); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5, 1); + super.initSettingsPanel(); + builder.appendRows("2dlu, p, 2dlu, p"); builder.add(Localization.lang("Additional parameters") + ":").xy(1, 3); builder.add(additionalParams).xy(3, 3); builder.add(Localization.lang("Use EMACS 23 insertion string") + ":").xy(1, 5); @@ -94,9 +78,16 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k couldNotConnect = false; couldNotCall = false; - + notDefined = false; + initParameters(); - + commandPath = Globals.prefs.get(commandPathPreferenceKey); + + if ((commandPath == null) || commandPath.trim().isEmpty()) { + notDefined = true; + return; + } + commandPath = Globals.prefs.get(commandPathPreferenceKey); String[] addParams = Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS).split(" "); try { @@ -175,14 +166,18 @@ public void operationCompleted(BasePanel panel) { + "the emacsclient/gnuclient program installed and available in the PATH."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); // @formatter:on - } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); } + super.operationCompleted(panel); } - + @Override protected void initParameters() { commandPathPreferenceKey = JabRefPreferences.EMACS_PATH; } + @Override + protected String getCommandName() { + return "gnuclient " + Localization.lang("or") + " emacsclient"; + } + } diff --git a/src/main/java/net/sf/jabref/external/push/PushToLyx.java b/src/main/java/net/sf/jabref/external/push/PushToLyx.java index 3153865ddb9..66189420b09 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToLyx.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLyx.java @@ -23,7 +23,6 @@ import javax.swing.*; import net.sf.jabref.*; -import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibtexDatabase; @@ -31,24 +30,30 @@ public class PushToLyx extends AbstractPushToApplication implements PushToApplication { - private boolean couldNotFindPipe; - @Override public void pushEntries(BibtexDatabase database, final BibtexEntry[] entries, final String keyString, MetaData metaData) { - couldNotFindPipe = false; + couldNotConnect = false; couldNotCall = false; + notDefined = false; + + initParameters(); + commandPath = Globals.prefs.get(commandPathPreferenceKey); + + if ((commandPath == null) || commandPath.trim().isEmpty()) { + notDefined = true; + return; + } - String lyxpipeSetting = Globals.prefs.get(JabRefPreferences.LYXPIPE); - if (!lyxpipeSetting.endsWith(".in")) { - lyxpipeSetting = lyxpipeSetting + ".in"; + if (!commandPath.endsWith(".in")) { + commandPath = commandPath + ".in"; } - File lp = new File(lyxpipeSetting); // this needs to fixed because it gives "asdf" when going prefs.get("lyxpipe") + File lp = new File(commandPath); // this needs to fixed because it gives "asdf" when going prefs.get("lyxpipe") if (!lp.exists() || !lp.canWrite()) { // See if it helps to append ".in": - lp = new File(lyxpipeSetting + ".in"); + lp = new File(commandPath + ".in"); if (!lp.exists() || !lp.canWrite()) { - couldNotFindPipe = true; + couldNotConnect = true; return; } } @@ -87,28 +92,30 @@ public Icon getIcon() { } @Override - public void operationCompleted(BasePanel panel) { - if (couldNotFindPipe) { - // @formatter:off - panel.output(Localization.lang("Error") + ": " + - Localization.lang("verify that LyX is running and that the lyxpipe is valid") - + ". [" + Globals.prefs.get(JabRefPreferences.LYXPIPE) + "]"); - } else if (couldNotCall) { - panel.output(Localization.lang("Error") + ": " + - Localization.lang("unable to write to") + " " + Globals.prefs.get(JabRefPreferences.LYXPIPE) + - ".in"); - // @formatter:on - } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); - } + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.LYXPIPE; + } + @Override + protected String getCouldNotCall() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("unable to write to") + " " + commandPath + + ".in"; + // @formatter:on } @Override - protected void initParameters() { - commandPathPreferenceKey = JabRefPreferences.LYXPIPE; + protected String getCouldNotConnect() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("verify that LyX is running and that the lyxpipe is valid") + + ". [" + commandPath + "]"; + // @formatter:on + } + @Override protected void initSettingsPanel() { settings = new JPanel(); settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); diff --git a/src/main/java/net/sf/jabref/external/push/PushToVim.java b/src/main/java/net/sf/jabref/external/push/PushToVim.java index 006ced3e4fd..aded03b66d9 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToVim.java +++ b/src/main/java/net/sf/jabref/external/push/PushToVim.java @@ -15,12 +15,9 @@ */ package net.sf.jabref.external.push; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.*; import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.actions.BrowseAction; import net.sf.jabref.logic.l10n.Localization; import net.sf.jabref.model.database.BibtexDatabase; import net.sf.jabref.model.entry.BibtexEntry; @@ -30,18 +27,14 @@ import java.io.InputStream; /** - * Created by IntelliJ IDEA. - * User: alver - * Date: Mar 7, 2007 - * Time: 6:55:56 PM - * To change this template use File | Settings | File Templates. + * Created by IntelliJ IDEA. User: alver Date: Mar 7, 2007 Time: 6:55:56 PM To change this template use File | Settings + * | File Templates. */ public class PushToVim extends AbstractPushToApplication implements PushToApplication { private final JTextField vimServer = new JTextField(30); - - private boolean couldNotConnect; - + + @Override public String getApplicationName() { return "Vim"; @@ -54,49 +47,48 @@ public Icon getIcon() { @Override public JPanel getSettingsPanel() { - if (settings == null) { - initSettingsPanel(); - } - Path.setText(Globals.prefs.get(JabRefPreferences.VIM)); vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); - return settings; + return super.getSettingsPanel(); } @Override public void storeSettings() { - Globals.prefs.put(JabRefPreferences.VIM, Path.getText()); + super.storeSettings(); Globals.prefs.put(JabRefPreferences.VIM_SERVER, vimServer.getText()); } + @Override protected void initSettingsPanel() { - FormBuilder builder = FormBuilder.create(); - builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p")); - builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1); - builder.add(Path).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(Path); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5,1); + super.initSettingsPanel(); + builder.appendRows("2dlu, p"); builder.add(Localization.lang("Vim Server Name") + ":").xy(1, 3); - builder.add(vimServer).xy(3,3); + builder.add(vimServer).xy(3, 3); settings = builder.build(); } @Override - public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, - MetaData metaData) { + public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, MetaData metaData) { couldNotConnect = false; couldNotCall = false; + notDefined = false; + + initParameters(); + commandPath = Globals.prefs.get(commandPathPreferenceKey); + + if ((commandPath == null) || commandPath.trim().isEmpty()) { + notDefined = true; + return; + } + try { // @formatter:off - String[] com = new String[] {Globals.prefs.get(JabRefPreferences.VIM), "--servername", + String[] com = new String[] {commandPath, "--servername", Globals.prefs.get(JabRefPreferences.VIM_SERVER), "--remote-send", "a" + citeCommand + "{" + keys + "}"}; // @formatter:on - final Process p = Runtime.getRuntime().exec(com); Runnable errorListener = new Runnable() { @@ -130,6 +122,7 @@ public void run() { @Override public void operationCompleted(BasePanel panel) { if (couldNotConnect) { + // @formatter:off JOptionPane.showMessageDialog( panel.frame(), "" + @@ -142,8 +135,14 @@ public void operationCompleted(BasePanel panel) { panel.frame(), Localization.lang("Could not run the 'vim' program."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - } else { - panel.output(Localization.lang("Pushed citations to %0",getApplicationName())); + // formatter:on } + super.operationCompleted(panel); } + + @Override + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.VIM; + } + } From f5ed0a307f94a87b937d064f9794213ef488d7f1 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 8 Oct 2015 18:08:40 +0200 Subject: [PATCH 07/10] Some more clean ups --- .../push/AbstractPushToApplication.java | 33 +++++++- .../sf/jabref/external/push/PushToLyx.java | 81 ++++++++++--------- 2 files changed, 71 insertions(+), 43 deletions(-) diff --git a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java index bbe2a5e98d8..9d605fcd98b 100644 --- a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -35,9 +35,9 @@ */ public abstract class AbstractPushToApplication implements PushToApplication { - protected boolean couldNotCall; - protected boolean couldNotConnect; - protected boolean notDefined; + protected boolean couldNotCall; // Set to true in case the command could not be executed, e.g., if the file is not found + protected boolean couldNotConnect; // Set to true in case the tunnel to the program (if one is used) does not operate + protected boolean notDefined; // Set to true if the corresponding path is not defined in the preferences protected JPanel settings; protected final JTextField Path = new JTextField(30); protected String commandPath; @@ -71,15 +71,18 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k initParameters(); commandPath = Globals.prefs.get(commandPathPreferenceKey); + // Check if a path to the command has been specified if ((commandPath == null) || commandPath.trim().isEmpty()) { notDefined = true; return; } + // Execute command try { Runtime.getRuntime().exec(getCommandLine(keyString)); } + // In case it didn't work catch (IOException excep) { couldNotCall = true; excep.printStackTrace(); @@ -107,10 +110,21 @@ public boolean requiresBibtexKeys() { return true; } + /** + * Function to get the command to be executed for pushing keys to be cited + * + * @param keyString String containing the Bibtex keys to be pushed to the application + * @return String array with the command to call and its arguments + */ protected String[] getCommandLine(String keyString) { return null; } + /** + * Function to get the command name in case it is different from the application name + * + * @return String with the command name + */ protected String getCommandName() { return null; } @@ -126,8 +140,15 @@ public JPanel getSettingsPanel() { return settings; } + /** + * Function to initialize parameters. Currently it is expected that commandPathPreferenceKey is set to the path of + * the application. + */ abstract protected void initParameters(); + /** + * Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings + */ protected void initSettingsPanel() { builder = FormBuilder.create(); builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p")); @@ -152,6 +173,9 @@ public void storeSettings() { Globals.prefs.put(commandPathPreferenceKey, Path.getText()); } + /** + * @return Error message in case couldNotCall is set + */ protected String getCouldNotCall() { // @formatter:off return Localization.lang("Error") + ": " @@ -159,6 +183,9 @@ protected String getCouldNotCall() { // @formatter:on } + /** + * @return Error message in case couldNotConnect is set + */ protected String getCouldNotConnect() { // @formatter:off return Localization.lang("Error") + ": " diff --git a/src/main/java/net/sf/jabref/external/push/PushToLyx.java b/src/main/java/net/sf/jabref/external/push/PushToLyx.java index 66189420b09..5db82726957 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToLyx.java +++ b/src/main/java/net/sf/jabref/external/push/PushToLyx.java @@ -30,6 +30,47 @@ public class PushToLyx extends AbstractPushToApplication implements PushToApplication { + @Override + public String getApplicationName() { + return "LyX/Kile"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("lyx"); + } + + @Override + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.LYXPIPE; + } + + @Override + protected String getCouldNotCall() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("unable to write to") + " " + commandPath + + ".in"; + // @formatter:on + } + + @Override + protected String getCouldNotConnect() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("verify that LyX is running and that the lyxpipe is valid") + + ". [" + commandPath + "]"; + // @formatter:on + + } + + @Override + protected void initSettingsPanel() { + settings = new JPanel(); + settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); + settings.add(Path); + } + @Override public void pushEntries(BibtexDatabase database, final BibtexEntry[] entries, final String keyString, MetaData metaData) { @@ -81,46 +122,6 @@ public void run() { }); } - @Override - public String getApplicationName() { - return "LyX/Kile"; - } - - @Override - public Icon getIcon() { - return IconTheme.getImage("lyx"); - } - - @Override - protected void initParameters() { - commandPathPreferenceKey = JabRefPreferences.LYXPIPE; - } - - @Override - protected String getCouldNotCall() { - // @formatter:off - return Localization.lang("Error") + ": " + - Localization.lang("unable to write to") + " " + commandPath + - ".in"; - // @formatter:on - } - - @Override - protected String getCouldNotConnect() { - // @formatter:off - return Localization.lang("Error") + ": " + - Localization.lang("verify that LyX is running and that the lyxpipe is valid") - + ". [" + commandPath + "]"; - // @formatter:on - - } - - @Override - protected void initSettingsPanel() { - settings = new JPanel(); - settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); - settings.add(Path); - } /*class Timeout extends javax.swing.Timer { public Timeout(int timeout, final Thread toStop, final String message) { From a9882d29e862bc44fda8e72dee0e3148ede8300d Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 9 Oct 2015 20:33:28 +0200 Subject: [PATCH 08/10] Changes as suggested by Simon Harrer --- .../push/AbstractPushToApplication.java | 9 +++- .../push/PushToApplicationButton.java | 41 ++---------------- .../external/push/PushToApplications.java | 42 +++++++++++++++++++ .../java/net/sf/jabref/gui/JabRefFrame.java | 3 +- .../java/net/sf/jabref/logic/util/OS.java | 10 ++--- 5 files changed, 60 insertions(+), 45 deletions(-) create mode 100644 src/main/java/net/sf/jabref/external/push/PushToApplications.java diff --git a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java index 9d605fcd98b..8d269d85c3c 100644 --- a/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -30,11 +30,16 @@ import net.sf.jabref.model.database.BibtexDatabase; import net.sf.jabref.model.entry.BibtexEntry; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * Abstract class for pushing entries into different editors. */ public abstract class AbstractPushToApplication implements PushToApplication { + private static final Log LOGGER = LogFactory.getLog(AbstractPushToApplication.class); + protected boolean couldNotCall; // Set to true in case the command could not be executed, e.g., if the file is not found protected boolean couldNotConnect; // Set to true in case the tunnel to the program (if one is used) does not operate protected boolean notDefined; // Set to true if the corresponding path is not defined in the preferences @@ -58,7 +63,7 @@ public String getTooltip() { @Override public String getKeyStrokeName() { - return Localization.lang("Push to %0", getApplicationName()); + return "Push to " + getApplicationName(); } @Override @@ -85,7 +90,7 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k // In case it didn't work catch (IOException excep) { couldNotCall = true; - excep.printStackTrace(); + LOGGER.warn(getCouldNotCall()); } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java index 9e7c934213e..0e9af76e0de 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java @@ -22,7 +22,6 @@ import net.sf.jabref.gui.JabRefFrame; import net.sf.jabref.gui.actions.MnemonicAwareAction; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.openoffice.OpenOfficePanel; import javax.swing.*; @@ -31,8 +30,6 @@ import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -45,8 +42,6 @@ */ public class PushToApplicationButton implements ActionListener { - public static final List applications; - private final JabRefFrame frame; private final List pushActions; private JPanel comp; @@ -61,27 +56,6 @@ public class PushToApplicationButton implements ActionListener { private final JPopupMenu optPopup = new JPopupMenu(); private final JMenuItem settings = new JMenuItem(Localization.lang("Settings")); - /** - * Set up the current available choices: - */ - static { - //TODO plugins create collection class - applications = new ArrayList(); - - PushToApplicationButton.applications.add(new PushToLyx()); - PushToApplicationButton.applications.add(new PushToEmacs()); - PushToApplicationButton.applications.add(new PushToWinEdt()); - PushToApplicationButton.applications.add(new PushToLatexEditor()); - PushToApplicationButton.applications.add(new PushToVim()); - PushToApplicationButton.applications.add(OpenOfficePanel.getInstance()); - PushToApplicationButton.applications.add(new PushToTeXstudio()); - PushToApplicationButton.applications.add(new PushToTexmaker()); - - // Finally, sort the entries: - //Collections.sort(applications, new PushToApplicationComparator()); - } - - public PushToApplicationButton(JabRefFrame frame, List pushActions) { this.frame = frame; this.pushActions = pushActions; @@ -248,6 +222,8 @@ public void actionPerformed(ActionEvent event) { im.put(Globals.prefs.getKey("Close dialog"), "close"); am.put("close", new AbstractAction() { + private static final long serialVersionUID = -4839826710086306753L; + @Override public void actionPerformed(ActionEvent e) { diag.dispose(); @@ -304,6 +280,8 @@ public void actionPerformed(ActionEvent e) { class MenuAction extends MnemonicAwareAction { + private static final long serialVersionUID = -4339280220347418559L; + public MenuAction() { putValue(Action.ACCELERATOR_KEY, Globals.prefs.getKey("Push to application")); } @@ -352,15 +330,4 @@ private void processPopupTrigger(MouseEvent e) { } } - - /** - * Comparator for sorting the selection according to name. - */ - private static class PushToApplicationComparator implements Comparator { - - @Override - public int compare(PushToApplication one, PushToApplication two) { - return one.getName().compareTo(two.getName()); - } - } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplications.java b/src/main/java/net/sf/jabref/external/push/PushToApplications.java new file mode 100644 index 00000000000..def6e100860 --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToApplications.java @@ -0,0 +1,42 @@ +package net.sf.jabref.external.push; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import net.sf.jabref.openoffice.OpenOfficePanel; + +public class PushToApplications { + public static final List applications; + + /** + * Set up the current available choices: + */ + static { + //TODO plugins create collection class + applications = new ArrayList(); + + PushToApplications.applications.add(new PushToLyx()); + PushToApplications.applications.add(new PushToEmacs()); + PushToApplications.applications.add(new PushToWinEdt()); + PushToApplications.applications.add(new PushToLatexEditor()); + PushToApplications.applications.add(new PushToVim()); + PushToApplications.applications.add(OpenOfficePanel.getInstance()); + PushToApplications.applications.add(new PushToTeXstudio()); + PushToApplications.applications.add(new PushToTexmaker()); + + // Finally, sort the entries: + //Collections.sort(applications, new PushToApplicationComparator()); + } + + /** + * Comparator for sorting the selection according to name. + */ + private static class PushToApplicationComparator implements Comparator { + + @Override + public int compare(PushToApplication one, PushToApplication two) { + return one.getName().compareTo(two.getName()); + } + } +} diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index cb75bac418f..d5013986edf 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -74,6 +74,7 @@ import net.sf.jabref.exporter.SaveDatabaseAction; import net.sf.jabref.external.ExternalFileTypeEditor; import net.sf.jabref.external.push.PushToApplicationButton; +import net.sf.jabref.external.push.PushToApplications; import net.sf.jabref.groups.EntryTableTransferHandler; import net.sf.jabref.groups.GroupSelector; import net.sf.jabref.gui.menus.help.ForkMeOnGitHubAction; @@ -908,7 +909,7 @@ private void initLayout() { setProgressBarVisible(false); pushExternalButton = new PushToApplicationButton(this, - PushToApplicationButton.applications); + PushToApplications.applications); fillMenu(); createToolBar(); getContentPane().setLayout(gbl); diff --git a/src/main/java/net/sf/jabref/logic/util/OS.java b/src/main/java/net/sf/jabref/logic/util/OS.java index 52d242660d2..d3866a8c969 100644 --- a/src/main/java/net/sf/jabref/logic/util/OS.java +++ b/src/main/java/net/sf/jabref/logic/util/OS.java @@ -8,9 +8,9 @@ public class OS { // https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/SystemUtils.html public static final String osName = System.getProperty("os.name", "unknown").toLowerCase(); - public static final boolean LINUX = osName.startsWith("linux"); - public static final boolean WINDOWS = osName.startsWith("win"); - public static final boolean OS_X = osName.startsWith("mac"); + public static final boolean LINUX = OS.osName.startsWith("linux"); + public static final boolean WINDOWS = OS.osName.startsWith("win"); + public static final boolean OS_X = OS.osName.startsWith("mac"); public static final String guessProgramPath(String programName, String windowsDirectory) { if (OS.WINDOWS) { @@ -18,7 +18,7 @@ public static final String guessProgramPath(String programName, String windowsDi if (progFiles == null) { progFiles = System.getenv("ProgramFiles"); } - if (windowsDirectory != null) { + if ((windowsDirectory != null) && !windowsDirectory.isEmpty()) { return progFiles + "\\" + windowsDirectory + "\\" + programName + ".exe"; } else { return progFiles + "\\" + programName + ".exe"; @@ -29,6 +29,6 @@ public static final String guessProgramPath(String programName, String windowsDi } public static final String guessProgramPath(String programName) { - return guessProgramPath(programName); + return OS.guessProgramPath(programName, null); } } From cd3719f6f9b7f73eddcff70894c792eb1b4449f9 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 9 Oct 2015 20:50:32 +0200 Subject: [PATCH 09/10] Added copyright statement, updated ChangeLog, removed print outs --- CHANGELOG | 1 + .../jabref/external/push/PushToApplications.java | 16 ++++++++++++++++ .../net/sf/jabref/external/push/PushToEmacs.java | 9 +++++++-- .../net/sf/jabref/external/push/PushToVim.java | 10 ++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1e1276df10c..0322fafa076 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ [master] - Removes non-compact rank symbols in favor of compact rank + - Reworked the PushToXXX functionality - All duplicate whitespaces / tabs / newlines are now removed from non-multiline fields - Fixed a bug in the IEEEXploreFetcher - Replaced some deprecated DefaultFormBuilder with FormBuilder diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplications.java b/src/main/java/net/sf/jabref/external/push/PushToApplications.java index def6e100860..7b6d3992b93 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToApplications.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplications.java @@ -1,3 +1,19 @@ +/* Copyright (C) 2003-2015 JabRef contributors. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + package net.sf.jabref.external.push; import java.util.ArrayList; diff --git a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java index 38f5f54d2ec..4dd79d01bd6 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToEmacs.java +++ b/src/main/java/net/sf/jabref/external/push/PushToEmacs.java @@ -29,11 +29,16 @@ import net.sf.jabref.model.database.BibtexDatabase; import net.sf.jabref.model.entry.BibtexEntry; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * Created by IntelliJ IDEA. User: alver Date: Jan 14, 2006 Time: 4:55:23 PM */ public class PushToEmacs extends AbstractPushToApplication implements PushToApplication { + private static final Log LOGGER = LogFactory.getLog(PushToEmacs.class); + private final JTextField additionalParams = new JTextField(30); private final JCheckBox useEmacs23 = new JCheckBox(); @@ -135,11 +140,11 @@ public void run() { sb.append((char) c); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.warn("Could not read from stderr."); } // Error stream has been closed. See if there were any errors: if (!sb.toString().trim().isEmpty()) { - System.out.println(sb); + LOGGER.warn("Push to Emacs error: " + sb); couldNotConnect = true; } } diff --git a/src/main/java/net/sf/jabref/external/push/PushToVim.java b/src/main/java/net/sf/jabref/external/push/PushToVim.java index aded03b66d9..9411f8482bb 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToVim.java +++ b/src/main/java/net/sf/jabref/external/push/PushToVim.java @@ -23,6 +23,10 @@ import net.sf.jabref.model.entry.BibtexEntry; import javax.swing.*; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.IOException; import java.io.InputStream; @@ -32,6 +36,8 @@ */ public class PushToVim extends AbstractPushToApplication implements PushToApplication { + private static final Log LOGGER = LogFactory.getLog(PushToEmacs.class); + private final JTextField vimServer = new JTextField(30); @@ -103,11 +109,11 @@ public void run() { sb.append((char) c); } } catch (IOException e) { - e.printStackTrace(); + LOGGER.warn("Could not read from stderr."); } // Error stream has been closed. See if there were any errors: if (!sb.toString().trim().isEmpty()) { - System.out.println(sb); + LOGGER.warn("Push to Emacs error: " + sb); couldNotConnect = true; } } From b93625d26d06082e3004e83594714ab895424dbc Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 9 Oct 2015 22:51:15 +0200 Subject: [PATCH 10/10] Removed unused comparator --- .../jabref/external/push/PushToApplications.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/main/java/net/sf/jabref/external/push/PushToApplications.java b/src/main/java/net/sf/jabref/external/push/PushToApplications.java index 7b6d3992b93..6268acb53c1 100644 --- a/src/main/java/net/sf/jabref/external/push/PushToApplications.java +++ b/src/main/java/net/sf/jabref/external/push/PushToApplications.java @@ -17,7 +17,6 @@ package net.sf.jabref.external.push; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import net.sf.jabref.openoffice.OpenOfficePanel; @@ -29,7 +28,6 @@ public class PushToApplications { * Set up the current available choices: */ static { - //TODO plugins create collection class applications = new ArrayList(); PushToApplications.applications.add(new PushToLyx()); @@ -40,19 +38,5 @@ public class PushToApplications { PushToApplications.applications.add(OpenOfficePanel.getInstance()); PushToApplications.applications.add(new PushToTeXstudio()); PushToApplications.applications.add(new PushToTexmaker()); - - // Finally, sort the entries: - //Collections.sort(applications, new PushToApplicationComparator()); - } - - /** - * Comparator for sorting the selection according to name. - */ - private static class PushToApplicationComparator implements Comparator { - - @Override - public int compare(PushToApplication one, PushToApplication two) { - return one.getName().compareTo(two.getName()); - } } }