Merge pull request #10722 from Eism/save_state_after_workspace_change
[MU4] Fixed saving/restoring state of ui when changing workspace
This commit is contained in:
commit
b81b7d6670
8 changed files with 64 additions and 15 deletions
|
@ -172,7 +172,15 @@ void DockWindow::init()
|
||||||
|
|
||||||
uiConfiguration()->windowGeometryChanged().onNotify(this, [this]() {
|
uiConfiguration()->windowGeometryChanged().onNotify(this, [this]() {
|
||||||
if (!m_quiting) {
|
if (!m_quiting) {
|
||||||
resetWindowState();
|
updatePageState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
workspaceManager()->currentWorkspaceAboutToBeChanged().onNotify(this, [this]() {
|
||||||
|
if (DockPageView* page = currentPage()) {
|
||||||
|
m_workspaceChanging = true;
|
||||||
|
savePageState(page->objectName());
|
||||||
|
m_workspaceChanging = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -515,11 +523,22 @@ void DockWindow::restorePageState(const QString& pageName)
|
||||||
{
|
{
|
||||||
TRACEFUNC;
|
TRACEFUNC;
|
||||||
|
|
||||||
|
ValNt<QByteArray> pageStateValNt = uiConfiguration()->pageState(pageName);
|
||||||
|
|
||||||
/// NOTE: Do not restore geometry
|
/// NOTE: Do not restore geometry
|
||||||
bool ok = restoreLayout(uiConfiguration()->pageState(pageName), true /*restoreRelativeToMainWindow*/);
|
bool ok = restoreLayout(pageStateValNt.val, true /*restoreRelativeToMainWindow*/);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
LOGE() << "Could not restore the state of " << pageName << "!";
|
LOGE() << "Could not restore the state of " << pageName << "!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pageStateValNt.notification.isConnected()) {
|
||||||
|
pageStateValNt.notification.onNotify(this, [this, pageName]() {
|
||||||
|
bool isCurrentPage = m_currentPage && (m_currentPage->objectName() == pageName);
|
||||||
|
if (isCurrentPage && !m_quiting && !m_workspaceChanging) {
|
||||||
|
updatePageState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DockWindow::restoreLayout(const QByteArray& layout, bool restoreRelativeToMainWindow)
|
bool DockWindow::restoreLayout(const QByteArray& layout, bool restoreRelativeToMainWindow)
|
||||||
|
@ -545,7 +564,7 @@ QByteArray DockWindow::windowState() const
|
||||||
return layoutSaver.serializeLayout();
|
return layoutSaver.serializeLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockWindow::resetWindowState()
|
void DockWindow::updatePageState()
|
||||||
{
|
{
|
||||||
QString currentPageUriBackup = currentPageUri();
|
QString currentPageUriBackup = currentPageUri();
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,16 @@
|
||||||
|
|
||||||
#include "framework/uicomponents/view/qmllistproperty.h"
|
#include "framework/uicomponents/view/qmllistproperty.h"
|
||||||
|
|
||||||
|
#include "async/asyncable.h"
|
||||||
|
#include "async/asyncable.h"
|
||||||
|
|
||||||
#include "modularity/ioc.h"
|
#include "modularity/ioc.h"
|
||||||
#include "async/asyncable.h"
|
#include "workspace/iworkspacemanager.h"
|
||||||
#include "ui/iuiconfiguration.h"
|
#include "ui/iuiconfiguration.h"
|
||||||
#include "async/asyncable.h"
|
|
||||||
#include "internal/istartupscenario.h"
|
#include "internal/istartupscenario.h"
|
||||||
#include "idockwindow.h"
|
|
||||||
#include "idockwindowprovider.h"
|
#include "idockwindowprovider.h"
|
||||||
|
|
||||||
|
#include "idockwindow.h"
|
||||||
#include "internal/dockbase.h"
|
#include "internal/dockbase.h"
|
||||||
|
|
||||||
namespace KDDockWidgets {
|
namespace KDDockWidgets {
|
||||||
|
@ -54,8 +57,9 @@ class DockWindow : public QQuickItem, public IDockWindow, public async::Asyncabl
|
||||||
Q_PROPERTY(QQmlListProperty<mu::dock::DockToolBarView> toolBars READ toolBarsProperty)
|
Q_PROPERTY(QQmlListProperty<mu::dock::DockToolBarView> toolBars READ toolBarsProperty)
|
||||||
Q_PROPERTY(QQmlListProperty<mu::dock::DockPageView> pages READ pagesProperty)
|
Q_PROPERTY(QQmlListProperty<mu::dock::DockPageView> pages READ pagesProperty)
|
||||||
|
|
||||||
INJECT(dock, IDockWindowProvider, dockWindowProvider)
|
|
||||||
INJECT(dock, ui::IUiConfiguration, uiConfiguration)
|
INJECT(dock, ui::IUiConfiguration, uiConfiguration)
|
||||||
|
INJECT(dock, workspace::IWorkspaceManager, workspaceManager)
|
||||||
|
INJECT(dock, IDockWindowProvider, dockWindowProvider)
|
||||||
INJECT(dock, appshell::IStartupScenario, startupScenario)
|
INJECT(dock, appshell::IStartupScenario, startupScenario)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -118,7 +122,7 @@ private:
|
||||||
void savePageState(const QString& pageName);
|
void savePageState(const QString& pageName);
|
||||||
void restorePageState(const QString& pageName);
|
void restorePageState(const QString& pageName);
|
||||||
|
|
||||||
void resetWindowState();
|
void updatePageState();
|
||||||
bool restoreLayout(const QByteArray& layout, bool restoreRelativeToMainWindow = false);
|
bool restoreLayout(const QByteArray& layout, bool restoreRelativeToMainWindow = false);
|
||||||
|
|
||||||
void initDocks(DockPageView* page);
|
void initDocks(DockPageView* page);
|
||||||
|
@ -134,6 +138,7 @@ private:
|
||||||
async::Channel<QStringList> m_docksOpenStatusChanged;
|
async::Channel<QStringList> m_docksOpenStatusChanged;
|
||||||
|
|
||||||
bool m_quiting = false;
|
bool m_quiting = false;
|
||||||
|
bool m_workspaceChanging = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -600,9 +600,13 @@ double UiConfiguration::dpi() const
|
||||||
return screen ? screen->logicalDotsPerInch() : 100;
|
return screen ? screen->logicalDotsPerInch() : 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray UiConfiguration::pageState(const QString& pageName) const
|
mu::ValNt<QByteArray> UiConfiguration::pageState(const QString& pageName) const
|
||||||
{
|
{
|
||||||
return m_uiArrangement.state(pageName);
|
ValNt<QByteArray> result;
|
||||||
|
result.val = m_uiArrangement.state(pageName);
|
||||||
|
result.notification = m_uiArrangement.stateChanged(pageName);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiConfiguration::setPageState(const QString& pageName, const QByteArray& state)
|
void UiConfiguration::setPageState(const QString& pageName, const QByteArray& state)
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
|
|
||||||
void setPhysicalDotsPerInch(std::optional<double> dpi) override;
|
void setPhysicalDotsPerInch(std::optional<double> dpi) override;
|
||||||
|
|
||||||
QByteArray pageState(const QString& pageName) const override;
|
ValNt<QByteArray> pageState(const QString& pageName) const override;
|
||||||
void setPageState(const QString& pageName, const QByteArray& state) override;
|
void setPageState(const QString& pageName, const QByteArray& state) override;
|
||||||
|
|
||||||
QByteArray windowGeometry() const override;
|
QByteArray windowGeometry() const override;
|
||||||
|
|
|
@ -25,10 +25,13 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "modularity/imoduleexport.h"
|
#include "retval.h"
|
||||||
#include "async/notification.h"
|
#include "async/notification.h"
|
||||||
|
#include "async/channel.h"
|
||||||
#include "actions/actiontypes.h"
|
#include "actions/actiontypes.h"
|
||||||
|
|
||||||
|
#include "modularity/imoduleexport.h"
|
||||||
|
|
||||||
#include "uitypes.h"
|
#include "uitypes.h"
|
||||||
|
|
||||||
class QByteArray;
|
class QByteArray;
|
||||||
|
@ -79,7 +82,7 @@ public:
|
||||||
//! NOTE Maybe set from command line
|
//! NOTE Maybe set from command line
|
||||||
virtual void setPhysicalDotsPerInch(std::optional<double> dpi) = 0;
|
virtual void setPhysicalDotsPerInch(std::optional<double> dpi) = 0;
|
||||||
|
|
||||||
virtual QByteArray pageState(const QString& pageName) const = 0;
|
virtual ValNt<QByteArray> pageState(const QString& pageName) const = 0;
|
||||||
virtual void setPageState(const QString& pageName, const QByteArray& state) = 0;
|
virtual void setPageState(const QString& pageName, const QByteArray& state) = 0;
|
||||||
|
|
||||||
virtual QByteArray windowGeometry() const = 0;
|
virtual QByteArray windowGeometry() const = 0;
|
||||||
|
|
|
@ -66,6 +66,11 @@ IWorkspacePtr WorkspaceManager::currentWorkspace() const
|
||||||
return m_currentWorkspace;
|
return m_currentWorkspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async::Notification WorkspaceManager::currentWorkspaceAboutToBeChanged() const
|
||||||
|
{
|
||||||
|
return m_currentWorkspaceAboutToBeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
async::Notification WorkspaceManager::currentWorkspaceChanged() const
|
async::Notification WorkspaceManager::currentWorkspaceChanged() const
|
||||||
{
|
{
|
||||||
return m_currentWorkspaceChanged;
|
return m_currentWorkspaceChanged;
|
||||||
|
@ -140,6 +145,10 @@ Ret WorkspaceManager::removeMissingWorkspaces(const IWorkspacePtrList& newWorksp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!containsWorkspace(newWorkspaceList, m_currentWorkspace)) {
|
||||||
|
m_currentWorkspace = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return make_ret(Ret::Code::Ok);
|
return make_ret(Ret::Code::Ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,8 +161,12 @@ Ret WorkspaceManager::removeWorkspace(const IWorkspacePtr& workspace)
|
||||||
|
|
||||||
for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) {
|
for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) {
|
||||||
if (it->get()->name() == workspaceName) {
|
if (it->get()->name() == workspaceName) {
|
||||||
m_workspaces.erase(it);
|
Ret ret = fileSystem()->remove(it->get()->filePath());
|
||||||
return fileSystem()->remove(it->get()->filePath());
|
if (ret) {
|
||||||
|
m_workspaces.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,6 +279,8 @@ void WorkspaceManager::setupCurrentWorkspace()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_currentWorkspaceAboutToBeChanged.notify();
|
||||||
|
|
||||||
saveCurrentWorkspace();
|
saveCurrentWorkspace();
|
||||||
|
|
||||||
//! NOTE Perhaps we need to unload the current workspace (clear memory)
|
//! NOTE Perhaps we need to unload the current workspace (clear memory)
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
IWorkspacePtr defaultWorkspace() const override;
|
IWorkspacePtr defaultWorkspace() const override;
|
||||||
|
|
||||||
IWorkspacePtr currentWorkspace() const override;
|
IWorkspacePtr currentWorkspace() const override;
|
||||||
|
async::Notification currentWorkspaceAboutToBeChanged() const override;
|
||||||
async::Notification currentWorkspaceChanged() const override;
|
async::Notification currentWorkspaceChanged() const override;
|
||||||
|
|
||||||
IWorkspacePtrList workspaces() const override;
|
IWorkspacePtrList workspaces() const override;
|
||||||
|
@ -81,6 +82,7 @@ private:
|
||||||
|
|
||||||
WorkspacePtr m_defaultWorkspace;
|
WorkspacePtr m_defaultWorkspace;
|
||||||
WorkspacePtr m_currentWorkspace;
|
WorkspacePtr m_currentWorkspace;
|
||||||
|
async::Notification m_currentWorkspaceAboutToBeChanged;
|
||||||
async::Notification m_currentWorkspaceChanged;
|
async::Notification m_currentWorkspaceChanged;
|
||||||
|
|
||||||
std::vector<WorkspacePtr> m_workspaces;
|
std::vector<WorkspacePtr> m_workspaces;
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
//! NOTE Current selected by a user, writable, optionally managed
|
//! NOTE Current selected by a user, writable, optionally managed
|
||||||
virtual IWorkspacePtr currentWorkspace() const = 0;
|
virtual IWorkspacePtr currentWorkspace() const = 0;
|
||||||
|
virtual async::Notification currentWorkspaceAboutToBeChanged() const = 0;
|
||||||
virtual async::Notification currentWorkspaceChanged() const = 0;
|
virtual async::Notification currentWorkspaceChanged() const = 0;
|
||||||
|
|
||||||
virtual IWorkspacePtrList workspaces() const = 0;
|
virtual IWorkspacePtrList workspaces() const = 0;
|
||||||
|
|
Loading…
Reference in a new issue