From 4c15030701964aee1c1dc908d6fa4dcdbec16a12 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 5 Oct 2015 12:08:56 +0200 Subject: [PATCH] threaded combo, Monodevelop addin improve --- GOLib.csproj | 2 +- MonoDevelop.GOLib/MonoDevelop.GOLib.addin.xml | 3 + MonoDevelop.GOLib/MonoDevelop.GOLib.csproj | 25 +++-- MonoDevelop.GOLib/src/DisplayBinding.cs | 2 +- MonoDevelop.GOLib/src/GOLibGtkHost.cs | 104 +++++++++++------- MonoDevelop.GOLib/src/GOLibNodeExtension.cs | 55 +++++++-- MonoDevelop.GOLib/src/GOLibView.cs | 89 ++++++++++++--- Tests/GOLIBTest_4.cs | 73 ++++++++++-- Tests/Interfaces/fps.goml | 44 ++++---- Tests/Interfaces/test4.goml | 24 +--- Tests/Tests.csproj | 11 +- src/CompilerServices/CompilerServices.cs | 1 - src/GraphicObjects/Combobox.cs | 86 ++++++++++----- src/GraphicObjects/GenericStack.cs | 2 + src/GraphicObjects/GraphicObject.cs | 59 +++++----- src/GraphicObjects/ListBox.cs | 78 +++++++++---- src/Interface.cs | 2 + src/LayoutingQueueItem.cs | 1 + src/OpenTKGameWindow.cs | 16 ++- 19 files changed, 469 insertions(+), 208 deletions(-) diff --git a/GOLib.csproj b/GOLib.csproj index 989740d6..2cd31f89 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -46,7 +46,7 @@ bin\Debug - TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME + TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME=1 \ No newline at end of file diff --git a/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj b/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj index 4dfac2d9..b2099b5a 100644 --- a/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj +++ b/MonoDevelop.GOLib/MonoDevelop.GOLib.csproj @@ -13,15 +13,12 @@ build - + - + @@ -57,6 +54,13 @@ \usr\local\lib\monodevelop\bin\MonoDevelop.Ide.dll False + + \usr\local\lib\monodevelop\bin\MonoDevelop.Core.dll + + + \usr\local\lib\monodevelop\AddIns\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.dll + False + gtk-sharp-2.0 @@ -73,15 +77,14 @@ - - \usr\local\lib\monodevelop\AddIns\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.dll - False - ..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll - - ..\..\..\..\..\usr\local\lib\monodevelop\bin\MonoDevelop.Core.dll + + ..\..\..\..\..\usr\local\lib\monodevelop\AddIns\DisplayBindings\SourceEditor\MonoDevelop.SourceEditor2.dll + + + ..\..\..\..\..\usr\local\lib\monodevelop\bin\Mono.TextEditor.dll diff --git a/MonoDevelop.GOLib/src/DisplayBinding.cs b/MonoDevelop.GOLib/src/DisplayBinding.cs index 55c6e78a..1898f16b 100644 --- a/MonoDevelop.GOLib/src/DisplayBinding.cs +++ b/MonoDevelop.GOLib/src/DisplayBinding.cs @@ -64,7 +64,7 @@ namespace MonoDevelop.GOLib } } public bool CanUseAsDefault - { get { return false; }} + { get { return true; }} public IViewContent CreateContent (FilePath fileName, string mimeType, Project ownerProject) { diff --git a/MonoDevelop.GOLib/src/GOLibGtkHost.cs b/MonoDevelop.GOLib/src/GOLibGtkHost.cs index f2a0bfa9..d041bba7 100644 --- a/MonoDevelop.GOLib/src/GOLibGtkHost.cs +++ b/MonoDevelop.GOLib/src/GOLibGtkHost.cs @@ -9,20 +9,31 @@ using MonoDevelop.Projects; using System.Diagnostics; using OpenTK.Input; using MonoDevelop.DesignerSupport; +using System.IO; +using MonoDevelop.Components.Commands; namespace MonoDevelop.GOLib { - public class GOLibGtkHost : Gtk.DrawingArea, ILayoutable, IGOLibHost, IPropertyPadProvider + public class GOLibGtkHost : Gtk.DrawingArea, ILayoutable, IGOLibHost, IPropertyPadProvider,ICommandDelegator { + #region ICommandDelegator implementation + + public object GetDelegatedCommandTarget () + { + return hoverWidget; + } + + #endregion + #region IPropertyPadProvider implementation public object GetActiveComponent () { - return hoverWidget; + return activeWidget; } public object GetProvider () { - return hoverWidget; + return activeWidget; } public void OnEndEditing (object obj) { @@ -30,7 +41,8 @@ namespace MonoDevelop.GOLib } public void OnChanged (object obj) { - + (obj as GraphicObject).registerForGraphicUpdate (); + QueueDraw (); } #endregion @@ -64,7 +76,7 @@ namespace MonoDevelop.GOLib Cairo.Context cr = Gdk.CairoHelper.Create(area.GdkWindow); _redrawClip.AddRectangle (this.ClientRectangle); - LoggingService.LogInfo ("expose event"); + //LoggingService.LogInfo ("expose event"); update (cr); @@ -85,7 +97,8 @@ namespace MonoDevelop.GOLib ((int)args.Event.X, (int)args.Event.Y, gtkButtonIdToOpenTkButton(args.Event.Button), true); Mouse_ButtonDown (o, e); - DesignerSupport.DesignerSupport.Service.SetPadContent (this); + + DesignerSupport.DesignerSupport.Service.SetPadContent (this, this); } void GOLibGtkHost_ButtonReleaseEvent (object o, Gtk.ButtonReleaseEventArgs args) { @@ -129,11 +142,42 @@ namespace MonoDevelop.GOLib public void Load(string path) { - goWidget = Interface.Load (path); + load(Interface.Load (path)); + } + + public void Load(Stream stream) + { + GraphicObject tmp = null; + try { + tmp = Interface.Load (stream, Interface.GetTopContainerOfGOMLStream (stream)); + } catch (Exception ex) { + return; + } + load (tmp); + QueueDraw (); + } + + void load(GraphicObject go) + { + if (goWidget != null) + DeleteWidget (goWidget); + goWidget = go; this.AddWidget (goWidget); } + public void AddWidget(GraphicObject g) + { + g.Parent = this; + GraphicObjects.Insert (0, g); + g.RegisterForLayouting ((int)LayoutingType.Sizing); + } + public void DeleteWidget(GraphicObject g) + { + g.Visible = false;//trick to ensure clip is added to refresh zone + g.ClearBinding(); + GraphicObjects.Remove (g); + } public List GraphicObjects = new List(); public Color Background = Color.Transparent; @@ -294,20 +338,6 @@ namespace MonoDevelop.GOLib #endregion - public void AddWidget(GraphicObject g) - { - g.Parent = this; - GraphicObjects.Insert (0, g); - - g.RegisterForLayouting ((int)LayoutingType.Sizing); - } - public void DeleteWidget(GraphicObject g) - { - g.Visible = false;//trick to ensure clip is added to refresh zone - g.ClearBinding(); - GraphicObjects.Remove (g); - } - // public void LoadInterface(string path, out T result) // { // GraphicObject.Load (path, out result, this); @@ -335,11 +365,11 @@ namespace MonoDevelop.GOLib #region Mouse Handling void Mouse_Move(object sender, MouseMoveEventArgs e) { - if (_activeWidget != null) { - //send move evt even if mouse move outside bounds - _activeWidget.onMouseMove (_activeWidget, e); - return; - } +// if (_activeWidget != null) { +// //send move evt even if mouse move outside bounds +// _activeWidget.onMouseMove (_activeWidget, e); +// return; +// } if (_hoverWidget != null) { //check topmost graphicobject first @@ -394,11 +424,11 @@ namespace MonoDevelop.GOLib } void Mouse_ButtonUp(object sender, MouseButtonEventArgs e) { - if (_activeWidget == null) - return; +// if (_activeWidget == null) +// return; - _activeWidget.onMouseButtonUp (this, e); - _activeWidget = null; + //_activeWidget.onMouseButtonUp (this, e); + //_activeWidget = null; MouseButtonUp.Raise (this, e); } void Mouse_ButtonDown(object sender, MouseButtonEventArgs e) @@ -407,17 +437,9 @@ namespace MonoDevelop.GOLib MouseButtonDown.Raise (this, e); return; } - - GraphicObject g = _hoverWidget; - while (!g.Focusable) { - g = g.Parent as GraphicObject; - if (g == null) { - return; - } - } - - _activeWidget = g; - _activeWidget.onMouseButtonDown (this, e); + + _activeWidget = _hoverWidget; + //_activeWidget.onMouseButtonDown (this, e); } void Mouse_WheelChanged(object sender, MouseWheelEventArgs e) diff --git a/MonoDevelop.GOLib/src/GOLibNodeExtension.cs b/MonoDevelop.GOLib/src/GOLibNodeExtension.cs index 3388c579..8c68d4cf 100644 --- a/MonoDevelop.GOLib/src/GOLibNodeExtension.cs +++ b/MonoDevelop.GOLib/src/GOLibNodeExtension.cs @@ -31,6 +31,7 @@ using MonoDevelop.Components; using MonoDevelop.Components.Commands; using MonoDevelop.Ide; using System.Linq; +using MonoDevelop.DesignerSupport; namespace MonoDevelop.GOLib { @@ -64,7 +65,7 @@ namespace MonoDevelop.GOLib } } - class GOLibCommandHandler: NodeCommandHandler + class GOLibCommandHandler: NodeCommandHandler //, IPropertyPadProvider { [CommandHandler (Commands.ShowGOLibViewer)] protected void OnShowGOLibViewer () @@ -80,19 +81,55 @@ namespace MonoDevelop.GOLib IdeApp.Workbench.OpenDocument (view, true); //IdeApp.Workbench.Documents.Where (d => d.FileName == file.FilePath); - } - public override void ActivateItem () - { + +// public override void ActivateItem () +// { // ProjectFile o = this.CurrentNode.DataItem as ProjectFile; +// // Ide.Gui.Document[] doc = IdeApp.Workbench.Documents.Where (d => d.FileName == o.FilePath).ToArray(); -// if (doc [0].ActiveView != null) -// return; - //doc [0].ActiveView.Select(); - OnShowGOLibViewer (); - } +// var tmp = MonoDevelop.Ide.Gui.DisplayBindingService.GetFileViewers (o.FilePath, o.Project).ToList(); +// +// OnShowGOLibViewer (); +// } +// #region IPropertyPadProvider implementation +// public object GetActiveComponent () +// { +// if (CurrentNodes.Length == 1) +// return CurrentNode.DataItem; +// else +// return null; +// } +// public object GetProvider () +// { +// return null; +// } +// public void OnEndEditing (object obj) +// { +// throw new NotImplementedException (); +// } +// public void OnChanged (object obj) +// { +// +// } +// #endregion } +// class GOLibItemPropertyProvider : IPropertyProvider +// { +// #region IPropertyProvider implementation +// public object CreateProvider (object obj) +// { +// var projectFile = obj as ProjectFile; +// return projectFile; +// } +// +// public bool SupportsObject (object obj) +// { +// return obj is ProjectFile; +// } +// #endregion +// } } diff --git a/MonoDevelop.GOLib/src/GOLibView.cs b/MonoDevelop.GOLib/src/GOLibView.cs index 650cfd09..a7cc3713 100644 --- a/MonoDevelop.GOLib/src/GOLibView.cs +++ b/MonoDevelop.GOLib/src/GOLibView.cs @@ -55,44 +55,107 @@ using MonoDevelop.Core; using MonoDevelop.Ide; using go; using MonoDevelop.DesignerSupport; +using MonoDevelop.SourceEditor; namespace MonoDevelop.GOLib { - class GOLibView : AbstractViewContent + class CustomVPaned : Gtk.VPaned, IPropertyPadProvider + { + #region IPropertyPadProvider implementation + public object GetActiveComponent () + { + return this.Child1 == null ? this as object: (this.Child1 as GOLibGtkHost).activeWidget as object; + } + public object GetProvider () + { + return null; + //throw new NotImplementedException (); + } + public void OnEndEditing (object obj) + { + //throw new NotImplementedException (); + } + public void OnChanged (object obj) + { + //throw new NotImplementedException (); + } + #endregion + + } + class GOLibView : SourceEditorView { GOLibGtkHost gtkGoWidgetHost; + CustomVPaned gtkGOMLWidget; double zoom = 1.0; public override Gtk.Widget Control { get { - return gtkGoWidgetHost; + return gtkGOMLWidget; } } - public GOLibView () + public GOLibView () : base() { gtkGoWidgetHost = new GOLibGtkHost (); + gtkGOMLWidget = new CustomVPaned (); + gtkGOMLWidget.CanFocus = true; + gtkGOMLWidget.Name = "vpaned1"; + gtkGOMLWidget.Add (gtkGoWidgetHost); + gtkGOMLWidget.Add (base.Control); + gtkGOMLWidget.SizeAllocated += GtkGOMLWidget_SizeAllocated; + this.Document.DocumentUpdated += Document_DocumentUpdated; + //this.DirtyChanged += GOLibView_DirtyChanged; } - public override void Load (string fileName) - { - gtkGoWidgetHost.Load (fileName); - ContentName = fileName; - this.IsDirty = false; + void Document_DocumentUpdated (object sender, EventArgs e) + { + reloadGOML (); + } + + void GOLibView_DirtyChanged (object sender, EventArgs e) + { - gtkGoWidgetHost.Show (); } - public override bool CanReuseView (string fileName) + + void reloadGOML() { - return base.CanReuseView (fileName); + using (MemoryStream stream = new MemoryStream ()) { + using (StreamWriter writer = new StreamWriter (stream)) { + writer.Write (this.Document.Text); + writer.Flush (); + + stream.Position = 0; + gtkGoWidgetHost.Load (stream); + } + } } - public override void RedrawContent () + + void GtkGOMLWidget_SizeAllocated (object o, Gtk.SizeAllocatedArgs args) { - base.RedrawContent (); + gtkGoWidgetHost.SetSizeRequest (-1, args.Allocation.Height / 2); + } + + public override void Load (string fileName) + { + gtkGoWidgetHost.Load (fileName); + //ContentName = fileName; + //this.IsDirty = false; + gtkGOMLWidget.ShowAll (); + gtkGOMLWidget.Show (); + + base.Load (fileName); } +// public override bool CanReuseView (string fileName) +// { +// return base.CanReuseView (fileName); +// } +// public override void RedrawContent () +// { +// base.RedrawContent (); +// } } } diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index a5cdbb49..62b9d257 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -82,6 +82,11 @@ namespace test new ClsItem("string 1"), new ClsItem("string 2") }); + int i = 0; + Color[] colorsArray; + volatile List loadedCols = new List(); + volatile bool allColsLoaded = false; + private static readonly object mutex = new object(); protected override void OnLoad (EventArgs e) { @@ -114,9 +119,18 @@ namespace test // }; - int i = 0; - foreach (Color col in Color.ColorDic) { - HorizontalStack s = colors.addChild (new HorizontalStack () { Fit = true}); + colorsArray = Color.ColorDic.ToArray (); + + Thread t = new Thread (loadingThread); + t.Start (); + +// ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList)); + } + + void loadingThread() + { + foreach (Color col in colorsArray) { + HorizontalStack s = new HorizontalStack () { Fit = true}; s.HorizontalAlignment = HorizontalAlignment.Left; Border b = new Border () { Bounds = new Size (32, 20), @@ -140,10 +154,18 @@ namespace test } ); i++; - if (i > 150) - break; - } -// ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList)); + + while(true){ + lock (mutex) { + loadedCols.Add (s); + break; + } + } + + Thread.Sleep (10); + + } + allColsLoaded = true; } void pFps_mousemove(object sender, MouseMoveEventArgs e) { @@ -154,7 +176,34 @@ namespace test c.Top += e.YDelta; c.registerForGraphicUpdate (); } - + void onButClick(object send, MouseButtonEventArgs e) + { + Color col = Color.ColorDic.ToArray () [i]; + HorizontalStack s = colors.addChild (new HorizontalStack () { Fit = true}); + s.HorizontalAlignment = HorizontalAlignment.Left; + Border b = new Border () { + Bounds = new Size (32, 20), + CornerRadius = 5, + Background = col, + BorderWidth = 2, + BorderColor = Color.Transparent, + Focusable = true + }; + b.MouseEnter += delegate(object sender, MouseMoveEventArgs ee) { + (sender as Border).BorderColor = Color.White; + }; + b.MouseLeave += delegate(object sender, MouseMoveEventArgs ee) { + (sender as Border).BorderColor = Color.Transparent; + }; + s.addChild (b); + + s.addChild ( + new Label (col.ToString ()){ + Bounds=new Rectangle(0,0,-1,-1), + } + ); + i++; + } private int frameCpt = 0; protected override void OnUpdateFrame (FrameEventArgs e) { @@ -162,6 +211,14 @@ namespace test fps = (int)RenderFrequency; + lock (mutex) { + if (loadedCols.Count > 50 || allColsLoaded) { + while (loadedCols.Count > 0) { + colors.addChild (loadedCols[0]); + loadedCols.RemoveAt (0); + } + } + } if (frameCpt > 200) { resetFps (); diff --git a/Tests/Interfaces/fps.goml b/Tests/Interfaces/fps.goml index baa85b63..91d02640 100755 --- a/Tests/Interfaces/fps.goml +++ b/Tests/Interfaces/fps.goml @@ -1,22 +1,24 @@  - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index d2866bb6..6bd2e14c 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -30,26 +30,12 @@ - - - + - - - +