Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cite entries without a key in OpenOffice/LibreOffice (#1682) #1683

Merged
merged 2 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Fixed [#1643](https://github.com/JabRef/jabref/issues/1643): Searching with double quotes in a specific field ignores the last character
- Fixed [#1288](https://github.com/JabRef/jabref/issues/1288): Newly opened bib-file is not focused
- Fixed [#1669](https://github.com/JabRef/jabref/issues/1669): Dialog for manual connection to OpenOffice/LibreOffice works again on Linux
- Fixed [#16682](https://github.com/JabRef/jabref/issues/1682): An entry now must have a BibTeX key to be cited in OpenOffice/LibreOffice


### Removed
Expand Down
60 changes: 59 additions & 1 deletion src/main/java/net/sf/jabref/gui/openoffice/OpenOfficePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@
import net.sf.jabref.gui.actions.BrowseAction;
import net.sf.jabref.gui.help.HelpAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableKeyChange;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.help.HelpFile;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.LabelPatternPreferences;
import net.sf.jabref.logic.labelpattern.LabelPatternUtil;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.openoffice.OOBibStyle;
import net.sf.jabref.logic.openoffice.OpenOfficePreferences;
Expand Down Expand Up @@ -638,7 +642,8 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP
if (panel != null) {
final BibDatabase database = panel.getDatabase();
List<BibEntry> entries = panel.getSelectedEntries();
if (!entries.isEmpty()) {
if (!entries.isEmpty() && checkThatEntriesHaveKeys(entries)) {

try {
if (style == null) {
style = loader.getUsedStyle();
Expand Down Expand Up @@ -669,6 +674,59 @@ private void pushEntries(boolean inParenthesisIn, boolean withText, boolean addP

}

/**
* Check that all entries in the list have BibTeX keys, if not ask if they should be generated
*
* @param entries A list of entries to be checked
* @return true if all entries have BibTeX keys, if it so may be after generating them
*/
private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) {
// Check if there are empty keys
boolean emptyKeys = false;
for (BibEntry entry : entries) {
if (entry.getCiteKey() == null) {
// Found one, no need to look further for now
emptyKeys = true;
break;
}
}

// If no empty keys, return true
if (!emptyKeys) {
return true;
}

// Ask if keys should be generated
String[] options = {Localization.lang("Generate keys"), Localization.lang("Cancel")};
int answer = JOptionPane.showOptionDialog(this.frame,
Localization.lang("Cannot cite entries without BibTeX keys. Generate keys now?"),
Localization.lang("Cite"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options,
null);
BasePanel panel = frame.getCurrentBasePanel();
if ((answer == JOptionPane.OK_OPTION) && (panel != null)) {
// Generate keys
LabelPatternPreferences prefs = LabelPatternPreferences.fromPreferences(Globals.prefs);
NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite"));
for (BibEntry entry : entries) {
if (entry.getCiteKey() == null) {
// Generate key
LabelPatternUtil.makeLabel(panel.getBibDatabaseContext().getMetaData(), panel.getDatabase(), entry,
prefs);
// Add undo change
undoCompound.addEdit(new UndoableKeyChange(panel.getDatabase(), entry, null, entry.getCiteKey()));
}
}
undoCompound.end();
// Add all undos
panel.getUndoManager().addEdit(undoCompound);
// Now every entry has a key
return true;
} else {
// No, we canceled (or there is no panel to get the database from, highly unlikely)
return false;
}
}

private void showConnectionLostErrorMessage() {
JOptionPane.showMessageDialog(frame,
Localization.lang("Connection to OpenOffice/LibreOffice has been lost. "
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1740,3 +1740,5 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=

3 changes: 2 additions & 1 deletion src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,6 @@ Add_{}_around_selected_text=
Format_field=
New_protected_terms_file=


change_field_%0_of_entry_%1_from_%2_to_%3=
change_key_from_%0_to_%1=
change_string_content_%0_to_%1=
Expand All @@ -2421,6 +2420,7 @@ Entry_from_%0=Eintrag_basierend_auf_%0

Merge_entry_with_%0_information=Eintrag_mit_%0-Informationen_zusammenführen
Updated_entry_with_info_from_%0=Eintrag_wurde_mit_%0-Information_aktualisiert.

Connection=Verbindung
Host=Host
Port=Port
Expand Down Expand Up @@ -2455,3 +2455,4 @@ Shared_version\:_%0=Gemainsam_genutzte_Version\:_%0
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=Bitte_führen_Sie_den_gemeinsam_genutzten_Eintrag_mit_Ihrem_zusammen_und_klicken_Sie_auf_"Einträge_zuammenführen",_um_das_Problem_zu_beheben.
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=Durch_einen_Abbruch_dieser_Operation_werden_die_Änderungen_nicht_synchronisiert._Trotzdem_abbrechen?
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=Der_Eintrag,_welchen_Sie_zur_Zeit_bearbeiten,_ist_auf_der_gemeinsam_genutzen_Datenbank_nicht_mehr_vorhanden._Klicken_Sie_auf_"Behalten",_um_den_Eintrag_wiederherzustellen.
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2284,3 +2284,4 @@ Shared_version\:_%0=Shared_version\:_%0
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1642,3 +1642,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2423,3 +2423,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1683,3 +1683,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,6 @@ Add_{}_around_selected_text=
Format_field=
New_protected_terms_file=


change_field_%0_of_entry_%1_from_%2_to_%3=
change_key_from_%0_to_%1=
change_string_content_%0_to_%1=
Expand Down Expand Up @@ -1659,3 +1658,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1759,3 +1759,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2400,3 +2400,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,6 @@ Add_{}_around_selected_text=
Format_field=
New_protected_terms_file=


change_field_%0_of_entry_%1_from_%2_to_%3=
change_key_from_%0_to_%1=
change_string_content_%0_to_%1=
Expand Down Expand Up @@ -2433,3 +2432,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2773,7 +2773,6 @@ Add_{}_around_selected_text=
Format_field=
New_protected_terms_file=


change_field_%0_of_entry_%1_from_%2_to_%3=
change_key_from_%0_to_%1=
change_string_content_%0_to_%1=
Expand Down Expand Up @@ -2825,3 +2824,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1655,3 +1655,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2401,3 +2401,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1600,3 +1600,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=Kan_inte_citera_poster_utan_BibTeX-nycklar._Generera_nycklar_nu?
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1673,3 +1673,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_vi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2427,3 +2427,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,6 @@ Add_{}_around_selected_text=
Format_field=
New_protected_terms_file=


change_field_%0_of_entry_%1_from_%2_to_%3=
change_key_from_%0_to_%1=
change_string_content_%0_to_%1=
Expand Down Expand Up @@ -1668,3 +1667,4 @@ Shared_version\:_%0=
Please_merge_the_shared_entry_with_yours_and_press_"Merge_entries"_to_resolve_this_problem.=
Canceling_this_operation_will_leave_your_changes_unsynchronized._Cancel_anyway?=
The_BibEntry_you_currently_work_on_has_been_deleted_on_the_shared_side._Hit_"Keep"_to_recover_the_entry.=
Cannot_cite_entries_without_BibTeX_keys._Generate_keys_now?=