-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix issue #9306: Move "Open only one instance of JabRef" preference option to somewhere else #10602
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
25409d9
Fix issue #9306: Move "Open only one instance of JabRef" preference o…
DiamondMyK 1590aee
edit issue#9306
DiamondMyK 8871338
Merge branch 'main' into move
DiamondMyK cc086b1
edit
DiamondMyK 23234b1
Merge branch 'move' of github.com:DiamondMyK/jabref into move
DiamondMyK 2a80d39
edit
DiamondMyK f648e50
edit
DiamondMyK ab974d6
edit
DiamondMyK 67af5e5
edit
DiamondMyK bf9ec9d
edit
DiamondMyK f0af57e
edit
DiamondMyK 14f9421
fix trustStoreManager NullPointerException
DiamondMyK e7b96c6
use one action factory
Siedlerchr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import javafx.beans.property.BooleanProperty; | ||
import javafx.beans.property.ListProperty; | ||
|
@@ -19,18 +20,26 @@ | |
import javafx.scene.control.SpinnerValueFactory; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.Globals; | ||
import org.jabref.gui.desktop.JabRefDesktop; | ||
import org.jabref.gui.preferences.PreferenceTabViewModel; | ||
import org.jabref.gui.remote.CLIMessageHandler; | ||
import org.jabref.gui.theme.Theme; | ||
import org.jabref.gui.theme.ThemeTypes; | ||
import org.jabref.gui.util.DirectoryDialogConfiguration; | ||
import org.jabref.gui.util.FileDialogConfiguration; | ||
import org.jabref.logic.l10n.Language; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.net.ssl.TrustStoreManager; | ||
import org.jabref.logic.remote.RemotePreferences; | ||
import org.jabref.logic.remote.RemoteUtil; | ||
import org.jabref.logic.util.StandardFileType; | ||
import org.jabref.model.database.BibDatabaseMode; | ||
import org.jabref.model.entry.BibEntryTypesManager; | ||
import org.jabref.model.strings.StringUtil; | ||
import org.jabref.model.util.FileUpdateMonitor; | ||
import org.jabref.preferences.FilePreferences; | ||
import org.jabref.preferences.InternalPreferences; | ||
import org.jabref.preferences.LibraryPreferences; | ||
import org.jabref.preferences.PreferencesService; | ||
import org.jabref.preferences.TelemetryPreferences; | ||
|
@@ -81,19 +90,33 @@ public class GeneralTabViewModel implements PreferenceTabViewModel { | |
private final TelemetryPreferences telemetryPreferences; | ||
private final LibraryPreferences libraryPreferences; | ||
private final FilePreferences filePreferences; | ||
private final RemotePreferences remotePreferences; | ||
|
||
private final Validator fontSizeValidator; | ||
private final Validator customPathToThemeValidator; | ||
|
||
private final List<String> restartWarning = new ArrayList<>(); | ||
|
||
public GeneralTabViewModel(DialogService dialogService, PreferencesService preferences) { | ||
private final BooleanProperty remoteServerProperty = new SimpleBooleanProperty(); | ||
private final StringProperty remotePortProperty = new SimpleStringProperty(""); | ||
private final Validator remotePortValidator; | ||
private final InternalPreferences internalPreferences; | ||
private final BooleanProperty versionCheckProperty = new SimpleBooleanProperty(); | ||
private final FileUpdateMonitor fileUpdateMonitor; | ||
private final BibEntryTypesManager entryTypesManager; | ||
private TrustStoreManager trustStoreManager; | ||
|
||
public GeneralTabViewModel(DialogService dialogService, PreferencesService preferences, FileUpdateMonitor fileUpdateMonitor, BibEntryTypesManager entryTypesManager) { | ||
Siedlerchr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
this.workspacePreferences = preferences.getWorkspacePreferences(); | ||
this.telemetryPreferences = preferences.getTelemetryPreferences(); | ||
this.libraryPreferences = preferences.getLibraryPreferences(); | ||
this.filePreferences = preferences.getFilePreferences(); | ||
this.remotePreferences = preferences.getRemotePreferences(); | ||
this.internalPreferences = preferences.getInternalPreferences(); | ||
this.fileUpdateMonitor = fileUpdateMonitor; | ||
this.entryTypesManager = entryTypesManager; | ||
this.trustStoreManager = trustStoreManager; | ||
|
||
fontSizeValidator = new FunctionBasedValidator<>( | ||
fontSizeProperty, | ||
|
@@ -116,6 +139,25 @@ public GeneralTabViewModel(DialogService dialogService, PreferencesService prefe | |
Localization.lang("General"), | ||
Localization.lang("Visual theme"), | ||
Localization.lang("Please specify a css theme file.")))); | ||
|
||
remotePortValidator = new FunctionBasedValidator<>( | ||
remotePortProperty, | ||
input -> { | ||
try { | ||
int portNumber = Integer.parseInt(remotePortProperty().getValue()); | ||
return RemoteUtil.isUserPort(portNumber); | ||
} catch (NumberFormatException ex) { | ||
return false; | ||
} | ||
}, | ||
ValidationMessage.error(String.format("%s > %s %n %n %s", | ||
Localization.lang("Network"), | ||
Localization.lang("Remote operation"), | ||
Localization.lang("You must enter an integer value in the interval 1025-65535")))); | ||
} | ||
|
||
public ValidationStatus remotePortValidationStatus() { | ||
return remotePortValidator.getValidationStatus(); | ||
} | ||
|
||
@Override | ||
|
@@ -125,8 +167,10 @@ public void setValues() { | |
// The light theme is in fact the absence of any theme modifying 'base.css'. Another embedded theme like | ||
// 'dark.css', stored in the classpath, can be introduced in {@link org.jabref.gui.theme.Theme}. | ||
switch (workspacePreferences.getTheme().getType()) { | ||
case DEFAULT -> selectedThemeProperty.setValue(ThemeTypes.LIGHT); | ||
case EMBEDDED -> selectedThemeProperty.setValue(ThemeTypes.DARK); | ||
case DEFAULT -> | ||
selectedThemeProperty.setValue(ThemeTypes.LIGHT); | ||
case EMBEDDED -> | ||
selectedThemeProperty.setValue(ThemeTypes.DARK); | ||
case CUSTOM -> { | ||
selectedThemeProperty.setValue(ThemeTypes.CUSTOM); | ||
customPathToThemeProperty.setValue(workspacePreferences.getTheme().getName()); | ||
|
@@ -151,6 +195,9 @@ public void setValues() { | |
|
||
createBackupProperty.setValue(filePreferences.shouldCreateBackup()); | ||
backupDirectoryProperty.setValue(filePreferences.getBackupDirectory().toString()); | ||
|
||
remoteServerProperty.setValue(remotePreferences.useRemoteServer()); | ||
remotePortProperty.setValue(String.valueOf(remotePreferences.getPort())); | ||
} | ||
|
||
@Override | ||
|
@@ -185,6 +232,38 @@ public void storeSettings() { | |
|
||
filePreferences.createBackupProperty().setValue(createBackupProperty.getValue()); | ||
filePreferences.backupDirectoryProperty().setValue(Path.of(backupDirectoryProperty.getValue())); | ||
|
||
getPortAsInt(remotePortProperty.getValue()).ifPresent(newPort -> { | ||
if (remotePreferences.isDifferentPort(newPort)) { | ||
remotePreferences.setPort(newPort); | ||
} | ||
}); | ||
|
||
internalPreferences.setVersionCheckEnabled(versionCheckProperty.getValue()); | ||
|
||
getPortAsInt(remotePortProperty.getValue()).ifPresent(newPort -> { | ||
if (remotePreferences.isDifferentPort(newPort)) { | ||
remotePreferences.setPort(newPort); | ||
} | ||
}); | ||
|
||
if (remoteServerProperty.getValue()) { | ||
remotePreferences.setUseRemoteServer(true); | ||
Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(preferences, fileUpdateMonitor, entryTypesManager), remotePreferences.getPort()); | ||
} else { | ||
remotePreferences.setUseRemoteServer(false); | ||
Globals.REMOTE_LISTENER.stop(); | ||
} | ||
trustStoreManager.flush(); | ||
Comment on lines
+252
to
+259
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. Fun fact: This code is doubled -- I will remove it in a new PR. |
||
|
||
if (remoteServerProperty.getValue()) { | ||
remotePreferences.setUseRemoteServer(true); | ||
Globals.REMOTE_LISTENER.openAndStart(new CLIMessageHandler(preferences, fileUpdateMonitor, entryTypesManager), remotePreferences.getPort()); | ||
} else { | ||
remotePreferences.setUseRemoteServer(false); | ||
Globals.REMOTE_LISTENER.stop(); | ||
} | ||
trustStoreManager.flush(); | ||
} | ||
|
||
public ValidationStatus fontSizeValidationStatus() { | ||
|
@@ -199,6 +278,10 @@ public ValidationStatus customPathToThemeValidationStatus() { | |
public boolean validateSettings() { | ||
CompositeValidator validator = new CompositeValidator(); | ||
|
||
if (remoteServerProperty.getValue()) { | ||
validator.addValidators(remotePortValidator); | ||
} | ||
|
||
if (fontOverrideProperty.getValue()) { | ||
validator.addValidators(fontSizeValidator); | ||
} | ||
|
@@ -310,6 +393,14 @@ public void backupFileDirBrowse() { | |
.ifPresent(dir -> backupDirectoryProperty.setValue(dir.toString())); | ||
} | ||
|
||
public BooleanProperty remoteServerProperty() { | ||
return remoteServerProperty; | ||
} | ||
|
||
public StringProperty remotePortProperty() { | ||
return remotePortProperty; | ||
} | ||
|
||
public void openBrowser() { | ||
String url = "https://themes.jabref.org"; | ||
try { | ||
|
@@ -318,4 +409,12 @@ public void openBrowser() { | |
dialogService.showErrorDialogAndWait(Localization.lang("Could not open website."), e); | ||
} | ||
} | ||
|
||
private Optional<Integer> getPortAsInt(String value) { | ||
try { | ||
return Optional.of(Integer.parseInt(value)); | ||
} catch (NumberFormatException ex) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I fixed grammar and spaces in dc2b649.