-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcudalister.lpr
221 lines (190 loc) · 5.21 KB
/
cudalister.lpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
library CudaLister;
{$mode objfpc}{$H+}
uses
Windows, SysUtils, Forms, Interfaces,
Controls,
FileUtil,
StrUtils,
IniFiles,
file_proc,
form_main,
form_options, proc_themes, form_listbox;
const
cDetectString: string = '';
BusyClose: boolean = false;
const
LISTPLUGIN_OK = 0;
LISTPLUGIN_ERROR = 1;
lc_copy = 1;
lc_newparams = 2;
lc_selectall = 3;
lc_setpercent = 4;
lcp_wraptext = 1;
lcp_fittowindow = 2;
lcp_ansi = 4;
lcp_ascii = 8;
lcp_variable = 12;
lcp_forceshow = 16;
lcs_findfirst = 1;
lcs_matchcase = 2;
lcs_wholewords = 4;
lcs_backwards = 8;
itm_percent = $FFFE;
itm_fontstyle = $FFFD;
itm_wrap = $FFFC;
itm_fit = $FFFB;
procedure LoadGlobalOptions;
begin
with TIniFile.Create(ListerIniFilename) do
try
OptNoCaret:= ReadBool(ListerIniSection, 'no_caret', false);
OptOnlyKnownTypes:= ReadBool(ListerIniSection, 'only_known_types', false);
OptMaxFileSizeMb:= ReadInteger(ListerIniSection, 'max_size', OptMaxFileSizeMb);
OptThemeUi:= ReadString(ListerIniSection, 'theme_ui', '-');
OptThemeSyntax:= ReadString(ListerIniSection, 'theme_syntax', '-');
finally
Free
end;
end;
procedure ListGetDetectString(DetectString: PChar; MaxLen: integer); stdcall;
begin
StrLCopy(DetectString, PChar(cDetectString), MaxLen);
end;
function ListLoadW(ListerWin: HWND; FileNamePtr: PWideChar; ShowFlags: integer): HWND; stdcall;
var
fn: string;
begin
Result:= 0;
LoadGlobalOptions;
fn:= UTF8Encode(WideString(FileNamePtr));
if not FileExists(fn) then exit;
if IsFileTooBig(fn) then exit;
if not IsFileText(fn) then exit;
if not IsCheckedLexerForFilename(fn) then exit;
Result := TfmMain.PluginShow(ListerWin, fn
//(ShowFlags and lcp_wraptext)<>0
);
end;
function ListLoad(ListerWin: HWND; FileNamePtr: PChar; ShowFlags: integer): HWND; stdcall;
begin
Result:= ListLoadW(ListerWin, PWideChar(WideString(string(FileNamePtr))), ShowFlags);
end;
procedure ListCloseWindow(PluginWin: HWND); stdcall;
begin
if BusyClose then exit;
BusyClose:= true;
TfmMain.PluginHide(PluginWin);
BusyClose:= false;
end;
type
TListDefaultParamStruct = record
size,
PluginInterfaceVersionLow,
PluginInterfaceVersionHi: DWORD;
DefaultIniName: array[0..MAX_PATH-1] of AnsiChar;
end;
pListDefaultParamStruct = ^TListDefaultParamStruct;
procedure ListSetDefaultParams(dps: pListDefaultParamStruct); stdcall;
begin
ListerIniFilename:= string(dps^.DefaultIniName);
end;
function ListLoadNextW(ParentWin, ListWin: HWND;
FileToLoad: PWideChar;
ShowFlags: integer): integer; stdcall;
var
fn: string;
Form: TfmMain;
begin
Result:= LISTPLUGIN_ERROR;
fn:= UTF8Encode(WideString(FileToLoad));
if (fn='') or (fn[Length(fn)]='\') then exit;
if IsFileTooBig(fn) then exit;
if not IsFileText(fn) then exit;
Form:= TfmMain(FindControl(ListWin));
if Assigned(Form) then
begin
Form.ConfirmSave;
Form.FileOpen(fn);
Result:= LISTPLUGIN_OK;
end;
end;
function ListLoadNext(ParentWin, ListWin: HWND;
FileToLoad: PChar;
ShowFlags: integer): integer; stdcall;
begin
Result:= ListLoadNextW(ParentWin, ListWin,
PWideChar(WideString(string(FileToLoad))), ShowFlags);
end;
function ListSendCommand(ListWin: HWND;
Command, Parameter: integer): integer; stdcall;
var
Form: TfmMain;
begin
Result:= LISTPLUGIN_OK;
Form:= TfmMain(FindControl(ListWin));
if Form=nil then exit;
case Command of
lc_copy:
Form.mnuTextCopyClick(nil);
lc_selectall:
Form.mnuTextSelClick(nil);
lc_setpercent:
begin
Form.ed.LineTop:= Form.ed.Strings.Count*Parameter div 100;
PostMessage(ListWin, WM_COMMAND, MAKELONG(Parameter, itm_percent), Form.Handle);
end;
lc_newparams:
begin
Form.SetWrapMode((Parameter and lcp_wraptext)=lcp_wraptext);
////don't change encoding for A/S keys, otherwise W(wrap) key will change enc too
//if (Parameter and lcp_ansi)=lcp_ansi then
// Form.SetEncodingName(cEncNameAnsi);
//if (Parameter and lcp_ascii)=lcp_ascii then
// Form.SetEncodingName(cEncNameOem);
end;
end;
end;
function ListSearchTextW(ListWin: HWND;
SearchString: PWideChar;
SearchParameter: integer): integer; stdcall;
var
Form: TfmMain;
begin
Result:= LISTPLUGIN_OK;
Form:= TfmMain(FindControl(ListWin));
if Assigned(Form) then
begin
Form.DoFind(
(SearchParameter and lcs_findfirst)=0,
(SearchParameter and lcs_backwards)<>0,
(SearchParameter and lcs_matchcase)<>0,
(SearchParameter and lcs_wholewords)<>0,
WideString(SearchString)
);
Form.Finder.StrFind:= SearchString;
end;
end;
function ListSearchText(ListWin: HWND;
SearchString: PChar;
SearchParameter: integer): integer; stdcall;
begin
Result:= ListSearchTextW(ListWin,
PWideChar(WideString(string(SearchString))),
SearchParameter);
end;
exports
ListSetDefaultParams,
ListGetDetectString,
ListLoad,
ListLoadW,
ListLoadNext,
ListLoadNextW,
ListCloseWindow,
ListSendCommand,
ListSearchText,
ListSearchTextW;
begin
Application.ShowHint:= false;
Application.ShowButtonGlyphs:= sbgNever;
Application.Initialize;
end.