Skip to content

Commit

Permalink
#5841: Save and restore the state of all floating ortho views when us…
Browse files Browse the repository at this point in the history
…ing Docking layout
  • Loading branch information
codereader committed Feb 28, 2022
1 parent aaf11c4 commit 5cd0c6b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 44 deletions.
3 changes: 0 additions & 3 deletions install/user.xml
Expand Up @@ -152,9 +152,6 @@
<startMonitorNum value="0" />
</multiMonitor>
<xyview>
<views name="default">
<view type="XY" xPosition="500" yPosition="100" width="400" height="430"/>
</views>
<showGrid value="1" />
<chaseMouse value="1" />
<chaseMouseCap value="32" />
Expand Down
6 changes: 6 additions & 0 deletions radiant/ui/mainframe/AuiLayout.cpp
Expand Up @@ -130,10 +130,16 @@ void AuiLayout::activate()
GlobalMenuManager().setVisibility("main/view/cameraview", false);
// Hide the console/texture browser toggles for non-floating/non-split views
GlobalMenuManager().setVisibility("main/view/textureBrowser", false);

// Restore all floating XY views
GlobalXYWnd().restoreState();
}

void AuiLayout::deactivate()
{
// Save all floating XYWnd states
GlobalXYWnd().saveState();

// Store perspective
GlobalRegistry().set(RKEY_ROOT, _auiMgr.SavePerspective().ToStdString());

Expand Down
70 changes: 29 additions & 41 deletions radiant/xyview/GlobalXYWnd.cpp
Expand Up @@ -72,49 +72,38 @@ XYWndManager::XYWndManager() :
*/
void XYWndManager::restoreState()
{
xml::NodeList views = GlobalRegistry().findXPath(RKEY_XYVIEW_ROOT + "//views");
auto views = GlobalRegistry().findXPath(RKEY_XYVIEW_ROOT + "//views");

if (!views.empty())
if (views.empty()) return;

// Find all <view> tags under the first found <views> tag
auto viewList = views[0].getNamedChildren("view");

for (const auto& node : viewList)
{
// Find all <view> tags under the first found <views> tag
xml::NodeList viewList = views[0].getNamedChildren("view");
// Assemble the XPath for the viewstate
std::string path = RKEY_XYVIEW_ROOT +
"/views/view[@name='" + node.getAttributeValue("name") + "']";

const std::string typeStr = node.getAttributeValue("type");

for (xml::NodeList::const_iterator i = viewList.begin();
i != viewList.end();
++i)
EViewType type = XY;

if (typeStr == "YZ")
{
// Assemble the XPath for the viewstate
std::string path = RKEY_XYVIEW_ROOT +
"/views/view[@name='" + i->getAttributeValue("name") + "']";

const std::string typeStr = i->getAttributeValue("type");

EViewType type = XY;

if (typeStr == "YZ")
{
type = YZ;
}
else if (typeStr == "XZ")
{
type = XZ;
}
else
{
type = XY;
}

// Create the view and restore the size
XYWndPtr newWnd = createFloatingOrthoView(type);
type = YZ;
}
else if (typeStr == "XZ")
{
type = XZ;
}
else
{
type = XY;
}
}
else
{
// Create at least one XYView, if no view info is found
rMessage() << "XYWndManager: No xywindow information found in XMLRegistry, creating default view.\n";

// Create a default OrthoView
createFloatingOrthoView(XY);
// Create the view and restore the size
createFloatingOrthoView(type);
}
}

Expand All @@ -126,10 +115,10 @@ void XYWndManager::saveState()
// Create a new node
std::string rootNodePath(RKEY_XYVIEW_ROOT + "/views");

for (XYWndMap::iterator i = _xyWnds.begin(); i != _xyWnds.end(); ++i)
for (auto& [_, view] : _xyWnds)
{
// Save each XYView state to the registry
FloatingOrthoViewPtr floatingView = std::dynamic_pointer_cast<FloatingOrthoView>(i->second);
auto floatingView = std::dynamic_pointer_cast<FloatingOrthoView>(view);

if (floatingView)
{
Expand All @@ -138,11 +127,10 @@ void XYWndManager::saveState()
}
}

// Free the allocated XYViews from the heap
void XYWndManager::destroyViews()
{
// Discard the whole list
for (XYWndMap::iterator i = _xyWnds.begin(); i != _xyWnds.end(); /* in-loop incr.*/)
for (auto i = _xyWnds.begin(); i != _xyWnds.end(); /* in-loop incr.*/)
{
// Extract the pointer to prevent the destructor from firing
XYWndPtr candidate = i->second;
Expand Down

0 comments on commit 5cd0c6b

Please sign in to comment.