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 authored and deepin-mozart committed Nov 26, 2024
1 parent 83fe5cc commit f5c081a
Show file tree
Hide file tree
Showing 20 changed files with 379 additions and 404 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: 3 additions & 2 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void CodeGeeXManager::saveConfig(const QString &sessionId, const QString &userId
OptionManager::getInstance()->setValue("CodeGeeX", "Id", map);
}

Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除") void CodeGeeXManager::loadConfig()
Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除")
void CodeGeeXManager::loadConfig()
{
QFile file(configFilePath());
if (!file.exists()) {
Expand Down Expand Up @@ -177,7 +178,7 @@ void CodeGeeXManager::independentAsking(const QString &prompt, const QMultiMap<Q
}
AskApi *api = new AskApi;
api->postSSEChat(kUrlSSEChat, sessionId, prompt, QSysInfo::machineUniqueId(), history, currentTalkID);
QTimer::singleShot(10000, api, [=](){
QTimer::singleShot(10000, api, [=]() {
if (pipe && pipe->isOpen()) {
qWarning() << "timed out, close pipe";
pipe->close();
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();
});
}
2 changes: 2 additions & 0 deletions src/plugins/core/session/sessiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include <QPushButton>
#include <QVBoxLayout>
#include <QEvent>
#include <QPainterPath>

DWIDGET_USE_NAMESPACE

Expand Down
17 changes: 14 additions & 3 deletions src/plugins/core/session/sessionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <QDir>
#include <QDateTime>
#include <QApplication>

constexpr char kDefaultSession[] { "default" };
constexpr char kSessionGroup[] { "Session" };
Expand Down Expand Up @@ -105,8 +106,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 +281,7 @@ bool SessionManager::loadSession(const QString &session)
return true;
}

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

Expand All @@ -290,7 +292,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 +315,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
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ QString ProfileSettingWidget::translateFilePath()
+ QDir::separator() + QString("translate.support");
}

Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除") QString ProfileSettingWidget::languageFilePath()
Q_DECL_DEPRECATED_X("-------------存在兼容代码需要删除")
QString ProfileSettingWidget::languageFilePath()
{
return CustomPaths::user(CustomPaths::Flags::Configures)
+ QDir::separator() + QString("chooselanguage.support");
Expand Down Expand Up @@ -83,7 +84,7 @@ void ProfileSettingWidget::readConfig()
{
QString languageName;
QFile file(languageFilePath());
if (file.exists()) {
if (file.exists()) {
QTextStream txtInput(&file);
if (file.open(QIODevice::ReadOnly)) {
languageName = d->languagePaths.key(txtInput.readLine());
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 f5c081a

Please sign in to comment.