mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-05-30 02:49:12 -04:00
feat: Add chat to editor view and refactor current openning
This commit is contained in:
47
chat/ChatDocument.cpp
Normal file
47
chat/ChatDocument.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "ChatDocument.hpp"
|
||||
|
||||
#include <utils/result.h>
|
||||
|
||||
#include "QodeAssistConstants.hpp"
|
||||
#include "QodeAssisttr.h"
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
ChatDocument::ChatDocument(QObject *parent)
|
||||
: Core::IDocument(parent)
|
||||
{
|
||||
setId(Constants::QODE_ASSIST_CHAT_EDITOR_ID);
|
||||
setMimeType("text/plain");
|
||||
setTemporary(true);
|
||||
setPreferredDisplayName(Tr::tr("QodeAssist Chat"));
|
||||
}
|
||||
|
||||
QByteArray ChatDocument::contents() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::Result<> ChatDocument::setContents(const QByteArray &)
|
||||
{
|
||||
return Utils::ResultOk;
|
||||
}
|
||||
|
||||
bool ChatDocument::isModified() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatDocument::isSaveAsAllowed() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ChatDocument::shouldAutoSave() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
27
chat/ChatDocument.hpp
Normal file
27
chat/ChatDocument.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/idocument.h>
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
// Backing document for a chat editor view. The chat persists itself through its own
|
||||
// autosave history file, so this document is purely a placeholder for the editor area
|
||||
// and never participates in Qt Creator's save infrastructure.
|
||||
class ChatDocument : public Core::IDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatDocument(QObject *parent = nullptr);
|
||||
|
||||
QByteArray contents() const override;
|
||||
Utils::Result<> setContents(const QByteArray &contents) override;
|
||||
bool isModified() const override;
|
||||
bool isSaveAsAllowed() const override;
|
||||
bool shouldAutoSave() const override;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
73
chat/ChatEditor.cpp
Normal file
73
chat/ChatEditor.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "ChatEditor.hpp"
|
||||
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <QAction>
|
||||
|
||||
#include "ChatDocument.hpp"
|
||||
#include "ChatView/ChatRootView.hpp"
|
||||
#include "ChatView/ChatWidget.hpp"
|
||||
#include "QodeAssistConstants.hpp"
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
ChatEditor::ChatEditor(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry)
|
||||
: m_engine(engine)
|
||||
, m_sessionFileRegistry(sessionFileRegistry)
|
||||
, m_document(new ChatDocument(this))
|
||||
, m_chatWidget(new ChatWidget(engine, sessionFileRegistry))
|
||||
{
|
||||
setWidget(m_chatWidget);
|
||||
setContext(Core::Context(Constants::QODE_ASSIST_CHAT_CONTEXT));
|
||||
setDuplicateSupported(true);
|
||||
|
||||
if (auto rootView = qobject_cast<ChatRootView *>(m_chatWidget->rootObject())) {
|
||||
connect(
|
||||
rootView,
|
||||
&ChatRootView::closeHostRequested,
|
||||
this,
|
||||
[this] {
|
||||
Core::EditorManager::closeEditors({this});
|
||||
if (auto command
|
||||
= Core::ActionManager::command(Core::Constants::REMOVE_CURRENT_SPLIT)) {
|
||||
if (auto action = command->action(); action && action->isEnabled())
|
||||
action->trigger();
|
||||
}
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatEditor::consumePendingChatFile()
|
||||
{
|
||||
if (auto rootView = qobject_cast<ChatRootView *>(m_chatWidget->rootObject()))
|
||||
rootView->consumePendingChatFile();
|
||||
}
|
||||
|
||||
ChatEditor::~ChatEditor()
|
||||
{
|
||||
delete m_chatWidget;
|
||||
}
|
||||
|
||||
Core::IDocument *ChatEditor::document() const
|
||||
{
|
||||
return m_document;
|
||||
}
|
||||
|
||||
QWidget *ChatEditor::toolBar()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Core::IEditor *ChatEditor::duplicate()
|
||||
{
|
||||
return new ChatEditor(m_engine, m_sessionFileRegistry);
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
39
chat/ChatEditor.hpp
Normal file
39
chat/ChatEditor.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
|
||||
class QQmlEngine;
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
class ChatDocument;
|
||||
class ChatWidget;
|
||||
class SessionFileRegistry;
|
||||
|
||||
// Editor-area host for the chat. Each editor (including a split duplicate) owns its own
|
||||
// ChatWidget and therefore its own independent chat session.
|
||||
class ChatEditor : public Core::IEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ChatEditor(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry);
|
||||
~ChatEditor() override;
|
||||
|
||||
Core::IDocument *document() const override;
|
||||
QWidget *toolBar() override;
|
||||
Core::IEditor *duplicate() override;
|
||||
|
||||
void consumePendingChatFile();
|
||||
|
||||
private:
|
||||
QQmlEngine *m_engine;
|
||||
SessionFileRegistry *m_sessionFileRegistry;
|
||||
ChatDocument *m_document;
|
||||
ChatWidget *m_chatWidget;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
20
chat/ChatEditorFactory.cpp
Normal file
20
chat/ChatEditorFactory.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "ChatEditorFactory.hpp"
|
||||
|
||||
#include "ChatEditor.hpp"
|
||||
#include "QodeAssistConstants.hpp"
|
||||
#include "QodeAssisttr.h"
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
ChatEditorFactory::ChatEditorFactory(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry)
|
||||
{
|
||||
setId(Constants::QODE_ASSIST_CHAT_EDITOR_ID);
|
||||
setDisplayName(Tr::tr("QodeAssist Chat"));
|
||||
setEditorCreator(
|
||||
[engine, sessionFileRegistry] { return new ChatEditor(engine, sessionFileRegistry); });
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
20
chat/ChatEditorFactory.hpp
Normal file
20
chat/ChatEditorFactory.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (C) 2024-2026 Petr Mironychev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
class QQmlEngine;
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
class SessionFileRegistry;
|
||||
|
||||
class ChatEditorFactory : public Core::IEditorFactory
|
||||
{
|
||||
public:
|
||||
ChatEditorFactory(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry);
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
ChatOutputPane::ChatOutputPane(QQmlEngine* engine, QObject *parent)
|
||||
ChatOutputPane::ChatOutputPane(
|
||||
QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry, QObject *parent)
|
||||
: Core::IOutputPane(parent)
|
||||
, m_chatWidget{new ChatWidget{engine}}
|
||||
, m_chatWidget{new ChatWidget{engine, sessionFileRegistry}}
|
||||
{
|
||||
setId("QodeAssistChat");
|
||||
setDisplayName(Tr::tr("QodeAssist Chat"));
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
class SessionFileRegistry;
|
||||
|
||||
class ChatOutputPane : public Core::IOutputPane
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ChatOutputPane(QQmlEngine* engine, QObject *parent = nullptr);
|
||||
explicit ChatOutputPane(
|
||||
QQmlEngine *engine,
|
||||
SessionFileRegistry *sessionFileRegistry,
|
||||
QObject *parent = nullptr);
|
||||
~ChatOutputPane() override;
|
||||
|
||||
QWidget *outputWidget(QWidget *parent) override;
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
#include "NavigationPanel.hpp"
|
||||
|
||||
#include "ChatView/ChatWidget.hpp"
|
||||
#include "ChatView/SessionFileRegistry.hpp"
|
||||
#include "QodeAssistConstants.hpp"
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
NavigationPanel::NavigationPanel(QQmlEngine* engine)
|
||||
NavigationPanel::NavigationPanel(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry)
|
||||
: m_engine{engine}
|
||||
, m_sessionFileRegistry{sessionFileRegistry}
|
||||
{
|
||||
setDisplayName(tr("QodeAssist Chat"));
|
||||
setPriority(500);
|
||||
@@ -21,7 +23,7 @@ NavigationPanel::~NavigationPanel() {}
|
||||
|
||||
Core::NavigationView NavigationPanel::createWidget()
|
||||
{
|
||||
return {.widget = new ChatWidget{m_engine}};
|
||||
return {.widget = new ChatWidget{m_engine, m_sessionFileRegistry}};
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
|
||||
@@ -11,17 +11,20 @@ class QQmlEngine;
|
||||
|
||||
namespace QodeAssist::Chat {
|
||||
|
||||
class SessionFileRegistry;
|
||||
|
||||
class NavigationPanel : public Core::INavigationWidgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NavigationPanel(QQmlEngine* engine);
|
||||
explicit NavigationPanel(QQmlEngine *engine, SessionFileRegistry *sessionFileRegistry);
|
||||
~NavigationPanel();
|
||||
|
||||
Core::NavigationView createWidget() override;
|
||||
|
||||
private:
|
||||
QPointer<QQmlEngine> m_engine;
|
||||
QPointer<SessionFileRegistry> m_sessionFileRegistry;
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Chat
|
||||
|
||||
Reference in New Issue
Block a user