-
-
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
Convert Preferences/ExternalTab to MVVM #5047
Conversation
@@ -1677,7 +1679,7 @@ Unable\ to\ generate\ new\ library=Unable to generate new library | |||
Open\ console=Open console | |||
Use\ default\ terminal\ emulator=Use default terminal emulator | |||
Execute\ command=Execute command | |||
Note\:\ Use\ the\ placeholder\ %0\ for\ the\ location\ of\ the\ opened\ library\ file.=Note: Use the placeholder %0 for the location of the opened library file. | |||
Note\:\ Use\ the\ placeholder\ %DIR%\ for\ the\ location\ of\ the\ opened\ library\ file.=Note: Use the placeholder %DIR% for the location of the opened library file. |
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.
This is a parameterized localization string, e.g. the %0 works similar as in String.format as argument and is usually used to indicate values that should not be translated
Not sure if it is possible to use them in the fxml directly
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.
It showed up fine, I did not see any complaints from the compiler nor from the jre. The original line was
new Label(Localization.lang("Note: Use the placeholder %0 for the location of the opened library file.", "%DIR") )
The other option I thought of would be to put this in the initialize-method as setValue. If you want so, I can change it, but I don't think that this would be a good solution, as everything else is completly written in fxml.
|
||
private ExternalTabViewModel viewModel; | ||
|
||
public ExternalTabView(DialogService dialogService, JabRefPreferences preferences, JabRefFrame frame) { |
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.
not sure for root components, but You can Inject DialogService and could also inject the PreferencesService interface. You would then just need the getters/setter methods for each value
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.
Is there some way also to inject the the JabRefFrame?
This @Inject-DI-stuff is really black-magic-vodoo to me.
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.
It is not possible to inject the JabRefFrame
(and we will also not add this functionality as we try to get rid of the omnipresence of JabrefFrame
). Here you find an overview of the possible @Inject
classes:
jabref/src/main/java/org/jabref/gui/DefaultInjector.java
Lines 31 to 51 in 47e3cc5
if (clazz == DialogService.class) { | |
return JabRefGUI.getMainFrame().getDialogService(); | |
} else if (clazz == TaskExecutor.class) { | |
return Globals.TASK_EXECUTOR; | |
} else if (clazz == PreferencesService.class) { | |
return Globals.prefs; | |
} else if (clazz == KeyBindingRepository.class) { | |
return Globals.getKeyPrefs(); | |
} else if (clazz == JournalAbbreviationLoader.class) { | |
return Globals.journalAbbreviationLoader; | |
} else if (clazz == StateManager.class) { | |
return Globals.stateManager; | |
} else if (clazz == FileUpdateMonitor.class) { | |
return Globals.getFileUpdateMonitor(); | |
} else if (clazz == ProtectedTermsLoader.class) { | |
return Globals.protectedTermsLoader; | |
} else if (clazz == ClipBoardManager.class) { | |
return Globals.clipboardManager; | |
} else if (clazz == UndoManager.class) { | |
return Globals.undoManager; | |
} else { |
If you want to dig deeper into how the injection works, have a look here: https://github.com/JabRef/afterburner.fx/tree/master/src/main/java/com/airhacks/afterburner/injection
But yes it is kind of black magic by design, since you normally you don't want to think about how the injection works.
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 think I somehow get an idea of how to use it.
If I inject the PreferencesService, would that imply, that I have to add getters and setters for every value accessed by the PreferenceDialog in PreferencesService (which is basically almost every value in JabRefPreferences)? Or do i just don't understand, what you mean?
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.
Yes, you are right. PreferencesServices is the interface for JabRefPreferences which can be injected. Of course you would need to add a lot of getters and setters for the values in the JabRefPreferences class, but I think it's not worth it for the preferences dialog.
But for other dialogs this is useful.
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.
What I can do is to inject PreferencesService in PreferencesDialog and downcast it to JabRefPreferences when I create the instances of the single tabs. - Or better I inject it in the TabsView and cast it when I create the ViewModel.
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.
In the long term, it is indeed desirable to inject the preference service. But this requires that all preference options are grouped in certain preference classes (e.g. EntryEditorPreferences). For the moment, it is ok if you pass a JabRefPreferences
as a constructor argument.
Ok, now dialogService is injected, preferencesService not. Reworking of JabRefPreferences would be another PR in the future sometime, bit this one should be done and ready to review and to merge, after the other one is merged. |
I just merged your other OR, seems to have created conflicts now |
I expected them, since i did a few addidtions, this PR wouldnt be compileable. Back in 15 mins. |
# Conflicts: # src/main/java/org/jabref/gui/preferences/ExternalTab.java # src/main/java/org/jabref/gui/preferences/PreferencesDialog.java
ok, resolved. |
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.
Looks really good to me!
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.
Thanks again for your hard work!
a20406d Added name of the editors of a given edition (#5140) 9881fc5 Ping on push, not PR, document role of dist-updater (#5137) 04668cc Create nouvelles-perspectives-en-sciences-sociales.csl (#5063) 1d94e21 Update bursa-uludag-universitesi-saglik-bilimleri-enstitusu.csl (#5047) 84f3893 Add Harvard style for Metropolia University of Applied Sciences (#5086) 8e43e79 Create opto-electronic-advances.csl (#5135) 36e4fba Update society-for-american-archaeology.csl (#5124) 69ca360 St. Paul Canon Law new style (#5138) b490ab0 Update and rename st-paul-university-faculty-of-canon-law.csl to saint-paul-university-faculty-of-canon-law.csl b498116 There is no en-CA locale 3c35f28 Metadata 7059cca Create tu-dortmund-agvm.csl (#5088) c321c98 Create new Citation type (#5093) a7edc8d Update international-organization.csl (#5103) 3d1a052 The AWS load balancer is messing things up (#5133) ca3839b Fix sort by a single macro (#5136) 5d1a7e8 Update chungara-revista-de-antropologia-chilena.csl (#5123) cd75d5d ping distribution-updater (#5132) dcf473a Update wirtschaftsuniversitat-wien-health-care-management.csl (#5125) a87085e Fix Harvard Praxisforschung Editors (#5130) d4176ca Switch automated tests to Github Actions (#5111) 726d0d8 Radiology, MPP, CORR -- small fixes: https://forums.zotero.org/discussion/85883/doi-radiology#latest https://forums.zotero.org/discussion/51058/style-request-molecular-plant-pathology#latest https://forums.zotero.org/discussion/85678/citing-style-clinical-orthopaedics-and-related-research#latest e23db68 Update to la-trobe-university-harvard style (#5119) c54b278 Create wirtschaftsuniversitat-wien-health-care-management.csl (#5110) 62fb019 Create austral-entomology.csl (#5118) afa328c Update iso690-author-date-en.csl (#5113) 5468dce Update iso690-author-date-fr-no-abstract.csl (#5112) 98af86c Update iso690-numeric-fr.csl (#5115) 09f84c4 Update iso690-author-date-fr.csl (#5114) 178a9e4 Fix current biology to superscript 1fa5ce7 Create droit-belge-centre-de-droit-prive-ulb.csl (#5107) 3a6a4bc Fix file modes (#5106) 48f50e5 Create chungara-revista-de-antropologia-chilena.csl (#5096) 1e848f8 Create the-journal-of-the-indian-law-institute.csl (#5100) 856524c Create molecular-biology.csl (#5101) eeebbf4 Create harvard-harper-adams-university.csl (#5104) d90993d Fix tests d4037bf WIP: St Paul Canon Law style git-subtree-dir: src/main/resources/csl-styles git-subtree-split: a20406d
follow-up to #5033
Converted the ExternalTab to MVVM, but keeps the same functionality like before. Just some small corrections. Ready to review.