Skip to content

Commit ffbb76d

Browse files
authored
Make Json highlighter configurable (#160)
1 parent cab7920 commit ffbb76d

File tree

7 files changed

+27
-8
lines changed

7 files changed

+27
-8
lines changed

NppJSONViewer/NppJsonViewer/Define.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const TCHAR STR_INI_FORMATTING_INDENTCOUNT[] = TEXT("INDENTATION_COUNT");
6262
const TCHAR STR_INI_OTHER_SEC[] = TEXT("Others");
6363
const TCHAR STR_INI_OTHER_FOLLOW_TAB[] = TEXT("FOLLOW_TAB");
6464
const TCHAR STR_INI_OTHER_AUTO_FORMAT[] = TEXT("AUTO_FORMAT");
65+
const TCHAR STR_INI_OTHER_USE_HIGHLIGHT[] = TEXT("USE_JSON_HIGHLIGHT");
6566
const TCHAR STR_INI_OTHER_IGNORE_COMMENT[] = TEXT("IGNORE_COMMENT");
6667
const TCHAR STR_INI_OTHER_IGNORE_COMMA[] = TEXT("IGNORE_TRAILLING_COMMA");
6768

@@ -109,5 +110,6 @@ struct Setting
109110
Indent indent {};
110111
bool bFollowCurrentTab = false;
111112
bool bAutoFormat = false;
113+
bool bUseJsonHighlight = true;
112114
ParseOptions parseOptions {};
113115
};

NppJSONViewer/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void JsonViewDlg::FormatJson()
7272
if (res.success)
7373
{
7474
m_Editor->ReplaceSelection(res.response);
75-
m_Editor->SetLangAsJson();
75+
HightlightAsJson();
7676
}
7777
else
7878
{
@@ -157,6 +157,13 @@ void JsonViewDlg::DrawJsonTree()
157157
EnableControls(ctrls, true);
158158
}
159159

160+
void JsonViewDlg::HightlightAsJson(bool bForcefully) const
161+
{
162+
bool setJsonLang = bForcefully || m_pSetting->bUseJsonHighlight;
163+
if (setJsonLang)
164+
m_Editor->SetLangAsJson();
165+
}
166+
160167
void JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string &jsonText)
161168
{
162169
RapidJsonHandler handler(this, tree_root);
@@ -183,7 +190,7 @@ void JsonViewDlg::PopulateTreeUsingSax(HTREEITEM tree_root, const std::string &j
183190
}
184191
else
185192
{
186-
m_Editor->SetLangAsJson();
193+
HightlightAsJson();
187194
}
188195
}
189196

NppJSONViewer/NppJsonViewer/JsonViewDlg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class JsonViewDlg : public DockingDlgInterface
3333

3434
private:
3535
void DrawJsonTree();
36+
void HightlightAsJson(bool bForcefully = false) const;
3637
void PopulateTreeUsingSax(HTREEITEM tree_root, const std::string &jsonText);
3738

3839
void ValidateJson();

NppJSONViewer/NppJsonViewer/Profile.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,34 @@ bool ProfileSetting::GetSettings(Setting &info) const
7474
bool bRetVal = true;
7575

7676
int nVal = 0;
77-
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_EOL, nVal);
77+
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_EOL, nVal, static_cast<int>(info.lineEnding));
7878
if (bRetVal)
7979
info.lineEnding = static_cast<LineEnding>(nVal);
8080

81-
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_LINE, nVal);
81+
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_LINE, nVal, static_cast<int>(info.lineFormat));
8282
if (bRetVal)
8383
info.lineFormat = static_cast<LineFormat>(nVal);
8484

85-
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_INDENT, nVal);
85+
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_INDENT, nVal, static_cast<int>(info.indent.style));
8686
if (bRetVal)
8787
info.indent.style = static_cast<IndentStyle>(nVal);
8888

8989
bRetVal &= ReadValue(STR_INI_FORMATTING_SEC, STR_INI_FORMATTING_INDENTCOUNT, nVal, info.indent.len);
9090
if (bRetVal)
9191
info.indent.len = nVal;
9292

93-
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_FOLLOW_TAB, nVal);
93+
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_FOLLOW_TAB, nVal, info.bFollowCurrentTab);
9494
if (bRetVal)
9595
info.bFollowCurrentTab = static_cast<bool>(nVal);
9696

97-
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_AUTO_FORMAT, nVal);
97+
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_AUTO_FORMAT, nVal, info.bAutoFormat);
9898
if (bRetVal)
9999
info.bAutoFormat = static_cast<bool>(nVal);
100100

101+
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_USE_HIGHLIGHT, nVal, info.bUseJsonHighlight);
102+
if (bRetVal)
103+
info.bUseJsonHighlight = static_cast<bool>(nVal);
104+
101105
bRetVal &= ReadValue(STR_INI_OTHER_SEC, STR_INI_OTHER_IGNORE_COMMENT, nVal, info.parseOptions.bIgnoreComment);
102106
if (bRetVal)
103107
info.parseOptions.bIgnoreComment = static_cast<bool>(nVal);
@@ -120,6 +124,7 @@ bool ProfileSetting::SetSettings(const Setting &info) const
120124

121125
bRetVal &= WriteValue(STR_INI_OTHER_SEC, STR_INI_OTHER_FOLLOW_TAB, info.bFollowCurrentTab);
122126
bRetVal &= WriteValue(STR_INI_OTHER_SEC, STR_INI_OTHER_AUTO_FORMAT, info.bAutoFormat);
127+
bRetVal &= WriteValue(STR_INI_OTHER_SEC, STR_INI_OTHER_USE_HIGHLIGHT, info.bUseJsonHighlight);
123128
bRetVal &= WriteValue(STR_INI_OTHER_SEC, STR_INI_OTHER_IGNORE_COMMENT, info.parseOptions.bIgnoreComment);
124129
bRetVal &= WriteValue(STR_INI_OTHER_SEC, STR_INI_OTHER_IGNORE_COMMA, info.parseOptions.bIgnoreTraillingComma);
125130

NppJSONViewer/NppJsonViewer/SettingsDlg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ bool SettingsDlg::Apply()
124124

125125
m_pSetting->bFollowCurrentTab = CUtility::GetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_FOLLOW_CURRENT_DOC));
126126
m_pSetting->bAutoFormat = CUtility::GetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_FORMAT_ON_OPEN));
127+
m_pSetting->bUseJsonHighlight = CUtility::GetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_JSON_HIGHLIGHT));
127128
m_pSetting->parseOptions.bIgnoreTraillingComma = CUtility::GetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_IGNORE_COMMA));
128129
m_pSetting->parseOptions.bIgnoreComment = CUtility::GetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_IGNORE_COMMENT));
129130

@@ -204,6 +205,7 @@ void SettingsDlg::InitDlg()
204205

205206
CUtility::SetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_FOLLOW_CURRENT_DOC), m_pSetting->bFollowCurrentTab);
206207
CUtility::SetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_FORMAT_ON_OPEN), m_pSetting->bAutoFormat);
208+
CUtility::SetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_JSON_HIGHLIGHT), m_pSetting->bUseJsonHighlight);
207209
CUtility::SetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_IGNORE_COMMA), m_pSetting->parseOptions.bIgnoreTraillingComma);
208210
CUtility::SetCheckboxStatus(::GetDlgItem(_hSelf, IDC_CHK_IGNORE_COMMENT), m_pSetting->parseOptions.bIgnoreComment);
209211
}

NppJSONViewer/NppJsonViewer/resource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define IDC_CHK_FORMAT_ON_OPEN 1029
4141
#define IDC_CHK_IGNORE_COMMA 1030
4242
#define IDC_CHK_IGNORE_COMMENT 1031
43+
#define IDC_CHK_JSON_HIGHLIGHT 1032
4344
#define IDM_COPY_TREEITEM 40001
4445
#define IDM_COPY_NODENAME 40002
4546
#define IDM_COPY_NODEVALUE 40003
@@ -53,7 +54,7 @@
5354
#ifndef APSTUDIO_READONLY_SYMBOLS
5455
#define _APS_NEXT_RESOURCE_VALUE 110
5556
#define _APS_NEXT_COMMAND_VALUE 40007
56-
#define _APS_NEXT_CONTROL_VALUE 1032
57+
#define _APS_NEXT_CONTROL_VALUE 1033
5758
#define _APS_NEXT_SYMED_VALUE 101
5859
#endif
5960
#endif

NppJSONViewer/NppJsonViewer/resource.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ BEGIN
103103
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,20,140,10
104104
CONTROL "Ignore trailing comma",IDC_CHK_IGNORE_COMMA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,33,140,10
105105
CONTROL "Ignore comments in json",IDC_CHK_IGNORE_COMMENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,46,140,10
106+
CONTROL "Use json highlighting",IDC_CHK_JSON_HIGHLIGHT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,59,140,10
106107
GROUPBOX " Indentation: ",IDC_STATIC,153,7,140,43
107108
CONTROL "Auto detect",IDC_RADIO_INDENT_AUTO,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,160,21,50,10
108109
CONTROL "Use tab",IDC_RADIO_INDENT_TAB,"Button",BS_AUTORADIOBUTTON,240,21,50,10

0 commit comments

Comments
 (0)