source: trunk/dll/command.c@ 1673

Last change on this file since 1673 was 1673, checked in by Gregg Young, 13 years ago

Update to Doxygen comment style Ticket 55. Also some minor code cleanup.

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