Skip to content

Commit

Permalink
C4ChatDlg: Restore StdStrBuf for new title setting and add extra code…
Browse files Browse the repository at this point in the history
… to protect against a null title
  • Loading branch information
Fulgen301 committed Nov 30, 2024
1 parent 8c1ef1a commit bd6fcff
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/C4ChatDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,25 +856,28 @@ C4ChatControl::ChatSheet *C4ChatControl::OpenQuery(const char *szForNick, bool f

void C4ChatControl::UpdateTitle()
{
std::string newTitle;
StdStrBuf sNewTitle;
if (pTabMain->GetActiveSheetIndex() == 0)
{
// login title
newTitle = LoadResStr(C4ResStrTableKey::IDS_CHAT_NOTCONNECTED);
const std::string notConnected{LoadResStr(C4ResStrTableKey::IDS_CHAT_NOTCONNECTED)};
sNewTitle.Copy(notConnected.c_str(), notConnected.size());
}
else
{
// login by active sheet
ChatSheet *pActiveSheet = GetActiveChatSheet();
if (pActiveSheet)
{
newTitle = pActiveSheet->GetChatTitle();
sNewTitle = pActiveSheet->GetChatTitle();
}
else
sNewTitle = "";
}
// call update proc only if title changed
if (sTitle.isNull() || newTitle.compare(sTitle.getData()))
if (sTitle != sNewTitle)
{
sTitle.Copy(newTitle.c_str());
sTitle.Take(sNewTitle);
if (pTitleChangeBC) pTitleChangeBC->OnOK(sTitle);
}
}
Expand Down Expand Up @@ -1137,5 +1140,5 @@ void C4ChatDlg::UpdateSize()

void C4ChatDlg::OnChatTitleChange(const StdStrBuf &sNewTitle)
{
SetTitle(std::format("{} - {}", LoadResStr(C4ResStrTableKey::IDS_DLG_CHAT), sNewTitle.getData()).c_str());
SetTitle(std::format("{} - {}", LoadResStr(C4ResStrTableKey::IDS_DLG_CHAT), sNewTitle.isNull() ? "(null)" : sNewTitle.getData()).c_str());
}

0 comments on commit bd6fcff

Please sign in to comment.