From: Jean-Philippe Bruyère Date: Thu, 19 Nov 2020 08:14:07 +0000 (+0100) Subject: save commit X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=962f64759978614459b18f8645381ba8061bea2e;p=jp%2Fcrowedit.git save commit --- diff --git a/.gitignore b/.gitignore index a9f5d34..69b037a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ Thumbs.db #dotCover *.dotCover .vs +.vscode diff --git a/Crow.Coding/src/SourceEditor.cs b/Crow.Coding/src/SourceEditor.cs index e32efd9..4913dda 100644 --- a/Crow.Coding/src/SourceEditor.cs +++ b/Crow.Coding/src/SourceEditor.cs @@ -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 (); diff --git a/Crow.Coding/ui/IDE.style b/Crow.Coding/ui/IDE.style index 7fbe631..5a3c67b 100644 --- a/Crow.Coding/ui/IDE.style +++ b/Crow.Coding/ui/IDE.style @@ -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 index 2fc2936..0000000 --- a/Crow.Coding/ui/MenuItem.template +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - diff --git a/src/CrowEdit.cs b/src/CrowEdit.cs index 54cb1c4..cfe2b1f 100644 --- a/src/CrowEdit.cs +++ b/src/CrowEdit.cs @@ -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 undoStack = new List(); List redoStack = new List(); @@ -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("CurrentDir"); } @@ -46,16 +46,23 @@ namespace CrowEdit NotifyValueChanged (CurrentDir); } } - public string CurFilePath { - get { return _curFilePath; } + public string CurrentFilePath { + get { return Configuration.Global.Get ("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 ("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 index 0000000..ed6a861 --- /dev/null +++ b/ui/CrowEdit.style @@ -0,0 +1,11 @@ +MenuIconSize = "14"; + +MenuItem { + Template = "#CrowEdit.ui.MenuItem.template"; +} + +MenuIcon { + Margin = "2"; + Width = "${MenuIconSize}"; + Height = "${MenuIconSize}"; +} diff --git a/ui/MenuItem.template b/ui/MenuItem.template index 5752b08..8c8f1d9 100644 --- a/ui/MenuItem.template +++ b/ui/MenuItem.template @@ -1,25 +1,25 @@  + Foreground = "{./Foreground}" CanPop="{./HasChildren}" + IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}"> - + diff --git a/ui/main.crow b/ui/main.crow index 07847f9..4500e70 100755 --- a/ui/main.crow +++ b/ui/main.crow @@ -1,5 +1,5 @@  - + @@ -8,7 +8,7 @@ - + @@ -27,20 +27,24 @@ - + - + - + Maximum="{../editor.MaxScrollY}" Orientation="Vertical" Width="14" + LargeIncrement="{../editor.VisibleLines}" + CursorSize="{../editor.ChildHeightRatio}"/> + Maximum="{../editor.MaxScrollX}" Height="14" + LargeIncrement="{../editor.VisibleColumns}" + CursorSize="{../editor.ChildWidthRatio}"/>