Skip to content

Commit

Permalink
#6146: Special toggle behaviour for controls in floating property panels
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 31, 2022
1 parent b953aab commit 7029b15
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
54 changes: 51 additions & 3 deletions radiant/ui/mainframe/AuiLayout.cpp
Expand Up @@ -421,6 +421,14 @@ void AuiLayout::focusControl(const std::string& controlName)
// Focus matching controls in the property notebook
_propertyNotebook->focusControl(controlName);

// Ensure the property panel is visible when focusing a tab
auto& propertyPane = _auiMgr.GetPane(PROPERTIES_PANEL);
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}

// Unset the focus of any wxPanels in floating windows
for (auto p = _panes.begin(); p != _panes.end(); ++p)
{
Expand All @@ -444,6 +452,46 @@ void AuiLayout::focusControl(const std::string& controlName)
}
}

void AuiLayout::toggleControlInPropertyPanel(const std::string& controlName)
{
// If the control is a property tab, make it visible
// If the notbeook is floating, toggling a visible tab also toggles the whole notebook
auto& propertyPane = _auiMgr.GetPane(PROPERTIES_PANEL);

if (propertyPane.IsFloating())
{
// Toggling a visible tab in the floating panel hides the whole notebook
if (propertyPane.IsShown() && _propertyNotebook->controlIsVisible(controlName))
{
propertyPane.Hide();
_auiMgr.Update();
return;
}

// Tab is not visible yet, focus it
_propertyNotebook->focusControl(controlName);

// Ensure the floating pane is visible
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}
}
else // Property panel is docked
{
// Focus matching controls in the property notebook
_propertyNotebook->focusControl(controlName);

// Ensure the non-floating property panel is visible
if (!propertyPane.IsShown())
{
propertyPane.Show(true);
_auiMgr.Update();
}
}
}

void AuiLayout::toggleControl(const std::string& controlName)
{
// Check the default settings if there's a control
Expand All @@ -461,11 +509,11 @@ void AuiLayout::toggleControl(const std::string& controlName)
}

// Control exists, we can toggle
// If the control is a property tab, then just focus it

// Controls in the property panel receive special treatment on toggling
if (_propertyNotebook->controlExists(controlName))
{
// Focus matching controls in the property notebook
_propertyNotebook->focusControl(controlName);
toggleControlInPropertyPanel(controlName);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/mainframe/AuiLayout.h
Expand Up @@ -70,6 +70,8 @@ class AuiLayout
void createPane(const std::string& controlName, const std::string& paneName,
const std::function<void(wxAuiPaneInfo&)>& setupPane);

void toggleControlInPropertyPanel(const std::string& controlName);

void onPaneClose(wxAuiManagerEvent& ev);
void handlePaneClosed(wxAuiPaneInfo& paneInfo);
void removeNonOrthoCenterPanes();
Expand Down
5 changes: 5 additions & 0 deletions radiant/ui/mainframe/PropertyNotebook.cpp
Expand Up @@ -299,6 +299,11 @@ bool PropertyNotebook::controlExists(const std::string& controlName)
return findControlIndexByName(controlName) != -1;
}

bool PropertyNotebook::controlIsVisible(const std::string& controlName)
{
return getSelectedControlName() == controlName;
}

void PropertyNotebook::focusControl(const std::string& controlName)
{
if (auto index = findControlIndexByName(controlName); index != -1)
Expand Down
3 changes: 3 additions & 0 deletions radiant/ui/mainframe/PropertyNotebook.h
Expand Up @@ -50,6 +50,9 @@ class PropertyNotebook :
// Returns true if the given control is loaded in a tab
bool controlExists(const std::string& controlName);

// Returns true if the tab of this control is shown
bool controlIsVisible(const std::string& controlName);

void saveState();
void restoreState();
void restoreDefaultState();
Expand Down

0 comments on commit 7029b15

Please sign in to comment.