From 8f66c3603d3342f8f3f2774084634824f5af06e5 Mon Sep 17 00:00:00 2001 From: James Crook Date: Wed, 7 Jun 2017 15:58:06 +0100 Subject: [PATCH] Screen capture preference panels too. --- src/Menus.cpp | 3 +++ src/Screenshot.cpp | 9 +++++++ src/commands/ScreenshotCommand.cpp | 41 +++++++++++++++++++++++++----- src/commands/ScreenshotCommand.h | 1 + 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index 0ab9ba520..ec6297517 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -4231,6 +4231,9 @@ void AudacityProject::OnPreferences() { GlobalPrefsDialog dialog(this /* parent */ ); + if( ScreenshotCommand::MayCapture( &dialog ) ) + return; + if (!dialog.ShowModal()) { // Canceled return; diff --git a/src/Screenshot.cpp b/src/Screenshot.cpp index 38a299a26..566c27538 100644 --- a/src/Screenshot.cpp +++ b/src/Screenshot.cpp @@ -72,6 +72,7 @@ class ScreenFrame final : public wxFrame void OnCaptureToolbars(wxCommandEvent & event); void OnCaptureMenus(wxCommandEvent & event); void OnCaptureEffects(wxCommandEvent & event); + void OnCapturePreferences(wxCommandEvent & event); void OnCaptureSelectionBar(wxCommandEvent & event); void OnCaptureTools(wxCommandEvent & event); void OnCaptureTransport(wxCommandEvent & event); @@ -182,6 +183,7 @@ enum IdCaptureToolbars, IdCaptureMenus, IdCaptureEffects, + IdCapturePreferences, IdCaptureSelectionBar, IdCaptureTools, IdCaptureTransport, @@ -228,6 +230,7 @@ BEGIN_EVENT_TABLE(ScreenFrame, wxFrame) EVT_BUTTON(IdCaptureToolbars, ScreenFrame::OnCaptureToolbars) EVT_BUTTON(IdCaptureMenus, ScreenFrame::OnCaptureMenus) EVT_BUTTON(IdCaptureEffects, ScreenFrame::OnCaptureEffects) + EVT_BUTTON(IdCapturePreferences, ScreenFrame::OnCapturePreferences) EVT_BUTTON(IdCaptureSelectionBar, ScreenFrame::OnCaptureSelectionBar) EVT_BUTTON(IdCaptureTools, ScreenFrame::OnCaptureTools) EVT_BUTTON(IdCaptureTransport, ScreenFrame::OnCaptureTransport) @@ -392,6 +395,7 @@ void ScreenFrame::PopulateOrExchange(ShuttleGui & S) #ifdef EXPERIMENTAL_DOCS_AUTOMATION S.Id(IdCaptureMenus).AddButton(_("All Menus")); S.Id(IdCaptureEffects).AddButton(_("All Effects")); + S.Id(IdCapturePreferences).AddButton(_("All Preferences")); #endif } S.EndHorizontalLay(); @@ -629,6 +633,11 @@ void ScreenFrame::OnCaptureEffects(wxCommandEvent & WXUNUSED(event)) DoCapture(wxT("effects")); } +void ScreenFrame::OnCapturePreferences(wxCommandEvent & WXUNUSED(event)) +{ + DoCapture(wxT("preferences")); +} + void ScreenFrame::OnCaptureSelectionBar(wxCommandEvent & WXUNUSED(event)) { DoCapture(wxT("selectionbar")); diff --git a/src/commands/ScreenshotCommand.cpp b/src/commands/ScreenshotCommand.cpp index df7b4d0f4..1c18c6b5b 100644 --- a/src/commands/ScreenshotCommand.cpp +++ b/src/commands/ScreenshotCommand.cpp @@ -42,6 +42,7 @@ project window. #include "../toolbars/ToolsToolBar.h" #include "../toolbars/TranscriptionToolBar.h" #include "../widgets/Ruler.h" +#include "../Prefs.h" #if defined(__WXMAC__) && !wxCHECK_VERSION(3, 0, 0) // @@ -376,16 +377,13 @@ void ScreenshotCommand::CaptureWindowOnIdle( wxWindow * pWin ) wxPoint Pos = pDlg->GetScreenPosition(); wxSize Siz = pDlg->GetSize(); - wxString Name = mDirToWriteTo; wxString Title = pDlg->GetTitle(); // Remove '/' from "Sliding Time Scale/Pitch Shift..." // and any other effects that have illegal filename chanracters. Title.Replace( "/", "" ); - Name.Replace( "effects000", Title ); - - int x = 0, y = 0; - int width, height; + Title.Replace( ":", "" ); + wxString Name = mDirToWriteTo + Title + ".png"; wxLogDebug("Taking screenshot of window %s (%i,%i,%i,%i)", Name, Pos.x, Pos.y, Siz.x, Siz.y ); @@ -400,13 +398,39 @@ void ScreenshotCommand::CaptureWindowOnIdle( wxWindow * pWin ) pDlg->GetEventHandler()->AddPendingEvent( Evt ); } +void ScreenshotCommand::CapturePreferences( AudacityProject * pProject, const wxString &fileName ){ + fileName;//compiler food. + CommandManager * pMan = pProject->GetCommandManager(); + + // Yucky static variables. Is there a better way? The problem is that we need the + // idle callback to know more about what to do. + mDirToWriteTo = fileName.BeforeLast('\\') + "\\"; + mpShooter = this; + const int nPrefsPages = 19; + + for( int i=0;iWrite(wxT("/Prefs/PrefsCategory"), (long)i); + gPrefs->Flush(); + wxString Command = "Preferences"; + if( !pMan->HandleTextualCommand( Command, AlwaysEnabledFlag, AlwaysEnabledFlag ) ) + { + wxLogDebug("Command %s not found", Command ); + } + // This sleep is not needed, but gives user a chance to see the + // dialogs as they whizz by. + wxMilliSleep( 200 ); + } +} + void ScreenshotCommand::CaptureEffects( AudacityProject * pProject, const wxString &fileName ){ fileName;//compiler food. CommandManager * pMan = pProject->GetCommandManager(); wxString Str; // Yucky static variables. Is there a better way? The problem is that we need the // idle callback to know more about what to do. - mDirToWriteTo = fileName; + mDirToWriteTo = fileName.BeforeLast('/') + "/"; mpShooter = this; #define TRICKY_CAPTURE @@ -523,6 +547,7 @@ void ScreenshotCommandType::BuildSignature(CommandSignature &signature) captureModeValidator->AddOption(wxT("toolbars")); captureModeValidator->AddOption(wxT("menus")); captureModeValidator->AddOption(wxT("effects")); + captureModeValidator->AddOption(wxT("preferences")); captureModeValidator->AddOption(wxT("selectionbar")); captureModeValidator->AddOption(wxT("tools")); captureModeValidator->AddOption(wxT("transport")); @@ -708,6 +733,10 @@ bool ScreenshotCommand::Apply(CommandExecutionContext context) { CaptureEffects(context.GetProject(), fileName); } + else if (captureMode.IsSameAs(wxT("preferences"))) + { + CapturePreferences(context.GetProject(), fileName); + } else if (captureMode.IsSameAs(wxT("selectionbar"))) { CaptureDock(context.GetProject()->GetToolManager()->GetBotDock(), fileName); diff --git a/src/commands/ScreenshotCommand.h b/src/commands/ScreenshotCommand.h index 464ac90dc..d18659fa5 100644 --- a/src/commands/ScreenshotCommand.h +++ b/src/commands/ScreenshotCommand.h @@ -49,6 +49,7 @@ private: void CaptureDock(wxWindow *win, const wxString &fileName); void CaptureMenus(wxMenuBar*pBar, const wxString &fileName); void CaptureEffects( AudacityProject * pProject, const wxString &fileName ); + void CapturePreferences( AudacityProject * pProject, const wxString &fileName ); void Capture(const wxString &basename, wxWindow *window, int x, int y, int width, int height,