-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
OO Maintenance: Better checks, clean up dead code, refactoring #11779
Changes from 4 commits
150603c
d21a455
041bf02
3dd04a4
f759087
985c9a8
cb1bcc8
073d550
7958e7d
68233dd
6594375
a913ebe
6131662
2e77921
9e76718
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,8 +128,8 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, | |
this.stateManager = stateManager; | ||
this.clipBoardManager = clipBoardManager; | ||
this.undoManager = undoManager; | ||
this.currentStyle = preferences.getOpenOfficePreferences().getCurrentStyle(); | ||
this.openOfficePreferences = preferences.getOpenOfficePreferences(); | ||
this.currentStyle = openOfficePreferences.getCurrentStyle(); | ||
|
||
ActionFactory factory = new ActionFactory(); | ||
|
||
|
@@ -157,7 +157,7 @@ public OpenOfficePanel(LibraryTabContainer tabContainer, | |
update.setMaxWidth(Double.MAX_VALUE); | ||
|
||
loader = new StyleLoader( | ||
preferences.getOpenOfficePreferences(), | ||
openOfficePreferences, | ||
preferences.getLayoutFormatterPreferences(), | ||
abbreviationRepository); | ||
|
||
|
@@ -327,7 +327,7 @@ private void exportEntries() { | |
|
||
private List<BibDatabase> getBaseList() { | ||
List<BibDatabase> databases = new ArrayList<>(); | ||
if (preferences.getOpenOfficePreferences().getUseAllDatabases()) { | ||
if (openOfficePreferences.getUseAllDatabases()) { | ||
for (BibDatabaseContext database : stateManager.getOpenDatabases()) { | ||
databases.add(database.getDatabase()); | ||
} | ||
|
@@ -341,7 +341,7 @@ private List<BibDatabase> getBaseList() { | |
} | ||
|
||
private void connectAutomatically() { | ||
DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(preferences.getOpenOfficePreferences(), dialogService); | ||
DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService); | ||
|
||
if (officeInstallation.isExecutablePathDefined()) { | ||
connect(); | ||
|
@@ -375,7 +375,7 @@ private void connectManually() { | |
var fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build(); | ||
Optional<Path> selectedPath = dialogService.showDirectorySelectionDialog(fileDialogConfiguration); | ||
|
||
DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(preferences.getOpenOfficePreferences(), dialogService); | ||
DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService); | ||
|
||
if (selectedPath.isPresent()) { | ||
BackgroundTask.wrap(() -> officeInstallation.setOpenOfficePreferences(selectedPath.get())) | ||
|
@@ -397,28 +397,20 @@ private void updateButtonAvailability() { | |
boolean isConnected = ooBase != null; | ||
boolean isConnectedToDocument = isConnected && !ooBase.isDocumentConnectionMissing(); | ||
|
||
// For these, we need to watch something | ||
boolean hasStyle = true; // (style != null); | ||
boolean hasDatabase = true; // !getBaseList().isEmpty(); | ||
boolean hasSelectedBibEntry = true; | ||
|
||
selectDocument.setDisable(!isConnected); | ||
pushEntries.setDisable(!(isConnectedToDocument && hasStyle && hasDatabase)); | ||
pushEntries.setDisable(!isConnectedToDocument); | ||
|
||
boolean canCite = isConnectedToDocument && hasStyle && hasSelectedBibEntry; | ||
boolean cslStyleSelected = preferences.getOpenOfficePreferences().getCurrentStyle() instanceof CitationStyle; | ||
pushEntriesInt.setDisable(!canCite); | ||
pushEntriesEmpty.setDisable(!canCite); | ||
pushEntriesAdvanced.setDisable(!canCite || cslStyleSelected); | ||
boolean cslStyleSelected = openOfficePreferences.getCurrentStyle() instanceof CitationStyle; | ||
pushEntriesInt.setDisable(!isConnectedToDocument); | ||
pushEntriesEmpty.setDisable(!isConnectedToDocument); | ||
pushEntriesAdvanced.setDisable(!isConnectedToDocument || cslStyleSelected); | ||
|
||
boolean canRefreshDocument = isConnectedToDocument && hasStyle; | ||
update.setDisable(!isConnectedToDocument); | ||
merge.setDisable(!isConnectedToDocument || cslStyleSelected); | ||
unmerge.setDisable(!isConnectedToDocument || cslStyleSelected); | ||
manageCitations.setDisable(!isConnectedToDocument || cslStyleSelected); | ||
|
||
update.setDisable(!canRefreshDocument); | ||
merge.setDisable(!canRefreshDocument || cslStyleSelected); | ||
unmerge.setDisable(!canRefreshDocument || cslStyleSelected); | ||
manageCitations.setDisable(!canRefreshDocument || cslStyleSelected); | ||
|
||
exportCitations.setDisable(!(isConnectedToDocument && hasDatabase) || cslStyleSelected); | ||
exportCitations.setDisable(!isConnectedToDocument || cslStyleSelected); | ||
} | ||
|
||
private void connect() { | ||
|
@@ -427,7 +419,7 @@ private void connect() { | |
protected OOBibBase call() throws BootstrapException, CreationException { | ||
updateProgress(ProgressBar.INDETERMINATE_PROGRESS, ProgressBar.INDETERMINATE_PROGRESS); | ||
|
||
Path path = Path.of(preferences.getOpenOfficePreferences().getExecutablePath()); | ||
Path path = Path.of(openOfficePreferences.getExecutablePath()); | ||
return createBibBase(path); | ||
} | ||
}; | ||
|
@@ -451,13 +443,13 @@ protected OOBibBase call() throws BootstrapException, CreationException { | |
LOGGER.error("autodetect failed", ex); | ||
switch (ex) { | ||
case UnsatisfiedLinkError unsatisfiedLinkError -> { | ||
LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); | ||
LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", unsatisfiedLinkError); | ||
|
||
dialogService.showErrorDialogAndWait(Localization.lang("Unable to connect. One possible reason is that JabRef " | ||
+ "and OpenOffice/LibreOffice are not both running in either 32 bit mode or 64 bit mode.")); | ||
} | ||
case IOException ioException -> { | ||
LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ex); | ||
LOGGER.warn("Could not connect to running OpenOffice/LibreOffice", ioException); | ||
|
||
dialogService.showErrorDialogAndWait(Localization.lang("Could not connect to running OpenOffice/LibreOffice."), | ||
Localization.lang("Could not connect to running OpenOffice/LibreOffice.") | ||
|
@@ -511,12 +503,6 @@ private void pushEntries(CitationType citationType, boolean addPageInfo) { | |
} | ||
|
||
final BibDatabaseContext bibDatabaseContext = stateManager.getActiveDatabase().get(); | ||
if (bibDatabaseContext == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future: It is ok to add Example:
OK, one needs to add The long discussion at https://stackoverflow.com/q/2758224/873282 says: do something else, but I like assertions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, will follow that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. At the time of the code. But what if there is a future refactoring. One could argue that the whole research of pre- and post conditions is useless, because the author was sure at when writing the code 🤣🤣 This kind of code (or JSpecify annitations are useful for working on the code at a later point of time. To avoid regressions. Side track: Another tool for avoiding regressions is OpenFastTrace - see https://devdocs.jabref.org/requirements/ for details ^^. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it is to ensure the precondition, it is better to revert this change and use the dedicated error dialog instead of using an internal assertion. Will be updated in latest commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checks for empty database and databasecontext merged in (updated) lines 509-515. |
||
OOError.noDataBaseIsOpenForCiting() | ||
.setTitle(errorDialogTitle) | ||
.showErrorDialog(dialogService); | ||
return; | ||
} | ||
|
||
List<BibEntry> entries = stateManager.getSelectedEntries(); | ||
if (entries.isEmpty()) { | ||
|
@@ -553,12 +539,12 @@ private void pushEntries(CitationType citationType, boolean addPageInfo) { | |
} | ||
|
||
Optional<Update.SyncOptions> syncOptions = | ||
preferences.getOpenOfficePreferences().getSyncWhenCiting() | ||
openOfficePreferences.getSyncWhenCiting() | ||
? Optional.of(new Update.SyncOptions(getBaseList())) | ||
: Optional.empty(); | ||
|
||
// Sync options are non-null only when "Automatically sync bibliography when inserting citations" is enabled | ||
if (syncOptions.isPresent() && preferences.getOpenOfficePreferences().getSyncWhenCiting()) { | ||
if (syncOptions.isPresent() && openOfficePreferences.getSyncWhenCiting()) { | ||
syncOptions.get().setUpdateBibliography(true); | ||
} | ||
ooBase.guiActionInsertEntry(entries, | ||
|
@@ -601,12 +587,12 @@ private boolean checkThatEntriesHaveKeys(List<BibEntry> entries) { | |
Optional<BibDatabaseContext> databaseContext = stateManager.getActiveDatabase(); | ||
if (citePressed && databaseContext.isPresent()) { | ||
// Generate keys | ||
CitationKeyPatternPreferences prefs = preferences.getCitationKeyPatternPreferences(); | ||
CitationKeyPatternPreferences citationKeyPatternPreferences = preferences.getCitationKeyPatternPreferences(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, you can have these passed in the constructor - and get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be the ideal level of abstraction, but Reason for moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @koppor I tried to clean it up a bit further by passing all the preference subtypes via constructor. Although I couldn't get rid of Advantage (imo) - more inversion of control (gets rid of all getters). |
||
NamedCompound undoCompound = new NamedCompound(Localization.lang("Cite")); | ||
for (BibEntry entry : entries) { | ||
if (entry.getCitationKey().isEmpty()) { | ||
// Generate key | ||
new CitationKeyGenerator(databaseContext.get(), prefs) | ||
new CitationKeyGenerator(databaseContext.get(), citationKeyPatternPreferences) | ||
.generateAndSetKey(entry) | ||
.ifPresent(change -> undoCompound.addEdit(new UndoableKeyChange(change))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two comments (non-null check / isEmpty) are typical
assert
statements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay wait, don't merge yet, I'll see if I can put those conditions/assertions (replacing
style
->currentStyle
) instead of complete removal. I don't know if there were reasons these were commented and true was hardcoded.