@@ -67,12 +67,13 @@ void JsonViewDlg::ShowDlg(bool bShow)
6767 DrawJsonTree ();
6868 }
6969
70- UpdateTitle ();
7170 DockingDlgInterface::display (bShow);
7271}
7372
7473void 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
104105void 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
132135void 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
295299void 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
325331void 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
527535void 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
553567void JsonViewDlg::PrepareButtons ()
0 commit comments