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

Fix for application dialogs opening in wrong displays #7273

Merged
merged 10 commits into from
Jan 2, 2021

Conversation

eludif
Copy link
Contributor

@eludif eludif commented Dec 29, 2020

What:

  • Fix for issue with application dialogs opening in the wrong display

Why:

  • Dialog opens in the display the application opened at startup (usually the primary display), regardless of the current position of the application main window

  • This is a draft to discuss the approach taken.

Fixes #7272

  • Change in CHANGELOG.md described (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not created an issue at https://github.com/JabRef/user-documentation/issues or, even better, submitted a pull request to the documentation repository.

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!
Setting the owner of the sub-dialogs is a good idea, indeed.

I was thinking about the best way to do this, without too much changes. Here is what I came up with:

What do you think?

@eludif
Copy link
Contributor Author

eludif commented Dec 29, 2020

Thanks for your contribution!
Setting the owner of the sub-dialogs is a good idea, indeed.

I was thinking about the best way to do this, without too much changes. Here is what I came up with:

What do you think?

Hi @tobiasdiez, thanks for the comments.

  • I agree based on your suggestion; for dialogs created with the help of DialogService, owners of such dialogs can easily be set.

  • It seems like we might have to consider adding a Window object to the BaseDialog constructor here:


    That way initOwner(mainWindow); can be called within the constructor, for dialogs not created with the help of DialogService, but rather extending BaseDialog.
    If not, we need a way to find out what what Window creates dialogs that extend BaseDialog, eg. AboutDialogView in order to set its owner.

@tobiasdiez
Copy link
Member

It seems like we might have to consider adding a Window object to the BaseDialog constructor here:

That would work indeed. However, then one needs to pass references of the main stage everywhere (like what you did in the current changes), and that's something I don't really like. Instead, I was proposing to pass references to the DialogService and then using something like

DialogService dialogService = ... coming from somewhere
AboutDialogView aboutDialogView = new AboutDialogView();
dialogService.show(aboutDialogView);

to show the dialog with the proper owner (set in the dialogservice class). In this way, only the dialogservice needs to know about the main stage. Moreover, there are already a lot of places that have the dialog service floating around, so hopefully less changes are required.

@eludif
Copy link
Contributor Author

eludif commented Dec 30, 2020

DialogService dialogService = ... coming from somewhere

Sounds good, can you explain how dependency inject is handled in this project, I'm unable to correctly inject DialogSerivce into AboutDialogView, thanks.

@tobiasdiez
Copy link
Member

You can use @Inject DialogService dialogService in View classes, e.g here:

@Inject private DialogService dialogService;

This is then usually passed to the ViewModel, which uses it to open a dialog.
viewModel = new AboutDialogViewModel(dialogService, clipBoardManager, buildInfo);

But for our purposes here that's not very helpful as there are almost no dialogs created from other dialogs. For actions, the usual pattern is to pass it as a constructor argument, e.g. https://github.com/JabRef/jabref/blob/4cf2fb06d3d876d2043f65ca0e51c3c4185fd05c/src/main/java/org/jabref/gui/undo/UndoRedoAction.java

@eludif
Copy link
Contributor Author

eludif commented Dec 30, 2020

What are your thoughts regarding instantiating via the Injector.instantiateModelOrService() method.

@eludif eludif marked this pull request as ready for review December 30, 2020 23:39
@eludif eludif changed the title [WIP] Fix for application dialogs opening in wrong displays Fix for application dialogs opening in wrong displays Dec 31, 2020
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the Injectior is actually a very good idea!

src/main/java/org/jabref/gui/JabRefDialogService.java Outdated Show resolved Hide resolved
@@ -272,4 +273,6 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
* @return the selected file or an empty {@link Optional} if no file has been selected
*/
Optional<Path> showFileOpenFromArchiveDialog(Path archivePath) throws IOException;

void show(BaseDialog<?> aboutDialogView);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it to showCustomDialog to be coherent with the above method. Or rename that to showAndWait...yeah maybe the later?

Please also rename the argument, and add a bit of documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename it to showCustomDialog to be coherent with the above method. Or rename that to showAndWait...yeah maybe the later?

Please also rename the argument, and add a bit of documentation.

Decided to go with showCustomDialog() as it seems to be more consistent with other methods in that interface.

- Rename DialogService.show() method to showCustomDialog()
- Rename showCustomDialog()'s argument
- Add documentation to showCustomDialog method
- Make createDialog and createDialogWithOptOut non static
@eludif eludif requested a review from tobiasdiez December 31, 2020 13:43
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the quick follow-ups! The code looks good to me!

@eludif eludif requested a review from tobiasdiez December 31, 2020 17:47
@eludif
Copy link
Contributor Author

eludif commented Dec 31, 2020

The added test seems to be failing, I am unable to run the tests locally. Do you have an idea what I might be missing in the test?

Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing javafx code is a bit more involved as you have to start the gui interface, see e.g. https://github.com/JabRef/jabref/blob/c8f7be89ad704065474decb61851e42416caf88d/src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java for an example.
To be honest, here it would be fine not to add a test (although it's always good to have tests of course).

@eludif eludif requested a review from tobiasdiez January 1, 2021 17:07
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your PR! LGTM

@eludif
Copy link
Contributor Author

eludif commented Jan 2, 2021

Thanks a lot for your PR! LGTM

Thanks for the help and comments. 👍🏾

Copy link
Member

@Siedlerchr Siedlerchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
It would be nice if you add some summary and explanation to our devdocs what to do when creating a new dialog, e.g using dialogService to start
https://devdocs.jabref.org/getting-into-the-code/code-howtos#javafx

@Siedlerchr
Copy link
Member

Please have a look at the markdownlint checkstlye output. Then I would be happy to merge

@Siedlerchr Siedlerchr merged commit 0b4be8a into JabRef:master Jan 2, 2021
Siedlerchr added a commit that referenced this pull request Jan 3, 2021
* upstream/master:
  fix checsktyle
  Fix for application dialogs opening in wrong displays (#7273)
  Only disable  move to file dir when path equals (#7269)
  Improved detection of long DOI's within text (#7260)
  Add missing author and fix name
  Fix style of highlighted checkboxes while searching in preferences (#7258)
  Updates to institution citation keys (#7210)
  Bump xmlunit-core from 2.8.1 to 2.8.2 (#7251)
  Bump classgraph from 4.8.97 to 4.8.98 (#7250)
  Bump bcprov-jdk15on from 1.67 to 1.68 (#7249)
  Bump xmlunit-matchers from 2.8.1 to 2.8.2 (#7252)
  Bump unirest-java from 3.11.06 to 3.11.09 (#7254)
  Bump org.beryx.jlink from 2.23.0 to 2.23.1 (#7253)
  Bump pascalgn/automerge-action from v0.12.0 to v0.13.0 (#7255)

# Conflicts:
#	src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java
@koppor
Copy link
Member

koppor commented Jan 4, 2021

This PR causes the about dialog not opening a second time (see #7287). Some dialogs can also be opened twice (Customized Entry Types).

@faeludire Could you have a look please?

This was referenced Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Application Dialogs Open on Wrong Display
4 participants