-
-
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
Refactor Open and Save Dialogs #1336
Conversation
Good idea to refactor the file dialogs 👍. Just one small comment so far: could you please make the methods non-static (and probably move the passed frame to the constructor). In this way the code becomes more testable because the file dialog can be mocked away. |
@tobiasdiez Yes, I already came up with a solution for this. I will probably use some kind of FactorPattern to create the dialogs. That reduces the number of constructors/method overloads. |
Current coverage is 27.54%@@ master #1336 diff @@
==========================================
Files 694 696 +2
Lines 46262 46335 +73
Methods 0 0
Messages 0 0
Branches 7649 7655 +6
==========================================
+ Hits 12733 12759 +26
- Misses 32432 32476 +44
- Partials 1097 1100 +3
|
What is the status here? I'd love to see these changes inside JabRef 3.5! |
Unfortunately I have not that much time atm. But I will try to see how far I get the next days. Mabye at the weekend I can get some time for it. Atm another project ist due on sunday...;) |
Got some time working on it. |
this.description = description; | ||
} | ||
|
||
public String[] getExtensions() { |
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.
List?
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.
Normally I would agree with you, but in this case an Array is better, because a) varargs (...) as parameter is handled as array and b) the array is then passed again as varags parameter to the FileNameFilterExtension.
A list would have to be converted back to array again to be passed as paramter.
And the decison for varargs was to support multiple file extension for one type in the enum e.g. Import_Format("Sample input format",xml,bib,dat)
http://docs.oracle.com/javase/1.5.0/docs/guide/language/varargs.html
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.
003d4e4
to
8453c2d
Compare
NewFileDialogs will be renamed when the work is done Reworked BrowseAction, added Enum for file extensions Use a more factory like pattern to create fileDialogs Avoids unnecessary constructor overloads Reworked FileExtensions to accept mutiple Extensions for one description Added OverwriteExistingFile in JFileChooser Refactored rest of the dialogs Removed obsolte keys Remove comment
8453c2d
to
39dbf77
Compare
Ready for review. |
@@ -199,6 +202,8 @@ public void changedUpdate(DocumentEvent documentEvent) { | |||
|
|||
}); | |||
|
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.
Get rid of print-debugging. :-)
return fileChooser.showDialog(parent, null) == JFileChooser.APPROVE_OPTION; | ||
} | ||
|
||
private static String getWorkingDir() { |
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.
Accept JabRefPreferences instead of operating on Globals.prefs
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, but you mean sth like this:
JabRefPreferences.getInstance().get(JabRefPreferences.WORKING_DIRECTORY);
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 gui code so no need to inject JabRefPreferences
? (I think @tobiasdiez means private static String getWorkingDir(JabRefPreferences prefs) {
)
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, all gui code, but still a bit confused about the Pref stuff 😕
The getWorkingDir() is only called from the constructor.
public NewFileDialogs(JFrame owner) {
this(owner, getWorkingDir());
}
So here I would need to pass the JabRefPreferences.getInstance()?
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 I thought about injecting the JabRefPreferences class. So
̀getWorkingDir(JabRefPreferences preferences)
and NewFileDialogs(JFrame owner, JabRefPreferences preferences)
which then is called via new NewFileDialogs(owner, Globals.prefs)
.
Just because its GUI code doesn't mean that it is ok to work on Globals.prefs
. We are just not as strict in enforcing the rule since sometimes it is very hard to implement. But here it is relatively simple.
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 agree that it is simple here, but I'm still under the impression that it indeed is OK. With that said, I also happens to inject it in gui code every now and then.
I guess here one may actually inject the preference value rather than the complete preferences as well?
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.
Oh, injecting the correct value in this particular case wouldn't make much sense. :-)
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 thought about this again and I see no advantages over injecting the Preferences or passing everytime the working directory.
The goal of the redesign was that the developer does not have to care about setting/passing the working directory every time. Passing the Preferences every time would not make any sense to me. Addtionally, it would create some extra dependencies of Globals.prefs to the caller class.
I really like the new FileDialog class and its fluent interface. The code needs some cleanup in general (remove commented-out code and debug prints, no abbreviations, ...) and then I think it is good to go. |
TXT( | ||
"Plain text file", "txt"), | ||
CLASS( | ||
"Class file", "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.
I think most of the description values should actually be localized.
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 was not sure about this, so I wanted to wait for feedback. But I agree that it probably makes sense.
Use optional Use Localization
Adressed comments. @tobiasdiez Not sure if I understand you right on how I should handle the WorkingDir-Prefs-stuff. |
Some renaming
RIS( | ||
Localization.lang("%0 file", "RIS"), "ris"), | ||
ENDNOTE( | ||
Localization.lang("Endnote/Refer file"), "ref"), |
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.
Please rewrite to Localization.lang("%0 file", "Endnote/Refer"), "ref"),
* master: (22 commits) Do not cite entries without a key in OpenOffice/LibreOffice (JabRef#1682) (JabRef#1683) Got rid of unused preferences (JabRef#1672) Move labelpattern (JabRef#1626) Implementation of shared database support (full system). (JabRef#1451) Removed bst from architecture tests JabRef#1699 Update PULL_REQUEST_TEMPLATE.md French localization: Menu: Translation of an empty string French localization: Jabref_fr: empty strings translated Updated string similarity version (JabRef#1698) Minify description of release process Announce switch from GPL to MIT in CONTRIBUTING.md and README.md Some cleanups to initialize empty MetaData at fewer positions (JabRef#1696) Automatic group names are converted from LaTeX to Unicode (JabRef#1684) Update ISSUE_TEMPLATE.md (JabRef#1686) Removed (false) NPE issue reported by FindBugs More Swedish translations (JabRef#1691) Updated wiremock version (JabRef#1690) Some minor code cleanups (JabRef#1689) Removed dependencies of Globals.prefs in some tests (JabRef#1688) Lookup BibEntry from ISBN and merge information (JabRef#1621) ... # Conflicts: # src/main/java/net/sf/jabref/gui/BasePanel.java # src/main/java/net/sf/jabref/importer/ImportMenuItem.java # src/main/resources/l10n/JabRef_da.properties # src/main/resources/l10n/JabRef_de.properties # src/main/resources/l10n/JabRef_en.properties # src/main/resources/l10n/JabRef_es.properties # src/main/resources/l10n/JabRef_fa.properties # src/main/resources/l10n/JabRef_fr.properties # src/main/resources/l10n/JabRef_in.properties # src/main/resources/l10n/JabRef_it.properties # src/main/resources/l10n/JabRef_ja.properties # src/main/resources/l10n/JabRef_nl.properties # src/main/resources/l10n/JabRef_no.properties # src/main/resources/l10n/JabRef_pt_BR.properties # src/main/resources/l10n/JabRef_ru.properties # src/main/resources/l10n/JabRef_sv.properties # src/main/resources/l10n/JabRef_tr.properties # src/main/resources/l10n/JabRef_vi.properties # src/main/resources/l10n/JabRef_zh.properties
Fix merge error Fix codacy issues
@oscargus Could you please have a look why the |
Fixed typo
Refactored Open and Save dialogs Introduced FileExtensions enum for FileDialog Filter Updated BrowseAction to use new dialogs Fix JabRef#1324 Fix JabRef#1609
Complete Refactoring of the ugly and propably outdated FileDialogs code
NewFileDialogs will be renamed when the work is done
Atm I want to keep it parallel.
TODO: