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