diff --git a/CMakeLists.txt b/CMakeLists.txt index b01d7d0e..7aa0747a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ qt_add_qml_module(chat icons/copy.svg icons/settings.svg icons/edit.svg + icons/trash.svg icons/network.svg icons/thumbs_up.svg icons/thumbs_down.svg diff --git a/chatlistmodel.h b/chatlistmodel.h index bb0bd1b2..f95b4695 100644 --- a/chatlistmodel.h +++ b/chatlistmodel.h @@ -72,14 +72,22 @@ public: const bool chatIsCurrent = chat == m_currentChat; emit disconnectChat(chat); const int index = m_chats.indexOf(chat); + if (m_chats.count() < 2) { + addChat(); + } else { + int nextIndex; + if (index == m_chats.count() - 1) + nextIndex = index - 1; + else + nextIndex = index + 1; + Chat *nextChat = get(nextIndex); + Q_ASSERT(nextChat); + setCurrentChat(nextChat); + } beginRemoveRows(QModelIndex(), index, index); m_chats.removeAll(chat); endRemoveRows(); delete chat; - if (m_chats.isEmpty()) - addChat(); - else - setCurrentChat(m_chats.first()); } Chat *currentChat() const diff --git a/icons/trash.svg b/icons/trash.svg new file mode 100644 index 00000000..b7c1a141 --- /dev/null +++ b/icons/trash.svg @@ -0,0 +1,5 @@ + + diff --git a/qml/ChatDrawer.qml b/qml/ChatDrawer.qml index 284d9780..a1883634 100644 --- a/qml/ChatDrawer.qml +++ b/qml/ChatDrawer.qml @@ -77,8 +77,7 @@ Drawer { delegate: Rectangle { id: chatRectangle - anchors.left: parent.left - anchors.right: parent.right + width: conversationList.width height: chatName.height opacity: 0.9 property bool isCurrent: LLM.chatListModel.currentChat === LLM.chatListModel.get(index) @@ -88,7 +87,7 @@ Drawer { TextArea { id: chatName anchors.left: parent.left - anchors.right: editButton.left + anchors.right: buttons.left color: theme.textColor padding: 15 focus: false @@ -121,22 +120,40 @@ Drawer { } } } - Button { - id: editButton + Row { + id: buttons anchors.verticalCenter: chatName.verticalCenter anchors.right: chatRectangle.right anchors.rightMargin: 10 - width: 30 - height: 30 - visible: isCurrent - background: Image { + spacing: 10 + Button { + id: editButton width: 30 height: 30 - source: "qrc:/gpt4all/icons/edit.svg" + visible: isCurrent + background: Image { + width: 30 + height: 30 + source: "qrc:/gpt4all/icons/edit.svg" + } + onClicked: { + chatName.focus = true + chatName.readOnly = false + } } - onClicked: { - chatName.focus = true - chatName.readOnly = false + Button { + id: trashButton + width: 30 + height: 30 + visible: isCurrent + background: Image { + width: 30 + height: 30 + source: "qrc:/gpt4all/icons/trash.svg" + } + onClicked: { + LLM.chatListModel.removeChat(LLM.chatListModel.get(index)) + } } } }