Changeset 1491 for trunk


Ignore:
Timestamp:
Dec 28, 2009, 3:20:57 AM (16 years ago)
Author:
Gregg Young
Message:

Moved the commands to the ini file; made command hotkeys user selectable; some code cleanup and consolidation in command.c (tickets 65, 186)

Location:
trunk/dll
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/command.c

    r1488 r1491  
    3333  21 Dec 09 GKY Added 20 new hot keys for commands.
    3434  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
    3537
    3638***********************************************************************/
     
    8082COMMAND;
    8183
     84BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp);
     85VOID save_commands(VOID);
     86
    8287// Data defintions
    8388#pragma data_seg(DATA1)
     
    8792static BOOL UsedCommandIDs[300];
    8893static BOOL UsedHotKeyIDs[40];
     94static PSZ pszCommandsList;
     95static ULONG ulSizeCommandsList = 10000;
     96static BOOL fLoadCommandsFromINI = FALSE;
    8997
    9098#pragma data_seg(GLOBAL2)
     
    349357    info = next;
    350358  }
     359  free(pszCommandsList);
    351360  cmdhead = cmdtail = NULL;
    352361}
     
    359368  CHAR title[100];
    360369  CHAR flags[34];
     370  //CHAR *p;
    361371  ULONG size;
    362372
    363   if (cmdhead)
    364     free_commands();
    365   PrfQueryProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     373
     374  size = sizeof(BOOL) * 300;
     375  PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
    366376                      &size);
    367   PrfQueryProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
    368                         &size);
    369   cmdloaded = TRUE;
    370   pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
    371   if (pszCmdLine) {
    372     BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
    373     fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
    374     if (fp) {
    375       while (!feof(fp)) {
    376         if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
    377           break;
    378         //title[strlen(title)] = 0;  // Match size to entry file max? Not needed as bstripcr does this? GKY 21 Dec 09
    379         if (!*title || *title == ';')
    380           continue;
    381         if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
    382           break;                                /* error! */
    383         if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
    384           break;
    385         //pszCmdLine[strlen(pszCmdLine)] = 0;      // fixme to know why chopped this way? Not needed as bstripcr does this? GKY 21 Dec 09
    386         flags[34] = 0;
    387         if (!pszCmdLine)
    388           continue;
    389         info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
    390         if (info) {
    391 #         ifdef FORTIFY
    392           Fortify_SetOwner(info, 1);
    393           Fortify_SetScope(info, 1);
    394 #         endif
    395           info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
    396           info->title = xstrdup(title, pszSrcFile, __LINE__);
    397           info->flags = atol(flags);
    398           if (!info->pszCmdLine || !info->title) {
    399             xfree(info->pszCmdLine, pszSrcFile, __LINE__);
    400             xfree(info->title, pszSrcFile, __LINE__);
    401             free(info);
     377  size = sizeof(BOOL) * 40;
     378  PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
     379                        &size); size = sizeof(BOOL);
     380  PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
     381                      &fLoadCommandsFromINI, &size);
     382  if (!fLoadCommandsFromINI) {
     383    if (cmdhead)
     384      free_commands();
     385    cmdloaded = TRUE;
     386    pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     387    pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
     388    if (pszCmdLine) {
     389      BldFullPathName(pszCmdLine, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
     390      fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
     391      if (fp) {
     392        while (!feof(fp)) {
     393          if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
    402394            break;
     395          if (!*title || *title == ';')
     396            continue;
     397          if (!xfgets_bstripcr(pszCmdLine, MaxComLineStrg, fp, pszSrcFile, __LINE__))
     398            break;                              /* error! */
     399          if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
     400            break;
     401          flags[34] = 0;
     402          if (!pszCmdLine)
     403            continue;
     404          info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
     405          if (info) {
     406  #       ifdef FORTIFY
     407            Fortify_SetOwner(info, 1);
     408            Fortify_SetScope(info, 1);
     409  #       endif
     410            info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
     411
     412            if (pszCommandsList) {
     413              strcpy(pszCommandsList + strlen(pszCommandsList), title);
     414              strcpy(pszCommandsList + strlen(pszCommandsList), ";");
     415            }
     416            info->title = xstrdup(title, pszSrcFile, __LINE__);
     417            info->flags = atol(flags);
     418            if (!info->pszCmdLine || !info->title) {
     419              xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     420              xfree(info->title, pszSrcFile, __LINE__);
     421              free(info);
     422              break;
     423            }
     424  #       ifdef FORTIFY
     425            Fortify_SetOwner(info->pszCmdLine, 1);
     426            Fortify_SetScope(info->pszCmdLine, 1);
     427            Fortify_SetOwner(info->title, 1);
     428            Fortify_SetScope(info->title, 1);
     429  #       endif
     430            if (!cmdhead)
     431              cmdhead = info;
     432            else {
     433              cmdtail->next = info;
     434              info->prev = cmdtail;
     435            }
     436            cmdtail = info;
    403437          }
    404 #         ifdef FORTIFY
    405           Fortify_SetOwner(info->pszCmdLine, 1);
    406           Fortify_SetScope(info->pszCmdLine, 1);
    407           Fortify_SetOwner(info->title, 1);
    408           Fortify_SetScope(info->title, 1);
    409 #         endif
    410           if (!cmdhead)
    411             cmdhead = info;
    412           else {
    413             cmdtail->next = info;
    414             info->prev = cmdtail;
    415           }
    416           cmdtail = info;
    417         }
    418       }
    419       free(pszCmdLine);
    420       fclose(fp);
    421       load_inicommands();
    422     }
    423   }
     438        }
     439        free(pszCmdLine);
     440        fclose(fp);
     441        if (pszCommandsList) {
     442          ulSizeCommandsList = strlen(pszCommandsList) + 1;
     443        }
     444      }
     445    }
     446  }
     447  load_inicommands();
    424448}
    425449
     
    438462  ULONG HotKeyID = 0;
    439463  CHAR env[1002];
    440   CHAR keyID[120];
    441   CHAR keyHotKeyID[120];
    442   CHAR keyenv[120];
     464  CHAR key[120];
     465  CHAR szTitle[100];
    443466  ULONG size;
    444 
    445   if (!cmdloaded || !cmdhead)
    446     return;
    447   info = cmdhead;
    448   while (info) {
    449     bstripcr(info->title);
    450     sprintf(keyID, "COMMAND.%sID", info->title);
    451     sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", info->title);
    452     sprintf(keyenv, "COMMAND.%senv", info->title);
    453     size = sizeof(ULONG);
    454     PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
    455     size = sizeof(ULONG);
    456     PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
    457     PrfQueryProfileString(fmprof, FM3Str, keyenv, NullStr, env, sizeof(env));
    458     if (ID) {
    459       if (env != NullStr)
    460         info->env = xstrdup(env, pszSrcFile, __LINE__);
    461       info->ID = ID;
    462       info->HotKeyID = HotKeyID;
    463     }
    464     //This updates the old commands.dat file to the new format
    465     //assigning the IDs based on file order or on next available ID if
    466     //COMMAND.DAT is hand edited.
    467     else {
    468       for (x = 0; x < 300; x++) {
    469         if (!UsedCommandIDs[x]) {
    470           ID = info->ID = IDM_COMMANDSTART + x;
    471           UsedCommandIDs[x] = TRUE;
    472           for (y = 0; y < 40; y++) {
    473             if (!UsedHotKeyIDs[y]) {
    474               HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
    475               UsedHotKeyIDs[y] = TRUE;
     467  CHAR *p, *pp;
     468  PSZ pszCmdLine;
     469  ULONG flags;
     470
     471#   ifdef FORTIFY
     472  Fortify_EnterScope();
     473#    endif
     474  pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     475  if (pszCmdLine) {
     476    if (fLoadCommandsFromINI) {
     477      if (cmdhead)
     478        free_commands();
     479      cmdloaded = TRUE;
     480      size = sizeof(ULONG);
     481      PrfQueryProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
     482                          &ulSizeCommandsList, &size);
     483      pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
     484      if (pszCommandsList)
     485        PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
     486                              NullStr, pszCommandsList, ulSizeCommandsList);
     487        p = pszCommandsList;
     488        while (*p == ';')
     489          p++;
     490        while (*p) {
     491          *szTitle = 0;
     492          pp = szTitle;
     493          while (*p && *p != ';')
     494            *pp++ = *p++;
     495          *pp = 0;
     496          while (*p == ';')
     497            p++;
     498          if (*szTitle) {
     499            bstripcr(szTitle);
     500            sprintf(key, "COMMAND.%sID", szTitle);
     501            size = sizeof(ULONG);
     502            PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
     503            sprintf(key, "COMMAND.%sHotKeyID", szTitle);
     504            size = sizeof(ULONG);
     505            PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
     506            sprintf(key, "COMMAND.%sflags", szTitle);
     507            size = sizeof(ULONG);
     508            PrfQueryProfileData(fmprof, FM3Str, key, &flags, &size);
     509            sprintf(key, "COMMAND.%senv", szTitle);
     510            PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
     511            sprintf(key, "COMMAND.%sCmdLine", szTitle);
     512            PrfQueryProfileString(fmprof, FM3Str, key, NullStr, pszCmdLine, MaxComLineStrg);
     513          }
     514          info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
     515          if (info) {
     516  #       ifdef FORTIFY
     517            Fortify_SetOwner(info, 1);
     518            Fortify_SetScope(info, 1);
     519  #       endif
     520            info->pszCmdLine = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
     521            info->title = xstrdup(szTitle, pszSrcFile, __LINE__);
     522            info->flags = flags;
     523            if (env != NullStr)
     524              info->env = xstrdup(env, pszSrcFile, __LINE__);
     525            info->ID = ID;
     526            info->HotKeyID = HotKeyID;
     527            if (!info->pszCmdLine || !info->title) {
     528              xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     529              xfree(info->title, pszSrcFile, __LINE__);
     530              xfree(info->env, pszSrcFile, __LINE__);
     531              free(info);
    476532              break;
    477533            }
     534            if (!cmdhead)
     535              cmdhead = info;
     536            else {
     537              cmdtail->next = info;
     538              info->prev = cmdtail;
     539            }
     540            cmdtail = info;
    478541          }
    479           break;
    480         }
    481         if (x == 299)
    482           saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
    483                  GetPString(IDS_COMMANDSLIMITTITLETEXT),
    484                  GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
    485       }
    486       PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
    487       info->env = env;
    488       if (env != NullStr)
    489         PrfWriteProfileString(fmprof, FM3Str, info->pszCmdLine, NULL);
    490       if (info->env)
    491         strcpy(env, info->env);
    492       ID = info->ID;
    493       HotKeyID = info->HotKeyID;
    494       PrfWriteProfileData(fmprof, FM3Str, keyID, &ID, sizeof(INT));
    495       PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, sizeof(INT));
    496       if (env != NullStr)
    497         PrfWriteProfileString(fmprof, FM3Str, keyenv, env);
    498       PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
    499                       sizeof(BOOL) * 300);
    500       PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
    501                         sizeof(BOOL) * 40);
    502     }
    503     ID = 0;
    504     HotKeyID = 0;
    505     info = info->next;
     542        }
     543      }
     544    }
     545    else {
     546      info = cmdhead;
     547      while (info) {
     548        bstripcr(info->title);
     549        sprintf(key, "COMMAND.%sID", info->title);
     550        size = sizeof(ULONG);
     551        PrfQueryProfileData(fmprof, FM3Str, key, &ID, &size);
     552        sprintf(key, "COMMAND.%sHotKeyID", info->title);
     553        size = sizeof(ULONG);
     554        PrfQueryProfileData(fmprof, FM3Str, key, &HotKeyID, &size);
     555        sprintf(key, "COMMAND.%senv", info->title);
     556        PrfQueryProfileString(fmprof, FM3Str, key, NullStr, env, sizeof(env));
     557        if (ID != 0) {
     558          if (env != NullStr)
     559            info->env = xstrdup(env, pszSrcFile, __LINE__);
     560          info->ID = ID;
     561          info->HotKeyID = HotKeyID;
     562        }
     563        //This updates the old commands.dat file to the new format
     564        //assigning the IDs based on file order or on next available ID if
     565        //COMMAND.DAT is hand edited.
     566        else {
     567          for (x = 0; x < 300; x++) {
     568            if (!UsedCommandIDs[x]) {
     569              ID = info->ID = IDM_COMMANDSTART + x;
     570              UsedCommandIDs[x] = TRUE;
     571              for (y = 0; y < 40; y++) {
     572                if (!UsedHotKeyIDs[y]) {
     573                  HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
     574                  UsedHotKeyIDs[y] = TRUE;
     575                  break;
     576                }
     577              }
     578              break;
     579            }
     580            if (x == 299)
     581              saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
     582                     GetPString(IDS_COMMANDSLIMITTITLETEXT),
     583                     GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
     584          }
     585          PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
     586          info->env = xstrdup(env, pszSrcFile, __LINE__);
     587        }
     588        ID = 0;
     589        HotKeyID = 0;
     590        info = info->next;
     591      }
     592      fLoadCommandsFromINI = TRUE;
     593      save_commands();
     594    }
     595    free(pszCmdLine);
    506596  }
    507597}
     
    510600{
    511601  LINKCMDS *info;
    512   FILE *fp;
    513   CHAR s[CCHMAXPATH + 14];
    514   INT x = 0;
    515   INT ID = 0;
    516   INT HotKeyID = 0;
    517   CHAR env[1002];
    518   CHAR keyID[120];
    519   CHAR keyHotKeyID[120];
    520   CHAR keyenv[120];
    521 
     602  CHAR key[120];
     603 
    522604  if (!cmdloaded || !cmdhead)
    523605    return;
     606 
    524607  info = cmdhead;
    525   BldFullPathName(s, pFM2SaveDirectory, PCSZ_COMMANDSDAT);
    526   if (CheckDriveSpaceAvail(s, ullDATFileSpaceNeeded, 1) == 2)
    527     return; //already gave error msg
    528   fp = xfopen(s, "w", pszSrcFile, __LINE__);
    529   if (fp) {
     608  pszCommandsList[0] = 0;
    530609    while (info) {
    531       fprintf(fp, ";\n%0.99s\n%0.*s\n%lu\n",
    532               info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
    533      
    534       if (info->env)
    535         strcpy(env, info->env);
    536       ID = info->ID;
    537       HotKeyID = info->HotKeyID;
     610      sprintf(key, "COMMAND.%sflags", info->title);
     611      PrfWriteProfileData(fmprof, FM3Str, key, &info->flags, sizeof(ULONG));
     612      sprintf(key, "COMMAND.%sCmdLine", info->title);
     613      PrfWriteProfileString(fmprof, FM3Str, key, info->pszCmdLine);
    538614      bstripcr(info->title);
    539       sprintf(keyID, "COMMAND.%sID", info->title);
    540       sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", info->title);
    541       sprintf(keyenv, "COMMAND.%senv", info->title);
    542       PrfWriteProfileData(fmprof, FM3Str, keyID, &ID, sizeof(INT));
    543       PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, sizeof(INT));
    544       if (env != NullStr)
    545         PrfWriteProfileString(fmprof, FM3Str, keyenv, env);
    546       x++;
     615      sprintf(key, "COMMAND.%sID", info->title);
     616      PrfWriteProfileData(fmprof, FM3Str, key, &info->ID, sizeof(INT));
     617      sprintf(key, "COMMAND.%sHotKeyID", info->title);
     618      PrfWriteProfileData(fmprof, FM3Str, key, &info->HotKeyID, sizeof(INT));
     619      if (info->env != NullStr) {
     620        sprintf(key, "COMMAND.%senv", info->title);
     621        PrfWriteProfileString(fmprof, FM3Str, key, info->env);
     622      }
     623      if ((strlen(pszCommandsList) + strlen(info->title) + 1) > ulSizeCommandsList)
     624        pszCommandsList = xrealloc(pszCommandsList,
     625                                   ulSizeCommandsList + strlen(info->title) + 1,
     626                                   pszSrcFile, __LINE__);
     627      strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
     628      strcpy(pszCommandsList + strlen(pszCommandsList), ";");
    547629      info = info->next;
    548630    } // while info
    549     PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     631    PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedCommandIDs", &UsedCommandIDs,
    550632                        sizeof(BOOL) * 300);
    551     PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
     633    PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.UsedHotKeyIDs", &UsedHotKeyIDs,
    552634                        sizeof(BOOL) * 40);
    553     fclose(fp);
    554   } // if (fp)
     635    ulSizeCommandsList = strlen(pszCommandsList) + 1;
     636    PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.SizeSortOrder",
     637                        &ulSizeCommandsList, sizeof(ULONG));
     638    PrfWriteProfileString(fmprof, FM3Str, "COMMANDS.SortOrder", pszCommandsList);
     639    PrfWriteProfileData(fmprof, FM3Str, "COMMANDS.LoadCommandsFromINI",
     640                        &fLoadCommandsFromINI, sizeof(BOOL));
    555641}
    556642
    557643//== add_command() Add command to list ==
    558644
    559 LINKCMDS *add_command(COMMAND *addme)
     645LINKCMDS *add_command(COMMAND *addme, BOOL fDontCheckHotKey)
    560646{
    561647  LINKCMDS *info;
    562648  INT x;
    563649  INT y;
     650  APIRET ret;
    564651
    565652  if (!addme || !*addme->pszCmdLine || !*addme->title)
    566653    return NULL;                        // No data
     654#   ifdef FORTIFY
     655    Fortify_EnterScope();
     656#    endif
    567657  info = cmdhead;
    568658  while (info) {
    569659    if (!stricmp(info->title, addme->title))
    570660      return NULL;                      // Got a dup
    571     if (addme->HotKeyID && info->HotKeyID && info->HotKeyID == addme->HotKeyID)
    572       info->HotKeyID = 0;  //avoid assigning hot key to multiple commands
    573661    info = info->next;
     662  }
     663  if (!fDontCheckHotKey && UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0]) {
     664    info = cmdhead;
     665    while (info) {
     666      if (info->HotKeyID == addme->HotKeyID) { //avoid assigning hot key to multiple commands
     667        ret = saymsg(MB_YESNOCANCEL, HWND_DESKTOP, NullStr,
     668                     GetPString(IDS_DUPLICATEHOTKEYTEXT));
     669        if (ret == MBID_YES) {
     670          info->HotKeyID = 0; 
     671          UsedHotKeyIDs[addme->HotKeyID - IDM_COMMANDNUM0] = FALSE;
     672          break;
     673        }
     674        else if (ret == MBID_NO) {
     675          addme->HotKeyID = 0;
     676          break;
     677        }
     678        else
     679          return NULL;
     680      }
     681      info = info->next;
     682    }
    574683  }
    575684  info = xmallocz(sizeof(LINKCMDS), pszSrcFile, __LINE__);
     
    579688  info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
    580689  info->HotKeyID = addme->HotKeyID;
    581   if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM19)
     690  info->ID = addme->ID;
     691  if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM39) {
    582692    UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
     693  }
    583694  else
    584695    info->HotKeyID = 0;
     
    589700        info->ID = IDM_COMMANDSTART + x;
    590701        UsedCommandIDs[x] = TRUE;
    591         for (y = 0; y < 40; y++) {
    592           if (!UsedHotKeyIDs[y]) {
    593             info->HotKeyID = IDM_COMMANDNUM0 + y;
    594             UsedHotKeyIDs[y] = TRUE;
    595             break;
     702        if (!info->HotKeyID && !fDontCheckHotKey) {
     703          for (y = 0; y < 40; y++) {
     704            if (!UsedHotKeyIDs[y]) {
     705              info->HotKeyID = IDM_COMMANDNUM0 + y;
     706              UsedHotKeyIDs[y] = TRUE;
     707              break;
    596708            }
    597709          }
     710        }
    598711        break;
    599712      }
     
    611724    xfree(info->pszCmdLine, pszSrcFile, __LINE__);
    612725    xfree(info->title, pszSrcFile, __LINE__);
    613     xfree(info->title, pszSrcFile, __LINE__);
     726    xfree(info->env, pszSrcFile, __LINE__);
    614727    free(info);
    615728    return NULL;
     
    622735    info->prev = cmdtail;
    623736    cmdtail = info;
     737  }
     738  pszCommandsList = xrealloc(pszCommandsList, ulSizeCommandsList + strlen(info->title) + 1,
     739                             pszSrcFile, __LINE__);
     740  if (pszCommandsList) {
     741    strcpy(pszCommandsList + strlen(pszCommandsList), info->title);
     742    strcpy(pszCommandsList + strlen(pszCommandsList), ";");
     743    ulSizeCommandsList = ulSizeCommandsList + strlen(info->title) + 1;
     744  }
     745  else {
     746    pszCommandsList = xmallocz(ulSizeCommandsList, pszSrcFile, __LINE__);
     747    if (pszCommandsList)
     748      PrfQueryProfileString(fmprof, FM3Str, "COMMANDS.SortOrder",
     749                            NullStr, pszCommandsList, ulSizeCommandsList);
     750    return 0;
    624751  }
    625752  return info;
     
    659786    }
    660787  }
     788#   ifdef FORTIFY
     789    Fortify_LeaveScope();
     790#    endif
    661791  return FALSE;
     792}
     793
     794BOOL QueryCommandSettings(HWND hwnd, COMMAND *temp)
     795{
     796   PSZ pszWorkBuf;
     797   APIRET ret;
     798   CHAR env[1002];
     799   INT x;
     800
     801   pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
     802   if (!pszWorkBuf) {
     803     return FALSE; //already complained
     804   }
     805   WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp->pszCmdLine);
     806   NormalizeCmdLine(pszWorkBuf, temp->pszCmdLine);
     807   memcpy(temp->pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
     808   free(pszWorkBuf);
     809   if (fCancelAction) {
     810     fCancelAction = FALSE;
     811     return FALSE;
     812   }
     813   if (!strchr(temp->pszCmdLine, '%')) {
     814     ret = saymsg(MB_YESNO,
     815                  HWND_DESKTOP,
     816                  NullStr,
     817                  GetPString(IDS_TOACTONSELECTEDTEXT));
     818     if (ret == MBID_YES)
     819       strcat(temp->pszCmdLine, " %a");
     820   }
     821   WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp->title), temp->title);
     822   bstripcr(temp->title);
     823   temp->flags = CheckExecutibleFlags(hwnd, 3);
     824   *env = 0;
     825   WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
     826   bstripcr(env);
     827   if (*env)
     828     strcpy(temp->env, env);
     829   x = (SHORT) WinSendDlgItemMsg(hwnd, CMD_HOTKEY,
     830                                 LM_QUERYSELECTION,
     831                                 MPFROMSHORT(LIT_FIRST), MPVOID);
     832   if (x < 40)
     833     temp->HotKeyID = x + IDM_COMMANDNUM0;
     834   else
     835     temp->HotKeyID = 0;
     836   DbgMsg(pszSrcFile, __LINE__, "info %i", temp->HotKeyID);
     837   return TRUE;
    662838}
    663839
     
    667843  LINKCMDS *info;
    668844
     845#   ifdef FORTIFY
     846    Fortify_EnterScope();
     847#    endif
    669848  switch (msg) {
    670849  case WM_INITDLG:
     
    737916            WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
    738917          else
    739             WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
    740         }
     918            WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
     919          for (x = 0; x < 40; x++) {
     920            CHAR s[CCHMAXPATH + 24];
     921
     922            sprintf(s, "%s%s%s",
     923                    x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0 ? "Ctrl+" : NullStr,
     924                    x > IDM_COMMANDNUM19 - IDM_COMMANDNUM0 ? "Alt+" : NullStr,
     925                    (x > IDM_COMMANDNUM9 - IDM_COMMANDNUM0 &&
     926                    x < IDM_COMMANDNUM20 - IDM_COMMANDNUM0) ||
     927                    x > IDM_COMMANDNUM29 - IDM_COMMANDNUM0 ? "Shift+" : NullStr);
     928            sprintf(&s[strlen(s)], "%d", (x % 10) + 1 == 10 ? 0 : (x % 10) + 1);
     929            sprintf(&s[strlen(s)], " %s", UsedHotKeyIDs[x] ? "(in use)" : NullStr);
     930            WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
     931                       MPFROM2SHORT(LIT_END, 0), MPFROMP(s));
     932            if (x == 39)
     933              WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_INSERTITEM,
     934                         MPFROM2SHORT(LIT_END, 0), MPFROMP("none"));
     935            if (info->HotKeyID == x + IDM_COMMANDNUM0)
     936              WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
     937                         MPFROM2SHORT(x, 0), MPFROMLONG(TRUE));
     938            if (x == 39 && info->HotKeyID == 0)
     939              WinSendMsg(WinWindowFromID(hwnd, CMD_HOTKEY), LM_SELECTITEM,
     940                         MPFROM2SHORT(x + 1, 0), MPFROMLONG(TRUE));
     941          } // for
     942        }
    741943        break;
    742944      }
     
    794996    case DID_OK:
    795997      {
    796         x = (SHORT) WinSendDlgItemMsg(hwnd,
    797                                       CMD_LISTBOX,
    798                                       LM_QUERYSELECTION, MPVOID, MPVOID);
    799         if (x == LIT_NONE)
    800           x = (SHORT) WinSendDlgItemMsg(hwnd,
    801                                         CMD_LISTBOX,
    802                                         LM_SELECTITEM,
    803                                         MPFROMSHORT(0), MPFROMSHORT(TRUE));
    804       }
    805       {
    806         COMMAND temp;
    807         PSZ pszWorkBuf;
    808         APIRET ret;
    809         CHAR env[1002];
    810 
    811         memset(&temp, 0, sizeof(COMMAND));
    812         temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
    813         if (!temp.pszCmdLine)
     998        COMMAND *temp;
     999        BOOL fDontCheckHotKey = FALSE;
     1000
     1001        temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
     1002        if (!temp)
     1003          break;  //already complained
     1004        temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     1005        if (!temp->pszCmdLine) {
     1006          free (temp);
    8141007          break; //already complained
    815         pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
    816         if (!pszWorkBuf) {
    817           free(temp.pszCmdLine);
    818           break; //already complained
    819         }
    820         WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
    821         NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
    822         memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    823         free(pszWorkBuf);
    824         if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
    825           ret = saymsg(MB_YESNO,
    826                        HWND_DESKTOP,
    827                        NullStr,
    828                        GetPString(IDS_TOACTONSELECTEDTEXT));
    829           if (ret == MBID_YES)
    830             strcat(temp.pszCmdLine, " %a");
    831         }
    832         WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    833         bstripcr(temp.title);
    834         temp.flags = CheckExecutibleFlags(hwnd, 3);
    835         /*if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
    836           temp.flags = 0;
    837         else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
    838           temp.flags = FULLSCREEN;
    839         else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
    840           temp.flags = MINIMIZED;
    841         else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
    842           temp.flags = MAXIMIZED;
    843         else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
    844           temp.flags = INVISIBLE;
    845         if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
    846           temp.flags |= KEEP;
    847         if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
    848           temp.flags |= PROMPT;
    849         if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    850           temp.flags |= ONCE;*/
    851         *env = 0;
    852         WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    853         bstripcr(env);
    854         if (*env) {
    855           strcpy(temp.env, env);
    856           }
    857         if (fCancelAction){
    858           fCancelAction = FALSE;
    859           free(temp.pszCmdLine);
     1008        }
     1009        if (QueryCommandSettings(hwnd, temp)){
     1010          if (temp->HotKeyID == 0)
     1011            fDontCheckHotKey = TRUE;
     1012          info = add_command(temp, fDontCheckHotKey);
     1013        }
     1014        else {
     1015          free(temp->pszCmdLine);
     1016          free(temp);
    8601017          break;
    8611018        }
    862         else
    863           info = add_command(&temp);
    864         if (!info)
    865           WinDismissDlg(hwnd, 0);
    866         else {
    867           x = (SHORT) WinSendDlgItemMsg(hwnd,
    868                                         CMD_LISTBOX,
    869                                         LM_INSERTITEM,
    870                                         MPFROM2SHORT(LIT_END, 0),
    871                                         MPFROMP(temp.title));
    872           if (x >= 0) {
    873             WinSendDlgItemMsg(hwnd,
    874                               CMD_LISTBOX,
    875                               LM_SETITEMHANDLE,
    876                               MPFROMSHORT(x), MPFROMP(info));
    877             WinSendDlgItemMsg(hwnd,
    878                               CMD_LISTBOX,
    879                               LM_SELECTITEM,
    880                               MPFROMSHORT(x), MPFROMSHORT(TRUE));
    881           }
    882         }
     1019        free(temp->pszCmdLine);
     1020        free(temp);
    8831021        save_commands();
    884         load_commands();
    885         free(temp.pszCmdLine);
    886       }
    887       x = (SHORT) WinSendDlgItemMsg(hwnd,
    888                                     CMD_LISTBOX,
    889                                     LM_QUERYSELECTION,
    890                                     MPFROMSHORT(LIT_FIRST), MPVOID);
    891       save_commands();
    892       WinDismissDlg(hwnd, 0);
    893       break;
     1022        WinDismissDlg(hwnd, 0);
     1023        break;
     1024      }
    8941025
    8951026    case DID_CANCEL:
     
    9061037    case CMD_ADD:
    9071038      {
    908         COMMAND temp;
    909         PSZ pszWorkBuf;
    910         APIRET ret;
    911         CHAR env[1002];
    912 
    913         memset(&temp, 0, sizeof(COMMAND));
    914         temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
    915         if (!temp.pszCmdLine)
     1039        COMMAND *temp;
     1040        BOOL fDontCheckHotKey = FALSE;
     1041
     1042        temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
     1043        if (!temp)
     1044          break;  //already complained
     1045        temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     1046        if (!temp->pszCmdLine) {
     1047          free (temp);
    9161048          break; //already complained
    917         pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
    918         if (!pszWorkBuf) {
    919           free(temp.pszCmdLine);
    920           break; //already complained
    921         }
    922         WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
    923         NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
    924         memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    925         free(pszWorkBuf);
    926         if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
    927           ret = saymsg(MB_YESNO,
    928                        HWND_DESKTOP,
    929                        NullStr,
    930                        GetPString(IDS_TOACTONSELECTEDTEXT));
    931           if (ret == MBID_YES)
    932             strcat(temp.pszCmdLine, " %a");
    933         }
    934         WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    935         bstripcr(temp.title);
    936         temp.flags = CheckExecutibleFlags(hwnd, 3);
    937         /*if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
    938           temp.flags = 0;
    939         else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
    940           temp.flags = FULLSCREEN;
    941         else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
    942           temp.flags = MINIMIZED;
    943         else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
    944           temp.flags = MAXIMIZED;
    945         else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
    946           temp.flags = INVISIBLE;
    947         if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
    948           temp.flags |= KEEP;
    949         if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
    950           temp.flags |= PROMPT;
    951         if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    952           temp.flags |= ONCE;*/
    953         *env = 0;
    954         WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    955         bstripcr(env);
    956         if (*env) {
    957           strcpy(temp.env, env);
    958           }
    959         if (fCancelAction){
    960           fCancelAction = FALSE;
    961           free(temp.pszCmdLine);
     1049        }
     1050        if (!QueryCommandSettings(hwnd, temp)) {
     1051          free(temp->pszCmdLine);
     1052          free(temp);
    9621053          break;
    9631054        }
    964         else
    965           info = add_command(&temp);
    966         if (!info) {
    967           saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
    968                  GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp.title);
    969         }
    970         else {
    971           x = (SHORT) WinSendDlgItemMsg(hwnd,
    972                                         CMD_LISTBOX,
    973                                         LM_INSERTITEM,
    974                                         MPFROM2SHORT(LIT_END, 0),
    975                                         MPFROMP(temp.title));
    976           if (x >= 0) {
    977             WinSendDlgItemMsg(hwnd,
    978                               CMD_LISTBOX,
    979                               LM_SETITEMHANDLE,
    980                               MPFROMSHORT(x), MPFROMP(info));
    981             WinSendDlgItemMsg(hwnd,
    982                               CMD_LISTBOX,
    983                               LM_SELECTITEM,
    984                               MPFROMSHORT(x), MPFROMSHORT(TRUE));
    985             save_commands();
    986           }
    987         }
    988         free(temp.pszCmdLine);
    989       }
    990       break;
     1055        else {
     1056          if (temp->HotKeyID == 0)
     1057            fDontCheckHotKey = TRUE;
     1058          info = add_command(temp, fDontCheckHotKey);
     1059          if (!info) {
     1060            saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
     1061                   GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp->title);
     1062            free(temp->pszCmdLine);
     1063            free(temp);
     1064            break;
     1065          }
     1066        x = (SHORT) WinSendDlgItemMsg(hwnd,
     1067                                      CMD_LISTBOX,
     1068                                      LM_INSERTITEM,
     1069                                      MPFROM2SHORT(LIT_END, 0),
     1070                                      MPFROMP(temp->title));
     1071        if (x >= 0) {
     1072          WinSendDlgItemMsg(hwnd,
     1073                            CMD_LISTBOX,
     1074                            LM_SETITEMHANDLE,
     1075                            MPFROMSHORT(x), MPFROMP(info));
     1076          WinSendDlgItemMsg(hwnd,
     1077                            CMD_LISTBOX,
     1078                            LM_SELECTITEM,
     1079                            MPFROMSHORT(x), MPFROMSHORT(TRUE));
     1080          }
     1081          save_commands();
     1082        }
     1083        free(temp->pszCmdLine);
     1084        free(temp);
     1085        break;
     1086      }
    9911087
    9921088    case CMD_DELETE:
     
    9991095        WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
    10001096        bstripcr(temp);
    1001         sprintf(keyID, "COMMAND.%sID", temp);
    1002         sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp);
    1003         sprintf(keyenv, "COMMAND.%senv", temp);
    1004         PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, NULL);
    1005         PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, NULL);
    1006         PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    10071097        if (!kill_command(temp))
    10081098          Runtime_Error(pszSrcFile, __LINE__, "kill_command");
    1009         else {
     1099        else {
     1100          sprintf(keyID, "COMMAND.%sID", temp);
     1101          sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp);
     1102          sprintf(keyenv, "COMMAND.%senv", temp);
     1103          PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
     1104          PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
     1105          PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    10101106          x = (SHORT) WinSendDlgItemMsg(hwnd,
    10111107                                        CMD_LISTBOX,
     
    10191115                              CMD_LISTBOX,
    10201116                              LM_SELECTITEM,
    1021                               MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
     1117                              MPFROMSHORT(0), MPFROMSHORT(TRUE));
    10221118          }
    10231119          save_commands();
     
    10271123
    10281124    case CMD_REPLACE:
    1029       { //Delete first
    1030         PSZ pszWorkBuf;
    1031         COMMAND temp;
    1032         APIRET ret;
     1125      {
     1126        COMMAND *temp;
    10331127        CHAR keyID[120];
    10341128        CHAR keyHotKeyID[120];
    10351129        CHAR keyenv[120];
    1036         CHAR env[1002];
    10371130        INT ID = 0;
    10381131        INT HotKeyID = 0;
    10391132        ULONG size;
    1040 
    1041         pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
    1042         if (!pszWorkBuf) {
     1133        BOOL fDontCheckHotKey = FALSE;
     1134
     1135        // Query the dialog
     1136        temp = xmallocz(sizeof(COMMAND), pszSrcFile, __LINE__);
     1137        if (!temp)
     1138          break;  //already complained
     1139        temp->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     1140        if (!temp->pszCmdLine) {
     1141          free (temp);
    10431142          break; //already complained
    10441143        }
    1045         memset(&temp, 0, sizeof(COMMAND));
    1046         temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
    1047         if (!temp.pszCmdLine) {
    1048           free(pszWorkBuf);
    1049           break; //already complained
    1050         }
    1051         WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
    1052         NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
    1053         memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    1054         free(pszWorkBuf);
    1055         if (fCancelAction){
    1056           fCancelAction = FALSE;
    1057           free(temp.pszCmdLine);
     1144        if (!QueryCommandSettings(hwnd, temp)) {
     1145          free(temp->pszCmdLine);
     1146          free(temp);
    10581147          break;
    1059         }
    1060         if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
    1061           ret = saymsg(MB_YESNO,
    1062                        HWND_DESKTOP,
    1063                        NullStr,
    1064                        GetPString(IDS_TOACTONSELECTEDTEXT));
    1065           if (ret == MBID_YES)
    1066             strcat(temp.pszCmdLine, " %a");
    10671148        }
    10681149        //remember item location in the list
     
    10711152                                      LM_QUERYSELECTION,
    10721153                                      MPFROMSHORT(LIT_CURSOR), MPVOID);
    1073         WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    1074         bstripcr(temp.title);
    1075         sprintf(keyID, "COMMAND.%sID", temp.title);
    1076         sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp.title);
    1077         sprintf(keyenv, "COMMAND.%senv", temp.title);
     1154        //Delete
     1155        sprintf(keyID, "COMMAND.%sID", temp->title);
     1156        sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp->title);
     1157        sprintf(keyenv, "COMMAND.%senv", temp->title);
    10781158        PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
    10791159        PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
    1080         PrfQueryProfileString(fmprof, FM3Str, keyenv, NullStr, env, sizeof(env));
    1081         temp.ID = ID;
    1082         temp.HotKeyID = HotKeyID;
    1083         if (env != NullStr)
    1084           strcpy(temp.env, env);
    1085         PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, NULL);
    1086         PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, NULL);
    1087         PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    1088         if (kill_command(temp.title)){
     1160        temp->ID = ID;
     1161        if (temp->HotKeyID == HotKeyID || temp->HotKeyID == 0)
     1162          fDontCheckHotKey = TRUE;
     1163        if (kill_command(temp->title)) {
     1164          PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, 0);
     1165          PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, 0);
     1166          PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    10891167          x = (SHORT) WinSendDlgItemMsg(hwnd,
    10901168                                        CMD_LISTBOX,
     
    11011179          }
    11021180        } // then do an add
    1103         temp.flags = CheckExecutibleFlags(hwnd, 3);
    1104         /*if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
    1105           temp.flags = 0;
    1106         else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
    1107           temp.flags = FULLSCREEN;
    1108         else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
    1109           temp.flags = MINIMIZED;
    1110         else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
    1111           temp.flags = MAXIMIZED;
    1112         else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
    1113           temp.flags = INVISIBLE;
    1114         if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
    1115           temp.flags |= KEEP;
    1116         if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
    1117           temp.flags |= PROMPT;
    1118         if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    1119           temp.flags |= ONCE;*/
    1120         *env = 0;
    1121         WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    1122         bstripcr(env);
    1123         if (*env)
    1124           strcpy(temp.env, env);
    1125         if (!*env && temp.env != NullStr)
    1126           strcpy(temp.env, NullStr);
    1127         info = add_command(&temp);
     1181        info = add_command(temp, fDontCheckHotKey);
    11281182        if (!info) {
    11291183          saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
    11301184                 GetPString(IDS_CANTADDCOMMANDTEXT),
    1131                  temp.title);
    1132           }
    1133 
     1185                 temp->title);
     1186        }
    11341187        else {
    11351188          //put item back in original place
     
    11381191                                        LM_INSERTITEM,
    11391192                                        MPFROM2SHORT(y, 0),
    1140                                         MPFROMP(temp.title));
     1193                                        MPFROMP(temp->title));
    11411194          if (x >= 0) {
    11421195            LINKCMDS *temphead = NULL,*last = NULL, *temptail = NULL;
     
    11791232            }
    11801233            cmdhead = temphead;
    1181             cmdtail = temptail;
     1234            cmdtail = temptail;
    11821235            save_commands();
    11831236          }
    11841237        }
    1185         free(temp.pszCmdLine);
     1238        xfree(temp->pszCmdLine, pszSrcFile, __LINE__);
     1239        xfree(temp, pszSrcFile, __LINE__);
    11861240      }
    11871241      break;
     
    11891243    return 0;
    11901244  }
     1245#   ifdef FORTIFY
     1246    Fortify_LeaveScope();
     1247#    endif
    11911248  return WinDefDlgProc(hwnd, msg, mp1, mp2);
    11921249}
  • trunk/dll/fm3dlg.h

    r1483 r1491  
    3636  13 Dec 09 GKY Updated Quick page "Default" to match current defaults; added Gregg's way
    3737                option to Quick page.
     38  27 Dec 09 GKY Made command hotkeys user selectable.
    3839
    3940***********************************************************************/
     
    516517#define PICKBTN_LISTBOX                                                                 22901
    517518
    518 #define CMD_FRAME                                                                                       23000
    519 #define CMD_LISTBOX                                                                             23001
    520 #define CMD_CL                                                                                          23002
    521 #define CMD_ADD                                                                                 23003
    522 #define CMD_DELETE                                                                              23004
    523 #define CMD_KEEP                                                                                        23005
     519#define CMD_FRAME                                                                       23000
     520#define CMD_LISTBOX                                                                     23001
     521#define CMD_CL                                                                          23002
     522#define CMD_ADD                                                                         23003
     523#define CMD_DELETE                                                                      23004
     524#define CMD_KEEP                                                                        23005
    524525#define CMD_FULLSCREEN                                                                  23006
    525526#define CMD_MINIMIZED                                                                   23007
    526527#define CMD_MAXIMIZED                                                                   23008
    527528#define CMD_INVISIBLE                                                                   23009
    528 #define CMD_ICON                                                                                        23010
    529 #define CMD_DEFAULT                                                                             23011
    530 #define CMD_PROMPT                                                                              23012
    531 #define CMD_ONCE                                                                                        23013
    532 #define CMD_TITLE                                                                                       23014
    533 #define CMD_REORDER                                                                             23015
    534 #define CMD_FIND                                                                                        23016
    535 #define CMD_ENVIRON                                                                             23017
     529#define CMD_ICON                                                                        23010
     530#define CMD_DEFAULT                                                                     23011
     531#define CMD_PROMPT                                                                      23012
     532#define CMD_ONCE                                                                        23013
     533#define CMD_TITLE                                                                       23014
     534#define CMD_REORDER                                                                     23015
     535#define CMD_FIND                                                                        23016
     536#define CMD_ENVIRON                                                                     23017
     537#define CMD_HOTKEY                                                                      23018
    536538
    537539#define KILL_FRAME                                                                              23100
  • trunk/dll/fm3res.dlg

    r1483 r1491  
    4949  13 Dec 09 GKY Updated Quick page "Default" to match current defaults; added Gregg's way
    5050                option to Quick page.
     51  27 Dec 09 GKY Made command hotkeys user selectable.
    5152
    5253***********************************************************************/
     
    875876            FCF_TITLEBAR
    876877    BEGIN
    877         CTEXT           "Environment:", -1, 56, 57, 114, 8, DT_VCENTER | NOT
    878                         WS_GROUP
     878        CTEXT           "Environment:", -1, 0, 54, 49, 10,  NOT WS_GROUP
     879        CTEXT           "Hotkey:", -1, 120, 62, 40, 10,  NOT WS_GROUP               
    879880        LTEXT           "Command line:", -1, 4, 116, 82, 8, NOT WS_GROUP
    880881        LTEXT           "Title:", -1, 4, 96, 24, 8, NOT WS_GROUP
     
    890891                        BS_NOPOINTERFOCUS
    891892        ENTRYFIELD      "", CMD_TITLE, 4, 86, 248, 8, ES_MARGIN | WS_GROUP
    892         AUTORADIOBUTTON "~Default", CMD_DEFAULT, 2, 74, 49, 10,
     893        AUTORADIOBUTTON "~Default", CMD_DEFAULT, 2, 74, 39, 10,
    893894                        BS_NOPOINTERFOCUS | WS_GROUP | WS_TABSTOP
    894         AUTORADIOBUTTON "F~ullScreen", CMD_FULLSCREEN, 59, 74, 62, 10,
    895                         BS_NOPOINTERFOCUS | WS_TABSTOP
    896         AUTORADIOBUTTON "Mi~nimized", CMD_MINIMIZED, 127, 74, 60, 10,
    897                         BS_NOPOINTERFOCUS | WS_TABSTOP
    898         AUTORADIOBUTTON "Ma~ximized", CMD_MAXIMIZED, 127, 64, 60, 10,
    899                         BS_NOPOINTERFOCUS | WS_TABSTOP
    900         AUTORADIOBUTTON "In~visible", CMD_INVISIBLE, 59, 64, 62, 10,
     895        AUTORADIOBUTTON "F~ullScreen", CMD_FULLSCREEN, 45, 74, 45, 10,
     896                        BS_NOPOINTERFOCUS | WS_TABSTOP
     897        AUTORADIOBUTTON "Mi~nimized", CMD_MINIMIZED, 145, 74, 45, 10,
     898                        BS_NOPOINTERFOCUS | WS_TABSTOP
     899        AUTORADIOBUTTON "Ma~ximized", CMD_MAXIMIZED, 95, 74, 45, 10,
     900                        BS_NOPOINTERFOCUS | WS_TABSTOP
     901        AUTORADIOBUTTON "In~visible", CMD_INVISIBLE, 195, 74, 42, 10,
    901902                        BS_NOPOINTERFOCUS | WS_TABSTOP
    902903        AUTOCHECKBOX    "~Prompt", CMD_PROMPT, 2, 64, 49, 10,
    903904                        BS_NOPOINTERFOCUS | WS_GROUP
    904         AUTOCHECKBOX    "~Each", CMD_ONCE, 194, 74, 37, 10,
     905        AUTOCHECKBOX    "~Each", CMD_ONCE, 95, 64, 27, 10,
    905906                        BS_NOPOINTERFOCUS | WS_GROUP
    906         AUTOCHECKBOX    "~Keep", CMD_KEEP, 194, 64, 37, 10,
     907        AUTOCHECKBOX    "~Keep", CMD_KEEP, 45, 64, 27, 10,
    907908                        BS_NOPOINTERFOCUS | WS_GROUP
    908909        CONTROL         "", CMD_ENVIRON, 4, 18, 247, 38, WC_MLE, MLS_HSCROLL |
    909910                        MLS_VSCROLL | MLS_IGNORETAB | WS_GROUP | WS_TABSTOP |
    910911                        WS_VISIBLE
     912        CONTROL         "", CMD_HOTKEY,160,12, 70, 60, WC_COMBOBOX,
     913                        CBS_DROPDOWNLIST | WS_TABSTOP |
     914                        WS_VISIBLE               
    911915        DEFPUSHBUTTON   "~Okay", DID_OK, 2, 2, 34, 14, BS_NOPOINTERFOCUS |
    912916                        WS_GROUP
  • trunk/dll/fm3res.rc

    r1490 r1491  
    5353  26 Dec 09 GKY Fixed some missing or duplicate mnemonics on the "Save Lists to clipboard/file"
    5454                submenu.
     55  27 Dec 09 GKY Strings for command.c changes
    5556
    5657***********************************************************************/
     
    24672468    IDS_NOTPROTECTONLYEXE                 "The file %s is a Dos or Windows executible, however Dos and WinOS2 are not currently activated on this system."
    24682469    IDS_INIFAILURETEXT                    "Check INI header failed will attempt to replace with backup if backup fails or not found will open with new ini"
     2470    IDS_DUPLICATEHOTKEYTEXT               "The hotkey you selected is in use by another command.\n Yes assigns it to this command and sets the other's to None.\n No sets this command to the next unused hotkey.\n Cancel returns you to the dialog to select a different HotKey."
    24692471    IDS_HELPCMDTEXT                       "/HELP"
    24702472    IDS_ZEROBYTETEXT                      "Zero byte file do you wish to open it in an editor (No cancels)"
     
    33153317    IDS_TOTARGETTEXT                      " (Target directory)"
    33163318    IDS_CANTADDCOMMANDTEXT                "Can't add %s to command list"
    3317     IDS_CANTADDCOMMANDTEXTDUP             "Can't add %s to command list It has a duplicate title"
     3319    IDS_CANTADDCOMMANDTEXTDUP             "Can't add %s to command list It has a duplicate title and/or hotkey"
    33183320    IDS_CREATESEMFAILED                   "Create Semaphore failed"
    33193321    IDS_POSTSEMFAILED                     "Post Semaphore failed"
  • trunk/dll/fm3str.h

    r1488 r1491  
    4040  21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
    4141                Added load_inicommand to load the IDs from the ini file.(new error strings)
     42  27 Dec 09 GKY Added IDS_DUPLICATEHOTKEYTEXT for command.c changes
    4243
    4344***********************************************************************/
     
    100101#define IDS_NOTPROTECTONLYEXE                                 50
    101102#define IDS_INIFAILURETEXT                                    51
     103#define IDS_DUPLICATEHOTKEYTEXT                               52
    102104#define IDS_HELPCMDTEXT                                       56
    103105#define IDS_ZEROBYTETEXT                                      58
     
    995997#define IDS_CANTFINDDRIVETEXT                                 995
    996998#define IDS_CANTDRAGROOTDIR                                   996
    997 #define IDS_DOSQAPPTYPEFAILEDTEXT                             997
     999//#define IDS_DOSQAPPTYPEFAILEDTEXT   moved to 1017           997
    9981000#define IDS_APPTYPEUNEXPECTEDTEXT                             998
    9991001#define IDS_PATHTODESKTOP                                     999
     
    10151017#define IDS_RESCANALLDRIVESTEXT                              1015
    10161018#define IDS_REFRESHREMOVABLESTEXT                            1016
     1019#define IDS_DOSQAPPTYPEFAILEDTEXT                            1017
     1020#define IDS_DOSQAPPTYPEFAILEDTEXT2                           1018
     1021#define IDS_DOSQAPPTYPEFAILEDTEXT3                           1019
    10171022
    10181023//The following strings were cut up form the string of the root name (ie IDS_SUGGEST1TEXT)
  • trunk/dll/mainwnd.c

    r1486 r1491  
    16121612                                 (!tool->text && tool->id >= IDM_COMMANDSTART
    16131613                                  && tool->id <
    1614                                   IDM_QUICKTOOLSTART) ? command_title(tool->
    1615                                                                       id -
     1614                                  IDM_QUICKTOOLSTART) ? command_title(tool->id -
    16161615                                                                      IDM_COMMANDSTART)
    16171616                                 : tool->text,
Note: See TracChangeset for help on using the changeset viewer.