Skip to content

Commit

Permalink
refactor: [recent] Refactor recent display widget and session management
Browse files Browse the repository at this point in the history
Refactored recent display widget to use a unified list view for both projects and documents, improving code organization and reducing duplication.  Major changes include:

- Combined project and document views into single RecentListView
- Improved session management with dirty state tracking
- Refactored session item widget to use animation for expand/collapse
- Updated session service interface for better state handling
- Simplified recent display widget UI layout and event handling

Log: Refactor recent module UI components and session management
  • Loading branch information
Kakueeen committed Nov 26, 2024
1 parent 83fe5cc commit 6281137
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 355 deletions.
1 change: 1 addition & 0 deletions src/common/util/eventdefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ OPI_OBJECT(workspace,
)
OPI_OBJECT(session,
OPI_INTERFACE(readyToSaveSession)
OPI_INTERFACE(sessionStatusChanged)
OPI_INTERFACE(sessionLoaded, "session")
OPI_INTERFACE(sessionCreated, "session")
OPI_INTERFACE(sessionRenamed, "oldName", "newName")
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/core/modules/sessionmanagermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void SessionManagerModule::initInterfaces()
sessionSrv->isDefaultSession = std::bind(&SessionManager::isDefaultSession, ins, _1);
sessionSrv->isSessionLoading = std::bind(&SessionManager::isSessionLoading, ins);
sessionSrv->isDefaultVirgin = std::bind(&SessionManager::isDefaultVirgin, ins);
sessionSrv->markSessionFileDirty = std::bind(&SessionManager::markSessionFileDirty, ins);
sessionSrv->sessionFile = std::bind(&SessionManager::sessionFile, ins, _1);
}

Expand All @@ -74,4 +75,8 @@ void SessionManagerModule::initOutputEvents()
[](const QString &name) {
session.sessionRemoved(name);
});
connect(ins, &SessionManager::sessionStatusChanged, this,
[] {
session.sessionStatusChanged();
});
}
16 changes: 13 additions & 3 deletions src/plugins/core/session/sessionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ SessionManager::SessionManager(QObject *parent)
{
d->readSettings();
connect(qApp, &QApplication::aboutToQuit, this, [this] {
if (!isSessionLoading() && !isDefaultVirgin())
saveSession();
d->saveSettings();
saveSession();
});
}

Expand Down Expand Up @@ -279,7 +280,7 @@ bool SessionManager::loadSession(const QString &session)
return true;
}

bool SessionManager::saveSession()
void SessionManager::saveSession()
{
Q_EMIT readyToSaveSession();

Expand All @@ -290,7 +291,7 @@ bool SessionManager::saveSession()
settings.setValue(kSessionGroup, iter.key(), iter.value());
}

return true;
d->sessionDateTimes.insert(d->currentSession, QDateTime::currentDateTime());
}

bool SessionManager::isDefaultSession(const QString &session)
Expand All @@ -313,6 +314,15 @@ bool SessionManager::isAutoLoadLastSession()
return d->isAutoLoad;
}

void SessionManager::markSessionFileDirty()
{
if (!d->virginSession)
return;

d->virginSession = false;
Q_EMIT sessionStatusChanged();
}

QString SessionManager::sessionFile(const QString &session)
{
QString format = "%1/%2.session";
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/core/session/sessionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ class SessionManager : public QObject
QVariant value(const QString &key);

bool loadSession(const QString &session);
bool saveSession();
void saveSession();
bool isDefaultSession(const QString &session);
bool isSessionLoading();
bool isDefaultVirgin();
bool isAutoLoadLastSession();

void markSessionFileDirty();
QString sessionFile(const QString &session);

Q_SIGNALS:
void readyToSaveSession();
void sessionLoaded(const QString &session);
void sessionStatusChanged();

void sessionCreated(const QString &session);
void sessionRenamed(const QString &oldName, const QString &newName);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/project/transceiver/projectcorereceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void ProjectCoreReceiver::processActiveProjectEvent(const dpf::Event &event)

void ProjectCoreReceiver::processOpenProjectEvent(const dpf::Event &event)
{
auto sessionSrv = dpfGetService(SessionService);
sessionSrv->markSessionFileDirty();
uiController.doSwitch(dpfservice::MWNA_EDIT);
auto &ctx = dpfInstance.serviceContext();
ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name());
Expand Down
1 change: 0 additions & 1 deletion src/plugins/recent/mainframe/itemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "itemdelegate.h"
#include "itemlistview.h"

#include <DApplication>
#include <DGuiApplicationHelper>
Expand Down
67 changes: 0 additions & 67 deletions src/plugins/recent/mainframe/itemlistview.cpp

This file was deleted.

37 changes: 0 additions & 37 deletions src/plugins/recent/mainframe/itemlistview.h

This file was deleted.

Loading

0 comments on commit 6281137

Please sign in to comment.