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