This topic explains how to initialize search fields from scripting in navigator or search dialog boxes.
In the first two examples we want to put content in the Title, Edition and Library fields on the search panes on the Pages navigator and Library navigators of the Pages main tab.
The context is defined as sw (ShellWindow). If there's one (If (sw IsNot Nothing)), an empty values list IdName is defined first (Dim values As New List(Of Common.IdName)), and then the values are added, one by one), as ids. The ids below are just as example. Dim sw As IShellWindow = ShellWindow If (sw IsNot Nothing) Then Dim values As New List(Of Common.IdName) values.Add(New Common.IdName(21, "title")) values.Add(New Common.IdName(567, "edition")) values.Add(New Common.IdName(456, "lib")) sw.SetElementOnSearch(values, False) End If If you want to use global variables, e.g. for last used values, use this code: Dim sw As IShellWindow = ShellWindow If (sw IsNot Nothing) Then Dim values As New List(Of Common.IdName) If SystemUserOptions.F_LastTitle <> 0 Then values.Add(New Common.IdName(SystemUserOptions.F_LastTitle, "title")) End If If SystemUserOptions.F_LastEdition <> 0 Then values.Add(New Common.IdName(SystemUserOptions.F_LastEdition, "edition")) End If If SystemUserOptions.F_LastObjLib <> 0 Then values.Add(New Common.IdName(SystemUserOptions.F_LastObjLib, "lib")) End If sw.SetElementOnSearch(values, False) End If For more information, see 'Last used' values in navigators between sessions. |
In Fred.vb, in the Public Sub AddPagesTabItem(), the values are loaded when you load the Pages main tab. Public Sub AddPagesTabItem() Dim tab As IShellTabItem = NewTab("Fred4Pages") If Not SystemUserOptions.fr_NoDefToolbars Then ShowDefToolbarsPages() End If ' restore settings If tab IsNot Nothing Then If SystemUserOptions.F_LastTitle <> 0 Then tab.SetElementOnSearch("title", SystemUserOptions.F_LastTitle) End If If SystemUserOptions.F_LastEdition <> 0 Then tab.SetElementOnSearch("edition", SystemUserOptions.F_LastEdition) End If If SystemUserOptions.F_LastObjLib <> 0 Then tab.SetElementOnSearch("lib", SystemUserOptions.F_LastObjLib) End If End If End Sub For more information, see 'Last used' values in navigators between sessions. |
The script below inserts the word Hello in the full text search field on a navigator on the Shell main tab. It should be pasted in Shell.vb in the MainAddin class (in a new sub), e.g: Public Sub SetFullText() Dim navTab As NavigatorTabItem = GetNavigatorTabItem()
If navTab IsNot Nothing Then Dim navTabSearchCriteria As SearchCriteria = navTab.SearchCriteria
Dim searchConditions As ShellSearchConditions = navTabSearchCriteria.SearchConditions
For Each search As ShellSearchCondition In searchConditions.List
If search.Path = "FullText" Then search.FromValue = "Hello" End If Next End If End Sub |
In this example, we want to initialize the "Name" field with the "z" string in a search dialog box that searches for txt objects, and execute the search:
Dim dlg As New SelectObjDialog(win)
dlg.SearchCriteria.SearchSettings = New SearchSettingList() From {
New SearchSetting() With {.Path = "[txt.name]", .FromValue = "z", .Op = OpCode.Starting, .IdList = New List(Of IdName)}
}
In this example, we want to initialize the "Name" field with the "z" string and the folder drop-down box with the id = 3446 in a search dialog box that searches for txt objects, and execute the search:
Dim dlg As New SelectObjDialog(win)
dlg.SearchCriteria.SearchSettings = New SearchSettingList() From {
New SearchSetting() With {.Path = "[txt.name]", .FromValue = "z", .Op = OpCode.Starting, .IdList = New List(Of IdName)},
SearchSetting.CreateReference("[txt.folderRef]", New Integer() {3446})
}
See also
Getting data from navigator search fields