+ enh: inconsistent indentation option switch

This commit is contained in:
Rainer Kottenhoff 2018-11-06 16:30:10 +01:00
parent 4afc4fd0d4
commit ddc11d2ff1
16 changed files with 48 additions and 49 deletions

View File

@ -287,6 +287,12 @@
#define IDC_RICHEDITABOUT 18091
#define IDC_TRANSL_AUTH 18092
#define IDC_TRANSPARENT 18093
#define IDC_TAB_WIDTH 18094
#define IDC_INDENT_DEPTH 18095
#define IDC_TAB_AS_SPC 18096
#define IDC_TAB_INDENTS 18097
#define IDC_BACKTAB_INDENTS 18098
#define IDC_WARN_INCONSISTENT_INDENTS 18099
#define CMD_ESCAPE 20000
#define CMD_SHIFTESC 20001

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2117,30 +2117,26 @@ bool LongLineSettingsDlg(HWND hwnd,UINT uidDlg,int *iNumber)
INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
{
UNUSED(lParam);
switch(umsg)
{
case WM_INITDIALOG:
{
if (Globals.hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hDlgIcon); }
SetDlgItemInt(hwnd,100,Settings.TabWidth,false);
SendDlgItemMessage(hwnd,100,EM_LIMITTEXT,15,0);
SetDlgItemInt(hwnd,IDC_TAB_WIDTH,Settings.TabWidth,false);
SendDlgItemMessage(hwnd,IDC_TAB_WIDTH,EM_LIMITTEXT,15,0);
SetDlgItemInt(hwnd,101,Settings.IndentWidth,false);
SendDlgItemMessage(hwnd,101,EM_LIMITTEXT,15,0);
SetDlgItemInt(hwnd,IDC_INDENT_DEPTH,Settings.IndentWidth,false);
SendDlgItemMessage(hwnd,IDC_INDENT_DEPTH,EM_LIMITTEXT,15,0);
if (Settings.TabsAsSpaces)
CheckDlgButton(hwnd,102,BST_CHECKED);
if (Settings.TabIndents)
CheckDlgButton(hwnd,103,BST_CHECKED);
if (Settings.BackspaceUnindents)
CheckDlgButton(hwnd,104,BST_CHECKED);
CheckDlgButton(hwnd,IDC_TAB_AS_SPC, Settings.TabsAsSpaces ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd,IDC_TAB_INDENTS, Settings.TabIndents ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd,IDC_BACKTAB_INDENTS, Settings.BackspaceUnindents ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwnd,IDC_WARN_INCONSISTENT_INDENTS, Settings.WarnInconsistentIndents ? BST_CHECKED : BST_UNCHECKED);
CenterDlgInParent(hwnd);
}
return true;
@ -2149,47 +2145,36 @@ INT_PTR CALLBACK TabSettingsDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lPa
switch(LOWORD(wParam))
{
case IDOK: {
BOOL fTranslated1,fTranslated2;
UINT iNewTabWidth = GetDlgItemInt(hwnd,100,&fTranslated1,FALSE);
UINT iNewIndentWidth = GetDlgItemInt(hwnd,101,&fTranslated2,FALSE);
if (fTranslated1 && fTranslated2)
case IDOK:
{
Settings.TabWidth = iNewTabWidth;
Settings.IndentWidth = iNewIndentWidth;
Settings.TabsAsSpaces = (IsDlgButtonChecked(hwnd,102)) ? true : false;
Settings.TabIndents = (IsDlgButtonChecked(hwnd,103)) ? true : false;
Settings.BackspaceUnindents = (IsDlgButtonChecked(hwnd,104)) ? true : false;
EndDialog(hwnd,IDOK);
}
else
PostMessage(hwnd,WM_NEXTDLGCTL,(WPARAM)(GetDlgItem(hwnd,(fTranslated1) ? 101 : 100)),1);
BOOL fTranslated1, fTranslated2;
UINT const iNewTabWidth = GetDlgItemInt(hwnd, IDC_TAB_WIDTH, &fTranslated1, FALSE);
UINT const iNewIndentWidth = GetDlgItemInt(hwnd, IDC_INDENT_DEPTH, &fTranslated2, FALSE);
if (fTranslated1 && fTranslated2) {
Settings.TabWidth = iNewTabWidth;
Settings.IndentWidth = iNewIndentWidth;
Settings.TabsAsSpaces = (IsDlgButtonChecked(hwnd, IDC_TAB_AS_SPC)) ? true : false;
Settings.TabIndents = (IsDlgButtonChecked(hwnd, IDC_TAB_INDENTS)) ? true : false;
Settings.BackspaceUnindents = (IsDlgButtonChecked(hwnd, IDC_BACKTAB_INDENTS)) ? true : false;
Settings.WarnInconsistentIndents = (IsDlgButtonChecked(hwnd, IDC_WARN_INCONSISTENT_INDENTS)) ? true : false;
EndDialog(hwnd, IDOK);
}
else {
PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(hwnd, (fTranslated1) ? IDC_INDENT_DEPTH : IDC_TAB_WIDTH)), 1);
}
}
break;
case IDCANCEL:
EndDialog(hwnd,IDCANCEL);
break;
default:
break;
}
return true;
}
UNUSED(lParam);
return false;
}

View File

@ -951,13 +951,16 @@ void EditDetectIndentMode(HWND hwnd)
}
}
}
if (((tabCount > 0) && (spaceCount > 0)) // mismatch
|| (Settings.TabsAsSpaces && (tabCount > 0)) // existing tabs, should be replaced by spaces
|| (!Settings.TabsAsSpaces && (spaceCount > 0))) // indent space, should be populated with tabs
{
MessageBox(hwnd, L"Found Indentation Inconsistency.", L"Notepad3 - Inconsistent Indentation", MB_OK | MB_ICONEXCLAMATION);
if (Settings.WarnInconsistentIndents && !Style_IsCurLexerStandard()) {
if (((tabCount > 0) && (spaceCount > 0))
//|| (Settings.TabsAsSpaces && (tabCount > 0)) // existing tabs, should be replaced by spaces
//|| (!Settings.TabsAsSpaces && (spaceCount > 0)) // indent space, should be populated with tabs
) {
MessageBox(hwnd, L"Found Indentation Inconsistency.", L"Notepad3 - Inconsistent Indentation", MB_OK | MB_ICONEXCLAMATION);
}
}
// TODO: Set correct Indent mode
}
@ -1342,6 +1345,8 @@ bool EditSaveFile(
if (hFile == INVALID_HANDLE_VALUE)
return false;
EditDetectIndentMode(hwnd);
// ensure consistent line endings
if (Settings.FixLineEndings) {
EditEnsureConsistentLineEndings(hwnd);

View File

@ -6825,6 +6825,7 @@ void LoadSettings()
GET_BOOL_VALUE_FROM_INISECTION(BackspaceUnindents, false);
GET_INT_VALUE_FROM_INISECTION(TabWidth, 4, 1, 1024); g_iTabWidthG = Settings.TabWidth;
GET_INT_VALUE_FROM_INISECTION(IndentWidth, 4, 0, 1024); g_iIndentWidthG = Settings.IndentWidth;
GET_BOOL_VALUE_FROM_INISECTION(WarnInconsistentIndents, true);
GET_BOOL_VALUE_FROM_INISECTION(MarkLongLines, true);
GET_INT_VALUE_FROM_INISECTION(LongLinesLimit, 80, 0, LONG_LINES_MARKER_LIMIT); g_iLongLinesLimitG = Settings.LongLinesLimit;
GET_INT_VALUE_FROM_INISECTION(LongLineMode, EDGE_LINE, EDGE_LINE, EDGE_BACKGROUND);
@ -7191,6 +7192,7 @@ void SaveSettings(bool bSaveSettingsNow)
if (g_iIndentWidthG != Defaults.TabWidth) {
IniSectionSetInt(pIniSection, L"IndentWidth", g_iIndentWidthG);
}
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, WarnInconsistentIndents);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Bool, MarkLongLines);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLinesLimit);
SAVE_VALUE_IF_NOT_EQ_DEFAULT(Int, LongLineMode);

View File

@ -282,6 +282,7 @@ typedef struct _settings_t
bool BackspaceUnindents;
int TabWidth;
int IndentWidth;
bool WarnInconsistentIndents;
bool MarkLongLines;
int LongLinesLimit;
int LongLineMode;