From 31816de039657321b242c564a56c2e6d3e46286a Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 23 Apr 2018 16:55:32 +0200 Subject: [PATCH 1/5] + enh: dynamic status-bar sections --- src/Helpers.c | 2 +- src/Notepad3.c | 155 +++++++++++++++++++++++++++--------------------- src/Notepad3.h | 17 +++--- src/Notepad3.rc | 9 ++- src/resource.h | 37 ++++++------ 5 files changed, 124 insertions(+), 96 deletions(-) diff --git a/src/Helpers.c b/src/Helpers.c index c29ccd009..5ad793310 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1007,7 +1007,7 @@ int StatusCalcPaneWidth(HWND hwnd,LPCWSTR lpsz) SelectObject(hdc,hfold); ReleaseDC(hwnd,hdc); - return(size.cx + 9); + return(size.cx + 16); } diff --git a/src/Notepad3.c b/src/Notepad3.c index fe150dc55..84325a060 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1925,20 +1925,6 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) EndDeferWindowPos(hdwp); - // Statusbar width - int aWidth[7]; - aWidth[STATUS_DOCPOS] = max(120,min(cx*4/10, StatusCalcPaneWidth(g_hwndStatus, - L" Ln 9'999'999 : 9'999'999 Col 9'999'999:999 / 999 Sel 9'999'999 (999 Bytes) SelLn 9'999'999 Occ 9'999'999 "))); - aWidth[STATUS_DOCSIZE] = aWidth[STATUS_DOCPOS] + StatusCalcPaneWidth(g_hwndStatus,L" 9999 Bytes [UTF-8] "); - aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); - aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); - aWidth[STATUS_OVRMODE] = aWidth[STATUS_EOLMODE] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); - aWidth[STATUS_2ND_DEF] = aWidth[STATUS_OVRMODE] + StatusCalcPaneWidth(g_hwndStatus, L" 2ND "); - aWidth[STATUS_LEXER] = -1; - - - SendMessage(g_hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth); - UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); @@ -5872,8 +5858,13 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) switch (pnmm->dwItemSpec) { + case STATUS_DOCLINE: + case STATUS_DOCCOLUMN: + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_EDIT_GOTOLINE,1),0); + return true; + case STATUS_CODEPAGE: - SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_ENCODING_SELECT,1),0); + PostMessage(hwnd,WM_COMMAND,MAKELONG(IDM_ENCODING_SELECT,1),0); return true; case STATUS_EOLMODE: @@ -5886,7 +5877,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) i++; if (i > IDM_LINEENDINGS_CR) i = IDM_LINEENDINGS_CRLF; - SendMessage(hwnd,WM_COMMAND,MAKELONG(i,1),0); + PostMessage(hwnd,WM_COMMAND,MAKELONG(i,1),0); return true; case STATUS_OVRMODE: @@ -5894,11 +5885,11 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) return true; case STATUS_2ND_DEF: - SendMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); return true; case STATUS_LEXER: - SendMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_SCHEME, 1), 0); + PostMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_SCHEME, 1), 0); return true; default: @@ -7269,9 +7260,11 @@ void UpdateStatusbar() static WCHAR tchSelB[32] = { L'\0' }; static WCHAR tchOcc[32] = { L'\0' }; static WCHAR tchReplOccs[32] = { L'\0' }; - static WCHAR tchDocPos[128] = { L'\0' }; + static WCHAR tchDocLine[64] = { L'\0' }; + static WCHAR tchDocColumn[64] = { L'\0' }; + static WCHAR tchDocSelection[64] = { L'\0' }; + static WCHAR tchDocOccurrence[64] = { L'\0' }; static WCHAR tchFRStatus[128] = { L'\0' }; - static WCHAR tchBytes[64] = { L'\0' }; static WCHAR tchDocSize[64] = { L'\0' }; static WCHAR tchEncoding[64] = { L'\0' }; @@ -7357,13 +7350,81 @@ void UpdateStatusbar() FormatNumberStr(tchLinesSelected); } - if (!bMarkLongLines) { - FormatString(tchDocPos, COUNTOF(tchDocPos), IDS_DOCPOS, tchLn, tchLines, tchCol, tchSel, tchSelB, tchLinesSelected, tchOcc); + FormatString(tchDocLine, COUNTOF(tchDocLine), IDS_STATUS_DOCLINE, tchLn, tchLines); + + if (bMarkLongLines) + FormatString(tchDocColumn, COUNTOF(tchDocColumn), IDS_STATUS_DOCCOLUMN2, tchCol, tchCols); + else + FormatString(tchDocColumn, COUNTOF(tchDocColumn), IDS_STATUS_DOCCOLUMN, tchCol); + + FormatString(tchDocSelection, COUNTOF(tchDocSelection), IDS_STATUS_SELECTION, tchSel, tchSelB, tchLinesSelected); + + FormatString(tchDocOccurrence, COUNTOF(tchDocOccurrence), IDS_STATUS_OCCURRENCE, tchOcc); + + // get number of bytes in current encoding + StrFormatByteSize(iTextLength, tchBytes, COUNTOF(tchBytes)); + FormatString(tchDocSize, COUNTOF(tchDocSize), IDS_STATUS_DOCSIZE, tchBytes); + + Encoding_SetLabel(iEncoding); + StringCchPrintf(tchEncoding, COUNTOF(tchEncoding), L"%s", Encoding_GetLabel(iEncoding)); + + if (g_iEOLMode == SC_EOL_CR) + { + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"CR"); + } + else if (g_iEOLMode == SC_EOL_LF) + { + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"LF"); } else { - FormatString(tchDocPos, COUNTOF(tchDocPos), IDS_DOCPOS2, tchLn, tchLines, tchCol, tchCols, tchSel, tchSelB, tchLinesSelected, tchOcc); + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"CR+LF"); } - + if (SendMessage(g_hwndEdit, SCI_GETOVERTYPE, 0, 0)) + { + StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L"OVR"); + } + else { + StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L"INS"); + } + if (Style_GetUse2ndDefault()) + { + StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L"2ND"); + } + else { + StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L"STD"); + } + Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); + + // Statusbar width + int aWidth[10]; + // max(120, min(cx * 4 / 10, StatusCalcPaneWidth(g_hwndStatus, L" Ln 9'999'999 : 9'999'999 Col 9'999'999:999 / 999 Sel 9'999'999 (999 Bytes) SelLn 9'999'999 Occ 9'999'999 "))); + aWidth[STATUS_DOCLINE] = StatusCalcPaneWidth(g_hwndStatus, tchDocLine); + aWidth[STATUS_DOCCOLUMN] = aWidth[STATUS_DOCLINE] + StatusCalcPaneWidth(g_hwndStatus, tchDocColumn); + aWidth[STATUS_SELECTION] = aWidth[STATUS_DOCCOLUMN] + StatusCalcPaneWidth(g_hwndStatus, tchDocSelection); + aWidth[STATUS_OCCURRENCE] = aWidth[STATUS_SELECTION] + StatusCalcPaneWidth(g_hwndStatus, tchDocOccurrence); + aWidth[STATUS_DOCSIZE] = aWidth[STATUS_OCCURRENCE] + StatusCalcPaneWidth(g_hwndStatus, tchDocSize); + aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus, tchEncoding); + aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + StatusCalcPaneWidth(g_hwndStatus, tchEOLMode); + aWidth[STATUS_OVRMODE] = aWidth[STATUS_EOLMODE] + StatusCalcPaneWidth(g_hwndStatus, tchOvrMode); + aWidth[STATUS_2ND_DEF] = aWidth[STATUS_OVRMODE] + StatusCalcPaneWidth(g_hwndStatus, L"STD"); + aWidth[STATUS_LEXER] = -1; // tchLexerName + + SendMessage(g_hwndStatus, SB_SETPARTS, COUNTOF(aWidth), (LPARAM)aWidth); + + StatusSetText(g_hwndStatus, STATUS_DOCLINE, tchDocLine); + StatusSetText(g_hwndStatus, STATUS_DOCCOLUMN, tchDocColumn); + StatusSetText(g_hwndStatus, STATUS_SELECTION, tchDocSelection); + StatusSetText(g_hwndStatus, STATUS_OCCURRENCE, tchDocOccurrence); + StatusSetText(g_hwndStatus, STATUS_DOCSIZE, tchDocSize); + StatusSetText(g_hwndStatus, STATUS_CODEPAGE, tchEncoding); + StatusSetText(g_hwndStatus, STATUS_EOLMODE, tchEOLMode); + StatusSetText(g_hwndStatus, STATUS_OVRMODE, tchOvrMode); + StatusSetText(g_hwndStatus, STATUS_2ND_DEF, tch2ndDef); + StatusSetText(g_hwndStatus, STATUS_LEXER, tchLexerName); + //InvalidateRect(g_hwndStatus,NULL,true); + + // -------------------------------------------------------------------------- + // update Find/Replace dialog (if any) if (g_hwndDlgFindReplace) { if (iReplacedOccurrences > 0) @@ -7371,54 +7432,12 @@ void UpdateStatusbar() else StringCchCopy(tchReplOccs, COUNTOF(tchReplOccs), L"--"); - FormatString(tchFRStatus, COUNTOF(tchFRStatus), IDS_FR_STATUS_FMT, + FormatString(tchFRStatus, COUNTOF(tchFRStatus), IDS_FR_STATUS_FMT, tchLn, tchLines, tchCol, tchSel, tchOcc, tchReplOccs, FR_Status[g_FindReplaceMatchFoundState]); + SetWindowText(GetDlgItem(g_hwndDlgFindReplace, IDS_FR_STATUS_TEXT), tchFRStatus); } - // get number of bytes in current encoding - StrFormatByteSize(iTextLength, tchBytes, COUNTOF(tchBytes)); - FormatString(tchDocSize, COUNTOF(tchDocSize), IDS_DOCSIZE, tchBytes); - - Encoding_SetLabel(iEncoding); - StringCchPrintf(tchEncoding, COUNTOF(tchEncoding), L" %s ", Encoding_GetLabel(iEncoding)); - - if (g_iEOLMode == SC_EOL_CR) - { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR "); - } - else if (g_iEOLMode == SC_EOL_LF) - { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" LF "); - } - else { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR+LF "); - } - if (SendMessage(g_hwndEdit, SCI_GETOVERTYPE, 0, 0)) - { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" OVR "); - } - else { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" INS "); - } - if (Style_GetUse2ndDefault()) - { - StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L" 2ND "); - } - else { - StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L" STD "); - } - Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); - - StatusSetText(g_hwndStatus, STATUS_DOCPOS, tchDocPos); - StatusSetText(g_hwndStatus, STATUS_DOCSIZE, tchDocSize); - StatusSetText(g_hwndStatus, STATUS_CODEPAGE, tchEncoding); - StatusSetText(g_hwndStatus, STATUS_EOLMODE, tchEOLMode); - StatusSetText(g_hwndStatus, STATUS_OVRMODE, tchOvrMode); - StatusSetText(g_hwndStatus, STATUS_2ND_DEF, tch2ndDef); - StatusSetText(g_hwndStatus, STATUS_LEXER, tchLexerName); - - //InvalidateRect(g_hwndStatus,NULL,true); } diff --git a/src/Notepad3.h b/src/Notepad3.h index 87d220028..a13520abb 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -92,13 +92,16 @@ typedef enum { //==== Statusbar ============================================================== -#define STATUS_DOCPOS 0 -#define STATUS_DOCSIZE 1 -#define STATUS_CODEPAGE 2 -#define STATUS_EOLMODE 3 -#define STATUS_OVRMODE 4 -#define STATUS_2ND_DEF 5 -#define STATUS_LEXER 6 +#define STATUS_DOCLINE 0 +#define STATUS_DOCCOLUMN 1 +#define STATUS_SELECTION 2 +#define STATUS_OCCURRENCE 3 +#define STATUS_DOCSIZE 4 +#define STATUS_CODEPAGE 5 +#define STATUS_EOLMODE 6 +#define STATUS_OVRMODE 7 +#define STATUS_2ND_DEF 8 +#define STATUS_LEXER 9 #define STATUS_HELP 255 diff --git a/src/Notepad3.rc b/src/Notepad3.rc index e96a5ef9f..f8a89ecdb 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1466,9 +1466,12 @@ BEGIN IDS_UNTITLED "Untitled" IDS_TITLEEXCERPT """%s""" IDS_READONLY "(Read Only)" - IDS_DOCPOS " Ln %s / %s Col %s Sel %s (%s) SelLn %s Occ %s " - IDS_DOCPOS2 " Ln %s / %s Col %s / %s Sel %s (%s) SelLn %s Occ %s " - IDS_DOCSIZE " %s [UTF-8]" + IDS_STATUS_DOCLINE "Ln %s / %s" + IDS_STATUS_DOCCOLUMN "Col %s" + IDS_STATUS_DOCCOLUMN2 "Col %s / %s" + IDS_STATUS_SELECTION "Sel %s (%s) / %s [ln]" + IDS_STATUS_OCCURRENCE "Occ %s" + IDS_STATUS_DOCSIZE "%s [UTF-8]" IDS_LOADFILE "Loading ""%s""..." IDS_SAVEFILE "Saving ""%s""..." IDS_PRINTFILE "Printing page %i..." diff --git a/src/resource.h b/src/resource.h index 2272c95df..e02dffbd1 100644 --- a/src/resource.h +++ b/src/resource.h @@ -180,23 +180,26 @@ #define IDS_UNTITLED 10003 #define IDS_TITLEEXCERPT 10004 #define IDS_READONLY 10005 -#define IDS_DOCPOS 10006 -#define IDS_DOCPOS2 10007 -#define IDS_DOCSIZE 10008 -#define IDS_LOADFILE 10009 -#define IDS_SAVEFILE 10010 -#define IDS_PRINTFILE 10011 -#define IDS_SAVINGSETTINGS 10012 -#define IDS_LINKDESCRIPTION 10013 -#define IDS_FILTER_ALL 10014 -#define IDS_FILTER_EXE 10015 -#define IDS_FILTER_INI 10016 -#define IDS_OPENWITH 10017 -#define IDS_FAVORITES 10018 -#define IDS_BACKSLASHHELP 10019 -#define IDS_REGEXPHELP 10020 -#define IDS_WILDCARDHELP 10021 -#define IDS_FR_STATUS_FMT 10022 +#define IDS_STATUS_DOCLINE 10006 +#define IDS_STATUS_DOCCOLUMN 10007 +#define IDS_STATUS_DOCCOLUMN2 10008 +#define IDS_STATUS_SELECTION 10009 +#define IDS_STATUS_OCCURRENCE 10010 +#define IDS_STATUS_DOCSIZE 10011 +#define IDS_LOADFILE 10012 +#define IDS_SAVEFILE 10013 +#define IDS_PRINTFILE 10014 +#define IDS_SAVINGSETTINGS 10015 +#define IDS_LINKDESCRIPTION 10016 +#define IDS_FILTER_ALL 10017 +#define IDS_FILTER_EXE 10018 +#define IDS_FILTER_INI 10019 +#define IDS_OPENWITH 10020 +#define IDS_FAVORITES 10021 +#define IDS_BACKSLASHHELP 10022 +#define IDS_REGEXPHELP 10023 +#define IDS_WILDCARDHELP 10024 +#define IDS_FR_STATUS_FMT 10025 #define CMD_ESCAPE 20000 #define CMD_SHIFTESC 20001 #define CMD_SHIFTCTRLENTER 20002 From 05b4ec8c3d9cad896a23450f9a25f967c83e7e53 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 23 Apr 2018 20:03:57 +0200 Subject: [PATCH 2/5] + enh: new status bar dynamics --- src/Helpers.c | 14 +++++++------- src/Helpers.h | 2 +- src/Notepad3.c | 51 ++++++++++++++++++++++++++++++++++++++------------ src/Notepad3.h | 13 ------------- src/TypeDefs.h | 9 +++++++++ 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/Helpers.c b/src/Helpers.c index 5ad793310..96d61b999 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -993,21 +993,21 @@ COLORREF GetBackgroundColor(HWND hwnd) // // StatusCalcPaneWidth() // -int StatusCalcPaneWidth(HWND hwnd,LPCWSTR lpsz) +LONG StatusCalcPaneWidth(HWND hwnd,LPCWSTR lpsz) { - SIZE size; - HDC hdc = GetDC(hwnd); - HFONT hfont = (HFONT)SendMessage(hwnd,WM_GETFONT,0,0); - HFONT hfold = SelectObject(hdc,hfont); - int mmode = SetMapMode(hdc,MM_TEXT); + HDC const hdc = GetDC(hwnd); + HGDIOBJ const hfont = (HGDIOBJ)SendMessage(hwnd,WM_GETFONT,0,0); + HGDIOBJ const hfold = SelectObject(hdc,hfont); + int const mmode = SetMapMode(hdc,MM_TEXT); + SIZE size = { 0, 0 }; GetTextExtentPoint32(hdc,lpsz,lstrlen(lpsz),&size); SetMapMode(hdc,mmode); SelectObject(hdc,hfold); ReleaseDC(hwnd,hdc); - return(size.cx + 16); + return (size.cx + 16L); } diff --git a/src/Helpers.h b/src/Helpers.h index 29cd5272e..ce4f2058e 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -171,7 +171,7 @@ void DeleteBitmapButton(HWND,int); bool StatusSetText(HWND,UINT,LPCWSTR); bool StatusSetTextID(HWND,UINT,UINT); COLORREF GetBackgroundColor(HWND); -int StatusCalcPaneWidth(HWND,LPCWSTR); +LONG StatusCalcPaneWidth(HWND,LPCWSTR); int Toolbar_GetButtons(HWND,int,LPWSTR,int); int Toolbar_SetButtons(HWND,int,LPCWSTR,void*,int); diff --git a/src/Notepad3.c b/src/Notepad3.c index 84325a060..1316bc4a7 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1872,6 +1872,9 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) // MsgSize() - Handles WM_SIZE // // +static int g_aStatusSectorWidth[STATUS_SECTOR_COUNT] = { -1 }; + + void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) { @@ -1925,6 +1928,31 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) EndDeferWindowPos(hdwp); + // calculate average space for statusbar sectors + //g_aStatusSectorWidth[STATUS_DOCLINE] = StatusCalcPaneWidth(g_hwndStatus, L"Ln 9'999'/9'999"); + //g_aStatusSectorWidth[STATUS_DOCCOLUMN] = StatusCalcPaneWidth(g_hwndStatus, L"Col 999/999"); + //g_aStatusSectorWidth[STATUS_SELECTION] = StatusCalcPaneWidth(g_hwndStatus, L"Sel 9'999 (9999 Bytes)/999[ln]"); + //g_aStatusSectorWidth[STATUS_OCCURRENCE] = StatusCalcPaneWidth(g_hwndStatus, L"Occ 9'999"); + //g_aStatusSectorWidth[STATUS_DOCSIZE] = StatusCalcPaneWidth(g_hwndStatus, L"9'999 (Bytes)"); + //g_aStatusSectorWidth[STATUS_CODEPAGE] = StatusCalcPaneWidth(g_hwndStatus, L"Unicode (UTF-8)"); + //g_aStatusSectorWidth[STATUS_EOLMODE] = StatusCalcPaneWidth(g_hwndStatus, L"LF"); + //g_aStatusSectorWidth[STATUS_OVRMODE] = StatusCalcPaneWidth(g_hwndStatus, L"OVR"); + //g_aStatusSectorWidth[STATUS_2ND_DEF] = StatusCalcPaneWidth(g_hwndStatus, L"2ND"); + //g_aStatusSectorWidth[STATUS_LEXER] = StatusCalcPaneWidth(g_hwndStatus, L"Standard Lexer"); + + int const weight[STATUS_SECTOR_COUNT+1] = { 3, 3, 5, 3, 2, 2, 1, 1, 1, 3, 24 }; + g_aStatusSectorWidth[STATUS_DOCLINE] = (cx * weight[STATUS_DOCLINE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_DOCCOLUMN] = (cx * weight[STATUS_DOCCOLUMN]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_SELECTION] = (cx * weight[STATUS_SELECTION]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_OCCURRENCE] = (cx * weight[STATUS_OCCURRENCE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_DOCSIZE] = (cx * weight[STATUS_DOCSIZE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_CODEPAGE] = (cx * weight[STATUS_CODEPAGE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_EOLMODE] = (cx * weight[STATUS_EOLMODE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_OVRMODE] = (cx * weight[STATUS_OVRMODE]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_2ND_DEF] = (cx * weight[STATUS_2ND_DEF]) / weight[STATUS_SECTOR_COUNT]; + g_aStatusSectorWidth[STATUS_LEXER] = -1; //(cx * weight[STATUS_LEXER]) / weight[STATUS_SECTOR_COUNT]; + + UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); @@ -7396,18 +7424,17 @@ void UpdateStatusbar() Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); // Statusbar width - int aWidth[10]; - // max(120, min(cx * 4 / 10, StatusCalcPaneWidth(g_hwndStatus, L" Ln 9'999'999 : 9'999'999 Col 9'999'999:999 / 999 Sel 9'999'999 (999 Bytes) SelLn 9'999'999 Occ 9'999'999 "))); - aWidth[STATUS_DOCLINE] = StatusCalcPaneWidth(g_hwndStatus, tchDocLine); - aWidth[STATUS_DOCCOLUMN] = aWidth[STATUS_DOCLINE] + StatusCalcPaneWidth(g_hwndStatus, tchDocColumn); - aWidth[STATUS_SELECTION] = aWidth[STATUS_DOCCOLUMN] + StatusCalcPaneWidth(g_hwndStatus, tchDocSelection); - aWidth[STATUS_OCCURRENCE] = aWidth[STATUS_SELECTION] + StatusCalcPaneWidth(g_hwndStatus, tchDocOccurrence); - aWidth[STATUS_DOCSIZE] = aWidth[STATUS_OCCURRENCE] + StatusCalcPaneWidth(g_hwndStatus, tchDocSize); - aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus, tchEncoding); - aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + StatusCalcPaneWidth(g_hwndStatus, tchEOLMode); - aWidth[STATUS_OVRMODE] = aWidth[STATUS_EOLMODE] + StatusCalcPaneWidth(g_hwndStatus, tchOvrMode); - aWidth[STATUS_2ND_DEF] = aWidth[STATUS_OVRMODE] + StatusCalcPaneWidth(g_hwndStatus, L"STD"); - aWidth[STATUS_LEXER] = -1; // tchLexerName + int aWidth[STATUS_SECTOR_COUNT]; + aWidth[STATUS_DOCLINE] = max(g_aStatusSectorWidth[STATUS_DOCLINE], StatusCalcPaneWidth(g_hwndStatus, tchDocLine)); + aWidth[STATUS_DOCCOLUMN] = aWidth[STATUS_DOCLINE] + max(g_aStatusSectorWidth[STATUS_DOCCOLUMN], StatusCalcPaneWidth(g_hwndStatus, tchDocColumn)); + aWidth[STATUS_SELECTION] = aWidth[STATUS_DOCCOLUMN] + max(g_aStatusSectorWidth[STATUS_SELECTION], StatusCalcPaneWidth(g_hwndStatus, tchDocSelection)); + aWidth[STATUS_OCCURRENCE] = aWidth[STATUS_SELECTION] + max(g_aStatusSectorWidth[STATUS_OCCURRENCE], StatusCalcPaneWidth(g_hwndStatus, tchDocOccurrence)); + aWidth[STATUS_DOCSIZE] = aWidth[STATUS_OCCURRENCE] + max(g_aStatusSectorWidth[STATUS_DOCSIZE], StatusCalcPaneWidth(g_hwndStatus, tchDocSize)); + aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + max(g_aStatusSectorWidth[STATUS_CODEPAGE], StatusCalcPaneWidth(g_hwndStatus, tchEncoding)); + aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + max(g_aStatusSectorWidth[STATUS_EOLMODE], StatusCalcPaneWidth(g_hwndStatus, tchEOLMode)); + aWidth[STATUS_OVRMODE] = g_aStatusSectorWidth[STATUS_OVRMODE]; + aWidth[STATUS_2ND_DEF] = g_aStatusSectorWidth[STATUS_2ND_DEF]; + aWidth[STATUS_LEXER] = g_aStatusSectorWidth[STATUS_LEXER]; SendMessage(g_hwndStatus, SB_SETPARTS, COUNTOF(aWidth), (LPARAM)aWidth); diff --git a/src/Notepad3.h b/src/Notepad3.h index a13520abb..bda6c881c 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -91,19 +91,6 @@ typedef enum { #define IDC_REUSELOCK 0xFB06 -//==== Statusbar ============================================================== -#define STATUS_DOCLINE 0 -#define STATUS_DOCCOLUMN 1 -#define STATUS_SELECTION 2 -#define STATUS_OCCURRENCE 3 -#define STATUS_DOCSIZE 4 -#define STATUS_CODEPAGE 5 -#define STATUS_EOLMODE 6 -#define STATUS_OVRMODE 7 -#define STATUS_2ND_DEF 8 -#define STATUS_LEXER 9 -#define STATUS_HELP 255 - //==== Change Notifications =================================================== #define ID_WATCHTIMER 0xA000 diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 011aa3b57..2cb7a6144 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -77,6 +77,15 @@ typedef enum { FND_NOP = 0, NXT_NOT_FND, NXT_FND, NXT_WRP_FND, PRV_NOT_FND, PRV_ typedef enum { FRMOD_IGNORE = 0, FRMOD_NORM, FRMOD_WRAPED } FR_UPD_MODES; typedef enum { MBINFO = 0, MBWARN, MBYESNO, MBYESNOWARN, MBYESNOCANCEL, MBOKCANCEL, MBRETRYCANCEL } MBTYPES; + +//==== Statusbar ============================================================== +typedef enum { + STATUS_DOCLINE = 0, STATUS_DOCCOLUMN, STATUS_SELECTION, STATUS_OCCURRENCE, STATUS_DOCSIZE, + STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER, + STATUS_SECTOR_COUNT, + STATUS_HELP = 255 +} STATUS_SECTOR_T; + // -------------------------------------------------------------------------- typedef struct _editfindreplace From 950cfa9ad650e3941ecb004054abf4bb982a6a31 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 24 Apr 2018 12:43:19 +0200 Subject: [PATCH 3/5] + enh: configurable statusbar --- Build/Notepad3.ini | Bin 5210 -> 5366 bytes src/Dialogs.c | 18 +- src/Helpers.c | 4 +- src/Notepad3.c | 421 +++++++++++++++++++++++++-------------------- src/Notepad3.rc | 3 +- src/Styles.c | 9 +- src/TypeDefs.h | 8 +- src/resource.h | 33 ++-- 8 files changed, 274 insertions(+), 222 deletions(-) diff --git a/Build/Notepad3.ini b/Build/Notepad3.ini index f666dcc02d1806afd63b13f9ab4980afe344adaa..a5cb3e208b074b6f2780c4def1e525f867fe3dd2 100644 GIT binary patch delta 169 zcmcbm@lA6>A7{NaLoh=LLn08DG88j70a-;1{tN{`ekMaM5LYpzGNb_26aZzCfoxj_ z0|s6OE(TP6Nnm|pK=s8yoWzg=R2dA!$zXHx8S;SQAe{;fhCplt#Ku5u!k{3*U= 0) && (iID < STATUS_SECTOR_COUNT)) { + g_aStatusbarSectionWidth[iID] = (bStatusBarOptimizedSpace ? 0 : (cx * weight[iID])); + totalWeight += weight[iID]; + } + } + p = StrEnd(p) + 1; + } + // normalize + if (!bStatusBarOptimizedSpace) { + for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { + if (g_aStatusbarSectionWidth[i] > 0) { + g_aStatusbarSectionWidth[i] /= totalWeight; + } + } + } + lastCX = cx; +} + //============================================================================= // @@ -888,7 +953,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) bOpened = FileLoad(false, false, false, bSkipUnicodeDetection, bSkipANSICodePageDetection, tchFile); } else { - LPCWSTR lpFileToOpen = flagBufferFile ? szBufferFile : lpFileArg; + LPCWSTR lpFileToOpen = flagBufferFile ? g_szTmpFilePath : lpFileArg; bOpened = FileLoad(false, false, false, bSkipUnicodeDetection, bSkipANSICodePageDetection, lpFileToOpen); if (bOpened) { if (flagBufferFile) { @@ -907,8 +972,8 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) UpdateLineNumberWidth(); // check for temp file and delete - if (flagIsElevated && PathFileExists(szBufferFile)) { - DeleteFile(szBufferFile); + if (flagIsElevated && PathFileExists(g_szTmpFilePath)) { + DeleteFile(g_szTmpFilePath); } } if (flagJumpTo) { // Jump to position @@ -1049,6 +1114,9 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) iReplacedOccurrences = 0; g_iMarkOccurrencesCount = (g_iMarkOccurrences > 0) ? 0 : -1; + + _StatusbarSetSections(g_WinInfo.cx); + UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); @@ -1578,10 +1646,10 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) // Add normal Toolbar Bitmap hbmp = NULL; - if (StringCchLenW(tchToolbarBitmap,COUNTOF(tchToolbarBitmap))) + if (StringCchLenW(g_tchToolbarBitmap,COUNTOF(g_tchToolbarBitmap))) { - if (!SearchPath(NULL,tchToolbarBitmap,NULL,COUNTOF(szTmp),szTmp,NULL)) - StringCchCopy(szTmp,COUNTOF(szTmp),tchToolbarBitmap); + if (!SearchPath(NULL,g_tchToolbarBitmap,NULL,COUNTOF(szTmp),szTmp,NULL)) + StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmap); hbmp = LoadImage(NULL,szTmp,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE); } @@ -1602,10 +1670,10 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) // Optionally add hot Toolbar Bitmap hbmp = NULL; - if (StringCchLenW(tchToolbarBitmapHot,COUNTOF(tchToolbarBitmapHot))) + if (StringCchLenW(g_tchToolbarBitmapHot,COUNTOF(g_tchToolbarBitmapHot))) { - if (!SearchPath(NULL,tchToolbarBitmapHot,NULL,COUNTOF(szTmp),szTmp,NULL)) - StringCchCopy(szTmp,COUNTOF(szTmp),tchToolbarBitmapHot); + if (!SearchPath(NULL,g_tchToolbarBitmapHot,NULL,COUNTOF(szTmp),szTmp,NULL)) + StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmapHot); hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); if (hbmp) @@ -1620,10 +1688,10 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) // Optionally add disabled Toolbar Bitmap hbmp = NULL; - if (StringCchLenW(tchToolbarBitmapDisabled,COUNTOF(tchToolbarBitmapDisabled))) + if (StringCchLenW(g_tchToolbarBitmapDisabled,COUNTOF(g_tchToolbarBitmapDisabled))) { - if (!SearchPath(NULL,tchToolbarBitmapDisabled,NULL,COUNTOF(szTmp),szTmp,NULL)) - StringCchCopy(szTmp,COUNTOF(szTmp),tchToolbarBitmapDisabled); + if (!SearchPath(NULL,g_tchToolbarBitmapDisabled,NULL,COUNTOF(szTmp),szTmp,NULL)) + StringCchCopy(szTmp,COUNTOF(szTmp),g_tchToolbarBitmapDisabled); hbmp = LoadImage(NULL, szTmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE); if (hbmp) @@ -1681,7 +1749,7 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) SendMessage(g_hwndToolbar,TB_ADDBUTTONS,NUMINITIALTOOLS,(LPARAM)tbbMainWnd); - if (Toolbar_SetButtons(g_hwndToolbar, IDT_FILE_NEW, tchToolbarButtons, tbbMainWnd, COUNTOF(tbbMainWnd)) == 0) { + if (Toolbar_SetButtons(g_hwndToolbar, IDT_FILE_NEW, g_tchToolbarButtons, tbbMainWnd, COUNTOF(tbbMainWnd)) == 0) { SendMessage(g_hwndToolbar, TB_ADDBUTTONS, NUMINITIALTOOLS, (LPARAM)tbbMainWnd); } SendMessage(g_hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc); @@ -1843,7 +1911,7 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) } // recreate toolbar and statusbar - Toolbar_GetButtons(g_hwndToolbar,IDT_FILE_NEW,tchToolbarButtons,COUNTOF(tchToolbarButtons)); + Toolbar_GetButtons(g_hwndToolbar,IDT_FILE_NEW,g_tchToolbarButtons,COUNTOF(g_tchToolbarButtons)); DestroyWindow(g_hwndToolbar); DestroyWindow(hwndReBar); @@ -1872,28 +1940,21 @@ void MsgThemeChanged(HWND hwnd,WPARAM wParam,LPARAM lParam) // MsgSize() - Handles WM_SIZE // // -static int g_aStatusSectorWidth[STATUS_SECTOR_COUNT] = { -1 }; - - void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) { - - RECT rc; - int x,y,cx,cy; - HDWP hdwp; - if (wParam == SIZE_MINIMIZED) return; - x = 0; - y = 0; + int x = 0; + int y = 0; - cx = LOWORD(lParam); - cy = HIWORD(lParam); + int cx = LOWORD(lParam); + int cy = HIWORD(lParam); if (bShowToolbar) { /* SendMessage(g_hwndToolbar,WM_SIZE,0,0); + RECT rc; GetWindowRect(g_hwndToolbar,&rc); y = (rc.bottom - rc.top); cy -= (rc.bottom - rc.top);*/ @@ -1912,12 +1973,13 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) if (bShowStatusbar) { + RECT rc; SendMessage(g_hwndStatus,WM_SIZE,0,0); GetWindowRect(g_hwndStatus,&rc); cy -= (rc.bottom - rc.top); } - hdwp = BeginDeferWindowPos(2); + HDWP hdwp = BeginDeferWindowPos(2); DeferWindowPos(hdwp,hwndEditFrame,NULL,x,y,cx,cy, SWP_NOZORDER | SWP_NOACTIVATE); @@ -1929,30 +1991,8 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) EndDeferWindowPos(hdwp); // calculate average space for statusbar sectors - //g_aStatusSectorWidth[STATUS_DOCLINE] = StatusCalcPaneWidth(g_hwndStatus, L"Ln 9'999'/9'999"); - //g_aStatusSectorWidth[STATUS_DOCCOLUMN] = StatusCalcPaneWidth(g_hwndStatus, L"Col 999/999"); - //g_aStatusSectorWidth[STATUS_SELECTION] = StatusCalcPaneWidth(g_hwndStatus, L"Sel 9'999 (9999 Bytes)/999[ln]"); - //g_aStatusSectorWidth[STATUS_OCCURRENCE] = StatusCalcPaneWidth(g_hwndStatus, L"Occ 9'999"); - //g_aStatusSectorWidth[STATUS_DOCSIZE] = StatusCalcPaneWidth(g_hwndStatus, L"9'999 (Bytes)"); - //g_aStatusSectorWidth[STATUS_CODEPAGE] = StatusCalcPaneWidth(g_hwndStatus, L"Unicode (UTF-8)"); - //g_aStatusSectorWidth[STATUS_EOLMODE] = StatusCalcPaneWidth(g_hwndStatus, L"LF"); - //g_aStatusSectorWidth[STATUS_OVRMODE] = StatusCalcPaneWidth(g_hwndStatus, L"OVR"); - //g_aStatusSectorWidth[STATUS_2ND_DEF] = StatusCalcPaneWidth(g_hwndStatus, L"2ND"); - //g_aStatusSectorWidth[STATUS_LEXER] = StatusCalcPaneWidth(g_hwndStatus, L"Standard Lexer"); - - int const weight[STATUS_SECTOR_COUNT+1] = { 3, 3, 5, 3, 2, 2, 1, 1, 1, 3, 24 }; - g_aStatusSectorWidth[STATUS_DOCLINE] = (cx * weight[STATUS_DOCLINE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_DOCCOLUMN] = (cx * weight[STATUS_DOCCOLUMN]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_SELECTION] = (cx * weight[STATUS_SELECTION]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_OCCURRENCE] = (cx * weight[STATUS_OCCURRENCE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_DOCSIZE] = (cx * weight[STATUS_DOCSIZE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_CODEPAGE] = (cx * weight[STATUS_CODEPAGE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_EOLMODE] = (cx * weight[STATUS_EOLMODE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_OVRMODE] = (cx * weight[STATUS_OVRMODE]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_2ND_DEF] = (cx * weight[STATUS_2ND_DEF]) / weight[STATUS_SECTOR_COUNT]; - g_aStatusSectorWidth[STATUS_LEXER] = -1; //(cx * weight[STATUS_LEXER]) / weight[STATUS_SECTOR_COUNT]; - - + _StatusbarSetSections(cx); + UpdateToolbar(); UpdateStatusbar(); UpdateLineNumberWidth(); @@ -2887,7 +2927,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) sei.fMask = 0; sei.hwnd = hwnd; sei.lpVerb = NULL; - sei.lpFile = tchFavoritesDir; + sei.lpFile = g_tchFavoritesDir; sei.lpParameters = NULL; sei.lpDirectory = NULL; sei.nShow = SW_SHOWNORMAL; @@ -6015,7 +6055,9 @@ void LoadSettings() WCHAR *pIniSection = LocalAlloc(LPTR, sizeof(WCHAR) * INISECTIONBUFCNT * HUGE_BUFFER); int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); - LoadIniSection(L"Settings",pIniSection,cchIniSection); + // -------------------------------------------------------------------------- + LoadIniSection(L"Settings", pIniSection, cchIniSection); + // -------------------------------------------------------------------------- bEnableSaveSettings = true; bSaveSettings = IniSectionGetBool(pIniSection,L"SaveSettings",true); @@ -6033,19 +6075,19 @@ void LoadSettings() g_efrData.bDotMatchAll = IniSectionGetBool(pIniSection, L"RegexDotMatchesAll", false); g_efrData.fuFlags = IniSectionGetUInt(pIniSection, L"efrData_fuFlags", 0); - if (!IniSectionGetString(pIniSection, L"OpenWithDir", L"", tchOpenWithDir, COUNTOF(tchOpenWithDir))) { - //SHGetSpecialFolderPath(NULL, tchOpenWithDir, CSIDL_DESKTOPDIRECTORY, true); - GetKnownFolderPath(&FOLDERID_Desktop, tchOpenWithDir, COUNTOF(tchOpenWithDir)); + if (!IniSectionGetString(pIniSection, L"OpenWithDir", L"", g_tchOpenWithDir, COUNTOF(g_tchOpenWithDir))) { + //SHGetSpecialFolderPath(NULL, g_tchOpenWithDir, CSIDL_DESKTOPDIRECTORY, true); + GetKnownFolderPath(&FOLDERID_Desktop, g_tchOpenWithDir, COUNTOF(g_tchOpenWithDir)); } else { - PathAbsoluteFromApp(tchOpenWithDir, NULL, COUNTOF(tchOpenWithDir), true); + PathAbsoluteFromApp(g_tchOpenWithDir, NULL, COUNTOF(g_tchOpenWithDir), true); } - if (!IniSectionGetString(pIniSection, L"Favorites", L"", tchFavoritesDir, COUNTOF(tchFavoritesDir))) { - //SHGetFolderPath(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,tchFavoritesDir); - GetKnownFolderPath(&FOLDERID_Favorites, tchFavoritesDir, COUNTOF(tchFavoritesDir)); + if (!IniSectionGetString(pIniSection, L"Favorites", L"", g_tchFavoritesDir, COUNTOF(g_tchFavoritesDir))) { + //SHGetFolderPath(NULL,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT,g_tchFavoritesDir); + GetKnownFolderPath(&FOLDERID_Favorites, g_tchFavoritesDir, COUNTOF(g_tchFavoritesDir)); } else { - PathAbsoluteFromApp(tchFavoritesDir, NULL, COUNTOF(tchFavoritesDir), true); + PathAbsoluteFromApp(g_tchFavoritesDir, NULL, COUNTOF(g_tchFavoritesDir), true); } iPathNameFormat = IniSectionGetInt(pIniSection,L"PathNameFormat",0); @@ -6195,7 +6237,7 @@ void LoadSettings() bTransparentModeAvailable = (bTransparentModeAvailable) ? true : false; // see TBBUTTON tbbMainWnd[] for initial/reset set of buttons - IniSectionGetString(pIniSection,L"ToolbarButtons", L"", tchToolbarButtons, COUNTOF(tchToolbarButtons)); + IniSectionGetString(pIniSection,L"ToolbarButtons", L"", g_tchToolbarButtons, COUNTOF(g_tchToolbarButtons)); bShowToolbar = IniSectionGetBool(pIniSection,L"ShowToolbar",true); @@ -6237,21 +6279,23 @@ void LoadSettings() xCustomSchemesDlg = IniSectionGetInt(pIniSection, L"CustomSchemesDlgPosX", 0); yCustomSchemesDlg = IniSectionGetInt(pIniSection, L"CustomSchemesDlgPosY", 0); + // -------------------------------------------------------------------------- LoadIniSection(L"Settings2",pIniSection,cchIniSection); + // -------------------------------------------------------------------------- bStickyWinPos = IniSectionGetInt(pIniSection,L"StickyWindowPosition",0); if (bStickyWinPos) bStickyWinPos = 1; IniSectionGetString(pIniSection,L"DefaultExtension",L"txt", - tchDefaultExtension,COUNTOF(tchDefaultExtension)); - StrTrim(tchDefaultExtension,L" \t.\""); + g_tchDefaultExtension,COUNTOF(g_tchDefaultExtension)); + StrTrim(g_tchDefaultExtension,L" \t.\""); IniSectionGetString(pIniSection,L"DefaultDirectory",L"", - tchDefaultDir,COUNTOF(tchDefaultDir)); + g_tchDefaultDir,COUNTOF(g_tchDefaultDir)); - ZeroMemory(tchFileDlgFilters,sizeof(WCHAR)*COUNTOF(tchFileDlgFilters)); + ZeroMemory(g_tchFileDlgFilters,sizeof(WCHAR)*COUNTOF(g_tchFileDlgFilters)); IniSectionGetString(pIniSection,L"FileDlgFilters",L"", - tchFileDlgFilters,COUNTOF(tchFileDlgFilters)-2); + g_tchFileDlgFilters,COUNTOF(g_tchFileDlgFilters)-2); dwFileCheckInverval = IniSectionGetInt(pIniSection,L"FileCheckInverval",2000); dwAutoReloadTimeout = IniSectionGetInt(pIniSection,L"AutoReloadTimeout",2000); @@ -6280,19 +6324,26 @@ void LoadSettings() iCurrentLineVerticalSlop = IniSectionGetInt(pIniSection, L"CurrentLineVerticalSlop", 5); iCurrentLineVerticalSlop = max(min(iCurrentLineVerticalSlop, 200), 0); + bStatusBarOptimizedSpace = IniSectionGetBool(pIniSection, L"StatusBarOptimizedSpace", false); + IniSectionGetString(pIniSection, L"StatusbarVisibleSections", STATUSBAR_DEFAULT_IDS, g_tchStatusbarSections, COUNTOF(g_tchStatusbarSections)); + + // -------------------------------------------------------------------------- LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection); + // -------------------------------------------------------------------------- IniSectionGetString(pIniSection,L"BitmapDefault",L"", - tchToolbarBitmap,COUNTOF(tchToolbarBitmap)); + g_tchToolbarBitmap,COUNTOF(g_tchToolbarBitmap)); IniSectionGetString(pIniSection,L"BitmapHot",L"", - tchToolbarBitmapHot,COUNTOF(tchToolbarBitmap)); + g_tchToolbarBitmapHot,COUNTOF(g_tchToolbarBitmap)); IniSectionGetString(pIniSection,L"BitmapDisabled",L"", - tchToolbarBitmapDisabled,COUNTOF(tchToolbarBitmap)); + g_tchToolbarBitmapDisabled,COUNTOF(g_tchToolbarBitmap)); int ResX = GetSystemMetrics(SM_CXSCREEN); int ResY = GetSystemMetrics(SM_CYSCREEN); + // -------------------------------------------------------------------------- LoadIniSection(L"Window", pIniSection, cchIniSection); + // -------------------------------------------------------------------------- WCHAR tchHighDpiToolBar[32] = { L'\0' }; StringCchPrintf(tchHighDpiToolBar,COUNTOF(tchHighDpiToolBar),L"%ix%i HighDpiToolBar", ResX, ResY); @@ -6404,9 +6455,9 @@ void SaveSettings(bool bSaveSettingsNow) { IniSectionSetBool(pIniSection, L"HideNonMatchedLines", g_efrData.bHideNonMatchedLines); IniSectionSetBool(pIniSection, L"RegexDotMatchesAll", g_efrData.bDotMatchAll); IniSectionSetInt(pIniSection, L"efrData_fuFlags", g_efrData.fuFlags); - PathRelativeToApp(tchOpenWithDir, wchTmp, COUNTOF(wchTmp), false, true, flagPortableMyDocs); + PathRelativeToApp(g_tchOpenWithDir, wchTmp, COUNTOF(wchTmp), false, true, flagPortableMyDocs); IniSectionSetString(pIniSection, L"OpenWithDir", wchTmp); - PathRelativeToApp(tchFavoritesDir, wchTmp, COUNTOF(wchTmp), false, true, flagPortableMyDocs); + PathRelativeToApp(g_tchFavoritesDir, wchTmp, COUNTOF(wchTmp), false, true, flagPortableMyDocs); IniSectionSetString(pIniSection, L"Favorites", wchTmp); IniSectionSetInt(pIniSection, L"PathNameFormat", iPathNameFormat); IniSectionSetBool(pIniSection, L"WordWrap", bWordWrapG); @@ -6483,9 +6534,9 @@ void SaveSettings(bool bSaveSettingsNow) { IniSectionSetInt(pIniSection, L"CustomSchemesDlgPosX", xCustomSchemesDlg); IniSectionSetInt(pIniSection, L"CustomSchemesDlgPosY", yCustomSchemesDlg); - Toolbar_GetButtons(g_hwndToolbar, IDT_FILE_NEW, tchToolbarButtons, COUNTOF(tchToolbarButtons)); - if (StringCchCompareX(tchToolbarButtons, TBBUTTON_DEFAULT_IDS) == 0) { tchToolbarButtons[0] = L'\0'; } - IniSectionSetString(pIniSection, L"ToolbarButtons", tchToolbarButtons); + Toolbar_GetButtons(g_hwndToolbar, IDT_FILE_NEW, g_tchToolbarButtons, COUNTOF(g_tchToolbarButtons)); + if (StringCchCompareX(g_tchToolbarButtons, TBBUTTON_DEFAULT_IDS) == 0) { g_tchToolbarButtons[0] = L'\0'; } + IniSectionSetString(pIniSection, L"ToolbarButtons", g_tchToolbarButtons); SaveIniSection(L"Settings", pIniSection); LocalFree(pIniSection); @@ -6626,11 +6677,11 @@ void ParseCommandLine() // Relaunch elevated else if (StrCmpNI(lp1,L"tmpfbuf=",CSTRLEN(L"tmpfbuf=")) == 0) { - StringCchCopyN(szBufferFile,COUNTOF(szBufferFile), + StringCchCopyN(g_szTmpFilePath,COUNTOF(g_szTmpFilePath), lp1 + CSTRLEN(L"tmpfbuf="),len - CSTRLEN(L"tmpfbuf=")); - TrimString(szBufferFile); - PathUnquoteSpaces(szBufferFile); - NormalizePathEx(szBufferFile,COUNTOF(szBufferFile)); + TrimString(g_szTmpFilePath); + PathUnquoteSpaces(g_szTmpFilePath); + NormalizePathEx(g_szTmpFilePath,COUNTOF(g_szTmpFilePath)); flagBufferFile = 1; } @@ -7278,31 +7329,13 @@ const static WCHAR* FR_Status[] = { L"[>--<]", L"[>>--]", L"[>>-+]", L"[+->]>", FR_STATES g_FindReplaceMatchFoundState = FND_NOP; +#define txtWidth 80 + void UpdateStatusbar() { - static WCHAR tchLn[32] = { L'\0' }; - static WCHAR tchLines[32] = { L'\0' }; - static WCHAR tchCol[32] = { L'\0' }; - static WCHAR tchCols[32] = { L'\0' }; - static WCHAR tchSel[32] = { L'\0' }; - static WCHAR tchSelB[32] = { L'\0' }; - static WCHAR tchOcc[32] = { L'\0' }; - static WCHAR tchReplOccs[32] = { L'\0' }; - static WCHAR tchDocLine[64] = { L'\0' }; - static WCHAR tchDocColumn[64] = { L'\0' }; - static WCHAR tchDocSelection[64] = { L'\0' }; - static WCHAR tchDocOccurrence[64] = { L'\0' }; - static WCHAR tchFRStatus[128] = { L'\0' }; - static WCHAR tchBytes[64] = { L'\0' }; - static WCHAR tchDocSize[64] = { L'\0' }; - static WCHAR tchEncoding[64] = { L'\0' }; + static WCHAR tchStatusBar[STATUS_SECTOR_COUNT][txtWidth]; - static WCHAR tchEOLMode[32] = { L'\0' }; - static WCHAR tchOvrMode[32] = { L'\0' }; - static WCHAR tch2ndDef[32] = { L'\0' }; - static WCHAR tchLexerName[128] = { L'\0' }; - static WCHAR tchLinesSelected[32] = { L'\0' }; - + static WCHAR tchFRStatus[128] = { L'\0' }; static WCHAR tchTmp[32] = { L'\0' }; if (!bShowStatusbar) { return; } @@ -7311,27 +7344,35 @@ void UpdateStatusbar() const DocPos iTextLength = SciCall_GetTextLength(); const int iEncoding = Encoding_Current(CPI_GET); + static WCHAR tchLn[32] = { L'\0' }; StringCchPrintf(tchLn, COUNTOF(tchLn), L"%td", SciCall_LineFromPosition(iPos) + 1); FormatNumberStr(tchLn); + static WCHAR tchLines[32] = { L'\0' }; StringCchPrintf(tchLines, COUNTOF(tchLines), L"%td", SciCall_GetLineCount()); FormatNumberStr(tchLines); DocPos iCol = SciCall_GetColumn(iPos) + 1; iCol += (DocPos)SendMessage(g_hwndEdit, SCI_GETSELECTIONNCARETVIRTUALSPACE, 0, 0); + static WCHAR tchCol[32] = { L'\0' }; StringCchPrintf(tchCol, COUNTOF(tchCol), L"%td", iCol); FormatNumberStr(tchCol); + static WCHAR tchCols[32] = { L'\0' }; if (bMarkLongLines) { StringCchPrintf(tchCols, COUNTOF(tchCols), L"%td", iLongLinesLimit); FormatNumberStr(tchCols); } + else { + tchCols[0] = L'\0'; + } - // Print number of selected chars in statusbar + // number of selected chars in statusbar const bool bIsSelEmpty = SciCall_IsSelectionEmpty(); const DocPos iSelStart = (bIsSelEmpty ? 0 : SciCall_GetSelectionStart()); const DocPos iSelEnd = (bIsSelEmpty ? 0 : SciCall_GetSelectionEnd()); - + static WCHAR tchSel[32] = { L'\0' }; + static WCHAR tchSelB[32] = { L'\0' }; if (!bIsSelEmpty && !SciCall_IsSelectionRectangle()) { const DocPos iSel = (DocPos)SendMessage(g_hwndEdit, SCI_COUNTCHARACTERS, iSelStart, iSelEnd); @@ -7344,8 +7385,26 @@ void UpdateStatusbar() tchSelB[0] = L'0'; tchSelB[1] = L'\0'; } - // Print number of occurrence marks found - if ((g_iMarkOccurrencesCount >= 0) && !g_bMarkOccurrencesMatchVisible) + // number of selected lines in statusbar + static WCHAR tchLinesSelected[32] = { L'\0' }; + if (bIsSelEmpty) { + tchLinesSelected[0] = L'-'; + tchLinesSelected[1] = L'-'; + tchLinesSelected[2] = L'\0'; + } + else { + const DocLn iLineStart = SciCall_LineFromPosition(iSelStart); + const DocLn iLineEnd = SciCall_LineFromPosition(iSelEnd); + const DocPos iStartOfLinePos = SciCall_PositionFromLine(iLineEnd); + DocLn iLinesSelected = (iLineEnd - iLineStart); + if ((iSelStart != iSelEnd) && (iStartOfLinePos != iSelEnd)) { iLinesSelected += 1; } + StringCchPrintf(tchLinesSelected, COUNTOF(tchLinesSelected), L"%i", iLinesSelected); + FormatNumberStr(tchLinesSelected); + } + + // number of occurrence marks found + static WCHAR tchOcc[32] = { L'\0' }; + if ((g_iMarkOccurrencesCount >= 0) && !g_bMarkOccurrencesMatchVisible) { if ((g_iMarkOccurrencesMaxCount < 0) || (g_iMarkOccurrencesCount < g_iMarkOccurrencesMaxCount)) { @@ -7362,97 +7421,83 @@ void UpdateStatusbar() StringCchCopy(tchOcc, COUNTOF(tchOcc), L"--"); } - // Print number of selected lines in statusbar - if (bIsSelEmpty) { - tchLinesSelected[0] = L'-'; - tchLinesSelected[1] = L'-'; - tchLinesSelected[2] = L'\0'; - } - else { - const DocLn iLineStart = SciCall_LineFromPosition(iSelStart); - const DocLn iLineEnd = SciCall_LineFromPosition(iSelEnd); - const DocPos iStartOfLinePos = SciCall_PositionFromLine(iLineEnd); - DocLn iLinesSelected = (iLineEnd - iLineStart); - if ((iSelStart != iSelEnd) && (iStartOfLinePos != iSelEnd)) { iLinesSelected += 1; } - StringCchPrintf(tchLinesSelected, COUNTOF(tchLinesSelected), L"%i", iLinesSelected); - FormatNumberStr(tchLinesSelected); - } + // -------------------------------------------------------------------------- - FormatString(tchDocLine, COUNTOF(tchDocLine), IDS_STATUS_DOCLINE, tchLn, tchLines); + FormatString(tchStatusBar[STATUS_DOCLINE], txtWidth, IDS_STATUS_DOCLINE, tchLn, tchLines); if (bMarkLongLines) - FormatString(tchDocColumn, COUNTOF(tchDocColumn), IDS_STATUS_DOCCOLUMN2, tchCol, tchCols); + FormatString(tchStatusBar[STATUS_DOCCOLUMN], txtWidth, IDS_STATUS_DOCCOLUMN2, tchCol, tchCols); else - FormatString(tchDocColumn, COUNTOF(tchDocColumn), IDS_STATUS_DOCCOLUMN, tchCol); + FormatString(tchStatusBar[STATUS_DOCCOLUMN], txtWidth, IDS_STATUS_DOCCOLUMN, tchCol); - FormatString(tchDocSelection, COUNTOF(tchDocSelection), IDS_STATUS_SELECTION, tchSel, tchSelB, tchLinesSelected); + FormatString(tchStatusBar[STATUS_SELECTION], txtWidth, IDS_STATUS_SELECTION, tchSel, tchSelB); + FormatString(tchStatusBar[STATUS_SELCTLINES], txtWidth, IDS_STATUS_SELCTLINES, tchLinesSelected); - FormatString(tchDocOccurrence, COUNTOF(tchDocOccurrence), IDS_STATUS_OCCURRENCE, tchOcc); + FormatString(tchStatusBar[STATUS_OCCURRENCE], txtWidth, IDS_STATUS_OCCURRENCE, tchOcc); // get number of bytes in current encoding + static WCHAR tchBytes[32] = { L'\0' }; StrFormatByteSize(iTextLength, tchBytes, COUNTOF(tchBytes)); - FormatString(tchDocSize, COUNTOF(tchDocSize), IDS_STATUS_DOCSIZE, tchBytes); + FormatString(tchStatusBar[STATUS_DOCSIZE], txtWidth, IDS_STATUS_DOCSIZE, tchBytes); Encoding_SetLabel(iEncoding); - StringCchPrintf(tchEncoding, COUNTOF(tchEncoding), L"%s", Encoding_GetLabel(iEncoding)); + StringCchPrintf(tchStatusBar[STATUS_CODEPAGE], txtWidth, L"%s", Encoding_GetLabel(iEncoding)); if (g_iEOLMode == SC_EOL_CR) { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"CR"); + StringCchCopy(tchStatusBar[STATUS_EOLMODE], txtWidth, L"CR"); } else if (g_iEOLMode == SC_EOL_LF) { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"LF"); + StringCchCopy(tchStatusBar[STATUS_EOLMODE], txtWidth, L"LF"); } else { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L"CR+LF"); + StringCchCopy(tchStatusBar[STATUS_EOLMODE], txtWidth, L"CR+LF"); } if (SendMessage(g_hwndEdit, SCI_GETOVERTYPE, 0, 0)) { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L"OVR"); + StringCchCopy(tchStatusBar[STATUS_OVRMODE], txtWidth, L"OVR"); } else { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L"INS"); + StringCchCopy(tchStatusBar[STATUS_OVRMODE], txtWidth, L"INS"); } if (Style_GetUse2ndDefault()) { - StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L"2ND"); + StringCchCopy(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"2ND"); } else { - StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L"STD"); + StringCchCopy(tchStatusBar[STATUS_2ND_DEF], txtWidth, L"STD"); } - Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); + Style_GetCurrentLexerName(tchStatusBar[STATUS_LEXER], txtWidth); // Statusbar width - int aWidth[STATUS_SECTOR_COUNT]; - aWidth[STATUS_DOCLINE] = max(g_aStatusSectorWidth[STATUS_DOCLINE], StatusCalcPaneWidth(g_hwndStatus, tchDocLine)); - aWidth[STATUS_DOCCOLUMN] = aWidth[STATUS_DOCLINE] + max(g_aStatusSectorWidth[STATUS_DOCCOLUMN], StatusCalcPaneWidth(g_hwndStatus, tchDocColumn)); - aWidth[STATUS_SELECTION] = aWidth[STATUS_DOCCOLUMN] + max(g_aStatusSectorWidth[STATUS_SELECTION], StatusCalcPaneWidth(g_hwndStatus, tchDocSelection)); - aWidth[STATUS_OCCURRENCE] = aWidth[STATUS_SELECTION] + max(g_aStatusSectorWidth[STATUS_OCCURRENCE], StatusCalcPaneWidth(g_hwndStatus, tchDocOccurrence)); - aWidth[STATUS_DOCSIZE] = aWidth[STATUS_OCCURRENCE] + max(g_aStatusSectorWidth[STATUS_DOCSIZE], StatusCalcPaneWidth(g_hwndStatus, tchDocSize)); - aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + max(g_aStatusSectorWidth[STATUS_CODEPAGE], StatusCalcPaneWidth(g_hwndStatus, tchEncoding)); - aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + max(g_aStatusSectorWidth[STATUS_EOLMODE], StatusCalcPaneWidth(g_hwndStatus, tchEOLMode)); - aWidth[STATUS_OVRMODE] = g_aStatusSectorWidth[STATUS_OVRMODE]; - aWidth[STATUS_2ND_DEF] = g_aStatusSectorWidth[STATUS_2ND_DEF]; - aWidth[STATUS_LEXER] = g_aStatusSectorWidth[STATUS_LEXER]; + int aStatusbarSections[STATUS_SECTOR_COUNT]; + int cnt = 0; + int totalWidth = 0; + for (int id = 0; id < STATUS_SECTOR_COUNT; ++id) { + if (g_aStatusbarSectionWidth[id] >= 0) { + totalWidth += max(g_aStatusbarSectionWidth[id], StatusCalcPaneWidth(g_hwndStatus, tchStatusBar[id])); + aStatusbarSections[cnt++] = totalWidth; + } + } - SendMessage(g_hwndStatus, SB_SETPARTS, COUNTOF(aWidth), (LPARAM)aWidth); + if (cnt > 0) { aStatusbarSections[cnt - 1] = -1; } + else { aStatusbarSections[0] = -1; bShowStatusbar = false; } - StatusSetText(g_hwndStatus, STATUS_DOCLINE, tchDocLine); - StatusSetText(g_hwndStatus, STATUS_DOCCOLUMN, tchDocColumn); - StatusSetText(g_hwndStatus, STATUS_SELECTION, tchDocSelection); - StatusSetText(g_hwndStatus, STATUS_OCCURRENCE, tchDocOccurrence); - StatusSetText(g_hwndStatus, STATUS_DOCSIZE, tchDocSize); - StatusSetText(g_hwndStatus, STATUS_CODEPAGE, tchEncoding); - StatusSetText(g_hwndStatus, STATUS_EOLMODE, tchEOLMode); - StatusSetText(g_hwndStatus, STATUS_OVRMODE, tchOvrMode); - StatusSetText(g_hwndStatus, STATUS_2ND_DEF, tch2ndDef); - StatusSetText(g_hwndStatus, STATUS_LEXER, tchLexerName); + SendMessage(g_hwndStatus, SB_SETPARTS, (WPARAM)cnt, (LPARAM)aStatusbarSections); + + cnt = 0; + for (int id = 0; id < STATUS_SECTOR_COUNT; ++id) { + if (g_aStatusbarSectionWidth[id] >= 0) { + StatusSetText(g_hwndStatus, cnt++, tchStatusBar[id]); + } + } //InvalidateRect(g_hwndStatus,NULL,true); // -------------------------------------------------------------------------- // update Find/Replace dialog (if any) + static WCHAR tchReplOccs[32] = { L'\0' }; if (g_hwndDlgFindReplace) { if (iReplacedOccurrences > 0) StringCchPrintf(tchReplOccs, COUNTOF(tchReplOccs), L"%i", iReplacedOccurrences); @@ -8133,9 +8178,9 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) if (bSaveAs || bSaveCopy || StringCchLenW(g_wchCurFile,COUNTOF(g_wchCurFile)) == 0) { WCHAR tchInitialDir[MAX_PATH] = { L'\0' }; - if (bSaveCopy && StringCchLenW(tchLastSaveCopyDir,COUNTOF(tchLastSaveCopyDir))) { - StringCchCopy(tchInitialDir,COUNTOF(tchInitialDir),tchLastSaveCopyDir); - StringCchCopy(tchFile,COUNTOF(tchFile),tchLastSaveCopyDir); + if (bSaveCopy && StringCchLenW(g_tchLastSaveCopyDir,COUNTOF(g_tchLastSaveCopyDir))) { + StringCchCopy(tchInitialDir,COUNTOF(tchInitialDir),g_tchLastSaveCopyDir); + StringCchCopy(tchFile,COUNTOF(tchFile),g_tchLastSaveCopyDir); PathCchAppend(tchFile,COUNTOF(tchFile),PathFindFileName(g_wchCurFile)); } else @@ -8161,8 +8206,8 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) UpdateLineNumberWidth(); } else { - StringCchCopy(tchLastSaveCopyDir,COUNTOF(tchLastSaveCopyDir),tchFile); - PathRemoveFileSpec(tchLastSaveCopyDir); + StringCchCopy(g_tchLastSaveCopyDir,COUNTOF(g_tchLastSaveCopyDir),tchFile); + PathRemoveFileSpec(g_tchLastSaveCopyDir); } } } @@ -8277,8 +8322,8 @@ bool OpenFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) StringCchCopy(tchInitialDir,COUNTOF(tchInitialDir),g_wchCurFile); PathRemoveFileSpec(tchInitialDir); } - else if (StringCchLenW(tchDefaultDir,COUNTOF(tchDefaultDir))) { - ExpandEnvironmentStrings(tchDefaultDir,tchInitialDir,COUNTOF(tchInitialDir)); + else if (StringCchLenW(g_tchDefaultDir,COUNTOF(g_tchDefaultDir))) { + ExpandEnvironmentStrings(g_tchDefaultDir,tchInitialDir,COUNTOF(tchInitialDir)); if (PathIsRelative(tchInitialDir)) { WCHAR tchModule[MAX_PATH] = { L'\0' }; GetModuleFileName(NULL,tchModule,COUNTOF(tchModule)); @@ -8301,7 +8346,7 @@ bool OpenFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | /* OFN_NOCHANGEDIR |*/ OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST | OFN_SHAREAWARE /*| OFN_NODEREFERENCELINKS*/; - ofn.lpstrDefExt = (StringCchLenW(tchDefaultExtension,COUNTOF(tchDefaultExtension))) ? tchDefaultExtension : NULL; + ofn.lpstrDefExt = (StringCchLenW(g_tchDefaultExtension,COUNTOF(g_tchDefaultExtension))) ? g_tchDefaultExtension : NULL; if (GetOpenFileName(&ofn)) { StringCchCopyN(lpstrFile,cchFile,szFile,COUNTOF(szFile)); @@ -8334,8 +8379,8 @@ bool SaveFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) StringCchCopy(tchInitialDir,COUNTOF(tchInitialDir),g_wchCurFile); PathRemoveFileSpec(tchInitialDir); } - else if (StringCchLenW(tchDefaultDir,COUNTOF(tchDefaultDir))) { - ExpandEnvironmentStrings(tchDefaultDir,tchInitialDir,COUNTOF(tchInitialDir)); + else if (StringCchLenW(g_tchDefaultDir,COUNTOF(g_tchDefaultDir))) { + ExpandEnvironmentStrings(g_tchDefaultDir,tchInitialDir,COUNTOF(tchInitialDir)); if (PathIsRelative(tchInitialDir)) { WCHAR tchModule[MAX_PATH] = { L'\0' }; GetModuleFileName(NULL,tchModule,COUNTOF(tchModule)); @@ -8357,7 +8402,7 @@ bool SaveFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) ofn.Flags = OFN_HIDEREADONLY /*| OFN_NOCHANGEDIR*/ | /*OFN_NODEREFERENCELINKS |*/ OFN_OVERWRITEPROMPT | OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST; - ofn.lpstrDefExt = (StringCchLenW(tchDefaultExtension,COUNTOF(tchDefaultExtension))) ? tchDefaultExtension : NULL; + ofn.lpstrDefExt = (StringCchLenW(g_tchDefaultExtension,COUNTOF(g_tchDefaultExtension))) ? g_tchDefaultExtension : NULL; if (GetSaveFileName(&ofn)) { StringCchCopyN(lpstrFile,cchFile,szNewFile,COUNTOF(szNewFile)); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index f8a89ecdb..a7437d88a 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1469,7 +1469,8 @@ BEGIN IDS_STATUS_DOCLINE "Ln %s / %s" IDS_STATUS_DOCCOLUMN "Col %s" IDS_STATUS_DOCCOLUMN2 "Col %s / %s" - IDS_STATUS_SELECTION "Sel %s (%s) / %s [ln]" + IDS_STATUS_SELECTION "Sel %s (%s)" + IDS_STATUS_SELCTLINES "SelLn %s" IDS_STATUS_OCCURRENCE "Occ %s" IDS_STATUS_DOCSIZE "%s [UTF-8]" IDS_LOADFILE "Loading ""%s""..." diff --git a/src/Styles.c b/src/Styles.c index 77d2e7232..8547310d5 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -4598,14 +4598,15 @@ void Style_SetIndentGuides(HWND hwnd,bool bShow) // // Style_GetFileOpenDlgFilter() // -extern WCHAR tchFileDlgFilters[5*1024]; +extern WCHAR g_tchFileDlgFilters[XXXL_BUFFER]; bool Style_GetOpenDlgFilterStr(LPWSTR lpszFilter,int cchFilter) { - if (StringCchLenW(tchFileDlgFilters,COUNTOF(tchFileDlgFilters)) == 0) - GetString(IDS_FILTER_ALL,lpszFilter,cchFilter); + if (StringCchLenW(g_tchFileDlgFilters, COUNTOF(g_tchFileDlgFilters)) == 0) { + GetString(IDS_FILTER_ALL, lpszFilter, cchFilter); + } else { - StringCchCopyN(lpszFilter,cchFilter,tchFileDlgFilters,cchFilter - 2); + StringCchCopyN(lpszFilter,cchFilter,g_tchFileDlgFilters,cchFilter - 2); StringCchCat(lpszFilter,cchFilter,L"||"); } PrepareFilterStr(lpszFilter); diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 2cb7a6144..66c35a53a 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -65,6 +65,7 @@ typedef enum BufferSizes LARGE_BUFFER = 512, HUGE_BUFFER = 1024, XHUGE_BUFFER = 2048, + XXXL_BUFFER = 4096, FILE_ARG_BUF = MAX_PATH + 2, FNDRPL_BUFFER = 1024, @@ -80,12 +81,15 @@ typedef enum { MBINFO = 0, MBWARN, MBYESNO, MBYESNOWARN, MBYESNOCANCEL, MBOKCANC //==== Statusbar ============================================================== typedef enum { - STATUS_DOCLINE = 0, STATUS_DOCCOLUMN, STATUS_SELECTION, STATUS_OCCURRENCE, STATUS_DOCSIZE, - STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER, + STATUS_DOCLINE = 0, STATUS_DOCCOLUMN, STATUS_SELECTION, STATUS_SELCTLINES, STATUS_OCCURRENCE, + STATUS_DOCSIZE, STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER, STATUS_SECTOR_COUNT, STATUS_HELP = 255 } STATUS_SECTOR_T; +#define STATUSBAR_DEFAULT_IDS L"0 1 2 3 4 5 6 7 8 9 10" +#define STATUSBAR_SECTOR_WEIGHTS { 2, 2, 3, 2, 2, 2, 2, 1, 1, 1, 3 } + // -------------------------------------------------------------------------- typedef struct _editfindreplace diff --git a/src/resource.h b/src/resource.h index e02dffbd1..2397aaf5a 100644 --- a/src/resource.h +++ b/src/resource.h @@ -184,22 +184,23 @@ #define IDS_STATUS_DOCCOLUMN 10007 #define IDS_STATUS_DOCCOLUMN2 10008 #define IDS_STATUS_SELECTION 10009 -#define IDS_STATUS_OCCURRENCE 10010 -#define IDS_STATUS_DOCSIZE 10011 -#define IDS_LOADFILE 10012 -#define IDS_SAVEFILE 10013 -#define IDS_PRINTFILE 10014 -#define IDS_SAVINGSETTINGS 10015 -#define IDS_LINKDESCRIPTION 10016 -#define IDS_FILTER_ALL 10017 -#define IDS_FILTER_EXE 10018 -#define IDS_FILTER_INI 10019 -#define IDS_OPENWITH 10020 -#define IDS_FAVORITES 10021 -#define IDS_BACKSLASHHELP 10022 -#define IDS_REGEXPHELP 10023 -#define IDS_WILDCARDHELP 10024 -#define IDS_FR_STATUS_FMT 10025 +#define IDS_STATUS_SELCTLINES 10010 +#define IDS_STATUS_OCCURRENCE 10011 +#define IDS_STATUS_DOCSIZE 10012 +#define IDS_LOADFILE 10013 +#define IDS_SAVEFILE 10014 +#define IDS_PRINTFILE 10015 +#define IDS_SAVINGSETTINGS 10016 +#define IDS_LINKDESCRIPTION 10017 +#define IDS_FILTER_ALL 10018 +#define IDS_FILTER_EXE 10019 +#define IDS_FILTER_INI 10020 +#define IDS_OPENWITH 10021 +#define IDS_FAVORITES 10022 +#define IDS_BACKSLASHHELP 10023 +#define IDS_REGEXPHELP 10024 +#define IDS_WILDCARDHELP 10025 +#define IDS_FR_STATUS_FMT 10026 #define CMD_ESCAPE 20000 #define CMD_SHIFTESC 20001 #define CMD_SHIFTCTRLENTER 20002 From 3a4c51c05ffa2f6c3808a65bae04be0dfecc8cd0 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 24 Apr 2018 12:55:25 +0200 Subject: [PATCH 4/5] + enh: Statusbar order configurable --- src/Notepad3.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 8347c4f46..d21bc787f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -837,6 +837,7 @@ static void __fastcall _InitWindowPosition(HWND hwnd) // // static int g_aStatusbarSectionWidth[STATUS_SECTOR_COUNT]; +static int g_aSBSOrder[STATUS_SECTOR_COUNT]; static void __fastcall _StatusbarSetSections(int cx) { @@ -846,6 +847,7 @@ static void __fastcall _StatusbarSetSections(int cx) // prepare sector array for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { g_aStatusbarSectionWidth[i] = -1; + g_aSBSOrder[i] = -1; } static WCHAR tchSectors[SMALL_BUFFER]; @@ -867,6 +869,7 @@ static void __fastcall _StatusbarSetSections(int cx) int const weight[STATUS_SECTOR_COUNT] = STATUSBAR_SECTOR_WEIGHTS; // fill width + int cnt = 0; int totalWeight = 1; p = tchSectors; while (*p) { @@ -875,6 +878,7 @@ static void __fastcall _StatusbarSetSections(int cx) if ((iID >= 0) && (iID < STATUS_SECTOR_COUNT)) { g_aStatusbarSectionWidth[iID] = (bStatusBarOptimizedSpace ? 0 : (cx * weight[iID])); totalWeight += weight[iID]; + g_aSBSOrder[cnt++] = iID; } } p = StrEnd(p) + 1; @@ -7470,12 +7474,14 @@ void UpdateStatusbar() } Style_GetCurrentLexerName(tchStatusBar[STATUS_LEXER], txtWidth); - // Statusbar width + // Statusbar widths int aStatusbarSections[STATUS_SECTOR_COUNT]; + int cnt = 0; int totalWidth = 0; - for (int id = 0; id < STATUS_SECTOR_COUNT; ++id) { - if (g_aStatusbarSectionWidth[id] >= 0) { + for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { + int const id = g_aSBSOrder[i]; + if ((id >= 0) && (g_aStatusbarSectionWidth[id] >= 0)) { totalWidth += max(g_aStatusbarSectionWidth[id], StatusCalcPaneWidth(g_hwndStatus, tchStatusBar[id])); aStatusbarSections[cnt++] = totalWidth; } @@ -7487,8 +7493,9 @@ void UpdateStatusbar() SendMessage(g_hwndStatus, SB_SETPARTS, (WPARAM)cnt, (LPARAM)aStatusbarSections); cnt = 0; - for (int id = 0; id < STATUS_SECTOR_COUNT; ++id) { - if (g_aStatusbarSectionWidth[id] >= 0) { + for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { + int const id = g_aSBSOrder[i]; + if ((id >= 0) && (g_aStatusbarSectionWidth[id] >= 0)) { StatusSetText(g_hwndStatus, cnt++, tchStatusBar[id]); } } From 9150fe96431918a1abd86cc745cf3ad7135d9dfb Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 24 Apr 2018 23:48:27 +0200 Subject: [PATCH 5/5] + fix: small issue reverting from "Focused View" --- src/Edit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Edit.c b/src/Edit.c index ccaefb9fa..706ed32ef 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6700,11 +6700,13 @@ void EditHideNotMarkedLineRange(HWND hwnd, DocPos iStartPos, DocPos iEndPos, boo IgnoreNotifyChangeEvent(); if (!bHideLines) { - SciCall_FoldAll(SC_FOLDACTION_EXPAND); SciCall_MarkerDeleteAll(MARKER_NP3_OCCUR_LINE); + DocLn const iLnCount = SciCall_GetLineCount(); + for (DocLn iLine = 0; iLine < iLnCount; ++iLine) { SciCall_SetFoldLevel(iLine, SC_FOLDLEVELBASE); } if (!g_bCodeFoldingAvailable) { SciCall_SetProperty("fold", "0"); } Style_SetFolding(hwnd, g_bCodeFoldingAvailable && g_bShowCodeFolding); EditApplyLexerStyle(hwnd, 0, -1); + SciCall_FoldAll(EXPAND); ObserveNotifyChangeEvent(); return; }