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