Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set delete button disable while ai anwsering. #88

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/plugins/codegeex/codegeexmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ void CodeGeeXManager::sendMessage(const QString &prompt)
}
QString machineId = QSysInfo::machineUniqueId();
askApi.postSSEChat(kUrlSSEChat, sessionId, prompt, machineId, history);

Q_EMIT chatStarted();
}

void CodeGeeXManager::onSessionCreated(const QString &talkId, bool isSuccessful)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/codegeex/codegeexmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CodeGeeXManager : public QObject
void createdNewSession();
void requestMessageUpdate(const MessageData &msg);
void requestToTransCode(const QString &code);
void chatStarted();
void chatFinished();

public Q_SLOTS:
Expand Down
9 changes: 0 additions & 9 deletions src/plugins/codegeex/data/messagedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ void MessageData::updateData(const QString &data)
if (lines.length() < msgDataLines.length())
return;

// QStringList newLines = lines.mid(msgDataLines.length());
// for (auto line : newLines) {
// if (line.startsWith("```")) {
// CodeData data;
// data.langueage = line.mid(3);
// codeDataList.append(data);
// }
// }

msgData = data;
msgDataLines = lines;
// qInfo() << "update msg line" << msgDataLines;
Expand Down
34 changes: 26 additions & 8 deletions src/plugins/codegeex/widgets/codegeexwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ void CodeGeeXWidget::toTranslateCode(const QString &code)
tabBar->setCurrentIndex(1);
}

void CodeGeeXWidget::onAnwserFinished()
{
if (deleteBtn)
deleteBtn->setEnabled(true);
if (createNewBtn)
createNewBtn->setEnabled(true);
}

void CodeGeeXWidget::onAnwserStarted()
{
if (deleteBtn)
deleteBtn->setEnabled(false);
if (createNewBtn)
createNewBtn->setEnabled(false);
}

void CodeGeeXWidget::initUI()
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Expand Down Expand Up @@ -119,6 +135,8 @@ void CodeGeeXWidget::initConnection()
connect(CodeGeeXManager::instance(), &CodeGeeXManager::loginSuccessed, this, &CodeGeeXWidget::onLoginSuccessed);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::createdNewSession, this, &CodeGeeXWidget::onNewSessionCreated);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::requestToTransCode, this, &CodeGeeXWidget::toTranslateCode);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::chatFinished, this, &CodeGeeXWidget::onAnwserFinished);
connect(CodeGeeXManager::instance(), &CodeGeeXManager::chatStarted, this, &CodeGeeXWidget::onAnwserStarted);
}

void CodeGeeXWidget::initAskWidget()
Expand All @@ -145,10 +163,10 @@ void CodeGeeXWidget::initAskWidget()
deleteBtn->setFlat(true);
deleteBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_del_hover.png")));
headerLayout->addWidget(deleteBtn);
historyBtn = new DPushButton(this);
historyBtn->setFlat(true);
historyBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_history_hover.png")));
headerLayout->addWidget(historyBtn);
// historyBtn = new DPushButton(this);
// historyBtn->setFlat(true);
// historyBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_history_hover.png")));
// headerLayout->addWidget(historyBtn);
createNewBtn = new DPushButton(this);
createNewBtn->setFlat(true);
createNewBtn->setIcon(QIcon(QPixmap(":/resoures/images/chat_icon_new_hover.png")));
Expand Down Expand Up @@ -211,25 +229,25 @@ void CodeGeeXWidget::initAskWidgetConnection()
stackWidget->setCurrentIndex(index + 1);
});
connect(deleteBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onDeleteBtnClicked);
connect(historyBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onHistoryBtnClicked);
// connect(historyBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onHistoryBtnClicked);
connect(createNewBtn, &DPushButton::clicked, this, &CodeGeeXWidget::onCreateNewBtnClicked);
}

void CodeGeeXWidget::resetHeaderBtns()
{
if (!deleteBtn || !historyBtn || !createNewBtn || !askPage)
if (!deleteBtn || /*!historyBtn ||*/ !createNewBtn || !askPage)
return;

switch (currentState) {
case AskPage:
deleteBtn->setVisible(!askPage->isIntroPageState());
createNewBtn->setVisible(!askPage->isIntroPageState());
historyBtn->setVisible(true);
// historyBtn->setVisible(true);
break;
case TrasnlatePage:
deleteBtn->setVisible(false);
createNewBtn->setVisible(false);
historyBtn->setVisible(false);
// historyBtn->setVisible(false);
break;
}
}
2 changes: 2 additions & 0 deletions src/plugins/codegeex/widgets/codegeexwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public Q_SLOTS:
void onHistoryBtnClicked();
void onCreateNewBtnClicked();
void toTranslateCode(const QString &code);
void onAnwserFinished();
void onAnwserStarted();

private:
void initUI();
Expand Down
Loading