2 FAR manager incremental search plugin, search as you type in editor.
3 Copyright (C) 1999-2019, Stanislav V. Mekhanoshin
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
20 static const TCHAR sDirIncSearch
[] =
21 #if defined(WINPORT_DIRECT)
22 _T("/Incremental Search");
24 _T("\\Incremental Search");
27 static const TCHAR sHlfConfig
[] = _T("Cfg");
28 static const TCHAR sHlfMenu
[] = _T("Menu");
31 FARAPIGETMSG apiGetMsg
;
34 FARAPIEDITORCONTROL apiEditorControl
;
35 #ifdef VIEWVER_SUPPORT
36 FARAPIVIEWERCONTROL apiViewerControl
;
37 int iViewerStatusColor
;
39 #if defined(WINPORT_DIRECT)
40 FARAPIDIALOGINIT apiDialogInit
;
41 FARAPIDIALOGRUN apiDialogRun
;
42 FARAPIDIALOGFREE apiDialogFree
;
43 FARAPISENDDLGMESSAGE apiSendDlgMessage
;
44 FARSTDSNPRINTF apiSnprintf
;
46 FARAPIDIALOG apiDialog
;
47 FARAPICHARTABLE apiCharTable
;
53 #if !defined(WINPORT_DIRECT)
57 KbdCommand aEvents
[PREVIEW_EVENTS
];
60 static TCHAR PluginRootKey
[_MAX_PATH
];
62 BOOL bThisUseSelection
;
65 BOOL bReverse
= FALSE
;
67 BOOL bCaseSensitive
= FALSE
;
68 BOOL bKeepSelection
= TRUE
;
69 BOOL bBeepOnMismatch
= FALSE
;
70 BOOL bRestartEOF
= FALSE
;
71 BOOL bUseSelection
= TRUE
;
72 BOOL bAutoNext
= FALSE
;
73 BOOL bBSunroll
= TRUE
;
79 #if !defined(WINPORT_DIRECT)
80 struct EditorConvertText ect
;
82 struct EditorSetPosition esp
;
83 struct EditorGetString egs
;
85 void RestoreConfig(void);
86 void SaveConfig(void);
88 #if !defined(WINPORT_DIRECT)
97 void __plugin WINAPI
EXP_NAME(SetStartupInfo
)(const struct PluginStartupInfo
*pInfo
)
99 ModuleNumber
= pInfo
->ModuleNumber
;
100 apiMenu
= pInfo
->Menu
;
101 apiGetMsg
= pInfo
->GetMsg
;
102 #if defined(WINPORT_DIRECT)
103 apiDialogInit
= pInfo
->DialogInit
;
104 apiDialogRun
= pInfo
->DialogRun
;
105 apiDialogFree
= pInfo
->DialogFree
;
106 apiSendDlgMessage
= pInfo
->SendDlgMessage
;
107 apiSnprintf
= pInfo
->FSF
->snprintf
;
109 apiDialog
= pInfo
->Dialog
;
110 apiCharTable
= pInfo
->CharTable
;
112 apiText
= pInfo
->Text
;
113 apiEditorControl
= pInfo
->EditorControl
;
114 _tstrcpy(PluginRootKey
, pInfo
->RootKey
);
115 _tstrcpy(PluginRootKey
+ _tstrlen(PluginRootKey
), sDirIncSearch
);
116 #ifdef VIEWVER_SUPPORT
117 apiViewerControl
= pInfo
->ViewerControl
;
118 iViewerStatusColor
= pInfo
->AdvControl(ModuleNumber
, ACTL_GETCOLOR
, (void *)COL_VIEWERSTATUS
);
123 int __plugin WINAPI
EXP_NAME(Configure
)(int ItemNumber
)
125 struct FarDialogItem DialogItems
[11];
126 static DialogTemplateItem DialogTemplate
[10] = {
127 {DI_CHECKBOX
, 5, 2, FALSE
, DIFT_MSGNUM
, MCaseSensitive
},
128 {DI_CHECKBOX
, 5, 3, FALSE
, DIFT_MSGNUM
, MRestartEOF
},
129 {DI_CHECKBOX
, 5, 4, FALSE
, DIFT_MSGNUM
, MKeepSelection
},
130 {DI_CHECKBOX
, 5, 5, FALSE
, DIFT_MSGNUM
, MBeepOnMismatch
},
131 {DI_CHECKBOX
, 5, 6, FALSE
, DIFT_MSGNUM
, MUseSelection
},
132 {DI_CHECKBOX
, 5, 7, FALSE
, DIFT_MSGNUM
, MAutoNext
},
133 {DI_CHECKBOX
, 5, 8, FALSE
, DIFT_MSGNUM
, MBSunroll
},
134 {DI_TEXT
, 5, 9, FALSE
, DIF_BOXCOLOR
| DIF_SEPARATOR
, 0 },
135 {DI_BUTTON
, 5, 10, FALSE
, DIF_CENTERGROUP
| DIFT_MSGNUM
, MOk
},
136 {DI_BUTTON
, 5, 10, FALSE
, DIF_CENTERGROUP
| DIFT_MSGNUM
, MCancel
}
141 DialogTemplate
[0].Selected
= (signed char)bCaseSensitive
;
142 DialogTemplate
[1].Selected
= (signed char)bRestartEOF
;
143 DialogTemplate
[2].Selected
= (signed char)bKeepSelection
;
144 DialogTemplate
[3].Selected
= (signed char)bBeepOnMismatch
;
145 DialogTemplate
[4].Selected
= (signed char)bUseSelection
;
146 DialogTemplate
[5].Selected
= (signed char)bAutoNext
;
147 DialogTemplate
[6].Selected
= (signed char)bBSunroll
;
149 if (DialogFromTemplate(GetMsg(MIncSearch
), DialogTemplate
, DialogItems
,
150 sizeof(DialogItems
) / sizeof(DialogItems
[0]), (TCHAR
*)sHlfConfig
, 1, 9)
154 bCaseSensitive
= DialogItems
[1].Selected
;
155 bRestartEOF
= DialogItems
[2].Selected
;
156 bKeepSelection
= DialogItems
[3].Selected
;
157 bBeepOnMismatch
= DialogItems
[4].Selected
;
158 bUseSelection
= DialogItems
[5].Selected
;
159 bAutoNext
= DialogItems
[6].Selected
;
160 bBSunroll
= DialogItems
[7].Selected
;
166 void __plugin WINAPI
EXP_NAME(GetPluginInfo
)(struct PluginInfo
*Info
)
168 static const TCHAR
*sPtr
;
170 sPtr
= GetMsg(MIncSearch
);
171 Info
->StructSize
= sizeof(*Info
);
173 #ifdef VIEWVER_SUPPORT
176 PF_DISABLEPANELS
| PF_EDITOR
;
177 Info
->DiskMenuStringsNumber
= 0;
178 Info
->PluginMenuStrings
= &sPtr
;
179 Info
->PluginMenuStringsNumber
= 1;
180 Info
->PluginConfigStrings
= &sPtr
;
181 Info
->PluginConfigStringsNumber
= 1;
184 HANDLE __plugin WINAPI
EXP_NAME(OpenPlugin
)(int OpenFrom
, INT_PTR Item
)
186 struct FarMenuItem aMenuItems
[7];
192 bThisUseSelection
= bUseSelection
;
193 bThisAutoNext
= bAutoNext
;
194 bStopOnFound
= FALSE
;
196 zeromem(aMenuItems
, sizeof(aMenuItems
));
197 #if defined(WINPORT_DIRECT)
198 aMenuItems
[0].Text
= GetMsg(MSearchForward
);
199 aMenuItems
[1].Text
= GetMsg(MSearchBackward
);
201 _tstrcpy(aMenuItems
[0].Text
, GetMsg(MSearchForward
));
202 _tstrcpy(aMenuItems
[1].Text
, GetMsg(MSearchBackward
));
204 aMenuItems
[2].Separator
= TRUE
;
205 if (OpenFrom
== OPEN_EDITOR
) {
206 #if defined(WINPORT_DIRECT)
207 aMenuItems
[3].Text
= GetMsg(MFindNext
);
208 aMenuItems
[4].Text
= GetMsg(MFindPrevious
);
210 _tstrcpy(aMenuItems
[3].Text
, GetMsg(MFindNext
));
211 _tstrcpy(aMenuItems
[4].Text
, GetMsg(MFindPrevious
));
213 aMenuItems
[5].Separator
= TRUE
;
214 nItems
= sizeof(aMenuItems
) / sizeof(aMenuItems
[0]);
218 #if defined(WINPORT_DIRECT)
219 aMenuItems
[nItems
- 1].Text
= GetMsg(MSetup
);
221 _tstrcpy(aMenuItems
[nItems
- 1].Text
, GetMsg(MSetup
));
223 aMenuItems
[bReverse
? 1 : 0].Selected
= TRUE
;
225 switch (apiMenu(ModuleNumber
, -1, -1, 0, FMENU_WRAPMODE
, GetMsg(MIncSearch
), NULL
, (TCHAR
*)sHlfMenu
,
226 NULL
, NULL
, aMenuItems
, nItems
)) {
234 if (OpenFrom
== OPEN_EDITOR
) {
240 bThisUseSelection
= TRUE
;
241 bThisAutoNext
= TRUE
;
246 EXP_NAME(Configure
)(0);
249 return INVALID_HANDLE_VALUE
;
251 if (OpenFrom
== OPEN_EDITOR
)
253 #ifdef VIEWVER_SUPPORT
257 return INVALID_HANDLE_VALUE
;