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/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/external/PushToLatexEditor.java b/src/main/java/net/sf/jabref/external/PushToLatexEditor.java deleted file mode 100644 index 51f73ce9e4c..00000000000 --- a/src/main/java/net/sf/jabref/external/PushToLatexEditor.java +++ /dev/null @@ -1,145 +0,0 @@ -/* 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; - -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; - -/** - * 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()); - } - - @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(); - } - } - - @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"); - } - } - - @Override - public boolean requiresBibtexKeys() { - return true; - } - - @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/PushToTeXstudio.java b/src/main/java/net/sf/jabref/external/PushToTeXstudio.java deleted file mode 100644 index a87ac8e5c71..00000000000 --- a/src/main/java/net/sf/jabref/external/PushToTeXstudio.java +++ /dev/null @@ -1,202 +0,0 @@ -/* 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; - -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; - -/** - * 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()); - } - - @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())); - } - } - - @Override - public boolean requiresBibtexKeys() { - return true; - } -} diff --git a/src/main/java/net/sf/jabref/external/PushToTexmaker.java b/src/main/java/net/sf/jabref/external/PushToTexmaker.java deleted file mode 100644 index e9284a110e1..00000000000 --- a/src/main/java/net/sf/jabref/external/PushToTexmaker.java +++ /dev/null @@ -1,142 +0,0 @@ -/* 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; - -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; - -/** - * 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()); - } - - @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; - } - - @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; - } - - @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()); - } -} diff --git a/src/main/java/net/sf/jabref/external/PushToWinEdt.java b/src/main/java/net/sf/jabref/external/PushToWinEdt.java deleted file mode 100644 index 981681115bd..00000000000 --- a/src/main/java/net/sf/jabref/external/PushToWinEdt.java +++ /dev/null @@ -1,140 +0,0 @@ -/* 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; - -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; - -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()); - } - - @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(); - } - - @Override - public void storeSettings() { - Globals.prefs.put(JabRefPreferences.WIN_EDT_PATH, winEdtPath.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_WIN_EDT, citeCommand.getText()); - } -} 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..8d269d85c3c --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/AbstractPushToApplication.java @@ -0,0 +1,201 @@ +/* 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; + +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 + protected JPanel settings; + protected final JTextField Path = new JTextField(30); + protected String commandPath; + protected String commandPathPreferenceKey; + protected String citeCommand = Globals.prefs.get(JabRefPreferences.CITE_COMMAND); + protected FormBuilder builder; + + + @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 "Push to " + getApplicationName(); + } + + @Override + public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) { + + couldNotConnect = false; + couldNotCall = false; + notDefined = false; + + 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; + LOGGER.warn(getCouldNotCall()); + } + } + + @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) { + panel.output(getCouldNotCall()); + } else if (couldNotConnect) { + panel.output(getCouldNotConnect()); + } else { + panel.output(Localization.lang("Pushed citations to %0", getApplicationName()) + "."); + } + } + + @Override + 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; + } + + @Override + public JPanel getSettingsPanel() { + initParameters(); + commandPath = Globals.prefs.get(commandPathPreferenceKey); + if (settings == null) { + initSettingsPanel(); + } + Path.setText(commandPath); + 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")); + 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(commandPathPreferenceKey, Path.getText()); + } + + /** + * @return Error message in case couldNotCall is set + */ + protected String getCouldNotCall() { + // @formatter:off + return Localization.lang("Error") + ": " + + Localization.lang("Could not call executable") + " '" + commandPath + "'."; + // @formatter:on + } + + /** + * @return Error message in case couldNotConnect is set + */ + 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/PushToApplication.java b/src/main/java/net/sf/jabref/external/push/PushToApplication.java similarity index 67% 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..428151b7b6a 100644 --- a/src/main/java/net/sf/jabref/external/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 @@ -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; @@ -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/PushToApplicationAction.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java similarity index 92% 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..f8762ae64dc 100644 --- a/src/main/java/net/sf/jabref/external/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 @@ -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; @@ -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/PushToApplicationButton.java b/src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java similarity index 88% 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..0e9af76e0de 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; @@ -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..6268acb53c1 --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToApplications.java @@ -0,0 +1,42 @@ +/* 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; +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 { + 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()); + } +} 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 52% 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..4dd79d01bd6 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; @@ -22,94 +22,59 @@ 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 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 + * 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 static final Log LOGGER = LogFactory.getLog(PushToEmacs.class); - 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() { - if (settings == null) { - initSettingsPanel(); - } - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS)); - emacsPath.setText(Globals.prefs.get(JabRefPreferences.EMACS_PATH)); 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(JabRefPreferences.CITE_COMMAND_EMACS, citeCommand.getText()); - Globals.prefs.put(JabRefPreferences.EMACS_PATH, emacsPath.getText()); + super.storeSettings(); Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText()); Globals.prefs.putBoolean(JabRefPreferences.EMACS_23, useEmacs23.isSelected()); } - private 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.add(Localization.lang("Path to gnuclient or emacsclient") + ":").xy(1, 1); - builder.add(emacsPath).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(emacsPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5,1); + @Override + protected void initSettingsPanel() { + 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(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 +82,22 @@ 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; + 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 { 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 +110,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); @@ -168,18 +140,18 @@ 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; } } }; JabRefExecutorService.INSTANCE.executeAndWait(errorListener); } catch (IOException excep) { - couldNotRunClient = true; + couldNotCall = true; } } @@ -187,27 +159,30 @@ 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); - } else { - panel.output(Localization.lang("Pushed citations to %0", getApplicationName())); + // @formatter:on } + super.operationCompleted(panel); } @Override - public boolean requiresBibtexKeys() { - return true; + 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/PushToLatexEditor.java b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java new file mode 100644 index 00000000000..8597d9996ae --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToLatexEditor.java @@ -0,0 +1,53 @@ +/* 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 javax.swing.*; + +import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.gui.IconTheme; + +/** + * Class for pushing entries into LatexEditor. + */ +public class PushToLatexEditor extends AbstractPushToApplication implements PushToApplication { + + @Override + public String getApplicationName() { + return "LatexEditor"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("edit"); + } + + @Override + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "-i", citeCommand + "{" + keyString + "}"}; + } + + @Override + protected String getCommandName() { + return "LEd.exe"; + } + + @Override + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.LATEX_EDITOR_PATH; + } + +} 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 55% 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..5db82726957 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; @@ -23,37 +23,78 @@ 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; import net.sf.jabref.model.entry.BibtexEntry; -public class PushToLyx implements PushToApplication { +public class PushToLyx extends AbstractPushToApplication implements PushToApplication { - private final JTextField lyxPipe = new JTextField(30); - private JPanel settings; + @Override + public String getApplicationName() { + return "LyX/Kile"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("lyx"); + } - private boolean couldNotFindPipe; - private boolean couldNotWrite; + @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) { - couldNotFindPipe = false; - couldNotWrite = false; + couldNotConnect = false; + couldNotCall = false; + notDefined = false; - String lyxpipeSetting = Globals.prefs.get(JabRefPreferences.LYXPIPE); - if (!lyxpipeSetting.endsWith(".in")) { - lyxpipeSetting = lyxpipeSetting + ".in"; + initParameters(); + commandPath = Globals.prefs.get(commandPathPreferenceKey); + + if ((commandPath == null) || commandPath.trim().isEmpty()) { + notDefined = true; + return; } - File lp = new File(lyxpipeSetting); // this needs to fixed because it gives "asdf" when going prefs.get("lyxpipe") + + if (!commandPath.endsWith(".in")) { + commandPath = commandPath + ".in"; + } + 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; } } @@ -75,79 +116,12 @@ 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) { - // @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 (couldNotWrite) { - 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())); - } - - } - - @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()); - } - - private void initSettingsPanel() { - settings = new JPanel(); - settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":")); - settings.add(lyxPipe); - } /*class Timeout extends javax.swing.Timer { public Timeout(int timeout, final Thread toStop, final String message) { diff --git a/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java new file mode 100644 index 00000000000..99dee113984 --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToTeXstudio.java @@ -0,0 +1,48 @@ +/* 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 javax.swing.*; + +import net.sf.jabref.gui.IconTheme; +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 extends AbstractPushToApplication implements PushToApplication { + + @Override + public String getApplicationName() { + return "TeXstudio"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("texstudio"); + } + + @Override + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "--insert-cite", keyString}; + } + + @Override + 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 new file mode 100644 index 00000000000..9849acbcd51 --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToTexmaker.java @@ -0,0 +1,49 @@ +/* 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 javax.swing.*; + +import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.gui.IconTheme; + +/** + * Class for pushing entries into TexMaker. + */ +public class PushToTexmaker extends AbstractPushToApplication implements PushToApplication { + + @Override + public String getApplicationName() { + return "Texmaker"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("texmaker"); + } + + @Override + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "-insert", citeCommand + "{" + keyString + "}"}; + } + + @Override + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.TEXMAKER_PATH; + } + +} 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 58% 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..9411f8482bb 100644 --- a/src/main/java/net/sf/jabref/external/PushToVim.java +++ b/src/main/java/net/sf/jabref/external/push/PushToVim.java @@ -13,114 +13,88 @@ 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; 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; import javax.swing.*; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.IOException; 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 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); +public class PushToVim extends AbstractPushToApplication implements PushToApplication { - private boolean couldNotConnect; - private boolean couldNotRunClient; + private static final Log LOGGER = LogFactory.getLog(PushToEmacs.class); + private final JTextField vimServer = new JTextField(30); - @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)); vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER)); - citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM)); - return settings; + return super.getSettingsPanel(); } @Override public void storeSettings() { - Globals.prefs.put(JabRefPreferences.VIM, vimPath.getText()); + super.storeSettings(); Globals.prefs.put(JabRefPreferences.VIM_SERVER, vimServer.getText()); - Globals.prefs.put(JabRefPreferences.CITE_COMMAND_VIM, citeCommand.getText()); } - private 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 %0", getApplicationName()) + ":").xy(1, 1); - builder.add(vimPath).xy(3,1); - BrowseAction action = BrowseAction.buildForFile(vimPath); - JButton browse = new JButton(Localization.lang("Browse")); - browse.addActionListener(action); - builder.add(browse).xy(5,1); + @Override + protected void initSettingsPanel() { + super.initSettingsPanel(); + builder.appendRows("2dlu, p"); 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); + 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; - couldNotRunClient = 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" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM) + + "a" + citeCommand + "{" + keys + "}"}; // @formatter:on - final Process p = Runtime.getRuntime().exec(com); Runnable errorListener = new Runnable() { @@ -135,18 +109,18 @@ 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; } } }; JabRefExecutorService.INSTANCE.executeAndWait(errorListener); } catch (IOException excep) { - couldNotRunClient = true; + couldNotCall = true; } } @@ -154,6 +128,7 @@ public void run() { @Override public void operationCompleted(BasePanel panel) { if (couldNotConnect) { + // @formatter:off JOptionPane.showMessageDialog( panel.frame(), "" + @@ -161,18 +136,19 @@ 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."), Localization.lang("Error"), JOptionPane.ERROR_MESSAGE); - } else { - panel.output(Localization.lang("Pushed citations to %0",getApplicationName())); + // formatter:on } + super.operationCompleted(panel); } - + @Override - public boolean requiresBibtexKeys() { - return true; + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.VIM; } + } diff --git a/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java new file mode 100644 index 00000000000..fae4ec65e9f --- /dev/null +++ b/src/main/java/net/sf/jabref/external/push/PushToWinEdt.java @@ -0,0 +1,44 @@ +/* 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 javax.swing.*; + +import net.sf.jabref.JabRefPreferences; +import net.sf.jabref.gui.IconTheme; + +public class PushToWinEdt extends AbstractPushToApplication implements PushToApplication { + + @Override + public String getApplicationName() { + return "WinEdt"; + } + + @Override + public Icon getIcon() { + return IconTheme.getImage("winedt"); + } + + @Override + protected String[] getCommandLine(String keyString) { + return new String[] {commandPath, "\"[InsText('" + citeCommand + "{" + keyString.replaceAll("'", "''") + "}');]\""}; + } + + @Override + protected void initParameters() { + commandPathPreferenceKey = JabRefPreferences.WIN_EDT_PATH; + } +} diff --git a/src/main/java/net/sf/jabref/gui/JabRefFrame.java b/src/main/java/net/sf/jabref/gui/JabRefFrame.java index a6132827000..d5013986edf 100644 --- a/src/main/java/net/sf/jabref/gui/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/gui/JabRefFrame.java @@ -73,7 +73,8 @@ 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.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/gui/preftabs/ExternalTab.java b/src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java index 505b29f3f3e..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,7 +26,8 @@ import javax.swing.event.ChangeListener; import net.sf.jabref.*; -import net.sf.jabref.external.*; +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; @@ -49,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; @@ -84,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()); @@ -204,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); @@ -242,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)) { @@ -270,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 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..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,7 +8,27 @@ 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) { + String progFiles = System.getenv("ProgramFiles(x86)"); + if (progFiles == null) { + progFiles = System.getenv("ProgramFiles"); + } + if ((windowsDirectory != null) && !windowsDirectory.isEmpty()) { + return progFiles + "\\" + windowsDirectory + "\\" + programName + ".exe"; + } else { + return progFiles + "\\" + programName + ".exe"; + } + } else { + return programName; + } + } + + public static final String guessProgramPath(String programName) { + return OS.guessProgramPath(programName, null); + } } 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;