From: Jean-Philippe Bruyère Date: Mon, 21 Jul 2025 18:35:08 +0000 (+0200) Subject: toolbox, undo/redo keybindings, dirty state forcing in crow service, wip X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=b217e275d4503cfe49dbe4e7ac613ee363adc190;p=jp%2Fcrowedit.git toolbox, undo/redo keybindings, dirty state forcing in crow service, wip --- diff --git a/CrowEditBase/src/Compiler/SourceDocument.cs b/CrowEditBase/src/Compiler/SourceDocument.cs index 8ee2e1d..a0f35ae 100644 --- a/CrowEditBase/src/Compiler/SourceDocument.cs +++ b/CrowEditBase/src/Compiler/SourceDocument.cs @@ -170,10 +170,10 @@ namespace CrowEditBase if (cancel.IsCancellationRequested) return; - NotifyValueChanged("Exceptions", Exceptions); + /*NotifyValueChanged("Exceptions", Exceptions); NotifyValueChanged ("SyntaxRootChildNodes", (object)null); NotifyValueChanged ("SyntaxRootChildNodes", SyntaxRootChildNodes); - Console.WriteLine("parse async finished"); + Console.WriteLine("parse async finished");*/ } } } \ No newline at end of file diff --git a/CrowEditBase/src/CrowEditBase.cs b/CrowEditBase/src/CrowEditBase.cs index 58459aa..b9b52b5 100644 --- a/CrowEditBase/src/CrowEditBase.cs +++ b/CrowEditBase/src/CrowEditBase.cs @@ -42,7 +42,7 @@ namespace CrowEditBase Document currentDocument; Editor currentEditor; Project currentProject; - public CommandGroup CommandsRoot, FileCommands, EditCommands, ViewCommands; + public CommandGroup CommandsRoot, FileCommands, EditCommands, ViewCommands, ToolBox; public ObservableList OpenedDocuments = new ObservableList (); public ObservableList Services = new ObservableList (); public ObservableList Plugins = new ObservableList (); diff --git a/CrowEditBase/src/CrowEditComponent.cs b/CrowEditBase/src/CrowEditComponent.cs index 79cbebc..ad6df55 100644 --- a/CrowEditBase/src/CrowEditComponent.cs +++ b/CrowEditBase/src/CrowEditComponent.cs @@ -17,6 +17,11 @@ namespace CrowEditBase //Debug.WriteLine ("Value changed: {0}->{1} = {2}", this, MemberName, _value); ValueChanged.Raise (this, new ValueChangeEventArgs (MemberName, _value)); } + public void NotifyValueChanged (string MemberName, string _value) + { + //Debug.WriteLine ("Value changed: {0}->{1} = {2}", this, MemberName, _value); + ValueChanged.Raise (this, new ValueChangeEventArgs (MemberName, _value)); + } public void NotifyValueChanged (object _value, [CallerMemberName] string caller = null) { NotifyValueChanged (caller, _value); diff --git a/CrowEditBase/src/Document.cs b/CrowEditBase/src/Document.cs index f91fdba..19e60ce 100644 --- a/CrowEditBase/src/Document.cs +++ b/CrowEditBase/src/Document.cs @@ -6,11 +6,12 @@ using System; using System.IO; using System.Threading; using Crow; +using Glfw; using static CrowEditBase.CrowEditBase; namespace CrowEditBase { - public abstract class Document : CrowEditComponent { + public abstract class Document : CrowEditComponent, ICommandHost { #region CTOR public Document (string fullPath, string editorPath) { initCommands (); @@ -31,8 +32,17 @@ namespace CrowEditBase /// public string EditorPath { get; private set; }//the ressource path is used as an id for editor template selection. public event EventHandler CloseEvent; + public event EventHandler KeyDown; - protected ReaderWriterLockSlim documentRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); + public bool OnKeyDown(object sender, KeyEventArgs e) { + if (KeyDown != null) { + KeyDown.Invoke (sender, e); + } + + return e.Handled; + } + + protected ReaderWriterLockSlim documentRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); public void EnterReadLock () => documentRWLock.EnterReadLock (); public void ExitReadLock () => documentRWLock.ExitReadLock (); public void EnterWriteLock () => documentRWLock.EnterWriteLock (); @@ -47,9 +57,9 @@ namespace CrowEditBase fullPath = value; NotifyValueChanged (fullPath); - NotifyValueChanged ("FileName", (object)FileName); - NotifyValueChanged ("FileDirectory", (object)Extension); - NotifyValueChanged ("Extension", (object)Extension); + NotifyValueChanged ("FileName", FileName); + NotifyValueChanged ("FileDirectory", FileDirectory); + NotifyValueChanged ("Extension", Extension); } } public string FileDirectory => System.IO.Path.GetDirectoryName (FullPath); @@ -59,17 +69,19 @@ namespace CrowEditBase (DateTime.Compare (accessTime, System.IO.File.GetLastWriteTime (FullPath)) < 0) : false; #region commands - public Command CMDUndo, CMDRedo, CMDSave, CMDSaveAs; Command CMDClose, CMDCloseOther; + public Command CMDUndo, CMDRedo, CMDSave, CMDSaveAs; public CommandGroup TabCommands => new CommandGroup ( CMDClose, CMDCloseOther ); protected virtual void initCommands () { - CMDUndo = new ActionCommand ("Undo", undo, "#icons.reply.svg", false); - CMDRedo = new ActionCommand ("Redo", redo, "#icons.share-arrow.svg", false); - CMDSave = new ActionCommand ("save", Save, "#icons.inbox.svg", false); + CMDUndo = new ActionCommand (this, "Undo", Undo, "#icons.reply.svg", new KeyBinding(Key.Z, Modifier.Control), false); + CMDRedo = new ActionCommand (this, "Redo", Redo, "#icons.share-arrow.svg", new KeyBinding(Key.Z, Modifier.Control | Modifier.Shift), false); + + CMDSave = new ActionCommand (this, "save", Save, "#icons.inbox.svg", new KeyBinding(Key.S, Modifier.Control), false); CMDSaveAs = new ActionCommand ("Save As...", SaveAs, "#icons.inbox.svg"); + CMDClose = new ActionCommand ("Close", () => App.CloseDocument (this), "#icons.sign-out.svg"); CMDCloseOther = new ActionCommand ("Close Others", () => App.CloseOthers (this), "#icons.inbox.svg"); } @@ -79,8 +91,8 @@ namespace CrowEditBase public abstract void RegisterClient (object client, bool initialState = false); public abstract void UnregisterClient (object client); protected abstract void saveFileDialog_OkClicked (object sender, EventArgs e); - protected abstract void undo(); - protected abstract void redo(); + public abstract void Undo(); + public abstract void Redo(); protected abstract void writeToDisk (); protected abstract void readFromDisk (); protected abstract void initNewFile (); diff --git a/CrowEditBase/src/Editor.cs b/CrowEditBase/src/Editor.cs index 4eebf3e..b8c4689 100644 --- a/CrowEditBase/src/Editor.cs +++ b/CrowEditBase/src/Editor.cs @@ -35,7 +35,6 @@ namespace CrowEditBase CMDCut = new ActionCommand (this, "Cut", Cut, "#icons.scissors.svg", new KeyBinding(Key.X, Modifier.Control), false); CMDCopy = new ActionCommand (this, "Copy", Copy, "#icons.copy-file.svg", new KeyBinding(Key.C, Modifier.Control), false); CMDPaste = new ActionCommand (this, "Paste", Paste, "#icons.paste-on-document.svg", new KeyBinding(Key.P, Modifier.Control), true); - ContextCommands = new CommandGroup (CMDCut, CMDCopy, CMDPaste); } @@ -701,8 +700,6 @@ namespace CrowEditBase } protected override void onDraw (IContext gr) { - //base.onDraw (gr); - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); @@ -814,23 +811,17 @@ namespace CrowEditBase if (!e.Handled) { TextSpan selection = Selection; update (new TextChange (selection.Start, selection.Length, e.KeyChar.ToString ())); - e.Handled = true; } - /*Insert (e.KeyChar.ToString()); - - SelRelease = -1; - SelBegin = new Point(CurrentColumn, SelBegin.Y); - - RegisterForGraphicUpdate();*/ } public override void onKeyDown (object sender, KeyEventArgs e) { Key key = e.Key; TextSpan selection = Selection; - /*document.EnterReadLock(); - try {*/ - switch (key) { + if (document != null && document.OnKeyDown(sender, e)) + return; + + switch (key) { case Key.Backspace: if (selection.IsEmpty) { if (selection.Start == 0) @@ -935,13 +926,10 @@ namespace CrowEditBase default: base.onKeyDown (sender, e); return; - } - autoAdjustScroll = true; - IFace.forceTextCursor(); - e.Handled = true; - /*} finally { - document.ExitReadLock (); - }*/ + } + autoAdjustScroll = true; + IFace.forceTextCursor(); + e.Handled = true; } #endregion #endregion @@ -1010,6 +998,8 @@ namespace CrowEditBase update (new TextChange (selection.Start, selection.Length, IFace.Clipboard)); } + + protected virtual void update (TextChange change) { if (!disableTextChangedEvent) OnTextChanged (this, new TextChangeEventArgs (change)); diff --git a/CrowEditBase/src/TextDocument.cs b/CrowEditBase/src/TextDocument.cs index e4b5cb7..d399ec5 100644 --- a/CrowEditBase/src/TextDocument.cs +++ b/CrowEditBase/src/TextDocument.cs @@ -114,7 +114,7 @@ namespace CrowEditBase writeToDisk (); } - protected override void undo () { + public override void Undo () { documentRWLock.EnterWriteLock (); try { if (undoStack.TryPop (out TextChange tc)) { @@ -130,7 +130,7 @@ namespace CrowEditBase documentRWLock.ExitWriteLock (); } } - protected override void redo () { + public override void Redo () { documentRWLock.EnterWriteLock (); try { if (redoStack.TryPop (out TextChange tc)) { diff --git a/CrowEditBase/ui/IconButton.template b/CrowEditBase/ui/IconButton.template new file mode 100644 index 0000000..b49e482 --- /dev/null +++ b/CrowEditBase/ui/IconButton.template @@ -0,0 +1,8 @@ + + diff --git a/plugins/CECrowPlugin/src/CrowService.cs b/plugins/CECrowPlugin/src/CrowService.cs index 80a9865..d06bf00 100644 --- a/plugins/CECrowPlugin/src/CrowService.cs +++ b/plugins/CECrowPlugin/src/CrowService.cs @@ -321,6 +321,7 @@ namespace CECrowPlugin CMDEditMode.CanExecute = !value; CMDRun.CanExecute = value; NotifyValueChanged(value); + ForceDirtyState(); } } public double ZoomFactor { @@ -363,7 +364,21 @@ namespace CECrowPlugin if (IsRunning) delUnlockRenderMutex(); } - public bool GetDirtyState => IsRunning ? (bool)fiDbgIFace_IsDirty.GetValue (dbgIFace) : false; + + bool dirtyState = false; + bool DirtyState { + get { + if (dirtyState) { + dirtyState = false; + return true; + } else + return false; + } + } + // force repaint of preview widget without debug interface update. + bool ForceDirtyState() => dirtyState = true; + + public bool GetDirtyState => IsRunning ? (bool)fiDbgIFace_IsDirty.GetValue (dbgIFace) | DirtyState : false; public bool DesignModeEnabled => IsRunning && ForeignWidgetContainer.fiWidget_design_id != null ? true : false; public Type GetWidgetTypeFromeName(string typeName) { if (!IsRunning) diff --git a/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs b/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs index 2cae562..fca8618 100644 --- a/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs +++ b/plugins/CECrowPlugin/src/ForeignWidgetContainer.cs @@ -44,7 +44,7 @@ namespace CECrowPlugin designColumn = (int)fiWidget_design_column?.GetValue(instance); designImlPath = (string)fiWidget_design_imlPath?.GetValue(instance); - Console.WriteLine($"new ForeignWidgetContainer: {this} {parent}"); + //Console.WriteLine($"new ForeignWidgetContainer: {this} {parent}"); } diff --git a/plugins/CECrowPlugin/src/Parsing/IML/ImlDocument.cs b/plugins/CECrowPlugin/src/Parsing/IML/ImlDocument.cs index 4406053..23b32c7 100644 --- a/plugins/CECrowPlugin/src/Parsing/IML/ImlDocument.cs +++ b/plugins/CECrowPlugin/src/Parsing/IML/ImlDocument.cs @@ -61,7 +61,7 @@ namespace CECrowPlugin } } public string TemplateContainerSource { - get => conf.Get (nameof(TemplateContainerSource), "