source: trunk/dll/command.c@ 1633

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

Fix trap on duplicate hot warning dialog exit if cancel is selected. Ticket 476

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