~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to src/commands/CommandManager.cpp

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
#include <wx/msgdlg.h>
84
84
#include <wx/log.h>
85
85
 
 
86
#include "../AudacityApp.h"
86
87
#include "../Prefs.h"
87
88
#include "../Project.h"
88
89
 
308
309
/// Add a menu item to the current menu.  When the user selects it, the
309
310
/// given functor will be called
310
311
void CommandManager::AddItem(wxString name, wxString label,
311
 
                             CommandFunctor *callback)
 
312
                             CommandFunctor *callback, int checkmark)
312
313
{
313
314
   int ID = NewIdentifier(name, label, CurrentMenu(), callback, false, 0, 0);
314
315
 
347
348
      dummy = dummy + wxT("\t") + mCommandIDHash[ID]->key;
348
349
   }
349
350
 
350
 
   CurrentMenu()->Append(ID, dummy);
 
351
   if (checkmark >= 0) {
 
352
      CurrentMenu()->AppendCheckItem(ID, dummy);
 
353
      CurrentMenu()->Check(ID, checkmark !=0);
 
354
   }
 
355
   else {
 
356
      CurrentMenu()->Append(ID, dummy);
 
357
   }
351
358
   CurrentMenu()->SetLabel(ID, newLabel);
352
359
}
353
360
 
537
544
      
538
545
      for(i=1; i<entry->count; i++) {
539
546
         ID = NextIdentifier(ID);
540
 
         wxMenuItem *item = entry->menu->FindItem(ID);
 
547
 
 
548
         // This menu item is not necessarily in the same menu, because
 
549
         // multi-items can be spread across multiple sub menus
 
550
         CommandListEntry *multiEntry = mCommandIDHash[ID];
 
551
         if (multiEntry) {
 
552
            wxMenuItem *item = multiEntry->menu->FindItem(ID);
 
553
 
541
554
         if (item) {
542
555
            item->Enable(enabled);
543
556
         } else {
544
557
            wxLogDebug(wxT("Warning: Menu entry with id %i in %s not found"),
545
558
                ID, (const wxChar*)entry->name);
546
559
         }
 
560
         } else {
 
561
            wxLogDebug(wxT("Warning: Menu entry with id %i not in hash"), ID);
 
562
         }
547
563
      }
548
564
   }
549
565
}
552
568
{
553
569
   CommandListEntry *entry = mCommandNameHash[name];
554
570
   if (!entry || !entry->menu) {
555
 
      //printf("WARNING: Unknown command enabled: '%s'\n", (const char *)name.mb_str());
 
571
      wxLogDebug(wxT("Warning: Unknown command enabled: '%s'"),
 
572
                 (const wxChar*)name);
556
573
      return;
557
574
   }
558
575
 
577
594
   }
578
595
}
579
596
 
 
597
void CommandManager::Check(wxString name, bool checked)
 
598
{
 
599
   CommandListEntry *entry = mCommandNameHash[name];
 
600
   if (!entry || !entry->menu) {
 
601
      return;
 
602
   }
 
603
 
 
604
   entry->menu->Check(entry->id, checked);
 
605
}
 
606
 
580
607
///Changes the label text of a menu item
581
608
void CommandManager::Modify(wxString name, wxString newLabel)
582
609
{
685
712
 
686
713
   return;
687
714
}
688
 
 
 
715
 
 
716
void CommandManager::TellUserWhyDisallowed( wxUint32 flagsGot, wxUint32 flagsRequired )
 
717
{
 
718
   // The default string for 'reason' is a catch all.  I hope it won't ever be seen
 
719
   // and that we will get something more specific.
 
720
   wxString reason = _("Disallowed for some reason.  Try selecting some Audio first?");
 
721
 
 
722
   wxUint32 missingFlags = flagsRequired & (~flagsGot );
 
723
   if( missingFlags & AudioIONotBusyFlag )
 
724
      reason= _("You can only do this when playing and recording are\n stopped.  [Pausing is not sufficient.]");
 
725
   else if( missingFlags & StereoRequiredFlag )
 
726
      reason = _("You must first select some stereo audio for this\n to use.  [You can't use this with mono.]");
 
727
   else if( missingFlags & TimeSelectedFlag )
 
728
      reason = _("You must first select some audio for this to use.");
 
729
   else if( missingFlags & WaveTracksSelectedFlag)
 
730
      reason = _("You must first select some audio for this\n to use. [Selecting other kinds of track won't work.]");
 
731
   // If the only thing wrong was no tracks, we do nothing and don't report a problem
 
732
   else if( missingFlags == TracksExistFlag )
 
733
      return;
 
734
 
 
735
   wxMessageBox(reason, _("Message"),  wxICON_WARNING | wxOK ); 
 
736
}
 
737
 
689
738
/// HandleCommandEntry() takes a CommandListEntry and executes it
690
739
/// returning true iff successful.  If you pass any flags,
691
740
///the command won't be executed unless the flags are compatible
697
746
 
698
747
   wxUint32 combinedMask = (mask & entry->mask);
699
748
   if (combinedMask) {
700
 
      bool allowed = ((flags & combinedMask) ==
701
 
                      (entry->flags & combinedMask));
 
749
 
 
750
      AudacityProject * proj;
 
751
      proj = GetActiveProject();
 
752
      wxASSERT( proj );
 
753
      if( !proj )
 
754
         return false;     
 
755
 
 
756
      // NB: The call may have the side effect of changing flags.
 
757
      bool allowed = proj->TryToMakeActionAllowed( flags, entry->flags, combinedMask );
 
758
 
702
759
      if (!allowed)
 
760
      {
 
761
         TellUserWhyDisallowed( 
 
762
            flags & combinedMask, entry->flags & combinedMask);
703
763
         return false;
 
764
      }
704
765
   }
705
766
 
706
767
   (*(entry->callback))(entry->index);