source: trunk/dll/command.c@ 1491

Last change on this file since 1491 was 1491, checked in by Gregg Young, 16 years ago

Moved the commands to the ini file; made command hotkeys user selectable; some code cleanup and consolidation in command.c (tickets 65, 186)

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