--- a\np2src\src\Notepad2.c Fri Oct 31 00:00:00 2008 +++ b\np2src\src\Notepad2.c Fri Oct 31 11:49:20 2008 @@ -54,12 +54,13 @@ 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}, @@ -124,12 +125,13 @@ BOOL bMarkLongLines; int iLongLinesLimit; int iLongLinesLimitG; int iLongLineMode; int iWrapCol = 0; BOOL bShowSelectionMargin; BOOL bShowLineNumbers; +BOOL bShowCodeFolding; BOOL bViewWhiteSpace; BOOL bViewEOLs; int iDefaultEncoding; BOOL bSkipUnicodeDetection; int iDefaultEOLMode; BOOL bFixLineEndings; @@ -1099,12 +1101,31 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wPara 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)L"_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); hwndEditFrame = CreateWindowEx( WS_EX_CLIENTEDGE, @@ -1609,12 +1630,13 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam 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); @@ -2999,12 +3021,18 @@ 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; @@ -4030,12 +4058,21 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wPara 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: @@ -4285,12 +4322,15 @@ void LoadSettings() bShowSelectionMargin = IniSectionGetInt(pIniSection,L"ShowSelectionMargin",0); if (bShowSelectionMargin) bShowSelectionMargin = 1; bShowLineNumbers = IniSectionGetInt(pIniSection,L"ShowLineNumbers",1); if (bShowLineNumbers) bShowLineNumbers = 1; + bShowCodeFolding = IniSectionGetInt(pIniSection,L"ShowCodeFolding",0); + if (bShowCodeFolding) bShowCodeFolding = 1; + bViewWhiteSpace = IniSectionGetInt(pIniSection,L"ViewWhiteSpace",0); if (bViewWhiteSpace) bViewWhiteSpace = 1; bViewEOLs = IniSectionGetInt(pIniSection,L"ViewEOLs",0); if (bViewEOLs) bViewEOLs = 1; @@ -4499,12 +4539,13 @@ void SaveSettings(BOOL bSaveSettingsNow) IniSectionSetInt(pIniSection,L"IndentWidth",iIndentWidthG); IniSectionSetInt(pIniSection,L"MarkLongLines",bMarkLongLines); IniSectionSetInt(pIniSection,L"LongLinesLimit",iLongLinesLimitG); IniSectionSetInt(pIniSection,L"LongLineMode",iLongLineMode); IniSectionSetInt(pIniSection,L"ShowSelectionMargin",bShowSelectionMargin); IniSectionSetInt(pIniSection,L"ShowLineNumbers",bShowLineNumbers); + IniSectionSetInt(pIniSection,L"ShowCodeFolding",bShowCodeFolding); IniSectionSetInt(pIniSection,L"ViewWhiteSpace",bViewWhiteSpace); IniSectionSetInt(pIniSection,L"ViewEOLs",bViewEOLs); IniSectionSetInt(pIniSection,L"DefaultEncoding",iDefaultEncoding); IniSectionSetInt(pIniSection,L"SkipUnicodeDetection",bSkipUnicodeDetection); IniSectionSetInt(pIniSection,L"DefaultEOLMode",iDefaultEOLMode); IniSectionSetInt(pIniSection,L"FixLineEndings",bFixLineEndings); --- a\np2src\src\Notepad2.rc Fri Oct 31 11:49:06 2008 +++ b\np2src\src\Notepad2.rc Fri Oct 31 11:49:20 2008 @@ -243,12 +243,13 @@ BEGIN 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" @@ -365,12 +366,14 @@ BEGIN "D", IDM_EDIT_DUPLICATELINE, VIRTKEY, CONTROL, NOINVERT "D", IDM_EDIT_SELECTIONDUPLICATE, VIRTKEY, ALT, NOINVERT "D", IDM_EDIT_DELETELINE, VIRTKEY, SHIFT, CONTROL, NOINVERT "E", IDM_EDIT_COPYADD, 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, --- a\np2src\src\resource.h Fri Oct 31 00:00:00 2008 +++ b\np2src\src\resource.h Fri Oct 31 11:49:20 2008 @@ -270,12 +270,13 @@ #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 --- a\np2src\src\Styles.c Fri Oct 31 11:49:06 2008 +++ b\np2src\src\Styles.c Fri Oct 31 11:53:39 2008 @@ -1474,19 +1474,54 @@ void Style_SetLexer(HWND hwnd,PEDITLEXER 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 + static 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) { --- a\np2src\scintilla\src\LexCPP.cxx Wed Sep 24 09:14:12 2008 +++ b\np2src\scintilla\src\LexCPP.cxx Fri Oct 31 11:49:20 2008 @@ -386,22 +386,24 @@ static void FoldCppDoc(unsigned int star levelNext++; } else if (!IsStreamCommentStyle(styleNext) && (styleNext != SCE_C_COMMENTLINEDOC) && !atEOL) { // Comments don't end at end of line and the next character may be unstyled. levelNext--; } } + /* Disable explicit folding; it can often cause problems with non-aware code if (foldComment && (style == SCE_C_COMMENTLINE)) { if ((ch == '/') && (chNext == '/')) { char chNext2 = styler.SafeGetCharAt(i + 2); if (chNext2 == '{') { levelNext++; } else if (chNext2 == '}') { levelNext--; } } } + */ if (foldPreprocessor && (style == SCE_C_PREPROCESSOR)) { if (ch == '#') { unsigned int j = i + 1; while ((j < endPos) && IsASpaceOrTab(styler.SafeGetCharAt(j))) { j++; } --- a\np2src\scintilla\src\LexPascal.cxx Thu May 31 21:57:24 2007 +++ b\np2src\scintilla\src\LexPascal.cxx Fri Oct 31 11:49:20 2008 @@ -304,22 +304,24 @@ static void FoldPascalDoc(unsigned int s char s[100]; getRange(lastStart, i, styler, s, sizeof(s)); levelCurrent += classifyFoldPointPascal(s); } } + /* Disable explicit folding; it can often cause problems with non-aware code if (foldComment && (style == SCE_C_COMMENTLINE)) { if ((ch == '/') && (chNext == '/')) { char chNext2 = styler.SafeGetCharAt(i + 2); if (chNext2 == '{') { levelCurrent++; } else if (chNext2 == '}') { levelCurrent--; } } } + */ if (foldPreprocessor && (style == SCE_C_PREPROCESSOR)) { if (ch == '{' && chNext == '$') { unsigned int j=i+2; // skip {$ while ((j