]> O.S.I.I.S - jp/crow.git/commitdiff
crowide wip, DesignIDS
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 17:18:42 +0000 (18:18 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 17:18:42 +0000 (18:18 +0100)
17 files changed:
CrowIDE/CrowIDE.csproj
CrowIDE/src/EditPane.cs
CrowIDE/src/ImlVisualEditor.cs
CrowIDE/src/MembersView.cs
CrowIDE/src/ProjectNodes.cs
CrowIDE/src/PropertyContainer.cs
CrowIDE/src/SourceEditor/SourceEditor.cs
CrowIDE/ui/CrowIDE.crow
CrowIDE/ui/EditPaneItems.template
CrowIDE/ui/IDE.style
CrowIDE/ui/IcoBut.template [new file with mode: 0644]
CrowIDE/ui/MembersItem.template [changed mode: 0644->0755]
CrowIDE/ui/MembersView.template
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs
src/Instantiator.cs

index 322e9beea866b8cc2a63eaab3b384e63dd124fef..b916d7169f8034986f24ae23099921e75be14a9e 100644 (file)
       <LogicalName>Crow.TreeExpandable.template</LogicalName>
     </EmbeddedResource>
     <EmbeddedResource Include="ui\ProjectTree.template" />
-    <EmbeddedResource Include="ui\MembersItem.template" />
     <EmbeddedResource Include="ui\EditPane.template">
       <LogicalName>Crow.Coding.EditPane.template</LogicalName>
     </EmbeddedResource>
     <EmbeddedResource Include="ui\Options.crow" />
     <EmbeddedResource Include="ui\IMLEdit.itemp" />
     <EmbeddedResource Include="ui\SrcEdit.itemp" />
+    <EmbeddedResource Include="ui\IcoBut.template" />
+    <EmbeddedResource Include="ui\MembersItem.template" />
   </ItemGroup>
   <ItemGroup>
     <None Include="ui\test.crow">
index d7ddba5ae5485b1ef04e222a5c4b87a34579ea86..780e86d5150be09bf42fb71676096d09ffeb60db 100644 (file)
@@ -31,9 +31,7 @@ namespace Crow.Coding
 {
        public class EditPane : TemplatedGroup
        {
-               public EditPane () : base()
-               {
-               }
+               public EditPane () {}
 
                object selectedItemElement = null;
 
index 3d59e9be1d4de87b472aa7c0d9c7de073002f4a9..7989936adad180005988f5ed3e10fe1026a4a87f 100644 (file)
@@ -43,7 +43,7 @@ namespace Crow.Coding
 
                DesignInterface imlVE;
                GraphicObject selectedItem;
-               ImlProjectItem projectItem;
+               ImlProjectItem projFile;
                Exception imlError = null;
 
                bool drawGrid;
@@ -97,35 +97,27 @@ namespace Crow.Coding
                [XmlIgnore]public List<LQIList> LQIs {
                        get { return imlVE.LQIs; }
                }
-
-               [XmlAttributeAttribute]
+                       
                public ProjectNode ProjectNode {
-                       get { return projectItem; }
+                       get { return projFile; }
                        set {
-                               if (projectItem == value)
+                               if (projFile == value)
                                        return;
 
+                               if (projFile != null)
+                                       projFile.UnregisterEditor (this);
+                               
+                               projFile = value as ImlProjectItem;
 
-                               if (projectItem != null)
-                                       projectItem.ValueChanged -= ProjectItem_ValueChanged;
-
-                               projectItem = value as ImlProjectItem;
-
-                               if (projectItem != null)
-                                       projectItem.ValueChanged += ProjectItem_ValueChanged;
+                               imlVE.ProjFile = projFile;
 
-                               NotifyValueChanged ("ProjectNode", projectItem);
+                               if (projFile != null)
+                                       projFile.RegisterEditor (this);
 
-                               reload ();
+                               NotifyValueChanged ("ProjectNode", projFile);
                        }
                }
 
-               void ProjectItem_ValueChanged (object sender, ValueChangeEventArgs e)
-               {
-                       if (e.MemberName == "Source")
-                               reload ();                      
-               }
-
                [XmlIgnore]public Exception IMLError {
                        get { return imlError; }
                        set {
@@ -140,24 +132,6 @@ namespace Crow.Coding
                        get { return imlError != null; }
                }
 
-               void reload(){
-                       if (projectItem == null)                                
-                               return;
-                       
-                       try {
-                               imlVE.ProjFile = projectItem;
-                               imlVE.Styling = projectItem.Project.solution.Styling;
-                               imlVE.DefaultTemplates = projectItem.Project.solution.DefaultTemplates;
-                               imlVE.Instantiators = new Dictionary<string, Instantiator>();
-                               imlVE.ClearInterface();
-                               imlVE.LoadIMLFragment(projectItem.Source);
-                               IMLError = null;
-                       } catch (Exception ex) {
-                               IMLError = ex.InnerException;
-                               Console.WriteLine (ex.ToString ());
-                       }
-               }
-
                public List<GraphicObject> GraphicTree {
                        get { return imlVE.GraphicTree; }
                }
@@ -166,9 +140,29 @@ namespace Crow.Coding
                {
                        while (true) {
                                try {
+                                       if (!projFile.RegisteredEditors[this]){
+                                               string selItemDesignID = null;
+                                               if (SelectedItem!=null)
+                                                       selItemDesignID = SelectedItem.design_id;
+                                               imlVE.ClearInterface();
+                                               Instantiator.NextInstantiatorID = 0;
+                                               imlVE.Styling = projFile.Project.solution.Styling;
+                                               imlVE.DefaultTemplates = projFile.Project.solution.DefaultTemplates;
+                                               imlVE.Instantiators = new Dictionary<string, Instantiator>();
+                                               imlVE.LoadIMLFragment(projFile.Source);
+                                               projFile.Instance = imlVE.GraphicTree[0];
+                                               GraphicObject go = null;
+                                               if (selItemDesignID!=null)
+                                                       projFile.Instance.FindByDesignID(selItemDesignID,out go);                                               
+                                               SelectedItem = go;
+                                               IMLError = null;
+                                               projFile.RegisteredEditors[this] = true;
+                                       }else if ((bool)projFile.Instance?.HasChanged){
+                                               projFile.UpdateSource(this, projFile.Instance.GetIML());
+                                       }
                                        imlVE.Update ();
                                } catch (Exception ex) {
-                                       System.Diagnostics.Debug.WriteLine (ex.ToString ());
+                                       IMLError = ex.InnerException;
                                        if (Monitor.IsEntered(imlVE.UpdateMutex))
                                                Monitor.Exit (imlVE.UpdateMutex);
                                }
@@ -215,9 +209,9 @@ namespace Crow.Coding
                        //base.onMouseDown (sender, e);
                        SelectedItem = HoverWidget;
 
-                       if (SelectedItem != null && projectItem != null) {
-                               projectItem.CurrentLine = HoverWidget.design_line;
-                               projectItem.CurrentColumn = HoverWidget.design_column;
+                       if (SelectedItem != null && projFile != null) {
+                               projFile.CurrentLine = SelectedItem.design_line;
+                               projFile.CurrentColumn = SelectedItem.design_column;
                        }
 
                }
index 79bcf5c415f408367836de35c2ea2134980032ff..f0c3a13a584f5dbab8fd9c4746851c8127d3c92d 100644 (file)
@@ -32,6 +32,12 @@ namespace Crow.Coding
        public class MembersView : ListBox
        {               
                object instance;
+               ImlProjectItem projFile;
+
+               public MembersView () : base() {}
+
+               //cache property containers per type
+               Dictionary<string,PropertyContainer[]> propContainersCache = new Dictionary<string, PropertyContainer[]>();
 
                [XmlAttributeAttribute][DefaultValue(null)]
                public virtual object Instance {
@@ -39,36 +45,70 @@ namespace Crow.Coding
                        set {
                                if (instance == value)
                                        return;
+                               object lastInst = instance;
+
                                instance = value;
                                NotifyValueChanged ("Instance", instance);
-                               if (Instance is GraphicObject)
-                                       NotifyValueChanged ("SelectedItemName", (Instance as GraphicObject).Name);
-                               else
+
+                               if (Instance is GraphicObject) {
+                                       NotifyValueChanged ("SelectedItemName", Instance.GetType().Name + (Instance as GraphicObject).design_id
+                                               + ":" + (Instance as GraphicObject).design_imlPath );
+                               }else
                                        NotifyValueChanged ("SelectedItemName", "");
 
-                               if (instance == null) {
+                               if (instance == null) { 
                                        Data = null;
                                        return;
+                               }       
+
+                               Type it = instance.GetType ();
+                               if (!propContainersCache.ContainsKey (it.FullName)) {
+                                       MemberInfo[] members = it.GetMembers (BindingFlags.Public | BindingFlags.Instance);
+                                       List<PropertyContainer> props = new List<PropertyContainer> ();
+                                       foreach (MemberInfo m in members) {
+                                               if (m.MemberType == MemberTypes.Property) {
+                                                       PropertyInfo pi = m as PropertyInfo;
+                                                       if (!pi.CanWrite)
+                                                               continue;
+                                                       if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null)
+                                                               continue;
+                                                       props.Add (new PropertyContainer (this, pi));
+                                               }
+                                       }
+                                       propContainersCache.Add (it.FullName, props.OrderBy (p => p.Name).ToArray ());
                                }
 
-                               MemberInfo[] members = instance.GetType ().GetMembers (BindingFlags.Public | BindingFlags.Instance);
+                               Data = propContainersCache [it.FullName];
 
-                               List<PropertyContainer> props = new List<PropertyContainer> ();
-                               foreach (MemberInfo m in members) {
-                                       if (m.MemberType == MemberTypes.Property) {
-                                               PropertyInfo pi = m as PropertyInfo;
-                                               if (!pi.CanWrite)
-                                                       continue;
-                                               if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null)
-                                                       continue;
-                                               props.Add (new PropertyContainer (pi, instance));
+                               if (lastInst != instance) {
+                                       foreach (PropertyContainer pc in propContainersCache [it.FullName]) {
+                                               pc.NotifyValueChanged ("Value", pc.Value);
                                        }
                                }
-                               Data = props.OrderBy(p=>p.Name).ToArray ();
                        }
                }
-               public MembersView () : base()
-               {
+               public ImlProjectItem ProjectNode {
+                       get { return projFile; }
+                       set {
+                               if (projFile == value)
+                                       return;
+                               
+//                             if (projFile != null)
+//                                     projFile.UnregisterEditor (this);
+                               
+                               projFile = value;
+
+//                             if (projFile != null)
+//                                     projFile.RegisterEditor (this);
+
+                               NotifyValueChanged ("ProjectNode", projFile);
+                       }
+               }
+
+               public void updateSource () {
+                       if (projFile == null)
+                               return;
+                       projFile.UpdateSource (this, (Instance as GraphicObject).GetIML ());
                }
 
 //             public override void Paint (ref Context ctx)
index c668cfd3bfd1d67c44c6fc8c4dbc19ab2adba080..eb7d6506ea6c837e68fca753c33b96aa63b18fa4 100644 (file)
@@ -29,6 +29,7 @@ using System.Linq;
 using System.Xml;
 using System.IO;
 using Crow;
+using System.Threading;
 
 namespace Crow.Coding
 {
@@ -61,17 +62,24 @@ namespace Crow.Coding
                public ProjectNode (Project project, ItemType _type, string _name) : this(project){                     
                        type = _type;
                        name = _name;
+                       initCommands ();
                }
                public ProjectNode (Project project){
                        Project = project;
+                       initCommands ();
                }
                #endregion
 
+               void initCommands () {
+                       Commands = new List<Crow.Command> ();
+               }
+
                ItemType type;
                string name;
                List<ProjectNode> childNodes = new List<ProjectNode>();
 
                public Project Project;
+               public List<Crow.Command> Commands;//list of command available for that node
 
                public virtual ItemType Type {
                        get { return type; }
@@ -143,21 +151,29 @@ namespace Crow.Coding
        }
 
        public class ProjectFile : ProjectItem {                
-               bool isOpened = false;
+               protected bool isOpened = false;
                DateTime accessTime;
                string source;
                string origSource;
                object selectedItem;
+               int curLine, curColumn;
+
+               internal ReaderWriterLockSlim srcEditMtx = new ReaderWriterLockSlim();
+
+               public Dictionary<object, bool> RegisteredEditors = new Dictionary<object, bool>();
+
+               Crow.Command cmdSave, cmdOpen;
 
-               public List<Crow.Command> Commands;
+               public ProjectFile (ProjectItem pi)
+                       : base (pi.Project, pi.node) {
 
-               public ProjectFile (ProjectItem pi) : base (pi.Project, pi.node){
-                       Commands = new List<Crow.Command> (new Crow.Command[] {
-                               new Crow.Command(new Action(() => Open())) 
-                               { Caption = "Open", Icon = new SvgPicture("#Crow.Coding.ui.icons.outbox.svg"), CanExecute = false},
-                               new Crow.Command(new Action(() => Save()))
-                               { Caption = "Save", Icon = new SvgPicture("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = false},
-                       });
+                       cmdSave = new Crow.Command (new Action (() => Save ()))
+                               { Caption = "Save", Icon = new SvgPicture ("#Crow.Coding.ui.icons.inbox.svg"), CanExecute = false };
+                       cmdOpen = new Crow.Command (new Action (() => Open ())) 
+                               { Caption = "Open", Icon = new SvgPicture ("#Crow.Coding.ui.icons.outbox.svg"), CanExecute = false };
+
+                       Commands.Insert (0, cmdOpen);
+                       Commands.Insert (1, cmdSave);
                }
 
                public string ResourceID {
@@ -173,6 +189,28 @@ namespace Crow.Coding
                                return node.SelectSingleNode ("LogicalName")?.InnerText;
                        }
                }
+
+               public void UnregisterEditor (object editor){
+                       lock(RegisteredEditors){
+                               RegisteredEditors.Remove (editor);
+                       }
+               }
+               public void RegisterEditor (object editor) {
+                       lock(RegisteredEditors){
+                               RegisteredEditors.Add (editor, false);
+                       }
+               }
+               public void UpdateSource (object sender, string newSrc){
+                       System.Diagnostics.Debug.WriteLine ("update source by {0}", sender);
+                       Source = newSrc;
+                       lock (RegisteredEditors) {
+                               object[] keys = RegisteredEditors.Keys.ToArray ();
+                               foreach (object editor in keys) {
+                                       if (editor != sender)
+                                               RegisteredEditors [editor] = false;
+                               }
+                       }
+               }
                public string Source {
                        get {
                                if (!isOpened)
@@ -188,15 +226,19 @@ namespace Crow.Coding
                        set {
                                if (source == value)
                                        return;
+                               
+                               srcEditMtx.EnterWriteLock ();
+
                                source = value;
                                NotifyValueChanged ("Source", source);
                                NotifyValueChanged ("IsDirty", IsDirty);
+
+                               srcEditMtx.ExitWriteLock ();
                        }
                }
                public bool IsDirty {
                        get { return source != origSource; }
                }
-               int curLine, curColumn;
                public int CurrentColumn{
                        get { return curColumn; }
                        set {
@@ -215,15 +257,6 @@ namespace Crow.Coding
                                NotifyValueChanged ("CurrentLine", curLine);
                        }
                }
-//             public bool IsSelected {
-//                     get { return isSelected; }
-//                     set { 
-//                             if (isSelected == value)
-//                                     return;
-//                             isSelected = value;
-//                             NotifyValueChanged ("IsSelected", isSelected);                          
-//                     }
-//             }
 
                public object SelectedItem {
                        get { return selectedItem; }
@@ -239,10 +272,6 @@ namespace Crow.Coding
                public CopyToOutputState CopyToOutputDirectory {
                        get {
                                XmlNode xn = node.SelectSingleNode ("CopyToOutputDirectory");
-//                             if (xn == null)
-//                                     return CopyToOutputState.Never;
-//                             CopyToOutputState tmp = (CopyToOutputState)Enum.Parse (typeof(CopyToOutputState), xn.InnerText, true);
-//                             return tmp;
                                return xn == null ? CopyToOutputState.Never :
                                        (CopyToOutputState)Enum.Parse (typeof(CopyToOutputState), xn.InnerText, true);
                        }
@@ -266,6 +295,8 @@ namespace Crow.Coding
                }
 
                public void OnQueryClose (object sender, EventArgs e){
+                       if (IsDirty)
+                               Console.WriteLine ("closing unsaved file");
                        Project.solution.CloseItem (this);
                }
        }
@@ -276,6 +307,21 @@ namespace Crow.Coding
                }
                #endregion
 
+               GraphicObject instance;
+
+               /// <summary>
+               /// instance created with an instantiator from the source by a DesignInterface,
+               /// for now, the one in ImlVisualEditor
+               /// </summary>
+               public GraphicObject Instance {
+                       get { return instance; }
+                       set {
+                               if (instance == value)
+                                       return;
+                               instance = value;
+                               NotifyValueChanged ("Instance", instance);
+                       }
+               }
        }
 }
 
index feea647778184785345397630d76bfe5afd5f7df..6caec9d49290d9f55f0f3428f50ae4e5a0cb2207 100644 (file)
@@ -26,6 +26,8 @@
 using System;
 using System.Reflection;
 using System.Linq;
+using System.Collections.Generic;
+using System.Diagnostics;
 
 namespace Crow.Coding
 {
@@ -39,44 +41,84 @@ namespace Crow.Coding
                }
                #endregion
 
+               public List<Crow.Command> Commands;
                PropertyInfo pi;
-               object instance;
-               GraphicObject go;
+               MembersView mview;
+//             object instance;
+//             GraphicObject go;
+
+               public PropertyContainer(MembersView mv, PropertyInfo prop){
+                       mview = mv;
+                       pi = prop;
+//                     instance = _instance;
+//                     go = instance as GraphicObject;
+
+                       Commands = new List<Crow.Command> (new Crow.Command[] {
+                               new Crow.Command(new Action(() => Reset())) { Caption = "Reset to default"},
+                       });
+               }
 
                public string Name { get { return pi.Name; }}
                public object Value {
-                       get { return go.design_members.ContainsKey(Name) ?
-                               go.design_members[Name] : pi.GetValue(instance); }
+                       get {
+                               return pi.GetValue(mview.ProjectNode.SelectedItem);
+//                             GraphicObject inst = mview.ProjectNode.SelectedItem as GraphicObject;
+//                             Debug.WriteLine("read {0}.{1}", inst.Name, Name);
+//                             if (!inst.design_members.ContainsKey (Name))
+//                                     return pi.GetValue (inst);
+//                             
+//                             if (inst.design_members [Name].StartsWith ("{"))
+//                                     return inst.design_members [Name];
+//                             else
+//                                     return pi.GetValue (inst);
+                       }
                        set {
-                               if (go.design_members.ContainsKey (Name)) {
-                                       if (go.design_members [Name] == (string)value)
-                                               return;
+                               try {
+                                       GraphicObject inst = mview.ProjectNode.SelectedItem as GraphicObject;
+                                       string valstr = null;
+                                       if (value != null)
+                                               valstr = value.ToString();
+                                       if (inst.design_members.ContainsKey (Name)) {
+                                               if (inst.design_members [Name] == valstr)
+                                                       return;
+                                               Debug.WriteLine("update {0} : {1} = {2}", inst.Name, Name, valstr);
+                                               inst.design_members [Name] = value.ToString();
+                                       } else {
+                                               Debug.WriteLine("add {0} : {1} = {2}", inst.Name, Name, valstr);
+                                               inst.design_members.Add (Name, value.ToString());
+                                       }                               
+
+                                       if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){
+                                               if (pi.PropertyType.IsEnum) {
+                                                       if (value is string) {
+                                                               pi.SetValue (inst, Enum.Parse (pi.PropertyType, (string)value));
+                                                       }else
+                                                               pi.SetValue (inst, value);
+                                               } else {
+                                                       MethodInfo me = pi.PropertyType.GetMethod
+                                                               ("Parse", BindingFlags.Static | BindingFlags.Public,
+                                                                       System.Type.DefaultBinder, new Type [] {typeof (string)},null);
+                                                       pi.SetValue (inst, me.Invoke (null, new object[] { value }), null);
+                                               }
+                                       }else
+                                               pi.SetValue(inst, value);
+                                       
+                                       mview.ProjectNode.Instance.HasChanged = true;
+                                       NotifyValueChanged ("Value", value);
+                                       NotifyValueChanged ("LabForeground", LabForeground);
+                               } catch (Exception ex) {
+                                       System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString());
                                }
-                               go.design_members [Name] = (string)value;
-//                             try {
-//                                     if (!pi.PropertyType.IsAssignableFrom(value.GetType()) && pi.PropertyType != typeof(string)){
-//                                             if (pi.PropertyType.IsEnum) {
-//                                                     if (value is string) {
-//                                                             pi.SetValue (instance, Enum.Parse (pi.PropertyType, (string)value));
-//                                                     }else
-//                                                             pi.SetValue (instance, value);
-//                                             } else {
-//                                                     MethodInfo me = pi.PropertyType.GetMethod
-//                                                             ("Parse", BindingFlags.Static | BindingFlags.Public,
-//                                                                     System.Type.DefaultBinder, new Type [] {typeof (string)},null);
-//                                                     pi.SetValue (instance, me.Invoke (null, new object[] { value }), null);
-//                                             }
-//                                     }else
-//                                             pi.SetValue(instance, value);
-//                             } catch (Exception ex) {
-//                                     System.Diagnostics.Debug.WriteLine ("Error setting property:"+ ex.ToString());
-//                             }
-                               NotifyValueChanged ("Value", value);
+                               //
                        }
                }
+               /// <summary>
+               /// for style attribute which is a string, return Style as type
+               /// </summary>
                public string Type { get { return pi.PropertyType.IsEnum ?
                                "System.Enum"
-                                       : pi.PropertyType.FullName; }}
+                                       : pi.Name == "Style" ? "Style" : pi.PropertyType.FullName; }}
+               
                public object[] Choices {
                        get {
                                return Enum.GetValues (pi.PropertyType).Cast<object>().ToArray();
@@ -84,15 +126,24 @@ namespace Crow.Coding
                }
 
                public Fill LabForeground {
-                       get { return go.design_members.ContainsKey(Name) ? Color.Black : Color.DimGray;}
+                       get { return (mview.ProjectNode.SelectedItem as GraphicObject).design_members.ContainsKey(Name) ? Color.Black : Color.DimGray;}
                }
 
-               public PropertyContainer(PropertyInfo prop, object _instance){
-                       pi = prop;
-                       instance = _instance;
-                       go = instance as GraphicObject;
+               /// <summary>
+               /// reset to default value
+               /// </summary>
+               public void Reset () {
+                       GraphicObject inst = mview.ProjectNode.SelectedItem as GraphicObject;
+                       if (!inst.design_members.ContainsKey (Name))
+                               return;
+                       inst.design_members.Remove (Name);
+                       //NotifyValueChanged ("Value", Value);
+                       mview.ProjectNode.Instance.HasChanged = true;
+                       //should reinstantiate to get default
                }
 
+
+
        }
 }
 
index db83b2baff0386af4c6159c8327d1eca73593631..d594776eab0c62bcb4bd18b174a81b48768b3060 100644 (file)
@@ -86,10 +86,25 @@ namespace Crow.Coding
                string oldSource = "";
                void updateSourceThreadFunc (){
                        while (true) {
-                               if (projNode != null && buffer != null) {
-                                       string newSrc = buffer.FullText;
-                                       if (projNode.Source != newSrc)
-                                               projNode.Source = newSrc;
+                               if (projFile != null && buffer != null) {
+                                       if (!projFile.RegisteredEditors [this]) {
+                                               loadSource ();
+                                               isDirty = false;
+                                               oldSource = projFile.Source;
+                                               projFile.RegisteredEditors [this] = true;
+                                       }
+                                       if (Monitor.TryEnter (buffer.EditMutex)) {
+                                               string newsrc = "";
+                                               bool wasDirty = false;
+                                               if (isDirty) {
+                                                       isDirty = false;
+                                                       wasDirty = true;
+                                                       newsrc = buffer.FullText;
+                                               }
+                                               Monitor.Exit (buffer.EditMutex);
+                                               if (wasDirty) 
+                                                       projFile.UpdateSource (this, newsrc);                                           
+                                       }
                                }
                                Thread.Sleep (100);
                        }
@@ -99,7 +114,7 @@ namespace Crow.Coding
 
                #region private and protected fields
                bool foldingEnabled = true;
-               ProjectFile projNode = null;
+               ProjectFile projFile = null;
                int leftMargin = 0;     //margin used to display line numbers, folding errors,etc...
                int visibleLines = 1;
                int visibleColumns = 1;
@@ -203,6 +218,8 @@ namespace Crow.Coding
                        buffer.ToogleFolding (line);
                }
 
+               volatile bool isDirty = false;
+
                #region Buffer events handlers
                void Buffer_BufferCleared (object sender, EventArgs e)
                {
@@ -213,6 +230,7 @@ namespace Crow.Coding
                        PrintedLines = null;
                        RegisterForGraphicUpdate ();
                        notifyPositionChanged ();
+                       isDirty = true;
                }
                void Buffer_LineAdditionEvent (object sender, CodeBufferEventArgs e)
                {
@@ -237,6 +255,7 @@ namespace Crow.Coding
                        updateMaxScrollY ();
                        RegisterForGraphicUpdate ();
                        notifyPositionChanged ();
+                       isDirty = true;
                }
                void Buffer_LineRemoveEvent (object sender, CodeBufferEventArgs e)
                {
@@ -254,6 +273,7 @@ namespace Crow.Coding
                        updateMaxScrollY ();
                        RegisterForGraphicUpdate ();
                        notifyPositionChanged ();
+                       isDirty = true;
                }
                void Buffer_LineUpadateEvent (object sender, CodeBufferEventArgs e)
                {
@@ -273,6 +293,7 @@ namespace Crow.Coding
                        
                        RegisterForGraphicUpdate ();
                        notifyPositionChanged ();
+                       isDirty = true;
                }
                void Buffer_PositionChanged (object sender, EventArgs e)
                {
@@ -356,39 +377,45 @@ namespace Crow.Coding
                public ProjectFile ProjectNode
                {
                        get {
-                               return projNode;
+                               return projFile;
                        }
                        set
                        {
-                               if (projNode == value)
+                               if (projFile == value)
                                        return;
 
-                               projNode = value;
+                               if (projFile != null)
+                                       projFile.UnregisterEditor (this);
 
-                               NotifyValueChanged ("ProjectNode", projNode);
+                               projFile = value;
+                               NotifyValueChanged ("ProjectNode", projFile);
 
-                               if (projNode == null)
-                                       return;
-                               
-                               if (!File.Exists (projNode.AbsolutePath))
+                               if (projFile == null)
                                        return;
 
-                               parser = getParserFromExt (System.IO.Path.GetExtension (projNode.Extension));
+                               parser = getParserFromExt (System.IO.Path.GetExtension (projFile.Extension));
 
-                               try {
-                                       buffer.Load (projNode.Source);
-                                       oldSource = projNode.Source;
-                               } catch (Exception ex) {
-                                       Debug.WriteLine (ex.ToString ());
-                               }
-
-                               updateMaxScrollY ();
-                               MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
-                               updatePrintedLines ();
+                               projFile.RegisterEditor (this);
 
-                               RegisterForGraphicUpdate ();
                        }
                }
+               void loadSource () {
+                       
+                       try {
+                               buffer.Load (projFile.Source);
+                       } catch (Exception ex) {
+                               Debug.WriteLine (ex.ToString ());
+                       }
+
+                       projFile.RegisteredEditors [this] = true;
+
+                       updateMaxScrollY ();
+                       MaxScrollX = Math.Max (0, buffer.longestLineCharCount - visibleColumns);
+                       updatePrintedLines ();
+
+                       RegisterForGraphicUpdate ();
+               }
+
                [XmlAttributeAttribute][DefaultValue("BlueGray")]
                public virtual Color SelectionBackground {
                        get { return selBackground; }
index d2be368c253c448aaa3f278979a8bdb9926a0634..9e2694f99deaed4657c818730fffa45eeaba1039 100644 (file)
@@ -42,7 +42,8 @@
                                                Data="{Projects}" SelectedItemChanged="onSelectedItemChanged"
                                                ItemTemplate="#Crow.Coding.ui.ProjectTree.template"/>
                                        <Splitter/>
-                                       <MembersView Instance="{SelectedItemElement}" DataTest="Type"
+                                       <MembersView ProjectNode="{SelectedItem}"
+                                               Instance="{SelectedItemElement}" DataTest="Type"
                                                ItemTemplate="#Crow.Coding.ui.MembersItem.template"/>
                                </VerticalStack>
                        </HorizontalStack>
index af7e7d10d92e378ca057378eb552248c4b2b28bb..e5e9b280d81734bcac33177169711cf3d2cda00b 100644 (file)
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="UTF-8" ?>
+<?xml version="1.0"?>
 <ItemTemplate> 
        <TabItem Caption="{DisplayName}" QueryClose="OnQueryClose">
                <Label Text="Error" Background="Red"/>
        </TabItem>
 </ItemTemplate>
-<ItemTemplate DataType=".svg" DataTest="Extension">
+<ItemTemplate DataType=".svg">
        <TabItem Caption="{DisplayName}" QueryClose="OnQueryClose">
                <Image Path="{AbsolutePath}"/>
        </TabItem>
 </ItemTemplate>
-<ItemTemplate Path="#Crow.Coding.ui.SrcEdit.itemp" DataType=".cs" DataTest="Extension"/>
-<ItemTemplate Path="#Crow.Coding.ui.SrcEdit.itemp" DataType=".style" DataTest="Extension"/>
-<ItemTemplate Path="#Crow.Coding.ui.IMLEdit.itemp" DataType=".crow" DataTest="Extension"/>
-<ItemTemplate Path="#Crow.Coding.ui.IMLEdit.itemp" DataType=".template" DataTest="Extension"/>
+<ItemTemplate Path="#Crow.Coding.ui.SrcEdit.itemp" DataType=".cs"/>
+<ItemTemplate Path="#Crow.Coding.ui.SrcEdit.itemp" DataType=".style"/>
+<ItemTemplate Path="#Crow.Coding.ui.IMLEdit.itemp" DataType=".crow"/>
+<ItemTemplate Path="#Crow.Coding.ui.IMLEdit.itemp" DataType=".template"/>
index 3dce97faaa1be2df252b571612aaa6ab71bfb188..d7212053ed096dd9b33c8dbf287528fa121099c5 100644 (file)
@@ -15,3 +15,11 @@ MemberViewHStack {
        MouseEnter={Background=UnitedNationsBlue};
        MouseLeave={Background=Transparent};
 }
+
+IcoBut {
+       Template = #Crow.Coding.ui.IcoBut.template;
+       MinimumSize = 10,10;
+       Width = 8;
+       Height = 14;
+       Background = White;
+}
\ No newline at end of file
diff --git a/CrowIDE/ui/IcoBut.template b/CrowIDE/ui/IcoBut.template
new file mode 100644 (file)
index 0000000..a9fc28a
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<Border Background="{./Background}" Name="Content"
+       BorderWidth="1" BorderStyle="Normal"
+       MouseDown="{BorderStyle=Sunken}"
+       MouseUp="{BorderStyle=Normal}">
+       <Image Margin="1" Path="#Crow.Coding.ui.icons.blank-file.svg" />
+</Border>
old mode 100644 (file)
new mode 100755 (executable)
index 5c56406..cc653ef
@@ -1,18 +1,18 @@
-<?xml version="1.0"?>
+<?xml version="1.0"?>
 <ItemTemplate>
-       <HorizontalStack Style="MemberViewHStack" >
+       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
                <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
                <TextBox Margin="1" Text="{²Value}" Height="Fit" Foreground = "{LabForeground}"/>
        </HorizontalStack>
 </ItemTemplate>
-<ItemTemplate DataType="System.Boolean">
-       <HorizontalStack Style="MemberViewHStack" >
+<ItemTemplate DataType="System.Boolean" >
+       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
                <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
                <CheckBox Background="White" Foreground = "{LabForeground}" Height="Stretched" Caption="" IsChecked="{²Value}"/>
        </HorizontalStack>
 </ItemTemplate>
 <ItemTemplate DataType="System.Enum">
-       <HorizontalStack Style="MemberViewHStack" >
+       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
                <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
                <ComboBox Margin="0"  Height="Stretched" Width="50%" Data="{Choices}"
                                SelectedItem="{²Value}">
@@ -27,7 +27,7 @@
                                                                                        Text="{../../../../../SelectedItem}"/>
                                                                                <Button Width="12" Height="12" Focusable="false"
                                                                                        Template="#Crow.Templates.ArrowBut.template">
-                                                                                       <Image Margin="1"  Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
+                                                                                       <Image Margin="1" Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
                                                                                </Button>
                                                                        </HorizontalStack>
                                                                </Border>
        </HorizontalStack>
 </ItemTemplate>
 <ItemTemplate DataType="Crow.Fill">
-       <HorizontalStack Style="MemberViewHStack" >
+       <HorizontalStack Style="MemberViewHStack" ContextCommands="{Commands}">
                <Label Style="MemberViewLabel" Text="{Name}" Foreground = "{LabForeground}"/>
-               <Popper Background="White" Margin="0" Height="Stretched" Caption="{Value}">
+               <Popper Height="Stretched" Caption="{Value}">
                        <Template>
-                               <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Background="{./Background}">
+                               <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}">
                                        <Template>
-                                               <HorizontalStack Spacing="3" Height="Fit" Background="{./Background}">
-                                                       <Border Foreground="{LabForeground}" Width="16" Height="10" CornerRadius="3"
+                                               <HorizontalStack Margin="1" Height="Stretched" Spacing="3" Background="White">
+                                                       <Border Foreground="{LabForeground}" Width="18" Height="12" CornerRadius="3"
                                                                Background="{Value}">
                                                        </Border>
-                                                       <Label Text="{./Caption}" Foreground="{LabForeground}"/>
+                                                       <Label Width="Stretched" Text="{./Caption}" Foreground="{LabForeground}"/>
                                                </HorizontalStack>
                                        </Template>
                                </CheckBox>
index 9784d737e321739a398cbc8a56be5bfe20c3cce9..07938b0e9e99f26cfe10be93dea1bc6d4c3fc186 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <VerticalStack>
        <Border Height="Fit">
-               <Label TextAlignment="Left" Text="{../../../SelectedItemName}" Width="Stretched"/>
+               <Label TextAlignment="Left" Text="{./SelectedItemName}" Width="Stretched"/>
        </Border>
        <HorizontalStack>
                <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"
index fadbe124f3a0846a39878f1c2a24b08020c07c21..f5a1a224efe78fe022742c328f68d6cc7ffc201d 100644 (file)
@@ -52,12 +52,23 @@ namespace Crow
                internal ReaderWriterLockSlim parentRWLock = new ReaderWriterLockSlim();
 
                #if DESIGN_MODE
+               public volatile bool HasChanged = false;
+               public string design_id;
                public int design_line;
                public int design_column;
                public string design_imlPath;
                public Dictionary<string,string> design_members = new Dictionary<string, string>();
                public bool design_isTGItem = false;
 
+               public virtual bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (this.design_id == designID){
+                               go = this;
+                               return true;
+                       }
+                       return false;
+               }
+
                public string GetIML(){
                        XmlDocument doc = new XmlDocument( );
 
@@ -73,6 +84,7 @@ namespace Crow
                                        getIML (doc, (XmlNode)doc);
                                        doc.WriteTo (xtw);
                                }
+                               this.HasChanged = false;
                                return sw.ToString ();
                        }
                }
index 2875b4de191c3f1d09911e8c807c0dc119bb733f..0eb1ece239d6215158b38cc6ef9ea5979b7ae7e1 100644 (file)
@@ -39,6 +39,20 @@ namespace Crow
        public class Group : GraphicObject
     {
                #if DESIGN_MODE
+               public override bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (base.FindByDesignID (designID, out go))
+                               return true;
+                       childrenRWLock.EnterReadLock ();
+                       foreach (GraphicObject w in Children) {
+                               if (!w.FindByDesignID (designID, out go))
+                                       continue;
+                               childrenRWLock.ExitReadLock ();
+                               return true;
+                       }
+                       childrenRWLock.ExitReadLock ();
+                       return false;
+               }
                public override void getIML (System.Xml.XmlDocument doc, System.Xml.XmlNode parentElem)
                {
                        if (this.design_isTGItem)
index f2626e255a17fd6dd26b02d9c534fd6d34fd1e3c..81017a7e6bb440558af61a5610e75f3711daa40f 100644 (file)
@@ -45,6 +45,14 @@ namespace Crow
                public PrivateContainer (Interface iface) : base(iface){}
                #endregion
 
+               #if DESIGN_MODE
+               public override bool FindByDesignID(string designID, out GraphicObject go){
+                       go = null;
+                       if (base.FindByDesignID (designID, out go))
+                               return true;
+                       return (bool)child?.FindByDesignID (designID, out go);                          
+               }
+               #endif
                protected GraphicObject child;
 
                protected virtual void SetChild(GraphicObject _child)
index c0b886ada2684694d959d2938f7409827a1b512e..5c6711f5f0e1bff56958f772701ebe88e3d3b8ce 100644 (file)
@@ -74,6 +74,13 @@ namespace Crow.IML
 
                internal string sourcePath;
 
+               #if DESIGN_MODE
+               public static int NextInstantiatorID = 0;
+               public int currentInstantiatorID = 0;
+               int currentDesignID = 0;
+               internal string NextDesignID { get { return string.Format ("{0}_{1}",currentInstantiatorID, currentDesignID++); }}
+               #endif
+
                #region CTOR
                /// <summary>
                /// Initializes a new instance of the Instantiator class.
@@ -86,6 +93,9 @@ namespace Crow.IML
                /// </summary>
                public Instantiator (Interface _iface, Stream stream, string srcPath = null)
                {
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        sourcePath = srcPath;
                        #if DEBUG_LOAD
@@ -112,12 +122,18 @@ namespace Crow.IML
                /// positionned on the start tag inside the itemTemplate
                /// </summary>
                public Instantiator (Interface _iface, XmlReader itr){
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        parseIML (itr);
                }
                //TODO:check if still used
                public Instantiator (Interface _iface, Type _root, InstanciatorInvoker _loader)
                {
+                       #if DESIGN_MODE
+                       currentInstantiatorID = NextInstantiatorID++;
+                       #endif
                        iface = _iface;
                        RootType = _root;
                        loader = _loader;
@@ -384,6 +400,9 @@ namespace Crow.IML
                                #if DESIGN_MODE
                                IXmlLineInfo li = (IXmlLineInfo)reader;
                                ctx.il.Emit (OpCodes.Ldloc_0);
+                               ctx.il.Emit (OpCodes.Ldstr, this.NextDesignID);
+                               ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_id"));
+                               ctx.il.Emit (OpCodes.Ldloc_0);
                                ctx.il.Emit (OpCodes.Ldc_I4, ctx.curLine + li.LineNumber);
                                ctx.il.Emit (OpCodes.Stfld, typeof(GraphicObject).GetField("design_line"));
                                ctx.il.Emit (OpCodes.Ldloc_0);