Search bar: recent images and macros now included as search terms · tannerhelland/PhotoDemon@e2c17ea · GitHub
Skip to content

Commit e2c17ea

Browse files
committed
Search bar: recent images and macros now included as search terms
For keyboard power users, this makes it extremely fast to load a recent image or macro - type Ctrl+F, some characters from the filename, and Enter!
1 parent 8a8160e commit e2c17ea

7 files changed

Lines changed: 169 additions & 68 deletions

File tree

‎Classes/pdMRUManager.cls‎

Lines changed: 30 additions & 42 deletions

‎Classes/pdRecentFiles.cls‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ Friend Function GetNumOfItems() As Long
490490
End Function
491491

492492
Private Sub InternalError(ByVal errText As String)
493-
PDDebug.LogAction "WARNING! pdRecentFiles has a problem: " & errText
493+
PDDebug.LogAction "WARNING! pdRecentFiles problem: " & errText
494494
End Sub
495495

496496
Private Sub Class_Initialize()

‎Forms/Layerpanel_Search.frm‎

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,21 @@ Option Explicit
6565
Private WithEvents lastUsedSettings As pdLastUsedSettings
6666
Attribute lastUsedSettings.VB_VarHelpID = -1
6767

68-
'Some search terms are managed by the menu manager. Others are managed by the tool manager.
68+
'Some search terms are managed by the menu manager; other, the tool manager or a miscellaneous catcha-ll.
6969
' We want to condense these into a single list of search terms, and when a search result is returned,
7070
' we'll match it up against its relevant source stack.
7171
Private m_AllSearchTerms As pdStringStack
7272
Private m_MenuSearchTerms As pdStringStack
73+
74+
'Menus can auto-map between searchable text and underlying query ID. Tools and miscellaneous targets cannot,
75+
' so we need to store *two* stacks per category - one for human-readable search terms, and another for
76+
' tool action IDs.
7377
Private m_ToolSearchTerms As pdStringStack
7478
Private m_ToolActions As pdStringStack
7579

80+
Private m_MiscSearchTerms As pdStringStack
81+
Private m_MiscActions As pdStringStack
82+
7683
Private Sub Form_Load()
7784

7885
'Load any last-used settings for this form
@@ -132,8 +139,13 @@ Private Sub Form_Resize()
132139
ReflowInterface
133140
End Sub
134141

142+
'If the search box does not have focus, give it focus. If it already has focus, select all text.
135143
Public Sub SetFocusToSearchBox()
136-
srchMain.SetFocusToSearchBox
144+
If srchMain.HasFocus() Then
145+
srchMain.SelectAll
146+
Else
147+
srchMain.SetFocusToSearchBox
148+
End If
137149
End Sub
138150

139151
Private Sub lastUsedSettings_ReadCustomPresetData()
@@ -144,13 +156,30 @@ Private Sub srchMain_Click(bestSearchHit As String)
144156

145157
srchMain.Text = bestSearchHit
146158

147-
If (m_MenuSearchTerms.ContainsString(bestSearchHit) >= 0) Then
159+
'Because the search term can come from one of three stacks (menus, tools, misc), we need to identify
160+
' which stack the current search term originated from to best know where to trigger its associated action.
161+
162+
'Check the menu stack first
163+
Dim idxQuery As Long
164+
idxQuery = m_MenuSearchTerms.ContainsString(bestSearchHit, True)
165+
166+
If (idxQuery >= 0) Then
148167
Actions.LaunchAction_BySearch bestSearchHit
149168

150-
'If the search result is *not* a menu, the menu module can't auto-map it to a corresponding
151-
' action string. Return the action string instead.
152169
Else
153-
Actions.LaunchAction_ByName m_ToolActions.GetString(m_ToolSearchTerms.ContainsString(bestSearchHit, True)), pdas_Search
170+
171+
'Check the tool stack next
172+
idxQuery = m_ToolSearchTerms.ContainsString(bestSearchHit, True)
173+
If (idxQuery >= 0) Then
174+
Actions.LaunchAction_ByName m_ToolActions.GetString(idxQuery), pdas_Search
175+
Else
176+
177+
'Finally, check the miscellaneous stack
178+
idxQuery = m_MiscSearchTerms.ContainsString(bestSearchHit, True)
179+
Actions.LaunchAction_ByName m_MiscActions.GetString(idxQuery), pdas_Search
180+
181+
End If
182+
154183
End If
155184

156185
'Before exiting, update the search list as available items may have changed.
@@ -169,12 +198,20 @@ End Sub
169198

170199
Private Sub UpdateSearchTerms()
171200

201+
'Start with menu-based search terms
172202
Set m_AllSearchTerms = New pdStringStack
173203
Menus.GetSearchableMenuList m_MenuSearchTerms
174204
m_AllSearchTerms.CloneStack m_MenuSearchTerms
175205

206+
'Add tool search terms
176207
toolbar_Toolbox.GetListOfToolNamesAndActions m_ToolSearchTerms, m_ToolActions
177208
m_AllSearchTerms.AppendStack m_ToolSearchTerms
209+
210+
'Add misc search terms
211+
Actions.GetMiscellaneousSearchActions m_MiscSearchTerms, m_MiscActions
212+
m_AllSearchTerms.AppendStack m_MiscSearchTerms
213+
214+
'Forward the full list to the search box
178215
srchMain.SetSearchList m_AllSearchTerms
179216

180217
End Sub

‎Forms/MainWindow.frm‎

Lines changed: 1 addition & 8 deletions

0 commit comments

Comments
 (0)