MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:rburnett Date:April 25 2006 5:01pm
Subject:Connector/NET commit: r232 - in trunk/VSTools: . Nodes
View as plain text  
Modified:
   trunk/VSTools/MyExplorerWindow.cs
   trunk/VSTools/Nodes/ExplorerNode.cs
   trunk/VSTools/Nodes/MyHierarchyNode.cs
   trunk/VSTools/Nodes/ServerNode.cs
Log:
selecting of nodes in the server explorer now shows that object in the properties window.
The next step is to trim the browsable properties on the node objects.


Modified: trunk/VSTools/MyExplorerWindow.cs
===================================================================
--- trunk/VSTools/MyExplorerWindow.cs	2006-04-25 01:26:54 UTC (rev 231)
+++ trunk/VSTools/MyExplorerWindow.cs	2006-04-25 17:01:33 UTC (rev 232)
@@ -29,6 +29,7 @@
         // using the Window property. Note that, even if this class implements IDispose, we are
         // not calling Dispose on this object. This is because ToolWindowPane calls Dispose on 
         // the object returned by the Window property.
+//        private IVsTrackSelectionEx trackSel;
         private ITrackSelection trackSel;
         private SelectionContainer selectContainer;
         private List<ServerNode> serverList;
@@ -78,6 +79,8 @@
         internal void AddServer(string name, string connectString)
         {
             ServerNode node = new ServerNode(name, connectString);
+            node.ChildNodeSelected += 
+                new ChildNodeSelectedEventHandler(node_ChildNodeSelected);
             node.Populate();
 
             hierarchyWindow.AddUIHierarchy(node, 
@@ -85,6 +88,11 @@
             serverList.Add(node);
         }
 
+        void node_ChildNodeSelected(object sender, ExplorerNode node)
+        {
+            UpdateSelection(node);
+        }
+
         private void LoadServers()
         {
             string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
@@ -107,17 +115,40 @@
             }
         }
 
-
         private ITrackSelection TrackSelection
         {
             get
             {
-                if (trackSel == null)
-                    trackSel = GetService(typeof(STrackSelection)) as ITrackSelection;
+                if (trackSel != null)
+                    return trackSel;
+                object spObj;
+                IVsWindowFrame wf = (this.Frame as IVsWindowFrame);
+                wf.GetProperty((int)__VSFPROPID.VSFPROPID_SPFrame, out spObj);
+                Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp =
+                    (Microsoft.VisualStudio.OLE.Interop.IServiceProvider)spObj;
+                trackSel = (ITrackSelection)GetMyService(
+                    sp, typeof(STrackSelection), typeof(ITrackSelection));
                 return trackSel;
             }
         }
 
+/*        private IVsTrackSelectionEx TrackSelection
+        {
+            get
+            {
+                if (trackSel != null)
+                    return trackSel;
+                object frameServiceProvider;
+                (this.Frame as IVsWindowFrame).GetProperty(
+                    (int)__VSFPROPID.VSFPROPID_SPFrame,
+                    out frameServiceProvider);
+                IServiceProvider frameSp = (frameServiceProvider as IServiceProvider);
+                trackSel = frameSp.GetService(typeof(SVsTrackSelectionEx))
+                    as IVsTrackSelectionEx;
+                return trackSel;
+            }
+        }
+        */
         public void UpdateSelection(Object o)
         {
             if (selectContainer == null)
@@ -161,6 +192,28 @@
             selectContainer = new SelectionContainer(true, true);
         }
 
+        private object GetMyService(Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp,
+            Type service, Type iface)
+        {
+            IntPtr pUnk = IntPtr.Zero;
+            Guid serviceGuid = service.GUID;
+            Guid ifaceGuid = iface.GUID;
+            int hr = sp.QueryService
+                (ref serviceGuid, ref ifaceGuid, out pUnk);
+            if (hr >= 0 && IntPtr.Zero != pUnk) 
+            {
+                try 
+                {
+                    return Marshal.GetObjectForIUnknown(pUnk);
+                }
+                finally 
+                {
+                    Marshal.Release(pUnk);
+                }
+            }
+            return null;
+        }
+
         private void AddCommand(OleMenuCommandService mcs, int cmd)
         {
             // Create the command for the menu item.

Modified: trunk/VSTools/Nodes/ExplorerNode.cs
===================================================================
--- trunk/VSTools/Nodes/ExplorerNode.cs	2006-04-25 01:26:54 UTC (rev 231)
+++ trunk/VSTools/Nodes/ExplorerNode.cs	2006-04-25 17:01:33 UTC (rev 232)
@@ -37,6 +37,8 @@
             newNodes = new ArrayList();
         }
 
+        #region Properties
+
         public virtual string Caption
         {
             get { return caption; }
@@ -80,11 +82,23 @@
         public abstract uint IconIndex { get; }
         public abstract bool Expandable { get; }
 
+        #endregion
+
         protected virtual string GetDeleteSql()
         {
             return String.Empty;
         }
 
+        public virtual void DoubleClick()
+        {
+            DoCommand(PkgCmdIDList.cmdidOpen);
+        }
+
+        public virtual void Select()
+        {
+            (GetHierNode() as ServerNode).SelectChild(this);
+        }
+
         internal virtual BaseEditor GetEditor()
         {
             return null;

Modified: trunk/VSTools/Nodes/MyHierarchyNode.cs
===================================================================
--- trunk/VSTools/Nodes/MyHierarchyNode.cs	2006-04-25 01:26:54 UTC (rev 231)
+++ trunk/VSTools/Nodes/MyHierarchyNode.cs	2006-04-25 17:01:33 UTC (rev 232)
@@ -14,12 +14,14 @@
 {
     internal abstract class HierNode : ExplorerNode, 
         IVsUIHierarchy, 
-        IVsPersistHierarchyItem2
+        IVsPersistHierarchyItem2,
+        IVsHierarchyDeleteHandler
     {
         private static ImageList imageList;
         private EventSinkCollection nodes;
         private ExplorerNode activeNode;
         private EventSinkCollection sinks;
+        Microsoft.VisualStudio.OLE.Interop.IServiceProvider serviceProvider;
 
         public HierNode(HierNode parent, string name) : base(parent, name)
         {
@@ -65,6 +67,10 @@
             imageList.Images.SetKeyName(13, "db.View.many_16x16.png");*/
         }
 
+        public Microsoft.VisualStudio.OLE.Interop.IServiceProvider SP
+        {
+            get { return serviceProvider; }
+        }
 
         public uint IndexNode(ExplorerNode node)
         {
@@ -155,15 +161,22 @@
         public int ExecCommand(uint itemid, ref Guid pguidCmdGroup, uint nCmdID, 
             uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
         {
-            DebugTrace.Trace("IVsUIHierarchy::ExecCommand");
-            //MessageBox.Show("guid = " + pguidCmdGroup.ToString() + ";cmdid=" + nCmdID);
+            DebugTrace.Trace("IVsUIHierarchy::ExecCommand guid=" +
+                pguidCmdGroup.ToString() + ";cmdid=" + nCmdID);
             if (pguidCmdGroup == VsMenus.guidVsUIHierarchyWindowCmds)
             {
-                if (nCmdID == (uint)VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_RightClick)
+                activeNode = NodeFromId(itemid);
+                switch (nCmdID)
                 {
-                    activeNode = NodeFromId(itemid);
-                    if (activeNode.MenuId != 0)
-                        ShowContextMenu(activeNode.MenuId, pvaIn);
+                    case (uint)VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_RightClick:
+                        if (activeNode.MenuId != 0)
+                            ShowContextMenu(activeNode.MenuId, pvaIn);
+                        break;
+                    case (uint)VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_EnterKey:
+                        break;
+                    case (uint)VSConstants.VsUIHierarchyWindowCmdIds.UIHWCMDID_DoubleClick:
+                        activeNode.DoubleClick();
+                        break;
                 }
 //#define UIHWCMDID_DoubleClick 2 
 
@@ -260,6 +273,7 @@
       //              break;
                 case __VSHPROPID.VSHPROPID_ItemDocCookie:
                     result = ItemId;
+                    node.Select();
                     break;
                     //2072
                     //2084
@@ -321,7 +335,7 @@
 
         public int QueryStatusCommand(uint itemid, ref Guid pguidCmdGroup, uint cCmds, Microsoft.VisualStudio.OLE.Interop.OLECMD[] prgCmds, IntPtr pCmdText)
         {
-            DebugTrace.Trace("IVsUIHierarchy::QueryStatusCommand");
+            //DebugTrace.Trace("IVsUIHierarchy::QueryStatusCommand");
             return VSConstants.S_OK;
         }
 
@@ -358,7 +372,8 @@
         public int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp)
         {
             DebugTrace.Trace("IVsUIHierarchy::SetSite");
-            return VSConstants.E_NOTIMPL;
+            serviceProvider = psp;
+            return VSConstants.S_OK;
         }
 
         public int UnadviseHierarchyEvents(uint dwCookie)
@@ -439,5 +454,21 @@
 
         #endregion
 
+
+        #region IVsHierarchyDeleteHandler Members
+
+        public int DeleteItem(uint dwDelItemOp, uint itemid)
+        {
+            return VSConstants.S_OK;
+        }
+
+        public int QueryDeleteItem(uint dwDelItemOp, uint itemid, out int pfCanDelete)
+        {
+            pfCanDelete = 1;
+            return VSConstants.S_OK;
+        }
+
+        #endregion
+
     }
 }

Modified: trunk/VSTools/Nodes/ServerNode.cs
===================================================================
--- trunk/VSTools/Nodes/ServerNode.cs	2006-04-25 01:26:54 UTC (rev 231)
+++ trunk/VSTools/Nodes/ServerNode.cs	2006-04-25 17:01:33 UTC (rev 232)
@@ -10,9 +10,12 @@
 
 namespace MySql.VSTools
 {
+    public delegate void ChildNodeSelectedEventHandler(object sender, ExplorerNode selectedNode);
+
     internal class ServerNode : HierNode
     {
         private MySqlConnection conn;
+        public event ChildNodeSelectedEventHandler ChildNodeSelected;
 
         public ServerNode(string name, string connectString)
             : base(null, name)
@@ -21,6 +24,8 @@
             ItemId = VSConstants.VSITEMID_ROOT;
         }
 
+        #region Properties
+
         public MySqlConnection Connection
         {
             get { return conn; }
@@ -40,7 +45,9 @@
         {
             get { return PkgCmdIDList.ServerCtxtMenu; }
         }
-        
+
+        #endregion
+
         public override void DoCommand(int commandId)
         {
             switch (commandId)
@@ -51,6 +58,9 @@
                 case PkgCmdIDList.cmdidNewQuery :
                     OpenNewQuery();
                     break;
+                default:
+                    base.DoCommand(commandId);
+                    break;
             }
         }
 
@@ -104,6 +114,10 @@
             (this.TreeView.Parent as ExplorerControl).SaveServers();
         }
 */
-
+        public void SelectChild(ExplorerNode node)
+        {
+            if (ChildNodeSelected != null)
+                ChildNodeSelected(this, node);
+        }
     }
 }

Thread
Connector/NET commit: r232 - in trunk/VSTools: . Nodesrburnett25 Apr