Changeset 1488 for trunk/dll/command.c


Ignore:
Timestamp:
Dec 22, 2009, 12:42:55 AM (16 years ago)
Author:
Gregg Young
Message:

Fixed commands so reordering them in commands.dat no longer changes their ID or hot key assignment; added 20 new hot keys; the environment information is now used when executing a command; some code clean up in command.c; added CheckExecutibleFlags to systemf.c the eliminate repetative code in assoc.c, command.c & cmdline.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/command.c

    r1487 r1488  
    2828  24 Aug 08 GKY Warn full drive on save of .DAT file; prevent loss of existing file
    2929  15 Oct 08 GKY Prevent asking to add %a on NormalizeCmdLine abort
     30  21 Dec 09 GKY Fix the environment so it can be saved, deleted and used consistently.
     31  21 Dec 09 GKY Allow command menu reorder without changing the "ID" or hot key for a command.
     32                Added load_inicommand to load the IDs from the ini file.
     33  21 Dec 09 GKY Added 20 new hot keys for commands.
     34  21 Dec 09 GKY Added CheckExecutibleFlags to streamline code in command.c assoc.c & cmdline.c
    3035
    3136***********************************************************************/
     
    6267#include "fortify.h"
    6368
     69VOID load_inicommands(VOID);
     70
    6471typedef struct
    6572{
    6673  PSZ pszCmdLine;
    6774  CHAR title[100];
     75  CHAR env[1002];
    6876  ULONG flags;
    6977  ULONG ID;
     
    7785static PSZ pszSrcFile = __FILE__;
    7886static LINKCMDS *cmdtail;
    79 static INT CommandDatVersion = 0;
     87static BOOL UsedCommandIDs[300];
     88static BOOL UsedHotKeyIDs[40];
    8089
    8190#pragma data_seg(GLOBAL2)
    8291LINKCMDS *cmdhead;
    8392BOOL cmdloaded;
    84 BOOL UsedCommandIDs[300];
    85 BOOL UsedHotKeyIDs[20];
    8693
    8794MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     
    338345    xfree(info->title, pszSrcFile, __LINE__);
    339346    xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     347    xfree(info->env, pszSrcFile, __LINE__);
    340348    free(info);
    341349    info = next;
     
    349357  LINKCMDS *info;
    350358  PSZ pszCmdLine;
    351   CHAR *p;
    352359  CHAR title[100];
    353360  CHAR flags[34];
    354   CHAR ID[34];
    355   CHAR HotKeyID[34];
     361  ULONG size;
    356362
    357363  if (cmdhead)
    358364    free_commands();
     365  PrfQueryProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     366                      &size);
     367  PrfQueryProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
     368                        &size);
    359369  cmdloaded = TRUE;
    360370  pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
     
    363373    fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
    364374    if (fp) {
    365       xfgets(title, sizeof(title), fp, pszSrcFile, __LINE__);
    366       lstrip(title);
    367       if (!strnicmp(title, "Version", 7) && !CommandDatVersion) {
    368         p = title + 7;
    369         while (*p == ' ')
    370           p++;
    371         bstripcr(p);
    372         CommandDatVersion = atol(p);
    373       }
    374375      while (!feof(fp)) {
    375376        if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
    376377          break;
    377         title[strlen(title)] = 0;                       // Match size to entry file max
     378        //title[strlen(title)] = 0;  // Match size to entry file max? Not needed as bstripcr does this? GKY 21 Dec 09
    378379        if (!*title || *title == ';')
    379380          continue;
     
    381382          break;                                /* error! */
    382383        if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
    383           break;                                /* error! */
    384         if (CommandDatVersion) {
    385           if (!xfgets_bstripcr(ID, sizeof(ID), fp, pszSrcFile, __LINE__))
    386             break;                              /* error! */
    387           ID[34] = 0;
    388           if (!xfgets_bstripcr(HotKeyID, sizeof(HotKeyID), fp, pszSrcFile, __LINE__))
    389             break;                              /* error! */
    390           ID[34] = 0;
    391         }
    392         pszCmdLine[strlen(pszCmdLine)] = 0;                     // fixme to know why chopped this way?
    393         //bstripcr(pszCmdLine);
     384          break;
     385        //pszCmdLine[strlen(pszCmdLine)] = 0;      // fixme to know why chopped this way? Not needed as bstripcr does this? GKY 21 Dec 09
    394386        flags[34] = 0;
    395         //bstripcr(flags);
    396387        if (!pszCmdLine)
    397388          continue;
     
    405396          info->title = xstrdup(title, pszSrcFile, __LINE__);
    406397          info->flags = atol(flags);
    407           if (CommandDatVersion) {
    408             info->ID = atol(ID);
    409             info->HotKeyID = atol(HotKeyID);
    410           }
    411398          if (!info->pszCmdLine || !info->title) {
    412399            xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     
    432419      free(pszCmdLine);
    433420      fclose(fp);
    434     }
     421      load_inicommands();
     422    }
     423  }
     424}
     425
     426/**
     427 * load_inicommand loads the data from the ini file into an info struct
     428 * after COMMANDS.DAT has been loaded; It generates new IDs where necessary
     429 * it saves the environment from the old ini key and deletes it as needed
     430 **/
     431
     432VOID load_inicommands(VOID)
     433{
     434  LINKCMDS *info;;
     435  INT x = 0;
     436  INT y = 0;
     437  ULONG ID = 0;
     438  ULONG HotKeyID = 0;
     439  CHAR env[1002];
     440  CHAR keyID[120];
     441  CHAR keyHotKeyID[120];
     442  CHAR keyenv[120];
     443  ULONG size;
     444
     445  if (!cmdloaded || !cmdhead)
     446    return;
     447  info = cmdhead;
     448  while (info) {
     449    bstripcr(info->title);
     450    sprintf(keyID, "COMMAND.%sID", info->title);
     451    sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", info->title);
     452    sprintf(keyenv, "COMMAND.%senv", info->title);
     453    size = sizeof(ULONG);
     454    PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
     455    size = sizeof(ULONG);
     456    PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
     457    PrfQueryProfileString(fmprof, FM3Str, keyenv, NullStr, env, sizeof(env));
     458    if (ID) {
     459      if (env != NullStr)
     460        info->env = xstrdup(env, pszSrcFile, __LINE__);
     461      info->ID = ID;
     462      info->HotKeyID = HotKeyID;
     463    }
     464    //This updates the old commands.dat file to the new format
     465    //assigning the IDs based on file order or on next available ID if
     466    //COMMAND.DAT is hand edited.
     467    else {
     468      for (x = 0; x < 300; x++) {
     469        if (!UsedCommandIDs[x]) {
     470          ID = info->ID = IDM_COMMANDSTART + x;
     471          UsedCommandIDs[x] = TRUE;
     472          for (y = 0; y < 40; y++) {
     473            if (!UsedHotKeyIDs[y]) {
     474              HotKeyID = info->HotKeyID = IDM_COMMANDNUM0 + y;
     475              UsedHotKeyIDs[y] = TRUE;
     476              break;
     477            }
     478          }
     479          break;
     480        }
     481        if (x == 299)
     482          saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
     483                 GetPString(IDS_COMMANDSLIMITTITLETEXT),
     484                 GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
     485      }
     486      PrfQueryProfileString(fmprof, FM3Str, info->pszCmdLine, NullStr, env, sizeof(env));
     487      info->env = env;
     488      if (env != NullStr)
     489        PrfWriteProfileString(fmprof, FM3Str, info->pszCmdLine, NULL);
     490      if (info->env)
     491        strcpy(env, info->env);
     492      ID = info->ID;
     493      HotKeyID = info->HotKeyID;
     494      PrfWriteProfileData(fmprof, FM3Str, keyID, &ID, sizeof(INT));
     495      PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, sizeof(INT));
     496      if (env != NullStr)
     497        PrfWriteProfileString(fmprof, FM3Str, keyenv, env);
     498      PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     499                      sizeof(BOOL) * 300);
     500      PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
     501                        sizeof(BOOL) * 40);
     502    }
     503    ID = 0;
     504    HotKeyID = 0;
     505    info = info->next;
    435506  }
    436507}
     
    442513  CHAR s[CCHMAXPATH + 14];
    443514  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];
    444521
    445522  if (!cmdloaded || !cmdhead)
     
    451528  fp = xfopen(s, "w", pszSrcFile, __LINE__);
    452529  if (fp) {
    453     //Adds line for version tracking
    454     fprintf(fp,"Version 2\n");
    455     fputs(GetPString(IDS_COMMANDFILETEXT), fp);
    456     info = cmdhead;
    457530    while (info) {
    458       //This updates the old commands.dat file to the new format
    459       //assigning the IDs based on file order
    460       if (!info->ID) {
    461         info->ID = IDM_COMMANDSTART + x;
    462         UsedCommandIDs[x] = TRUE;
    463         if (x < 20) {
    464           info->HotKeyID = IDM_COMMANDNUM0 + x;
    465           UsedHotKeyIDs[x] = TRUE;
    466         }
    467       }
    468         fprintf(fp, ";\n%0.99s\n%0.*s\n%lu\n%lu\n%lu\n",
    469                 info->title, MaxComLineStrg, info->pszCmdLine,
    470                 info->flags, info->ID, info->HotKeyID);
    471       //else
    472       //  fprintf(fp,
    473       //          ";\n%0.99s\n%0.*s\n%lu\n",
    474       //          info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
     531      fprintf(fp, ";\n%0.99s\n%0.*s\n%lu\n",
     532              info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
     533     
     534      if (info->env)
     535        strcpy(env, info->env);
     536      ID = info->ID;
     537      HotKeyID = info->HotKeyID;
     538      bstripcr(info->title);
     539      sprintf(keyID, "COMMAND.%sID", info->title);
     540      sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", info->title);
     541      sprintf(keyenv, "COMMAND.%senv", info->title);
     542      PrfWriteProfileData(fmprof, FM3Str, keyID, &ID, sizeof(INT));
     543      PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, sizeof(INT));
     544      if (env != NullStr)
     545        PrfWriteProfileString(fmprof, FM3Str, keyenv, env);
    475546      x++;
    476547      info = info->next;
    477     } // while
     548    } // while info
    478549    PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
    479550                        sizeof(BOOL) * 300);
    480551    PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
    481                         sizeof(BOOL) * 20);
     552                        sizeof(BOOL) * 40);
    482553    fclose(fp);
    483554  } // if (fp)
     
    489560{
    490561  LINKCMDS *info;
    491   ULONG size;
    492562  INT x;
     563  INT y;
    493564
    494565  if (!addme || !*addme->pszCmdLine || !*addme->title)
     
    498569    if (!stricmp(info->title, addme->title))
    499570      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
    500573    info = info->next;
    501574  }
     
    506579  info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
    507580  info->HotKeyID = addme->HotKeyID;
     581  if (info->HotKeyID >= IDM_COMMANDNUM0 && info->HotKeyID <= IDM_COMMANDNUM19)
     582    UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = TRUE;
     583  else
     584    info->HotKeyID = 0;
    508585  if (!info->ID) {
    509     PrfQueryProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
    510                         &size); //profile updated by save_commands
     586    //profile updated by save_commands
    511587    for (x = 0; x < 300; x++) {
    512588      if (!UsedCommandIDs[x]) {
    513589        info->ID = IDM_COMMANDSTART + x;
    514590        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;
     596            }
     597          }
    515598        break;
    516599      }
     600      if (x == 299)
     601        saymsg(MB_OK | MB_ICONEXCLAMATION , HWND_DESKTOP,
     602               GetPString(IDS_COMMANDSLIMITTITLETEXT),
     603               GetPString(IDS_COMMANDSLIMITREACHEDTEXT ));
    517604    }
    518605  }
    519606  if (addme->flags)
    520607    info->flags = addme->flags;
     608  if (addme->env)
     609    info->env = xstrdup(addme->env, pszSrcFile, __LINE__);
    521610  if (!info->pszCmdLine || !info->title || !info->ID) {
    522611    xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     612    xfree(info->title, pszSrcFile, __LINE__);
    523613    xfree(info->title, pszSrcFile, __LINE__);
    524614    free(info);
     
    561651        }
    562652        xfree(info->pszCmdLine, pszSrcFile, __LINE__);
    563         xfree(info->title, pszSrcFile, __LINE__);
     653        xfree(info->title, pszSrcFile, __LINE__);
     654        xfree(info->env, pszSrcFile, __LINE__);
    564655        free(info);
    565656        return TRUE;
     
    642733          WinCheckButton(hwnd, CMD_KEEP, ((info->flags & KEEP) != 0));
    643734          WinCheckButton(hwnd, CMD_ONCE, ((info->flags & ONCE) != 0));
    644           WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
    645           {
    646             CHAR env[1002];
    647             ULONG size;
    648 
    649             *env = 0;
    650             size = sizeof(env) - 1;
    651             if (PrfQueryProfileData(fmprof, FM3Str, info->pszCmdLine, env, &size) &&
    652                 *env)
    653               WinSetDlgItemText(hwnd, CMD_ENVIRON, env);
    654             else
    655               WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
    656           }
     735          WinSetDlgItemText(hwnd, CMD_TITLE, info->title);
     736          if (info->env)
     737            WinSetDlgItemText(hwnd, CMD_ENVIRON, info->env);
     738          else
     739            WinSetDlgItemText(hwnd, CMD_ENVIRON, NullStr);
    657740        }
    658741        break;
     
    724807        PSZ pszWorkBuf;
    725808        APIRET ret;
     809        CHAR env[1002];
    726810
    727811        memset(&temp, 0, sizeof(COMMAND));
     
    746830            strcat(temp.pszCmdLine, " %a");
    747831        }
    748         WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    749         if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
     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))
    750836          temp.flags = 0;
    751837        else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
     
    762848          temp.flags |= PROMPT;
    763849        if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    764           temp.flags |= 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          }
    765857        if (fCancelAction){
    766858          fCancelAction = FALSE;
     
    771863          info = add_command(&temp);
    772864        if (!info)
    773         {
    774           WinDismissDlg(hwnd, 0);
    775           /*saymsg(MB_ENTER, hwnd,
    776            GetPString(IDS_ERRORTEXT),
    777                  GetPString(IDS_CANTADDCOMMANDTEXT),
    778                  temp.title);*/
    779          }
     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        }
     883        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;
     894
     895    case DID_CANCEL:
     896      WinDismissDlg(hwnd, 0);
     897      break;
     898
     899    case IDM_HELP:
     900      if (hwndHelp)
     901        WinSendMsg(hwndHelp,
     902                   HM_DISPLAY_HELP,
     903                   MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
     904      break;
     905
     906    case CMD_ADD:
     907      {
     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)
     916          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);
     962          break;
     963        }
     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        }
    780970        else {
    781           CHAR env[1002];
    782 
    783           *env = 0;
    784           WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    785           bstripcr(env);
    786           if (*env) {
    787             PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
    788           }
    789971          x = (SHORT) WinSendDlgItemMsg(hwnd,
    790972                                        CMD_LISTBOX,
     
    806988        free(temp.pszCmdLine);
    807989      }
    808       x = (SHORT) WinSendDlgItemMsg(hwnd,
    809                                     CMD_LISTBOX,
    810                                     LM_QUERYSELECTION,
    811                                     MPFROMSHORT(LIT_FIRST), MPVOID);
    812       WinDismissDlg(hwnd, 0);
    813       break;
    814 
    815     case DID_CANCEL:
    816       WinDismissDlg(hwnd, 0);
    817       break;
    818 
    819     case IDM_HELP:
    820       if (hwndHelp)
    821         WinSendMsg(hwndHelp,
    822                    HM_DISPLAY_HELP,
    823                    MPFROM2SHORT(HELP_COMMAND, 0), MPFROMSHORT(HM_RESOURCEID));
    824       break;
    825 
    826     case CMD_ADD:
    827       {
    828         COMMAND temp;
    829         PSZ pszWorkBuf;
    830         APIRET ret;
    831 
    832         memset(&temp, 0, sizeof(COMMAND));
    833         temp.pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
    834         if (!temp.pszCmdLine)
    835           break; //already complained
    836         pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
    837         if (!pszWorkBuf) {
    838           free(temp.pszCmdLine);
    839           break; //already complained
    840         }
    841         WinQueryDlgItemText(hwnd, CMD_CL, MaxComLineStrg, temp.pszCmdLine);
    842         NormalizeCmdLine(pszWorkBuf, temp.pszCmdLine);
    843         memcpy(temp.pszCmdLine, pszWorkBuf, strlen(pszWorkBuf) + 1);
    844         free(pszWorkBuf);
    845         if (!strchr(temp.pszCmdLine, '%') && !fCancelAction){
    846           ret = saymsg(MB_YESNO,
    847                        HWND_DESKTOP,
    848                        NullStr,
    849                        GetPString(IDS_TOACTONSELECTEDTEXT));
    850           if (ret == MBID_YES)
    851             strcat(temp.pszCmdLine, " %a");
    852         }
    853         WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    854         if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
    855           temp.flags = 0;
    856         else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
    857           temp.flags = FULLSCREEN;
    858         else if (WinQueryButtonCheckstate(hwnd, CMD_MINIMIZED))
    859           temp.flags = MINIMIZED;
    860         else if (WinQueryButtonCheckstate(hwnd, CMD_MAXIMIZED))
    861           temp.flags = MAXIMIZED;
    862         else if (WinQueryButtonCheckstate(hwnd, CMD_INVISIBLE))
    863           temp.flags = INVISIBLE;
    864         if (WinQueryButtonCheckstate(hwnd, CMD_KEEP))
    865           temp.flags |= KEEP;
    866         if (WinQueryButtonCheckstate(hwnd, CMD_PROMPT))
    867           temp.flags |= PROMPT;
    868         if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    869           temp.flags |= ONCE;
    870         if (fCancelAction){
    871           fCancelAction = FALSE;
    872           free(temp.pszCmdLine);
    873           break;
    874         }
    875         else
    876           info = add_command(&temp);
    877         if (!info) {
    878           saymsg(MB_ENTER, hwnd, GetPString(IDS_ERRORTEXT),
    879                  GetPString(IDS_CANTADDCOMMANDTEXTDUP), temp.title);
    880         }
    881         else {
    882           CHAR env[1002];
    883 
    884           *env = 0;
    885           WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    886           bstripcr(env);
    887           if (*env) {
    888             PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
    889           }
    890           x = (SHORT) WinSendDlgItemMsg(hwnd,
    891                                         CMD_LISTBOX,
    892                                         LM_INSERTITEM,
    893                                         MPFROM2SHORT(LIT_END, 0),
    894                                         MPFROMP(temp.title));
    895           if (x >= 0) {
    896             WinSendDlgItemMsg(hwnd,
    897                               CMD_LISTBOX,
    898                               LM_SETITEMHANDLE,
    899                               MPFROMSHORT(x), MPFROMP(info));
    900             WinSendDlgItemMsg(hwnd,
    901                               CMD_LISTBOX,
    902                               LM_SELECTITEM,
    903                               MPFROMSHORT(x), MPFROMSHORT(TRUE));
    904             save_commands();
    905           }
    906         }
    907         free(temp.pszCmdLine);
    908       }
    909990      break;
    910991
    911992    case CMD_DELETE:
    912993      {
    913         CHAR temp[100];
     994        CHAR temp[100];
     995        CHAR keyID[120];
     996        CHAR keyHotKeyID[120];
     997        CHAR keyenv[120];
    914998
    915999        WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
    916         bstrip(temp);
    917         PrfWriteProfileString(fmprof, FM3Str, temp, NULL);
     1000        bstripcr(temp);
     1001        sprintf(keyID, "COMMAND.%sID", temp);
     1002        sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp);
     1003        sprintf(keyenv, "COMMAND.%senv", temp);
     1004        PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, NULL);
     1005        PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, NULL);
     1006        PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    9181007        if (!kill_command(temp))
    9191008          Runtime_Error(pszSrcFile, __LINE__, "kill_command");
     
    9321021                              MPFROMSHORT(LIT_NONE), MPFROMSHORT(FALSE));
    9331022          }
    934           save_commands();
     1023          save_commands();
    9351024        }
    9361025      }
     
    9421031        COMMAND temp;
    9431032        APIRET ret;
     1033        CHAR keyID[120];
     1034        CHAR keyHotKeyID[120];
     1035        CHAR keyenv[120];
     1036        CHAR env[1002];
     1037        INT ID = 0;
     1038        INT HotKeyID = 0;
     1039        ULONG size;
    9441040
    9451041        pszWorkBuf = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
     
    9761072                                      MPFROMSHORT(LIT_CURSOR), MPVOID);
    9771073        WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    978         bstrip(temp.title);
    979         PrfWriteProfileString(fmprof, FM3Str, temp.title, NULL);
     1074        bstripcr(temp.title);
     1075        sprintf(keyID, "COMMAND.%sID", temp.title);
     1076        sprintf(keyHotKeyID, "COMMAND.%sHotKeyID", temp.title);
     1077        sprintf(keyenv, "COMMAND.%senv", temp.title);
     1078        PrfQueryProfileData(fmprof, FM3Str, keyID, &ID, &size);
     1079        PrfQueryProfileData(fmprof, FM3Str, keyHotKeyID, &HotKeyID, &size);
     1080        PrfQueryProfileString(fmprof, FM3Str, keyenv, NullStr, env, sizeof(env));
     1081        temp.ID = ID;
     1082        temp.HotKeyID = HotKeyID;
     1083        if (env != NullStr)
     1084          strcpy(temp.env, env);
     1085        PrfWriteProfileData(fmprof, FM3Str, keyID, NULL, NULL);
     1086        PrfWriteProfileData(fmprof, FM3Str, keyHotKeyID, NULL, NULL);
     1087        PrfWriteProfileString(fmprof, FM3Str, keyenv, NULL);
    9801088        if (kill_command(temp.title)){
    9811089          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    9931101          }
    9941102        } // then do an add
    995         if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
     1103        temp.flags = CheckExecutibleFlags(hwnd, 3);
     1104        /*if (WinQueryButtonCheckstate(hwnd, CMD_DEFAULT))
    9961105          temp.flags = 0;
    9971106        else if (WinQueryButtonCheckstate(hwnd, CMD_FULLSCREEN))
     
    10081117          temp.flags |= PROMPT;
    10091118        if (WinQueryButtonCheckstate(hwnd, CMD_ONCE))
    1010           temp.flags |= 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);
    10111127        info = add_command(&temp);
    10121128        if (!info) {
     
    10171133
    10181134        else {
    1019           CHAR env[1002];
    1020 
    1021           *env = 0;
    1022           WinQueryDlgItemText(hwnd, CMD_ENVIRON, 1000, env);
    1023           bstripcr(env);
    1024           if (*env) {
    1025             PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
    1026           } //put item back in original place
     1135          //put item back in original place
    10271136          x = (SHORT) WinSendDlgItemMsg(hwnd,
    10281137                                        CMD_LISTBOX,
     
    10891198  LINKCMDS *info;
    10901199
    1091   DbgMsg(pszSrcFile, __LINE__,"ID %i", cx);
    10921200  list = BuildList(hwnd);
    10931201  x = 0;
    10941202  info = cmdhead;
    10951203  while (info) {
    1096     //x++;
    10971204    if (cx < 4300) {
    10981205      if (info->ID == cx)
     
    11081215
    11091216    INT flags;
    1110     CHAR env[1002];
    11111217
    11121218    x--;
     
    11191225      flags |= SEPARATE;
    11201226    flags &= ~(KEEP | DIEAFTER);
    1121     PrfQueryProfileString(fmprof, FM3Str, info->title, NullStr, env, sizeof(env));
    11221227    if (!strchr(info->pszCmdLine, '%')) {
    11231228      CHAR *fakelist[2];
     
    11271232      ExecOnList(hwnd,
    11281233                 info->pszCmdLine,
    1129                  flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
     1234                 flags, info->env != NullStr ? info->env : NULL,
     1235                 fakelist, GetPString(IDS_EXECCMDTITLETEXT),
    11301236                 pszSrcFile, __LINE__);
    11311237    }
     
    11411247        ExecOnList(hwnd,
    11421248                   info->pszCmdLine,
    1143                    flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
     1249                   flags, info->env != NullStr ? info->env : NULL,
     1250                   fakelist, GetPString(IDS_EXECCMDTITLETEXT),
    11441251                   pszSrcFile, __LINE__);
    11451252      }
     
    11481255      ExecOnList(hwnd,
    11491256                 info->pszCmdLine,
    1150                  flags, env, list, GetPString(IDS_EXECCMDTITLETEXT),
     1257                 flags, info->env != NullStr ? info->env : NULL,
     1258                 list, GetPString(IDS_EXECCMDTITLETEXT),
    11511259                 pszSrcFile, __LINE__);
    11521260    else
Note: See TracChangeset for help on using the changeset viewer.