コード例 #1
0
        /// <summary>
        /// Shows the tool window when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void ShowToolWindow(object sender, EventArgs e)
        {
            // Get the instance number 0 of this tool window. This window is single instance so this instance
            // is actually the only one.
            // The last flag is set to true so that if the tool window does not exists it will be created.
            ToolWindowPane window = this.package.FindToolWindow(typeof(OpenShiftProjectWindow), 0, true);

            if ((null == window) || (null == window.Frame))
            {
                throw new NotSupportedException("Cannot create tool window");
            }
            vm = (window.Content as FrameworkElement).DataContext as OpenShiftExplorerViewModel;
            if (vm == null)
            {
                throw new NotSupportedException("Cannot allocate a proper ViewModel");
            }
            IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());

            // Create the handles for the toolbar command.
            var mcs             = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            var toolbarbtnCmdID = new CommandID(OpenShiftProjectWindowCommand.CommandSet,
                                                OpenShiftProjectWindowCommand.cmdidOpenShiftProjectReload);

            if (mcs.FindCommand(toolbarbtnCmdID) == null)
            {
                var menuItem = new MenuCommand(new EventHandler(ButtonHandler), toolbarbtnCmdID);
                mcs.AddCommand(menuItem);
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OpenShiftProjectWindow"/> class.
        /// </summary>
        public OpenShiftProjectWindow() : base(null)
        {
            this.Caption = "OpenShift Project Explorer";

            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            var vm = new OpenShiftExplorerViewModel();

            control = new OpenShiftProjectWindowControl()
            {
                DataContext = vm
            };
            this.Content = control;
            vm.LoadAsync().FireAndForget();

            this.ToolBar = new CommandID(OpenShiftProjectWindowCommand.CommandSet,
                                         OpenShiftProjectWindowCommand.ToolbarID);
            this.ToolBarLocation = (int)VSTWT_LOCATION.VSTWT_TOP;
        }