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

Save deletion of current searchquery #2469

Merged
merged 2 commits into from
Jan 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Non-ISO timestamp settings prevented the opening of the entry editor (see [#2447](https://github.com/JabRef/jabref/issues/2447))
- When pressing <kbd>Ctrl</kbd> + <kbd>F</kbd> and the searchbar is already focused the text will be selected.
- LaTeX symbols are now displayed as Unicode for the author column in the main table. "'n" and "\'{n}" are parsed correctly. Fixes [#2458](https://github.com/JabRef/jabref/issues/2458).
- Fixes [#2468](https://github.com/JabRef/jabref/issues/2468): Save deletion of current searchquery.
Copy link
Member

@koppor koppor Jan 15, 2017

Choose a reason for hiding this comment

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

I would use (a slight update of) your long sentence of the PR text here - and put the "Fixes" as last (as with the other entries)

If one deleted the current query, it was not saved (every database can have its own query). Fixes #2468.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


### Removed

Expand Down
15 changes: 12 additions & 3 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe

private ContentAutoCompleters autoCompleters;

private SearchQuery currentSearchQuery;
/** the query the user searches when this basepanel is active */
Copy link
Member

Choose a reason for hiding this comment

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

Please use // as comment for fields. (Or quote some manual where block comments are recommended)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

JavaDoc works on properties too (I think you overlooked the second asterisks).

private Optional<SearchQuery> currentSearchQuery = Optional.empty();


public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
Expand Down Expand Up @@ -2405,12 +2406,20 @@ public BibDatabaseContext getDatabaseContext() {
return bibDatabaseContext;
}

public SearchQuery getCurrentSearchQuery() {
public Optional<SearchQuery> getCurrentSearchQuery() {
return currentSearchQuery;
}

/**
* Set the query the user currently searches while this basepanel is active
* @param currentSearchQuery can be null
*/
public void setCurrentSearchQuery(SearchQuery currentSearchQuery) {
this.currentSearchQuery = currentSearchQuery;
if (currentSearchQuery == null) {
Copy link
Member

Choose a reason for hiding this comment

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

You can use Optional.ofNullable(currentSearchQuery) instead of this if/else block

Copy link
Member

Choose a reason for hiding this comment

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

However, I am unsure whether trim().isEmpty() should be checked for. I think, your current code is OK. (After the usage of ofNullable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.currentSearchQuery = Optional.empty();
} else {
this.currentSearchQuery = Optional.of(currentSearchQuery);
}
}

public CitationStyleCache getCitationStyleCache() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ public void windowClosing(WindowEvent e) {
globalSearchBar.performSearch();
} else {
String content = "";
SearchQuery currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if ((currentSearchQuery != null) && !currentSearchQuery.getQuery().trim().isEmpty()) {
content = currentSearchQuery.getQuery();
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ private void clearSearch(BasePanel currentBasePanel) {

if (currentBasePanel != null) {
currentBasePanel.getMainTable().getTableModel().updateSearchState(MainTableDataModel.DisplayOption.DISABLED);
currentBasePanel.setCurrentSearchQuery(null);
}

if (dontSelectSearchBar){
Expand Down