Skip to content

Commit

Permalink
Search now per tab, plus global search only per popup from an existin…
Browse files Browse the repository at this point in the history
…g search window.

TODO: settings menu, some TODOs in the code in which other classes want to listen to search changes.
  • Loading branch information
simonharrer committed Nov 16, 2015
1 parent 30e8851 commit a2b0588
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 283 deletions.
4 changes: 0 additions & 4 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public class JabRefPreferences {
public static final String DEFAULT_OWNER = "defaultOwner";
public static final String GROUPS_VISIBLE_ROWS = "groupsVisibleRows";
public static final String DEFAULT_ENCODING = "defaultEncoding";
public static final String SEARCH_BAR_VISIBLE = "searchBarVisible";
public static final String TOOLBAR_VISIBLE = "toolbarVisible";
public static final String HIGHLIGHT_GROUPS_MATCHING_ALL = "highlightGroupsMatchingAll";
public static final String HIGHLIGHT_GROUPS_MATCHING_ANY = "highlightGroupsMatchingAny";
Expand Down Expand Up @@ -253,7 +252,6 @@ public class JabRefPreferences {
// When this should be made possible, the code to inspect is net.sf.jabref.gui.preftabs.LabelPatternPrefTab.storeSettings() -> LabelPattern keypatterns = getLabelPattern(); etc
public static final String DEFAULT_LABEL_PATTERN = "defaultLabelPattern";

public static final String SEARCH_MODE_GLOBAL = "searchAllBases";
public static final String SEARCH_MODE_FLOAT = "floatSearch";
public static final String GRAY_OUT_NON_HITS = "grayOutNonHits";
public static final String CONFIRM_DELETE = "confirmDelete";
Expand Down Expand Up @@ -572,7 +570,6 @@ private JabRefPreferences() {
defaults.put(HIGHLIGHT_GROUPS_MATCHING_ANY, Boolean.FALSE);
defaults.put(HIGHLIGHT_GROUPS_MATCHING_ALL, Boolean.FALSE);
defaults.put(TOOLBAR_VISIBLE, Boolean.TRUE);
defaults.put(SEARCH_BAR_VISIBLE, Boolean.TRUE);
defaults.put(DEFAULT_ENCODING, "UTF-8");
defaults.put(GROUPS_VISIBLE_ROWS, 8);
defaults.put(DEFAULT_OWNER, System.getProperty("user.name"));
Expand Down Expand Up @@ -647,7 +644,6 @@ private JabRefPreferences() {
defaults.put(CONFIRM_DELETE, Boolean.TRUE);
defaults.put(GRAY_OUT_NON_HITS, Boolean.TRUE);
defaults.put(SEARCH_MODE_FLOAT, Boolean.TRUE);
defaults.put(SEARCH_MODE_GLOBAL, Boolean.FALSE);
defaults.put(DEFAULT_LABEL_PATTERN, "[authors3][year]");
defaults.put(PREVIEW_ENABLED, Boolean.TRUE);
defaults.put(ACTIVE_PREVIEW, 0);
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.sf.jabref.gui.labelPattern.SearchFixDuplicateLabels;
import net.sf.jabref.gui.mergeentries.MergeEntriesDialog;
import net.sf.jabref.gui.mergeentries.MergeEntryDOIDialog;
import net.sf.jabref.gui.search.SearchBar;
import net.sf.jabref.gui.undo.*;
import net.sf.jabref.gui.worker.*;
import net.sf.jabref.importer.AppendDatabaseAction;
Expand Down Expand Up @@ -184,7 +185,7 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe

private final HashMap<String, Object> actions = new HashMap<>();
private final SidePaneManager sidePaneManager;

private final SearchBar searchBar;

// Returns a collection of AutoCompleters, which are populated from the current database
public ContentAutoCompleters getAutoCompleters() {
Expand All @@ -209,7 +210,13 @@ public BasePanel(JabRefFrame frame, BibtexDatabase db, File file, MetaData metaD
this.frame = frame;
database = db;

searchBar = new SearchBar(this);


setupMainPanel();

this.add(searchBar, BorderLayout.NORTH);

setupActions();

metaData.setFile(file);
Expand Down Expand Up @@ -719,17 +726,7 @@ public void run() {

actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this));

actions.put(Actions.SEARCH, (BaseAction) () -> {
frame.setSearchBarVisible(true);
frame.getSearchBar().focus();
});

actions.put(Actions.TOGGLE_SEARCH, (BaseAction) () -> {
frame.setSearchBarVisible(! frame.searchBar.isVisible());
if (frame.searchBar.isVisible()) {
frame.getSearchBar().focus();
}
});
actions.put(Actions.SEARCH, (BaseAction) searchBar::focus);

// The action for copying the selected entry's key.
actions.put(Actions.COPY_KEY, (BaseAction) () -> {
Expand Down Expand Up @@ -1512,6 +1509,9 @@ public BibtexEntry newEntry(BibtexEntryType type) {
return null;
}

public SearchBar getSearchBar() {
return searchBar;
}

/**
* This listener is used to add a new entry to a group (or a set of groups) in case the Group View is selected and
Expand Down Expand Up @@ -1829,7 +1829,7 @@ protected boolean accept(Component c) {
}

public void updateSearchManager() {
frame.getSearchBar().setAutoCompleter(searchAutoCompleter);
searchBar.setAutoCompleter(searchAutoCompleter);
}

private void instantiateSearchAutoCompleter() {
Expand Down
45 changes: 2 additions & 43 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
// The sidepane manager takes care of populating the sidepane.
public SidePaneManager sidePaneManager;

public SearchBar searchBar;

public JTabbedPane tabbedPane; // initialized at constructor
final String htmlPadding = "<html><div style='padding:2px 5px;'>";

Expand Down Expand Up @@ -245,7 +243,6 @@ void addJToogleButton(JToggleButton button) {
/* References to the toggle buttons in the toolbar */
// the groups interface
public JToggleButton groupToggle;
public JToggleButton searchToggle;
public JToggleButton previewToggle;
public JToggleButton fetcherToggle;

Expand Down Expand Up @@ -330,9 +327,6 @@ void addJToogleButton(JToggleButton button) {
public final AbstractAction loadSessionAction = new LoadSessionAction();
private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"),
Localization.lang("Search"), prefs.getKey(KeyBinds.SEARCH), IconTheme.JabRefIcon.SEARCH.getIcon());
private final AbstractAction toggleSearch = new GeneralAction(Actions.TOGGLE_SEARCH,
Localization.menuTitle("Search"), Localization.lang("Toggle search panel"),
IconTheme.JabRefIcon.SEARCH.getIcon());

private final AbstractAction copyKey = new GeneralAction(Actions.COPY_KEY, Localization.menuTitle("Copy BibTeX key"),
prefs.getKey(KeyBinds.COPY_BIB_TE_X_KEY));
Expand Down Expand Up @@ -594,7 +588,6 @@ public void stateChanged(ChangeEvent e) {
BasePanel bp = basePanel();
if (bp != null) {
groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
searchToggle.setSelected(sidePaneManager.isComponentVisible("search"));
previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED));
fetcherToggle.setSelected(sidePaneManager.isComponentVisible(generalFetcher.getTitle()));
Globals.focusListener.setFocused(bp.mainTable);
Expand Down Expand Up @@ -841,9 +834,6 @@ private void tearDownJabRef(Vector<String> filenames) {
Globals.autoSaveManager.clearAutoSaves();
}

// Let the search interface store changes to prefs.
searchBar.updatePrefs();

prefs.flush();

// dispose all windows, even if they are not displayed anymore
Expand Down Expand Up @@ -989,21 +979,9 @@ private void initLayout() {
gbl.setConstraints(contentPane, con);
getContentPane().add(contentPane);

JPanel main = new JPanel();
main.setLayout( new OverlayLayout(main) );
searchBar = new SearchBar(this);
searchBar.setAlignmentX(1.0f);
searchBar.setAlignmentY(0.0f);
searchBar.setMaximumSize(new Dimension(400, 25));
main.add(searchBar);
setSearchBarVisible(Globals.prefs.getBoolean(JabRefPreferences.SEARCH_BAR_VISIBLE));
tabbedPane.setAlignmentX(1.0f);
tabbedPane.setAlignmentY(0.0f);
main.add(tabbedPane);

UIManager.put("TabbedPane.contentBorderInsets", new Insets(0,0,0,0));

contentPane.setRightComponent(main);
contentPane.setRightComponent(tabbedPane);
contentPane.setLeftComponent(sidePaneManager.getPanel());
sidePaneManager.updateView();

Expand Down Expand Up @@ -1324,7 +1302,6 @@ private void fillMenu() {
view.add(decreseFontSize);
view.addSeparator();
view.add(toggleToolbar);
view.add(toggleSearch);
view.add(generalFetcher.getAction());
view.add(toggleGroups);
view.add(togglePreview);
Expand Down Expand Up @@ -1490,9 +1467,6 @@ private void createToolBar() {
tlb.addSeparator();
}

searchToggle = new JToggleButton(toggleSearch);
tlb.addJToogleButton(searchToggle);

fetcherToggle = new JToggleButton(generalFetcher.getAction());
tlb.addJToogleButton(fetcherToggle);

Expand Down Expand Up @@ -1555,7 +1529,7 @@ private void initActions() {
openDatabaseOnlyActions.addAll(Arrays.asList(manageSelectors,
mergeDatabaseAction, newSubDatabaseAction, close, save, saveAs, saveSelectedAs, saveSelectedAsPlain, undo,
redo, cut, delete, copy, paste, mark, unmark, unmarkAll, editEntry,
selectAll, copyKey, copyCiteKey, copyKeyAndTitle, editPreamble, editStrings, toggleGroups, toggleSearch,
selectAll, copyKey, copyCiteKey, copyKeyAndTitle, editPreamble, editStrings, toggleGroups,
makeKeyAction, normalSearch, mergeEntries, cleanupEntries, exportToClipboard,
replaceAll, sendAsEmail, downloadFullText, writeXmpAction,
findUnlinkedFiles, addToGroup, removeFromGroup, moveToGroup, autoLinkFile, resolveDuplicateKeys,
Expand Down Expand Up @@ -2355,21 +2329,6 @@ public void showMessage(String message) {
JOptionPane.showMessageDialog(this, message);
}

public SearchBar getSearchBar() {
return searchBar;
}

public void setSearchBarVisible(boolean visible) {
searchBar.setVisible(visible);
searchToggle.setSelected(visible);
if(visible) {
setTabAreaInsets(tabbedPane, new Insets(3, 2, 2, 250));
} else {
setTabAreaInsets(tabbedPane, new Insets(3, 2, 2, 2));
}
}


// Copied from org.pushingpixels.lafwidget.LafWidgetSupport
// http://jarvis.cs.ucdavis.edu/code_essence/functions/5829321
// We need to use reflection to change the tabAreaInsets since a TappedPaneUI does not provide an easier way to set this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ private void instantiatePreviews() {
new PreviewPanel(panel.database(), null, panel, panel.metaData(), Globals.prefs
.get(JabRefPreferences.PREVIEW_1), true)};

panel.frame().getSearchBar().addSearchListener(previewPanel[0]);
panel.frame().getSearchBar().addSearchListener(previewPanel[1]);
// TODO SIMON
//panel.frame().getSearchBar().addSearchListener(previewPanel[0]);
//panel.frame().getSearchBar().addSearchListener(previewPanel[1]);
}

public void updatePreviews() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/sf/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class Actions {
public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ANY = "toggleHighlightGroupsMatchingAny";
public static final String TOGGLE_GROUPS = "toggleGroups";
public static final String TOGGLE_PREVIEW = "togglePreview";
public static final String TOGGLE_SEARCH = "toggleSearch";
public static final String TOGGLE_TOOLBAR = "toggleToolbar";
public static final String UNABBREVIATE = "unabbreviate";
public static final String UNDO = "undo";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ public void actionPerformed(ActionEvent actionEvent) {

private void setupSourcePanel() {
source = new JTextAreaWithHighlighting();
frame.getSearchBar().addSearchListener((SearchTextListener) source);
// TODO SIMON
// frame.getSearchBar().addSearchListener((SearchTextListener) source);

source.setEditable(true);
source.setLineWrap(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,15 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
defaultHeight = 0;
} else {
fieldEditor = new TextArea(fields[i], null);
frame.getSearchBar().addSearchListener((TextArea) fieldEditor);
// TODO SIMON
// frame.getSearchBar().addSearchListener((TextArea) fieldEditor);
defaultHeight = fieldEditor.getPane().getPreferredSize().height;
}

JComponent extra = parent.getExtra(fields[i], fieldEditor);

// Add autocompleter listener, if required for this field:
AutoCompleter autoCompleter = bPanel.getAutoCompleters().get(fields[i]);
AutoCompleter<String> autoCompleter = bPanel.getAutoCompleters().get(fields[i]);
AutoCompleteListener autoCompleteListener = null;
if (autoCompleter != null) {
autoCompleteListener = new AutoCompleteListener(autoCompleter);
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/net/sf/jabref/gui/search/GlobalSearchWorker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package net.sf.jabref.gui.search;

import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibtexEntry;

import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

class GlobalSearchWorker extends AbstractWorker {

private final JabRefFrame frame;
private final SearchQuery searchQuery;
private final SearchResultsDialog dialog;

public GlobalSearchWorker(JabRefFrame frame, SearchQuery query) {
this.frame = Objects.requireNonNull(frame);
this.searchQuery = Objects.requireNonNull(query);

dialog = new SearchResultsDialog(frame,
Localization.lang("Search results in all databases for %0",
this.searchQuery.toString()));
}

/* (non-Javadoc)
* @see net.sf.jabref.Worker#run()
*/
@Override
public void run() {
// Search all databases
for (int i = 0; i < frame.getTabbedPane().getTabCount(); i++) {
BasePanel basePanel = frame.baseAt(i);
for (BibtexEntry entry : basePanel.getDatabase().getEntries()) {
boolean hit = searchQuery.rule.applyRule(searchQuery.query, entry);
if (hit) {
dialog.addEntry(entry, basePanel);
}
}
}
}

/* (non-Javadoc)
* @see net.sf.jabref.AbstractWorker#update()
*/
@Override
public void update() {
dialog.selectFirstEntry();
dialog.setVisible(true);
}

}
4 changes: 3 additions & 1 deletion src/main/java/net/sf/jabref/gui/search/JSearchTextField.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.sf.jabref.gui.search;

import net.sf.jabref.logic.l10n.Localization;

import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
Expand All @@ -17,7 +19,7 @@ public JSearchTextField() {
super();
this.setEditable(true);
this.setText("");
this.textWhenNotFocused = "Search...";
this.textWhenNotFocused = Localization.lang("Search...");
this.addFocusListener(this);
}

Expand Down
Loading

0 comments on commit a2b0588

Please sign in to comment.