Changeset 1486


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

Location:
trunk/dll
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/collect.c

    r1456 r1486  
    22932293          INT x;
    22942294
    2295           x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
     2295          x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
    22962296          if (x >= 0) {
    2297             x++;
     2297            //x++;
    22982298            RunCommand(hwnd, x);
    22992299            if (fUnHilite)
  • 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
  • trunk/dll/command.h

    r1205 r1486  
    3232  CHAR *title;
    3333  ULONG flags;
     34  ULONG ID;
     35  ULONG HotKeyID;
    3436  struct LINKCMDS *next;
    3537  struct LINKCMDS *prev;
  • trunk/dll/dircnrs.c

    r1482 r1486  
    27342734            if (!cmdloaded)
    27352735              load_commands();
    2736             x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
     2736            x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
    27372737            if (x >= 0) {
    2738               x++;
     2738              //x++;
    27392739              RunCommand(hwnd, x);
    27402740              if (fUnHilite)
  • trunk/dll/fm3dll2.h

    r1480 r1486  
    504504#define IDM_COMMANDSMENU    4000
    505505#define IDM_COMMANDSTART    4001
    506 #define IDM_COMMANDNUM0     4001
    507 #define IDM_COMMANDNUM1     4002
    508 #define IDM_COMMANDNUM2     4003
    509 #define IDM_COMMANDNUM3     4004
    510 #define IDM_COMMANDNUM4     4005
    511 #define IDM_COMMANDNUM5     4006
    512 #define IDM_COMMANDNUM6     4007
    513 #define IDM_COMMANDNUM7     4008
    514 #define IDM_COMMANDNUM8     4009
    515 #define IDM_COMMANDNUM9     4010
    516 #define IDM_COMMANDNUM10    4011
    517 #define IDM_COMMANDNUM11    4012
    518 #define IDM_COMMANDNUM12    4013
    519 #define IDM_COMMANDNUM13    4014
    520 #define IDM_COMMANDNUM14    4015
    521 #define IDM_COMMANDNUM15    4016
    522 #define IDM_COMMANDNUM16    4017
    523 #define IDM_COMMANDNUM17    4018
    524 #define IDM_COMMANDNUM18    4019
    525 #define IDM_COMMANDNUM19    4020
     506#define IDM_COMMANDNUM0     4301
     507#define IDM_COMMANDNUM1     4302
     508#define IDM_COMMANDNUM2     4303
     509#define IDM_COMMANDNUM3     4304
     510#define IDM_COMMANDNUM4     4305
     511#define IDM_COMMANDNUM5     4306
     512#define IDM_COMMANDNUM6     4307
     513#define IDM_COMMANDNUM7     4308
     514#define IDM_COMMANDNUM8     4309
     515#define IDM_COMMANDNUM9     4310
     516#define IDM_COMMANDNUM10    4311
     517#define IDM_COMMANDNUM11    4312
     518#define IDM_COMMANDNUM12    4313
     519#define IDM_COMMANDNUM13    4314
     520#define IDM_COMMANDNUM14    4315
     521#define IDM_COMMANDNUM15    4316
     522#define IDM_COMMANDNUM16    4317
     523#define IDM_COMMANDNUM17    4318
     524#define IDM_COMMANDNUM18    4319
     525#define IDM_COMMANDNUM19    4320
    526526
    527527#define IDM_QUICKTOOLSTART  4899
  • trunk/dll/ipf/fm3.ipf

    r1471 r1486  
    593593whitespace after the button (separates it from the next button).
    594594:p.
    595 If you check the :hp1. Don't user FM2 defined bmp:ehp1. checkbox, FM/2 will allow
     595If you check the :hp1.Don't use FM2 defined bmp:ehp1. checkbox, FM/2 will
    596596no longer load the button's bitmap. This will change the button to a text button.
    597 It will also allow you to use your own bitmap for this button Bitmaps are named
    598 after the :hp1.ID:ehp1. of the button -- for example, the bitmap file for ID 1005
    599 would be named "1005.bmp". Clicking the :hp1.Edit bmp:ehp1. button will cause ICONEDIT
    600 to be loaded with the bitmap, ready to edit. (Note that bitmaps should
    601 be 32 x 32.; if the bmp seems to big try resizing it to 28 x 28)
     597It will also allow you to use your own bitmap for this button Bitmaps can be  named
     598after the :hp1.ID:ehp1. or the :hp1.Text:ehp1. of the button -- for example,
     599the bitmap file for ID 1026 (MakeDir) could be named "1026.bmp" or "MakeDir.bmp".
     600Clicking the :hp1.Edit bmp:ehp1. button will cause ICONEDIT to be loaded with
     601the bitmap, ready to edit. (Note that bitmaps should be 32 x 32.; if the bmp
     602seems to big try resizing it to 28 x 28)
    602603:p.
    603604The :hp1.ID:ehp1. field identifies the command that is associated with
  • trunk/dll/loadbmp.c

    r1438 r1486  
    4040static HBITMAP LoadBitmapFromFile(CHAR * pszFileName);
    4141
    42 HBITMAP LoadBitmapFromFileNum(USHORT id)
     42HBITMAP LoadBitmapFromFileIdentifier(USHORT id, CHAR *text)
    4343{
    4444  char s[CCHMAXPATH];
     45  HBITMAP hBmp = (HBITMAP) 0;
    4546
    4647  strcpy(s, pFM2SaveDirectory);
    4748  sprintf(s + strlen(s), "%s%u.BMP", PCSZ_BACKSLASH, id);
    48   return LoadBitmapFromFile(s);
     49  hBmp = LoadBitmapFromFile(s);
     50  if (!hBmp) {
     51    strcpy(s, pFM2SaveDirectory);
     52    sprintf(s + strlen(s), "%s%s.BMP", PCSZ_BACKSLASH, text);
     53    hBmp = LoadBitmapFromFile(s);
     54  }
     55  return hBmp;
    4956}
    5057
     
    362369}
    363370
    364 #pragma alloc_text(LOADBITMAP,LoadBitmapFromFile,LoadBitmapFromFileNum)
     371#pragma alloc_text(LOADBITMAP,LoadBitmapFromFile,LoadBitmapFromFileIdentifier)
  • trunk/dll/loadbmp.h

    r1198 r1486  
    1616#define LOADBMP_H
    1717
    18 HBITMAP LoadBitmapFromFileNum(USHORT id);
     18HBITMAP LoadBitmapFromFileIdentifier(USHORT id, CHAR *text);
    1919
    2020
  • trunk/dll/mainwnd.c

    r1482 r1486  
    15821582      }
    15831583      if (!hwndTool) {
    1584         HBITMAP hbm = LoadBitmapFromFileNum(tool->id);
     1584        HBITMAP hbm = LoadBitmapFromFileIdentifier(tool->id, tool->text);
    15851585
    15861586        if (hbm) {
     
    53605360          break;
    53615361        }
    5362         x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
     5362        x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
    53635363        if (x >= 0) {
    5364           x++;
     5364          //x++;
    53655365          RunCommand(hwndCnr, x);
    53665366          if (fUnHilite) {
     
    60136013
    60146014  case UM_ADDTOMENU:
    6015     AddToMenu((CHAR *)mp1, WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
     6015    AddToMenu((
     6016               CHAR *)mp1, WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
    60166017                                            FID_MENU));
    60176018    return 0;
     
    63516352                                                 LM_QUERYSELECTION,
    63526353                                                 MPFROMSHORT(LIT_FIRST), MPVOID);
    6353               if (sSelect >= 0)
     6354              if (sSelect >= 0) {
     6355                CHAR s[CCHMAXPATH];
     6356                CHAR *p;
     6357
     6358                WinSendMsg(hwndCmdlist, LM_QUERYITEMTEXT,
     6359                           MPFROM2SHORT(sSelect, CCHMAXPATH), MPFROMP(s));
     6360                p = strrchr(s, '}');
     6361                p = 0;
     6362                p = strrchr(s, '{');
     6363                p++;
    63546364                WinPostMsg(hwnd,
    63556365                           WM_COMMAND,
    6356                            MPFROM2SHORT(IDM_COMMANDSTART + sSelect, 0),
    6357                            MPVOID);
    6358               WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
     6366                           MPFROM2SHORT(atol(p), 0), //IDM_COMMANDSTART + sSelect, 0),
     6367                           MPVOID);
     6368              }
     6369                WinSetWindowText(hwndCmdlist, GetPString(IDS_COMMANDSTEXT));
    63596370            }
    63606371          }
  • trunk/dll/mainwnd2.c

    r1482 r1486  
    719719        break;
    720720      }
    721       x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
     721      x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
    722722      if (x >= 0) {
    723         x++;
     723        //x++;
    724724        RunCommand(hwndCnr, x);
    725725        if (fUnHilite) {
  • trunk/dll/misc.c

    r1480 r1486  
    13201320                                  MPVOID, MPVOID);
    13211321    WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM, MPFROMSHORT(-1), MPVOID);
    1322     for (x = 0; x < numitems; x++)
     1322    //for (x = 0; x < numitems; x++)
     1323    info = cmdhead;
     1324    while (info) {
    13231325      WinSendMsg(mit.hwndSubMenu, MM_DELETEITEM,
    1324                  MPFROMSHORT((SHORT) (x + IDM_COMMANDSTART)), MPVOID);
     1326                 MPFROMSHORT((SHORT) (info->ID)), MPVOID);
     1327      info = info->next;
     1328    }
    13251329    if (hwndCnr && cmdhead) {
    13261330      x = 0;
     
    13311335
    13321336        sprintf(s,
    1333                 "%s%s%s",
    1334                 info->title,
    1335                 x < 20 ? "\tCtrl + " : NullStr,
    1336                 x < 20 && x > 9 ? "Shift + " : NullStr);
    1337         if (x < 20)
     1337                "%s {%i} %s%s",
     1338                info->title, info->ID,
     1339                info->HotKeyID ? "\tCtrl + " : NullStr,
     1340                info->HotKeyID && info->HotKeyID > 4310 ? "Shift + " : NullStr);
     1341        if (info->HotKeyID)
    13381342          sprintf(&s[strlen(s)], "%d",
    1339                   ((x % 10) + 1) == 10 ? 0 : (x % 10) + 1);
    1340         mi.id = IDM_COMMANDSTART + x;
     1343                  (((info->HotKeyID - 4301) % 10) + 1) == 10 ? 0 :
     1344                  ((info->HotKeyID - 4301) % 10) + 1);
     1345        mi.id = info->ID; //IDM_COMMANDSTART + x;
    13411346        mi.afAttribute = (info->flags & ONCE ? MIA_CHECKED : 0) |
    13421347                         (info->flags & PROMPT ? MIA_FRAMED : 0);
  • trunk/dll/tools.c

    r1435 r1486  
    669669      CHAR idstr[7];
    670670      USHORT id;
     671      CHAR text[CCHMAXPATH];
    671672
    672673      *idstr = 0;
    673674      WinQueryDlgItemText(hwnd, ADDBTN_ID, 6, idstr);
     675      WinQueryDlgItemText(hwnd, ADDBTN_TEXT,CCHMAXPATH - 1, text);
    674676      id = atoi(idstr);
    675677      if (id) {
     
    678680          hbm = GpiLoadBitmap(hps, 0, id, 28, 28);
    679681        if (!hbm)
    680           hbm = LoadBitmapFromFileNum(id);
     682          hbm = LoadBitmapFromFileIdentifier(id, text);
    681683        if (hbm) {
    682684          hbmd = (HBITMAP) WinSendDlgItemMsg(hwnd, ADDBTN_BMP, SM_QUERYHANDLE,
  • trunk/dll/treecnr.c

    r1480 r1486  
    30063006          if (!cmdloaded)
    30073007            load_commands();
    3008           x = SHORT1FROMMP(mp1) - IDM_COMMANDSTART;
     3008          x = SHORT1FROMMP(mp1);// - IDM_COMMANDSTART;
    30093009          if (x >= 0) {
    3010             x++;
     3010            //x++;
    30113011            RunCommand(hwnd, x);
    30123012            if (fUnHilite)
Note: See TracChangeset for help on using the changeset viewer.