|
8 | 8 | #include <format> |
9 | 9 |
|
10 | 10 |
|
11 | | -JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData& nppData, int nCmdId, const std::wstring& path) |
| 11 | +JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData& nppData, int nCmdId, std::shared_ptr<Setting>& pSetting) |
12 | 12 | : m_NppData(nppData) |
13 | 13 | , DockingDlgInterface(IDD_TREEDLG) |
14 | 14 | , m_nDlgId(nCmdId) |
15 | | - , m_configPath(path) |
16 | 15 | , m_Editor(std::make_unique<ScintillaEditor>(nppData)) |
17 | 16 | , m_hTreeView(std::make_unique<TreeViewCtrl>()) |
| 17 | + , m_pSetting(pSetting) |
18 | 18 | { |
19 | 19 | _hParent = nppData._nppHandle; |
20 | 20 | _hInst = hIntance; |
@@ -112,6 +112,23 @@ void JsonViewDlg::CompressJson() |
112 | 112 | } |
113 | 113 | } |
114 | 114 |
|
| 115 | +void JsonViewDlg::HandleTabActivated() |
| 116 | +{ |
| 117 | + const bool bIsVisible = isCreated() && isVisible(); |
| 118 | + if (bIsVisible && m_Editor->IsJsonFile()) |
| 119 | + { |
| 120 | + if (m_pSetting->follow_current_tab) |
| 121 | + { |
| 122 | + DrawJsonTree(); |
| 123 | + } |
| 124 | + |
| 125 | + if (m_pSetting->auto_format_on_open) |
| 126 | + { |
| 127 | + FormatJson(); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
115 | 132 | void JsonViewDlg::ValidateJson() |
116 | 133 | { |
117 | 134 | // Get the current scintilla |
@@ -468,7 +485,7 @@ auto JsonViewDlg::CopyPath() const -> std::wstring |
468 | 485 |
|
469 | 486 | int JsonViewDlg::ShowMessage(const std::wstring& title, const std::wstring& msg, int flag, bool bForceShow) |
470 | 487 | { |
471 | | - return (!m_isSilent || bForceShow) ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK; |
| 488 | + return bForceShow ? ::MessageBox(_hParent, msg.c_str(), title.c_str(), flag) : IDOK; |
472 | 489 | } |
473 | 490 |
|
474 | 491 | void JsonViewDlg::ToggleMenuItemState(bool bVisible) |
@@ -511,43 +528,63 @@ void JsonViewDlg::HandleTreeEvents(LPARAM lParam) |
511 | 528 |
|
512 | 529 | auto JsonViewDlg::GetFormatSetting() const -> std::tuple<LE, LF, char, unsigned> |
513 | 530 | { |
514 | | - // Default scintilla setting |
515 | | - const auto eol = m_Editor->GetEOL(); |
516 | | - auto [indentChar, indentLen] = m_Editor->GetIndent(); |
517 | | - |
518 | 531 | LE le = LE::kCrLf; |
519 | 532 | LF lf = LF::kFormatDefault; |
| 533 | + char indentChar = ' '; |
| 534 | + unsigned indentLen = 0; |
| 535 | + |
| 536 | + // Line formatting options |
| 537 | + lf = static_cast<LF>(m_pSetting->lf); |
520 | 538 |
|
521 | | - switch (eol) |
| 539 | + // End of line options |
| 540 | + switch (m_pSetting->le) |
522 | 541 | { |
523 | | - case 0: le = LE::kCrLf; break; |
524 | | - case 1: le = LE::kCr; break; |
525 | | - default: le = LE::kLf; break; |
526 | | - } |
| 542 | + case LineEnding::WINDOWS: |
| 543 | + le = LE::kCrLf; |
| 544 | + break; |
527 | 545 |
|
| 546 | + case LineEnding::UNIX: |
| 547 | + le = LE::kLf; |
| 548 | + break; |
528 | 549 |
|
529 | | - std::unique_ptr<Setting> pInfo = std::make_unique<Setting>(); |
530 | | - if (ProfileSetting(m_configPath).GetSettings(*pInfo)) |
531 | | - { |
532 | | - lf = static_cast<LF>(pInfo->lf); |
| 550 | + case LineEnding::MAC: |
| 551 | + le = LE::kCr; |
| 552 | + break; |
533 | 553 |
|
534 | | - switch (pInfo->le) |
| 554 | + // Takes from Notepad++ |
| 555 | + case LineEnding::AUTO: |
| 556 | + default: |
| 557 | + { |
| 558 | + const auto eol = m_Editor->GetEOL(); |
| 559 | + switch (eol) |
535 | 560 | { |
536 | | - case LineEnding::WINDOWS: le = LE::kCrLf; break; |
537 | | - case LineEnding::UNIX: le = LE::kLf; break; |
538 | | - case LineEnding::MAC: le = LE::kCr; break; |
539 | | - case LineEnding::AUTO: break; // Takes from Notepad++ |
540 | | - default: break; // Takes from Notepad++ |
| 561 | + case 0: le = LE::kCrLf; break; |
| 562 | + case 1: le = LE::kCr; break; |
| 563 | + default: le = LE::kLf; break; |
541 | 564 | } |
| 565 | + } |
| 566 | + } |
542 | 567 |
|
| 568 | + // Indentation options |
| 569 | + switch (m_pSetting->indent.style) |
| 570 | + { |
| 571 | + case IndentStyle::TAB: |
| 572 | + indentChar = '\t'; |
| 573 | + indentLen = 1; |
| 574 | + break; |
543 | 575 |
|
544 | | - switch (pInfo->indent.style) |
545 | | - { |
546 | | - case IndentStyle::TAB: indentChar = '\t'; indentLen = 1; break; |
547 | | - case IndentStyle::SPACE: indentChar = ' '; indentLen = pInfo->indent.len; break; |
548 | | - case IndentStyle::AUTO: break; // Takes from Notepad++ |
549 | | - default: break; // Takes from Notepad++ |
550 | | - } |
| 576 | + case IndentStyle::SPACE: |
| 577 | + indentChar = ' '; |
| 578 | + indentLen = m_pSetting->indent.len; |
| 579 | + break; |
| 580 | + |
| 581 | + // Takes from Notepad++ |
| 582 | + case IndentStyle::AUTO: |
| 583 | + default: |
| 584 | + const auto [c, l] = m_Editor->GetIndent(); |
| 585 | + indentChar = c; |
| 586 | + indentLen = l; |
| 587 | + break; |
551 | 588 | } |
552 | 589 |
|
553 | 590 | return std::tuple<LE, LF, char, unsigned>(le, lf, indentChar, indentLen); |
|
0 commit comments