mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-06-04 01:28:58 -04:00
fix: Sync editors and chat when sync enable
This commit is contained in:
parent
1dfb3feb96
commit
45aba6b6be
@ -82,9 +82,20 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
|||||||
|
|
||||||
auto editors = Core::EditorManager::instance();
|
auto editors = Core::EditorManager::instance();
|
||||||
|
|
||||||
connect(editors, &Core::EditorManager::editorOpened, this, &ChatRootView::onEditorOpened);
|
connect(editors, &Core::EditorManager::editorCreated, this, &ChatRootView::onEditorCreated);
|
||||||
connect(editors, &Core::EditorManager::editorAboutToClose, this, &ChatRootView::onEditorAboutToClose);
|
connect(
|
||||||
connect(editors, &Core::EditorManager::editorsClosed, this, &ChatRootView::onEditorsClosed);
|
editors,
|
||||||
|
&Core::EditorManager::editorAboutToClose,
|
||||||
|
this,
|
||||||
|
&ChatRootView::onEditorAboutToClose);
|
||||||
|
|
||||||
|
connect(editors, &Core::EditorManager::currentEditorAboutToChange, this, [this]() {
|
||||||
|
if (m_isSyncOpenFiles) {
|
||||||
|
for (auto editor : m_currentEditors) {
|
||||||
|
onAppendLinkFileFromEditor(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
updateInputTokensCount();
|
updateInputTokensCount();
|
||||||
}
|
}
|
||||||
@ -375,6 +386,12 @@ void ChatRootView::setIsSyncOpenFiles(bool state)
|
|||||||
m_isSyncOpenFiles = state;
|
m_isSyncOpenFiles = state;
|
||||||
emit isSyncOpenFilesChanged();
|
emit isSyncOpenFilesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_isSyncOpenFiles) {
|
||||||
|
for (auto editor : m_currentEditors) {
|
||||||
|
onAppendLinkFileFromEditor(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::updateInputTokensCount()
|
void ChatRootView::updateInputTokensCount()
|
||||||
@ -416,7 +433,20 @@ bool ChatRootView::isSyncOpenFiles() const
|
|||||||
return m_isSyncOpenFiles;
|
return m_isSyncOpenFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::onEditorOpened(Core::IEditor *editor)
|
void ChatRootView::onEditorAboutToClose(Core::IEditor *editor)
|
||||||
|
{
|
||||||
|
if (auto document = editor->document(); document && isSyncOpenFiles()) {
|
||||||
|
QString filePath = document->filePath().toString();
|
||||||
|
m_linkedFiles.removeOne(filePath);
|
||||||
|
emit linkedFilesChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (editor) {
|
||||||
|
m_currentEditors.removeOne(editor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatRootView::onAppendLinkFileFromEditor(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
if (auto document = editor->document(); document && isSyncOpenFiles()) {
|
if (auto document = editor->document(); document && isSyncOpenFiles()) {
|
||||||
QString filePath = document->filePath().toString();
|
QString filePath = document->filePath().toString();
|
||||||
@ -427,25 +457,10 @@ void ChatRootView::onEditorOpened(Core::IEditor *editor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatRootView::onEditorAboutToClose(Core::IEditor *editor)
|
void ChatRootView::onEditorCreated(Core::IEditor *editor, const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
if (auto document = editor->document(); document && isSyncOpenFiles()) {
|
if (editor && editor->document()) {
|
||||||
QString filePath = document->filePath().toString();
|
m_currentEditors.append(editor);
|
||||||
m_linkedFiles.removeOne(filePath);
|
|
||||||
emit linkedFilesChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatRootView::onEditorsClosed(QList<Core::IEditor *> editors)
|
|
||||||
{
|
|
||||||
if (isSyncOpenFiles()) {
|
|
||||||
for (Core::IEditor *editor : editors) {
|
|
||||||
if (auto document = editor->document()) {
|
|
||||||
QString filePath = document->filePath().toString();
|
|
||||||
m_linkedFiles.removeOne(filePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit linkedFilesChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ public:
|
|||||||
|
|
||||||
bool isSyncOpenFiles() const;
|
bool isSyncOpenFiles() const;
|
||||||
|
|
||||||
void onEditorOpened(Core::IEditor *editor);
|
|
||||||
void onEditorAboutToClose(Core::IEditor *editor);
|
void onEditorAboutToClose(Core::IEditor *editor);
|
||||||
void onEditorsClosed(QList<Core::IEditor *> editors);
|
void onAppendLinkFileFromEditor(Core::IEditor *editor);
|
||||||
|
void onEditorCreated(Core::IEditor *editor, const Utils::FilePath &filePath);
|
||||||
|
|
||||||
QString chatFileName() const;
|
QString chatFileName() const;
|
||||||
void setRecentFilePath(const QString &filePath);
|
void setRecentFilePath(const QString &filePath);
|
||||||
@ -106,6 +106,7 @@ private:
|
|||||||
int m_messageTokensCount{0};
|
int m_messageTokensCount{0};
|
||||||
int m_inputTokensCount{0};
|
int m_inputTokensCount{0};
|
||||||
bool m_isSyncOpenFiles;
|
bool m_isSyncOpenFiles;
|
||||||
|
QList<Core::IEditor *> m_currentEditors;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QodeAssist::Chat
|
} // namespace QodeAssist::Chat
|
||||||
|
Loading…
x
Reference in New Issue
Block a user