mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
fix: Saving name of chat in native language
- Add button to show chat history folder in system viewer
This commit is contained in:
parent
45aba6b6be
commit
56995c9edf
@ -20,6 +20,7 @@
|
|||||||
#include "ChatRootView.hpp"
|
#include "ChatRootView.hpp"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
this,
|
this,
|
||||||
&ChatRootView::updateInputTokensCount);
|
&ChatRootView::updateInputTokensCount);
|
||||||
|
|
||||||
connect(m_chatModel, &ChatModel::modelReseted, [this]() { setRecentFilePath(QString{}); });
|
connect(m_chatModel, &ChatModel::modelReseted, this, [this]() { setRecentFilePath(QString{}); });
|
||||||
connect(this, &ChatRootView::attachmentFilesChanged, &ChatRootView::updateInputTokensCount);
|
connect(this, &ChatRootView::attachmentFilesChanged, &ChatRootView::updateInputTokensCount);
|
||||||
connect(this, &ChatRootView::linkedFilesChanged, &ChatRootView::updateInputTokensCount);
|
connect(this, &ChatRootView::linkedFilesChanged, &ChatRootView::updateInputTokensCount);
|
||||||
connect(&Settings::chatAssistantSettings().useSystemPrompt, &Utils::BaseAspect::changed,
|
connect(&Settings::chatAssistantSettings().useSystemPrompt, &Utils::BaseAspect::changed,
|
||||||
@ -91,7 +92,7 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
|
|
||||||
connect(editors, &Core::EditorManager::currentEditorAboutToChange, this, [this]() {
|
connect(editors, &Core::EditorManager::currentEditorAboutToChange, this, [this]() {
|
||||||
if (m_isSyncOpenFiles) {
|
if (m_isSyncOpenFiles) {
|
||||||
for (auto editor : m_currentEditors) {
|
for (auto editor : std::as_const(m_currentEditors)) {
|
||||||
onAppendLinkFileFromEditor(editor);
|
onAppendLinkFileFromEditor(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,17 +257,50 @@ QString ChatRootView::getSuggestedFileName() const
|
|||||||
{
|
{
|
||||||
QStringList parts;
|
QStringList parts;
|
||||||
|
|
||||||
|
static const QRegularExpression saitizeSymbols = QRegularExpression("[\\/:*?\"<>|\\s]");
|
||||||
|
static const QRegularExpression underSymbols = QRegularExpression("_+");
|
||||||
|
|
||||||
if (m_chatModel->rowCount() > 0) {
|
if (m_chatModel->rowCount() > 0) {
|
||||||
QString firstMessage
|
QString firstMessage
|
||||||
= m_chatModel->data(m_chatModel->index(0), ChatModel::Content).toString();
|
= m_chatModel->data(m_chatModel->index(0), ChatModel::Content).toString();
|
||||||
QString shortMessage = firstMessage.split('\n').first().simplified().left(30);
|
QString shortMessage = firstMessage.split('\n').first().simplified().left(30);
|
||||||
shortMessage.replace(QRegularExpression("[^a-zA-Z0-9_-]"), "_");
|
|
||||||
parts << shortMessage;
|
QString sanitizedMessage = shortMessage;
|
||||||
|
sanitizedMessage.replace(saitizeSymbols, "_");
|
||||||
|
sanitizedMessage.replace(underSymbols, "_");
|
||||||
|
sanitizedMessage = sanitizedMessage.trimmed();
|
||||||
|
|
||||||
|
if (!sanitizedMessage.isEmpty()) {
|
||||||
|
if (sanitizedMessage.startsWith('_')) {
|
||||||
|
sanitizedMessage.remove(0, 1);
|
||||||
|
}
|
||||||
|
if (sanitizedMessage.endsWith('_')) {
|
||||||
|
sanitizedMessage.chop(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString targetDir = getChatsHistoryDir();
|
||||||
|
QString fullPath = QDir(targetDir).filePath(sanitizedMessage);
|
||||||
|
|
||||||
|
QFileInfo fileInfo(fullPath);
|
||||||
|
if (!fileInfo.exists() && QFileInfo(fileInfo.path()).isWritable()) {
|
||||||
|
parts << sanitizedMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parts << QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm");
|
parts << QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm");
|
||||||
|
|
||||||
return parts.join("_");
|
QString fileName = parts.join("_");
|
||||||
|
|
||||||
|
QString fullPath = QDir(getChatsHistoryDir()).filePath(fileName);
|
||||||
|
QFileInfo finalCheck(fullPath);
|
||||||
|
|
||||||
|
if (fileName.isEmpty() || finalCheck.exists() || !QFileInfo(finalCheck.path()).isWritable()) {
|
||||||
|
fileName = QString("chat_%1").arg(
|
||||||
|
QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::autosave()
|
void ChatRootView::autosave()
|
||||||
@ -319,7 +353,7 @@ void ChatRootView::showAttachFilesDialog()
|
|||||||
QStringList newFilePaths = dialog.selectedFiles();
|
QStringList newFilePaths = dialog.selectedFiles();
|
||||||
if (!newFilePaths.isEmpty()) {
|
if (!newFilePaths.isEmpty()) {
|
||||||
bool filesAdded = false;
|
bool filesAdded = false;
|
||||||
for (const QString &filePath : newFilePaths) {
|
for (const QString &filePath : std::as_const(newFilePaths)) {
|
||||||
if (!m_attachmentFiles.contains(filePath)) {
|
if (!m_attachmentFiles.contains(filePath)) {
|
||||||
m_attachmentFiles.append(filePath);
|
m_attachmentFiles.append(filePath);
|
||||||
filesAdded = true;
|
filesAdded = true;
|
||||||
@ -353,7 +387,7 @@ void ChatRootView::showLinkFilesDialog()
|
|||||||
QStringList newFilePaths = dialog.selectedFiles();
|
QStringList newFilePaths = dialog.selectedFiles();
|
||||||
if (!newFilePaths.isEmpty()) {
|
if (!newFilePaths.isEmpty()) {
|
||||||
bool filesAdded = false;
|
bool filesAdded = false;
|
||||||
for (const QString &filePath : newFilePaths) {
|
for (const QString &filePath : std::as_const(newFilePaths)) {
|
||||||
if (!m_linkedFiles.contains(filePath)) {
|
if (!m_linkedFiles.contains(filePath)) {
|
||||||
m_linkedFiles.append(filePath);
|
m_linkedFiles.append(filePath);
|
||||||
filesAdded = true;
|
filesAdded = true;
|
||||||
@ -388,12 +422,31 @@ void ChatRootView::setIsSyncOpenFiles(bool state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (m_isSyncOpenFiles) {
|
if (m_isSyncOpenFiles) {
|
||||||
for (auto editor : m_currentEditors) {
|
for (auto editor : std::as_const(m_currentEditors)) {
|
||||||
onAppendLinkFileFromEditor(editor);
|
onAppendLinkFileFromEditor(editor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChatRootView::openChatHistoryFolder()
|
||||||
|
{
|
||||||
|
QString path;
|
||||||
|
if (auto project = ProjectExplorer::ProjectManager::startupProject()) {
|
||||||
|
Settings::ProjectSettings projectSettings(project);
|
||||||
|
path = projectSettings.chatHistoryPath().toString();
|
||||||
|
} else {
|
||||||
|
path = QString("%1/qodeassist/chat_history").arg(Core::ICore::userResourcePath().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir dir(path);
|
||||||
|
if (!dir.exists()) {
|
||||||
|
dir.mkpath(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl url = QUrl::fromLocalFile(dir.absolutePath());
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
void ChatRootView::updateInputTokensCount()
|
void ChatRootView::updateInputTokensCount()
|
||||||
{
|
{
|
||||||
int inputTokens = m_messageTokensCount;
|
int inputTokens = m_messageTokensCount;
|
||||||
|
@ -64,6 +64,7 @@ public:
|
|||||||
Q_INVOKABLE void removeFileFromLinkList(int index);
|
Q_INVOKABLE void removeFileFromLinkList(int index);
|
||||||
Q_INVOKABLE void calculateMessageTokensCount(const QString &message);
|
Q_INVOKABLE void calculateMessageTokensCount(const QString &message);
|
||||||
Q_INVOKABLE void setIsSyncOpenFiles(bool state);
|
Q_INVOKABLE void setIsSyncOpenFiles(bool state);
|
||||||
|
Q_INVOKABLE void openChatHistoryFolder();
|
||||||
|
|
||||||
Q_INVOKABLE void updateInputTokensCount();
|
Q_INVOKABLE void updateInputTokensCount();
|
||||||
int inputTokensCount() const;
|
int inputTokensCount() const;
|
||||||
|
@ -75,6 +75,7 @@ ChatRootView {
|
|||||||
recentPath {
|
recentPath {
|
||||||
text: qsTr("Latest chat file name: %1").arg(root.chatFileName.length > 0 ? root.chatFileName : "Unsaved")
|
text: qsTr("Latest chat file name: %1").arg(root.chatFileName.length > 0 ? root.chatFileName : "Unsaved")
|
||||||
}
|
}
|
||||||
|
openChatHistory.onClicked: root.openChatHistoryFolder()
|
||||||
}
|
}
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
|
@ -29,6 +29,7 @@ Rectangle {
|
|||||||
property alias clearButton: clearButtonId
|
property alias clearButton: clearButtonId
|
||||||
property alias tokensBadge: tokensBadgeId
|
property alias tokensBadge: tokensBadgeId
|
||||||
property alias recentPath: recentPathId
|
property alias recentPath: recentPathId
|
||||||
|
property alias openChatHistory: openChatHistoryId
|
||||||
|
|
||||||
color: palette.window.hslLightness > 0.5 ?
|
color: palette.window.hslLightness > 0.5 ?
|
||||||
Qt.darker(palette.window, 1.1) :
|
Qt.darker(palette.window, 1.1) :
|
||||||
@ -66,11 +67,16 @@ Rectangle {
|
|||||||
Text {
|
Text {
|
||||||
id: recentPathId
|
id: recentPathId
|
||||||
|
|
||||||
Layout.fillWidth: true
|
|
||||||
elide: Text.ElideMiddle
|
elide: Text.ElideMiddle
|
||||||
color: palette.text
|
color: palette.text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QoAButton {
|
||||||
|
id: openChatHistoryId
|
||||||
|
|
||||||
|
text: qsTr("Show in system")
|
||||||
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user