#15051 closed enhancement (fixed)
Add help button to "Search for Objects by Preset"
| Reported by: | jidanni | Owned by: | team |
|---|---|---|---|
| Priority: | normal | Milestone: | 20.05 |
| Component: | Core | Version: | |
| Keywords: | search preset help focus traversal | Cc: | Klumbumbus, stoecker, GerdP |
Description
Search has a Help button, but "Search for Objects by Preset" doesn't.
Some people's first search is Search for Objects by Preset, not plain Search. So Help is needed.
Attachments (0)
Change History (24)
comment:1 by , 7 years ago
| Milestone: | → 19.01 |
|---|
comment:2 by , 7 years ago
| Cc: | added |
|---|---|
| Summary: | Search has a Help button, but Search for Objects by Preset doesn't → Add help button to "Search for Objects by Preset" |
comment:3 by , 7 years ago
I wonder if the "Search for Objects by Preset" window is still needed since it was integrated in the default search window too.
comment:4 by , 7 years ago
Good point. The only argument I found after some testing is that "Search for Objects by Preset" can be operated quickly using the keyboard only:
[Ctrl]+F3–tree–[Enter][Ctrl]+F– 6×[Tab]–tree–[Enter]– does not work (i.e., select everything) since a preset must be double-clicked in order to obtain the search phrasepreset:"Geography/Nature/Tree"
We could try to address this issue (tabindex, respect selected preset items for empty search phrase) and then remove "Search for Objects by Preset".
comment:5 by , 7 years ago
| Milestone: | 19.01 → 19.02 |
|---|
comment:6 by , 7 years ago
| Cc: | removed |
|---|---|
| Keywords: | search preset help added |
| Milestone: | 19.02 → 19.03 |
| Priority: | trivial → normal |
comment:8 by , 7 years ago
| Cc: | added |
|---|---|
| Keywords: | focus traversal added |
@team: I spent an hour trying to customize focus traversal without success, I think it's a lot simpler to put the preset list on the left side of the search dialog instead of on the right. This way the focus will work by itself. Any objection?
Below my (failed) attempt:
-
SearchDialog.java
3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 7 import java.awt.Container; 6 8 import java.awt.Cursor; 7 9 import java.awt.Dimension; 8 10 import java.awt.FlowLayout; 11 import java.awt.FocusTraversalPolicy; 9 12 import java.awt.GridBagLayout; 10 13 import java.awt.event.ActionEvent; 11 14 import java.awt.event.MouseAdapter; 12 15 import java.awt.event.MouseEvent; 16 import java.util.ArrayList; 13 17 import java.util.Arrays; 14 18 import java.util.Collections; 15 19 import java.util.List; … … 52 56 private final SearchSetting searchSettings; 53 57 54 58 private final HistoryComboBox hcbSearchString = new HistoryComboBox(); 59 private final TaggingPresetSelector selector = new TaggingPresetSelector(false, false); 55 60 private final JCheckBox addOnToolbar = new JCheckBox(tr("add toolbar button"), false); 56 61 57 62 private JCheckBox caseSensitive; … … 83 88 setContent(buildPanel(searchExpressionHistory, expertMode)); 84 89 } 85 90 91 private static void addFocusableComponents(List<Component> order, Component c) { 92 if (c.isFocusable()) { 93 order.add(c); 94 } 95 if (c instanceof Container) { 96 for (Component child : ((Container) c).getComponents()) { 97 addFocusableComponents(order, child); 98 } 99 } 100 } 101 102 private static void setFocusTraversalOrder(Container container, List<Component> components) { 103 104 List<Component> order = new ArrayList<>(); 105 components.forEach(c -> addFocusableComponents(order, c)); 106 107 container.setFocusCycleRoot(true); 108 container.setFocusTraversalPolicy(new FocusTraversalPolicy() { 109 110 @Override 111 public Component getFirstComponent(Container aContainer) { 112 return order.get(0); 113 } 114 115 @Override 116 public Component getLastComponent(Container aContainer) { 117 return order.get(order.size() - 1); 118 } 119 120 @Override 121 public Component getDefaultComponent(Container aContainer) { 122 return order.get(0); 123 } 124 125 @Override 126 public Component getComponentBefore(Container aContainer, Component aComponent) { 127 int idx = order.indexOf(aComponent) - 1; 128 return order.get(idx < 0 ? order.size() - 1 : idx); 129 } 130 131 @Override 132 public Component getComponentAfter(Container aContainer, Component aComponent) { 133 return order.get((order.indexOf(aComponent) + 1) % order.size()); 134 } 135 }); 136 } 137 86 138 private JPanel buildPanel(List<String> searchExpressionHistory, boolean expertMode) { 87 139 88 140 // prepare the combo box with the search expressions … … 194 246 * selected preset by the user. Every query is of the form ' group/sub-group/.../presetName' 195 247 * if the corresponding group of the preset exists, otherwise it is simply ' presetName'. 196 248 */ 197 TaggingPresetSelector selector = new TaggingPresetSelector(false, false);198 249 selector.setBorder(BorderFactory.createTitledBorder(tr("Search by preset"))); 199 250 selector.setDblClickListener(ev -> setPresetDblClickListener(selector, editorComponent)); 200 251 … … 204 255 p.add(right, GBC.std().fill(GBC.BOTH).insets(0, 10, 0, 0)); 205 256 p.add(selector, GBC.eol().fill(GBC.BOTH).insets(0, 10, 0, 0)); 206 257 258 setFocusTraversalOrder(p, Arrays.asList(top, selector, left, right)); 259 207 260 return p; 208 261 } 209 262 … … 244 297 searchSettings.regexSearch = regexSearch.isSelected(); 245 298 searchSettings.mapCSSSearch = mapCSSSearch.isSelected(); 246 299 300 if (searchSettings.text.isEmpty()) { 301 searchSettings.text = presetSearchQuery(selector.getSelectedPreset()); 302 } 303 247 304 if (inSelection.isSelected()) { 248 305 searchSettings.mode = SearchMode.in_selection; 249 306 } else if (replace.isSelected()) { … … 364 421 } 365 422 366 423 /** 367 * 424 * Sets the preset list double-click handler that generates the associated search query 368 425 * @param selector Selector component that the user interacts with 369 426 * @param searchEditor Editor for search queries 370 427 */ … … 384 441 // invokeLater allows us to defer the selection until waiting for focus. 385 442 SwingUtilities.invokeLater(() -> { 386 443 int textOffset = searchEditor.getCaretPosition(); 387 String presetSearchQuery = " preset:" +388 "\"" + selectedPreset.getRawName() + "\"";389 444 try { 390 searchEditor.getDocument().insertString(textOffset, presetSearchQuery , null);445 searchEditor.getDocument().insertString(textOffset, presetSearchQuery(selectedPreset), null); 391 446 } catch (BadLocationException e1) { 392 447 throw new JosmRuntimeException(e1.getMessage(), e1); 393 448 } 394 449 }); 395 450 } 396 451 452 private static String presetSearchQuery(TaggingPreset selectedPreset) { 453 return selectedPreset != null ? " preset:\"" + selectedPreset.getRawName() + "\"" : ""; 454 } 455 397 456 private static class SearchKeywordRow extends JPanel { 398 457 399 458 private final HistoryComboBox hcb;
comment:9 by , 7 years ago
I think I don't like the idea to reorder this often used dialog. Up to now I did not even recognize the "search by preset" stuff.
With
[Ctrl]+F – 6×[Tab] – tree - [Down] – [Enter]
you get into the list. Would it be possible to bind a hotkey - e.g. [Tab]or [Space] - so that it creates the corresponding search entry?
comment:11 by , 7 years ago
| Milestone: | 19.03 → 19.04 |
|---|
comment:13 by , 7 years ago
| Milestone: | 19.04 → 19.05 |
|---|
comment:14 by , 7 years ago
| Milestone: | 19.05 |
|---|
follow-up: 17 comment:16 by , 6 years ago
| Milestone: | → 20.04 |
|---|
follow-up: 18 comment:17 by , 6 years ago
comment:18 by , 6 years ago
Replying to skyper:
Replying to simon04:
Think this should be moved to Help/Dialog/TaggingPresetSearchPrimitiveDialog
Should dialogs not be under Help/Dialog?
Is there any reason, to have it under wiki:Help/Action?
I would move it but I have no user rights to do it and the code needs to be changed anyway.
comment:19 by , 6 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
comment:20 by , 6 years ago
… should be documented analogously since they are both placed in the presets menu and use the same dialog structure



The problem is: we do not yet have a help page for this action. The closest one is Help/Action/TaggingPresetSearch.