mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-06-25 15:02:03 +00:00
chat: fix issues with the initial "New Chat" (#2330)
* select the existing new chat if there already is one when "New Chat" is clicked * scroll to the new chat when "New Chat" is clicked * fix the "New Chat" being scrolled past the top of the chat list Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
parent
7e1e00f331
commit
fbbf810020
@ -15,18 +15,19 @@ ChatListModel *ChatListModel::globalInstance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChatListModel::ChatListModel()
|
ChatListModel::ChatListModel()
|
||||||
: QAbstractListModel(nullptr)
|
: QAbstractListModel(nullptr) {}
|
||||||
|
|
||||||
|
void ChatListModel::loadChats()
|
||||||
{
|
{
|
||||||
addChat();
|
addChat();
|
||||||
|
|
||||||
ChatsRestoreThread *thread = new ChatsRestoreThread;
|
ChatsRestoreThread *thread = new ChatsRestoreThread;
|
||||||
connect(thread, &ChatsRestoreThread::chatRestored, this, &ChatListModel::restoreChat);
|
connect(thread, &ChatsRestoreThread::chatRestored, this, &ChatListModel::restoreChat, Qt::QueuedConnection);
|
||||||
connect(thread, &ChatsRestoreThread::finished, this, &ChatListModel::chatsRestoredFinished);
|
connect(thread, &ChatsRestoreThread::finished, this, &ChatListModel::chatsRestoredFinished, Qt::QueuedConnection);
|
||||||
connect(thread, &ChatsRestoreThread::finished, thread, &QObject::deleteLater);
|
connect(thread, &ChatsRestoreThread::finished, thread, &QObject::deleteLater);
|
||||||
thread->start();
|
thread->start();
|
||||||
|
|
||||||
connect(MySettings::globalInstance(), &MySettings::serverChatChanged, this, &ChatListModel::handleServerEnabledChanged);
|
connect(MySettings::globalInstance(), &MySettings::serverChatChanged, this, &ChatListModel::handleServerEnabledChanged);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatListModel::removeChatFile(Chat *chat) const
|
void ChatListModel::removeChatFile(Chat *chat) const
|
||||||
|
@ -81,11 +81,15 @@ public:
|
|||||||
bool shouldSaveChatGPTChats() const;
|
bool shouldSaveChatGPTChats() const;
|
||||||
void setShouldSaveChatGPTChats(bool b);
|
void setShouldSaveChatGPTChats(bool b);
|
||||||
|
|
||||||
|
Q_INVOKABLE void loadChats();
|
||||||
|
|
||||||
Q_INVOKABLE void addChat()
|
Q_INVOKABLE void addChat()
|
||||||
{
|
{
|
||||||
// Don't add a new chat if we already have one
|
// Select the existing new chat if we already have one
|
||||||
if (m_newChat)
|
if (m_newChat) {
|
||||||
|
setCurrentChat(m_newChat);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new chat pointer and connect it to determine when it is populated
|
// Create a new chat pointer and connect it to determine when it is populated
|
||||||
m_newChat = new Chat(this);
|
m_newChat = new Chat(this);
|
||||||
@ -114,20 +118,6 @@ public:
|
|||||||
emit countChanged();
|
emit countChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNewChat(Chat* chat)
|
|
||||||
{
|
|
||||||
// Don't add a new chat if we already have one
|
|
||||||
if (m_newChat)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_newChat = chat;
|
|
||||||
connect(m_newChat->chatModel(), &ChatModel::countChanged,
|
|
||||||
this, &ChatListModel::newChatCountChanged);
|
|
||||||
connect(m_newChat, &Chat::nameChanged,
|
|
||||||
this, &ChatListModel::nameChanged);
|
|
||||||
setCurrentChat(m_newChat);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_INVOKABLE void removeChat(Chat* chat)
|
Q_INVOKABLE void removeChat(Chat* chat)
|
||||||
{
|
{
|
||||||
Q_ASSERT(chat != m_serverChat);
|
Q_ASSERT(chat != m_serverChat);
|
||||||
|
@ -39,7 +39,8 @@ Rectangle {
|
|||||||
text: qsTr("\uFF0B New chat")
|
text: qsTr("\uFF0B New chat")
|
||||||
Accessible.description: qsTr("Create a new chat")
|
Accessible.description: qsTr("Create a new chat")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
ChatListModel.addChat();
|
ChatListModel.addChat()
|
||||||
|
conversationList.positionViewAtIndex(0, ListView.Beginning)
|
||||||
Network.trackEvent("new_chat", {"number_of_chats": ChatListModel.count})
|
Network.trackEvent("new_chat", {"number_of_chats": ChatListModel.count})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,6 +61,9 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.rightMargin: 10
|
anchors.rightMargin: 10
|
||||||
model: ChatListModel
|
model: ChatListModel
|
||||||
|
|
||||||
|
Component.onCompleted: ChatListModel.loadChats()
|
||||||
|
|
||||||
ScrollBar.vertical: ScrollBar {
|
ScrollBar.vertical: ScrollBar {
|
||||||
parent: conversationList.parent
|
parent: conversationList.parent
|
||||||
anchors.top: conversationList.top
|
anchors.top: conversationList.top
|
||||||
|
Loading…
Reference in New Issue
Block a user