source: trunk/dll/command.c@ 1486

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

Initial changes to commands handling. Allows you to reorder commands menu without breaking toolbars and changing hotkeys. Fixes the environment so it is used and so it is deleted if the command is deleted. Allows for user defined bitmaps in toolbars which are named based on the text or the the ID of the command.The new commands.dat will not be usable with earlier versions of FM/2

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