source: trunk/dll/command.c@ 1634

Last change on this file since 1634 was 1634, checked in by Gregg Young, 14 years ago

Added comments for previous commit

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