Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

shellext: refactor CShellExtCMenu to use string tokens instead of enums

Changeset dd4619fe1cce

Parent 45a95cee4988

by Adrian Buehlmann

Changes to one file · Browse files at dd4619fe1cce Showing diff from parent 45a95cee4988 Diff from another changeset...

 
111
112
113
114
115
116
117
118
119
120
121
122
 
 
 
 
 
 
 
 
 
123
124
125
126
127
128
129
130
131
132
133
 
 
 
 
 
 
134
135
136
137
138
139
140
141
 
 
 
 
142
143
144
145
146
147
148
149
150
 
441
442
443
444
445
446
 
 
447
448
449
 
 
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
 
 
478
479
480
 
508
509
510
511
 
512
513
514
 
515
516
 
517
518
 
519
520
521
522
523
524
 
 
 
 
525
526
527
 
 
528
529
530
 
531
532
533
 
538
539
540
541
 
542
543
 
 
544
545
546
 
553
554
555
556
557
 
558
559
560
 
561
562
563
 
111
112
113
 
 
 
 
 
 
 
 
 
114
115
116
117
118
119
120
121
122
123
 
 
 
 
 
 
 
 
 
 
124
125
126
127
128
129
130
 
 
 
 
 
 
 
131
132
133
134
135
 
 
 
 
 
136
137
138
 
429
430
431
 
 
 
432
433
434
 
 
435
436
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
439
440
441
442
 
470
471
472
 
473
474
475
 
476
477
 
478
479
 
480
481
482
483
484
 
 
485
486
487
488
489
 
 
490
491
492
493
 
494
495
496
497
 
502
503
504
 
505
506
 
507
508
509
510
511
 
518
519
520
 
 
521
522
523
 
524
525
526
527
@@ -111,40 +111,28 @@
  {"", L"", L"", ".ico", 0},  };   -/* These enumerations must match the order of menuDescList */ -enum menuDescListEntries -{ - Commit, Init, Clone, Status, Shelve, Add, Revert, Remove, Rename, - Log, Synch, Serve, Update, Recover, Thgstatus, Userconf, Repoconf, - About, Datamine, VDiff, Ignore, Guess, Grep, Forget, Shellconf, - /* Add new items here */ - Separator, EndOfList -}; +const char* RepoNoFilesMenu = + "commit status shelve vidff sep" + " add revert rename forget remove sep" + " log update grep sep" + " synch serve clone init thgstatus sep" + " ignore guess recover sep" + " shellconf repoconf userconf sep" + " about" +;   -menuDescListEntries RepoNoFilesMenu[] = -{ - Commit, Status, Shelve, VDiff, Separator, - Add, Revert, Rename, Forget, Remove, Separator, - Log, Update, Grep, Separator, - Synch, Serve, Clone, Init, Thgstatus, Separator, - Ignore, Guess, Recover, Separator, - Shellconf, Repoconf, Userconf, Separator, - About, EndOfList -}; +const char* RepoFilesMenu = + "commit status vidff sep" + " add revert rename forget remove sep" + " log datamine sep" + " about" +;   -menuDescListEntries RepoFilesMenu[] = -{ - Commit, Status, VDiff, Separator, - Add, Revert, Rename, Forget, Remove, Separator, - Log, Datamine, Separator, - About, EndOfList -}; +const char* NoRepoMenu = + "clone init shellconf userconf thgstatus sep" + " about" +;   -menuDescListEntries NoRepoMenu[] = -{ - Clone, Init, Shellconf, Userconf, Thgstatus, Separator, - About, EndOfList -};    typedef std::map<std::string, MenuDescription> MenuDescriptionMap;  typedef std::map<UINT, MenuDescription> MenuIdCmdMap; @@ -441,40 +429,14 @@
    InitMenuMaps();   - const std::size_t sz = sizeof(menuDescList) / sizeof(MenuDescription); - bool promoted[sz]; - memset(&promoted, 0, sizeof(promoted)); + typedef std::vector<std::string> entriesT; + typedef entriesT::const_iterator entriesIter;   - std::string cval = "commit,log"; // default value if key not found - GetRegistryConfig("PromotedItems", cval); + std::string promoted_string = "commit,log"; // default value if key not found + GetRegistryConfig("PromotedItems", promoted_string);   - size_t found; - do - { - if (cval.empty()) - break; - - found = cval.find_first_of(','); - - std::string key; - if( found == std::string::npos ) - key = cval; - else - { - key = cval.substr(0, found); - cval = cval.substr(found+1); - } - - for (UINT i = 0; i < sz; i++) - { - if (!key.compare(menuDescList[i].name)) - { - promoted[i] = true; - break; - } - } - } - while (found != std::string::npos); + entriesT promoted; + Tokenize(promoted_string, promoted, ",");     // Select menu to show   bool fileMenu = myFiles.size() > 0; @@ -508,26 +470,28 @@
  );     /* We have three menu types: files-selected, no-files-selected, no-repo */ - menuDescListEntries *entries; + const char* entries_string = 0;   if (isHgrepo)   if (fileMenu) - entries = RepoFilesMenu; + entries_string = RepoFilesMenu;   else - entries = RepoNoFilesMenu; + entries_string = RepoNoFilesMenu;   else - entries = NoRepoMenu; + entries_string = NoRepoMenu;     // start building TortoiseHg menus and submenus   InsertMenu(hMenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL);   - menuDescListEntries *walk; - for (walk = entries; *walk != EndOfList; walk++) + entriesT entries; + Tokenize(entries_string, entries, " "); + + for (entriesIter i = entries.begin(); i != entries.end(); i++)   { - UINT idx = (UINT) *walk; - if (promoted[idx]) + std::string name = *i; + if (contains(promoted, name))   {   InsertMenuItemByName( - hMenu, menuDescList[idx].name, indexMenu++, + hMenu, name, indexMenu++,   idCmd++, idCmdFirst, L"Hg "   );   } @@ -538,9 +502,10 @@
  {   UINT indexSubMenu = 0;   bool isSeparator = true; - for (walk = entries; *walk != EndOfList; walk++) + for (entriesIter i = entries.begin(); i != entries.end(); i++)   { - if (*walk == Separator) + std::string name = *i; + if (name == "sep")   {   if (!isSeparator)   { @@ -553,11 +518,10 @@
  }   else   { - UINT idx = (UINT) *walk; - if (!promoted[idx]) + if (!contains(promoted, name))   {   InsertMenuItemByName( - hSubMenu, menuDescList[idx].name, + hSubMenu, name,   indexSubMenu++, idCmd++, idCmdFirst, L""   );   isSeparator = false;