Skip to content

Commit

Permalink
fixup! Toolbar : Toggle all tools with hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Nov 8, 2023
1 parent 3a8c2fd commit 34a7926
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
7 changes: 5 additions & 2 deletions include/GafferUI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ class GAFFERUI_API View : public Gaffer::Node

private :

void toolsChildAdded( Gaffer::GraphComponent *child ) const;
void toolPlugSet( Gaffer::Plug *plug ) const;
void toolsChildAdded( Gaffer::GraphComponent *child );
void toolPlugSet( Gaffer::Plug *plug );

using ToolPlugSetMap = std::unordered_map<std::string, Gaffer::Signals::ScopedConnection>;
ToolPlugSetMap m_toolPlugSetConnections;

ViewportGadgetPtr m_viewportGadget;
Gaffer::ContextPtr m_context;
Expand Down
20 changes: 9 additions & 11 deletions src/GafferUI/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,13 @@ void View::registerView( const IECore::TypeId nodeType, const std::string &plugP
namedCreators()[nodeType].push_back( RegexAndCreator( boost::regex( plugPath ), creator ) );
}

void View::toolsChildAdded( Gaffer::GraphComponent *child ) const
void View::toolsChildAdded( Gaffer::GraphComponent *child )
{
auto tool = static_cast<Tool *>( child ); // Type guaranteed by `ToolContainer::acceptsChild()`
tool->plugSetSignal().connect( boost::bind( &View::toolPlugSet, this, ::_1 ) );
m_toolPlugSetConnections[tool->getName()] = tool->plugSetSignal().connect( boost::bind( &View::toolPlugSet, this, ::_1 ) );
}

void View::toolPlugSet( Gaffer::Plug *plug ) const
void View::toolPlugSet( Gaffer::Plug *plug )
{
auto tool = plug->ancestor<Tool>();
if( plug != tool->activePlug() )
Expand All @@ -279,23 +279,21 @@ void View::toolPlugSet( Gaffer::Plug *plug ) const
{
if( t != tool && exclusive( t.get() ) )
{
// Prevent re-entering `toolPlugSet()` when disabling other exclusive tools
Signals::BlockedConnection toolPlugSetBlocker( m_toolPlugSetConnections[t->getName()] );
t->activePlug()->setValue( false );
}
}
}

bool exclusivePlugActive = false;
for( auto &t : Tool::Range( *tools() ) )
{
exclusivePlugActive |= ( exclusive( t.get() ) && t->activePlug()->getValue() );
}
if( !exclusivePlugActive )
else
{
for( auto &t : Tool::Range( *tools() ) )
{
auto order = Metadata::value<IntData>( t.get(), "order" );
if( order && order->readable() == 0 )
if( order && order->readable() == 0 )
{
// Prevent re-entering `toolPlugSet()` when enabling the default tool
Signals::BlockedConnection toolPlugSetBlocker( m_toolPlugSetConnections[t->getName()] );
t->activePlug()->setValue( true );
break;
}
Expand Down

0 comments on commit 34a7926

Please sign in to comment.