--- a\np2src\Notepad2.ini Wed Apr 09 18:00:00 2008 +++ b\np2src\Notepad2.ini Sat Jul 05 16:17:06 2008 @@ -23,16 +23,17 @@ ShowIndentGuides= TabsAsSpaces= TabWidth= IndentWidth= MarkLongLines= LongLinesLimit= LongLineMode= ShowSelectionMargin= ShowLineNumbers= +ShowCodeFolding= ViewWhiteSpace= ViewEOLs= DefaultEncoding= SkipUnicodeDetection= DefaultEOLMode= FixLineEndings= PrintHeader= PrintFooter= --- a\np2src\src\Notepad2.c Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Notepad2.c Sat Jul 05 12:52:23 2008 @@ -50,16 +50,17 @@ HWND hwndReBar; HWND hwndEdit; HWND hwndMain; HWND hwndFindReplace = NULL; HWND hwndNextCBChain = NULL; HWND hDlgFindReplace = NULL; #define NUMTOOLBITMAPS 23 #define NUMINITIALTOOLS 24 +#define MARGIN_FOLD_INDEX 2 TBBUTTON tbbMainWnd[] = { {0,IDT_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {1,IDT_FILE_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {2,IDT_FILE_BROWSE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {3,IDT_FILE_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {0,0,0,TBSTYLE_SEP,0,0}, {4,IDT_EDIT_UNDO,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, {5,IDT_EDIT_REDO,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, @@ -115,16 +116,17 @@ BOOL bHiliteCurrentLine; BOOL bTabsAsSpaces; int iTabWidth; int iIndentWidth; BOOL bMarkLongLines; int iLongLinesLimit; int iLongLineMode; BOOL bShowSelectionMargin; BOOL bShowLineNumbers; +BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; int iDefaultEncoding; BOOL bSkipUnicodeDetection; int iDefaultEOLMode; BOOL bFixLineEndings; int iPrintHeader; int iPrintFooter; @@ -989,16 +991,35 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wPara // Margins SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,2,0); SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,1,(bShowSelectionMargin)?16:0); UpdateLineNumberWidth(); //SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,0, // (bShowLineNumbers)?SendMessage(hwndEdit,SCI_TEXTWIDTH,STYLE_LINENUMBER,(LPARAM)"_999999_"):0); + // Code folding + SendMessage(hwndEdit, SCI_SETMARGINTYPEN, MARGIN_FOLD_INDEX, SC_MARGIN_SYMBOL); + SendMessage(hwndEdit, SCI_SETMARGINMASKN, MARGIN_FOLD_INDEX, SC_MASK_FOLDERS); + SendMessage(hwndEdit, SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, (bShowCodeFolding) ? 11 : 0); + SendMessage(hwndEdit, SCI_SETPROPERTY, (WPARAM)"fold", (LPARAM)"1"); + SendMessage(hwndEdit, SCI_SETPROPERTY, (WPARAM)"fold.compact", (LPARAM)"0"); + SendMessage(hwndEdit, SCI_SETPROPERTY, (WPARAM)"fold.comment", (LPARAM)"1"); + SendMessage(hwndEdit, SCI_SETPROPERTY, (WPARAM)"fold.html", (LPARAM)"1"); + SendMessage(hwndEdit, SCI_SETPROPERTY, (WPARAM)"fold.preprocessor", (LPARAM)"1"); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED); + SendMessage(hwndEdit, SCI_MARKERDEFINE, SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER); + SendMessage(hwndEdit, SCI_SETFOLDFLAGS, 16, 0); + SendMessage(hwndEdit, SCI_SETMARGINSENSITIVEN, MARGIN_FOLD_INDEX, 1); + // Nonprinting characters SendMessage(hwndEdit,SCI_SETVIEWWS,(bViewWhiteSpace)?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE,0); SendMessage(hwndEdit,SCI_SETVIEWEOL,bViewEOLs,0); if (PrivateIsAppThemed()) { bIsAppThemed = TRUE; SetWindowLong(hwndEdit,GWL_EXSTYLE,GetWindowLong(hwndEdit,GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE); SetWindowPos(hwndEdit,NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); @@ -1433,16 +1454,17 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam CheckCmd(hmenu,IDM_VIEW_WORDWRAP,fWordWrap); CheckCmd(hmenu,IDM_VIEW_LONGLINEMARKER,bMarkLongLines); CheckCmd(hmenu,IDM_VIEW_TABSASSPACES,bTabsAsSpaces); CheckCmd(hmenu,IDM_VIEW_SHOWINDENTGUIDES,bShowIndentGuides); CheckCmd(hmenu,IDM_VIEW_AUTOINDENTTEXT,bAutoIndent); CheckCmd(hmenu,IDM_VIEW_LINENUMBERS,bShowLineNumbers); CheckCmd(hmenu,IDM_VIEW_MARGIN,bShowSelectionMargin); + CheckCmd(hmenu,IDM_VIEW_FOLDING,bShowCodeFolding); CheckCmd(hmenu,IDM_VIEW_SHOWWHITESPACE,bViewWhiteSpace); CheckCmd(hmenu,IDM_VIEW_SHOWEOLS,bViewEOLs); CheckCmd(hmenu,IDM_VIEW_WORDWRAPSYMBOLS,bShowWordWrapSymbols); CheckCmd(hmenu,IDM_VIEW_MATCHBRACES,bMatchBraces); CheckCmd(hmenu,IDM_VIEW_TOOLBAR,bShowToolbar); EnableCmd(hmenu,IDM_VIEW_CUSTOMIZETB,bShowToolbar); CheckCmd(hmenu,IDM_VIEW_STATUSBAR,bShowStatusbar); @@ -2802,16 +2824,22 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wPar case IDM_VIEW_MARGIN: bShowSelectionMargin = (bShowSelectionMargin) ? FALSE : TRUE; SendMessage(hwndEdit,SCI_SETMARGINWIDTHN,1,(bShowSelectionMargin)?16:0); break; + case IDM_VIEW_FOLDING: + bShowCodeFolding = (bShowCodeFolding) ? FALSE : TRUE; + SendMessage(hwndEdit, SCI_SETMARGINWIDTHN, MARGIN_FOLD_INDEX, (bShowCodeFolding) ? 11 : 0); + break; + + case IDM_VIEW_SHOWWHITESPACE: bViewWhiteSpace = (bViewWhiteSpace) ? FALSE : TRUE; SendMessage(hwndEdit,SCI_SETVIEWWS,(bViewWhiteSpace)?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE,0); break; case IDM_VIEW_SHOWEOLS: bViewEOLs = (bViewEOLs) ? FALSE : TRUE; @@ -3764,16 +3792,25 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wPara break; case SCN_SAVEPOINTLEFT: bModified = TRUE; SetWindowTitle(hwnd,uidsAppTitle,IDS_UNTITLED,szCurFile, iPathNameFormat,bModified || iCodePage != iInitialCP, IDS_READONLY,bReadOnly); break; + + case SCN_MARGINCLICK: + if (scn->margin == MARGIN_FOLD_INDEX) + { + int iCurLine = SendMessage(hwndEdit, SCI_LINEFROMPOSITION, scn->position, 0); + if (SendMessage(hwndEdit, SCI_GETFOLDLEVEL, iCurLine, 0) & SC_FOLDLEVELHEADERFLAG) + SendMessage(hwndEdit, SCI_TOGGLEFOLD, iCurLine, 0); + } + break; } break; case IDC_TOOLBAR: switch(pnmh->code) { @@ -4017,16 +4054,19 @@ void LoadSettings() iLongLineMode = max(min(iLongLineMode,EDGE_BACKGROUND),EDGE_LINE); bShowSelectionMargin = IniSectionGetInt(pIniSection,"ShowSelectionMargin",0); if (bShowSelectionMargin) bShowSelectionMargin = 1; bShowLineNumbers = IniSectionGetInt(pIniSection,"ShowLineNumbers",1); if (bShowLineNumbers) bShowLineNumbers = 1; + bShowCodeFolding = IniSectionGetInt(pIniSection,"ShowCodeFolding",0); + if (bShowCodeFolding) bShowCodeFolding = 1; + bViewWhiteSpace = IniSectionGetInt(pIniSection,"ViewWhiteSpace",0); if (bViewWhiteSpace) bViewWhiteSpace = 1; bViewEOLs = IniSectionGetInt(pIniSection,"ViewEOLs",0); if (bViewEOLs) bViewEOLs = 1; iDefaultEncoding = IniSectionGetInt(pIniSection,"DefaultEncoding",0); iDefaultEncoding = max(min(iDefaultEncoding,4),0); @@ -4225,16 +4265,17 @@ void SaveSettings(BOOL bSaveSettingsNow) IniSectionSetInt(pIniSection,"TabsAsSpaces",bTabsAsSpaces); IniSectionSetInt(pIniSection,"TabWidth",iTabWidth); IniSectionSetInt(pIniSection,"IndentWidth",iIndentWidth); IniSectionSetInt(pIniSection,"MarkLongLines",bMarkLongLines); IniSectionSetInt(pIniSection,"LongLinesLimit",iLongLinesLimit); IniSectionSetInt(pIniSection,"LongLineMode",iLongLineMode); IniSectionSetInt(pIniSection,"ShowSelectionMargin",bShowSelectionMargin); IniSectionSetInt(pIniSection,"ShowLineNumbers",bShowLineNumbers); + IniSectionSetInt(pIniSection,"ShowCodeFolding",bShowCodeFolding); IniSectionSetInt(pIniSection,"ViewWhiteSpace",bViewWhiteSpace); IniSectionSetInt(pIniSection,"ViewEOLs",bViewEOLs); IniSectionSetInt(pIniSection,"DefaultEncoding",iDefaultEncoding); IniSectionSetInt(pIniSection,"SkipUnicodeDetection",bSkipUnicodeDetection); IniSectionSetInt(pIniSection,"DefaultEOLMode",iDefaultEOLMode); IniSectionSetInt(pIniSection,"FixLineEndings",bFixLineEndings); IniSectionSetInt(pIniSection,"PrintHeader",iPrintHeader); IniSectionSetInt(pIniSection,"PrintFooter",iPrintFooter); --- a\np2src\src\Notepad2.rc Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Notepad2.rc Sat Jul 05 12:04:19 2008 @@ -238,16 +238,17 @@ BEGIN MENUITEM SEPARATOR MENUITEM "Visual &Brace Matching\tCtrl+Shift+V", IDM_VIEW_MATCHBRACES MENUITEM "Highlight C&urrent Line\tCtrl+Shift+I", IDM_VIEW_HILITECURRENTLINE MENUITEM SEPARATOR MENUITEM "Line &Numbers\tCtrl+Shift+N", IDM_VIEW_LINENUMBERS MENUITEM "Selection &Margin\tCtrl+Shift+M", IDM_VIEW_MARGIN + MENUITEM "Code &Folding\tCtrl+Shift+F", IDM_VIEW_FOLDING MENUITEM SEPARATOR MENUITEM "Zoom &In\tCtrl++", IDM_VIEW_ZOOMIN MENUITEM "Zoom &Out\tCtrl+-", IDM_VIEW_ZOOMOUT MENUITEM "Reset &Zoom\tCtrl+/", IDM_VIEW_RESETZOOM END POPUP "&Settings" BEGIN MENUITEM "Insert Tabs as &Spaces", IDM_VIEW_TABSASSPACES @@ -358,16 +359,18 @@ BEGIN "C", IDM_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT "C", IDM_EDIT_COPYALL, VIRTKEY, ALT, NOINVERT "C", IDM_EDIT_COPYLINE, VIRTKEY, SHIFT, CONTROL, NOINVERT "D", IDM_EDIT_DUPLICATELINE, VIRTKEY, CONTROL, NOINVERT "D", IDM_EDIT_SELECTIONDUPLICATE, VIRTKEY, ALT, NOINVERT "E", IDM_EDIT_DELETELINE, VIRTKEY, CONTROL, NOINVERT "F", IDM_EDIT_FIND, VIRTKEY, CONTROL, NOINVERT + "F", IDM_VIEW_FOLDING, VIRTKEY, SHIFT, CONTROL, + NOINVERT "G", IDM_EDIT_GOTOLINE, VIRTKEY, CONTROL, NOINVERT "G", IDM_VIEW_SHOWINDENTGUIDES, VIRTKEY, SHIFT, CONTROL, NOINVERT "H", IDM_EDIT_REPLACE, VIRTKEY, CONTROL, NOINVERT "H", IDM_FILE_RECENT, VIRTKEY, ALT, NOINVERT "H", IDM_VIEW_AUTOCLOSETAGS, VIRTKEY, SHIFT, CONTROL, NOINVERT "I", IDM_EDIT_SPLITLINES, VIRTKEY, CONTROL, NOINVERT --- a\np2src\src\resource.h Wed Apr 09 18:00:00 2008 +++ b\np2src\src\resource.h Sat Jul 05 11:58:55 2008 @@ -255,16 +255,17 @@ #define IDM_VIEW_SAVEBEFORERUNNINGTOOLS 40436 #define IDM_VIEW_NOSAVERECENT 40437 #define IDM_VIEW_NOSAVEFINDREPL 40438 #define IDM_VIEW_TOOLBAR 40439 #define IDM_VIEW_CUSTOMIZETB 40440 #define IDM_VIEW_STATUSBAR 40441 #define IDM_VIEW_SAVESETTINGS 40442 #define IDM_VIEW_SAVESETTINGSNOW 40443 +#define IDM_VIEW_FOLDING 40444 #define IDM_HELP_ABOUT 40500 #define IDM_TRAY_RESTORE 40600 #define IDM_TRAY_EXIT 40601 #define IDT_FILE_NEW 40700 #define IDT_FILE_OPEN 40701 #define IDT_FILE_BROWSE 40702 #define IDT_FILE_SAVE 40703 #define IDT_EDIT_UNDO 40704 --- a\np2src\src\Styles.c Wed Apr 09 18:00:00 2008 +++ b\np2src\src\Styles.c Sat Jul 05 16:16:55 2008 @@ -1494,23 +1494,58 @@ void Style_SetLexer(HWND hwnd,PEDITLEXER SendMessage(hwnd,SCI_SETCARETWIDTH,iValue,0); } if (SendMessage(hwnd,SCI_GETEDGEMODE,0,0) == EDGE_LINE) { if (Style_StrGetColor(TRUE,lexDefault.Styles[11+iIdx].szValue,&rgb)) // edge fore SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); - } + } else { if (Style_StrGetColor(FALSE,lexDefault.Styles[11+iIdx].szValue,&rgb)) // edge back SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); - } + } + + { // set folding style; braces are for scoping only + const int markers[] = + { + SC_MARKNUM_FOLDEROPEN, + SC_MARKNUM_FOLDER, + SC_MARKNUM_FOLDERSUB, + SC_MARKNUM_FOLDERTAIL, + SC_MARKNUM_FOLDEREND, + SC_MARKNUM_FOLDEROPENMID, + SC_MARKNUM_FOLDERMIDTAIL + }; + + int nmarkers = COUNTOF(markers); + + DWORD fore = SendMessage(hwnd, SCI_STYLEGETFORE, STYLE_DEFAULT, 0); + DWORD back = SendMessage(hwnd, SCI_STYLEGETBACK, STYLE_DEFAULT, 0); + + SendMessage(hwnd, SCI_SETFOLDMARGINCOLOUR, TRUE, back); + SendMessage(hwnd, SCI_SETFOLDMARGINHICOLOUR, TRUE, back); + + // Set marker color to the average of fore and back + fore = (((fore & 0xFF0000) + (back & 0xFF0000)) >> 1 & 0xFF0000) | + (((fore & 0x00FF00) + (back & 0x00FF00)) >> 1 & 0x00FF00) | + (((fore & 0x0000FF) + (back & 0x0000FF)) >> 1 & 0x0000FF); + + // Rounding hack for pure white against pure black + if (fore == 0x7F7F7F) fore = 0x808080; + + for (; nmarkers; --nmarkers) + { + SendMessage(hwnd, SCI_MARKERSETBACK, markers[nmarkers-1], fore); + SendMessage(hwnd, SCI_MARKERSETFORE, markers[nmarkers-1], back); + } + } // end set folding style if (SendMessage(hwnd,SCI_GETINDENTATIONGUIDES,0,0) != SC_IV_NONE) Style_SetIndentGuides(hwnd,TRUE); if (pLexNew->iLexer != SCLEX_NULL) { i = 1; while (pLexNew->Styles[i].iStyle != -1) {