]> O.S.I.I.S - jp/crow.git/commitdiff
folding level
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 7 Mar 2018 19:28:42 +0000 (20:28 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 7 Mar 2018 19:28:42 +0000 (20:28 +0100)
13 files changed:
CrowIDE/CrowIDE.csproj
CrowIDE/src/CrowIDE.cs
CrowIDE/src/SourceEditor/CSharpParser.cs
CrowIDE/src/SourceEditor/CodeBuffer.cs
CrowIDE/src/SourceEditor/CodeLine.cs
CrowIDE/src/SourceEditor/Node.cs
CrowIDE/src/SourceEditor/SourceEditor.cs
CrowIDE/ui/CrowIDE.crow
CrowIDE/ui/DockWindows/winProperties.crow [new file with mode: 0644]
CrowIDE/ui/DockWindows/winSolution.crow
Images/screenshot.png
Templates/DockWindow.template
src/GraphicObjects/DockWindow.cs

index ba425c6eb1ea7673bbf905d3a4b5dde99557c5e2..9cca73b4c3670ff402a1e3417173d402de92182f 100644 (file)
     <EmbeddedResource Include="ui\DockWindows\winEditor.crow" />
     <EmbeddedResource Include="ui\DockWindows\winErrors.crow" />
     <EmbeddedResource Include="ui\DockWindows\winSolution.crow" />
+    <EmbeddedResource Include="ui\DockWindows\winProperties.crow" />
   </ItemGroup>
   <ItemGroup>
     <None Include="ui\test.crow">
index 9d2c3814c12a0d2cdb08828bcff12a0dfb30cd59..752f6a708527c79370931b3e666e597da8adf16b 100644 (file)
@@ -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, "<FileDialog Caption='Open File' CurrentDirectory='{²CurrentDirectory}' SearchPattern='*.sln' OkClicked='onFileOpen'/>");
+
+                       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){
index d7f15a7aa939c8d34d733df37c483beacce94fc1..2878ce19da417903a3c1ed85e0b485a25714b09e 100644 (file)
@@ -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++;
index ec9bbc3eb60c99ea68586d39a08fdc9d54e85d91..3672479792c7bae55c27cea360b5ec706b82ce61 100644 (file)
@@ -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++;
                                }
index ca8c830755c04ef38ee60cc65fc4fa8bde48a260..041e903cd8c4dd3597a4103f0a789910932fb3bc 100644 (file)
@@ -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; }
index 24818e019fc65afb481d3cc1c191b133403fbcc9..9db5542856cdd8c1f50731e0ae18d862ffe7eed4 100644 (file)
@@ -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);
index 1264f4a164bd3e659e3f4b32c249558925398c54..867a4722a27db183c3e7c0b416fddeefb5bc8e40 100644 (file)
@@ -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);
                                }
index e7d19afc1f250ee25bd2d903aef91775bcd315f7..22f98ebc39ae0fde40038cdb06f7882d7bf724e3 100644 (file)
@@ -19,6 +19,8 @@
                        </MenuItem>
                        <MenuItem Caption="View" Fit="true" PopWidth="150">
                                <MenuItem Command="{CMDViewSolution}"/>
+                               <MenuItem Command="{CMDViewEditor}"/>
+                               <MenuItem Command="{CMDViewProperties}"/>
                                <MenuItem Command="{CMDViewErrors}"/>
                                <MenuItem Command="{CMDViewGTExp}"/>
                                <MenuItem Command="{CMDViewProps}"/>
@@ -34,7 +36,8 @@
                        </MenuItem>
                </Menu>
                <Docker Name="mainDock">
-                       <DockWindow DataSource="{CurrentSolution}" Name="winEditor" Caption="Edit View" Width="70%" Height="80%">
+                       <DockStack />
+<!--                   <DockWindow DataSource="{CurrentSolution}" Name="winEditor" Caption="Edit View" Width="70%" Height="80%">
                                <Template>
                                        <Border BorderWidth="1" Foreground="Jet" CornerRadius="{./CornerRadius}"
                                                                        Background="{./Background}"
@@ -45,7 +48,7 @@
                                </Template>
                                <EditPane SelectedItem="{²SelectedItem}" SelectedItemElement="{²SelectedItemElement}" Data="{OpenedItems}" DataTest="Extension"
                                        ItemTemplate="#Crow.Coding.ui.EditPaneItems.template"/>
-                       </DockWindow>
+                       </DockWindow>-->
                </Docker>
        </VerticalStack>
 </Window>
diff --git a/CrowIDE/ui/DockWindows/winProperties.crow b/CrowIDE/ui/DockWindows/winProperties.crow
new file mode 100644 (file)
index 0000000..057d45e
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<DockWindow DataSource="{CurrentSolution}" Name="winProperties" Caption="Properties" Width="30%" Height="80%">
+       <MembersView ProjectNode="{SelectedItem}"
+               Instance="{SelectedItemElement}" DataTest="Type"
+               ItemTemplate="#Crow.Coding.ui.MembersItem.template"/>
+</DockWindow>
+
index c9de649bcae948270fc1dc04ea9bb5f75dbf2e0d..aacdbf25667f4c949f2b3adff975f578a289c09e 100644 (file)
@@ -1,12 +1,6 @@
 <?xml version="1.0"?>
 <DockWindow DataSource="{CurrentSolution}" Name="winSolution" Caption="Solution" Width="30%" Height="80%">
-       <VerticalStack>
-               <TreeView Name="treeview" IsRoot="true" Height="50%"
-                       Data="{Projects}" SelectedItemChanged="onSelectedItemChanged"
-                       ItemTemplate="#Crow.Coding.ui.ProjectTree.template"/>
-               <Splitter/>
-               <MembersView ProjectNode="{SelectedItem}"
-                       Instance="{SelectedItemElement}" DataTest="Type"
-                       ItemTemplate="#Crow.Coding.ui.MembersItem.template"/>
-       </VerticalStack>
+       <TreeView Name="treeview" IsRoot="true"
+               Data="{Projects}" SelectedItemChanged="onSelectedItemChanged"
+               ItemTemplate="#Crow.Coding.ui.ProjectTree.template"/>
 </DockWindow>
index 23be2ad432154ac8c29f222ca54b1e09284375a3..e2f802f2f7177c4fc6b361d80196cb89e6a84cde 100644 (file)
Binary files a/Images/screenshot.png and b/Images/screenshot.png differ
index 3e5b499adecc306530e2fa2fd6afee1582c59cc6..56afd3ebd8460e81afa36889f96bb4f94dc8d7a3 100755 (executable)
@@ -1,15 +1,16 @@
 <?xml version="1.0"?>
 <!--<GraphicObject Background="{./Background}"/>-->
-<Border BorderWidth="1" Foreground="White" CornerRadius="{./CornerRadius}"
+<Border BorderWidth="1" Foreground="Black" CornerRadius="{./CornerRadius}"
                                Background="{./Background}"
                                MouseEnter="./onBorderMouseEnter"
                                MouseLeave="./onBorderMouseLeave">
        <VerticalStack Spacing="0">
+               <Label Visible="{./IsDocked}" Width="Stretched" Foreground="White" Margin="0" TextAlignment="Left" Text="{./Caption}" />
                <HorizontalStack Background="vgradient|0:0.5,0.6,0.5,0.5|1:0.2,0.3,0.3,0.7"
-                               Name="hs" Margin="0" Spacing="0" Height="Fit">
+                               Name="hs" Margin="0" Spacing="0" Height="Fit" Visible="{./IsFloating}">
                        <GraphicObject Width="5"/>
                        <Image Margin="1" Width="10" Height="10" Path="{./Icon}"/>
-                       <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Center" Text="{./Caption}" />
+                       <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Left" Text="{./Caption}" />
                        <Border CornerRadius="6" BorderWidth="1" Foreground="Transparent"  Height="10" Width="10"
                                MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}">
                                <Image Focusable="true" Name="Image" Margin="0" Width="Stretched" Height="Stretched" Path="#Crow.Images.Icons.exit2.svg"
index 34290a2e613a0a2b0dbfb7eb07936ba25941b914..e3dc2b9fbe156f3a4c5027ab961d08575fb3d153 100644 (file)
@@ -24,6 +24,7 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 using System;
+using System.Xml.Serialization;
 
 namespace Crow
 {
@@ -52,8 +53,11 @@ namespace Crow
                                        return;
                                isDocked = value;
                                NotifyValueChanged ("IsDocked", isDocked);
+                               NotifyValueChanged ("IsFloating", !isDocked);
                        }
                }
+               [XmlIgnore] public bool IsFloating { get { return !isDocked; }}
+
                public Alignment DockingPosition {
                        get { return docking; }
                        set {
@@ -125,7 +129,7 @@ namespace Crow
                protected override void onDrop (object sender, DragDropEventArgs e)
                {
                        if (!isDocked && DockingPosition != Alignment.Undefined)
-                               dock (e.DropTarget as DockStack);
+                               Dock (e.DropTarget as DockStack);
                        base.onDrop (sender, e);
                }
                public void Undock () {
@@ -146,7 +150,7 @@ namespace Crow
                        }
                }
 
-               void dock (DockStack target){
+               public void Dock (DockStack target){
                        lock (IFace.UpdateMutex) {
                                IsDocked = true;
                                //undockingMousePosOrig = lastMousePos;