]> O.S.I.I.S - jp/crowedit.git/commitdiff
save commit
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 19 Nov 2020 08:14:07 +0000 (09:14 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 19 Nov 2020 08:14:07 +0000 (09:14 +0100)
.gitignore
Crow.Coding/src/SourceEditor.cs
Crow.Coding/ui/IDE.style
Crow.Coding/ui/MenuItem.template [deleted file]
src/CrowEdit.cs
ui/CrowEdit.style [new file with mode: 0644]
ui/MenuItem.template
ui/main.crow
ui/openFile.crow
ui/saveFile.crow

index a9f5d34b02fa94a167c5351a3c9dce7ccf6c2673..69b037a4cfc18f967ac49069e14a81f8c03d676b 100644 (file)
@@ -40,3 +40,4 @@ Thumbs.db
 #dotCover
 *.dotCover
 .vs
+.vscode
index e32efd95ac6dad5d11b3f85e533bec90ddfbcd43..4913dda0f14ac35e267ff1eca1a4233603cc8529 100644 (file)
@@ -54,9 +54,12 @@ namespace Crow.Coding
                        buffer.SelectionChanged += Buffer_SelectionChanged;
                        buffer.PositionChanged += Buffer_PositionChanged;
                        buffer.FoldingEvent += Buffer_FoldingEvent;
-                       buffer.Add (new CodeLine(""));
                }
                #endregion
+               protected override void onInitialized (object sender, EventArgs e) {
+                       buffer.Add (new CodeLine (""));
+                       base.onInitialized (sender, e);
+               }
 
                ReaderWriterLockSlim editorMutex = new ReaderWriterLockSlim (LockRecursionPolicy.SupportsRecursion);
 
@@ -71,7 +74,7 @@ namespace Crow.Coding
 
                #region private and protected fields
                bool foldingEnabled = true;
-               int leftMargin = 0;     //margin used to display line numbers, folding errors,etc...
+               int leftMargin; //margin used to display line numbers, folding errors,etc...
                int visibleLines = 1;
                int visibleColumns = 1;
                int firstPrintedLine = -1;
@@ -432,7 +435,12 @@ namespace Crow.Coding
                                filePath = value;
                                if (!string.IsNullOrEmpty (filePath)) {
                                        parser = getParserFromExt (System.IO.Path.GetExtension (filePath));
-                                       loadSource();
+                                       if (File.Exists (filePath))
+                                               loadSource ();
+                                       else {
+                                               buffer.Clear ();
+                                               buffer.Add (new CodeLine (""));
+                                       }
                                }
                        }
                }
@@ -449,16 +457,11 @@ namespace Crow.Coding
                        return (BufferParser)Activator.CreateInstance (parserType, buffer );
                }
                void loadSource () {
-
-                       try {
-                               using (StreamReader sr = new StreamReader (filePath)) {
-                                       if (parser == null)
-                                               buffer.Load (sr.ReadToEnd());
-                                       else//parser may have special linebrk rules
-                                               buffer.Load (sr.ReadToEnd (), parser.LineBrkRegex);
-                               }
-                       } catch (Exception ex) {
-                               Debug.WriteLine (ex.ToString ());
+                       using (StreamReader sr = new StreamReader (filePath)) {
+                               if (parser == null)
+                                       buffer.Load (sr.ReadToEnd());
+                               else//parser may have special linebrk rules
+                                       buffer.Load (sr.ReadToEnd (), parser.LineBrkRegex);
                        }
 
                        updateMaxScrollY ();
@@ -543,8 +546,8 @@ namespace Crow.Coding
                                        else
                                                mgFg = Colors.LightGrey;
                                }else if (buffer.CurrentLine == lineIndex && HasFocus) {
-                                       mgFg = Colors.Black;
-                                       mgBg = Colors.DarkGrey;
+                                       mgFg = Colors.White;
+                                       mgBg = Colors.RoyalBlue;
                                }
                                string strLN = (lineIndex+1).ToString ();
                                gr.SetSource (mgBg);
@@ -816,6 +819,7 @@ namespace Crow.Coding
 
                        Rectangle cb = ClientRectangle;
 
+
                        Foreground.SetAsSource (gr);
 
                        buffer.editMutex.EnterReadLock ();
@@ -849,12 +853,20 @@ namespace Crow.Coding
                                        }
                                        li--;
                                }
-
-                               for (int i = 0; i < visibleLines; i++) {
+                               int i;
+                               for (i = 0; i < visibleLines; i++) {
                                        if (i + ScrollY >= unfoldedLines)//TODO:need optimize
                                                break;
                                        drawLine (gr, cb, i);
                                }
+                               double y = cb.Y + (fe.Ascent + fe.Descent) * i, x = cb.X;
+                               if (y < cb.Bottom) {
+                                       //draw end of margin
+                                       Rectangle mgR = new Rectangle ((int)x, (int)y, leftMargin - leftMarginGap, (int)(cb.Bottom - y));
+                                       gr.SetSource (Colors.Grey);
+                                       gr.Rectangle (mgR);
+                                       gr.Fill ();
+                               }
                        }
 
                        editorMutex.ExitReadLock ();
index 7fbe631626d6c91dfc54ec1898309801a577cef7..5a3c67b459d9ca218f2fd725964d897c7bf9ef8d 100644 (file)
@@ -23,7 +23,3 @@ IcoBut {
        Height = "14";
        Background = "White";
 }
-
-MenuItem {
-       Template = "#Crow.Coding.ui.MenuItem.template";
-}
\ No newline at end of file
diff --git a/Crow.Coding/ui/MenuItem.template b/Crow.Coding/ui/MenuItem.template
deleted file mode 100644 (file)
index 2fc2936..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0"?>
-<Popper Font="{./Font}" Caption="{./Caption}"  Background="{./Background}" PopDirection="{./PopDirection}"
-       Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
-       IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}">
-       <Template>
-               <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}">
-                       <Template>
-                               <Border Name="border1"
-                                               MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
-                                               MouseLeave="{Foreground=Transparent}"
-                                               MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}"
-                                               MouseUp="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
-                                               MinimumSize = "40,0"
-                                               Foreground="Transparent"
-                                               Background="{./Background}">
-                                               <HorizontalStack HorizontalAlignment="Left" Margin="1">
-                                                       <Image MaximumSize="10,10" Picture="{../../../../../Icon}"/>
-                                                       <Label Text="{./Caption}"
-                                                               Foreground="{./Foreground}"
-                                                               Font="{./Font}" />
-                                               </HorizontalStack>
-                               </Border>
-                       </Template>
-               </CheckBox>
-       </Template>
-       <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="Jet">
-               <VerticalStack Name="ItemsContainer"/>
-       </Border>
-</Popper>
index 54cb1c47ce39dd3952ba3913397826c6571528a5..cfe2b1f0a114303a946c0800867a9332e7f49b87 100644 (file)
@@ -14,8 +14,10 @@ namespace CrowEdit
                public Command CMDNew, CMDOpen, CMDSave, CMDSaveAs, CMDQuit, CMDShowLeftPane,
                        CMDUndo, CMDRedo, CMDCut, CMDCopy, CMDPaste, CMDHelp, CMDAbout, CMDOptions;
 
-               string _curFilePath = "unamed.txt";
+               const string _defaultFileName = "unnamed.txt";
                string _text = "", _origText="";
+               bool isDirty = false;
+               public new bool IsDirty { get { return _text != _origText; } }
 
                List<string> undoStack = new List<string>();
                List<string> redoStack = new List<string>();
@@ -34,8 +36,6 @@ namespace CrowEdit
                                NotifyValueChanged ("IsDirty", IsDirty);
                        }
                }
-               bool isDirty = false;
-               public bool IsDirty { get { return _text != _origText; }}
 
                public string CurrentDir {
                        get { return Configuration.Global.Get<string>("CurrentDir"); }
@@ -46,16 +46,23 @@ namespace CrowEdit
                                NotifyValueChanged (CurrentDir);
                        }
                }
-               public string CurFilePath {
-                       get { return _curFilePath; }
+               public string CurrentFilePath {
+                       get { return Configuration.Global.Get<string> ("CurrentFilePath"); }
                        set {
-                               if (_curFilePath == value)
+                               if (CurrentFilePath == value)
                                        return;
-                               _curFilePath = value;
-                               NotifyValueChanged (_curFilePath);
+                               Configuration.Global.Set ("CurrentFilePath", value);
+                               NotifyValueChanged (CurrentFilePath);
+
                        }
                }
-               bool showLeftPane;
+               public string CurFileName {
+                       get => string.IsNullOrEmpty (CurrentFilePath) ? _defaultFileName : Path.GetFileName (CurrentFilePath);
+               }
+               public string CurFileDir {
+                       get => string.IsNullOrEmpty (CurrentFilePath) ? CurrentDir : Path.GetDirectoryName (CurrentFilePath);
+               }
+
                public bool ShowLeftPane {
                        get { return Configuration.Global.Get<bool> ("ShowLeftPane"); }
                        set {
@@ -66,8 +73,6 @@ namespace CrowEdit
                        }
                }
 
-               public string CurFileFullPath { get { return Path.Combine(CurrentDir,CurFilePath); }}
-
                void initCommands(){
                        CMDNew = new Command(new Action(() => onNewFile())) { Caption = "New", Icon = new SvgPicture("#CrowEdit.ui.icons.blank-file.svg")};
                        CMDOpen = new Command(new Action(() => openFileDialog())) { Caption = "Open...", Icon = new SvgPicture("#CrowEdit.ui.icons.outbox.svg")};
@@ -137,18 +142,16 @@ namespace CrowEdit
                {
                        FileDialog fd = sender as FileDialog;
 
-                       if (!string.IsNullOrEmpty (fd.SelectedFile))
-                               CurFilePath = fd.SelectedFile;
-                       CurrentDir = fd.SelectedDirectory;
+                       if (string.IsNullOrEmpty (fd.SelectedFile))
+                               return;
+                       CurrentFilePath = Path.Combine (fd.SelectedDirectory, fd.SelectedFile);
 
-                       System.Diagnostics.Debug.WriteLine (CurFileFullPath);
 //                     using (StreamWriter sr = new StreamWriter (fd.SelectedFile)) {
 //                             sr.Write(_text);
 //                     }
                        _origText = _text;
 
                        NotifyValueChanged ("IsDirty", false);
-                       NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
                }
                void onTextChanged (object sender, TextChangeEventArgs e)
                {
@@ -181,7 +184,7 @@ namespace CrowEdit
                                openFile (filePath, directory);
                }
                void newFile () {
-                       CurFilePath = "unamed.txt";
+                       CurrentFilePath = Path.Combine (CurFileDir, _defaultFileName);
                        _origText = _text = "";
                        NotifyValueChanged ("Text", (object)_text);
                        NotifyValueChanged ("IsDirty", false);
@@ -189,18 +192,13 @@ namespace CrowEdit
                        undoStack.Clear ();
                        CMDRedo.CanExecute = false;
                        CMDUndo.CanExecute = false;
-                       NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
                }
                void openFile (string filePath, string directory) {
-                       CurFilePath = filePath;
-                       CurrentDir = directory;
-
+                       CurrentFilePath = Path.Combine(directory, filePath);
                        redoStack.Clear ();
                        undoStack.Clear ();
                        CMDRedo.CanExecute = false;
                        CMDUndo.CanExecute = false;
-
-                       NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
                }
 
                [STAThread]
@@ -222,7 +220,6 @@ namespace CrowEdit
                        this.ValueChanged += CrowEdit_ValueChanged;
                        initCommands ();
                        Load ("#CrowEdit.ui.main.crow").DataSource = this;
-                       NotifyValueChanged ("CurFileFullPath", (object)CurFileFullPath);
                }
 
                /*void textView_KeyDown (object sender, Crow.KeyEventArgs e)
diff --git a/ui/CrowEdit.style b/ui/CrowEdit.style
new file mode 100644 (file)
index 0000000..ed6a861
--- /dev/null
@@ -0,0 +1,11 @@
+MenuIconSize = "14";
+
+MenuItem {
+       Template = "#CrowEdit.ui.MenuItem.template";
+}
+
+MenuIcon {
+       Margin = "2";
+       Width = "${MenuIconSize}";
+       Height = "${MenuIconSize}";
+}
index 5752b088ce7607ae7c589da03eafe79ba7f2f9c1..8c8f1d92d31d462eba3bdda24522eab558ca0b1a 100644 (file)
@@ -1,25 +1,25 @@
 <?xml version="1.0"?>
 <Popper Font="{./Font}" Caption="{./Caption}"  Background="{./Background}" PopDirection="{./PopDirection}"
-       Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
-       IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}">
+       Foreground = "{./Foreground}" CanPop="{./HasChildren}"
+       IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}">
        <Template>
-               <Border Name="border1"
-                               MouseEnter="{Foreground=vgradient|0:White|0.2:Gray|0.9:Gray|1:Black}"
-                               MouseLeave="{Foreground=Transparent}"
-                               MouseDown="{Foreground=vgradient|0:Black|0.05:Gray|0.85:Gray|1:White}"
-                               MouseUp="{Foreground=vgradient|0:White|0.2:Gray|0.9:Gray|1:Black}"
-                               MinimumSize = "40,0"
-                               Foreground="Transparent"
-                               Background="{./Background}">
-                               <HorizontalStack HorizontalAlignment="Left" Margin="1">
-                                       <Image MaximumSize="10,10" Picture="{../../../../Icon}"/>
-                                       <Label Text="{./Caption}"
-                                               Foreground="{./Foreground}"
-                                               Font="{./Font}" />
-                               </HorizontalStack>
-               </Border>
+               <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}">
+                       <Template>              
+                               <Border Name="border1"
+                                               MinimumSize = "60,0"
+                                               Foreground="Transparent"
+                                               Background="{./Background}">
+                                       <HorizontalStack HorizontalAlignment="Left" Margin="1">
+                                               <Image Style="MenuIcon" Picture="{../../../../../Icon}"/>
+                                               <Label Text="{./Caption}"
+                                                       Foreground="{./Foreground}"
+                                                       Font="{./Font}" />
+                                       </HorizontalStack>                                      
+                               </Border>
+                       </Template>             
+               </CheckBox>
        </Template>
-       <Border Foreground="DimGray" Width="{../PopWidth}" Height="{../PopHeight}" Background="Onyx">
+       <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="${MenuBackground}">
                <VerticalStack Name="ItemsContainer"/>
        </Border>
 </Popper>
index 07847f94dbbb4fd22c1231bee2352031c52a6c1a..4500e706e23adb3550aaba2556f13a23491e069c 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<VerticalStack Spacing="0" Background="DimGrey">
+<VerticalStack Spacing="0" >
        <Menu>
                <MenuItem Caption="File" Width="Fit" PopWidth="80">
                        <MenuItem Command="{CMDNew}" />
@@ -8,7 +8,7 @@
                        <MenuItem Command="{CMDSaveAs}" />
                        <MenuItem Command="{CMDQuit}" />
                </MenuItem>
-               <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="100">
+               <MenuItem Caption="Edit" Name="edit" Width="Fit" PopWidth="130">
                        <MenuItem Command="{CMDUndo}" />
                        <MenuItem Command="{CMDRedo}" />
                        <MenuItem Command="{CMDCut}" />
                        <HorizontalStack Height="Fit" Margin="2" Background="Onyx">
                                <Image Margin="2" Width="16" Height="16" Path="#Crow.Icons.level-up.svg" MouseClick="./goUpDirClick"
                                                         Background="Jet" MouseEnter="{Background=Grey}" MouseLeave="{Background=Jet}" />                       
-                               <TextBox Text="{²CurrentDir}" Margin="2"/>
+                               <TextBox Text="{²CurrentDir}" Margin="1"/>
                        </HorizontalStack>              
-                       <DirectoryView Margin="1" Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged"/>
+                       <DirectoryView Margin="0" Name="dv" CurrentDirectory="{CurrentDir}" SelectedItemChanged="Dv_SelectedItemChanged" Background="Jet"/>
                </VerticalStack>
                <Splitter Width="6" Visible="{ShowLeftPane}"/>
                <VerticalStack>
                        <HorizontalStack Height="Stretched" >
-                               <SourceEditor Focusable="true" Name="editor" Font="monospace, 12" VerticalAlignment="Top" FilePath="{CurFileFullPath}"
+                               <SourceEditor Focusable="true" Name="editor" Font="monospace, 12" VerticalAlignment="Top" FilePath="{CurrentFilePath}"
                                                Foreground="Jet" Background="White" Width="Stretched" Height="Stretched" KeyDown="textView_KeyDown"/>
                                <ScrollBar Name="scrollbarY" Value="{²../editor.ScrollY}"
-                                       Maximum="{../editor.MaxScrollY}" Orientation="Vertical" Width="14" />
+                                       Maximum="{../editor.MaxScrollY}" Orientation="Vertical" Width="14"
+                                       LargeIncrement="{../editor.VisibleLines}"
+                                 CursorSize="{../editor.ChildHeightRatio}"/>
                        </HorizontalStack>
                        <ScrollBar Style="HScrollBar" Name="scrollbarX" Value="{²../editor.ScrollX}"
-                                       Maximum="{../editor.MaxScrollX}" Height="14" />
+                                       Maximum="{../editor.MaxScrollX}" Height="14"
+                                       LargeIncrement="{../editor.VisibleColumns}"
+                                       CursorSize="{../editor.ChildWidthRatio}"/>
                        <HorizontalStack Height="Fit">
                                <Label Text="{../../editor.HoverError}" Width="Stretched"/>
                                <Widget Background="Red" Width="5" Height="5" Visible="{../../editor.IsDirty}"/>
index 8686dd531b1464860c6cb38421bdafbd89cb9e7b..433c53452c2fed4c9ed103333a4a34ee4732c3f1 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <FileDialog Width="60%" Height="50%" Caption="Open File" AlwaysOnTop="true"
-       CurrentDirectory="{CurrentDir}"
-       SelectedFile="{CurFilePath}"
+       CurrentDirectory="{CurFileDir}"
+       SelectedFile="{CurFileName}"
        OkClicked="openFileDialog_OkClicked"/>
 
index 3e262238ca4a20cfc340e5514a8774984857dc15..f5fb1f5368b737d205bdf05488ed5d51bc9ca92f 100644 (file)
@@ -1,3 +1,3 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<FileDialog Width="60%" Height="50%" Caption="Save File" CurrentDirectory="{CurrentDir}" OkClicked="saveFileDialog_OkClicked"/>
+<FileDialog Width="60%" Height="50%" Caption="Save File" CurrentDirectory="{CurFileDir}" OkClicked="saveFileDialog_OkClicked"/>