mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-06-06 14:29:18 -04:00
feat: Improve chat, status and message sending keys (#361)
This commit is contained in:
@@ -45,6 +45,7 @@ qt_add_qml_module(QodeAssistChatView
|
||||
icons/window-unlock.svg
|
||||
icons/chat-icon.svg
|
||||
icons/chat-pause-icon.svg
|
||||
icons/warning-icon.svg
|
||||
icons/new-chat-icon.svg
|
||||
icons/rules-icon.svg
|
||||
icons/context-icon.svg
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QKeySequence>
|
||||
#include <QMessageBox>
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
@@ -52,6 +53,21 @@ bool isChatEditor(Core::IEditor *editor)
|
||||
return editor && editor->document()
|
||||
&& editor->document()->id() == Utils::Id(Constants::QODE_ASSIST_CHAT_EDITOR_ID);
|
||||
}
|
||||
|
||||
QKeySequence sendMessageKeySequence()
|
||||
{
|
||||
auto command = Core::ActionManager::command(Constants::QODE_ASSIST_CHAT_SEND_MESSAGE);
|
||||
if (!command)
|
||||
return {};
|
||||
|
||||
QKeySequence sequence = command->keySequence();
|
||||
if (sequence.isEmpty()) {
|
||||
const QList<QKeySequence> defaults = command->defaultKeySequences();
|
||||
if (!defaults.isEmpty())
|
||||
sequence = defaults.constFirst();
|
||||
}
|
||||
return sequence;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ChatRootView::ChatRootView(QQuickItem *parent)
|
||||
@@ -76,6 +92,22 @@ ChatRootView::ChatRootView(QQuickItem *parent)
|
||||
this,
|
||||
[this]() { setIsSyncOpenFiles(Settings::chatAssistantSettings().linkOpenFiles()); });
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this] {
|
||||
if (auto sendCommand
|
||||
= Core::ActionManager::command(Constants::QODE_ASSIST_CHAT_SEND_MESSAGE)) {
|
||||
connect(
|
||||
sendCommand,
|
||||
&Core::Command::keySequenceChanged,
|
||||
this,
|
||||
&ChatRootView::sendShortcutTextChanged,
|
||||
Qt::UniqueConnection);
|
||||
}
|
||||
emit sendShortcutTextChanged();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
|
||||
auto &settings = Settings::generalSettings();
|
||||
|
||||
connect(
|
||||
@@ -743,6 +775,32 @@ void ChatRootView::calculateMessageTokensCount(const QString &message)
|
||||
m_tokenCounter->setMessage(message);
|
||||
}
|
||||
|
||||
bool ChatRootView::isSendShortcut(int key, int modifiers) const
|
||||
{
|
||||
const QKeySequence sequence = sendMessageKeySequence();
|
||||
if (sequence.isEmpty())
|
||||
return false;
|
||||
|
||||
const QKeyCombination combination = sequence[0];
|
||||
const int sequenceKey = combination.key();
|
||||
|
||||
const int relevantMask = Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier
|
||||
| Qt::MetaModifier;
|
||||
const int sequenceModifiers = combination.keyboardModifiers() & relevantMask;
|
||||
const int eventModifiers = modifiers & relevantMask;
|
||||
|
||||
const bool isReturnLike = sequenceKey == Qt::Key_Return || sequenceKey == Qt::Key_Enter;
|
||||
const bool keyMatches = key == sequenceKey
|
||||
|| (isReturnLike && (key == Qt::Key_Return || key == Qt::Key_Enter));
|
||||
|
||||
return keyMatches && eventModifiers == sequenceModifiers;
|
||||
}
|
||||
|
||||
QString ChatRootView::sendShortcutText() const
|
||||
{
|
||||
return sendMessageKeySequence().toString(QKeySequence::NativeText);
|
||||
}
|
||||
|
||||
void ChatRootView::setIsSyncOpenFiles(bool state)
|
||||
{
|
||||
if (m_isSyncOpenFiles != state) {
|
||||
|
||||
@@ -49,6 +49,7 @@ class ChatRootView : public QQuickItem
|
||||
Q_PROPERTY(int activeRulesCount READ activeRulesCount NOTIFY activeRulesCountChanged FINAL)
|
||||
Q_PROPERTY(bool useTools READ useTools WRITE setUseTools NOTIFY useToolsChanged FINAL)
|
||||
Q_PROPERTY(bool useThinking READ useThinking WRITE setUseThinking NOTIFY useThinkingChanged FINAL)
|
||||
Q_PROPERTY(QString sendShortcutText READ sendShortcutText NOTIFY sendShortcutTextChanged FINAL)
|
||||
|
||||
Q_PROPERTY(int currentMessageTotalEdits READ currentMessageTotalEdits NOTIFY currentMessageEditsStatsChanged FINAL)
|
||||
Q_PROPERTY(int currentMessageAppliedEdits READ currentMessageAppliedEdits NOTIFY currentMessageEditsStatsChanged FINAL)
|
||||
@@ -98,6 +99,8 @@ public:
|
||||
Q_INVOKABLE void showAddImageDialog();
|
||||
Q_INVOKABLE bool isImageFile(const QString &filePath) const;
|
||||
Q_INVOKABLE void calculateMessageTokensCount(const QString &message);
|
||||
Q_INVOKABLE bool isSendShortcut(int key, int modifiers) const;
|
||||
QString sendShortcutText() const;
|
||||
Q_INVOKABLE void setIsSyncOpenFiles(bool state);
|
||||
Q_INVOKABLE void openChatHistoryFolder();
|
||||
Q_INVOKABLE void openRulesFolder();
|
||||
@@ -218,6 +221,7 @@ signals:
|
||||
|
||||
void lastErrorMessageChanged();
|
||||
void lastInfoMessageChanged();
|
||||
void sendShortcutTextChanged();
|
||||
void activeRulesChanged();
|
||||
void activeRulesCountChanged();
|
||||
|
||||
|
||||
5
ChatView/icons/warning-icon.svg
Normal file
5
ChatView/icons/warning-icon.svg
Normal file
@@ -0,0 +1,5 @@
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M12 3L22 20H2L12 3Z" stroke="black" stroke-width="2" stroke-linejoin="round"/>
|
||||
<path d="M12 10V14" stroke="black" stroke-width="2" stroke-linecap="round"/>
|
||||
<path d="M12 17H12.01" stroke="black" stroke-width="2.4" stroke-linecap="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 350 B |
@@ -19,6 +19,9 @@ ChatRootView {
|
||||
colorGroup: SystemPalette.Active
|
||||
}
|
||||
|
||||
property bool hasActiveError: false
|
||||
readonly property color errorColor: "#d32f2f"
|
||||
|
||||
palette {
|
||||
window: sysPalette.window
|
||||
windowText: sysPalette.windowText
|
||||
@@ -411,11 +414,10 @@ ChatRootView {
|
||||
QQC.TextArea {
|
||||
id: messageInput
|
||||
|
||||
placeholderText: Qt.platform.os === "osx"
|
||||
? qsTr("Type your message here... (⌘+↩ to send)")
|
||||
: qsTr("Type your message here... (Ctrl+Enter to send)")
|
||||
placeholderText: qsTr("Type your message here... (%1 to send)").arg(root.sendShortcutText)
|
||||
placeholderTextColor: palette.mid
|
||||
color: palette.text
|
||||
wrapMode: TextArea.Wrap
|
||||
background: Rectangle {
|
||||
radius: 2
|
||||
color: palette.base
|
||||
@@ -494,6 +496,9 @@ ChatRootView {
|
||||
skillCommandPopup.dismiss()
|
||||
event.accepted = true
|
||||
}
|
||||
} else if (root.isSendShortcut(event.key, event.modifiers)) {
|
||||
root.sendChatMessage()
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -586,13 +591,21 @@ ChatRootView {
|
||||
Layout.preferredHeight: 40
|
||||
|
||||
isCompressing: root.isCompressing
|
||||
isProcessing: root.isRequestInProgress
|
||||
sendButton.onClicked: !root.isRequestInProgress ? root.sendChatMessage()
|
||||
: root.cancelRequest()
|
||||
sendButton.icon.source: !root.isRequestInProgress ? "qrc:/qt/qml/ChatView/icons/chat-icon.svg"
|
||||
: "qrc:/qt/qml/ChatView/icons/chat-pause-icon.svg"
|
||||
sendButton.text: !root.isRequestInProgress ? qsTr("Send") : qsTr("Stop")
|
||||
sendButtonTooltip.text: !root.isRequestInProgress ? qsTr("Send message to LLM %1").arg(Qt.platform.os === "osx" ? "Cmd+Return" : "Ctrl+Return")
|
||||
: qsTr("Stop")
|
||||
sendButton.icon.source: root.isRequestInProgress
|
||||
? ""
|
||||
: (root.hasActiveError ? "qrc:/qt/qml/ChatView/icons/warning-icon.svg"
|
||||
: "qrc:/qt/qml/ChatView/icons/chat-icon.svg")
|
||||
sendButton.text: root.isRequestInProgress ? qsTr("Stop") : qsTr("Send")
|
||||
sendButton.accentColor: (root.hasActiveError && !root.isRequestInProgress)
|
||||
? root.errorColor : "transparent"
|
||||
sendButtonTooltip.text: root.isRequestInProgress
|
||||
? qsTr("Stop")
|
||||
: (root.hasActiveError
|
||||
? root.lastErrorMessage
|
||||
: qsTr("Send message to LLM %1").arg(root.sendShortcutText))
|
||||
compressButton.onClicked: compressConfirmDialog.open()
|
||||
cancelCompressButton.onClicked: root.cancelCompression()
|
||||
syncOpenFiles {
|
||||
@@ -667,6 +680,7 @@ ChatRootView {
|
||||
}
|
||||
|
||||
function sendChatMessage() {
|
||||
root.hasActiveError = false
|
||||
root.sendMessage(fileMentionPopup.expandMentions(messageInput.text))
|
||||
messageInput.text = ""
|
||||
fileMentionPopup.clearMentions()
|
||||
@@ -689,13 +703,122 @@ ChatRootView {
|
||||
onAccepted: root.compressCurrentChat()
|
||||
}
|
||||
|
||||
Toast {
|
||||
id: errorToast
|
||||
z: 1000
|
||||
Rectangle {
|
||||
id: errorBanner
|
||||
|
||||
color: Qt.rgba(0.8, 0.2, 0.2, 0.9)
|
||||
border.color: Qt.darker(infoToast.color, 1.3)
|
||||
toastTextColor: "#FFFFFF"
|
||||
z: 1000
|
||||
visible: root.hasActiveError && root.lastErrorMessage.length > 0
|
||||
|
||||
width: parent.width / 2
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.rightMargin: 10
|
||||
anchors.bottomMargin: bottomBar.height + 48
|
||||
|
||||
height: visible ? errorRow.implicitHeight + 12 : 0
|
||||
|
||||
color: Qt.rgba(0.83, 0.18, 0.18, 0.96)
|
||||
radius: 6
|
||||
border.color: Qt.darker(color, 1.3)
|
||||
border.width: 1
|
||||
|
||||
RowLayout {
|
||||
id: errorRow
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.leftMargin: 10
|
||||
anchors.rightMargin: 6
|
||||
spacing: 8
|
||||
|
||||
TextEdit {
|
||||
Layout.fillWidth: true
|
||||
text: root.lastErrorMessage
|
||||
color: "#FFFFFF"
|
||||
font.pixelSize: 12
|
||||
wrapMode: TextEdit.Wrap
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
selectionColor: Qt.darker(errorBanner.color, 1.3)
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: copyErrorButton
|
||||
|
||||
property bool copied: false
|
||||
|
||||
Layout.alignment: Qt.AlignTop
|
||||
implicitWidth: copyErrorLabel.implicitWidth + 18
|
||||
implicitHeight: 22
|
||||
radius: 4
|
||||
color: copyErrorMouse.containsMouse ? Qt.rgba(1, 1, 1, 0.28)
|
||||
: Qt.rgba(1, 1, 1, 0.16)
|
||||
border.color: Qt.rgba(1, 1, 1, 0.45)
|
||||
border.width: 1
|
||||
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
|
||||
Text {
|
||||
id: copyErrorLabel
|
||||
|
||||
anchors.centerIn: parent
|
||||
text: copyErrorButton.copied ? qsTr("Copied") : qsTr("Copy")
|
||||
color: "#FFFFFF"
|
||||
font.pixelSize: 12
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: copyErrorMouse
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
root.copyToClipboard(root.lastErrorMessage)
|
||||
copyErrorButton.copied = true
|
||||
copyErrorResetTimer.restart()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: copyErrorResetTimer
|
||||
|
||||
interval: 1500
|
||||
onTriggered: copyErrorButton.copied = false
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: closeErrorButton
|
||||
|
||||
Layout.alignment: Qt.AlignTop
|
||||
implicitWidth: 22
|
||||
implicitHeight: 22
|
||||
radius: 4
|
||||
color: closeErrorMouse.containsMouse ? Qt.rgba(1, 1, 1, 0.28) : "transparent"
|
||||
border.color: Qt.rgba(1, 1, 1, 0.45)
|
||||
border.width: closeErrorMouse.containsMouse ? 1 : 0
|
||||
|
||||
Behavior on color { ColorAnimation { duration: 120 } }
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "✕"
|
||||
color: "#FFFFFF"
|
||||
font.pixelSize: 12
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: closeErrorMouse
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.hasActiveError = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Toast {
|
||||
@@ -735,7 +858,7 @@ ChatRootView {
|
||||
target: root
|
||||
function onLastErrorMessageChanged() {
|
||||
if (root.lastErrorMessage.length > 0) {
|
||||
errorToast.show(root.lastErrorMessage)
|
||||
root.hasActiveError = true
|
||||
}
|
||||
}
|
||||
function onLastInfoMessageChanged() {
|
||||
|
||||
@@ -19,6 +19,7 @@ Rectangle {
|
||||
property alias cancelCompressButton: cancelCompressButtonId
|
||||
|
||||
property bool isCompressing: false
|
||||
property bool isProcessing: false
|
||||
property alias sendButtonTooltip: sendButtonTooltipId
|
||||
|
||||
color: palette.window.hslLightness > 0.5 ?
|
||||
@@ -159,11 +160,25 @@ Rectangle {
|
||||
QoAButton {
|
||||
id: sendButtonId
|
||||
|
||||
leftPadding: root.isProcessing ? 22 : 4
|
||||
|
||||
icon {
|
||||
height: 15
|
||||
width: 15
|
||||
}
|
||||
|
||||
BusyIndicator {
|
||||
id: sendBusyIndicator
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 14
|
||||
height: 14
|
||||
running: root.isProcessing
|
||||
visible: root.isProcessing
|
||||
}
|
||||
|
||||
QoAToolTip {
|
||||
id: sendButtonTooltipId
|
||||
|
||||
|
||||
Reference in New Issue
Block a user