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