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

DependencyDialog shows dependencies of an AudacityProject on AliasedFile s. More...

Inheritance diagram for DependencyDialog:
wxDialogWrapper wxTabTraversalWrapper< wxDialog >

Public Member Functions

 DependencyDialog (wxWindow *parent, wxWindowID id, AudacityProject *project, AliasedFileArray &aliasedFiles, bool isSaving)
 
- 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)
 

Private Member Functions

void PopulateList ()
 
void PopulateOrExchange (ShuttleGui &S)
 
void OnCancel (wxCommandEvent &evt)
 
void OnCopySelectedFiles (wxCommandEvent &evt)
 
void OnList (wxListEvent &evt)
 
void OnSize (wxSizeEvent &evt)
 
void OnNo (wxCommandEvent &evt)
 
void OnYes (wxCommandEvent &evt)
 
void OnRightClick (wxListEvent &evt)
 
void OnCopyToClipboard (wxCommandEvent &evt)
 
void SaveFutureActionChoice ()
 

Private Attributes

AudacityProjectmProject
 
AliasedFileArraymAliasedFiles
 
bool mIsSaving
 
bool mHasMissingFiles
 
bool mHasNonMissingFiles
 
wxStaticText * mMessageStaticText
 
wxListCtrl * mFileListCtrl
 
wxButton * mCopySelectedFilesButton
 
wxButton * mCopyAllFilesButton
 
wxChoice * mFutureActionChoice
 

Detailed Description

DependencyDialog shows dependencies of an AudacityProject on AliasedFile s.

Definition at line 245 of file Dependencies.cpp.

Constructor & Destructor Documentation

DependencyDialog::DependencyDialog ( wxWindow *  parent,
wxWindowID  id,
AudacityProject project,
AliasedFileArray aliasedFiles,
bool  isSaving 
)

Member Function Documentation

void DependencyDialog::OnCancel ( wxCommandEvent &  evt)
private

Definition at line 562 of file Dependencies.cpp.

References _(), AudacityMessageBox(), and mIsSaving.

563 {
564  if (mIsSaving)
565  {
566  int ret = AudacityMessageBox(
567  _("If you proceed, your project will not be saved to disk. Is this what you want?"),
568  _("Cancel Save"), wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT, this);
569  if (ret != wxYES)
570  return;
571  }
572 
573  EndModal(wxID_CANCEL);
574 }
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
_("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
void DependencyDialog::OnCopySelectedFiles ( wxCommandEvent &  evt)
private

Definition at line 504 of file Dependencies.cpp.

References mAliasedFiles, mFileListCtrl, mHasNonMissingFiles, mProject, PopulateList(), RemoveDependencies(), and SaveFutureActionChoice().

505 {
506  AliasedFileArray aliasedFilesToDelete, remainingAliasedFiles;
507 
508  long i = 0;
509  for( const auto &file : mAliasedFiles ) {
510  if (mFileListCtrl->GetItemState(i, wxLIST_STATE_SELECTED))
511  aliasedFilesToDelete.push_back( file );
512  else
513  remainingAliasedFiles.push_back( file );
514  ++i;
515  }
516 
517  // provides STRONG-GUARANTEE
518  RemoveDependencies(mProject, aliasedFilesToDelete);
519 
520  // COMMIT OPERATIONS needing NOFAIL-GUARANTEE:
521  mAliasedFiles.swap( remainingAliasedFiles );
522  PopulateList();
523 
524  if (mAliasedFiles.empty() || !mHasNonMissingFiles)
525  {
527  EndModal(wxID_NO); // Don't need to remove dependencies
528  }
529 }
static void RemoveDependencies(AudacityProject *project, AliasedFileArray &aliasedFiles)
std::list< AliasedFile > AliasedFileArray
Definition: Dependencies.h:53
void SaveFutureActionChoice()
wxListCtrl * mFileListCtrl
AudacityProject * mProject
AliasedFileArray & mAliasedFiles
void DependencyDialog::OnCopyToClipboard ( wxCommandEvent &  evt)
private

Definition at line 539 of file Dependencies.cpp.

References Internat::FormatSize(), mAliasedFiles, and safenew.

540 {
541  static_cast<void>(evt);
542  wxString Files = "";
543  for (const auto &aliasedFile : mAliasedFiles) {
544  const wxFileName & fileName = aliasedFile.mFileName;
545  wxLongLong byteCount = (aliasedFile.mByteCount * 124) / 100;
546  bool bOriginalExists = aliasedFile.mbOriginalExists;
547  // All fields quoted, as e.g. size may contain a comma in the number.
548  Files += wxString::Format( "\"%s\", \"%s\", \"%s\"\n",
549  fileName.GetFullPath(),
550  Internat::FormatSize( byteCount),
551  bOriginalExists ? "OK":"Missing" );
552  }
553 
554  // copy data onto clipboard
555  if (wxTheClipboard->Open()) {
556  // Clipboard owns the data you give it
557  wxTheClipboard->SetData(safenew wxTextDataObject(Files));
558  wxTheClipboard->Close();
559  }
560 }
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:191
#define safenew
Definition: Audacity.h:230
AliasedFileArray & mAliasedFiles
void DependencyDialog::OnList ( wxListEvent &  evt)
private

Definition at line 462 of file Dependencies.cpp.

References mCopySelectedFilesButton, and mFileListCtrl.

463 {
465  return;
466 
467  wxString itemStr = evt.GetText();
468  if (evt.GetData() == 0)
469  // This list item is one of mAliasedFiles for which
470  // the original is missing, i.e., moved or deleted.
471  // wxListCtrl does not provide for items that are not
472  // allowed to be selected, so always deselect these items.
473  mFileListCtrl->SetItemState(evt.GetIndex(), 0, wxLIST_STATE_SELECTED); // Deselect.
474 
475  mCopySelectedFilesButton->Enable(
476  mFileListCtrl->GetSelectedItemCount() > 0);
477 }
wxListCtrl * mFileListCtrl
wxButton * mCopySelectedFilesButton
void DependencyDialog::OnNo ( wxCommandEvent &  evt)
private

Definition at line 492 of file Dependencies.cpp.

References SaveFutureActionChoice().

493 {
495  EndModal(wxID_NO);
496 }
void SaveFutureActionChoice()
void DependencyDialog::OnRightClick ( wxListEvent &  evt)
private

Definition at line 531 of file Dependencies.cpp.

References _(), and CopyNamesToClipboardID.

532 {
533  static_cast<void>(event);
534  wxMenu menu;
535  menu.Append(CopyNamesToClipboardID, _("&Copy Names to Clipboard"));
536  PopupMenu(&menu);
537 }
_("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
void DependencyDialog::OnSize ( wxSizeEvent &  evt)
private

Definition at line 479 of file Dependencies.cpp.

References mFileListCtrl.

480 {
481  int fileListCtrlWidth, fileListCtrlHeight;
482  mFileListCtrl->GetSize(&fileListCtrlWidth, &fileListCtrlHeight);
483 
484  // File path is column 0. File size is column 1.
485  // File size column is always 120 px wide.
486  // Also subtract 8 from file path column width for borders.
487  mFileListCtrl->SetColumnWidth(0, fileListCtrlWidth - 120 - 8);
488  mFileListCtrl->SetColumnWidth(1, 120);
489  wxDialogWrapper::OnSize(evt);
490 }
wxListCtrl * mFileListCtrl
void DependencyDialog::OnYes ( wxCommandEvent &  evt)
private

Definition at line 498 of file Dependencies.cpp.

References SaveFutureActionChoice().

499 {
501  EndModal(wxID_YES);
502 }
void SaveFutureActionChoice()
void DependencyDialog::PopulateList ( )
private

Definition at line 421 of file Dependencies.cpp.

References _(), Internat::FormatSize(), kExtraMsgForMissingFiles(), kStdMsg(), mAliasedFiles, mCopyAllFilesButton, mFileListCtrl, mHasMissingFiles, mHasNonMissingFiles, and mMessageStaticText.

Referenced by OnCopySelectedFiles(), and PopulateOrExchange().

422 {
423  mFileListCtrl->DeleteAllItems();
424 
425  mHasMissingFiles = false;
426  mHasNonMissingFiles = false;
427  long i = 0;
428  for (const auto &aliasedFile : mAliasedFiles) {
429  const wxFileName &fileName = aliasedFile.mFileName;
430  wxLongLong byteCount = (aliasedFile.mByteCount * 124) / 100;
431  bool bOriginalExists = aliasedFile.mbOriginalExists;
432 
433  if (bOriginalExists)
434  {
435  mFileListCtrl->InsertItem(i, fileName.GetFullPath());
436  mHasNonMissingFiles = true;
437  mFileListCtrl->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
438  }
439  else
440  {
441  mFileListCtrl->InsertItem(i,
442  wxString::Format( _("MISSING %s"), fileName.GetFullPath() ) );
443  mHasMissingFiles = true;
444  mFileListCtrl->SetItemState(i, 0, wxLIST_STATE_SELECTED); // Deselect.
445  mFileListCtrl->SetItemTextColour(i, *wxRED);
446  }
447  mFileListCtrl->SetItem(i, 1, Internat::FormatSize(byteCount));
448  mFileListCtrl->SetItemData(i, long(bOriginalExists));
449 
450  ++i;
451  }
452 
453  wxString msg = kStdMsg();
454  if (mHasMissingFiles)
455  msg += kExtraMsgForMissingFiles();
456  mMessageStaticText->SetLabel(msg);
457 
460 }
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:191
wxListCtrl * mFileListCtrl
_("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
static const wxString kStdMsg()
static const wxString kExtraMsgForMissingFiles()
wxStaticText * mMessageStaticText
wxButton * mCopyAllFilesButton
AliasedFileArray & mAliasedFiles
void DependencyDialog::PopulateOrExchange ( ShuttleGui S)
private

Definition at line 348 of file Dependencies.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddChoice(), ShuttleGuiBase::AddListControlReportMode(), ShuttleGuiBase::AddVariableText(), CopySelectedFilesButtonID, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndVerticalLay(), FileListID, FutureActionChoiceID, ShuttleGui::Id(), kStdMsg(), mCopyAllFilesButton, mCopySelectedFilesButton, mFileListCtrl, mFutureActionChoice, mHasMissingFiles, mIsSaving, mMessageStaticText, PopulateList(), ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartStatic(), and ShuttleGuiBase::StartVerticalLay().

349 {
350  S.SetBorder(5);
351  S.StartVerticalLay();
352  {
354 
355  S.StartStatic(_("Project Dependencies"),1);
356  {
358  mFileListCtrl->InsertColumn(0, _("Audio File"));
359  mFileListCtrl->SetColumnWidth(0, 220);
360  mFileListCtrl->InsertColumn(1, _("Disk Space"));
361  mFileListCtrl->SetColumnWidth(1, 120);
362  PopulateList();
363 
366  _("Copy Selected Files"),
367  wxALIGN_LEFT);
368  mCopySelectedFilesButton->Enable(
369  mFileListCtrl->GetSelectedItemCount() > 0);
370  mCopySelectedFilesButton->SetDefault();
371  mCopySelectedFilesButton->SetFocus();
372  }
373  S.EndStatic();
374 
375  S.StartHorizontalLay(wxALIGN_CENTRE,0);
376  {
377  if (mIsSaving) {
378  S.Id(wxID_CANCEL).AddButton(_("Cancel Save"));
379  S.Id(wxID_NO).AddButton(_("Save Without Copying"));
380  }
381  else
382  S.Id(wxID_NO).AddButton(_("Do Not Copy"));
383 
385  S.Id(wxID_YES).AddButton(_("Copy All Files (Safer)"));
386 
387  // Enabling mCopyAllFilesButton is also done in PopulateList,
388  // but at its call above, mCopyAllFilesButton does not yet exist.
390  }
391  S.EndHorizontalLay();
392 
393  if (mIsSaving)
394  {
395  S.StartHorizontalLay(wxALIGN_LEFT,0);
396  {
397  wxArrayString choices;
398  /*i18n-hint: One of the choices of what you want Audacity to do when
399  * Audacity finds a project depends on another file.*/
400  choices.Add(_("Ask me"));
401  choices.Add(_("Always copy all files (safest)"));
402  choices.Add(_("Never copy any files"));
405  _("Whenever a project depends on other files:"),
406  _("Ask me"), &choices);
407  }
408  S.EndHorizontalLay();
409  } else
410  {
411  mFutureActionChoice = NULL;
412  }
413  }
414  S.EndVerticalLay();
415  Layout();
416  Fit();
417  SetMinSize(GetSize());
418  Center();
419 }
void EndHorizontalLay()
void EndVerticalLay()
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
wxListCtrl * AddListControlReportMode()
Definition: ShuttleGui.cpp:689
wxChoice * AddChoice(const wxString &Prompt, const wxString &Selected, const wxArrayString *pChoices)
Definition: ShuttleGui.cpp:371
ShuttleGui & Id(int id)
wxChoice * mFutureActionChoice
wxListCtrl * mFileListCtrl
_("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
static const wxString kStdMsg()
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
wxButton * mCopySelectedFilesButton
wxStaticText * mMessageStaticText
wxButton * mCopyAllFilesButton
void SetBorder(int Border)
Definition: ShuttleGui.h:286
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
void StartVerticalLay(int iProp=1)
void DependencyDialog::SaveFutureActionChoice ( )
private

Definition at line 576 of file Dependencies.cpp.

References gPrefs, and mFutureActionChoice.

Referenced by OnCopySelectedFiles(), OnNo(), and OnYes().

577 {
579  {
580  wxString savePref;
581  int sel = mFutureActionChoice->GetSelection();
582  switch (sel)
583  {
584  case 1: savePref = wxT("copy"); break;
585  case 2: savePref = wxT("never"); break;
586  default: savePref = wxT("ask");
587  }
588  gPrefs->Write(wxT("/FileFormats/SaveProjectWithDependencies"),
589  savePref);
590  gPrefs->Flush();
591  }
592 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxChoice * mFutureActionChoice

Member Data Documentation

AliasedFileArray& DependencyDialog::mAliasedFiles
private

Definition at line 273 of file Dependencies.cpp.

Referenced by OnCopySelectedFiles(), OnCopyToClipboard(), and PopulateList().

wxButton* DependencyDialog::mCopyAllFilesButton
private

Definition at line 281 of file Dependencies.cpp.

Referenced by PopulateList(), and PopulateOrExchange().

wxButton* DependencyDialog::mCopySelectedFilesButton
private

Definition at line 280 of file Dependencies.cpp.

Referenced by OnList(), and PopulateOrExchange().

wxListCtrl* DependencyDialog::mFileListCtrl
private
wxChoice* DependencyDialog::mFutureActionChoice
private

Definition at line 282 of file Dependencies.cpp.

Referenced by PopulateOrExchange(), and SaveFutureActionChoice().

bool DependencyDialog::mHasMissingFiles
private

Definition at line 275 of file Dependencies.cpp.

Referenced by PopulateList(), and PopulateOrExchange().

bool DependencyDialog::mHasNonMissingFiles
private

Definition at line 276 of file Dependencies.cpp.

Referenced by OnCopySelectedFiles(), and PopulateList().

bool DependencyDialog::mIsSaving
private

Definition at line 274 of file Dependencies.cpp.

Referenced by OnCancel(), and PopulateOrExchange().

wxStaticText* DependencyDialog::mMessageStaticText
private

Definition at line 278 of file Dependencies.cpp.

Referenced by PopulateList(), and PopulateOrExchange().

AudacityProject* DependencyDialog::mProject
private

Definition at line 272 of file Dependencies.cpp.

Referenced by OnCopySelectedFiles().


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