1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: command.c 1487 2009-12-17 16:25:11Z gyoung $
|
---|
5 |
|
---|
6 | Custom commands
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2004, 2008 Steven H. Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
12 | 06 Jun 05 SHL Drop unused code
|
---|
13 | 14 Jul 06 SHL Use Runtime_Error
|
---|
14 | 29 Jul 06 SHL Use xfgets_bstripcr
|
---|
15 | 15 Aug 06 SHL Better can't add message
|
---|
16 | 18 Sep 06 GKY Add replace command and update okay to add if changed
|
---|
17 | 17 Feb 07 GKY Move error messages etc to string file
|
---|
18 | 22 Mar 07 GKY Use QWL_USER
|
---|
19 | 23 Mar 07 GKY Replace doesn't change item position
|
---|
20 | 23 Mar 07 GKY Okay fails silently when item not changed
|
---|
21 | 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
|
---|
22 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
23 | 06 Jan 08 GKY Use NormalizeCmdLine to check program strings on entry
|
---|
24 | 29 Feb 08 GKY Changes to enable user settable command line length
|
---|
25 | 29 Feb 08 GKY Use xfree where appropriate
|
---|
26 | 18 Jul 08 SHL Add Fortify support
|
---|
27 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
|
---|
28 | 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
|
---|
29 | 15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
|
---|
30 |
|
---|
31 | ***********************************************************************/
|
---|
32 |
|
---|
33 | #include <stdlib.h>
|
---|
34 | #include <string.h>
|
---|
35 | #include <share.h>
|
---|
36 |
|
---|
37 | #define INCL_DOS
|
---|
38 | #define INCL_WIN
|
---|
39 | #define INCL_LONGLONG // dircnrs.h
|
---|
40 |
|
---|
41 | #include "fm3dll.h"
|
---|
42 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
43 | #include "notebook.h" // Data declaration(s)
|
---|
44 | #include "init.h" // Data declaration(s)
|
---|
45 | #include "mainwnd.h" // Data declaration(s)
|
---|
46 | #include "newview.h" // Data declarations
|
---|
47 | #include "fm3dlg.h"
|
---|
48 | #include "fm3str.h"
|
---|
49 | #include "tools.h"
|
---|
50 | #include "arccnrs.h" // BldQuotedFileName
|
---|
51 | #include "errutil.h" // Dos_Error...
|
---|
52 | #include "strutil.h" // GetPString
|
---|
53 | #include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
|
---|
54 | #include "misc.h" // DrawTargetEmphasis
|
---|
55 | #include "systemf.h" // ExecOnList
|
---|
56 | #include "getnames.h" // insert_filename
|
---|
57 | #include "wrappers.h" // xfgets
|
---|
58 | #include "pathutil.h" // NormalizeCmdLine
|
---|
59 | #include "command.h"
|
---|
60 | #include "strips.h" // bstrip
|
---|
61 | #include "dirs.h" // save_dir2
|
---|
62 | #include "fortify.h"
|
---|
63 |
|
---|
64 | typedef struct
|
---|
65 | {
|
---|
66 | PSZ pszCmdLine;
|
---|
67 | CHAR title[100];
|
---|
68 | ULONG flags;
|
---|
69 | ULONG ID;
|
---|
70 | ULONG HotKeyID;
|
---|
71 | }
|
---|
72 | COMMAND;
|
---|
73 |
|
---|
74 | // Data defintions
|
---|
75 | #pragma data_seg(DATA1)
|
---|
76 |
|
---|
77 | static PSZ pszSrcFile = __FILE__;
|
---|
78 | static LINKCMDS *cmdtail;
|
---|
79 | static INT CommandDatVersion = 0;
|
---|
80 |
|
---|
81 | #pragma data_seg(GLOBAL2)
|
---|
82 | LINKCMDS *cmdhead;
|
---|
83 | BOOL cmdloaded;
|
---|
84 | BOOL UsedCommandIDs[300];
|
---|
85 | BOOL UsedHotKeyIDs[20];
|
---|
86 |
|
---|
87 | MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
88 | {
|
---|
89 | PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
90 | static BOOL emphasized = FALSE;
|
---|
91 |
|
---|
92 | switch (msg) {
|
---|
93 | case DM_DRAGOVER:
|
---|
94 | if (!emphasized) {
|
---|
95 | emphasized = TRUE;
|
---|
96 | DrawTargetEmphasis(hwnd, emphasized);
|
---|
97 | }
|
---|
98 | if (AcceptOneDrop(hwnd, mp1, mp2))
|
---|
99 | return MRFROM2SHORT(DOR_DROP, DO_MOVE);
|
---|
100 | return MRFROM2SHORT(DOR_NEVERDROP, 0);
|
---|
101 |
|
---|
102 | case DM_DRAGLEAVE:
|
---|
103 | if (emphasized) {
|
---|
104 | emphasized = FALSE;
|
---|
105 | DrawTargetEmphasis(hwnd, emphasized);
|
---|
106 | }
|
---|
107 | break;
|
---|
108 |
|
---|
109 | case DM_DROPHELP:
|
---|
110 | DropHelp(mp1, mp2, hwnd, GetPString(IDS_DROPCMDHELPTEXT));
|
---|
111 | return 0;
|
---|
112 |
|
---|
113 | case DM_DROP:
|
---|
114 | {
|
---|
115 | char szFrom[CCHMAXPATH + 5];
|
---|
116 |
|
---|
117 | if (emphasized) {
|
---|
118 | emphasized = FALSE;
|
---|
119 | DrawTargetEmphasis(hwnd, emphasized);
|
---|
120 | }
|
---|
121 | if (GetOneDrop(hwnd, mp1, mp2, szFrom, CCHMAXPATH)) {
|
---|
122 | strcat(szFrom, " %a");
|
---|
123 | WinSetWindowText(hwnd, szFrom);
|
---|
124 | }
|
---|
125 | }
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 | return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
|
---|
129 | WinDefWindowProc(hwnd, msg, mp1, mp2);
|
---|
130 | }
|
---|
131 |
|
---|
132 | MRESULT EXPENTRY ReOrderProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
133 | {
|
---|
134 | switch (msg) {
|
---|
135 | case WM_INITDLG:
|
---|
136 | if (!cmdhead) {
|
---|
137 | WinDismissDlg(hwnd, 0);
|
---|
138 | break;
|
---|
139 | }
|
---|
140 | {
|
---|
141 | LINKCMDS *info;
|
---|
142 | SHORT x;
|
---|
143 |
|
---|
144 | info = cmdhead;
|
---|
145 | while (info) {
|
---|
146 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_INSERTITEM,
|
---|
147 | MPFROMSHORT(LIT_END),
|
---|
148 | MPFROMP(info->title));
|
---|
149 | if (x < 0) {
|
---|
150 | Runtime_Error(pszSrcFile, __LINE__, "no cmd");
|
---|
151 | WinDismissDlg(hwnd, 0);
|
---|
152 | }
|
---|
153 | else {
|
---|
154 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SETITEMHANDLE,
|
---|
155 | MPFROMSHORT(x), MPFROMP(info));
|
---|
156 | }
|
---|
157 | info = info->next;
|
---|
158 | }
|
---|
159 | }
|
---|
160 | break;
|
---|
161 |
|
---|
162 | case WM_CONTROL:
|
---|
163 | return 0;
|
---|
164 |
|
---|
165 | case WM_COMMAND:
|
---|
166 | switch (SHORT1FROMMP(mp1)) {
|
---|
167 | case DID_CANCEL:
|
---|
168 | WinDismissDlg(hwnd, 0);
|
---|
169 | break;
|
---|
170 |
|
---|
171 | case DID_OK:
|
---|
172 | {
|
---|
173 | LINKCMDS *temphead = NULL, *info, *last = NULL, *temptail = NULL;
|
---|
174 | SHORT sSelect, numitems;
|
---|
175 |
|
---|
176 | sSelect = 0;
|
---|
177 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
178 | LM_QUERYITEMCOUNT,
|
---|
179 | MPVOID, MPVOID);
|
---|
180 | while (numitems) {
|
---|
181 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
182 | LM_QUERYITEMHANDLE,
|
---|
183 | MPFROMSHORT(sSelect++),
|
---|
184 | MPVOID);
|
---|
185 | if (info) {
|
---|
186 | if (!temphead) {
|
---|
187 | temphead = info;
|
---|
188 | info->prev = NULL;
|
---|
189 | }
|
---|
190 | else {
|
---|
191 | last->next = info;
|
---|
192 | info->prev = last;
|
---|
193 | }
|
---|
194 | temptail = info;
|
---|
195 | last = info;
|
---|
196 | info->next = NULL;
|
---|
197 | }
|
---|
198 | numitems--;
|
---|
199 | }
|
---|
200 | sSelect = 0;
|
---|
201 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
202 | LM_QUERYITEMCOUNT,
|
---|
203 | MPVOID, MPVOID);
|
---|
204 | while (numitems) {
|
---|
205 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
206 | LM_QUERYITEMHANDLE,
|
---|
207 | MPFROMSHORT(sSelect++),
|
---|
208 | MPVOID);
|
---|
209 | if (info) {
|
---|
210 | if (!temphead) {
|
---|
211 | temphead = info;
|
---|
212 | info->prev = NULL;
|
---|
213 | }
|
---|
214 | else {
|
---|
215 | last->next = info;
|
---|
216 | info->prev = last;
|
---|
217 | }
|
---|
218 | temptail = info;
|
---|
219 | last = info;
|
---|
220 | info->next = NULL;
|
---|
221 | }
|
---|
222 | numitems--;
|
---|
223 | }
|
---|
224 | cmdhead = temphead;
|
---|
225 | cmdtail = temptail;
|
---|
226 | }
|
---|
227 | WinDismissDlg(hwnd, 1);
|
---|
228 | break;
|
---|
229 |
|
---|
230 | case IDM_HELP:
|
---|
231 | if (hwndHelp)
|
---|
232 | WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
|
---|
233 | MPFROM2SHORT(HELP_REORDERCOMMANDS, 0),
|
---|
234 | MPFROMSHORT(HM_RESOURCEID));
|
---|
235 | break;
|
---|
236 |
|
---|
237 | case RE_ADD:
|
---|
238 | {
|
---|
239 | SHORT sSelect, x;
|
---|
240 | LINKCMDS *info;
|
---|
241 |
|
---|
242 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
243 | LM_QUERYSELECTION,
|
---|
244 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
245 | while (sSelect >= 0) {
|
---|
246 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
247 | LM_QUERYITEMHANDLE,
|
---|
248 | MPFROMSHORT(sSelect), MPVOID);
|
---|
249 | if (info) {
|
---|
250 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
251 | LM_INSERTITEM,
|
---|
252 | MPFROM2SHORT(LIT_END, 0),
|
---|
253 | MPFROMP(info->title));
|
---|
254 | if (x >= 0) {
|
---|
255 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
256 | LM_SETITEMHANDLE,
|
---|
257 | MPFROMSHORT(x), MPFROMP(info));
|
---|
258 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_DELETEITEM,
|
---|
259 | MPFROMSHORT(sSelect), MPVOID);
|
---|
260 | }
|
---|
261 | }
|
---|
262 | else
|
---|
263 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX, LM_SELECTITEM,
|
---|
264 | MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
|
---|
265 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
266 | LM_QUERYSELECTION,
|
---|
267 | MPFROMSHORT(LIT_FIRST),
|
---|
268 | MPVOID);
|
---|
269 | }
|
---|
270 | }
|
---|
271 | break;
|
---|
272 |
|
---|
273 | case RE_REMOVE:
|
---|
274 | {
|
---|
275 | SHORT sSelect, x;
|
---|
276 | LINKCMDS *info;
|
---|
277 |
|
---|
278 | sSelect = (SHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
279 | LM_QUERYSELECTION,
|
---|
280 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
281 | while (sSelect >= 0) {
|
---|
282 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
283 | LM_QUERYITEMHANDLE,
|
---|
284 | MPFROMSHORT(sSelect), MPVOID);
|
---|
285 | if (info) {
|
---|
286 | x = (SHORT) WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
287 | LM_INSERTITEM,
|
---|
288 | MPFROM2SHORT(LIT_END, 0),
|
---|
289 | MPFROMP(info->title));
|
---|
290 | if (x >= 0) {
|
---|
291 | WinSendDlgItemMsg(hwnd, RE_ADDLISTBOX,
|
---|
292 | LM_SETITEMHANDLE,
|
---|
293 | MPFROMSHORT(x), MPFROMP(info));
|
---|
294 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_DELETEITEM,
|
---|
295 | MPFROMSHORT(sSelect), MPVOID);
|
---|
296 | }
|
---|
297 | }
|
---|
298 | else
|
---|
299 | WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX, LM_SELECTITEM,
|
---|
300 | MPFROMSHORT(sSelect), MPFROMSHORT(FALSE));
|
---|
301 | sSelect = (USHORT) WinSendDlgItemMsg(hwnd, RE_REMOVELISTBOX,
|
---|
302 | LM_QUERYSELECTION,
|
---|
303 | MPFROMSHORT(LIT_FIRST),
|
---|
304 | MPVOID);
|
---|
305 | }
|
---|
306 | }
|
---|
307 | break;
|
---|
308 | }
|
---|
309 | return 0;
|
---|
310 | }
|
---|
311 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
312 | }
|
---|
313 |
|
---|
314 | CHAR *command_title(INT cx)
|
---|
315 | {
|
---|
316 | static CHAR duh[] = "???";
|
---|
317 | LINKCMDS *info;
|
---|
318 | INT x = 0;
|
---|
319 |
|
---|
320 | if (!cmdloaded)
|
---|
321 | load_commands();
|
---|
322 | info = cmdhead;
|
---|
323 | while (info) {
|
---|
324 | if (x == cx)
|
---|
325 | return info->title;
|
---|
326 | info = info->next;
|
---|
327 | }
|
---|
328 | return duh;
|
---|
329 | }
|
---|
330 |
|
---|
331 | VOID free_commands(VOID)
|
---|
332 | {
|
---|
333 | LINKCMDS *info, *next;
|
---|
334 |
|
---|
335 | info = cmdhead;
|
---|
336 | while (info) {
|
---|
337 | next = info->next;
|
---|
338 | xfree(info->title, pszSrcFile, __LINE__);
|
---|
339 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
---|
340 | free(info);
|
---|
341 | info = next;
|
---|
342 | }
|
---|
343 | cmdhead = cmdtail = NULL;
|
---|
344 | }
|
---|
345 |
|
---|
346 | VOID load_commands(VOID)
|
---|
347 | {
|
---|
348 | FILE *fp;
|
---|
349 | LINKCMDS *info;
|
---|
350 | PSZ pszCmdLine;
|
---|
351 | CHAR *p;
|
---|
352 | CHAR title[100];
|
---|
353 | CHAR flags[34];
|
---|
354 | CHAR ID[34];
|
---|
355 | CHAR HotKeyID[34];
|
---|
356 |
|
---|
357 | if (cmdhead)
|
---|
358 | free_commands();
|
---|
359 | cmdloaded = TRUE;
|
---|
360 | pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
361 | if (pszCmdLine) {
|
---|
362 | BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
|
---|
363 | fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
|
---|
364 | if (fp) {
|
---|
365 | xfgets(title, sizeof(title), fp, pszSrcFile, __LINE__);
|
---|
366 | lstrip(title);
|
---|
367 | if (!strnicmp(title, "Version", 7) && !CommandDatVersion) {
|
---|
368 | p = title + 7;
|
---|
369 | while (*p == ' ')
|
---|
370 | p++;
|
---|
371 | bstripcr(p);
|
---|
372 | CommandDatVersion = atol(p);
|
---|
373 | }
|
---|
374 | while (!feof(fp)) {
|
---|
375 | if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
|
---|
376 | break;
|
---|
377 | title[strlen(title)] = 0; // Match size to entry file max
|
---|
378 | if (!*title || *title == ';')
|
---|
379 | continue;
|
---|
380 | if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
|
---|
381 | break; /* error! */
|
---|
382 | if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
|
---|
383 | break; /* error! */
|
---|
384 | if (CommandDatVersion) {
|
---|
385 | if (!xfgets_bstripcr(ID, sizeof(ID), fp, pszSrcFile, __LINE__))
|
---|
386 | break; /* error! */
|
---|
387 | ID[34] = 0;
|
---|
388 | if (!xfgets_bstripcr(HotKeyID, sizeof(HotKeyID), fp, pszSrcFile, __LINE__))
|
---|
389 | break; /* error! */
|
---|
390 | ID[34] = 0;
|
---|
391 | }
|
---|
392 | pszCmdLine[strlen(pszCmdLine)] = 0; // fixme to know why chopped this way?
|
---|
393 | //bstripcr(pszCmdLine);
|
---|
394 | flags[34] = 0;
|
---|
395 | //bstripcr(flags);
|
---|
396 | if (!pszCmdLine)
|
---|
397 | continue;
|
---|
398 | info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
|
---|
399 | if (info) {
|
---|
400 | # ifdef FORTIFY
|
---|
401 | Fortify_SetOwner(info, 1);
|
---|
402 | Fortify_SetScope(info, 1);
|
---|
403 | # endif
|
---|
404 | info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
|
---|
405 | info->title = xstrdup(title, pszSrcFile, __LINE__);
|
---|
406 | info->flags = atol(flags);
|
---|
407 | if (CommandDatVersion) {
|
---|
408 | info->ID = atol(ID);
|
---|
409 | info->HotKeyID = atol(HotKeyID);
|
---|
410 | }
|
---|
411 | if (!info->pszCmdLine || !info->title) {
|
---|
412 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
---|
413 | xfree(info->title, pszSrcFile, __LINE__);
|
---|
414 | free(info);
|
---|
415 | break;
|
---|
416 | }
|
---|
417 | # ifdef FORTIFY
|
---|
418 | Fortify_SetOwner(info->pszCmdLine, 1);
|
---|
419 | Fortify_SetScope(info->pszCmdLine, 1);
|
---|
420 | Fortify_SetOwner(info->title, 1);
|
---|
421 | Fortify_SetScope(info->title, 1);
|
---|
422 | # endif
|
---|
423 | if (!cmdhead)
|
---|
424 | cmdhead = info;
|
---|
425 | else {
|
---|
426 | cmdtail->next = info;
|
---|
427 | info->prev = cmdtail;
|
---|
428 | }
|
---|
429 | cmdtail = info;
|
---|
430 | }
|
---|
431 | }
|
---|
432 | free(pszCmdLine);
|
---|
433 | fclose(fp);
|
---|
434 | }
|
---|
435 | }
|
---|
436 | }
|
---|
437 |
|
---|
438 | VOID save_commands(VOID)
|
---|
439 | {
|
---|
440 | LINKCMDS *info;
|
---|
441 | FILE *fp;
|
---|
442 | CHAR s[CCHMAXPATH + 14];
|
---|
443 | INT x = 0;
|
---|
444 |
|
---|
445 | if (!cmdloaded || !cmdhead)
|
---|
446 | return;
|
---|
447 | info = cmdhead;
|
---|
448 | BldFullPathName(s, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
|
---|
449 | if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
|
---|
450 | return; //already gave error msg
|
---|
451 | fp = xfopen(s, "w", pszSrcFile, __LINE__);
|
---|
452 | if (fp) {
|
---|
453 | //Adds line for version tracking
|
---|
454 | fprintf(fp,"Version 2\n");
|
---|
455 | fputs(GetPString(IDS_COMMANDFILETEXT), fp);
|
---|
456 | info = cmdhead;
|
---|
457 | while (info) {
|
---|
458 | //This updates the old commands.dat file to the new format
|
---|
459 | //assigning the IDs based on file order
|
---|
460 | if (!info->ID) {
|
---|
461 | info->ID = IDM_COMMANDSTART + x;
|
---|
462 | UsedCommandIDs[x] = TRUE;
|
---|
463 | if (x < 20) {
|
---|
464 | info->HotKeyID = IDM_COMMANDNUM0 + x;
|
---|
465 | UsedHotKeyIDs[x] = TRUE;
|
---|
466 | }
|
---|
467 | }
|
---|
468 | fprintf(fp, ";\n%0.99s\n%0.*s\n%lu\n%lu\n%lu\n",
|
---|
469 | info->title, MaxComLineStrg, info->pszCmdLine,
|
---|
470 | info->flags, info->ID, info->HotKeyID);
|
---|
471 | //else
|
---|
472 | // fprintf(fp,
|
---|
473 | // ";\n%0.99s\n%0.*s\n%lu\n",
|
---|
474 | // info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
|
---|
475 | x++;
|
---|
476 | info = info->next;
|
---|
477 | } // while
|
---|
478 | PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
|
---|
479 | sizeof(BOOL) * 300);
|
---|
480 | PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
|
---|
481 | sizeof(BOOL) * 20);
|
---|
482 | fclose(fp);
|
---|
483 | } // if (fp)
|
---|
484 | }
|
---|
485 |
|
---|
486 | //== add_command() Add command to list ==
|
---|
487 |
|
---|
488 | LINKCMDS *add_command(COMMAND *addme)
|
---|
489 | {
|
---|
490 | LINKCMDS *info;
|
---|
491 | ULONG size;
|
---|
492 | INT x;
|
---|
493 |
|
---|
494 | if (!addme || !*addme->pszCmdLine || !*addme->title)
|
---|
495 | return NULL; // No data
|
---|
496 | info = cmdhead;
|
---|
497 | while (info) {
|
---|
498 | if (!stricmp(info->title, addme->title))
|
---|
499 | return NULL; // Got a dup
|
---|
500 | info = info->next;
|
---|
501 | }
|
---|
502 | info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
|
---|
503 | if (!info)
|
---|
504 | return NULL;
|
---|
505 | info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
|
---|
506 | info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
|
---|
507 | info->HotKeyID = addme->HotKeyID;
|
---|
508 | if (!info->ID) {
|
---|
509 | PrfQueryProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
|
---|
510 | &size); //profile updated by save_commands
|
---|
511 | for (x = 0; x < 300; x++) {
|
---|
512 | if (!UsedCommandIDs[x]) {
|
---|
513 | info->ID = IDM_COMMANDSTART + x;
|
---|
514 | UsedCommandIDs[x] = TRUE;
|
---|
515 | break;
|
---|
516 | }
|
---|
517 | }
|
---|
518 | }
|
---|
519 | if (addme->flags)
|
---|
520 | info->flags = addme->flags;
|
---|
521 | if (!info->pszCmdLine || !info->title || !info->ID) {
|
---|
522 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
---|
523 | xfree(info->title, pszSrcFile, __LINE__);
|
---|
524 | free(info);
|
---|
525 | return NULL;
|
---|
526 | }
|
---|
527 | if (!cmdhead) /* only item in list */
|
---|
528 | cmdhead = cmdtail = info;
|
---|
529 | else {
|
---|
530 | /* place at tail */
|
---|
531 | cmdtail->next = info;
|
---|
532 | info->prev = cmdtail;
|
---|
533 | cmdtail = info;
|
---|
534 | }
|
---|
535 | return info;
|
---|
536 | }
|
---|
537 |
|
---|
538 | BOOL kill_command(CHAR * killme)
|
---|
539 | {
|
---|
540 | LINKCMDS *info;
|
---|
541 |
|
---|
542 | if (killme && *killme) {
|
---|
543 | info = cmdhead;
|
---|
544 | while (info) {
|
---|
545 | if (!stricmp(info->title, killme)) {
|
---|
546 | UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
|
---|
547 | if (info->HotKeyID)
|
---|
548 | UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
|
---|
549 | if (info == cmdhead) {
|
---|
550 | cmdhead = info->next;
|
---|
551 | if (info == cmdtail)
|
---|
552 | cmdtail = info->prev;
|
---|
553 | }
|
---|
554 | else {
|
---|
555 | if (info->next)
|
---|
556 | (info->next)->prev = info->prev;
|
---|
557 | if (info->prev)
|
---|
558 | (info->prev)->next = info->next;
|
---|
559 | if (info == cmdtail)
|
---|
560 | cmdtail = info->prev;
|
---|
561 | }
|
---|
562 | xfree(info->pszCmdLine, pszSrcFile, __LINE__);
|
---|
563 | xfree(info->title, pszSrcFile, __LINE__);
|
---|
564 | free(info);
|
---|
565 | return TRUE;
|
---|
566 | }
|
---|
567 | info = info->next;
|
---|
568 | }
|
---|
569 | }
|
---|
570 | return FALSE;
|
---|
571 | }
|
---|
572 |
|
---|
573 | MRESULT EXPENTRY CommandDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
574 | {
|
---|
575 | SHORT x, y;
|
---|
576 | LINKCMDS *info;
|
---|
577 |
|
---|
578 | switch (msg) {
|
---|
579 | case WM_INITDLG:
|
---|
580 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
581 | WinSendDlgItemMsg(hwnd, CMD_CL, EM_SETTEXTLIMIT,
|
---|
582 | MPFROM2SHORT(MaxComLineStrg - 1, 0), MPVOID);
|
---|
583 | WinSendDlgItemMsg(hwnd, CMD_TITLE, EM_SETTEXTLIMIT,
|
---|
584 | MPFROM2SHORT(99, 0), MPVOID);
|
---|
585 | WinSetDlgItemText(hwnd, CMD_CL, NullStr);
|
---|
586 | WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
|
---|
587 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
---|
588 | WinCheckButton(hwnd, CMD_PROMPT, FALSE);
|
---|
589 | WinCheckButton(hwnd, CMD_ONCE, FALSE);
|
---|
590 | info = cmdhead;
|
---|
591 | while (info) {
|
---|
592 | x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_INSERTITEM,
|
---|
593 | MPFROM2SHORT(LIT_END, 0),
|
---|
594 | MPFROMP(info->title));
|
---|
595 | if (x >= 0)
|
---|
596 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SETITEMHANDLE,
|
---|
597 | MPFROMSHORT(x), MPFROMP(info));
|
---|
598 | info = info->next;
|
---|
599 | }
|
---|
600 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_SELECTITEM,
|
---|
601 | MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
---|
602 | {
|
---|
603 | PFNWP oldproc;
|
---|
604 |
|
---|
605 | oldproc = WinSubclassWindow(WinWindowFromID(hwnd, CMD_CL),
|
---|
606 | (PFNWP) CommandTextProc);
|
---|
607 | if (oldproc)
|
---|
608 | WinSetWindowPtr(WinWindowFromID(hwnd, CMD_CL), QWL_USER, (PVOID) oldproc);
|
---|
609 | }
|
---|
610 | break;
|
---|
611 |
|
---|
612 | case WM_CONTROL:
|
---|
613 | if (SHORT1FROMMP(mp1) == CMD_LISTBOX) {
|
---|
614 | switch (SHORT2FROMMP(mp1)) {
|
---|
615 | case LN_ENTER:
|
---|
616 | case LN_SELECT:
|
---|
617 | x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
---|
618 | LM_QUERYSELECTION,
|
---|
619 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
620 | if (x >= 0) {
|
---|
621 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
---|
622 | LM_QUERYITEMHANDLE,
|
---|
623 | MPFROMSHORT(x), MPVOID);
|
---|
624 | if (!info) {
|
---|
625 | Runtime_Error(pszSrcFile, __LINE__, "LM_QUERYITEMHANDLE");
|
---|
626 | break;
|
---|
627 | }
|
---|
628 | WinSetDlgItemText(hwnd, CMD_CL, info->pszCmdLine);
|
---|
629 | if (!(info->flags & 1023))
|
---|
630 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
---|
631 | else {
|
---|
632 | if (info->flags & FULLSCREEN)
|
---|
633 | WinCheckButton(hwnd, CMD_FULLSCREEN, TRUE);
|
---|
634 | else if (info->flags & MINIMIZED)
|
---|
635 | WinCheckButton(hwnd, CMD_MINIMIZED, TRUE);
|
---|
636 | else if (info->flags & MAXIMIZED)
|
---|
637 | WinCheckButton(hwnd, CMD_MAXIMIZED, TRUE);
|
---|
638 | else if (info->flags & INVISIBLE)
|
---|
639 | WinCheckButton(hwnd, CMD_INVISIBLE, TRUE);
|
---|
640 | }
|
---|
641 | WinCheckButton(hwnd, CMD_PROMPT, ((info->flags & PROMPT) != 0));
|
---|
642 | WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
|
---|
643 | WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
|
---|
644 | WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
|
---|
645 | {
|
---|
646 | CHAR env[1002];
|
---|
647 | ULONG size;
|
---|
648 |
|
---|
649 | *env = 0;
|
---|
650 | size = sizeof(env) - 1;
|
---|
651 | if (PrfQueryProfileData(fmprof, FM3Str, info->pszCmdLine, env, &size) &&
|
---|
652 | *env)
|
---|
653 | WinSetDlgItemText(hwnd, CMD_ENVIRON, env);
|
---|
654 | else
|
---|
655 | WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
|
---|
656 | }
|
---|
657 | }
|
---|
658 | break;
|
---|
659 | }
|
---|
660 | }
|
---|
661 | return 0;
|
---|
662 |
|
---|
663 | case WM_COMMAND:
|
---|
664 | switch (SHORT1FROMMP(mp1)) {
|
---|
665 | case CMD_FIND:
|
---|
666 | {
|
---|
667 | CHAR filename[CCHMAXPATH + 9], szfilename[CCHMAXPATH + 9];
|
---|
668 |
|
---|
669 | *filename = 0;
|
---|
670 | if (insert_filename(hwnd, filename, 2, FALSE) && *filename) {
|
---|
671 | BldQuotedFileName(szfilename, filename);
|
---|
672 | WinSetDlgItemText(hwnd, CMD_CL, szfilename);
|
---|
673 | }
|
---|
674 | }
|
---|
675 | break;
|
---|
676 |
|
---|
677 | case CMD_REORDER:
|
---|
678 | if (!cmdhead || !cmdhead->next) {
|
---|
679 | Runtime_Error(pszSrcFile, __LINE__, "no cmd");
|
---|
680 | break;
|
---|
681 | }
|
---|
682 | if (WinDlgBox(HWND_DESKTOP, hwnd, ReOrderProc, FM3ModHandle,
|
---|
683 | RE_FRAME, MPVOID)) {
|
---|
684 | WinSendDlgItemMsg(hwnd, CMD_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
685 | WinSetDlgItemText(hwnd, CMD_CL, NullStr);
|
---|
686 | WinSetDlgItemText(hwnd, CMD_TITLE, NullStr);
|
---|
687 | info = cmdhead;
|
---|
688 | while (info) {
|
---|
689 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
690 | CMD_LISTBOX,
|
---|
691 | LM_INSERTITEM,
|
---|
692 | MPFROM2SHORT(LIT_END, 0),
|
---|
693 | MPFROMP(info->title));
|
---|
694 | if (x >= 0)
|
---|
695 | WinSendDlgItemMsg(hwnd,
|
---|
696 | CMD_LISTBOX,
|
---|
697 | LM_SETITEMHANDLE,
|
---|
698 | MPFROMSHORT(x), MPFROMP(info));
|
---|
699 | info = info->next;
|
---|
700 | }
|
---|
701 | WinSendDlgItemMsg(hwnd,
|
---|
702 | CMD_LISTBOX,
|
---|
703 | LM_SELECTITEM, MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
---|
704 | WinCheckButton(hwnd, CMD_DEFAULT, TRUE);
|
---|
705 | WinCheckButton(hwnd, CMD_PROMPT, FALSE);
|
---|
706 | WinCheckButton(hwnd, CMD_ONCE, FALSE);
|
---|
707 | save_commands();
|
---|
708 | }
|
---|
709 | break;
|
---|
710 |
|
---|
711 | case DID_OK:
|
---|
712 | {
|
---|
713 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
714 | CMD_LISTBOX,
|
---|
715 | LM_QUERYSELECTION, MPVOID, MPVOID);
|
---|
716 | if (x == LIT_NONE)
|
---|
717 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
718 | CMD_LISTBOX,
|
---|
719 | LM_SELECTITEM,
|
---|
720 | MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
---|
721 | }
|
---|
722 | {
|
---|
723 | COMMAND temp;
|
---|
724 | PSZ pszWorkBuf;
|
---|
725 | APIRET ret;
|
---|
726 |
|
---|
727 | memset(&temp, 0, sizeof(COMMAND));
|
---|
728 | temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
729 | if (!temp.pszCmdLine)
|
---|
730 | break; //already complained
|
---|
731 | pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
732 | if (!pszWorkBuf) {
|
---|
733 | free(temp.pszCmdLine);
|
---|
734 | break; //already complained
|
---|
735 | }
|
---|
736 | WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
|
---|
737 | NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
|
---|
738 | memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
|
---|
739 | free(pszWorkBuf);
|
---|
740 | if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
|
---|
741 | ret = saymsg(MB_YESNO,
|
---|
742 | HWND_DESKTOP,
|
---|
743 | NullStr,
|
---|
744 | GetPString(IDS_TOACTONSELECTEDTEXT));
|
---|
745 | if (ret == MBID_YES)
|
---|
746 | strcat(temp.pszCmdLine, " %a");
|
---|
747 | }
|
---|
748 | WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
|
---|
749 | if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
|
---|
750 | temp.flags = 0;
|
---|
751 | else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
|
---|
752 | temp.flags = FULLSCREEN;
|
---|
753 | else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
|
---|
754 | temp.flags = MINIMIZED;
|
---|
755 | else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
|
---|
756 | temp.flags = MAXIMIZED;
|
---|
757 | else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
|
---|
758 | temp.flags = INVISIBLE;
|
---|
759 | if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
|
---|
760 | temp.flags |= KEEP;
|
---|
761 | if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
|
---|
762 | temp.flags |= PROMPT;
|
---|
763 | if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
|
---|
764 | temp.flags |= ONCE;
|
---|
765 | if (fCancelAction){
|
---|
766 | fCancelAction = FALSE;
|
---|
767 | free(temp.pszCmdLine);
|
---|
768 | break;
|
---|
769 | }
|
---|
770 | else
|
---|
771 | info = add_command(&temp);
|
---|
772 | if (!info)
|
---|
773 | {
|
---|
774 | WinDismissDlg(hwnd, 0);
|
---|
775 | /*saymsg(MB_ENTER, hwnd,
|
---|
776 | GetPString(IDS_ERRORTEXT),
|
---|
777 | GetPString(IDS_CANTADDCOMMANDTEXT),
|
---|
778 | temp.title);*/
|
---|
779 | }
|
---|
780 | else {
|
---|
781 | CHAR env[1002];
|
---|
782 |
|
---|
783 | *env = 0;
|
---|
784 | WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
|
---|
785 | bstripcr(env);
|
---|
786 | if (*env) {
|
---|
787 | PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
|
---|
788 | }
|
---|
789 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
790 | CMD_LISTBOX,
|
---|
791 | LM_INSERTITEM,
|
---|
792 | MPFROM2SHORT(LIT_END, 0),
|
---|
793 | MPFROMP(temp.title));
|
---|
794 | if (x >= 0) {
|
---|
795 | WinSendDlgItemMsg(hwnd,
|
---|
796 | CMD_LISTBOX,
|
---|
797 | LM_SETITEMHANDLE,
|
---|
798 | MPFROMSHORT(x), MPFROMP(info));
|
---|
799 | WinSendDlgItemMsg(hwnd,
|
---|
800 | CMD_LISTBOX,
|
---|
801 | LM_SELECTITEM,
|
---|
802 | MPFROMSHORT(x), MPFROMSHORT(TRUE));
|
---|
803 | save_commands();
|
---|
804 | }
|
---|
805 | }
|
---|
806 | free(temp.pszCmdLine);
|
---|
807 | }
|
---|
808 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
809 | CMD_LISTBOX,
|
---|
810 | LM_QUERYSELECTION,
|
---|
811 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
812 | WinDismissDlg(hwnd, 0);
|
---|
813 | break;
|
---|
814 |
|
---|
815 | case DID_CANCEL:
|
---|
816 | WinDismissDlg(hwnd, 0);
|
---|
817 | break;
|
---|
818 |
|
---|
819 | case IDM_HELP:
|
---|
820 | if (hwndHelp)
|
---|
821 | WinSendMsg(hwndHelp,
|
---|
822 | HM_DISPLAY_HELP,
|
---|
823 | MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
|
---|
824 | break;
|
---|
825 |
|
---|
826 | case CMD_ADD:
|
---|
827 | {
|
---|
828 | COMMAND temp;
|
---|
829 | PSZ pszWorkBuf;
|
---|
830 | APIRET ret;
|
---|
831 |
|
---|
832 | memset(&temp, 0, sizeof(COMMAND));
|
---|
833 | temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
834 | if (!temp.pszCmdLine)
|
---|
835 | break; //already complained
|
---|
836 | pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
837 | if (!pszWorkBuf) {
|
---|
838 | free(temp.pszCmdLine);
|
---|
839 | break; //already complained
|
---|
840 | }
|
---|
841 | WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
|
---|
842 | NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
|
---|
843 | memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
|
---|
844 | free(pszWorkBuf);
|
---|
845 | if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
|
---|
846 | ret = saymsg(MB_YESNO,
|
---|
847 | HWND_DESKTOP,
|
---|
848 | NullStr,
|
---|
849 | GetPString(IDS_TOACTONSELECTEDTEXT));
|
---|
850 | if (ret == MBID_YES)
|
---|
851 | strcat(temp.pszCmdLine, " %a");
|
---|
852 | }
|
---|
853 | WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
|
---|
854 | if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
|
---|
855 | temp.flags = 0;
|
---|
856 | else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
|
---|
857 | temp.flags = FULLSCREEN;
|
---|
858 | else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
|
---|
859 | temp.flags = MINIMIZED;
|
---|
860 | else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
|
---|
861 | temp.flags = MAXIMIZED;
|
---|
862 | else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
|
---|
863 | temp.flags = INVISIBLE;
|
---|
864 | if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
|
---|
865 | temp.flags |= KEEP;
|
---|
866 | if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
|
---|
867 | temp.flags |= PROMPT;
|
---|
868 | if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
|
---|
869 | temp.flags |= ONCE;
|
---|
870 | if (fCancelAction){
|
---|
871 | fCancelAction = FALSE;
|
---|
872 | free(temp.pszCmdLine);
|
---|
873 | break;
|
---|
874 | }
|
---|
875 | else
|
---|
876 | info = add_command(&temp);
|
---|
877 | if (!info) {
|
---|
878 | saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
|
---|
879 | GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp.title);
|
---|
880 | }
|
---|
881 | else {
|
---|
882 | CHAR env[1002];
|
---|
883 |
|
---|
884 | *env = 0;
|
---|
885 | WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
|
---|
886 | bstripcr(env);
|
---|
887 | if (*env) {
|
---|
888 | PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
|
---|
889 | }
|
---|
890 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
891 | CMD_LISTBOX,
|
---|
892 | LM_INSERTITEM,
|
---|
893 | MPFROM2SHORT(LIT_END, 0),
|
---|
894 | MPFROMP(temp.title));
|
---|
895 | if (x >= 0) {
|
---|
896 | WinSendDlgItemMsg(hwnd,
|
---|
897 | CMD_LISTBOX,
|
---|
898 | LM_SETITEMHANDLE,
|
---|
899 | MPFROMSHORT(x), MPFROMP(info));
|
---|
900 | WinSendDlgItemMsg(hwnd,
|
---|
901 | CMD_LISTBOX,
|
---|
902 | LM_SELECTITEM,
|
---|
903 | MPFROMSHORT(x), MPFROMSHORT(TRUE));
|
---|
904 | save_commands();
|
---|
905 | }
|
---|
906 | }
|
---|
907 | free(temp.pszCmdLine);
|
---|
908 | }
|
---|
909 | break;
|
---|
910 |
|
---|
911 | case CMD_DELETE:
|
---|
912 | {
|
---|
913 | CHAR temp[100];
|
---|
914 |
|
---|
915 | WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
|
---|
916 | bstrip(temp);
|
---|
917 | PrfWriteProfileString(fmprof, FM3Str, temp, NULL);
|
---|
918 | if (!kill_command(temp))
|
---|
919 | Runtime_Error(pszSrcFile, __LINE__, "kill_command");
|
---|
920 | else {
|
---|
921 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
922 | CMD_LISTBOX,
|
---|
923 | LM_QUERYSELECTION,
|
---|
924 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
925 | if (x >= 0) {
|
---|
926 | WinSendDlgItemMsg(hwnd,
|
---|
927 | CMD_LISTBOX,
|
---|
928 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
|
---|
929 | WinSendDlgItemMsg(hwnd,
|
---|
930 | CMD_LISTBOX,
|
---|
931 | LM_SELECTITEM,
|
---|
932 | MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
|
---|
933 | }
|
---|
934 | save_commands();
|
---|
935 | }
|
---|
936 | }
|
---|
937 | break;
|
---|
938 |
|
---|
939 | case CMD_REPLACE:
|
---|
940 | { //Delete first
|
---|
941 | PSZ pszWorkBuf;
|
---|
942 | COMMAND temp;
|
---|
943 | APIRET ret;
|
---|
944 |
|
---|
945 | pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
946 | if (!pszWorkBuf) {
|
---|
947 | break; //already complained
|
---|
948 | }
|
---|
949 | memset(&temp, 0, sizeof(COMMAND));
|
---|
950 | temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
951 | if (!temp.pszCmdLine) {
|
---|
952 | free(pszWorkBuf);
|
---|
953 | break; //already complained
|
---|
954 | }
|
---|
955 | WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
|
---|
956 | NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
|
---|
957 | memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
|
---|
958 | free(pszWorkBuf);
|
---|
959 | if (fCancelAction){
|
---|
960 | fCancelAction = FALSE;
|
---|
961 | free(temp.pszCmdLine);
|
---|
962 | break;
|
---|
963 | }
|
---|
964 | if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
|
---|
965 | ret = saymsg(MB_YESNO,
|
---|
966 | HWND_DESKTOP,
|
---|
967 | NullStr,
|
---|
968 | GetPString(IDS_TOACTONSELECTEDTEXT));
|
---|
969 | if (ret == MBID_YES)
|
---|
970 | strcat(temp.pszCmdLine, " %a");
|
---|
971 | }
|
---|
972 | //remember item location in the list
|
---|
973 | y = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
974 | CMD_LISTBOX,
|
---|
975 | LM_QUERYSELECTION,
|
---|
976 | MPFROMSHORT(LIT_CURSOR), MPVOID);
|
---|
977 | WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
|
---|
978 | bstrip(temp.title);
|
---|
979 | PrfWriteProfileString(fmprof, FM3Str, temp.title, NULL);
|
---|
980 | if (kill_command(temp.title)){
|
---|
981 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
982 | CMD_LISTBOX,
|
---|
983 | LM_QUERYSELECTION,
|
---|
984 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
---|
985 | if (x >= 0) {
|
---|
986 | WinSendDlgItemMsg(hwnd,
|
---|
987 | CMD_LISTBOX,
|
---|
988 | LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
|
---|
989 | WinSendDlgItemMsg(hwnd,
|
---|
990 | CMD_LISTBOX,
|
---|
991 | LM_SELECTITEM,
|
---|
992 | MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
|
---|
993 | }
|
---|
994 | } // then do an add
|
---|
995 | if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
|
---|
996 | temp.flags = 0;
|
---|
997 | else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
|
---|
998 | temp.flags = FULLSCREEN;
|
---|
999 | else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
|
---|
1000 | temp.flags = MINIMIZED;
|
---|
1001 | else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
|
---|
1002 | temp.flags = MAXIMIZED;
|
---|
1003 | else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
|
---|
1004 | temp.flags = INVISIBLE;
|
---|
1005 | if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
|
---|
1006 | temp.flags |= KEEP;
|
---|
1007 | if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
|
---|
1008 | temp.flags |= PROMPT;
|
---|
1009 | if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
|
---|
1010 | temp.flags |= ONCE;
|
---|
1011 | info = add_command(&temp);
|
---|
1012 | if (!info) {
|
---|
1013 | saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
|
---|
1014 | GetPString(IDS_CANTADDCOMMANDTEXT),
|
---|
1015 | temp.title);
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | else {
|
---|
1019 | CHAR env[1002];
|
---|
1020 |
|
---|
1021 | *env = 0;
|
---|
1022 | WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
|
---|
1023 | bstripcr(env);
|
---|
1024 | if (*env) {
|
---|
1025 | PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
|
---|
1026 | } //put item back in original place
|
---|
1027 | x = (SHORT) WinSendDlgItemMsg(hwnd,
|
---|
1028 | CMD_LISTBOX,
|
---|
1029 | LM_INSERTITEM,
|
---|
1030 | MPFROM2SHORT(y, 0),
|
---|
1031 | MPFROMP(temp.title));
|
---|
1032 | if (x >= 0) {
|
---|
1033 | LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
|
---|
1034 | SHORT numitems, sSelect = 0;
|
---|
1035 |
|
---|
1036 | WinSendDlgItemMsg(hwnd,
|
---|
1037 | CMD_LISTBOX,
|
---|
1038 | LM_SETITEMHANDLE,
|
---|
1039 | MPFROMSHORT(x), MPFROMP(info));
|
---|
1040 | WinSendDlgItemMsg(hwnd,
|
---|
1041 | CMD_LISTBOX,
|
---|
1042 | LM_SELECTITEM,
|
---|
1043 | MPFROMSHORT(x), MPFROMSHORT(TRUE));
|
---|
1044 | //then reorder
|
---|
1045 | numitems = (SHORT) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
---|
1046 | LM_QUERYITEMCOUNT,
|
---|
1047 | MPVOID, MPVOID);
|
---|
1048 |
|
---|
1049 | while (numitems) {
|
---|
1050 |
|
---|
1051 |
|
---|
1052 | info = (LINKCMDS *) WinSendDlgItemMsg(hwnd, CMD_LISTBOX,
|
---|
1053 | LM_QUERYITEMHANDLE,
|
---|
1054 | MPFROMSHORT(sSelect++),
|
---|
1055 | MPVOID);
|
---|
1056 | if (info) {
|
---|
1057 | if (!temphead) {
|
---|
1058 | temphead = info;
|
---|
1059 | info->prev = NULL;
|
---|
1060 | }
|
---|
1061 | else {
|
---|
1062 | last->next = info;
|
---|
1063 | info->prev = last;
|
---|
1064 | }
|
---|
1065 | temptail = info;
|
---|
1066 | last = info;
|
---|
1067 | info->next = NULL;
|
---|
1068 | }
|
---|
1069 | numitems--;
|
---|
1070 | }
|
---|
1071 | cmdhead = temphead;
|
---|
1072 | cmdtail = temptail;
|
---|
1073 | save_commands();
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 | free(temp.pszCmdLine);
|
---|
1077 | }
|
---|
1078 | break;
|
---|
1079 | }
|
---|
1080 | return 0;
|
---|
1081 | }
|
---|
1082 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | VOID RunCommand(HWND hwnd, INT cx)
|
---|
1086 | {
|
---|
1087 | INT x;
|
---|
1088 | CHAR **list;
|
---|
1089 | LINKCMDS *info;
|
---|
1090 |
|
---|
1091 | DbgMsg(pszSrcFile, __LINE__,"ID %i", cx);
|
---|
1092 | list = BuildList(hwnd);
|
---|
1093 | x = 0;
|
---|
1094 | info = cmdhead;
|
---|
1095 | while (info) {
|
---|
1096 | //x++;
|
---|
1097 | if (cx < 4300) {
|
---|
1098 | if (info->ID == cx)
|
---|
1099 | break;
|
---|
1100 | }
|
---|
1101 | else {
|
---|
1102 | if (info->HotKeyID == cx)
|
---|
1103 | break;
|
---|
1104 | }
|
---|
1105 | info = info->next;
|
---|
1106 | }
|
---|
1107 | if (info) {
|
---|
1108 |
|
---|
1109 | INT flags;
|
---|
1110 | CHAR env[1002];
|
---|
1111 |
|
---|
1112 | x--;
|
---|
1113 | flags = info->flags;
|
---|
1114 | if (!(flags & FULLSCREEN))
|
---|
1115 | flags |= WINDOWED;
|
---|
1116 | if (flags & KEEP)
|
---|
1117 | flags |= SEPARATEKEEP;
|
---|
1118 | else
|
---|
1119 | flags |= SEPARATE;
|
---|
1120 | flags &= ~(KEEP | DIEAFTER);
|
---|
1121 | PrfQueryProfileString(fmprof, FM3Str, info->title, NullStr, env, sizeof(env));
|
---|
1122 | if (!strchr(info->pszCmdLine, '%')) {
|
---|
1123 | CHAR *fakelist[2];
|
---|
1124 |
|
---|
1125 | *fakelist = "C";
|
---|
1126 | fakelist[1] = NULL;
|
---|
1127 | ExecOnList(hwnd,
|
---|
1128 | info->pszCmdLine,
|
---|
1129 | flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
|
---|
1130 | pszSrcFile, __LINE__);
|
---|
1131 | }
|
---|
1132 | else if ((flags & ONCE) && list && list[0]) {
|
---|
1133 |
|
---|
1134 | CHAR *fakelist[2];
|
---|
1135 | INT cntr;
|
---|
1136 |
|
---|
1137 | flags &= (~ONCE);
|
---|
1138 | for (cntr = 0; list[cntr]; cntr++) {
|
---|
1139 | *fakelist = list[cntr];
|
---|
1140 | fakelist[1] = NULL;
|
---|
1141 | ExecOnList(hwnd,
|
---|
1142 | info->pszCmdLine,
|
---|
1143 | flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
|
---|
1144 | pszSrcFile, __LINE__);
|
---|
1145 | }
|
---|
1146 | }
|
---|
1147 | else if (list && list[0])
|
---|
1148 | ExecOnList(hwnd,
|
---|
1149 | info->pszCmdLine,
|
---|
1150 | flags, env, list, GetPString(IDS_EXECCMDTITLETEXT),
|
---|
1151 | pszSrcFile, __LINE__);
|
---|
1152 | else
|
---|
1153 | return;
|
---|
1154 | }
|
---|
1155 | FreeList(list);
|
---|
1156 | DosPostEventSem(CompactSem);
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | VOID EditCommands(HWND hwnd)
|
---|
1160 | {
|
---|
1161 | static CHAR stop = 0;
|
---|
1162 |
|
---|
1163 | if (stop)
|
---|
1164 | return;
|
---|
1165 | stop++;
|
---|
1166 | if (!cmdloaded)
|
---|
1167 | load_commands();
|
---|
1168 | WinDlgBox(HWND_DESKTOP,
|
---|
1169 | hwnd, CommandDlgProc, FM3ModHandle, CMD_FRAME, MPFROMP(&hwnd));
|
---|
1170 | stop = 0;
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | #pragma alloc_text(COMMAND,command_title,free_commands,add_command,kill_command)
|
---|
1174 | #pragma alloc_text(COMMAND,CommandDlgProc,EditCommands,ReOrderProc,CommandTextProc)
|
---|