Skip to content

Commit 0ccee3a

Browse files
committedOct 14, 2015
Merge pull request #218 from oscargus/abstractpusher
AbstractPushToApplication
2 parents 1032437 + b93625d commit 0ccee3a

22 files changed

+672
-952
lines changed
 

‎CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[master]
22
- Removes non-compact rank symbols in favor of compact rank
3+
- Reworked the PushToXXX functionality
34
- All duplicate whitespaces / tabs / newlines are now removed from non-multiline fields
45
- Fixed a bug in the IEEEXploreFetcher
56
- Replaced some deprecated DefaultFormBuilder with FormBuilder

‎src/main/java/net/sf/jabref/JabRefPreferences.java

+6-17
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,6 @@ public class JabRefPreferences {
294294
public static final String FILECHOOSER_DISABLE_RENAME = "filechooserDisableRename";
295295
public static final String USE_NATIVE_FILE_DIALOG_ON_MAC = "useNativeFileDialogOnMac";
296296
public static final String FLOAT_MARKED_ENTRIES = "floatMarkedEntries";
297-
public static final String CITE_COMMAND_LED = "citeCommandLed";
298-
public static final String CITE_COMMAND_WIN_EDT = "citeCommandWinEdt";
299-
public static final String CITE_COMMAND_EMACS = "citeCommandEmacs";
300-
public static final String CITE_COMMAND_TEXMAKER = "citeCommandTexmaker";
301-
public static final String CITE_COMMAND_VIM = "citeCommandVim";
302-
public static final String CITE_COMMAND_TEXSTUDIO = "citeCommandTeXstudio";
303297
public static final String CITE_COMMAND = "citeCommand";
304298
public static final String EXTERNAL_JOURNAL_LISTS = "externalJournalLists";
305299
public static final String PERSONAL_JOURNAL_LIST = "personalJournalList";
@@ -430,6 +424,11 @@ private JabRefPreferences() {
430424
// load user preferences
431425
prefs = Preferences.userNodeForPackage(JabRef.class);
432426

427+
defaults.put(TEXMAKER_PATH, OS.guessProgramPath("texmaker", "Texmaker"));
428+
defaults.put(WIN_EDT_PATH, OS.guessProgramPath("WinEdt", "WinEdt Team\\WinEdt"));
429+
defaults.put(LATEX_EDITOR_PATH, OS.guessProgramPath("LEd", "LEd"));
430+
defaults.put(TEXSTUDIO_PATH, OS.guessProgramPath("texstudio", "TeXstudio"));
431+
433432
if (OS.OS_X) {
434433
//defaults.put("pdfviewer", "/Applications/Preview.app");
435434
//defaults.put("psviewer", "/Applications/Preview.app");
@@ -444,9 +443,6 @@ private JabRefPreferences() {
444443
//defaults.put("psviewer", "cmd.exe /c start /b");
445444
//defaults.put("htmlviewer", "cmd.exe /c start /b");
446445
defaults.put(WIN_LOOK_AND_FEEL, "com.jgoodies.looks.windows.WindowsLookAndFeel");
447-
defaults.put(WIN_EDT_PATH, "C:\\Program Files\\WinEdt Team\\WinEdt\\WinEdt.exe");
448-
defaults.put(LATEX_EDITOR_PATH, "C:\\Program Files\\LEd\\LEd.exe");
449-
defaults.put(TEXMAKER_PATH, "C:\\Program Files\\Texmaker\\texmaker.exe");
450446
defaults.put(EMACS_PATH, "emacsclient.exe");
451447
defaults.put(EMACS_23, true);
452448
defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-n -e");
@@ -463,7 +459,6 @@ private JabRefPreferences() {
463459
defaults.put(EMACS_PATH, "gnuclient");
464460
defaults.put(EMACS_23, false);
465461
defaults.put(EMACS_ADDITIONAL_PARAMETERS, "-batch -eval");
466-
defaults.put(TEXMAKER_PATH, "texmaker");
467462

468463
}
469464
defaults.put(USE_PROXY, Boolean.FALSE);
@@ -755,13 +750,7 @@ private JabRefPreferences() {
755750

756751
defaults.put(PERSONAL_JOURNAL_LIST, null);
757752
defaults.put(EXTERNAL_JOURNAL_LISTS, null);
758-
defaults.put(CITE_COMMAND, "cite"); // obsoleted by the app-specific ones
759-
defaults.put(CITE_COMMAND_VIM, "\\cite");
760-
defaults.put(CITE_COMMAND_EMACS, "\\cite");
761-
defaults.put(CITE_COMMAND_WIN_EDT, "\\cite");
762-
defaults.put(CITE_COMMAND_TEXSTUDIO, "\\cite");
763-
defaults.put(CITE_COMMAND_LED, "\\cite");
764-
defaults.put(CITE_COMMAND_TEXMAKER, "\\cite");
753+
defaults.put(CITE_COMMAND, "\\cite"); // obsoleted by the app-specific ones (not any more?)
765754
defaults.put(FLOAT_MARKED_ENTRIES, Boolean.TRUE);
766755

767756
defaults.put(USE_NATIVE_FILE_DIALOG_ON_MAC, Boolean.FALSE);

‎src/main/java/net/sf/jabref/external/PushToLatexEditor.java

-145
This file was deleted.

‎src/main/java/net/sf/jabref/external/PushToTeXstudio.java

-202
This file was deleted.

‎src/main/java/net/sf/jabref/external/PushToTexmaker.java

-142
This file was deleted.

‎src/main/java/net/sf/jabref/external/PushToWinEdt.java

-140
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
/* Copyright (C) 2015 JabRef contributors.
2+
Copyright (C) 2015 Oscar Gustafsson.
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License along
14+
with this program; if not, write to the Free Software Foundation, Inc.,
15+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
*/
17+
package net.sf.jabref.external.push;
18+
19+
import java.io.IOException;
20+
21+
import javax.swing.*;
22+
23+
import net.sf.jabref.*;
24+
25+
import com.jgoodies.forms.builder.FormBuilder;
26+
import com.jgoodies.forms.layout.FormLayout;
27+
import net.sf.jabref.gui.BasePanel;
28+
import net.sf.jabref.gui.actions.BrowseAction;
29+
import net.sf.jabref.logic.l10n.Localization;
30+
import net.sf.jabref.model.database.BibtexDatabase;
31+
import net.sf.jabref.model.entry.BibtexEntry;
32+
33+
import org.apache.commons.logging.Log;
34+
import org.apache.commons.logging.LogFactory;
35+
36+
/**
37+
* Abstract class for pushing entries into different editors.
38+
*/
39+
public abstract class AbstractPushToApplication implements PushToApplication {
40+
41+
private static final Log LOGGER = LogFactory.getLog(AbstractPushToApplication.class);
42+
43+
protected boolean couldNotCall; // Set to true in case the command could not be executed, e.g., if the file is not found
44+
protected boolean couldNotConnect; // Set to true in case the tunnel to the program (if one is used) does not operate
45+
protected boolean notDefined; // Set to true if the corresponding path is not defined in the preferences
46+
protected JPanel settings;
47+
protected final JTextField Path = new JTextField(30);
48+
protected String commandPath;
49+
protected String commandPathPreferenceKey;
50+
protected String citeCommand = Globals.prefs.get(JabRefPreferences.CITE_COMMAND);
51+
protected FormBuilder builder;
52+
53+
54+
@Override
55+
public String getName() {
56+
return Localization.menuTitle("Insert selected citations into %d", getApplicationName());
57+
}
58+
59+
@Override
60+
public String getTooltip() {
61+
return Localization.lang("Push to %0", getApplicationName());
62+
}
63+
64+
@Override
65+
public String getKeyStrokeName() {
66+
return "Push to " + getApplicationName();
67+
}
68+
69+
@Override
70+
public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData) {
71+
72+
couldNotConnect = false;
73+
couldNotCall = false;
74+
notDefined = false;
75+
76+
initParameters();
77+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
78+
79+
// Check if a path to the command has been specified
80+
if ((commandPath == null) || commandPath.trim().isEmpty()) {
81+
notDefined = true;
82+
return;
83+
}
84+
85+
// Execute command
86+
try {
87+
Runtime.getRuntime().exec(getCommandLine(keyString));
88+
}
89+
90+
// In case it didn't work
91+
catch (IOException excep) {
92+
couldNotCall = true;
93+
LOGGER.warn(getCouldNotCall());
94+
}
95+
}
96+
97+
@Override
98+
public void operationCompleted(BasePanel panel) {
99+
if (notDefined) {
100+
// @formatter:off
101+
panel.output(Localization.lang("Error") + ": "
102+
+ Localization.lang("Path to %0 not defined", getApplicationName()) + ".");
103+
// @formatter:on
104+
} else if (couldNotCall) {
105+
panel.output(getCouldNotCall());
106+
} else if (couldNotConnect) {
107+
panel.output(getCouldNotConnect());
108+
} else {
109+
panel.output(Localization.lang("Pushed citations to %0", getApplicationName()) + ".");
110+
}
111+
}
112+
113+
@Override
114+
public boolean requiresBibtexKeys() {
115+
return true;
116+
}
117+
118+
/**
119+
* Function to get the command to be executed for pushing keys to be cited
120+
*
121+
* @param keyString String containing the Bibtex keys to be pushed to the application
122+
* @return String array with the command to call and its arguments
123+
*/
124+
protected String[] getCommandLine(String keyString) {
125+
return null;
126+
}
127+
128+
/**
129+
* Function to get the command name in case it is different from the application name
130+
*
131+
* @return String with the command name
132+
*/
133+
protected String getCommandName() {
134+
return null;
135+
}
136+
137+
@Override
138+
public JPanel getSettingsPanel() {
139+
initParameters();
140+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
141+
if (settings == null) {
142+
initSettingsPanel();
143+
}
144+
Path.setText(commandPath);
145+
return settings;
146+
}
147+
148+
/**
149+
* Function to initialize parameters. Currently it is expected that commandPathPreferenceKey is set to the path of
150+
* the application.
151+
*/
152+
abstract protected void initParameters();
153+
154+
/**
155+
* Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings
156+
*/
157+
protected void initSettingsPanel() {
158+
builder = FormBuilder.create();
159+
builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p"));
160+
String label = Localization.lang("Path to %0", getApplicationName());
161+
// In case the application name and the actual command is not the same, add the command in brackets
162+
if (getCommandName() != null) {
163+
label += " (" + getCommandName() + "):";
164+
} else {
165+
label += ":";
166+
}
167+
builder.add(label).xy(1, 1);
168+
builder.add(Path).xy(3, 1);
169+
BrowseAction action = BrowseAction.buildForFile(Path);
170+
JButton browse = new JButton(Localization.lang("Browse"));
171+
browse.addActionListener(action);
172+
builder.add(browse).xy(5, 1);
173+
settings = builder.build();
174+
}
175+
176+
@Override
177+
public void storeSettings() {
178+
Globals.prefs.put(commandPathPreferenceKey, Path.getText());
179+
}
180+
181+
/**
182+
* @return Error message in case couldNotCall is set
183+
*/
184+
protected String getCouldNotCall() {
185+
// @formatter:off
186+
return Localization.lang("Error") + ": "
187+
+ Localization.lang("Could not call executable") + " '" + commandPath + "'.";
188+
// @formatter:on
189+
}
190+
191+
/**
192+
* @return Error message in case couldNotConnect is set
193+
*/
194+
protected String getCouldNotConnect() {
195+
// @formatter:off
196+
return Localization.lang("Error") + ": "
197+
+ Localization.lang("Could not connect to ") + getApplicationName() + ".";
198+
// @formatter:on
199+
}
200+
201+
}

‎src/main/java/net/sf/jabref/external/PushToApplication.java ‎src/main/java/net/sf/jabref/external/push/PushToApplication.java

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2003-2011 JabRef contributors.
1+
/* Copyright (C) 2003-2015 JabRef contributors.
22
This program is free software; you can redistribute it and/or modify
33
it under the terms of the GNU General Public License as published by
44
the Free Software Foundation; either version 2 of the License, or
@@ -13,7 +13,7 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

1818
import net.sf.jabref.gui.BasePanel;
1919
import net.sf.jabref.model.database.BibtexDatabase;
@@ -23,8 +23,7 @@
2323
import javax.swing.*;
2424

2525
/**
26-
* Class that defines interaction with an external application in the form of
27-
* "pushing" selected entries to it.
26+
* Class that defines interaction with an external application in the form of "pushing" selected entries to it.
2827
*/
2928
public interface PushToApplication {
3029

@@ -39,43 +38,41 @@ public interface PushToApplication {
3938
String getKeyStrokeName();
4039

4140
/**
42-
* This method asks the implementing class to return a JPanel populated
43-
* with the imlementation's options panel, if necessary. If the JPanel
44-
* is shown to the user, and the user indicates that settings should
45-
* be stored, the implementation's storeSettings() method will be called.
46-
* This method must make sure all widgets in the panel are in the correct
47-
* selection states.
41+
* This method asks the implementing class to return a JPanel populated with the imlementation's options panel, if
42+
* necessary. If the JPanel is shown to the user, and the user indicates that settings should be stored, the
43+
* implementation's storeSettings() method will be called. This method must make sure all widgets in the panel are
44+
* in the correct selection states.
4845
*
4946
* @return a JPanel containing options, or null if options are not needed.
5047
*/
5148
JPanel getSettingsPanel();
5249

5350
/**
54-
* This method is called to indicate that the settings panel returned from
55-
* the getSettingsPanel() method has been shown to the user and that the
56-
* user has indicated that the settings should be stored. This method must
57-
* store the state of the widgets in the settings panel to Globals.prefs.
51+
* This method is called to indicate that the settings panel returned from the getSettingsPanel() method has been
52+
* shown to the user and that the user has indicated that the settings should be stored. This method must store the
53+
* state of the widgets in the settings panel to Globals.prefs.
5854
*/
5955
void storeSettings();
6056

6157
/**
62-
* The actual operation. This method will not be called on the event dispatch
63-
* thread, so it should not do GUI operations without utilizing invokeLater().
58+
* The actual operation. This method will not be called on the event dispatch thread, so it should not do GUI
59+
* operations without utilizing invokeLater().
60+
*
6461
* @param database
6562
* @param entries
6663
* @param metaData
6764
*/
6865
void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keyString, MetaData metaData);
6966

7067
/**
71-
* Reporting etc., this method is called on the event dispatch thread after
72-
* pushEntries() returns.
68+
* Reporting etc., this method is called on the event dispatch thread after pushEntries() returns.
7369
*/
7470
void operationCompleted(BasePanel panel);
7571

7672
/**
77-
* Check whether this operation requires BibTeX keys to be set for the entries.
78-
* If true is returned an error message will be displayed if keys are missing.
73+
* Check whether this operation requires BibTeX keys to be set for the entries. If true is returned an error message
74+
* will be displayed if keys are missing.
75+
*
7976
* @return true if BibTeX keys are required for this operation.
8077
*/
8178
boolean requiresBibtexKeys();

‎src/main/java/net/sf/jabref/external/PushToApplicationAction.java ‎src/main/java/net/sf/jabref/external/push/PushToApplicationAction.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2003-2011 JabRef contributors.
1+
/* Copyright (C) 2003-2015 JabRef contributors.
22
This program is free software; you can redistribute it and/or modify
33
it under the terms of the GNU General Public License as published by
44
the Free Software Foundation; either version 2 of the License, or
@@ -13,7 +13,7 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

1818
import java.awt.event.ActionEvent;
1919

@@ -33,6 +33,7 @@
3333
*/
3434
class PushToApplicationAction extends AbstractAction implements Runnable {
3535

36+
private static final long serialVersionUID = 9008115216029319314L;
3637
private final PushToApplication operation;
3738
private final JabRefFrame frame;
3839
private BasePanel panel;
@@ -62,17 +63,15 @@ public void actionPerformed(ActionEvent e) {
6263
// Check if any entries are selected:
6364
entries = panel.getSelectedEntries();
6465
if (entries.length == 0) {
65-
JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."),
66-
(String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
66+
JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires one or more entries to be selected."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
6767
return;
6868
}
6969

7070
// If required, check that all entries have BibTeX keys defined:
7171
if (operation.requiresBibtexKeys()) {
7272
for (BibtexEntry entry : entries) {
7373
if (entry.getCiteKey() == null || entry.getCiteKey().trim().isEmpty()) {
74-
JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires all selected entries to have BibTex keys defined."),
75-
(String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
74+
JOptionPane.showMessageDialog(frame, Localization.lang("This operation requires all selected entries to have BibTex keys defined."), (String) getValue(Action.NAME), JOptionPane.ERROR_MESSAGE);
7675
return;
7776
}
7877
}
@@ -99,7 +98,7 @@ public void run() {
9998

10099
private String getKeyString(BibtexEntry[] entries) {
101100
StringBuilder result = new StringBuilder();
102-
String citeKey;//, message = "";
101+
String citeKey;
103102
boolean first = true;
104103
for (BibtexEntry bes : entries) {
105104
citeKey = bes.getField(BibtexEntry.KEY_FIELD);

‎src/main/java/net/sf/jabref/external/PushToApplicationButton.java ‎src/main/java/net/sf/jabref/external/push/PushToApplicationButton.java

+5-38
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

1818
import com.jgoodies.forms.builder.ButtonBarBuilder;
1919

@@ -22,7 +22,6 @@
2222
import net.sf.jabref.gui.JabRefFrame;
2323
import net.sf.jabref.gui.actions.MnemonicAwareAction;
2424
import net.sf.jabref.logic.l10n.Localization;
25-
import net.sf.jabref.openoffice.OpenOfficePanel;
2625

2726
import javax.swing.*;
2827

@@ -31,8 +30,6 @@
3130
import java.awt.event.ActionListener;
3231
import java.awt.event.MouseAdapter;
3332
import java.awt.event.MouseEvent;
34-
import java.util.ArrayList;
35-
import java.util.Comparator;
3633
import java.util.HashMap;
3734
import java.util.List;
3835

@@ -45,8 +42,6 @@
4542
*/
4643
public class PushToApplicationButton implements ActionListener {
4744

48-
public static final List<PushToApplication> applications;
49-
5045
private final JabRefFrame frame;
5146
private final List<PushToApplication> pushActions;
5247
private JPanel comp;
@@ -61,27 +56,6 @@ public class PushToApplicationButton implements ActionListener {
6156
private final JPopupMenu optPopup = new JPopupMenu();
6257
private final JMenuItem settings = new JMenuItem(Localization.lang("Settings"));
6358

64-
/**
65-
* Set up the current available choices:
66-
*/
67-
static {
68-
//TODO plugins create collection class
69-
applications = new ArrayList<PushToApplication>();
70-
71-
PushToApplicationButton.applications.add(new PushToLyx());
72-
PushToApplicationButton.applications.add(new PushToEmacs());
73-
PushToApplicationButton.applications.add(new PushToWinEdt());
74-
PushToApplicationButton.applications.add(new PushToLatexEditor());
75-
PushToApplicationButton.applications.add(new PushToVim());
76-
PushToApplicationButton.applications.add(OpenOfficePanel.getInstance());
77-
PushToApplicationButton.applications.add(new PushToTeXstudio());
78-
PushToApplicationButton.applications.add(new PushToTexmaker());
79-
80-
// Finally, sort the entries:
81-
//Collections.sort(applications, new PushToApplicationComparator());
82-
}
83-
84-
8559
public PushToApplicationButton(JabRefFrame frame, List<PushToApplication> pushActions) {
8660
this.frame = frame;
8761
this.pushActions = pushActions;
@@ -248,6 +222,8 @@ public void actionPerformed(ActionEvent event) {
248222
im.put(Globals.prefs.getKey("Close dialog"), "close");
249223
am.put("close", new AbstractAction() {
250224

225+
private static final long serialVersionUID = -4839826710086306753L;
226+
251227
@Override
252228
public void actionPerformed(ActionEvent e) {
253229
diag.dispose();
@@ -304,6 +280,8 @@ public void actionPerformed(ActionEvent e) {
304280

305281
class MenuAction extends MnemonicAwareAction {
306282

283+
private static final long serialVersionUID = -4339280220347418559L;
284+
307285
public MenuAction() {
308286
putValue(Action.ACCELERATOR_KEY, Globals.prefs.getKey("Push to application"));
309287
}
@@ -352,15 +330,4 @@ private void processPopupTrigger(MouseEvent e) {
352330

353331
}
354332
}
355-
356-
/**
357-
* Comparator for sorting the selection according to name.
358-
*/
359-
private static class PushToApplicationComparator implements Comparator<PushToApplication> {
360-
361-
@Override
362-
public int compare(PushToApplication one, PushToApplication two) {
363-
return one.getName().compareTo(two.getName());
364-
}
365-
}
366333
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Copyright (C) 2003-2015 JabRef contributors.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation; either version 2 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License along
13+
with this program; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*/
16+
17+
package net.sf.jabref.external.push;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import net.sf.jabref.openoffice.OpenOfficePanel;
23+
24+
public class PushToApplications {
25+
public static final List<PushToApplication> applications;
26+
27+
/**
28+
* Set up the current available choices:
29+
*/
30+
static {
31+
applications = new ArrayList<PushToApplication>();
32+
33+
PushToApplications.applications.add(new PushToLyx());
34+
PushToApplications.applications.add(new PushToEmacs());
35+
PushToApplications.applications.add(new PushToWinEdt());
36+
PushToApplications.applications.add(new PushToLatexEditor());
37+
PushToApplications.applications.add(new PushToVim());
38+
PushToApplications.applications.add(OpenOfficePanel.getInstance());
39+
PushToApplications.applications.add(new PushToTeXstudio());
40+
PushToApplications.applications.add(new PushToTexmaker());
41+
}
42+
}

‎src/main/java/net/sf/jabref/external/PushToEmacs.java ‎src/main/java/net/sf/jabref/external/push/PushToEmacs.java

+60-85
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

1818
import java.io.IOException;
1919
import java.io.InputStream;
@@ -22,107 +22,82 @@
2222

2323
import net.sf.jabref.*;
2424

25-
import com.jgoodies.forms.builder.FormBuilder;
26-
import com.jgoodies.forms.layout.FormLayout;
2725
import net.sf.jabref.gui.BasePanel;
2826
import net.sf.jabref.gui.IconTheme;
29-
import net.sf.jabref.gui.actions.BrowseAction;
3027
import net.sf.jabref.logic.l10n.Localization;
3128
import net.sf.jabref.logic.util.OS;
3229
import net.sf.jabref.model.database.BibtexDatabase;
3330
import net.sf.jabref.model.entry.BibtexEntry;
3431

32+
import org.apache.commons.logging.Log;
33+
import org.apache.commons.logging.LogFactory;
34+
3535
/**
36-
* Created by IntelliJ IDEA.
37-
* User: alver
38-
* Date: Jan 14, 2006
39-
* Time: 4:55:23 PM
36+
* Created by IntelliJ IDEA. User: alver Date: Jan 14, 2006 Time: 4:55:23 PM
4037
*/
41-
public class PushToEmacs implements PushToApplication {
38+
public class PushToEmacs extends AbstractPushToApplication implements PushToApplication {
39+
40+
private static final Log LOGGER = LogFactory.getLog(PushToEmacs.class);
4241

43-
private JPanel settings;
44-
private final JTextField citeCommand = new JTextField(30);
45-
private final JTextField emacsPath = new JTextField(30);
4642
private final JTextField additionalParams = new JTextField(30);
4743
private final JCheckBox useEmacs23 = new JCheckBox();
4844

49-
private boolean couldNotConnect;
50-
private boolean couldNotRunClient;
51-
52-
53-
@Override
54-
public String getName() {
55-
return Localization.lang("Insert selected citations into %0" ,getApplicationName());
56-
}
5745

5846
@Override
5947
public String getApplicationName() {
6048
return "Emacs";
6149
}
6250

63-
@Override
64-
public String getTooltip() {
65-
return Localization.lang("Push to %0", getApplicationName());
66-
}
67-
6851
@Override
6952
public Icon getIcon() {
7053
return IconTheme.getImage("emacs");
7154
}
7255

73-
@Override
74-
public String getKeyStrokeName() {
75-
return "Push to Emacs";
76-
}
77-
7856
@Override
7957
public JPanel getSettingsPanel() {
80-
if (settings == null) {
81-
initSettingsPanel();
82-
}
83-
citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS));
84-
emacsPath.setText(Globals.prefs.get(JabRefPreferences.EMACS_PATH));
8558
additionalParams.setText(Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS));
8659
useEmacs23.setSelected(Globals.prefs.getBoolean(JabRefPreferences.EMACS_23));
87-
return settings;
60+
return super.getSettingsPanel();
8861
}
8962

9063
@Override
9164
public void storeSettings() {
92-
Globals.prefs.put(JabRefPreferences.CITE_COMMAND_EMACS, citeCommand.getText());
93-
Globals.prefs.put(JabRefPreferences.EMACS_PATH, emacsPath.getText());
65+
super.storeSettings();
9466
Globals.prefs.put(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS, additionalParams.getText());
9567
Globals.prefs.putBoolean(JabRefPreferences.EMACS_23, useEmacs23.isSelected());
9668
}
9769

98-
private void initSettingsPanel() {
99-
FormBuilder builder = FormBuilder.create();
100-
builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p, 2dlu, p"));
101-
builder.add(Localization.lang("Path to gnuclient or emacsclient") + ":").xy(1, 1);
102-
builder.add(emacsPath).xy(3,1);
103-
BrowseAction action = BrowseAction.buildForFile(emacsPath);
104-
JButton browse = new JButton(Localization.lang("Browse"));
105-
browse.addActionListener(action);
106-
builder.add(browse).xy(5,1);
70+
@Override
71+
protected void initSettingsPanel() {
72+
super.initSettingsPanel();
73+
builder.appendRows("2dlu, p, 2dlu, p");
10774
builder.add(Localization.lang("Additional parameters") + ":").xy(1, 3);
108-
builder.add(additionalParams).xy(3,3);
75+
builder.add(additionalParams).xy(3, 3);
10976
builder.add(Localization.lang("Use EMACS 23 insertion string") + ":").xy(1, 5);
110-
builder.add(useEmacs23).xy(3,5);
111-
builder.add(Localization.lang("Cite command") + ":").xy(1, 7);
112-
builder.add(citeCommand).xy(3,7);
77+
builder.add(useEmacs23).xy(3, 5);
11378
settings = builder.build();
11479
}
11580

11681
@Override
11782
public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, MetaData metaData) {
11883

11984
couldNotConnect = false;
120-
couldNotRunClient = false;
121-
String command = Globals.prefs.get(JabRefPreferences.EMACS_PATH);
85+
couldNotCall = false;
86+
notDefined = false;
87+
88+
initParameters();
89+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
90+
91+
if ((commandPath == null) || commandPath.trim().isEmpty()) {
92+
notDefined = true;
93+
return;
94+
}
95+
96+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
12297
String[] addParams = Globals.prefs.get(JabRefPreferences.EMACS_ADDITIONAL_PARAMETERS).split(" ");
12398
try {
12499
String[] com = new String[addParams.length + 2];
125-
com[0] = command;
100+
com[0] = commandPath;
126101
System.arraycopy(addParams, 0, com, 1, addParams.length);
127102
String prefix;
128103
String suffix;
@@ -135,19 +110,16 @@ public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String k
135110
}
136111

137112
com[com.length - 1] = OS.WINDOWS ?
138-
// Windows gnuclient escaping:
139-
// java string: "(insert \\\"\\\\cite{Blah2001}\\\")";
140-
// so cmd receives: (insert \"\\cite{Blah2001}\")
141-
// so emacs receives: (insert "\cite{Blah2001}")
142-
prefix.concat("\\\"\\" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS).replaceAll("\\\\", "\\\\\\\\") +
143-
"{" + keys + "}\\\"").concat(suffix)
144-
:
145-
// Linux gnuclient escaping:
146-
// java string: "(insert \"\\\\cite{Blah2001}\")"
147-
// so sh receives: (insert "\\cite{Blah2001}")
148-
// so emacs receives: (insert "\cite{Blah2001}")
149-
prefix.concat("\"" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_EMACS).replaceAll("\\\\", "\\\\\\\\") +
150-
"{" + keys + "}\"").concat(suffix);
113+
// Windows gnuclient escaping:
114+
// java string: "(insert \\\"\\\\cite{Blah2001}\\\")";
115+
// so cmd receives: (insert \"\\cite{Blah2001}\")
116+
// so emacs receives: (insert "\cite{Blah2001}")
117+
prefix.concat("\\\"\\" + citeCommand.replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\\\"").concat(suffix) :
118+
// Linux gnuclient escaping:
119+
// java string: "(insert \"\\\\cite{Blah2001}\")"
120+
// so sh receives: (insert "\\cite{Blah2001}")
121+
// so emacs receives: (insert "\cite{Blah2001}")
122+
prefix.concat("\"" + citeCommand.replaceAll("\\\\", "\\\\\\\\") + "{" + keys + "}\"").concat(suffix);
151123

152124
final Process p = Runtime.getRuntime().exec(com);
153125

@@ -168,46 +140,49 @@ public void run() {
168140
sb.append((char) c);
169141
}
170142
} catch (IOException e) {
171-
e.printStackTrace();
143+
LOGGER.warn("Could not read from stderr.");
172144
}
173145
// Error stream has been closed. See if there were any errors:
174146
if (!sb.toString().trim().isEmpty()) {
175-
System.out.println(sb);
147+
LOGGER.warn("Push to Emacs error: " + sb);
176148
couldNotConnect = true;
177149
}
178150
}
179151
};
180152
JabRefExecutorService.INSTANCE.executeAndWait(errorListener);
181153
} catch (IOException excep) {
182-
couldNotRunClient = true;
154+
couldNotCall = true;
183155
}
184156

185157
}
186158

187159
@Override
188160
public void operationCompleted(BasePanel panel) {
189161
if (couldNotConnect) {
190-
JOptionPane.showMessageDialog(
191-
panel.frame(),
192-
"<HTML>" +
193-
Localization.lang("Could not connect to a running gnuserv process. Make sure that "
194-
+ "Emacs or XEmacs is running,<BR>and that the server has been started "
195-
+ "(by running the command 'server-start'/'gnuserv-start').")
196-
+ "</HTML>",
162+
// @formatter:off
163+
JOptionPane.showMessageDialog(panel.frame(), "<HTML>" +
164+
Localization.lang("Could not connect to a running gnuserv process. Make sure that "
165+
+ "Emacs or XEmacs is running,<BR>and that the server has been started "
166+
+ "(by running the command 'server-start'/'gnuserv-start').") + "</HTML>",
197167
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
198-
} else if (couldNotRunClient) {
199-
JOptionPane.showMessageDialog(
200-
panel.frame(),
168+
} else if (couldNotCall) {
169+
JOptionPane.showMessageDialog(panel.frame(),
201170
Localization.lang("Could not run the gnuclient/emacsclient program. Make sure you have "
202-
+ "the emacsclient/gnuclient program installed and available in the PATH."),
171+
+ "the emacsclient/gnuclient program installed and available in the PATH."),
203172
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
204-
} else {
205-
panel.output(Localization.lang("Pushed citations to %0", getApplicationName()));
173+
// @formatter:on
206174
}
175+
super.operationCompleted(panel);
207176
}
208177

209178
@Override
210-
public boolean requiresBibtexKeys() {
211-
return true;
179+
protected void initParameters() {
180+
commandPathPreferenceKey = JabRefPreferences.EMACS_PATH;
212181
}
182+
183+
@Override
184+
protected String getCommandName() {
185+
return "gnuclient " + Localization.lang("or") + " emacsclient";
186+
}
187+
213188
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright (C) 2003-2015 JabRef contributors.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation; either version 2 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License along
13+
with this program; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*/
16+
package net.sf.jabref.external.push;
17+
18+
import javax.swing.*;
19+
20+
import net.sf.jabref.JabRefPreferences;
21+
import net.sf.jabref.gui.IconTheme;
22+
23+
/**
24+
* Class for pushing entries into LatexEditor.
25+
*/
26+
public class PushToLatexEditor extends AbstractPushToApplication implements PushToApplication {
27+
28+
@Override
29+
public String getApplicationName() {
30+
return "LatexEditor";
31+
}
32+
33+
@Override
34+
public Icon getIcon() {
35+
return IconTheme.getImage("edit");
36+
}
37+
38+
@Override
39+
protected String[] getCommandLine(String keyString) {
40+
return new String[] {commandPath, "-i", citeCommand + "{" + keyString + "}"};
41+
}
42+
43+
@Override
44+
protected String getCommandName() {
45+
return "LEd.exe";
46+
}
47+
48+
@Override
49+
protected void initParameters() {
50+
commandPathPreferenceKey = JabRefPreferences.LATEX_EDITOR_PATH;
51+
}
52+
53+
}

‎src/main/java/net/sf/jabref/external/PushToLyx.java ‎src/main/java/net/sf/jabref/external/push/PushToLyx.java

+57-83
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

1818
import java.io.BufferedWriter;
1919
import java.io.File;
@@ -23,37 +23,78 @@
2323
import javax.swing.*;
2424

2525
import net.sf.jabref.*;
26-
import net.sf.jabref.gui.BasePanel;
2726
import net.sf.jabref.gui.IconTheme;
2827
import net.sf.jabref.logic.l10n.Localization;
2928
import net.sf.jabref.model.database.BibtexDatabase;
3029
import net.sf.jabref.model.entry.BibtexEntry;
3130

32-
public class PushToLyx implements PushToApplication {
31+
public class PushToLyx extends AbstractPushToApplication implements PushToApplication {
3332

34-
private final JTextField lyxPipe = new JTextField(30);
35-
private JPanel settings;
33+
@Override
34+
public String getApplicationName() {
35+
return "LyX/Kile";
36+
}
37+
38+
@Override
39+
public Icon getIcon() {
40+
return IconTheme.getImage("lyx");
41+
}
3642

37-
private boolean couldNotFindPipe;
38-
private boolean couldNotWrite;
43+
@Override
44+
protected void initParameters() {
45+
commandPathPreferenceKey = JabRefPreferences.LYXPIPE;
46+
}
3947

48+
@Override
49+
protected String getCouldNotCall() {
50+
// @formatter:off
51+
return Localization.lang("Error") + ": " +
52+
Localization.lang("unable to write to") + " " + commandPath +
53+
".in";
54+
// @formatter:on
55+
}
56+
57+
@Override
58+
protected String getCouldNotConnect() {
59+
// @formatter:off
60+
return Localization.lang("Error") + ": " +
61+
Localization.lang("verify that LyX is running and that the lyxpipe is valid")
62+
+ ". [" + commandPath + "]";
63+
// @formatter:on
64+
65+
}
66+
67+
@Override
68+
protected void initSettingsPanel() {
69+
settings = new JPanel();
70+
settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":"));
71+
settings.add(Path);
72+
}
4073

4174
@Override
4275
public void pushEntries(BibtexDatabase database, final BibtexEntry[] entries, final String keyString, MetaData metaData) {
4376

44-
couldNotFindPipe = false;
45-
couldNotWrite = false;
77+
couldNotConnect = false;
78+
couldNotCall = false;
79+
notDefined = false;
4680

47-
String lyxpipeSetting = Globals.prefs.get(JabRefPreferences.LYXPIPE);
48-
if (!lyxpipeSetting.endsWith(".in")) {
49-
lyxpipeSetting = lyxpipeSetting + ".in";
81+
initParameters();
82+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
83+
84+
if ((commandPath == null) || commandPath.trim().isEmpty()) {
85+
notDefined = true;
86+
return;
5087
}
51-
File lp = new File(lyxpipeSetting); // this needs to fixed because it gives "asdf" when going prefs.get("lyxpipe")
88+
89+
if (!commandPath.endsWith(".in")) {
90+
commandPath = commandPath + ".in";
91+
}
92+
File lp = new File(commandPath); // this needs to fixed because it gives "asdf" when going prefs.get("lyxpipe")
5293
if (!lp.exists() || !lp.canWrite()) {
5394
// See if it helps to append ".in":
54-
lp = new File(lyxpipeSetting + ".in");
95+
lp = new File(commandPath + ".in");
5596
if (!lp.exists() || !lp.canWrite()) {
56-
couldNotFindPipe = true;
97+
couldNotConnect = true;
5798
return;
5899
}
59100
}
@@ -75,79 +116,12 @@ public void run() {
75116
lyx_out.close();
76117

77118
} catch (IOException excep) {
78-
couldNotWrite = true;
119+
couldNotCall = true;
79120
}
80121
}
81122
});
82123
}
83124

84-
@Override
85-
public String getName() {
86-
return Localization.lang("Insert selected citations into %0" ,getApplicationName());
87-
}
88-
89-
@Override
90-
public String getApplicationName() {
91-
return "LyX/Kile";
92-
}
93-
94-
@Override
95-
public String getTooltip() {
96-
return Localization.lang("Push to %0",getApplicationName());
97-
}
98-
99-
@Override
100-
public Icon getIcon() {
101-
return IconTheme.getImage("lyx");
102-
}
103-
104-
@Override
105-
public String getKeyStrokeName() {
106-
return "Push to LyX";
107-
}
108-
109-
@Override
110-
public void operationCompleted(BasePanel panel) {
111-
if (couldNotFindPipe) {
112-
// @formatter:off
113-
panel.output(Localization.lang("Error") + ": " +
114-
Localization.lang("verify that LyX is running and that the lyxpipe is valid")
115-
+ ". [" + Globals.prefs.get(JabRefPreferences.LYXPIPE) + "]");
116-
} else if (couldNotWrite) {
117-
panel.output(Localization.lang("Error") + ": " +
118-
Localization.lang("unable to write to") + " " + Globals.prefs.get(JabRefPreferences.LYXPIPE) +
119-
".in");
120-
// @formatter:on
121-
} else {
122-
panel.output(Localization.lang("Pushed citations to %0", getApplicationName()));
123-
}
124-
125-
}
126-
127-
@Override
128-
public boolean requiresBibtexKeys() {
129-
return true;
130-
}
131-
132-
@Override
133-
public JPanel getSettingsPanel() {
134-
if (settings == null) {
135-
initSettingsPanel();
136-
}
137-
lyxPipe.setText(Globals.prefs.get(JabRefPreferences.LYXPIPE));
138-
return settings;
139-
}
140-
141-
@Override
142-
public void storeSettings() {
143-
Globals.prefs.put(JabRefPreferences.LYXPIPE, lyxPipe.getText());
144-
}
145-
146-
private void initSettingsPanel() {
147-
settings = new JPanel();
148-
settings.add(new JLabel(Localization.lang("Path to LyX pipe") + ":"));
149-
settings.add(lyxPipe);
150-
}
151125
/*class Timeout extends javax.swing.Timer
152126
{
153127
public Timeout(int timeout, final Thread toStop, final String message) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Copyright (C) 2003-2015 JabRef contributors.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation; either version 2 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License along
13+
with this program; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*/
16+
package net.sf.jabref.external.push;
17+
18+
import javax.swing.*;
19+
20+
import net.sf.jabref.gui.IconTheme;
21+
import net.sf.jabref.JabRefPreferences;
22+
23+
/**
24+
* Created by IntelliJ IDEA. User: alver Date: Jan 14, 2006 Time: 4:55:23 PM To change this template use File | Settings
25+
* | File Templates.
26+
*/
27+
public class PushToTeXstudio extends AbstractPushToApplication implements PushToApplication {
28+
29+
@Override
30+
public String getApplicationName() {
31+
return "TeXstudio";
32+
}
33+
34+
@Override
35+
public Icon getIcon() {
36+
return IconTheme.getImage("texstudio");
37+
}
38+
39+
@Override
40+
protected String[] getCommandLine(String keyString) {
41+
return new String[] {commandPath, "--insert-cite", keyString};
42+
}
43+
44+
@Override
45+
protected void initParameters() {
46+
commandPathPreferenceKey = JabRefPreferences.TEXSTUDIO_PATH;
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (C) 2015 JabRef contributors.
2+
Copyright (C) 2015 Oscar Gustafsson.
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; either version 2 of the License, or
6+
(at your option) any later version.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License along
14+
with this program; if not, write to the Free Software Foundation, Inc.,
15+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16+
*/
17+
package net.sf.jabref.external.push;
18+
19+
import javax.swing.*;
20+
21+
import net.sf.jabref.JabRefPreferences;
22+
import net.sf.jabref.gui.IconTheme;
23+
24+
/**
25+
* Class for pushing entries into TexMaker.
26+
*/
27+
public class PushToTexmaker extends AbstractPushToApplication implements PushToApplication {
28+
29+
@Override
30+
public String getApplicationName() {
31+
return "Texmaker";
32+
}
33+
34+
@Override
35+
public Icon getIcon() {
36+
return IconTheme.getImage("texmaker");
37+
}
38+
39+
@Override
40+
protected String[] getCommandLine(String keyString) {
41+
return new String[] {commandPath, "-insert", citeCommand + "{" + keyString + "}"};
42+
}
43+
44+
@Override
45+
protected void initParameters() {
46+
commandPathPreferenceKey = JabRefPreferences.TEXMAKER_PATH;
47+
}
48+
49+
}

‎src/main/java/net/sf/jabref/external/PushToVim.java ‎src/main/java/net/sf/jabref/external/push/PushToVim.java

+42-66
Original file line numberDiff line numberDiff line change
@@ -13,114 +13,88 @@
1313
with this program; if not, write to the Free Software Foundation, Inc.,
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1515
*/
16-
package net.sf.jabref.external;
16+
package net.sf.jabref.external.push;
1717

18-
import com.jgoodies.forms.builder.FormBuilder;
19-
import com.jgoodies.forms.layout.FormLayout;
2018
import net.sf.jabref.*;
2119
import net.sf.jabref.gui.BasePanel;
2220
import net.sf.jabref.gui.IconTheme;
23-
import net.sf.jabref.gui.actions.BrowseAction;
2421
import net.sf.jabref.logic.l10n.Localization;
2522
import net.sf.jabref.model.database.BibtexDatabase;
2623
import net.sf.jabref.model.entry.BibtexEntry;
2724

2825
import javax.swing.*;
26+
27+
import org.apache.commons.logging.Log;
28+
import org.apache.commons.logging.LogFactory;
29+
2930
import java.io.IOException;
3031
import java.io.InputStream;
3132

3233
/**
33-
* Created by IntelliJ IDEA.
34-
* User: alver
35-
* Date: Mar 7, 2007
36-
* Time: 6:55:56 PM
37-
* To change this template use File | Settings | File Templates.
34+
* Created by IntelliJ IDEA. User: alver Date: Mar 7, 2007 Time: 6:55:56 PM To change this template use File | Settings
35+
* | File Templates.
3836
*/
39-
public class PushToVim implements PushToApplication {
40-
41-
private JPanel settings;
42-
private final JTextField vimPath = new JTextField(30);
43-
private final JTextField vimServer = new JTextField(30);
44-
private final JTextField citeCommand = new JTextField(30);
37+
public class PushToVim extends AbstractPushToApplication implements PushToApplication {
4538

46-
private boolean couldNotConnect;
47-
private boolean couldNotRunClient;
39+
private static final Log LOGGER = LogFactory.getLog(PushToEmacs.class);
4840

41+
private final JTextField vimServer = new JTextField(30);
4942

50-
@Override
51-
public String getName() {
52-
return Localization.lang("Insert selected citations into %0" ,getApplicationName());
53-
}
5443

5544
@Override
5645
public String getApplicationName() {
5746
return "Vim";
5847
}
5948

60-
@Override
61-
public String getTooltip() {
62-
return Localization.lang("Push to %0", getApplicationName());
63-
}
64-
6549
@Override
6650
public Icon getIcon() {
6751
return IconTheme.getImage("vim");
6852
}
6953

70-
@Override
71-
public String getKeyStrokeName() {
72-
return null;
73-
}
74-
7554
@Override
7655
public JPanel getSettingsPanel() {
77-
if (settings == null) {
78-
initSettingsPanel();
79-
}
80-
vimPath.setText(Globals.prefs.get(JabRefPreferences.VIM));
8156
vimServer.setText(Globals.prefs.get(JabRefPreferences.VIM_SERVER));
82-
citeCommand.setText(Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM));
83-
return settings;
57+
return super.getSettingsPanel();
8458
}
8559

8660
@Override
8761
public void storeSettings() {
88-
Globals.prefs.put(JabRefPreferences.VIM, vimPath.getText());
62+
super.storeSettings();
8963
Globals.prefs.put(JabRefPreferences.VIM_SERVER, vimServer.getText());
90-
Globals.prefs.put(JabRefPreferences.CITE_COMMAND_VIM, citeCommand.getText());
9164
}
9265

93-
private void initSettingsPanel() {
94-
FormBuilder builder = FormBuilder.create();
95-
builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p"));
96-
builder.add(Localization.lang("Path to %0", getApplicationName()) + ":").xy(1, 1);
97-
builder.add(vimPath).xy(3,1);
98-
BrowseAction action = BrowseAction.buildForFile(vimPath);
99-
JButton browse = new JButton(Localization.lang("Browse"));
100-
browse.addActionListener(action);
101-
builder.add(browse).xy(5,1);
66+
@Override
67+
protected void initSettingsPanel() {
68+
super.initSettingsPanel();
69+
builder.appendRows("2dlu, p");
10270
builder.add(Localization.lang("Vim Server Name") + ":").xy(1, 3);
103-
builder.add(vimServer).xy(3,3);
104-
builder.add(Localization.lang("Cite command") + ":").xy(1, 5);
105-
builder.add(citeCommand).xy(3,5);
71+
builder.add(vimServer).xy(3, 3);
10672
settings = builder.build();
10773
}
10874

10975
@Override
110-
public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys,
111-
MetaData metaData) {
76+
public void pushEntries(BibtexDatabase database, BibtexEntry[] entries, String keys, MetaData metaData) {
11277

11378
couldNotConnect = false;
114-
couldNotRunClient = false;
79+
couldNotCall = false;
80+
notDefined = false;
81+
82+
initParameters();
83+
commandPath = Globals.prefs.get(commandPathPreferenceKey);
84+
85+
if ((commandPath == null) || commandPath.trim().isEmpty()) {
86+
notDefined = true;
87+
return;
88+
}
89+
11590
try {
11691
// @formatter:off
117-
String[] com = new String[] {Globals.prefs.get(JabRefPreferences.VIM), "--servername",
92+
String[] com = new String[] {commandPath, "--servername",
11893
Globals.prefs.get(JabRefPreferences.VIM_SERVER), "--remote-send",
119-
"<C-\\><C-N>a" + Globals.prefs.get(JabRefPreferences.CITE_COMMAND_VIM) +
94+
"<C-\\><C-N>a" + citeCommand +
12095
"{" + keys + "}"};
12196
// @formatter:on
12297

123-
12498
final Process p = Runtime.getRuntime().exec(com);
12599

126100
Runnable errorListener = new Runnable() {
@@ -135,44 +109,46 @@ public void run() {
135109
sb.append((char) c);
136110
}
137111
} catch (IOException e) {
138-
e.printStackTrace();
112+
LOGGER.warn("Could not read from stderr.");
139113
}
140114
// Error stream has been closed. See if there were any errors:
141115
if (!sb.toString().trim().isEmpty()) {
142-
System.out.println(sb);
116+
LOGGER.warn("Push to Emacs error: " + sb);
143117
couldNotConnect = true;
144118
}
145119
}
146120
};
147121
JabRefExecutorService.INSTANCE.executeAndWait(errorListener);
148122
} catch (IOException excep) {
149-
couldNotRunClient = true;
123+
couldNotCall = true;
150124
}
151125

152126
}
153127

154128
@Override
155129
public void operationCompleted(BasePanel panel) {
156130
if (couldNotConnect) {
131+
// @formatter:off
157132
JOptionPane.showMessageDialog(
158133
panel.frame(),
159134
"<HTML>" +
160135
Localization.lang("Could not connect to Vim server. Make sure that "
161136
+ "Vim is running<BR>with correct server name.")
162137
+ "</HTML>",
163138
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
164-
} else if (couldNotRunClient) {
139+
} else if (couldNotCall) {
165140
JOptionPane.showMessageDialog(
166141
panel.frame(),
167142
Localization.lang("Could not run the 'vim' program."),
168143
Localization.lang("Error"), JOptionPane.ERROR_MESSAGE);
169-
} else {
170-
panel.output(Localization.lang("Pushed citations to %0",getApplicationName()));
144+
// formatter:on
171145
}
146+
super.operationCompleted(panel);
172147
}
173-
148+
174149
@Override
175-
public boolean requiresBibtexKeys() {
176-
return true;
150+
protected void initParameters() {
151+
commandPathPreferenceKey = JabRefPreferences.VIM;
177152
}
153+
178154
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (C) 2003-2015 JabRef contributors.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU General Public License as published by
4+
the Free Software Foundation; either version 2 of the License, or
5+
(at your option) any later version.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License along
13+
with this program; if not, write to the Free Software Foundation, Inc.,
14+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15+
*/
16+
package net.sf.jabref.external.push;
17+
18+
import javax.swing.*;
19+
20+
import net.sf.jabref.JabRefPreferences;
21+
import net.sf.jabref.gui.IconTheme;
22+
23+
public class PushToWinEdt extends AbstractPushToApplication implements PushToApplication {
24+
25+
@Override
26+
public String getApplicationName() {
27+
return "WinEdt";
28+
}
29+
30+
@Override
31+
public Icon getIcon() {
32+
return IconTheme.getImage("winedt");
33+
}
34+
35+
@Override
36+
protected String[] getCommandLine(String keyString) {
37+
return new String[] {commandPath, "\"[InsText('" + citeCommand + "{" + keyString.replaceAll("'", "''") + "}');]\""};
38+
}
39+
40+
@Override
41+
protected void initParameters() {
42+
commandPathPreferenceKey = JabRefPreferences.WIN_EDT_PATH;
43+
}
44+
}

‎src/main/java/net/sf/jabref/gui/JabRefFrame.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
import net.sf.jabref.exporter.SaveAllAction;
7474
import net.sf.jabref.exporter.SaveDatabaseAction;
7575
import net.sf.jabref.external.ExternalFileTypeEditor;
76-
import net.sf.jabref.external.PushToApplicationButton;
76+
import net.sf.jabref.external.push.PushToApplicationButton;
77+
import net.sf.jabref.external.push.PushToApplications;
7778
import net.sf.jabref.groups.EntryTableTransferHandler;
7879
import net.sf.jabref.groups.GroupSelector;
7980
import net.sf.jabref.gui.menus.help.ForkMeOnGitHubAction;
@@ -908,7 +909,7 @@ private void initLayout() {
908909
setProgressBarVisible(false);
909910

910911
pushExternalButton = new PushToApplicationButton(this,
911-
PushToApplicationButton.applications);
912+
PushToApplications.applications);
912913
fillMenu();
913914
createToolBar();
914915
getContentPane().setLayout(gbl);

‎src/main/java/net/sf/jabref/gui/preftabs/ExternalTab.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import javax.swing.event.ChangeListener;
2727

2828
import net.sf.jabref.*;
29-
import net.sf.jabref.external.*;
29+
import net.sf.jabref.external.ExternalFileTypeEditor;
30+
import net.sf.jabref.external.push.*;
3031
import net.sf.jabref.gui.GUIGlobals;
3132
import net.sf.jabref.gui.IconTheme;
3233
import net.sf.jabref.gui.JabRefFrame;
@@ -49,6 +50,7 @@ class ExternalTab extends JPanel implements PrefsTab {
4950
private final JTextField fileDir;
5051
private final JTextField psDir;
5152
private final JTextField emailSubject;
53+
private final JTextField citeCommand;
5254

5355
private final JCheckBox bibLocationAsFileDir;
5456
private final JCheckBox bibLocAsPrimaryDir;
@@ -84,10 +86,12 @@ public void stateChanged(ChangeEvent changeEvent) {
8486
JButton editFileTypes = new JButton(Localization.lang("Manage external file types"));
8587
runAutoFileSearch = new JCheckBox(Localization.lang("When opening file link, search for matching file if no link is defined"));
8688
allowFileAutoOpenBrowse = new JCheckBox(Localization.lang("Automatically open browse dialog when creating new file link"));
89+
citeCommand = new JTextField(25);
8790
regExpTextField = new JTextField(25);
8891
useRegExpComboBox = new JRadioButton(Localization.lang("Use Regular Expression Search"));
8992
ItemListener regExpListener = new ItemListener() {
9093

94+
9195
@Override
9296
public void itemStateChanged(ItemEvent e) {
9397
regExpTextField.setEditable(useRegExpComboBox.isSelected());
@@ -204,6 +208,12 @@ public void itemStateChanged(ItemEvent e) {
204208
builder.append(new JPanel());
205209
builder.append(butpan, 3);
206210

211+
builder.nextLine();
212+
lab = new JLabel(Localization.lang("Cite command") + ':');
213+
builder.append(pan);
214+
builder.append(lab);
215+
builder.append(citeCommand);
216+
207217
builder.nextLine();
208218
builder.append(pan);
209219
builder.append(editFileTypes);
@@ -242,6 +252,8 @@ public void setValues() {
242252
emailSubject.setText(prefs.get(JabRefPreferences.EMAIL_SUBJECT));
243253
openFoldersOfAttachedFiles.setSelected(prefs.getBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES));
244254

255+
citeCommand.setText(prefs.get(JabRefPreferences.CITE_COMMAND));
256+
245257
if (prefs.getBoolean(JabRefPreferences.AUTOLINK_USE_REG_EXP_SEARCH_KEY)) {
246258
useRegExpComboBox.setSelected(true);
247259
} else if (prefs.getBoolean(JabRefPreferences.AUTOLINK_EXACT_KEY_ONLY)) {
@@ -270,6 +282,7 @@ public void storeSettings() {
270282
prefs.putBoolean(JabRefPreferences.ALLOW_FILE_AUTO_OPEN_BROWSE, allowFileAutoOpenBrowse.isSelected());
271283
prefs.put(JabRefPreferences.EMAIL_SUBJECT, emailSubject.getText());
272284
prefs.putBoolean(JabRefPreferences.OPEN_FOLDERS_OF_ATTACHED_FILES, openFoldersOfAttachedFiles.isSelected());
285+
prefs.put(JabRefPreferences.CITE_COMMAND, citeCommand.getText());
273286
}
274287

275288
@Override

‎src/main/java/net/sf/jabref/logic/util/OS.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,27 @@ public class OS {
88
// https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/SystemUtils.html
99
public static final String osName = System.getProperty("os.name", "unknown").toLowerCase();
1010

11-
public static final boolean LINUX = osName.startsWith("linux");
12-
public static final boolean WINDOWS = osName.startsWith("win");
13-
public static final boolean OS_X = osName.startsWith("mac");
11+
public static final boolean LINUX = OS.osName.startsWith("linux");
12+
public static final boolean WINDOWS = OS.osName.startsWith("win");
13+
public static final boolean OS_X = OS.osName.startsWith("mac");
14+
15+
public static final String guessProgramPath(String programName, String windowsDirectory) {
16+
if (OS.WINDOWS) {
17+
String progFiles = System.getenv("ProgramFiles(x86)");
18+
if (progFiles == null) {
19+
progFiles = System.getenv("ProgramFiles");
20+
}
21+
if ((windowsDirectory != null) && !windowsDirectory.isEmpty()) {
22+
return progFiles + "\\" + windowsDirectory + "\\" + programName + ".exe";
23+
} else {
24+
return progFiles + "\\" + programName + ".exe";
25+
}
26+
} else {
27+
return programName;
28+
}
29+
}
30+
31+
public static final String guessProgramPath(String programName) {
32+
return OS.guessProgramPath(programName, null);
33+
}
1434
}

‎src/main/java/net/sf/jabref/openoffice/OpenOfficePanel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import net.sf.jabref.*;
2222
import net.sf.jabref.exporter.layout.Layout;
2323
import net.sf.jabref.exporter.layout.LayoutHelper;
24-
import net.sf.jabref.external.PushToApplication;
24+
import net.sf.jabref.external.push.PushToApplication;
2525
import net.sf.jabref.gui.*;
2626
import net.sf.jabref.gui.worker.AbstractWorker;
2727
import net.sf.jabref.gui.actions.BrowseAction;

0 commit comments

Comments
 (0)
Please sign in to comment.