Changeset 1486 for trunk/dll/command.c


Ignore:
Timestamp:
Dec 17, 2009, 1:36:04 AM (16 years ago)
Author:
Gregg Young
Message:

Initial changes to commands handling. Allows you to reorder commands menu without breaking toolbars and changing hotkeys. Fixes the environment so it is used and so it is deleted if the command is deleted. Allows for user defined bitmaps in toolbars which are named based on the text or the the ID of the command.The new commands.dat will not be usable with earlier versions of FM/2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/command.c

    r1398 r1486  
    6565{
    6666  PSZ pszCmdLine;
    67   INT flags;
    6867  CHAR title[100];
     68  ULONG flags;
     69  ULONG ID;
     70  ULONG HotKeyID;
    6971}
    7072COMMAND;
     
    7577static PSZ pszSrcFile = __FILE__;
    7678static LINKCMDS *cmdtail;
     79static INT CommandDatVersion = 0;
    7780
    7881#pragma data_seg(GLOBAL2)
    7982LINKCMDS *cmdhead;
    8083BOOL cmdloaded;
     84BOOL UsedCommandIDs[300];
     85BOOL UsedHotKeyIDs[20];
    8186
    8287MRESULT EXPENTRY CommandTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     
    344349  LINKCMDS *info;
    345350  PSZ pszCmdLine;
     351  CHAR *p;
    346352  CHAR title[100];
    347353  CHAR flags[34];
     354  CHAR ID[34];
     355  CHAR HotKeyID[34];
    348356
    349357  if (cmdhead)
     
    355363    fp = _fsopen(pszCmdLine, "r", SH_DENYWR);
    356364    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      }
    357374      while (!feof(fp)) {
    358375        if (!xfgets_bstripcr(title, sizeof(title), fp, pszSrcFile, __LINE__))
     
    365382        if (!xfgets_bstripcr(flags, sizeof(flags), fp, pszSrcFile, __LINE__))
    366383          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        }
    367392        pszCmdLine[strlen(pszCmdLine)] = 0;                     // fixme to know why chopped this way?
    368393        //bstripcr(pszCmdLine);
     
    380405          info->title = xstrdup(title, pszSrcFile, __LINE__);
    381406          info->flags = atol(flags);
     407          if (CommandDatVersion) {
     408            info->ID = atol(ID);
     409            info->HotKeyID = atol(HotKeyID);
     410          }
    382411          if (!info->pszCmdLine || !info->title) {
    383412            xfree(info->pszCmdLine, pszSrcFile, __LINE__);
     
    412441  FILE *fp;
    413442  CHAR s[CCHMAXPATH + 14];
     443  INT x = 0;
    414444
    415445  if (!cmdloaded || !cmdhead)
     
    421451  fp = xfopen(s, "w", pszSrcFile, __LINE__);
    422452  if (fp) {
     453    //Adds line for version tracking
     454    fprintf(fp,"Version 2\n");
    423455    fputs(GetPString(IDS_COMMANDFILETEXT), fp);
    424456    info = cmdhead;
    425457    while (info) {
    426       fprintf(fp,
    427               ";\n%0.99s\n%0.*s\n%lu\n",
    428               info->title, MaxComLineStrg, info->pszCmdLine, info->flags);
     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);
     475      x++;
    429476      info = info->next;
    430     }
     477    } // while
     478    PrfWriteProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     479                        sizeof(BOOL) * 300);
     480    PrfWriteProfileData(fmprof, FM3Str, "UsedHotKeyIDs", &UsedHotKeyIDs,
     481                        sizeof(BOOL) * 20);
    431482    fclose(fp);
    432   }
     483  } // if (fp)
    433484}
    434485
    435486//== add_command() Add command to list ==
    436487
    437 LINKCMDS *add_command(COMMAND * addme)
     488LINKCMDS *add_command(COMMAND *addme)
    438489{
    439490  LINKCMDS *info;
     491  ULONG size;
     492  INT x;
    440493
    441494  if (!addme || !*addme->pszCmdLine || !*addme->title)
     
    452505  info->pszCmdLine = xstrdup(addme->pszCmdLine, pszSrcFile, __LINE__);
    453506  info->title = xstrdup(addme->title, pszSrcFile, __LINE__);
     507  info->HotKeyID = addme->HotKeyID;
     508  if (!info->ID) {
     509    PrfQueryProfileData(fmprof, FM3Str, "UsedCommandIDs", &UsedCommandIDs,
     510                        &size); //profile updated by save_commands
     511    for (x = 0; x < 300; x++) {
     512      if (!UsedCommandIDs[x]) {
     513        info->ID = IDM_COMMANDSTART + x;
     514        break;
     515      }
     516    }
     517  }
    454518  if (addme->flags)
    455519    info->flags = addme->flags;
    456   if (!info->pszCmdLine || !info->title) {
     520  if (!info->pszCmdLine || !info->title || !info->ID) {
    457521    xfree(info->pszCmdLine, pszSrcFile, __LINE__);
    458522    xfree(info->title, pszSrcFile, __LINE__);
     
    479543    while (info) {
    480544      if (!stricmp(info->title, killme)) {
     545        UsedCommandIDs[info->ID - IDM_COMMANDSTART] = FALSE;
     546        if (info->HotKeyID)
     547          UsedHotKeyIDs[info->HotKeyID - IDM_COMMANDNUM0] = FALSE;
    481548        if (info == cmdhead) {
    482549          cmdhead = info->next;
     
    818885          bstripcr(env);
    819886          if (*env) {
    820             PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
     887            PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
    821888          }
    822889          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    846913
    847914        WinQueryDlgItemText(hwnd, CMD_TITLE, 100, temp);
    848         bstrip(temp);
     915        bstrip(temp);
     916        PrfWriteProfileString(fmprof, FM3Str, temp, NULL);
    849917        if (!kill_command(temp))
    850918          Runtime_Error(pszSrcFile, __LINE__, "kill_command");
     
    908976        WinQueryDlgItemText(hwnd, CMD_TITLE, sizeof(temp.title), temp.title);
    909977        bstrip(temp.title);
     978        PrfWriteProfileString(fmprof, FM3Str, temp.title, NULL);
    910979        if (kill_command(temp.title)){
    911980          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    9531022          bstripcr(env);
    9541023          if (*env) {
    955             PrfWriteProfileString(fmprof, FM3Str, temp.pszCmdLine, env);
     1024            PrfWriteProfileString(fmprof, FM3Str, temp.title, env);
    9561025          } //put item back in original place
    9571026          x = (SHORT) WinSendDlgItemMsg(hwnd,
     
    10191088  LINKCMDS *info;
    10201089
     1090  DbgMsg(pszSrcFile, __LINE__,"ID %i", cx);
    10211091  list = BuildList(hwnd);
    10221092  x = 0;
    10231093  info = cmdhead;
    10241094  while (info) {
    1025     x++;
    1026     if (x == cx)
    1027       break;
     1095    //x++;
     1096    if (cx < 4300) {
     1097      if (info->ID == cx)
     1098        break;
     1099    }
     1100    else {
     1101      if (info->HotKeyID == cx)
     1102        break;
     1103    }
    10281104    info = info->next;
    10291105  }
     
    10311107
    10321108    INT flags;
     1109    CHAR env[1002];
    10331110
    10341111    x--;
     
    10411118      flags |= SEPARATE;
    10421119    flags &= ~(KEEP | DIEAFTER);
     1120    PrfQueryProfileString(fmprof, FM3Str, info->title, NullStr, env, sizeof(env));
    10431121    if (!strchr(info->pszCmdLine, '%')) {
    10441122      CHAR *fakelist[2];
     
    10481126      ExecOnList(hwnd,
    10491127                 info->pszCmdLine,
    1050                  flags, NULL, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
     1128                 flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
    10511129                 pszSrcFile, __LINE__);
    10521130    }
     
    10621140        ExecOnList(hwnd,
    10631141                   info->pszCmdLine,
    1064                    flags, NULL, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
     1142                   flags, env, fakelist, GetPString(IDS_EXECCMDTITLETEXT),
    10651143                   pszSrcFile, __LINE__);
    10661144      }
     
    10691147      ExecOnList(hwnd,
    10701148                 info->pszCmdLine,
    1071                  flags, NULL, list, GetPString(IDS_EXECCMDTITLETEXT),
     1149                 flags, env, list, GetPString(IDS_EXECCMDTITLETEXT),
    10721150                 pszSrcFile, __LINE__);
    10731151    else
Note: See TracChangeset for help on using the changeset viewer.