diff --git a/src/commands/CommandContext.cpp b/src/commands/CommandContext.cpp index 93098b3f5..9a9261af0 100644 --- a/src/commands/CommandContext.cpp +++ b/src/commands/CommandContext.cpp @@ -97,3 +97,42 @@ AudacityApp * CommandContext::GetApp() const AudacityProject *CommandContext::GetProject() const { return GetActiveProject();} +void CommandContext::StartArray() const +{ + if( pOutput ) + pOutput->StartArray(); +} +void CommandContext::EndArray() const +{ + if( pOutput ) + pOutput->EndArray(); +} +void CommandContext::StartStruct() const +{ + if( pOutput ) + pOutput->StartStruct(); +} +void CommandContext::EndStruct() const +{ + if( pOutput ) + pOutput->EndStruct(); +} +void CommandContext::AddItem(const wxString &value , const wxString &name ) const +{ + if( pOutput ) + pOutput->AddItem( value, name ); +} +void CommandContext::AddBool(const bool value , const wxString &name ) const +{ + if( pOutput ) + pOutput->AddItem( value, name ); +} +void CommandContext::AddItem(const double value , const wxString &name ) const +{ + if( pOutput ) + pOutput->AddItem( value, name ); +} + + + + diff --git a/src/commands/CommandContext.h b/src/commands/CommandContext.h index 03c45f4e9..155c52f4c 100644 --- a/src/commands/CommandContext.h +++ b/src/commands/CommandContext.h @@ -38,6 +38,16 @@ public: virtual void Status( const wxString & WXUNUSED(message) ) const; virtual void Error( const wxString & WXUNUSED(message) ) const; virtual void Progress( double WXUNUSED(d) ) const; + + // Output formatting... + void StartArray() const; + void EndArray() const; + void StartStruct() const; + void EndStruct() const; + void AddItem(const wxString &value , const wxString &name="" ) const; + void AddBool(const bool value , const wxString &name="" ) const; + void AddItem(const double value , const wxString &name="" ) const; + AudacityProject &project; std::unique_ptr pOutput; const wxEvent *pEvt; diff --git a/src/commands/CommandTargets.cpp b/src/commands/CommandTargets.cpp index 1e17e5395..753462e24 100644 --- a/src/commands/CommandTargets.cpp +++ b/src/commands/CommandTargets.cpp @@ -23,6 +23,46 @@ dialog, if necessary. #include "../ShuttleGui.h" #include "../Project.h" +void CommandMessageTarget::StartArray() +{ + wxString Padding; + Padding.Pad( mCounts.GetCount() *2 -2); + Update( wxString::Format( "%s%s[ ", ( mCounts.Last() > 0 ) ? ",\n" : "\n", Padding )); + mCounts.Last() += 1; + mCounts.push_back( 0 ); +} + +void CommandMessageTarget::EndArray(){ + if( mCounts.GetCount() > 1 ){ + mCounts.pop_back(); + } + Update( " ]" ); +} +void CommandMessageTarget::StartStruct(){ + wxString Padding; + Padding.Pad( mCounts.GetCount() *2 -2); + Update( wxString::Format( "%s%s{ ", ( mCounts.Last() > 0 ) ? ",\n" : "\n", Padding )); + mCounts.Last() += 1; + mCounts.push_back( 0 ); +} +void CommandMessageTarget::EndStruct(){ + if( mCounts.GetCount() > 1 ){ + mCounts.pop_back(); + } + Update( " }" ); +} +void CommandMessageTarget::AddItem(const wxString &value, const wxString &name){ + Update( wxString::Format( "%s%s%s\"%s\"", (mCounts.Last()>0)?", ":"", name, !name.IsEmpty()?":":"",value)); + mCounts.Last() += 1; +} +void CommandMessageTarget::AddItem(const bool value, const wxString &name){ + Update( wxString::Format( "%s%s%s%s", (mCounts.Last()>0)?", ":"", name, !name.IsEmpty()?":":"",value?"True":"False")); + mCounts.Last() += 1; +} +void CommandMessageTarget::AddItem(const double value, const wxString &name){ + Update( wxString::Format( "%s%s%s%g", (mCounts.Last()>0)?", ":"", name, !name.IsEmpty()?":":"",value)); + mCounts.Last() += 1; +} /// Dialog for long messages. @@ -114,7 +154,7 @@ void LongMessageDialog::AcceptText( const wxString & Text ) pDlg->Init(); pDlg->Show(); } - pDlg->mText->SetValue( pDlg->mText->GetValue( ) + "\n" + Text ); + pDlg->mText->SetValue( pDlg->mText->GetValue( ) + Text ); } diff --git a/src/commands/CommandTargets.h b/src/commands/CommandTargets.h index 423c58598..c7e93d127 100644 --- a/src/commands/CommandTargets.h +++ b/src/commands/CommandTargets.h @@ -38,6 +38,25 @@ public: virtual void Update(double completed) = 0; }; +/// Interface for objects that can receive (string) messages from a command +class CommandMessageTarget /* not final */ +{ +public: + CommandMessageTarget() {mCounts.push_back(0);} + virtual ~CommandMessageTarget() {} + virtual void Update(const wxString &message) = 0; + virtual void StartArray(); + virtual void EndArray(); + virtual void StartStruct(); + virtual void EndStruct(); + virtual void AddItem(const wxString &value , const wxString &name="" ); + virtual void AddItem(const bool value , const wxString &name="" ); + virtual void AddItem(const double value , const wxString &name="" ); + wxArrayInt mCounts; +}; + + + /// Used to ignore a command's progress updates class NullProgressTarget final : public CommandProgressTarget { @@ -62,13 +81,6 @@ public: } }; -/// Interface for objects that can receive (string) messages from a command -class CommandMessageTarget /* not final */ -{ -public: - virtual ~CommandMessageTarget() {} - virtual void Update(const wxString &message) = 0; -}; /// class ProgressToMessageTarget final : public CommandProgressTarget @@ -198,6 +210,7 @@ public: ~CommandOutputTarget() { } + // Lots of forwarding... void Progress(double completed) { if (mProgressTarget) @@ -213,6 +226,44 @@ public: if (mErrorTarget) mErrorTarget->Update(message); } + void StartArray() + { + if (mStatusTarget) + mStatusTarget->StartArray(); + } + void EndArray() + { + if (mStatusTarget) + mStatusTarget->EndArray(); + } + void StartStruct() + { + if (mStatusTarget) + mStatusTarget->StartStruct(); + } + void EndStruct() + { + if (mStatusTarget) + mStatusTarget->EndStruct(); + } + void AddItem(const wxString &value , const wxString &name="" ) + { + if (mStatusTarget) + mStatusTarget->AddItem( value, name ); + } + void AddItem(const bool value , const wxString &name="" ) + { + if (mStatusTarget) + mStatusTarget->AddItem( value, name ); + } + void AddItem(const double value , const wxString &name="" ) + { + if (mStatusTarget) + mStatusTarget->AddItem( value, name ); + } + + + }; class InteractiveOutputTarget : public CommandOutputTarget diff --git a/src/commands/GetInfoCommand.cpp b/src/commands/GetInfoCommand.cpp index e0ec0ed8b..0afed25f6 100644 --- a/src/commands/GetInfoCommand.cpp +++ b/src/commands/GetInfoCommand.cpp @@ -255,8 +255,14 @@ void GetInfoCommand::ExploreAdornments( const CommandContext &context, wxSize s = pWin->GetWindowBorderSize(); wxRect R( 2,32, R1.GetWidth() - s.GetWidth() * 2 -16, 22 ); - context.Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],", - depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "MenuBar" )); + context.StartArray(); + context.AddItem( depth ); + context.AddItem( R.GetLeft() ); + context.AddItem( R.GetTop() ); + context.AddItem( R.GetRight() ); + context.AddItem( R.GetBottom() ); + context.AddItem( "MenuBar" ); + context.EndArray(); } void GetInfoCommand::ExploreTrackPanel( const CommandContext &context, @@ -330,8 +336,14 @@ void GetInfoCommand::ExploreTrackPanel( const CommandContext &context, R.height -= (kTopMargin + kBottomMargin); R.SetPosition( R.GetPosition() + P ); - context.Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],", - depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "VRuler" )); + context.StartArray(); + context.AddItem( depth ); + context.AddItem( R.GetLeft() ); + context.AddItem( R.GetTop() ); + context.AddItem( R.GetRight() ); + context.AddItem( R.GetBottom() ); + context.AddItem( "VRuler" ); + context.EndArray(); } } } @@ -366,8 +378,16 @@ void GetInfoCommand::ExploreWindows( const CommandContext &context, continue; if( Name.IsEmpty() ) Name = wxString("*") + item->GetToolTipText(); - context.Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],", - depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), Name )); + + context.StartArray(); + context.AddItem( depth ); + context.AddItem( R.GetLeft() ); + context.AddItem( R.GetTop() ); + context.AddItem( R.GetRight() ); + context.AddItem( R.GetBottom() ); + context.AddItem( Name ); + context.EndArray(); + ExploreWindows( context, P, item, item->GetId(), depth+1 ); } } @@ -375,20 +395,27 @@ void GetInfoCommand::ExploreWindows( const CommandContext &context, bool GetInfoCommand::SendBoxesAsJson(const CommandContext &context) { - context.Status("Boxes"); + //context.Status("Boxes"); wxWindow * pWin = context.GetProject(); - context.Status( "[" ); + context.StartArray(); wxRect R = pWin->GetScreenRect(); //R.SetPosition( wxPoint(0,0) ); //wxString Name = pWin->GetName(); - context.Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],", - 0, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "Audacity Window" )); + context.StartArray(); + context.AddItem( 0 ); + context.AddItem( R.GetLeft() ); + context.AddItem( R.GetTop() ); + context.AddItem( R.GetRight() ); + context.AddItem( R.GetBottom() ); + context.AddItem( "Audacity Window" ); + context.EndArray( ); + ExploreAdornments( context, pWin->GetPosition()+wxSize( 6,-1), pWin, pWin->GetId(), 1 ); ExploreWindows( context, pWin->GetPosition()+wxSize( 6,-1), pWin, pWin->GetId(), 1 ); - context.Status( "]" ); + context.EndArray( ); return true; }