]> O.S.I.I.S - jp/crowedit.git/commitdiff
* SourceEditor.cs: mouse click folding
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 13:27:19 +0000 (14:27 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Nov 2017 13:27:19 +0000 (14:27 +0100)
* main.crow:
* CrowEdit.csproj:
* CrowEdit.cs:
* EditorOptions.crow: editor options pannel

CrowEdit.csproj
src/CrowEdit.cs
src/SourceEditor.cs
ui/EditorOptions.crow [new file with mode: 0644]
ui/main.crow

index 0cad08ba12cd9ca767101394a6de4dfd87733cff..3c197e192d3eb1305f754f11c958006e37078932 100644 (file)
@@ -48,7 +48,6 @@
     <None Include="ui\icons\search.svg" />
     <None Include="ui\icons\text-file.svg" />
     <None Include="ui\icons\text-label.svg" />
-    <None Include="ui\icons\tools.svg" />
     <None Include="ui\icons\zoom-in.svg" />
     <None Include="ui\icons\zoom-out.svg" />
     <None Include="ui\icons\basic_floppydisk.svg" />
     <EmbeddedResource Include="ui\icons\inbox.svg" />
     <EmbeddedResource Include="ui\icons\outbox.svg" />
     <EmbeddedResource Include="ui\saveFile.crow" />
+    <EmbeddedResource Include="ui\EditorOptions.crow" />
+    <EmbeddedResource Include="ui\icons\tools.svg" />
   </ItemGroup>
 </Project>
index 32b1d0ec3893993ffa29277e6da951be1c8582c8..a9af7dca1771d4c1b0e2a54ee07c5cbd1c3b381a 100644 (file)
@@ -27,7 +27,7 @@ namespace CrowEdit
 {
        public class CrowEdit : CrowWindow
        {
-               public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout;
+               public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout, CMDOptions;
 
                string _curDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
                string _curFilePath = "unamed.txt";
@@ -85,6 +85,7 @@ namespace CrowEdit
                        CMDCopy = new Command(new Action(() => Quit (null, null))) { Caption = "Copy", Icon = new SvgPicture("#CrowEdit.ui.icons.copy-file.svg"), CanExecute = false};
                        CMDPaste = new Command(new Action(() => Quit (null, null))) { Caption = "Paste", Icon = new SvgPicture("#CrowEdit.ui.icons.paste-on-document.svg"), CanExecute = false};
                        CMDHelp = new Command(new Action(() => System.Diagnostics.Debug.WriteLine("help"))) { Caption = "Help", Icon = new SvgPicture("#CrowEdit.ui.icons.question.svg")};
+                       CMDOptions = new Command(new Action(() => openOptionsDialog())) { Caption = "Editor Options", Icon = new SvgPicture("#CrowEdit.ui.icons.tools.svg")};
 
                }
                void newFile(){
@@ -124,6 +125,10 @@ namespace CrowEdit
                        if (redoStack.Count == 0)
                                CMDRedo.CanExecute = false;
                }
+               void openOptionsDialog(){
+                       GraphicObject ed = this.FindByName("editor");
+                       Load ("#CrowEdit.ui.EditorOptions.crow").DataSource = ed;
+               }
                void openFileDialog(){
                        Load ("#CrowEdit.ui.openFile.crow").DataSource = this;
                }
@@ -188,7 +193,6 @@ namespace CrowEdit
 
                        this.ValueChanged += CrowEdit_ValueChanged;
                        initCommands ();
-
                        Load ("#CrowEdit.ui.main.crow").DataSource = this;
                        NotifyValueChanged ("CurFileFullPath", CurFileFullPath);
                }
index 511864e93f057571068a742040a2474f328e5d83..2c53ba7b275b6f711d0fcc861e5e77eaa6c9e858 100644 (file)
@@ -70,7 +70,7 @@ namespace Crow.Coding
                }
                #endregion
 
-               const int leftMarginGap = 2;//gap between items in margin and text
+               const int leftMarginGap = 5;//gap between items in margin and text
                const int foldSize = 9;//folding rectangles size
 
                #region private and protected fields
@@ -99,7 +99,7 @@ namespace Crow.Coding
                void measureLeftMargin () {
                        leftMargin = 0;
                        if (PrintLineNumbers)
-                               leftMargin += (int)Math.Ceiling((double)buffer.LineCount.ToString().Length * fe.MaxXAdvance);
+                               leftMargin += (int)Math.Ceiling((double)buffer.LineCount.ToString().Length * fe.MaxXAdvance) +6;
                        if (foldingEnabled)
                                leftMargin += foldSize;
                        if (leftMargin > 0)
@@ -272,6 +272,7 @@ namespace Crow.Coding
                                        return;
                                Configuration.Set ("PrintLineNumbers", value);
                                NotifyValueChanged ("PrintLineNumbers", PrintLineNumbers);
+                               measureLeftMargin ();
                                RegisterForGraphicUpdate ();
                        }
                }
@@ -924,16 +925,20 @@ namespace Crow.Coding
                        if (!this.Focusable)
                                return;
 
-                       base.onMouseDown (sender, e);
+                       if (mouseLocalPos.X >= leftMargin)
+                               base.onMouseDown (sender, e);
 
                        if (doubleClicked) {
                                doubleClicked = false;
                                return;
                        }
 
-                       updateCurrentPos ();
-                       SelBegin = SelRelease = CurrentPosition;
-                                               
+                       if (mouseLocalPos.X < leftMargin) {
+                               toogleFolding (parser.Tokens.IndexOf (PrintedLines[(int)Math.Max (0, Math.Floor (mouseLocalPos.Y / fe.Height))]));
+                       } else {
+                               updateCurrentPos ();
+                               SelBegin = SelRelease = CurrentPosition;
+                       }               
                        RegisterForRedraw();
                }
                public override void onMouseUp (object sender, MouseButtonEventArgs e)
diff --git a/ui/EditorOptions.crow b/ui/EditorOptions.crow
new file mode 100644 (file)
index 0000000..bf2a2bc
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Window AlwaysOnTop="true" Caption="Editor Options" Width="60%" Height="80%">
+       <VerticalStack>
+               <CheckBox Caption="Print line number" IsChecked="{²PrintLineNumbers}"/>
+       </VerticalStack>
+</Window>
\ No newline at end of file
index 04ecc85565225f71cf2c8aa5ffbf524ded1ddafb..edad15daf0945629e66164501dafb5dd98909607 100755 (executable)
@@ -9,12 +9,13 @@
                                <MenuItem Command="{CMDSaveAs}" />
                                <MenuItem Command="{CMDQuit}" />
                        </MenuItem>
-                       <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="60">
+                       <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="100">
                                <MenuItem Command="{CMDUndo}" />
                                <MenuItem Command="{CMDRedo}" />
                                <MenuItem Command="{CMDCut}" />
                                <MenuItem Command="{CMDCopy}" />
                                <MenuItem Command="{CMDPaste}" />
+                               <MenuItem Command="{CMDOptions}"/>
                        </MenuItem>
                        <MenuItem Caption="Help" Width="Fit" PopWidth="60">
                                <MenuItem Caption="About"/>