source: trunk/dll/cmdline.c@ 1546

Last change on this file since 1546 was 1546, checked in by Gregg Young, 15 years ago

Add menu item to allow opening of directory container from the collector based on the path of the selected item. (Ticket 362) Add open file button to EAs dialog to allow opening of a new file's eas (Ticket 439). Initial work on populating the help table (It provides F1 help a few more places) (Ticket 95). Some minor code cleanup and help file updates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 25.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: cmdline.c 1546 2010-10-23 22:33:00Z gyoung $
5
6 User defined commands support
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004, 2010 Steven H.Levine
10
11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 05 Jun 05 SHL Use QWL_USER
13 22 Jul 06 SHL Check more run time errors
14 29 Jul 06 SHL Use xfgets_bstripcr
15 22 Mar 07 GKY Use QWL_USER
16 16 Jun 07 SHL Update for OpenWatcom
17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
18 29 Feb 08 GKY Use xfree where appropriate
19 20 Apr 08 GKY New variable names; Save and Load command lines of user set length
20 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory and use BldFullPathName
21 24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
22 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
23 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
24 profile calls for user settings that work and are setable in more than one
25 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
26 aren't user settable; realappname should be used for setting applicable to
27 one or more miniapp but not to FM/2
28 21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
29 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
30 23 Oct 10 GKY Changes to populate and utilize a HELPTABLE for context specific help
31
32***********************************************************************/
33
34#include <stdlib.h>
35#include <string.h>
36#include <share.h>
37#include <io.h> // unlink
38
39#define INCL_DOS
40#define INCL_WIN
41#define INCL_LONGLONG // dircnrs.h
42
43#include "fm3dll.h"
44#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
45#include "arccnrs.h" // Data declaration(s)
46#include "fm2cmd.h" // Data declaration(s)
47#include "notebook.h" // Data declaration(s)
48#include "init.h" // Data declaration(s)
49#include "newview.h" // Data declarations
50#include "fm3dlg.h"
51#include "fm3str.h"
52#include "mle.h"
53#include "errutil.h" // Dos_Error...
54#include "strutil.h" // GetPString
55#include "mainwnd.h" // BubbleHelp
56#include "cmdline.h" // CmdLineDlgProc, CmdLine2DlgProc
57#include "chklist.h" // PosOverOkay
58#include "pathutil.h" // MaxCmdLineStr
59#include "strips.h" // bstrip
60#include "misc.h" // CheckDriveSpaceAvail
61#include "srchpath.h" // searchpath
62#include "wrappers.h" // xfgets_bstripcr
63#include "valid.h" // IsFile
64#include "dirs.h" // save_dir2
65#include "systemf.h"
66#include "fortify.h"
67
68#define MAXNUMCMDLINES 250
69
70typedef struct LINKCMDLINES
71{
72 CHAR *cmdline;
73 struct LINKCMDLINES *next;
74}
75LINKCMDLINES;
76
77static LINKCMDLINES *DoItYourselfCmdLine = NULL, *MiniCmdLine = NULL;
78static BOOL DoItYourselfLoaded = FALSE, MiniLoaded = FALSE;
79
80// Data definitions
81static PSZ pszSrcFile = __FILE__;
82
83#pragma data_seg(GLOBAL1)
84BOOL fSaveBigCmds;
85
86
87VOID load_cmdlines(BOOL DoItYourself)
88{
89 /** load linked list of cmdlines from CMDLINES.DAT file
90 * if DoItYourself = TRUE (main command line dialog)
91 * else load from CMDMINI.DAT (mini command line at
92 * bottom of main window).
93 */
94
95 FILE *fp;
96 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
97 PSZ pszCmdLine;
98 //CHAR s[1024];
99 INT x = 0;
100 CHAR *moder = "r";
101
102 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
103 if (pszCmdLine) {
104 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
105 if (DoItYourself)
106 DoItYourselfLoaded = TRUE;
107 else
108 MiniLoaded = TRUE;
109 BldFullPathName(pszCmdLine, pFM2SaveDirectory,
110 (DoItYourself) ? PCSZ_CMDLINESDAT : PCSZ_CMDMINIDAT);
111 fp = xfsopen(pszCmdLine, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
112 if (fp) {
113 while (x < MAXNUMCMDLINES && !feof(fp)) {
114 if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
115 break;
116 if (pszCmdLine && *pszCmdLine != ';') {
117 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__);
118 if (info) {
119 x++;
120 info->cmdline = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
121 if (!info->cmdline)
122 free(info);
123 else {
124 info->next = NULL;
125 if (!CmdLineHead)
126 CmdLineHead = info;
127 else
128 last->next = info;
129 last = info;
130 }
131 }
132 }
133 }
134 fclose(fp);
135 }
136 free(pszCmdLine);
137 }
138 if (DoItYourself)
139 DoItYourselfCmdLine = CmdLineHead;
140 else
141 MiniCmdLine = CmdLineHead;
142}
143
144VOID save_cmdlines(BOOL DoItYourself)
145{
146 /** save linked list of cmdlines from CMDLINES.DAT file
147 * if DoItYourself = TRUE (main command line dialog)
148 * else load from CMDMINI.DAT (mini command line at
149 * bottom of main window).
150 */
151
152 LINKCMDLINES *info, *CmdLineHead;
153 FILE *fp;
154 PSZ pszCmdLine;
155 //CHAR s[CCHMAXPATH + 14];
156 CHAR *modew = "w";
157
158 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
159 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
160 return;
161 pszCmdLine = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
162 if (!pszCmdLine)
163 return;
164 BldFullPathName(pszCmdLine, pFM2SaveDirectory,
165 (DoItYourself) ? PCSZ_CMDLINESDAT : PCSZ_CMDMINIDAT);
166 if (CheckDriveSpaceAvail(pszCmdLine, ullDATFileSpaceNeeded, 1) == 2)
167 return; //already gave error msg
168 if (CmdLineHead) {
169 fp = xfopen(pszCmdLine, modew, pszSrcFile, __LINE__, FALSE);
170 if (fp) {
171 fputs(GetPString(IDS_COMMANDFILE2TEXT), fp);
172 info = CmdLineHead;
173 while (info) {
174 fprintf(fp, "%0.*s\n", 1000, info->cmdline);
175 info = info->next;
176 }
177 fclose(fp);
178 }
179 }
180 else
181 unlink(pszCmdLine);
182 if (DoItYourself)
183 DoItYourselfCmdLine = CmdLineHead;
184 else
185 MiniCmdLine = CmdLineHead;
186}
187
188BOOL add_cmdline(CHAR *cmdline, BOOL DoItYourself)
189{
190 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
191 INT x = 0;
192
193 if (!cmdline || !*cmdline)
194 return FALSE;
195 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
196 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
197 load_cmdlines(DoItYourself);
198 info = CmdLineHead;
199 while (info) {
200 if (!stricmp(info->cmdline, cmdline))
201 return FALSE;
202 last = info;
203 info = info->next;
204 x++;
205 }
206 info = xmalloc(sizeof(LINKCMDLINES), pszSrcFile, __LINE__);
207 if (info) {
208 info->cmdline = xstrdup(cmdline, pszSrcFile, __LINE__);
209 if (!info->cmdline)
210 xfree(info, pszSrcFile, __LINE__);
211 else {
212 info->next = NULL;
213 if (!CmdLineHead)
214 CmdLineHead = info;
215 else
216 last->next = info;
217 if (x > MAXNUMCMDLINES) {
218 info = CmdLineHead;
219 CmdLineHead = CmdLineHead->next;
220 free(info);
221 }
222 if (DoItYourself)
223 DoItYourselfCmdLine = CmdLineHead;
224 else
225 MiniCmdLine = CmdLineHead;
226 return TRUE;
227 }
228 }
229 return FALSE;
230}
231
232BOOL remove_cmdline(CHAR *cmdline, BOOL DoItYourself)
233{
234 LINKCMDLINES *info, *last = NULL, *CmdLineHead;
235
236 if (!cmdline || !*cmdline)
237 return FALSE;
238 if ((DoItYourself && !DoItYourselfLoaded) || (!DoItYourself && !MiniLoaded))
239 load_cmdlines(DoItYourself);
240 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
241 info = CmdLineHead;
242 while (info) {
243 if (!stricmp(info->cmdline, cmdline)) {
244 if (last)
245 last->next = info->next;
246 else
247 CmdLineHead = info->next;
248 xfree(info->cmdline, pszSrcFile, __LINE__);
249 free(info);
250 if (DoItYourself)
251 DoItYourselfCmdLine = CmdLineHead;
252 else
253 MiniCmdLine = CmdLineHead;
254 return TRUE;
255 }
256 last = info;
257 info = info->next;
258 }
259 return FALSE;
260}
261
262VOID free_cmdlines(BOOL DoItYourself)
263{
264 LINKCMDLINES *info, *next, *CmdLineHead;
265
266 CmdLineHead = (DoItYourself) ? DoItYourselfCmdLine : MiniCmdLine;
267 info = CmdLineHead;
268 while (info) {
269 next = info->next;
270 xfree(info->cmdline, pszSrcFile, __LINE__);
271 free(info);
272 info = next;
273 }
274 CmdLineHead = NULL;
275 if (DoItYourself)
276 DoItYourselfCmdLine = CmdLineHead;
277 else
278 MiniCmdLine = CmdLineHead;
279 DosPostEventSem(CompactSem);
280}
281
282MRESULT EXPENTRY CmdBtnSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
283{
284 switch (msg) {
285 case WM_MOUSEMOVE:
286 {
287 ULONG strid = 0;
288
289 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
290 case EXEC2_CLR:
291 strid = IDS_CMDWIPEALLHELPTEXT;
292 break;
293 case EXEC2_DEL:
294 strid = IDS_CMDDELHILITEHELPTEXT;
295 break;
296 case IDM_HELP:
297 strid = IDS_CMDHELPHELPTEXT;
298 break;
299 case DID_CANCEL:
300 strid = IDS_CMDCLOSEBOXHELPTEXT;
301 break;
302 case EXEC2_OPEN:
303 strid = IDS_CMDOPENHELPTEXT;
304 break;
305 case EXEC2_CLOSE:
306 strid = IDS_CMDCLOSEHELPTEXT;
307 break;
308 case EXEC2_FILTER:
309 strid = IDS_CMDFILTERHELPTEXT;
310 break;
311 case EXEC2_KEEP:
312 strid = IDS_CMDKEEPHELPTEXT;
313 break;
314 case EXEC2_SAVE:
315 strid = IDS_CMDSAVEHELPTEXT;
316 break;
317 }
318 if (strid)
319 BubbleHelp(hwnd, TRUE, FALSE, FALSE, GetPString(strid));
320 }
321 break;
322 }
323 return PFNWPButton(hwnd, msg, mp1, mp2);
324}
325
326MRESULT EXPENTRY CmdListSubProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
327{
328 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
329
330 switch (msg) {
331 case WM_MOUSEMOVE:
332 if (hwndBubble)
333 WinDestroyWindow(hwndBubble);
334 break;
335
336 case WM_CHAR:
337 if (SHORT1FROMMP(mp1) & KC_KEYUP) {
338 if ((SHORT1FROMMP(mp1) & KC_VIRTUALKEY) &&
339 (SHORT2FROMMP(mp2)) == VK_DELETE) {
340 if ((SHORT1FROMMP(mp1) & KC_CTRL) != KC_CTRL)
341 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
342 MPFROM2SHORT(EXEC2_DEL, 0), MPVOID);
343 else
344 PostMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
345 MPFROM2SHORT(EXEC2_CLR, 0), MPVOID);
346 }
347 }
348 break;
349 }
350 return oldproc(hwnd, msg, mp1, mp2);
351}
352
353MRESULT EXPENTRY CmdLineDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
354{
355 EXECARGS *ex;
356
357 switch (msg) {
358 case WM_INITDLG:
359 ex = (EXECARGS *) mp2;
360 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) ex);
361 if (!ex || !ex->commandline) {
362 WinDismissDlg(hwnd, 0);
363 break;
364 }
365 if (*ex->title)
366 WinSetWindowText(hwnd, ex->title);
367 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), FALSE);
368 WinCheckButton(hwnd, EXEC_SAVECMD, fSaveBigCmds);
369 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETTEXTLIMIT,
370 MPFROM2SHORT(1000, 0), MPVOID);
371 WinSetDlgItemText(hwnd, EXEC_CL, ex->commandline);
372 WinSetWindowPtr(WinWindowFromID(hwnd, EXEC_LISTBOX),
373 QWL_USER,
374 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
375 EXEC_LISTBOX),
376 (PFNWP) CmdListSubProc));
377 if (*ex->commandline == ' ')
378 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETSEL, MPFROM2SHORT(0, 0), MPVOID);
379 WinSendDlgItemMsg(hwnd, EXEC_CL, EM_SETINSERTMODE,
380 MPFROMSHORT(TRUE), MPVOID);
381 if (ex->flags & MINIMIZED)
382 WinCheckButton(hwnd, EXEC_MINIMIZED, TRUE);
383 else if (ex->flags & MAXIMIZED)
384 WinCheckButton(hwnd, EXEC_MAXIMIZED, TRUE);
385 else if (ex->flags & FULLSCREEN)
386 WinCheckButton(hwnd, EXEC_FULLSCREEN, TRUE);
387 else if (ex->flags & INVISIBLE)
388 WinCheckButton(hwnd, EXEC_INVISIBLE, TRUE);
389 else
390 WinCheckButton(hwnd, EXEC_DEFAULT, TRUE);
391 if ((ex->flags & SEPARATEKEEP) == SEPARATEKEEP)
392 WinCheckButton(hwnd, EXEC_KEEP, TRUE);
393 else
394 WinCheckButton(hwnd, EXEC_KEEP, FALSE);
395 MLEsetformat(WinWindowFromID(hwnd, EXEC_ENVIRON), MLFIE_NOTRANS);
396 MLEsetlimit(WinWindowFromID(hwnd, EXEC_ENVIRON), 1000);
397 WinSetDlgItemText(hwnd, EXEC_ENVIRON, ex->environment);
398// WinEnableWindow(WinWindowFromID(hwnd,EXEC_ENVIRON),FALSE);
399 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
400 PosOverOkay(hwnd);
401 break;
402
403 case UM_SETUP:
404 {
405 ULONG apptype = 0L;
406 CHAR executable[CCHMAXPATH], commandline[1001], *p;
407
408 ex = INSTDATA(hwnd);
409 if (!ex)
410 return 0;
411 WinSetDlgItemText(hwnd, EXEC_WARNING, NullStr);
412 WinSetDlgItemText(hwnd, EXEC_WARNING2, NullStr);
413 *commandline = 0;
414 WinQueryDlgItemText(hwnd, EXEC_CL, 1000, commandline);
415 if (!*commandline)
416 return 0;
417 if (*ex->path) {
418 strcpy(executable, ex->path);
419 AddBackslashToPath(executable);
420 //if (executable[strlen(executable) - 1] != '\\')
421 // strcat(executable, "\\");
422 }
423 else
424 *executable = 0;
425 strncat(executable, commandline, CCHMAXPATH - strlen(executable));
426 executable[CCHMAXPATH - 1] = 0;
427 p = strchr(executable, ' ');
428 if (p)
429 *p = 0;
430 if (IsFile(executable) == -1) {
431 strncpy(executable, commandline, CCHMAXPATH);
432 executable[CCHMAXPATH - 1] = 0;
433 p = strchr(executable, ' ');
434 if (p)
435 *p = 0;
436 if (IsFile(executable) == -1) {
437 p = searchpath(executable);
438 if (*p)
439 strcpy(executable, p);
440 else {
441 WinSetDlgItemText(hwnd,
442 EXEC_WARNING2,
443 (CHAR *) GetPString(IDS_CANTFINDFILETEXT));
444 break;
445 }
446 }
447 }
448 if (DosQueryAppType(executable, &apptype) ||
449 (apptype && !(apptype &
450 (FAPPTYP_NOTWINDOWCOMPAT |
451 FAPPTYP_WINDOWCOMPAT |
452 FAPPTYP_WINDOWAPI |
453 FAPPTYP_BOUND |
454 FAPPTYP_DOS |
455 FAPPTYP_WINDOWSREAL |
456 FAPPTYP_WINDOWSPROT | FAPPTYP_32BIT | 0x1000)))) {
457 p = strchr(executable, '.');
458 if (p) {
459 if (!stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTCMD) ||
460 !stricmp(p, PCSZ_DOTBTM)) {
461 WinSetDlgItemText(hwnd,
462 EXEC_WARNING2,
463 (CHAR *) GetPString(IDS_RUNTHRUCMDEXETEXT));
464 break;
465 }
466 }
467 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_NOTDIRECTEXETEXT));
468 }
469 else if (apptype) { /* acceptable */
470
471 CHAR s[257];
472
473 *s = 0;
474 WinSetDlgItemText(hwnd, EXEC_WARNING, (CHAR *) GetPString(IDS_ACCEPTABLEAPPTEXT));
475 if (apptype & FAPPTYP_DOS)
476 strcat(s, GetPString(IDS_DOSTEXT));
477 if (apptype & FAPPTYP_WINDOWSREAL) {
478 if (*s)
479 strcat(s, " ");
480 strcat(s, GetPString(IDS_WINDOWSREALTEXT));
481 }
482 if (apptype & FAPPTYP_WINDOWSPROT) {
483 if (*s)
484 strcat(s, " ");
485 strcat(s, GetPString(IDS_WINDOWSPROTTEXT));
486 }
487 if (apptype & 0x1000) {
488 if (*s)
489 strcat(s, " ");
490 strcat(s, GetPString(IDS_WINDOWSENHTEXT));
491 }
492 if ((apptype & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) {
493 if (*s)
494 strcat(s, " ");
495 strcat(s, GetPString(IDS_PMTEXT));
496 WinCheckButton(hwnd, EXEC_FULLSCREEN, FALSE);
497 WinEnableWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), FALSE);
498 }
499 if (apptype & FAPPTYP_BOUND) {
500 if (*s)
501 strcat(s, " ");
502 strcat(s, GetPString(IDS_BOUNDTEXT));
503 }
504 if ((apptype & FAPPTYP_WINDOWCOMPAT) &&
505 !(apptype & FAPPTYP_NOTWINDOWCOMPAT)) {
506 if (*s)
507 strcat(s, " ");
508 strcat(s, GetPString(IDS_VIOTEXT));
509 }
510 if ((apptype & FAPPTYP_NOTWINDOWCOMPAT) &&
511 !(apptype & FAPPTYP_WINDOWCOMPAT)) {
512 if (*s)
513 strcat(s, " ");
514 strcat(s, GetPString(IDS_FULLSCREENTEXT));
515 }
516 if (apptype & FAPPTYP_32BIT) {
517 if (*s)
518 strcat(s, " ");
519 strcat(s, GetPString(IDS_32BITTEXT));
520 }
521 WinSetDlgItemText(hwnd, EXEC_WARNING2, s);
522 if ((apptype & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL |
523 FAPPTYP_WINDOWSPROT | 0x1000)) ||
524 ((apptype & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI)) {
525 WinCheckButton(hwnd, EXEC_KEEP, FALSE);
526 WinEnableWindow(WinWindowFromID(hwnd, EXEC_KEEP), FALSE);
527 }
528 if (apptype & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | 0x1000))
529 WinCheckButton(hwnd, EXEC_FULLSCREEN, TRUE);
530 }
531 else
532 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_UNKNOWNDEFAULTTEXT));
533 }
534 return 0;
535
536 case WM_ADJUSTWINDOWPOS:
537 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
538 break;
539
540 case UM_SETDIR:
541 PaintRecessedWindow(WinWindowFromID(hwnd,
542 EXEC_WARNING2),
543 (HPS) 0, FALSE, FALSE);
544 return 0;
545
546 case UM_RESCAN:
547 WinSendDlgItemMsg(hwnd, EXEC_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
548 if (!DoItYourselfLoaded)
549 load_cmdlines(TRUE);
550 {
551 LINKCMDLINES *info;
552
553 info = DoItYourselfCmdLine;
554 while (info) {
555 WinSendDlgItemMsg(hwnd,
556 EXEC_LISTBOX,
557 LM_INSERTITEM,
558 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline));
559 info = info->next;
560 }
561 }
562 return 0;
563
564 case WM_CONTROL:
565 switch (SHORT1FROMMP(mp1)) {
566 case EXEC_SAVECMD:
567 {
568 fSaveBigCmds = (fSaveBigCmds) ? FALSE : TRUE;
569 WinCheckButton(hwnd, EXEC_SAVECMD, fSaveBigCmds);
570 PrfWriteProfileData(fmprof, appname, "SaveBigCmds", &fSaveBigCmds, sizeof(BOOL));
571 }
572 break;
573 case EXEC_CL:
574 switch (SHORT2FROMMP(mp1)) {
575 case EN_KILLFOCUS:
576 ex = INSTDATA(hwnd);
577 if (!ex || !ex->dropped)
578 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
579 break;
580 }
581 break;
582 case EXEC_LISTBOX:
583 switch (SHORT2FROMMP(mp1)) {
584 case LN_KILLFOCUS:
585 ex = INSTDATA(hwnd);
586 if (ex) {
587 if (ex->dropped)
588 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(EXEC_DROP, 0), MPVOID);
589 }
590 break;
591 case LN_ENTER:
592 {
593 SHORT x;
594 CHAR cmdline[1001];
595
596 x = (SHORT) WinSendDlgItemMsg(hwnd,
597 EXEC_LISTBOX,
598 LM_QUERYSELECTION,
599 MPFROMSHORT(LIT_FIRST), MPVOID);
600 if (x >= 0) {
601 *cmdline = 0;
602 WinSendDlgItemMsg(hwnd,
603 EXEC_LISTBOX,
604 LM_QUERYITEMTEXT,
605 MPFROM2SHORT(x,
606 sizeof(cmdline)),
607 MPFROMP(cmdline));
608 bstrip(cmdline);
609 if (*cmdline) {
610 WinSetDlgItemText(hwnd, EXEC_CL, cmdline);
611 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(EXEC_DROP, 0), MPVOID);
612 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
613 }
614 }
615 }
616 break;
617 }
618 break;
619 }
620 return 0;
621
622 case WM_HELP:
623 if (hwndHelp)
624 WinSendMsg(hwndHelp,
625 HM_DISPLAY_HELP,
626 MPFROM2SHORT(HELP_CMDLINE, 0), MPFROMSHORT(HM_RESOURCEID));
627 break;
628
629 case WM_COMMAND:
630 switch (SHORT1FROMMP(mp1)) {
631 case EXEC2_CLR:
632 free_cmdlines(TRUE);
633 save_cmdlines(TRUE);
634 WinSendDlgItemMsg(hwnd, EXEC_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
635 break;
636 case EXEC2_DEL:
637 {
638 SHORT x;
639 CHAR cmdline[1001];
640
641 x = (SHORT) WinSendDlgItemMsg(hwnd,
642 EXEC_LISTBOX,
643 LM_QUERYSELECTION,
644 MPFROMSHORT(LIT_FIRST), MPVOID);
645 if (x >= 0) {
646 *cmdline = 0;
647 WinSendDlgItemMsg(hwnd,
648 EXEC_LISTBOX,
649 LM_QUERYITEMTEXT,
650 MPFROM2SHORT(x, sizeof(cmdline)),
651 MPFROMP(cmdline));
652 bstrip(cmdline);
653 if (*cmdline) {
654 if (remove_cmdline(cmdline, TRUE) && fSaveBigCmds) {
655 save_cmdlines(TRUE);
656 WinSendDlgItemMsg(hwnd,
657 EXEC_LISTBOX,
658 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
659 if (x)
660 x--;
661 WinSendDlgItemMsg(hwnd,
662 EXEC_LISTBOX,
663 LM_SELECTITEM,
664 MPFROMSHORT(x), MPFROMSHORT(TRUE));
665 }
666 }
667 }
668 }
669 break;
670 case EXEC_DROP:
671 ex = INSTDATA(hwnd);
672 if (ex) {
673 if (!ex->dropped) {
674 *ex->tempprompt = 0;
675 WinQueryDlgItemText(hwnd,
676 EXEC_WARNING2,
677 sizeof(ex->tempprompt), ex->tempprompt);
678 WinSetDlgItemText(hwnd, EXEC_WARNING2, (CHAR *) GetPString(IDS_CMDSELCMDHELPTEXT));
679 ex->dropped = TRUE;
680 if ((SHORT) WinSendDlgItemMsg(hwnd,
681 EXEC_LISTBOX,
682 LM_QUERYITEMCOUNT,
683 MPVOID, MPVOID) == 0)
684 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
685 WinShowWindow(WinWindowFromID(hwnd, EXEC_CL), FALSE);
686 WinShowWindow(WinWindowFromID(hwnd, EXEC_WARNING), FALSE);
687 WinShowWindow(WinWindowFromID(hwnd, EXEC_DEFAULT), FALSE);
688 WinShowWindow(WinWindowFromID(hwnd, EXEC_MINIMIZED), FALSE);
689 WinShowWindow(WinWindowFromID(hwnd, EXEC_MAXIMIZED), FALSE);
690 WinShowWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), FALSE);
691 WinShowWindow(WinWindowFromID(hwnd, EXEC_INVISIBLE), FALSE);
692 WinShowWindow(WinWindowFromID(hwnd, EXEC_KEEP), FALSE);
693 WinShowWindow(WinWindowFromID(hwnd, EXEC_ENVIRON), FALSE);
694 WinShowWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
695 WinShowWindow(WinWindowFromID(hwnd, IDM_HELP), FALSE);
696 WinShowWindow(WinWindowFromID(hwnd, EXEC_ABORT), FALSE);
697 WinShowWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
698 WinShowWindow(WinWindowFromID(hwnd, EXEC_LISTBOX), TRUE);
699 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, EXEC_LISTBOX));
700 WinSetDlgItemText(hwnd, EXEC_DROP, "^");
701 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), TRUE);
702 }
703 else {
704 ex->dropped = FALSE;
705 WinSetDlgItemText(hwnd, EXEC_WARNING2, ex->tempprompt);
706 WinShowWindow(WinWindowFromID(hwnd, EXEC_LISTBOX), FALSE);
707 WinShowWindow(WinWindowFromID(hwnd, EXEC_CL), TRUE);
708 WinShowWindow(WinWindowFromID(hwnd, EXEC_WARNING), TRUE);
709 WinShowWindow(WinWindowFromID(hwnd, EXEC_DEFAULT), TRUE);
710 WinShowWindow(WinWindowFromID(hwnd, EXEC_MINIMIZED), TRUE);
711 WinShowWindow(WinWindowFromID(hwnd, EXEC_MAXIMIZED), TRUE);
712 WinShowWindow(WinWindowFromID(hwnd, EXEC_FULLSCREEN), TRUE);
713 WinShowWindow(WinWindowFromID(hwnd, EXEC_INVISIBLE), TRUE);
714 WinShowWindow(WinWindowFromID(hwnd, EXEC_KEEP), TRUE);
715 WinShowWindow(WinWindowFromID(hwnd, EXEC_ENVIRON), TRUE);
716 WinShowWindow(WinWindowFromID(hwnd, DID_OK), TRUE);
717 WinShowWindow(WinWindowFromID(hwnd, IDM_HELP), TRUE);
718 WinShowWindow(WinWindowFromID(hwnd, EXEC_ABORT), TRUE);
719 WinShowWindow(WinWindowFromID(hwnd, DID_CANCEL), TRUE);
720 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, EXEC_CL));
721 WinSetDlgItemText(hwnd, EXEC_DROP, "v");
722 WinShowWindow(WinWindowFromID(hwnd, EXEC2_DEL), FALSE);
723 }
724 }
725 break;
726
727 case DID_OK:
728 ex = INSTDATA(hwnd);
729 WinQueryDlgItemText(hwnd, EXEC_CL, 1000, ex->commandline);
730 ex->flags = CheckExecutibleFlags(hwnd, 2);
731 /*ex->flags = 0;
732 if (WinQueryButtonCheckstate(hwnd, EXEC_MINIMIZED))
733 ex->flags |= MINIMIZED;
734 if (WinQueryButtonCheckstate(hwnd, EXEC_MAXIMIZED))
735 ex->flags |= MAXIMIZED;
736 if (WinQueryButtonCheckstate(hwnd, EXEC_FULLSCREEN))
737 ex->flags |= FULLSCREEN;
738 else
739 ex->flags |= WINDOWED;
740 if (WinQueryButtonCheckstate(hwnd, EXEC_INVISIBLE))
741 ex->flags |= INVISIBLE;
742 if (WinQueryButtonCheckstate(hwnd, EXEC_KEEP))
743 ex->flags |= SEPARATEKEEP;
744 else
745 ex->flags |= SEPARATE;*/
746 strset(ex->environment, 0);
747 WinQueryDlgItemText(hwnd, EXEC_ENVIRON, 1000, ex->environment);
748 if (add_cmdline(ex->commandline, TRUE) && fSaveBigCmds)
749 save_cmdlines(TRUE);
750 WinDismissDlg(hwnd, 1);
751 break;
752
753 case DID_CANCEL:
754 WinDismissDlg(hwnd, 0);
755 break;
756
757 case EXEC_ABORT:
758 WinDismissDlg(hwnd, 2);
759 break;
760
761 case IDM_HELP:
762 if (hwndHelp)
763 WinSendMsg(hwndHelp,
764 HM_DISPLAY_HELP,
765 MPFROM2SHORT(HELP_CMDLINE, 0), MPFROMSHORT(HM_RESOURCEID));
766 break;
767 }
768 return 0;
769
770 case WM_DESTROY:
771 break;
772 }
773 return WinDefDlgProc(hwnd, msg, mp1, mp2);
774}
775
776MRESULT EXPENTRY CmdLine2DlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
777{
778 switch (msg) {
779 case WM_INITDLG:
780 if (!mp2) {
781 WinDismissDlg(hwnd, 0);
782 break;
783 }
784 WinSetWindowPtr(hwnd, QWL_USER, mp2);
785 {
786 int x;
787 USHORT ids[] = { IDM_HELP, EXEC2_CLR, EXEC2_DEL, EXEC2_KEEP, EXEC2_SAVE,
788 EXEC2_OPEN, EXEC2_CLOSE, EXEC2_FILTER, DID_CANCEL, 0
789 };
790
791 WinSetWindowPtr(WinWindowFromID(hwnd, EXEC2_LISTBOX),
792 QWL_USER,
793 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
794 EXEC2_LISTBOX),
795 (PFNWP) CmdListSubProc));
796 for (x = 0; ids[x]; x++)
797 WinSetWindowPtr(WinWindowFromID(hwnd, ids[x]),
798 QWL_USER,
799 (PVOID) WinSubclassWindow(WinWindowFromID(hwnd,
800 ids[x]),
801 (PFNWP) CmdBtnSubProc));
802 }
803 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
804 break;
805
806 case UM_RESCAN:
807 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
808 if (!MiniLoaded)
809 load_cmdlines(FALSE);
810 {
811 LINKCMDLINES *info;
812
813 info = MiniCmdLine;
814 while (info) {
815 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_INSERTITEM,
816 MPFROM2SHORT(LIT_END, 0), MPFROMP(info->cmdline));
817 info = info->next;
818 }
819 }
820 return 0;
821
822 case WM_CONTROL:
823 switch (SHORT1FROMMP(mp1)) {
824 case EXEC2_LISTBOX:
825 switch (SHORT2FROMMP(mp1)) {
826 case LN_ENTER:
827 {
828 SHORT x;
829 CHAR *cmdline = WinQueryWindowPtr(hwnd, QWL_USER);
830
831 x = (SHORT) WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX,
832 LM_QUERYSELECTION,
833 MPFROMSHORT(LIT_FIRST), MPVOID);
834 if (x >= 0) {
835 *cmdline = 0;
836 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_QUERYITEMTEXT,
837 MPFROM2SHORT(x, 1000), MPFROMP(cmdline));
838 bstrip(cmdline);
839 if (*cmdline)
840 WinDismissDlg(hwnd, 1);
841 }
842 }
843 break;
844 }
845 break;
846 }
847 return 0;
848
849 case WM_COMMAND:
850 switch (SHORT1FROMMP(mp1)) {
851 case EXEC2_KEEP:
852 case EXEC2_SAVE:
853 case EXEC2_FILTER:
854 case EXEC2_CLOSE:
855 case EXEC2_OPEN:
856 case IDM_HELP:
857 {
858 char *cmdline = WinQueryWindowPtr(hwnd, QWL_USER);
859 ULONG strid = 0;
860
861 if (cmdline) {
862 switch (SHORT1FROMMP(mp1)) {
863 case EXEC2_OPEN:
864 strid = IDS_OPENCMDTEXT;
865 break;
866 case EXEC2_CLOSE:
867 strid = IDS_CLOSECMDTEXT;
868 break;
869 case EXEC2_FILTER:
870 strid = IDS_FILTERCMDTEXT;
871 break;
872 case EXEC2_SAVE:
873 strid = (fSaveMiniCmds) ? IDS_NOSAVECMDTEXT : IDS_SAVECMDTEXT;
874 break;
875 case EXEC2_KEEP:
876 strid = (fKeepCmdLine) ? IDS_NOKEEPCMDTEXT : IDS_KEEPCMDTEXT;
877 break;
878 case IDM_HELP:
879 strid = IDS_HELPCMDTEXT;
880 break;
881 }
882 if (strid) {
883 strcpy(cmdline, GetPString(strid));
884 WinDismissDlg(hwnd, 1);
885 }
886 }
887 break;
888 }
889 case EXEC2_CLR:
890 free_cmdlines(FALSE);
891 save_cmdlines(FALSE);
892 WinSendDlgItemMsg(hwnd, EXEC2_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
893 break;
894 case EXEC2_DEL:
895 {
896 SHORT x;
897 CHAR cmdline[1001];
898
899 x = (SHORT) WinSendDlgItemMsg(hwnd,
900 EXEC2_LISTBOX,
901 LM_QUERYSELECTION,
902 MPFROMSHORT(LIT_FIRST), MPVOID);
903 if (x >= 0) {
904 *cmdline = 0;
905 WinSendDlgItemMsg(hwnd,
906 EXEC2_LISTBOX,
907 LM_QUERYITEMTEXT,
908 MPFROM2SHORT(x, sizeof(cmdline)),
909 MPFROMP(cmdline));
910 bstrip(cmdline);
911 if (*cmdline) {
912 if (remove_cmdline(cmdline, FALSE) && fSaveMiniCmds) {
913 save_cmdlines(FALSE);
914 WinSendDlgItemMsg(hwnd,
915 EXEC2_LISTBOX,
916 LM_DELETEITEM, MPFROMSHORT(x), MPVOID);
917 if (x)
918 x--;
919 WinSendDlgItemMsg(hwnd,
920 EXEC2_LISTBOX,
921 LM_SELECTITEM,
922 MPFROMSHORT(x), MPFROMSHORT(TRUE));
923 }
924 }
925 }
926 }
927 break;
928 case DID_CANCEL:
929 WinDismissDlg(hwnd, 0);
930 break;
931 }
932 return 0;
933
934 case WM_DESTROY:
935 break;
936 }
937 return WinDefDlgProc(hwnd, msg, mp1, mp2);
938}
939
940#pragma alloc_text(CMDLINE1,CmdLineDlgProc,CmdListSubProc,CmdLine2DlgProc,CmdBtnSubProc)
941#pragma alloc_text(CMDLINE2,save_cmdlines,load_cmdlines,add_cmdline,remove_cmdline,free_cmdlines)
Note: See TracBrowser for help on using the repository browser.