Skip to content

Commit 14dfa49

Browse files
committed
Fix title update issue
1 parent 3d85bd1 commit 14dfa49

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ void JsonViewDlg::ShowDlg(bool bShow)
6767
DrawJsonTree();
6868
}
6969

70-
UpdateTitle();
7170
DockingDlgInterface::display(bShow);
7271
}
7372

7473
void JsonViewDlg::FormatJson()
7574
{
75+
UpdateTitle();
76+
7677
const auto selectedData = m_pEditor->GetJsonText();
7778
const auto selectedText = IsSelectionValidJson(selectedData);
7879

@@ -103,6 +104,8 @@ void JsonViewDlg::FormatJson()
103104

104105
void JsonViewDlg::CompressJson()
105106
{
107+
UpdateTitle();
108+
106109
const auto selectedData = m_pEditor->GetJsonText();
107110
const auto selectedText = IsSelectionValidJson(selectedData);
108111

@@ -131,6 +134,8 @@ void JsonViewDlg::CompressJson()
131134

132135
void JsonViewDlg::SortJsonByKey()
133136
{
137+
UpdateTitle();
138+
134139
const auto selectedData = m_pEditor->GetJsonText();
135140
const auto selectedText = IsSelectionValidJson(selectedData);
136141

@@ -287,13 +292,14 @@ void JsonViewDlg::HandleTabActivated()
287292
{
288293
FormatJson();
289294
}
290-
UpdateTitle();
291295
}
292296
}
293297
}
294298

295299
void JsonViewDlg::ValidateJson()
296300
{
301+
UpdateTitle();
302+
297303
const auto selectedData = m_pEditor->GetJsonText();
298304
const auto selectedText = IsSelectionValidJson(selectedData);
299305

@@ -324,6 +330,8 @@ void JsonViewDlg::ValidateJson()
324330

325331
void JsonViewDlg::DrawJsonTree()
326332
{
333+
UpdateTitle();
334+
327335
// Disable all buttons and treeView
328336
std::vector<DWORD> ctrls = {IDC_BTN_REFRESH, IDC_BTN_VALIDATE, IDC_BTN_FORMAT, IDC_BTN_SEARCH, IDC_EDT_SEARCH};
329337
EnableControls(ctrls, false);
@@ -526,28 +534,34 @@ void JsonViewDlg::SearchInTree()
526534

527535
void JsonViewDlg::UpdateTitle()
528536
{
529-
GetTitleFileName();
530-
updateDockingDlg();
531-
}
532-
533-
void JsonViewDlg::GetTitleFileName()
534-
{
535-
if (!m_pCurrFileName)
537+
const auto titleFileName = GetTitleFileName();
538+
if (!titleFileName.empty())
536539
{
537-
m_pCurrFileName = std::make_unique<wchar_t[]>(FILENAME_LEN_IN_TITLE);
540+
if (!m_pCurrFileName)
541+
{
542+
m_pCurrFileName = std::make_unique<wchar_t[]>(FILENAME_LEN_IN_TITLE);
543+
}
544+
545+
if (_wcsicmp(m_pCurrFileName.get(), titleFileName.c_str()) != 0)
546+
{
547+
memset(m_pCurrFileName.get(), 0, FILENAME_LEN_IN_TITLE);
548+
wcsncpy_s(m_pCurrFileName.get(), FILENAME_LEN_IN_TITLE, titleFileName.c_str(), _TRUNCATE);
549+
550+
updateDockingDlg();
551+
}
538552
}
553+
}
539554

555+
auto JsonViewDlg::GetTitleFileName() const -> std::wstring
556+
{
540557
auto currFile = m_pEditor->GetCurrentFileName();
541558
if (currFile.length() >= FILENAME_LEN_IN_TITLE)
542559
{
543560
// If the filename is too long, truncate it and add "..."
544561
currFile = currFile.substr(0, FILENAME_LEN_IN_TITLE - 4) + L"...";
545562
}
546563

547-
memset(m_pCurrFileName.get(), 0, FILENAME_LEN_IN_TITLE);
548-
wcsncpy_s(m_pCurrFileName.get(), FILENAME_LEN_IN_TITLE, currFile.c_str(), _TRUNCATE);
549-
550-
updateDockingDlg();
564+
return currFile;
551565
}
552566

553567
void JsonViewDlg::PrepareButtons()

src/NppJsonViewer/JsonViewDlg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class JsonViewDlg : public DockingDlgInterface
5454

5555
void SearchInTree();
5656

57-
void GetTitleFileName();
57+
auto GetTitleFileName() const -> std::wstring;
5858
void PrepareButtons();
5959
void SetIconAndTooltip(eButton ctrlType, const std::wstring &toolTip);
6060

0 commit comments

Comments
 (0)