Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LabelDialog Class Referencefinal

Dialog for editing labels. More...

#include <LabelDialog.h>

Inheritance diagram for LabelDialog:
wxDialogWrapper wxTabTraversalWrapper< wxDialog >

Public Member Functions

 LabelDialog (wxWindow *parent, TrackFactory &factory, TrackList *tracks, LabelTrack *selectedTrack, int index, ViewInfo &viewinfo, double rate, const NumericFormatId &format, const NumericFormatId &freqFormat)
 
 ~LabelDialog ()
 
bool Show (bool show=true) override
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&...args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Member Functions

void Populate ()
 Creates the dialog and its contents. More...
 
void PopulateOrExchange (ShuttleGui &S)
 
void PopulateLabels ()
 
virtual void OnHelp (wxCommandEvent &event)
 
virtual wxString GetHelpPageName ()
 
bool TransferDataToWindow () override
 
bool TransferDataFromWindow () override
 
bool Validate () override
 
void FindAllLabels ()
 
void AddLabels (const LabelTrack *t)
 
void FindInitialRow ()
 
wxString TrackName (int &index, const wxString &dflt=_("Label Track"))
 
void OnUpdate (wxCommandEvent &event)
 
void OnFreqUpdate (wxCommandEvent &event)
 
void OnInsert (wxCommandEvent &event)
 
void OnRemove (wxCommandEvent &event)
 
void OnImport (wxCommandEvent &event)
 
void OnExport (wxCommandEvent &event)
 
void OnSelectCell (wxGridEvent &event)
 
void OnCellChange (wxGridEvent &event)
 
void OnChangeTrack (wxGridEvent &event, int row, RowData *rd)
 
void OnChangeLabel (wxGridEvent &event, int row, RowData *rd)
 
void OnChangeStime (wxGridEvent &event, int row, RowData *rd)
 
void OnChangeEtime (wxGridEvent &event, int row, RowData *rd)
 
void OnChangeLfreq (wxGridEvent &event, int row, RowData *rd)
 
void OnChangeHfreq (wxGridEvent &event, int row, RowData *rd)
 
void OnOK (wxCommandEvent &event)
 
void OnCancel (wxCommandEvent &event)
 
void ReadSize ()
 
void WriteSize ()
 

Private Attributes

GridmGrid
 
ChoiceEditormChoiceEditor
 
NumericEditormTimeEditor
 
NumericEditormFrequencyEditor
 
RowDataArray mData
 
TrackFactorymFactory
 
TrackListmTracks
 
LabelTrackmSelectedTrack {}
 
int mIndex { -1 }
 
ViewInfomViewInfo
 
wxArrayString mTrackNames
 
double mRate
 
NumericFormatId mFormat
 
NumericFormatId mFreqFormat
 
int mInitialRow
 

Detailed Description

Dialog for editing labels.

Definition at line 34 of file LabelDialog.h.

Constructor & Destructor Documentation

LabelDialog::LabelDialog ( wxWindow *  parent,
TrackFactory factory,
TrackList tracks,
LabelTrack selectedTrack,
int  index,
ViewInfo viewinfo,
double  rate,
const NumericFormatId format,
const NumericFormatId freqFormat 
)
LabelDialog::~LabelDialog ( )

Definition at line 122 of file LabelDialog.cpp.

123 {
124 }

Member Function Documentation

void LabelDialog::AddLabels ( const LabelTrack t)
private

Definition at line 467 of file LabelDialog.cpp.

References LabelTrack::GetLabel(), Track::GetName(), LabelTrack::GetNumLabels(), mData, mIndex, mSelectedTrack, LabelStruct::selectedRegion, LabelStruct::title, and TrackName().

Referenced by FindAllLabels(), and OnImport().

468 {
469  wxString lab;
470  int tndx = 0;
471  int i;
472 
473  // Add a NEW track name
474  TrackName(tndx, t->GetName());
475 
476  // If editor was invoked for one label, add that one only, else add all.
477  if (!mSelectedTrack || mSelectedTrack == t) {
478  for (i = 0; i < t->GetNumLabels(); i++) {
479  const LabelStruct *ls = t->GetLabel(i);
480 
481  if (mIndex < 0 || mIndex == i)
482  mData.push_back(RowData(tndx, ls->title, ls->selectedRegion));
483  }
484  }
485 }
LabelTrack * mSelectedTrack
Definition: LabelDialog.h:104
wxString title
Definition: LabelTrack.h:92
RowDataArray mData
Definition: LabelDialog.h:100
int GetNumLabels() const
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:44
const LabelStruct * GetLabel(int index) const
wxString GetName() const
Definition: Track.h:271
SelectedRegion selectedRegion
Definition: LabelTrack.h:91
wxString TrackName(int &index, const wxString &dflt=_("Label Track"))
void LabelDialog::FindAllLabels ( )
private

Definition at line 447 of file LabelDialog.cpp.

References AddLabels(), FindInitialRow(), TrackListIterator::First(), Track::GetKind(), Track::Label, mData, mTracks, TrackListIterator::Next(), and OnInsert().

Referenced by PopulateLabels().

448 {
450  Track *t;
451 
452 
453  // Add labels from all label tracks
454  for (t = iter.First(); t; t = iter.Next()) {
455  if (t->GetKind() == Track::Label)
456  AddLabels(static_cast<const LabelTrack *>(t));
457  }
458 
459  FindInitialRow();
460 
461  if (mData.size() == 0) {
462  wxCommandEvent e;
463  OnInsert(e);
464  }
465 }
RowDataArray mData
Definition: LabelDialog.h:100
virtual int GetKind() const
Definition: Track.h:330
void AddLabels(const LabelTrack *t)
void FindInitialRow()
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
void OnInsert(wxCommandEvent &event)
An iterator for a TrackList.
Definition: Track.h:402
TrackList * mTracks
Definition: LabelDialog.h:103
void LabelDialog::FindInitialRow ( )
private

Definition at line 487 of file LabelDialog.cpp.

References mData, mInitialRow, mViewInfo, ViewInfo::selectedRegion, and SelectedRegion::t0().

Referenced by FindAllLabels().

488 {
489  int cnt = mData.size();
490  mInitialRow = -1;
491 
492  if (cnt == 0)
493  return;
494 
495  // find closest previous label
496 
497  double distMin = std::numeric_limits<double>::max();
498  double dist;
499  double t0 = mViewInfo->selectedRegion.t0();
500  int i;
501  for (i = 0; i < cnt; i++)
502  {
503  dist = t0 - mData[i].selectedRegion.t0();
504  if (dist >= 0.0 && dist < distMin)
505  {
506  mInitialRow = i;
507  distMin = dist;
508  }
509  }
510 
511  // if no previous label was found, find first label
512 
513  if (mInitialRow == -1)
514  {
515  double t0Min = std::numeric_limits<double>::max();
516  for (i = 0; i < cnt; i++)
517  {
518  if (mData[i].selectedRegion.t0() < t0Min)
519  {
520  mInitialRow = i;
521  t0Min = mData[i].selectedRegion.t0();
522  }
523  }
524  }
525 }
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
RowDataArray mData
Definition: LabelDialog.h:100
ViewInfo * mViewInfo
Definition: LabelDialog.h:106
virtual wxString LabelDialog::GetHelpPageName ( )
inlineprivatevirtual

Definition at line 63 of file LabelDialog.h.

Referenced by OnHelp().

63 {return "Labels_Editor";};
void LabelDialog::OnCancel ( wxCommandEvent &  event)
private

Definition at line 936 of file LabelDialog.cpp.

References mGrid, and WriteSize().

937 {
938  if (mGrid->IsCellEditControlShown()) {
939  auto editor = mGrid->GetCellEditor(mGrid->GetGridCursorRow(),
940  mGrid->GetGridCursorCol());
941  editor->Reset();
942  // To avoid memory leak, don't forget DecRef()!
943  editor->DecRef();
944  mGrid->HideCellEditControl();
945  return;
946  }
947 
948  WriteSize();
949  // Standard handling
950  EndModal(wxID_CANCEL);
951 
952  return;
953 }
void WriteSize()
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnCellChange ( wxGridEvent &  event)
private

Definition at line 759 of file LabelDialog.cpp.

References Col_Etime, Col_Hfreq, Col_Label, Col_Lfreq, Col_Stime, Col_Track, mData, OnChangeEtime(), OnChangeHfreq(), OnChangeLabel(), OnChangeLfreq(), OnChangeStime(), and OnChangeTrack().

760 {
761  static bool guard = false;
762  int row = event.GetRow();
763 
764  // Guard against recursion which can happen when a change to the "NEW label" row
765  // is made. When InsertRow() is done in TransferDataToWindow(), checks are made
766  // within wxGrid to see if the edit control is active and since it hasn't yet
767  // been marked inactive on the first time through here, we get entered again.
768  // Sort of a double change. I think this is probably a bug in wxGrid.
769  if (guard) {
770  return;
771  }
772  guard = true;
773 
774  // The change was to an existing label, so go process it based
775  // on which column was changed.
776  RowData *rd = &mData[row];
777  switch (event.GetCol())
778  {
779  case Col_Track:
780  OnChangeTrack(event, row, rd);
781  break;
782 
783  case Col_Label:
784  OnChangeLabel(event, row, rd);
785  break;
786 
787  case Col_Stime:
788  OnChangeStime(event, row, rd);
789  break;
790 
791  case Col_Etime:
792  OnChangeEtime(event, row, rd);
793  break;
794 
795  case Col_Lfreq:
796  OnChangeLfreq(event, row, rd);
797  break;
798 
799  case Col_Hfreq:
800  OnChangeHfreq(event, row, rd);
801  break;
802  }
803 
804  // Done...no need for protection anymore
805  guard = false;
806 
807  return;
808 }
void OnChangeLfreq(wxGridEvent &event, int row, RowData *rd)
void OnChangeLabel(wxGridEvent &event, int row, RowData *rd)
RowDataArray mData
Definition: LabelDialog.h:100
void OnChangeEtime(wxGridEvent &event, int row, RowData *rd)
void OnChangeTrack(wxGridEvent &event, int row, RowData *rd)
void OnChangeHfreq(wxGridEvent &event, int row, RowData *rd)
void OnChangeStime(wxGridEvent &event, int row, RowData *rd)
void LabelDialog::OnChangeEtime ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 864 of file LabelDialog.cpp.

References Col_Etime, Col_Stime, mGrid, RowData::selectedRegion, SelectedRegion::setT1(), and SelectedRegion::t0().

Referenced by OnCellChange().

865 {
866  // Remember the value...no need to repopulate
867  double t {};
868  mGrid->GetCellValue(row, Col_Etime).ToDouble(&t);
869  rd->selectedRegion.setT1(t, false);
870  mGrid->SetCellValue(row, Col_Stime, wxString::Format(wxT("%g"),
871  rd->selectedRegion.t0()));
872 
873  return;
874 }
double t0() const
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
bool setT1(double t, bool maySwap=true)
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnChangeHfreq ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 888 of file LabelDialog.cpp.

References Col_Hfreq, Col_Lfreq, SelectedRegion::f0(), mGrid, RowData::selectedRegion, and SelectedRegion::setF1().

Referenced by OnCellChange().

889 {
890  // Remember the value...no need to repopulate
891  double f;
892  mGrid->GetCellValue(row, Col_Hfreq).ToDouble(&f);
893  rd->selectedRegion.setF1(f, false);
894  mGrid->SetCellValue(row, Col_Lfreq, wxString::Format(wxT("%g"),
895  rd->selectedRegion.f0()));
896 
897  return;
898 }
double f0() const
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
bool setF1(double f, bool maySwap=true)
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnChangeLabel ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 844 of file LabelDialog.cpp.

References Col_Label, mGrid, and RowData::title.

Referenced by OnCellChange().

845 {
846  // Remember the value...no need to repopulate
847  rd->title = mGrid->GetCellValue(row, Col_Label);
848 
849  return;
850 }
wxString title
Definition: LabelDialog.cpp:66
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnChangeLfreq ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 876 of file LabelDialog.cpp.

References Col_Hfreq, Col_Lfreq, SelectedRegion::f1(), mGrid, RowData::selectedRegion, and SelectedRegion::setF0().

Referenced by OnCellChange().

877 {
878  // Remember the value...no need to repopulate
879  double f;
880  mGrid->GetCellValue(row, Col_Lfreq).ToDouble(&f);
881  rd->selectedRegion.setF0(f, false);
882  mGrid->SetCellValue(row, Col_Hfreq, wxString::Format(wxT("%g"),
883  rd->selectedRegion.f1()));
884 
885  return;
886 }
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
double f1() const
Grid * mGrid
Definition: LabelDialog.h:95
bool setF0(double f, bool maySwap=true)
void LabelDialog::OnChangeStime ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 852 of file LabelDialog.cpp.

References Col_Etime, Col_Stime, mGrid, RowData::selectedRegion, SelectedRegion::setT0(), and SelectedRegion::t1().

Referenced by OnCellChange().

853 {
854  // Remember the value...no need to repopulate
855  double t {};
856  mGrid->GetCellValue(row, Col_Stime).ToDouble(&t);
857  rd->selectedRegion.setT0(t, false);
858  mGrid->SetCellValue(row, Col_Etime, wxString::Format(wxT("%g"),
859  rd->selectedRegion.t1()));
860 
861  return;
862 }
double t1() const
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
bool setT0(double t, bool maySwap=true)
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnChangeTrack ( wxGridEvent &  event,
int  row,
RowData rd 
)
private

Definition at line 810 of file LabelDialog.cpp.

References _(), Col_Track, RowData::index, mGrid, mTrackNames, TrackName(), and TransferDataToWindow().

Referenced by OnCellChange().

811 {
812  wxString val = mGrid->GetCellValue(row, Col_Track);
813 
814  // User selected the "New..." choice so ask for a NEW name
815  if (mTrackNames.Index(val) == 0) {
817  _("New Label Track"),
818  _("Enter track name"),
819  /* i18n-hint: (noun) it's the name of a kind of track.*/
820  _("Label Track"));
821 
822  // User canceled so repopulating the grid will set the track
823  // name to the orignal value
824  if (d.ShowModal() == wxID_CANCEL) {
826  return;
827  }
828 
829  // Force generation of a NEW track name
830  rd->index = 0;
831  TrackName(rd->index, d.GetValue());
832  }
833  else {
834  // Remember the tracks index
835  rd->index = mTrackNames.Index(val);
836  }
837 
838  // Repopulate the grid
840 
841  return;
842 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
Wrap wxTextEntryDialog so that caption IS translatable.
Definition: ErrorDialog.h:108
bool TransferDataToWindow() override
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
Grid * mGrid
Definition: LabelDialog.h:95
wxString TrackName(int &index, const wxString &dflt=_("Label Track"))
void LabelDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 663 of file LabelDialog.cpp.

References _(), AudacityMessageBox(), FileNames::Export, mData, mFactory, mTrackNames, TrackFactory::NewLabelTrack(), RowData::selectedRegion, FileNames::SelectFile(), and RowData::title.

664 {
665  int cnt = mData.size();
666 
667  // Silly user (could just disable the button, but that's a hassle ;-))
668  if (cnt == 0) {
669  AudacityMessageBox(_("No labels to export."));
670  return;
671  }
672 
673  // Extract the actual name.
674  wxString fName = mTrackNames[mTrackNames.GetCount() - 1].AfterFirst(wxT('-')).Mid(1);
675 
677  _("Export Labels As:"),
678  wxEmptyString,
679  fName,
680  wxT("txt"),
681  wxT("*.txt"),
682  wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
683  this);
684 
685  if (fName == wxT(""))
686  return;
687 
688  // Move existing files out of the way. Otherwise wxTextFile will
689  // append to (rather than replace) the current file.
690 
691  if (wxFileExists(fName)) {
692 #ifdef __WXGTK__
693  wxString safetyFileName = fName + wxT("~");
694 #else
695  wxString safetyFileName = fName + wxT(".bak");
696 #endif
697 
698  if (wxFileExists(safetyFileName))
699  wxRemoveFile(safetyFileName);
700 
701  wxRename(fName, safetyFileName);
702  }
703 
704  wxTextFile f(fName);
705 #ifdef __WXMAC__
706  wxFile{}.Create(fName);
707 #else
708  f.Create();
709 #endif
710  f.Open();
711  if (!f.IsOpened()) {
713  wxString::Format( _("Couldn't write to file: %s"), fName ) );
714  return;
715  }
716 
717  // Transfer our collection to a temporary label track
718  auto lt = mFactory.NewLabelTrack();
719  int i;
720 
721  for (i = 0; i < cnt; i++) {
722  RowData &rd = mData[i];
723 
724  lt->AddLabel(rd.selectedRegion, rd.title,-2);
725  }
726 
727  // Export them and clean
728  lt->Export(f);
729 
730 #ifdef __WXMAC__
731  f.Write(wxTextFileType_Mac);
732 #else
733  f.Write();
734 #endif
735  f.Close();
736 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxString title
Definition: LabelDialog.cpp:66
RowDataArray mData
Definition: LabelDialog.h:100
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
static wxString SelectFile(Operation op, const wxString &message, const wxString &default_path, const wxString &default_filename, const wxString &default_extension, const wxString &wildcard, int flags, wxWindow *parent)
Definition: FileNames.cpp:411
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< LabelTrack > NewLabelTrack()
Definition: LabelTrack.cpp:99
TrackFactory & mFactory
Definition: LabelDialog.h:102
void LabelDialog::OnFreqUpdate ( wxCommandEvent &  event)
private

Definition at line 537 of file LabelDialog.cpp.

References NumericConverter::FREQUENCY, NumericConverter::LookupFormat(), mFreqFormat, and TransferDataToWindow().

538 {
539  // Remember the NEW format and repopulate grid
541  NumericConverter::FREQUENCY, event.GetString() );
543 
544  event.Skip(false);
545 }
NumericFormatId mFreqFormat
Definition: LabelDialog.h:109
bool TransferDataToWindow() override
static NumericFormatId LookupFormat(Type type, const wxString &id)
void LabelDialog::OnHelp ( wxCommandEvent &  event)
privatevirtual

Definition at line 279 of file LabelDialog.cpp.

References GetHelpPageName(), and HelpSystem::ShowHelp().

280 {
281  wxString page = GetHelpPageName();
282  HelpSystem::ShowHelp(this, page, true);
283 }
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:194
virtual wxString GetHelpPageName()
Definition: LabelDialog.h:63
void LabelDialog::OnImport ( wxCommandEvent &  event)
private

Definition at line 623 of file LabelDialog.cpp.

References _(), AddLabels(), AudacityMessageBox(), mFactory, TrackFactory::NewLabelTrack(), FileNames::Open, FileNames::SelectFile(), and TransferDataToWindow().

624 {
625  // Ask user for a filename
626  wxString fileName =
628  _("Select a text file containing labels"),
629  wxEmptyString, // Path
630  wxT(""), // Name
631  wxT(".txt"), // Extension
632  _("Text files (*.txt)|*.txt|All files|*"),
633  wxRESIZE_BORDER, // Flags
634  this); // Parent
635 
636  // They gave us one...
637  if (fileName != wxT("")) {
638  wxTextFile f;
639 
640  // Get at the data
641  f.Open(fileName);
642  if (!f.IsOpened()) {
644  wxString::Format( _("Could not open file: %s"), fileName ));
645  }
646  else {
647  // Create a temporary label track and load the labels
648  // into it
649  auto lt = mFactory.NewLabelTrack();
650  lt->Import(f);
651 
652  // Add the labels to our collection
653  AddLabels(lt.get());
654 
655  // Done with the temporary track
656  }
657 
658  // Repopulate the grid
660  }
661 }
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
void AddLabels(const LabelTrack *t)
bool TransferDataToWindow() override
static wxString SelectFile(Operation op, const wxString &message, const wxString &default_path, const wxString &default_filename, const wxString &default_extension, const wxString &wildcard, int flags, wxWindow *parent)
Definition: FileNames.cpp:411
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< LabelTrack > NewLabelTrack()
Definition: LabelTrack.cpp:99
TrackFactory & mFactory
Definition: LabelDialog.h:102
void LabelDialog::OnInsert ( wxCommandEvent &  event)
private

Definition at line 547 of file LabelDialog.cpp.

References Col_Label, Col_Track, ID_INSERTA, mData, mGrid, mTrackNames, and TransferDataToWindow().

Referenced by FindAllLabels().

548 {
549  int cnt = mData.size();
550  int row = 0;
551  int index = 0;
552 
553  // Make sure the edit control isn't active before inserting any rows
554  if (mGrid->IsCellEditControlShown()) {
555  mGrid->HideCellEditControl();
556  }
557 
558  // Attempt to guess which track the label should reside on
559  if (cnt > 0) {
560  row = mGrid->GetGridCursorRow();
561  if (row > 0 && row >= cnt) {
562  index = mTrackNames.Index(mGrid->GetCellValue(row - 1, Col_Track));
563  }
564  else {
565  index = mTrackNames.Index(mGrid->GetCellValue(row, Col_Track));
566  }
567  }
568 
569  // Insert NEW label before or after the current row
570  if (event.GetId() == ID_INSERTA && row < cnt) {
571  row++;
572  }
573  mData.insert(mData.begin() + row, RowData(index, wxT(""), SelectedRegion()));
574 
575  // Repopulate the grid
577 
578  // Reposition cursor to NEW row/col and put user into edit mode to
579  // set the label name
580  mGrid->SetGridCursor(row, Col_Label);
581  mGrid->EnableCellEditControl(true);
582  mGrid->ShowCellEditControl();
583 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
RowDataArray mData
Definition: LabelDialog.h:100
bool TransferDataToWindow() override
Defines a selected portion of a project.
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnOK ( wxCommandEvent &  event)
private

Definition at line 919 of file LabelDialog.cpp.

References mGrid, TransferDataFromWindow(), Validate(), and WriteSize().

920 {
921  if (mGrid->IsCellEditControlShown()) {
922  mGrid->SaveEditControlValue();
923  mGrid->HideCellEditControl();
924  return;
925  }
926 
927  // Standard handling
928  if (Validate() && TransferDataFromWindow()) {
929  WriteSize();
930  EndModal(wxID_OK);
931  }
932 
933  return;
934 }
bool Validate() override
bool TransferDataFromWindow() override
void WriteSize()
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnRemove ( wxCommandEvent &  event)
private

Definition at line 585 of file LabelDialog.cpp.

References mData, mGrid, and TransferDataToWindow().

586 {
587  int row = mGrid->GetGridCursorRow();
588  int col = mGrid->GetGridCursorCol();
589  int cnt = mData.size();
590 
591  // Don't try to remove if no labels exist
592  if (cnt == 0) {
593  return;
594  }
595 
596  // Make sure the edit control isn't active before removing rows
597  if (mGrid->IsCellEditControlShown()) {
598  mGrid->HideCellEditControl();
599  }
600 
601  // Remove the row
602  //RowData &rd = mData[row];
603  mData.erase(mData.begin() + row);
604 
605  // Repopulate the grid
607 
608  // Reposition the cursor
609  if (row > 0 && row >= --cnt) {
610  row--;
611  }
612  mGrid->SetGridCursor(row, col);
613 
614  // Make sure focus isn't lost
615  if (mData.size() == 0 && wxWindow::FindFocus() == mGrid->GetGridWindow()) {
616  wxWindow *ok = wxWindow::FindWindowById( wxID_OK, this);
617  if (ok) {
618  ok->SetFocus();
619  }
620  }
621 }
RowDataArray mData
Definition: LabelDialog.h:100
bool TransferDataToWindow() override
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::OnSelectCell ( wxGridEvent &  event)
private

Definition at line 738 of file LabelDialog.cpp.

References TrackListIterator::First(), GetActiveProject(), mData, mTracks, mViewInfo, TrackListIterator::Next(), AudacityProject::RedrawProject(), RowData::selectedRegion, ViewInfo::selectedRegion, and Track::SetSelected().

739 {
741  Track *t = iter.First();
742  while( t )
743  {
744  t->SetSelected( true );
745  t = iter.Next();
746  }
747 
748  if (!mData.empty())
749  {
750  RowData &rd = mData[event.GetRow()];
752 
754  }
755 
756  event.Skip();
757 }
void RedrawProject(const bool bForceWaveTracks=false)
Definition: Project.cpp:1378
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
RowDataArray mData
Definition: LabelDialog.h:100
virtual void SetSelected(bool s)
Definition: Track.cpp:99
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
ViewInfo * mViewInfo
Definition: LabelDialog.h:106
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
An iterator for a TrackList.
Definition: Track.h:402
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
TrackList * mTracks
Definition: LabelDialog.h:103
void LabelDialog::OnUpdate ( wxCommandEvent &  event)
private

Definition at line 527 of file LabelDialog.cpp.

References NumericConverter::LookupFormat(), mFormat, NumericConverter::TIME, and TransferDataToWindow().

528 {
529  // Remember the NEW format and repopulate grid
531  NumericConverter::TIME, event.GetString() );
533 
534  event.Skip(false);
535 }
NumericFormatId mFormat
Definition: LabelDialog.h:109
bool TransferDataToWindow() override
static NumericFormatId LookupFormat(Type type, const wxString &id)
void LabelDialog::Populate ( )
private

Creates the dialog and its contents.

Definition at line 208 of file LabelDialog.cpp.

References eIsCreating, ID_IMPORT, mGrid, PopulateLabels(), PopulateOrExchange(), and ReadSize().

209 {
210 
211  //------------------------- Main section --------------------
212  ShuttleGui S(this, eIsCreating);
214  // ----------------------- End of main section --------------
215 
216  // Go populate the macros list.
217  PopulateLabels();
218 
219  // Layout the works
220  Layout();
221  //Fit();
222 
223  // Resize width based on width of columns and the vertical scrollbar
224  wxRect r = mGrid->GetGridColLabelWindow()->GetRect();
225  wxScrollBar sb(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
226  r.width += sb.GetSize().GetWidth() + 6;
227 
228  // Add the size of the right column of buttons too...
229  wxWindow * w = FindWindowById( ID_IMPORT, this );
230  wxASSERT( w );
231  if( w )
232  r.width += w->GetSize().GetWidth();
233 
234  SetClientSize(r.width, 300);
235 
236  // Make sure it doesn't go below this size
237  r = GetRect();
238  SetSizeHints(r.GetWidth(), r.GetHeight());
239 
240  // Bug 1465
241  // There might be a saved size, in which case use that.
242  ReadSize();
243 
244  // Center on display
245  Center();
246 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void PopulateOrExchange(ShuttleGui &S)
void PopulateLabels()
Grid * mGrid
Definition: LabelDialog.h:95
void ReadSize()
void LabelDialog::PopulateLabels ( )
private

Definition at line 126 of file LabelDialog.cpp.

References _(), Col_Etime, Col_Hfreq, Col_Label, Col_Lfreq, Col_Max, Col_Stime, Col_Track, FindAllLabels(), GRID_VALUE_CHOICE, GRID_VALUE_FREQUENCY, GRID_VALUE_TIME, mChoiceEditor, mFrequencyEditor, mGrid, mTimeEditor, mTrackNames, safenew, and TransferDataToWindow().

Referenced by Populate().

127 {
128  // Build the initial (empty) grid
129  mGrid->CreateGrid(0, Col_Max);
130  mGrid->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTER);
131 
132  /* i18n-hint: (noun). A track contains waves, audio etc.*/
133  mGrid->SetColLabelValue(0,_("Track"));
134  /* i18n-hint: (noun)*/
135  mGrid->SetColLabelValue(1,_("Label"));
136  /* i18n-hint: (noun) of a label*/
137  mGrid->SetColLabelValue(2,_("Start Time"));
138  /* i18n-hint: (noun) of a label*/
139  mGrid->SetColLabelValue(3,_("End Time"));
140  /* i18n-hint: (noun) of a label*/
141  mGrid->SetColLabelValue(4,_("Low Frequency"));
142  /* i18n-hint: (noun) of a label*/
143  mGrid->SetColLabelValue(5,_("High Frequency"));
144 
145  // Create and remember editors. No need to DELETE these as the wxGrid will
146  // do it for us. (The DecRef() that is needed after GetDefaultEditorForType
147  // becomes the duty of the wxGridCellAttr objects after we set them in the grid.)
148  mChoiceEditor = (ChoiceEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_CHOICE);
149  mTimeEditor = static_cast<NumericEditor*>
150  (mGrid->GetDefaultEditorForType(GRID_VALUE_TIME));
151  mFrequencyEditor = static_cast<NumericEditor *>
152  (mGrid->GetDefaultEditorForType(GRID_VALUE_FREQUENCY));
153 
154  // Initialize and set the track name column attributes
155  wxGridCellAttr *attr;
156  mGrid->SetColAttr(Col_Track, (attr = safenew wxGridCellAttr));
157  attr->SetEditor(mChoiceEditor);
158  mTrackNames.Add(_("New..."));
159 
160  // Initialize and set the time column attributes
161  mGrid->SetColAttr(Col_Stime, (attr = safenew wxGridCellAttr));
162  // Don't need DecRef() after this GetDefaultRendererForType.
163  attr->SetRenderer(mGrid->GetDefaultRendererForType(GRID_VALUE_TIME));
164  attr->SetEditor(mTimeEditor);
165  attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
166 
167  mGrid->SetColAttr(Col_Etime, attr->Clone());
168 
169  // Initialize and set the frequency column attributes
170  mGrid->SetColAttr(Col_Lfreq, (attr = safenew wxGridCellAttr));
171  // Don't need DecRef() after this GetDefaultRendererForType.
172  attr->SetRenderer(mGrid->GetDefaultRendererForType(GRID_VALUE_FREQUENCY));
173  attr->SetEditor(mFrequencyEditor);
174  attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
175 
176  mGrid->SetColAttr(Col_Hfreq, attr->Clone());
177 
178  // Seems there's a bug in wxGrid. Adding only 1 row does not
179  // allow SetCellSize() to work properly and you will not get
180  // the expected 1 row by 4 column cell.
181  //
182  // So, we set the minimum row height to 0 and basically hide
183  // the extra row by setting its height to 0. And not allowing the
184  // rows to be manually resized prevents the user from ever seeing
185  // the extra row.
186  mGrid->SetRowMinimalAcceptableHeight(0);
187  mGrid->EnableDragRowSize(false);
188 
189  // Locate all labels in current track list
190  FindAllLabels();
191 
192  // Populate the grid
194 
195  // Resize the label name column and ensure it doesn't go below an
196  // arbitrary width.
197  //
198  // This should not be in TransferDataToWindow() since a user might
199  // resize the column and we'd resize it back to the minimum.
200  mGrid->AutoSizeColumn(Col_Label, false );
201  mGrid->SetColSize(Col_Label, wxMax(150, mGrid->GetColSize(Col_Label)));
202  mGrid->SetColMinimalWidth(Col_Label, mGrid->GetColSize(Col_Label));
203 
204 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
void FindAllLabels()
#define GRID_VALUE_TIME
Definition: Grid.h:41
#define GRID_VALUE_CHOICE
Definition: Grid.h:126
NumericEditor * mFrequencyEditor
Definition: LabelDialog.h:98
#define safenew
Definition: Audacity.h:230
#define GRID_VALUE_FREQUENCY
Definition: Grid.h:42
bool TransferDataToWindow() override
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ChoiceEditor * mChoiceEditor
Definition: LabelDialog.h:96
Grid * mGrid
Definition: LabelDialog.h:95
NumericEditor * mTimeEditor
Definition: LabelDialog.h:97
void LabelDialog::PopulateOrExchange ( ShuttleGui S)
private

Definition at line 248 of file LabelDialog.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddFixedText(), ShuttleGui::AddStandardButtons(), ShuttleGuiBase::AddWindow(), eCancelButton, eHelpButton, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndVerticalLay(), eOkButton, ShuttleGui::Id(), ID_EXPORT, ID_IMPORT, ID_INSERTB, ID_REMOVE, mGrid, ShuttleGui::Prop(), safenew, ShuttleGuiBase::StartHorizontalLay(), and ShuttleGuiBase::StartVerticalLay().

Referenced by Populate().

249 {
250  S.AddFixedText(_("Press F2 or double click to edit cell contents."));
251  S.StartHorizontalLay(wxEXPAND,1);
252  {
253  S.StartVerticalLay(wxEXPAND,1);
254  {
255  mGrid = safenew Grid(this, wxID_ANY);
256  S.Prop(1).AddWindow( mGrid );
257  }
258  S.EndVerticalLay();
259  S.StartVerticalLay(0);
260  {
261  //S.Id(ID_INSERTA).AddButton(_("&Insert"), wxALIGN_LEFT);
262  S.Id(ID_INSERTB).AddButton(_("&Insert"), wxALIGN_LEFT);
263  //S.Id(EditButtonID).AddButton(_("&Edit"), wxALIGN_LEFT);
264  S.Id(ID_REMOVE).AddButton(_("De&lete"), wxALIGN_LEFT);
265  S.Id(ID_IMPORT).AddButton(_("I&mport..."), wxALIGN_LEFT);
266  S.Id(ID_EXPORT).AddButton(_("&Export..."), wxALIGN_LEFT);
267  }
268  S.EndVerticalLay();
269  }
270  S.EndHorizontalLay();
271 
272  S.StartHorizontalLay(wxALIGN_RIGHT, false);
273  {
275  }
276  S.EndHorizontalLay();
277 }
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:288
#define safenew
Definition: Audacity.h:230
void EndHorizontalLay()
void EndVerticalLay()
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
ShuttleGui & Id(int id)
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:418
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
Supplies an accessible grid based on wxGrid.
Definition: Grid.h:193
Grid * mGrid
Definition: LabelDialog.h:95
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
void StartVerticalLay(int iProp=1)
void LabelDialog::ReadSize ( )
private

Definition at line 900 of file LabelDialog.cpp.

References gPrefs.

Referenced by Populate().

900  {
901  wxSize sz = GetSize();
902  int prefWidth, prefHeight;
903  gPrefs->Read(wxT("/LabelEditor/Width"), &prefWidth, sz.x);
904  gPrefs->Read(wxT("/LabelEditor/Height"), &prefHeight, sz.y);
905 
906  wxRect screenRect(wxGetClientDisplayRect());
907  wxSize prefSize = wxSize(prefWidth, prefHeight);
908  prefSize.DecTo(screenRect.GetSize());
909  SetSize(prefSize);
910 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool LabelDialog::Show ( bool  show = true)
override

Definition at line 349 of file LabelDialog.cpp.

References Col_Label, mGrid, and mInitialRow.

350 {
351  bool ret = wxDialogWrapper::Show(show);
352 
353  // Set initial row
354  // (This will not work until the grid is actually displayed)
355  if (show && mInitialRow != -1) {
356  mGrid->SetGridCursor(mInitialRow, Col_Label);
357  }
358 
359  return ret;
360 }
Grid * mGrid
Definition: LabelDialog.h:95
wxString LabelDialog::TrackName ( int &  index,
const wxString &  dflt = _("Label Track") 
)
private

Definition at line 435 of file LabelDialog.cpp.

References mTrackNames.

Referenced by AddLabels(), OnChangeTrack(), and TransferDataToWindow().

436 {
437  // Generate a NEW track name if the passed index is out of range
438  if (index < 1 || index >= (int)mTrackNames.GetCount()) {
439  index = mTrackNames.GetCount();
440  mTrackNames.Add(wxString::Format(wxT("%d - %s"), index, dflt));
441  }
442 
443  // Return the track name
444  return mTrackNames[index];
445 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
bool LabelDialog::TransferDataFromWindow ( )
overrideprivate

Definition at line 362 of file LabelDialog.cpp.

References TrackList::Add(), LabelTrack::DeleteLabel(), TrackListIterator::First(), Track::GetKind(), LabelTrack::GetNumLabels(), RowData::index, Track::Label, mData, mFactory, mIndex, mSelectedTrack, mTrackNames, mTracks, name, TrackFactory::NewLabelTrack(), TrackListIterator::Next(), RowData::selectedRegion, and RowData::title.

Referenced by OnOK().

363 {
364  int cnt = mData.size();
365  int i;
367  Track *t;
368  int tndx = 0;
369 
370  // Clear label tracks of labels
371  for (t = iter.First(); t; t = iter.Next()) {
372  if (t->GetKind() == Track::Label) {
373  ++tndx;
374  LabelTrack *lt = static_cast<LabelTrack*>(t);
375  if (!mSelectedTrack) {
376  for (i = lt->GetNumLabels() - 1; i >= 0 ; i--) {
377  lt->DeleteLabel(i);
378  }
379  }
380  else if (mSelectedTrack == lt && mIndex > -1) {
381  lt->DeleteLabel(mIndex);
382  }
383  else
384  // Do nothing to the nonselected tracks
385  ;
386  }
387  }
388 
389  // Create any added tracks
390  while (tndx < (int)mTrackNames.GetCount() - 1) {
391 
392  // Extract the name
393  wxString name = mTrackNames[tndx + 1].AfterFirst(wxT('-')).Mid(1);
394 
395  // Create the NEW track and add to track list
396  auto newTrack = mFactory.NewLabelTrack();
397  newTrack->SetName(name);
398  mTracks->Add(std::move(newTrack));
399  tndx++;
400  }
401 
402  // Repopulate with updated labels
403  for (i = 0; i < cnt; i++) {
404  RowData &rd = mData[i];
405 
406  // Look for track with matching index
407  tndx = 1;
408  for (t = iter.First(); t; t = iter.Next()) {
409  if (t->GetKind() == Track::Label && rd.index == tndx++) {
410  break;
411  }
412  }
413  wxASSERT(t);
414  if (!t)
415  return false;
416 
417  // Add the label to it
418  static_cast<LabelTrack *>(t)->AddLabel(rd.selectedRegion, rd.title,-2);
419  static_cast<LabelTrack *>(t)->Unselect();
420  }
421 
422  return true;
423 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
LabelTrack * mSelectedTrack
Definition: LabelDialog.h:104
void DeleteLabel(int index)
Track * Add(std::unique_ptr< TrackKind > &&t)
Add a Track, giving it a fresh id.
Definition: Track.cpp:906
wxString title
Definition: LabelDialog.cpp:66
RowDataArray mData
Definition: LabelDialog.h:100
int GetNumLabels() const
virtual int GetKind() const
Definition: Track.h:330
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
An iterator for a TrackList.
Definition: Track.h:402
const wxChar * name
Definition: Distortion.cpp:94
TrackList * mTracks
Definition: LabelDialog.h:103
std::unique_ptr< LabelTrack > NewLabelTrack()
Definition: LabelTrack.cpp:99
TrackFactory & mFactory
Definition: LabelDialog.h:102
bool LabelDialog::TransferDataToWindow ( )
overrideprivate

Definition at line 286 of file LabelDialog.cpp.

References Col_Etime, Col_Hfreq, Col_Label, Col_Lfreq, Col_Stime, Col_Track, SelectedRegion::f0(), SelectedRegion::f1(), RowData::index, mChoiceEditor, mData, mFormat, mFreqFormat, mFrequencyEditor, mGrid, mRate, mTimeEditor, mTrackNames, RowData::selectedRegion, ChoiceEditor::SetChoices(), NumericEditor::SetFormat(), NumericEditor::SetRate(), SelectedRegion::t0(), SelectedRegion::t1(), RowData::title, and TrackName().

Referenced by OnChangeTrack(), OnFreqUpdate(), OnImport(), OnInsert(), OnRemove(), OnUpdate(), and PopulateLabels().

287 {
288  int cnt = mData.size();
289  int i;
290 
291  // Set the editor parameters. Do this each time since they may change
292  // due to NEW tracks and change in NumericTextCtrl format. Rate won't
293  // change but might as well leave it here.
299 
300  // Disable redrawing until we're done
301  mGrid->BeginBatch();
302 
303  // Delete all rows
304  if (mGrid->GetNumberRows()) {
305  mGrid->DeleteRows(0, mGrid->GetNumberRows());
306  }
307 
308  // Add the exact number that we'll need
309  mGrid->InsertRows(0, cnt);
310 
311  // Populate the rows
312  for (i = 0; i < cnt; i++) {
313  RowData &rd = mData[i];
314 
315  // Set the cell contents
316  mGrid->SetCellValue(i, Col_Track, TrackName(rd.index));
317  mGrid->SetCellValue(i, Col_Label, rd.title);
318  mGrid->SetCellValue(i, Col_Stime,
319  wxString::Format(wxT("%g"), rd.selectedRegion.t0()));
320  mGrid->SetCellValue(i, Col_Etime,
321  wxString::Format(wxT("%g"), rd.selectedRegion.t1()));
322  mGrid->SetCellValue(i, Col_Lfreq,
323  wxString::Format(wxT("%g"), rd.selectedRegion.f0()));
324  mGrid->SetCellValue(i, Col_Hfreq,
325  wxString::Format(wxT("%g"), rd.selectedRegion.f1()));
326  }
327 
328  // Autosize all the rows
329  mGrid->AutoSizeRows(true);
330 
331  // Resize the track name column. Use a wxChoice to determine the maximum
332  // width needed.
333  wxChoice tc(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, mTrackNames);
334  mGrid->SetColSize(Col_Track, tc.GetSize().x);
335  mGrid->SetColMinimalWidth(Col_Track, tc.GetSize().x);
336 
337  // Autosize the time columns and set their minimal widths
338  mGrid->AutoSizeColumn(Col_Stime);
339  mGrid->AutoSizeColumn(Col_Etime);
340  mGrid->AutoSizeColumn(Col_Lfreq);
341  mGrid->AutoSizeColumn(Col_Hfreq);
342 
343  // We're done, so allow the grid to redraw
344  mGrid->EndBatch();
345 
346  return true;
347 }
wxArrayString mTrackNames
Definition: LabelDialog.h:107
double t0() const
NumericFormatId mFreqFormat
Definition: LabelDialog.h:109
double mRate
Definition: LabelDialog.h:108
NumericEditor * mFrequencyEditor
Definition: LabelDialog.h:98
wxString title
Definition: LabelDialog.cpp:66
NumericFormatId mFormat
Definition: LabelDialog.h:109
RowDataArray mData
Definition: LabelDialog.h:100
double t1() const
double f0() const
void SetFormat(const NumericFormatId &format)
Definition: Grid.cpp:144
SelectedRegion selectedRegion
Definition: LabelDialog.cpp:67
void SetChoices(const wxArrayString &choices)
Definition: Grid.cpp:362
ChoiceEditor * mChoiceEditor
Definition: LabelDialog.h:96
double f1() const
Grid * mGrid
Definition: LabelDialog.h:95
NumericEditor * mTimeEditor
Definition: LabelDialog.h:97
void SetRate(double rate)
Definition: Grid.cpp:149
wxString TrackName(int &index, const wxString &dflt=_("Label Track"))
bool LabelDialog::Validate ( )
overrideprivate

Definition at line 425 of file LabelDialog.cpp.

References mGrid.

Referenced by OnOK().

426 {
427  if (mGrid->IsCellEditControlShown()) {
428  mGrid->HideCellEditControl();
429  mGrid->SaveEditControlValue();
430  }
431 
432  return true;
433 }
Grid * mGrid
Definition: LabelDialog.h:95
void LabelDialog::WriteSize ( )
private

Definition at line 912 of file LabelDialog.cpp.

References gPrefs.

Referenced by OnCancel(), and OnOK().

912  {
913  wxSize sz = GetSize();
914  gPrefs->Write(wxT("/LabelEditor/Width"), sz.x);
915  gPrefs->Write(wxT("/LabelEditor/Height"), sz.y);
916  gPrefs->Flush();
917 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73

Member Data Documentation

ChoiceEditor* LabelDialog::mChoiceEditor
private

Definition at line 96 of file LabelDialog.h.

Referenced by PopulateLabels(), and TransferDataToWindow().

RowDataArray LabelDialog::mData
private
TrackFactory& LabelDialog::mFactory
private

Definition at line 102 of file LabelDialog.h.

Referenced by OnExport(), OnImport(), and TransferDataFromWindow().

NumericFormatId LabelDialog::mFormat
private

Definition at line 109 of file LabelDialog.h.

Referenced by OnUpdate(), and TransferDataToWindow().

NumericFormatId LabelDialog::mFreqFormat
private

Definition at line 109 of file LabelDialog.h.

Referenced by OnFreqUpdate(), and TransferDataToWindow().

NumericEditor* LabelDialog::mFrequencyEditor
private

Definition at line 98 of file LabelDialog.h.

Referenced by PopulateLabels(), and TransferDataToWindow().

Grid* LabelDialog::mGrid
private
int LabelDialog::mIndex { -1 }
private

Definition at line 105 of file LabelDialog.h.

Referenced by AddLabels(), and TransferDataFromWindow().

int LabelDialog::mInitialRow
private

Definition at line 111 of file LabelDialog.h.

Referenced by FindInitialRow(), and Show().

double LabelDialog::mRate
private

Definition at line 108 of file LabelDialog.h.

Referenced by TransferDataToWindow().

LabelTrack* LabelDialog::mSelectedTrack {}
private

Definition at line 104 of file LabelDialog.h.

Referenced by AddLabels(), and TransferDataFromWindow().

NumericEditor* LabelDialog::mTimeEditor
private

Definition at line 97 of file LabelDialog.h.

Referenced by PopulateLabels(), and TransferDataToWindow().

wxArrayString LabelDialog::mTrackNames
private
TrackList* LabelDialog::mTracks
private

Definition at line 103 of file LabelDialog.h.

Referenced by FindAllLabels(), OnSelectCell(), and TransferDataFromWindow().

ViewInfo* LabelDialog::mViewInfo
private

Definition at line 106 of file LabelDialog.h.

Referenced by FindInitialRow(), and OnSelectCell().


The documentation for this class was generated from the following files: