-
-
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
Enhanced message log #4815
Enhanced message log #4815
Changes from 5 commits
3ab1bd7
577de6a
7e20650
23362fa
7995593
deff466
e5cb625
7ccf914
67e33e1
0444b6a
f2a31d0
d87c7f6
ea3e786
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 |
---|---|---|
|
@@ -24,21 +24,28 @@ | |
import javafx.scene.control.ChoiceDialog; | ||
import javafx.scene.control.DialogPane; | ||
import javafx.scene.control.TextInputDialog; | ||
import javafx.scene.layout.Pane; | ||
import javafx.scene.layout.Region; | ||
import javafx.stage.DirectoryChooser; | ||
import javafx.stage.FileChooser; | ||
import javafx.stage.Stage; | ||
import javafx.stage.Window; | ||
import javafx.util.Duration; | ||
|
||
import org.jabref.JabRefGUI; | ||
import org.jabref.gui.icon.IconTheme; | ||
import org.jabref.gui.util.DefaultTaskExecutor; | ||
import org.jabref.gui.util.DirectoryDialogConfiguration; | ||
import org.jabref.gui.util.FileDialogConfiguration; | ||
import org.jabref.gui.util.ZipFileChooser; | ||
import org.jabref.logic.l10n.Localization; | ||
|
||
import com.jfoenix.controls.JFXSnackbar; | ||
import com.jfoenix.controls.JFXSnackbar.SnackbarEvent; | ||
import com.jfoenix.controls.JFXSnackbarLayout; | ||
import org.controlsfx.dialog.ExceptionDialog; | ||
import org.controlsfx.dialog.ProgressDialog; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class provides methods to create default | ||
|
@@ -51,18 +58,28 @@ | |
*/ | ||
public class FXDialogService implements DialogService { | ||
|
||
private static final Duration TOAST_MESSAGE_DISPLAY_TIME = Duration.millis(3000); | ||
private static final Logger LOGGER = LoggerFactory.getLogger(FXDialogService.class); | ||
|
||
private final Window mainWindow; | ||
private final JFXSnackbar statusLine; | ||
|
||
/** | ||
* @deprecated try not to initialize a new dialog service but reuse the one constructed in {@link org.jabref.gui.JabRefFrame}. | ||
*/ | ||
@Deprecated | ||
public FXDialogService() { | ||
this(null); | ||
this(null, null); | ||
} | ||
|
||
public FXDialogService(Window mainWindow) { | ||
this.mainWindow = mainWindow; | ||
this.statusLine = new JFXSnackbar(); | ||
} | ||
|
||
public FXDialogService(Window mainWindow, Pane mainPane) { | ||
this.mainWindow = mainWindow; | ||
this.statusLine = new JFXSnackbar(mainPane); | ||
} | ||
|
||
private static FXDialog createDialog(AlertType type, String title, String content) { | ||
|
@@ -253,7 +270,8 @@ public <V> void showProgressDialogAndWait(String title, String content, Task<V> | |
|
||
@Override | ||
public void notify(String message) { | ||
JabRefGUI.getMainFrame().output(message); | ||
LOGGER.info(message); | ||
DefaultTaskExecutor.runInJavaFXThread(() -> statusLine.fireEvent(new SnackbarEvent(new JFXSnackbarLayout(message), TOAST_MESSAGE_DISPLAY_TIME, 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. Please remove the 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. I think this method is still sometimes called from background threads therefore we risk exceptions 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. Is there an alternative to this method? I also think it is necessary to run it on the JavaFX thread, for example in 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. Usually background tasks are not allowed to communicate things directly. The general principle is that only the hard work is moved to a different task (by using Personally, I would prefer exceptions instead of facing potentially hard to debug threading issues. But for now you can simply leave the 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. Ok, I understand and will keep that in mind. |
||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ public static void openBrowserShowPopup(String url) { | |
String couldNotOpenBrowser = Localization.lang("Could not open browser."); | ||
String openManually = Localization.lang("Please open %0 manually.", url); | ||
String copiedToClipboard = Localization.lang("The link has been copied to the clipboard."); | ||
JabRefGUI.getMainFrame().output(couldNotOpenBrowser); | ||
JabRefGUI.getMainFrame().getDialogService().notify(couldNotOpenBrowser); | ||
JOptionPane.showMessageDialog(null, | ||
couldNotOpenBrowser + "\n" + openManually + "\n" + | ||
copiedToClipboard, | ||
|
@@ -239,7 +239,7 @@ public static void openConsole(File file) throws IOException { | |
// replace the placeholder if used | ||
String commandLoggingText = command.replace("%DIR", absolutePath); | ||
|
||
JabRefGUI.getMainFrame().output(Localization.lang("Executing command \"%0\"...", commandLoggingText)); | ||
JabRefGUI.getMainFrame().getDialogService().notify(Localization.lang("Executing command \"%0\"...", commandLoggingText)); | ||
LOGGER.info("Executing command \"" + commandLoggingText + "\"..."); | ||
|
||
try { | ||
|
@@ -251,7 +251,7 @@ public static void openConsole(File file) throws IOException { | |
Localization.lang("Error occured while executing the command \"%0\".", commandLoggingText), | ||
Localization.lang("Open console") + " - " + Localization.lang("Error"), | ||
JOptionPane.ERROR_MESSAGE); | ||
JabRefGUI.getMainFrame().output(null); | ||
JabRefGUI.getMainFrame().getDialogService().notify(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. I just saw that we seemed to forgot to convert that old swing dialog here. Could you please fix this as well? 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. did it in f2a31d0, there was also another one in the same class |
||
} | ||
} | ||
|
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.
The
null
argument will lead to a NPE below innotify
. Leaving it asthis(null)
should work.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.
Ok, I will fix it in the next commit.