/// <summary>
        /// Handle change to the current selection is done throught the properties window
        /// drop down list.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Arguments</param>
        private void selectionContainer_SelectedObjectsChanged(object sender, EventArgs e)
        {
            // Set the flag letting us know we are changing the selection ourself
            ignoreSelectedObjectsChanges = true;
            try
            {
                // First clear the current selection
                this.listView1.SelectedItems.Clear();
                // See if we have something selected
                if (selectionContainer.SelectedObjects.Count > 0)
                {
                    // We only support single selection, so pick the first one
                    IEnumerator enumerator = selectionContainer.SelectedObjects.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        SelectionProperties newSelection = (SelectionProperties)enumerator.Current;
                        int index = newSelection.Index;

                        // Select the corresponding item
                        this.listView1.SelectedItem = this.listView1.Items[index];
                    }
                }
            }
            finally
            {
                // make sure we react to future events
                ignoreSelectedObjectsChanges = false;
            }
        }
        /// <summary>
        /// Push properties for the selected item to the properties window.
        /// Note that throwing from a Windows Forms event handler would cause
        /// Visual Studio to crash. So if you expect your code to throw
        /// you should make sure to catch the exceptions you expect
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Arguments</param>
        private void listView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // If the change originates from us setting the selection, ignore the event
            if (ignoreSelectedObjectsChanges)
            {
                return;
            }
            // Create the array that will hold the properties (one set of properties per item selected)
            ArrayList selectedObjects = new ArrayList();

            if (listView1.SelectedItems.Count > 0)
            {
                // Get the index of the selected item
                int index = listView1.Items.IndexOf(listView1.SelectedItems[0]);
                // Get the IVsWindowFrame for that item
                IVsWindowFrame frame = toolWindowsList[index];
                // Add the properties for the selected item
                SelectionProperties properties = toolWindowsList.GetFrameProperties(frame);
                // Keeping track of the index helps us know which tool window was selected
                // when the change is done through the property window drop-down.
                properties.Index = index;
                // This sample only supports single selection, but if multiple
                // selection is supported, multiple items could be added. The
                // properties that they had in common would then be shown.
                selectedObjects.Add(properties);
            }

            // Update our selection container
            selectionContainer.SelectedObjects = selectedObjects;
            // In order to enable the drop-down of the properties window to display
            // all our possible items, we need to provide the list
            selectionContainer.SelectableObjects = toolWindowsList.WindowsProperties;
            // Inform Visual Studio that we changed the selection and push the new list of properties
            TrackSelection.OnSelectChange(selectionContainer);
        }
        /// <summary>
        /// Provides the properties object corresponding to the window frame
        /// </summary>
        /// <param name="frame">Window frame to return properties for</param>
        /// <returns>Properties object</returns>
        internal SelectionProperties GetFrameProperties(IVsWindowFrame frame)
        {
            // Get the caption and Guid for the current tool window
            string caption         = (string)this.GetProperty(frame, (int)__VSFPROPID.VSFPROPID_Caption);
            Guid   persistenceGuid = this.GetGuidProperty(frame, (int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot);;
            // Create the property object based on this and add it to the list
            SelectionProperties property = new SelectionProperties(caption, persistenceGuid);

            return(property);
        }
Example #4
0
 /// <summary>
 /// Provides the properties object corresponding to the window frame
 /// </summary>
 /// <param name="frame">Window frame to return properties for</param>
 /// <returns>Properties object</returns>
 internal SelectionProperties GetFrameProperties(IVsWindowFrame frame)
 {
     // Get the caption and Guid for the current tool window
     string caption = (string)this.GetProperty(frame, (int)__VSFPROPID.VSFPROPID_Caption);
     Guid persistenceGuid = this.GetGuidProperty(frame, (int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot); ;
     // Create the property object based on this and add it to the list
     SelectionProperties property = new SelectionProperties(caption, persistenceGuid);
     return property;
 }