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