feat: Add chat file name in top bar

This commit is contained in:
Petr Mironychev 2025-01-24 00:52:10 +01:00
parent bf63ae5714
commit 258053d826
4 changed files with 34 additions and 4 deletions

View File

@ -72,7 +72,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
this,
&ChatRootView::updateInputTokensCount);
connect(m_chatModel, &ChatModel::modelReseted, [this]() { m_recentFilePath = QString(); });
connect(m_chatModel, &ChatModel::modelReseted, [this]() { setRecentFilePath(QString{}); });
connect(this, &ChatRootView::attachmentFilesChanged, &ChatRootView::updateInputTokensCount);
connect(this, &ChatRootView::linkedFilesChanged, &ChatRootView::updateInputTokensCount);
connect(&Settings::chatAssistantSettings().useSystemPrompt, &Utils::BaseAspect::changed,
@ -107,7 +107,7 @@ void ChatRootView::sendMessage(const QString &message)
if (reply == QMessageBox::Yes) {
autosave();
m_chatModel->clear();
m_recentFilePath = QString{};
setRecentFilePath(QString{});
return;
}
}
@ -182,7 +182,7 @@ void ChatRootView::loadHistory(const QString &filePath)
if (!result.success) {
LOG_MESSAGE(QString("Failed to load chat history: %1").arg(result.errorMessage));
} else {
m_recentFilePath = filePath;
setRecentFilePath(filePath);
}
updateInputTokensCount();
}
@ -265,7 +265,7 @@ void ChatRootView::autosave()
QString filePath = getAutosaveFilePath();
if (!filePath.isEmpty()) {
ChatSerializer::saveToFile(m_chatModel, filePath);
m_recentFilePath = filePath;
setRecentFilePath(filePath);
}
}
@ -447,4 +447,17 @@ void ChatRootView::onEditorsClosed(QList<Core::IEditor *> editors)
}
}
QString ChatRootView::chatFileName() const
{
return QFileInfo(m_recentFilePath).baseName();
}
void ChatRootView::setRecentFilePath(const QString &filePath)
{
if (m_recentFilePath != filePath) {
m_recentFilePath = filePath;
emit chatFileNameChanged();
}
}
} // namespace QodeAssist::Chat

View File

@ -36,6 +36,7 @@ class ChatRootView : public QQuickItem
Q_PROPERTY(QStringList attachmentFiles READ attachmentFiles NOTIFY attachmentFilesChanged FINAL)
Q_PROPERTY(QStringList linkedFiles READ linkedFiles NOTIFY linkedFilesChanged FINAL)
Q_PROPERTY(int inputTokensCount READ inputTokensCount NOTIFY inputTokensCountChanged FINAL)
Q_PROPERTY(QString chatFileName READ chatFileName NOTIFY chatFileNameChanged FINAL)
QML_ELEMENT
@ -73,6 +74,9 @@ public:
void onEditorAboutToClose(Core::IEditor *editor);
void onEditorsClosed(QList<Core::IEditor *> editors);
QString chatFileName() const;
void setRecentFilePath(const QString &filePath);
public slots:
void sendMessage(const QString &message);
void copyToClipboard(const QString &text);
@ -87,6 +91,7 @@ signals:
void linkedFilesChanged();
void inputTokensCountChanged();
void isSyncOpenFilesChanged();
void chatFileNameChanged();
private:
QString getChatsHistoryDir() const;

View File

@ -72,6 +72,9 @@ ChatRootView {
tokensBadge {
text: qsTr("tokens:%1/%2").arg(root.inputTokensCount).arg(root.chatModel.tokensThreshold)
}
recentPath {
text: qsTr("Latest chat file name: %1").arg(root.chatFileName.length > 0 ? root.chatFileName : "Unsaved")
}
}
ListView {

View File

@ -28,6 +28,7 @@ Rectangle {
property alias loadButton: loadButtonId
property alias clearButton: clearButtonId
property alias tokensBadge: tokensBadgeId
property alias recentPath: recentPathId
color: palette.window.hslLightness > 0.5 ?
Qt.darker(palette.window, 1.1) :
@ -62,6 +63,14 @@ Rectangle {
text: qsTr("Clear")
}
Text {
id: recentPathId
Layout.fillWidth: true
elide: Text.ElideMiddle
color: palette.text
}
Item {
Layout.fillWidth: true
}