source: trunk/dll/command.c@ 1494

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

Fix bustage from earlier commit

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