1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

Merge pull request #164 from abb128/master

Implement toolbar edit mode
This commit is contained in:
Sol Fisher Romanoff 2021-07-15 21:39:49 +03:00 committed by GitHub
commit af2b77bf47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 19 deletions

View File

@ -926,6 +926,9 @@ AdornedRulerPanel::AdornedRulerPanel(AudacityProject* project,
mTracks = &TrackList::Get( *project ); mTracks = &TrackList::Get( *project );
mIsSnapped = false; mIsSnapped = false;
mEditMode = gPrefs->Read(wxT("/GUI/Toolbars/EditMode"), true);
mGrabber = nullptr;
mIsRecording = false; mIsRecording = false;
@ -969,7 +972,13 @@ void AdornedRulerPanel::Refresh( bool eraseBackground, const wxRect *rect )
void AdornedRulerPanel::UpdatePrefs() void AdornedRulerPanel::UpdatePrefs()
{ {
if (mNeedButtonUpdate) { bool mode = gPrefs->Read(wxT("/GUI/Toolbars/EditMode"), true);
if ( mode != mEditMode )
{
mEditMode = mode;
ReCreateButtons();
}else if (mNeedButtonUpdate) {
// Visit this block once only in the lifetime of this panel // Visit this block once only in the lifetime of this panel
mNeedButtonUpdate = false; mNeedButtonUpdate = false;
// Do this first time setting of button status texts // Do this first time setting of button status texts
@ -1009,6 +1018,12 @@ void AdornedRulerPanel::ReCreateButtons()
button = nullptr; button = nullptr;
} }
if ( mGrabber )
{
mGrabber->Destroy();
mGrabber = nullptr;
}
size_t iButton = 0; size_t iButton = 0;
// Make the short row of time ruler pushbottons. // Make the short row of time ruler pushbottons.
// Don't bother with sizers. Their sizes and positions are fixed. // Don't bother with sizers. Their sizes and positions are fixed.
@ -1017,12 +1032,14 @@ void AdornedRulerPanel::ReCreateButtons()
wxPoint position( 1, 0 ); wxPoint position( 1, 0 );
Grabber * pGrabber = safenew Grabber(this, this->GetId()); if ( mEditMode )
pGrabber->SetAsSpacer( true ); {
//pGrabber->SetSize( 10, 27 ); // default is 10,27 mGrabber = safenew Grabber(this, this->GetId());
pGrabber->SetPosition( position ); mGrabber->SetAsSpacer( true );
//mGrabber->SetSize( 10, 27 ); // default is 10,27
position.x = 12; mGrabber->SetPosition( position );
position.x = 12;
}else position.x = 0;
auto size = theTheme.ImageSize( bmpRecoloredUpSmall ); auto size = theTheme.ImageSize( bmpRecoloredUpSmall );
size.y = std::min(size.y, GetRulerHeight(false)); size.y = std::min(size.y, GetRulerHeight(false));

View File

@ -13,6 +13,7 @@
#include "CellularPanel.h" #include "CellularPanel.h"
#include "widgets/Ruler.h" // member variable #include "widgets/Ruler.h" // member variable
#include "widgets/Grabber.h" // mGrabber
#include "Prefs.h" #include "Prefs.h"
#include "ViewInfo.h" // for PlayRegion #include "ViewInfo.h" // for PlayRegion
@ -142,6 +143,9 @@ private:
double mQuickPlayPos; double mQuickPlayPos;
bool mIsSnapped; bool mIsSnapped;
bool mEditMode;
Grabber *mGrabber;
PlayRegion mOldPlayRegion; PlayRegion mOldPlayRegion;

View File

@ -5,6 +5,7 @@
#include "../commands/CommandContext.h" #include "../commands/CommandContext.h"
#include "../commands/CommandManager.h" #include "../commands/CommandManager.h"
#include "../toolbars/ToolManager.h" #include "../toolbars/ToolManager.h"
#include "../CommonCommandFlags.h"
/// Namespace for functions for View Toolbar menu /// Namespace for functions for View Toolbar menu
namespace ToolbarActions { namespace ToolbarActions {
@ -21,6 +22,19 @@ void OnResetToolBars(const CommandContext &context)
ToolManager::OnResetToolBars(context); ToolManager::OnResetToolBars(context);
} }
void OnEditMode(const CommandContext &context)
{
auto &project = context.project;
auto &commandManager = CommandManager::Get( project );
bool checked = !gPrefs->Read(wxT("/GUI/Toolbars/EditMode"), true);
gPrefs->Write(wxT("/GUI/Toolbars/EditMode"), checked);
gPrefs->Flush();
commandManager.Check(wxT("EditMode"), checked);
wxTheApp->AddPendingEvent(wxCommandEvent{ EVT_PREFS_UPDATE });
}
}; // struct Handler }; // struct Handler
@ -48,8 +62,11 @@ BaseItemSharedPtr ToolbarsMenu()
( FinderScope{ findCommandHandler }, ( FinderScope{ findCommandHandler },
Section( wxT("Toolbars"), Section( wxT("Toolbars"),
Menu( wxT("Toolbars"), XXO("&Toolbars"), Menu( wxT("Toolbars"), XXO("&Toolbars"),
Section( "Reset", Section( "Manage",
/* i18n-hint: (verb)*/ /* i18n-hint: (verb)*/
Command( wxT("EditMode"), XXO("Edit &Mode (on/off)"),
FN(OnEditMode), AudioIONotBusyFlag(),
Options{}.CheckTest( wxT("/GUI/Toolbars/EditMode"), true ) ),
Command( wxT("ResetToolbars"), XXO("Reset Toolb&ars"), Command( wxT("ResetToolbars"), XXO("Reset Toolb&ars"),
FN(OnResetToolBars), AlwaysEnabledFlag ) FN(OnResetToolBars), AlwaysEnabledFlag )
), ),

View File

@ -346,6 +346,7 @@ ToolBar::ToolBar( AudacityProject &project,
mHSizer = NULL; mHSizer = NULL;
mVisible = false; mVisible = false;
mPositioned = false; mPositioned = false;
mEditMode = gPrefs->Read(wxT("/GUI/Toolbars/EditMode"), true);
mGrabber = NULL; mGrabber = NULL;
mResizer = NULL; mResizer = NULL;
@ -538,10 +539,14 @@ void ToolBar::ReCreateButtons()
// Create the main sizer // Create the main sizer
auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL); auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
// Create the grabber and add it to the main sizer // Grabber is created only when editing, or when it's undocked
mGrabber = safenew Grabber(this, mType); // (as otherwise the undocked toolbar can't be moved around)
ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1); if (mEditMode || !IsDocked())
{
// Create the grabber and add it to the main sizer
mGrabber = safenew Grabber(this, mType);
ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1);
}
// Use a box sizer for laying out controls // Use a box sizer for laying out controls
ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND); ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
@ -549,7 +554,7 @@ void ToolBar::ReCreateButtons()
Populate(); Populate();
// Add some space for the resize border // Add some space for the resize border
if (IsResizable()) if (mEditMode && IsResizable())
{ {
// Create the resizer and add it to the main sizer // Create the resizer and add it to the main sizer
mResizer = safenew ToolBarResizer(this); mResizer = safenew ToolBarResizer(this);
@ -621,6 +626,21 @@ void ToolBar::UpdatePrefs()
} }
#endif #endif
bool updated = false;
bool editing = gPrefs->Read(wxT("/GUI/Toolbars/EditMode"), true);
if ( editing != mEditMode )
{
mEditMode = editing;
updated = true;
}
if ( updated )
{
ReCreateButtons();
Updated();
}
return; return;
} }
@ -632,6 +652,15 @@ ToolDock *ToolBar::GetDock()
return dynamic_cast<ToolDock*>(GetParent()); return dynamic_cast<ToolDock*>(GetParent());
} }
//
// Returns whether or not edit mode is enabled
//
bool ToolBar::GetEditMode()
{
return mEditMode;
}
// //
// Toggle the docked/floating state // Toggle the docked/floating state
// //
@ -640,13 +669,16 @@ void ToolBar::SetDocked( ToolDock *dock, bool pushed )
// Remember it // Remember it
// mDock = dock; // mDock = dock;
// Change the tooltip of the grabber if ( mGrabber )
{
// Change the tooltip of the grabber
#if wxUSE_TOOLTIPS #if wxUSE_TOOLTIPS
mGrabber->SetToolTip( GetTitle() ); mGrabber->SetToolTip( GetTitle() );
#endif #endif
// Set the grabber button state // Set the grabber button state
mGrabber->PushButton( pushed ); mGrabber->PushButton( pushed );
}
if (mResizer) if (mResizer)
{ {

View File

@ -121,6 +121,7 @@ class AUDACITY_DLL_API ToolBar /* not final */
TranslatableString GetLabel(); TranslatableString GetLabel();
wxString GetSection(); wxString GetSection();
ToolDock *GetDock(); ToolDock *GetDock();
bool GetEditMode();
private: private:
void SetLabel(const wxString & label) override; void SetLabel(const wxString & label) override;
@ -249,6 +250,7 @@ public:
bool mVisible; bool mVisible;
bool mResizable; bool mResizable;
bool mPositioned; // true if position floating determined. bool mPositioned; // true if position floating determined.
bool mEditMode;
public: public:

View File

@ -1177,7 +1177,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
DoneDragging(); DoneDragging();
return; return;
} }
else if( mDragDock && !event.ShiftDown() ) else if( mDragDock && !event.ShiftDown() && mDragBar->GetEditMode() )
{ {
// Trip over...everyone ashore that's going ashore... // Trip over...everyone ashore that's going ashore...
mDragDock->Dock( mDragBar, true, mDragBefore ); mDragDock->Dock( mDragBar, true, mDragBefore );
@ -1249,7 +1249,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
dock = mBotDock; dock = mBotDock;
// Looks like we have a winner... // Looks like we have a winner...
if( dock ) if( dock && mDragBar->GetEditMode() )
{ {
wxPoint p; wxPoint p;
wxRect r; wxRect r;