From: Jean-Philippe Bruyère Date: Wed, 7 Mar 2018 19:28:42 +0000 (+0100) Subject: folding level X-Git-Tag: 0.7.3~4^2~20 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=60c257e887087678c416eebf716fd7e0fa77c2bc;p=jp%2Fcrow.git folding level --- diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index ba425c6e..9cca73b4 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -176,6 +176,7 @@ + diff --git a/CrowIDE/src/CrowIDE.cs b/CrowIDE/src/CrowIDE.cs index 9d2c3814..752f6a70 100644 --- a/CrowIDE/src/CrowIDE.cs +++ b/CrowIDE/src/CrowIDE.cs @@ -41,7 +41,7 @@ namespace Crow.Coding public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout, CMDOptions, - CMDViewGTExp, CMDViewProps, CMDViewProj, CMDViewProjProps, CMDViewErrors, CMDViewSolution, + CMDViewGTExp, CMDViewProps, CMDViewProj, CMDViewProjProps, CMDViewErrors, CMDViewSolution, CMDViewEditor, CMDViewProperties, CMDCompile; void initCommands () { @@ -62,6 +62,10 @@ namespace Crow.Coding { Caption = "Errors pane"}; CMDViewSolution = new Command(new Action(() => loadDockWindow ("#Crow.Coding.ui.DockWindows.winSolution.crow"))) { Caption = "Solution Tree"}; + CMDViewEditor = new Command(new Action(() => loadDockWindow ("#Crow.Coding.ui.DockWindows.winEditor.crow"))) + { Caption = "Editor Pane"}; + CMDViewProperties = new Command(new Action(() => loadDockWindow ("#Crow.Coding.ui.DockWindows.winProperties.crow"))) + { Caption = "Properties"}; CMDViewGTExp = new Command(new Action(() => loadWindow ("#Crow.Coding.ui.GTreeExplorer.crow"))) { Caption = "Graphic Tree Explorer"}; CMDViewProps = new Command(new Action(() => loadWindow ("#Crow.Coding.ui.MemberView.crow"))) { Caption = "Properties View"}; @@ -123,6 +127,10 @@ namespace Crow.Coding instFileDlg = Instantiator.CreateFromImlFragment (MainIFace, ""); + + DockWindow dw = loadDockWindow ("#Crow.Coding.ui.DockWindows.winEditor.crow"); + dw.DockingPosition = Alignment.Center; + dw.Dock (mainDock.Children [0] as DockStack); } void loadProjProps () { @@ -207,19 +215,20 @@ namespace Crow.Coding // loadWindow ("#Crow.Coding.ui.CSProjExplorer.crow"); // } } - void loadDockWindow(string path){ + DockWindow loadDockWindow(string path){ lock (MainIFace.UpdateMutex) { - try { - GraphicObject g = MainIFace.FindByName (path); - if (g != null) - return; - g = MainIFace.Load (path); - mainDock.AddChild (g); - g.Name = path; - g.DataSource = CurrentSolution; - } catch (Exception ex) { - System.Diagnostics.Debug.WriteLine (ex.ToString ()); + GraphicObject g = MainIFace.FindByName (path); + if (g == null){ + try { + g = MainIFace.Load (path); + mainDock.AddChild (g); + g.Name = path; + g.DataSource = CurrentSolution; + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine (ex.ToString ()); + } } + return g as DockWindow; } } void loadWindow(string path, object dataSource = null){ diff --git a/CrowIDE/src/SourceEditor/CSharpParser.cs b/CrowIDE/src/SourceEditor/CSharpParser.cs index d7f15a7a..2878ce19 100644 --- a/CrowIDE/src/SourceEditor/CSharpParser.cs +++ b/CrowIDE/src/SourceEditor/CSharpParser.cs @@ -287,7 +287,7 @@ namespace Crow.Coding } if (cl.Tokens [tokPtr].Type == TokenType.LineComment && onlyWhiteSpace) { - currentNode = addChildNode (currentNode, cl, tokPtr); + int startLine = ptrLine; ptrLine++; while (ptrLine < buffer.LineCount) { int idx = buffer [ptrLine].FirstNonBlankTokIndex; @@ -297,7 +297,11 @@ namespace Crow.Coding break; ptrLine++; } - closeNodeAndGoUp (ref currentNode, buffer [ptrLine]); + ptrLine--; + if (ptrLine - startLine > 0) { + currentNode = addChildNode (currentNode, cl, tokPtr); + closeNodeAndGoUp (ref currentNode, buffer [ptrLine]); + } break; } @@ -308,6 +312,12 @@ namespace Crow.Coding case TokenType.CloseBlock: closeNodeAndGoUp (ref currentNode, cl); break; + case TokenType.Preprocessor: + if (cl.Tokens [tokPtr].Content.StartsWith ("#region")) { + currentNode = addChildNode (currentNode, cl, tokPtr); + }else if (cl.Tokens [tokPtr].Content.StartsWith("#endregion")) + closeNodeAndGoUp (ref currentNode, cl); + break; } onlyWhiteSpace = false; tokPtr++; diff --git a/CrowIDE/src/SourceEditor/CodeBuffer.cs b/CrowIDE/src/SourceEditor/CodeBuffer.cs index ec9bbc3e..36724797 100644 --- a/CrowIDE/src/SourceEditor/CodeBuffer.cs +++ b/CrowIDE/src/SourceEditor/CodeBuffer.cs @@ -209,8 +209,13 @@ namespace Crow.Coding int i = 0, vl = 0; editMutex.EnterReadLock (); while (i < LineCount) { - if (this [i].IsFolded) + if (this [i].IsFolded) { i = GetEndNodeIndex (i); + if (i < 0) { + Console.WriteLine ("error folding"); + break; + } + } i++; vl++; } diff --git a/CrowIDE/src/SourceEditor/CodeLine.cs b/CrowIDE/src/SourceEditor/CodeLine.cs index ca8c8307..041e903c 100644 --- a/CrowIDE/src/SourceEditor/CodeLine.cs +++ b/CrowIDE/src/SourceEditor/CodeLine.cs @@ -32,7 +32,9 @@ namespace Crow.Coding //LineUpadateEvent.Raise (this, new CodeBufferEventArgs (i)); } } - public bool IsFoldable { get { return SyntacticNode != null; } } + public bool IsFoldable { get { return SyntacticNode == null ? false : + SyntacticNode.EndLine != SyntacticNode.StartLine && SyntacticNode.EndLine != null; } } + public int FoldingLevel { get { return IsFoldable ? SyntacticNode.Level : 0; } } public bool IsFolded = false; public bool IsParsed { get { return Tokens != null; } diff --git a/CrowIDE/src/SourceEditor/Node.cs b/CrowIDE/src/SourceEditor/Node.cs index 24818e01..9db55428 100644 --- a/CrowIDE/src/SourceEditor/Node.cs +++ b/CrowIDE/src/SourceEditor/Node.cs @@ -23,6 +23,10 @@ namespace Crow.Coding Children.Add (child); } + public int Level { + get { return Parent == null ? 1 : Parent.Level + 1; } + } + public override string ToString () { return string.Format ("Name:{0}, Type:{1}\n\tparent:{2}", Name, Type, Parent); diff --git a/CrowIDE/src/SourceEditor/SourceEditor.cs b/CrowIDE/src/SourceEditor/SourceEditor.cs index 1264f4a1..867a4722 100644 --- a/CrowIDE/src/SourceEditor/SourceEditor.cs +++ b/CrowIDE/src/SourceEditor/SourceEditor.cs @@ -115,6 +115,7 @@ namespace Crow.Coding } const int leftMarginGap = 3;//gap between items in margin and text const int foldSize = 9;//folding rectangles size + const int foldMargin = 30;//folding rectangles size #region private and protected fields bool foldingEnabled = true; @@ -150,7 +151,7 @@ namespace Crow.Coding if (PrintLineNumbers) leftMargin += (int)Math.Ceiling((double)buffer.LineCount.ToString().Length * fe.MaxXAdvance) +6; if (foldingEnabled) - leftMargin += foldSize; + leftMargin += foldMargin; if (leftMargin > 0) leftMargin += leftMarginGap; updateVisibleColumns (); @@ -597,21 +598,47 @@ namespace Crow.Coding } + //draw folding if (foldingEnabled){ + + Rectangle rFld = new Rectangle (cb.X + leftMargin - leftMarginGap - foldMargin, + (int)(y + (fe.Ascent + fe.Descent) / 2.0 - foldSize / 2.0), foldSize, foldSize); + + gr.SetSourceColor (Color.Black); + + int level = 0; + + if (currentNode != null) { + if (cl == currentNode.EndLine) + currentNode = currentNode.Parent; + if (currentNode != null) + level = currentNode.Level; + } + + rFld.Left += level * 5; + if (cl.IsFoldable) { - if (cl.SyntacticNode.StartLine != cl.SyntacticNode.EndLine) { - gr.SetSourceColor (Color.Black); - Rectangle rFld = new Rectangle (cb.X + leftMargin - leftMarginGap - foldSize, (int)(y + (fe.Ascent+fe.Descent) / 2.0 - foldSize / 2.0), foldSize, foldSize); - gr.Rectangle (rFld, 1.0); - if (cl.IsFolded) { - gr.MoveTo (rFld.Center.X + 0.5, rFld.Y + 2); - gr.LineTo (rFld.Center.X + 0.5, rFld.Bottom - 2); - } - gr.MoveTo (rFld.Left + 2, rFld.Center.Y + 0.5); - gr.LineTo (rFld.Right - 2, rFld.Center.Y + 0.5); - gr.Stroke (); - } + gr.Rectangle (rFld, 1.0); + if (cl.IsFolded) { + gr.MoveTo (rFld.Center.X + 0.5, rFld.Y + 2); + gr.LineTo (rFld.Center.X + 0.5, rFld.Bottom - 2); + }else + currentNode = cl.SyntacticNode; + + gr.MoveTo (rFld.Left + 2, rFld.Center.Y + 0.5); + gr.LineTo (rFld.Right - 2, rFld.Center.Y + 0.5); + gr.Stroke (); + +// } else if (currentNode != null){ +// if (cl == currentNode.EndLine) +// currentNode = currentNode.Parent; +// if (currentNode != null) { +// int level = currentNode.Level; +// gr.MoveTo (rFld.Center.X + 0.5 + level * 5, y); +// gr.LineTo (rFld.Center.X + 0.5 + level * 5, y + fe.Ascent + fe.Descent); +// gr.Stroke (); +// } } } @@ -623,6 +650,7 @@ namespace Crow.Coding else drawParsedCodeLine (gr, x, y, i, lineIndex); } + Node currentNode = null; // void drawParsed(Context gr){ // if (PrintedLines == null) // return; @@ -834,9 +862,21 @@ namespace Crow.Coding seMutex.EnterReadLock (); - if (PrintedLines != null) { + if (PrintedLines != null) { + int unfoldedLines = buffer.UnfoldedLines; + currentNode = null; + CodeLine cl = PrintedLines[0]; + int li = buffer.IndexOf(cl); + while (li > 0) { + if (buffer [li].IsFoldable) { + currentNode = buffer [li].SyntacticNode; + break; + } + li--; + } + for (int i = 0; i < visibleLines; i++) { - if (i + ScrollY >= buffer.UnfoldedLines)//TODO:need optimize + if (i + ScrollY >= unfoldedLines)//TODO:need optimize break; drawLine (gr, cb, i); } diff --git a/CrowIDE/ui/CrowIDE.crow b/CrowIDE/ui/CrowIDE.crow index e7d19afc..22f98ebc 100644 --- a/CrowIDE/ui/CrowIDE.crow +++ b/CrowIDE/ui/CrowIDE.crow @@ -19,6 +19,8 @@ + + @@ -34,7 +36,8 @@ - + + diff --git a/CrowIDE/ui/DockWindows/winProperties.crow b/CrowIDE/ui/DockWindows/winProperties.crow new file mode 100644 index 00000000..057d45eb --- /dev/null +++ b/CrowIDE/ui/DockWindows/winProperties.crow @@ -0,0 +1,7 @@ + + + + + diff --git a/CrowIDE/ui/DockWindows/winSolution.crow b/CrowIDE/ui/DockWindows/winSolution.crow index c9de649b..aacdbf25 100644 --- a/CrowIDE/ui/DockWindows/winSolution.crow +++ b/CrowIDE/ui/DockWindows/winSolution.crow @@ -1,12 +1,6 @@  - - - - - + diff --git a/Images/screenshot.png b/Images/screenshot.png index 23be2ad4..e2f802f2 100644 Binary files a/Images/screenshot.png and b/Images/screenshot.png differ diff --git a/Templates/DockWindow.template b/Templates/DockWindow.template index 3e5b499a..56afd3eb 100755 --- a/Templates/DockWindow.template +++ b/Templates/DockWindow.template @@ -1,15 +1,16 @@ - +