|
4 | 4 | #include "StringHelper.h" |
5 | 5 | #include "RapidJsonHandler.h" |
6 | 6 | #include "ScintillaEditor.h" |
7 | | -#include "JsonHandler.h" |
| 7 | +#include "Profile.h" |
8 | 8 | #include <format> |
9 | 9 |
|
10 | 10 |
|
11 | | -JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData& nppData, int nCmdId) : |
12 | | - m_NppData(nppData), |
13 | | - DockingDlgInterface(IDD_TREEDLG), |
14 | | - m_nDlgId(nCmdId), |
15 | | - m_Editor(std::make_unique<ScintillaEditor>(nppData)), |
16 | | - m_hTreeView(std::make_unique<TreeViewCtrl>()) |
| 11 | +JsonViewDlg::JsonViewDlg(HINSTANCE hIntance, const NppData& nppData, int nCmdId, const std::wstring& path) |
| 12 | + : m_NppData(nppData) |
| 13 | + , DockingDlgInterface(IDD_TREEDLG) |
| 14 | + , m_nDlgId(nCmdId) |
| 15 | + , m_configPath(path) |
| 16 | + , m_Editor(std::make_unique<ScintillaEditor>(nppData)) |
| 17 | + , m_hTreeView(std::make_unique<TreeViewCtrl>()) |
17 | 18 | { |
18 | 19 | _hParent = nppData._nppHandle; |
19 | 20 | _hInst = hIntance; |
@@ -62,12 +63,10 @@ void JsonViewDlg::ShowDlg(bool bShow) |
62 | 63 |
|
63 | 64 | void JsonViewDlg::FormatJson() |
64 | 65 | { |
65 | | - // Get the current scintilla |
66 | | - const auto eol = m_Editor->GetEOL(); |
67 | | - const auto indent = m_Editor->GetIndent(); |
68 | 66 | const auto selectedText = m_Editor->GetJsonText(); |
| 67 | + const auto [le, lf, indentChar, indentLen] = GetFormatSetting(); |
69 | 68 |
|
70 | | - Result res = JsonHandler().FormatJson(selectedText, eol, indent.len, indent.ch); |
| 69 | + Result res = JsonHandler().FormatJson(selectedText, le, lf, indentChar, indentLen); |
71 | 70 |
|
72 | 71 | if (res.success) |
73 | 72 | { |
@@ -523,6 +522,50 @@ void JsonViewDlg::HandleTreeEvents(LPARAM lParam) |
523 | 522 | } |
524 | 523 | } |
525 | 524 |
|
| 525 | +auto JsonViewDlg::GetFormatSetting() const -> std::tuple<LE, LF, char, unsigned> |
| 526 | +{ |
| 527 | + // Default scintilla setting |
| 528 | + const auto eol = m_Editor->GetEOL(); |
| 529 | + auto [indentChar, indentLen] = m_Editor->GetIndent(); |
| 530 | + |
| 531 | + LE le = LE::kCrLf; |
| 532 | + LF lf = LF::kFormatDefault; |
| 533 | + |
| 534 | + switch (eol) |
| 535 | + { |
| 536 | + case 0: le = LE::kCrLf; break; |
| 537 | + case 1: le = LE::kCr; break; |
| 538 | + default: le = LE::kLf; break; |
| 539 | + } |
| 540 | + |
| 541 | + |
| 542 | + std::unique_ptr<Setting> pInfo = std::make_unique<Setting>(); |
| 543 | + if (ProfileSetting(m_configPath).GetSettings(*pInfo)) |
| 544 | + { |
| 545 | + lf = static_cast<LF>(pInfo->lf); |
| 546 | + |
| 547 | + switch (pInfo->le) |
| 548 | + { |
| 549 | + case LineEnding::WINDOWS: le = LE::kCrLf; break; |
| 550 | + case LineEnding::UNIX: le = LE::kLf; break; |
| 551 | + case LineEnding::MAC: le = LE::kCr; break; |
| 552 | + case LineEnding::AUTO: break; // Takes from Notepad++ |
| 553 | + default: break; // Takes from Notepad++ |
| 554 | + } |
| 555 | + |
| 556 | + |
| 557 | + switch (pInfo->indent.style) |
| 558 | + { |
| 559 | + case IndentStyle::TAB: indentChar = '\t'; indentLen = 1; break; |
| 560 | + case IndentStyle::SPACE: indentChar = ' '; indentLen = pInfo->indent.len; break; |
| 561 | + case IndentStyle::AUTO: break; // Takes from Notepad++ |
| 562 | + default: break; // Takes from Notepad++ |
| 563 | + } |
| 564 | + } |
| 565 | + |
| 566 | + return std::tuple<LE, LF, char, unsigned>(le, lf, indentChar, indentLen); |
| 567 | +} |
| 568 | + |
526 | 569 | INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) |
527 | 570 | { |
528 | 571 | switch (message) |
|
0 commit comments