예제 #1
0
        /// <summary>
        /// Checks the text of a dialog and dismisses it.
        ///
        /// dlgField is the field to check the text of.
        /// buttonId is the button to press to dismiss.
        /// </summary>
        private static void CheckAndDismissDialog(string[] text, int dlgField, IntPtr buttonId)
        {
            IVsUIShell uiShell = VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 100 && hwnd.ToInt32() == VsIdeTestHostContext.Dte.MainWindow.HWnd; i++)
            {
                System.Threading.Thread.Sleep(100);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            Assert.IsTrue(hwnd.ToInt32() != VsIdeTestHostContext.Dte.MainWindow.HWnd && hwnd != IntPtr.Zero);
            StringBuilder title = new StringBuilder(4096);

            Assert.AreNotEqual(NativeMethods.GetDlgItemText(hwnd, dlgField, title, title.Capacity), (uint)0);

            string t = title.ToString();

            foreach (string expected in text)
            {
                Assert.IsTrue(t.Contains(expected));
            }
            NativeMethods.EndDialog(hwnd, buttonId);
        }
예제 #2
0
        public void DismissAllDialogs() {
            int foundWindow = 2;

            while (foundWindow != 0) {
                IVsUIShell uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
                if (uiShell == null) {
                    return;
                }

                IntPtr hwnd;
                uiShell.GetDialogOwnerHwnd(out hwnd);

                for (int j = 0; j < 10 && hwnd == _mainWindowHandle; j++) {
                    System.Threading.Thread.Sleep(100);
                    uiShell.GetDialogOwnerHwnd(out hwnd);
                }

                //We didn't see any dialogs
                if (hwnd == IntPtr.Zero || hwnd == _mainWindowHandle) {
                    foundWindow--;
                    continue;
                }

                //MessageBoxButton.Abort
                //MessageBoxButton.Cancel
                //MessageBoxButton.No
                //MessageBoxButton.Ok
                //MessageBoxButton.Yes
                //The second parameter is going to be the value returned... We always send Ok
                Debug.WriteLine("Dismissing dialog");
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
                NativeMethods.EndDialog(hwnd, new IntPtr(1));
            }
        }
예제 #3
0
        /// <summary>
        /// Checks the text of a dialog and dismisses it.
        ///
        /// dlgField is the field to check the text of.
        /// buttonId is the button to press to dismiss.
        /// </summary>
        private static void CheckAndDismissDialog(string[] text, int dlgField, IntPtr buttonId)
        {
            var        handle  = new IntPtr(VSTestContext.DTE.MainWindow.HWnd);
            IVsUIShell uiShell = VSTestContext.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 20 && hwnd == handle; i++)
            {
                System.Threading.Thread.Sleep(500);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "hwnd is null, We failed to get the dialog");
            Assert.AreNotEqual(handle, hwnd, "hwnd is Dte.MainWindow, We failed to get the dialog");
            Console.WriteLine("Ending dialog: ");
            AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
            Console.WriteLine("--------");
            try {
                StringBuilder title = new StringBuilder(4096);
                Assert.AreNotEqual(NativeMethods.GetDlgItemText(hwnd, dlgField, title, title.Capacity), (uint)0);

                string t = title.ToString();
                AssertUtil.Contains(t, text);
            } finally {
                NativeMethods.EndDialog(hwnd, buttonId);
            }
        }
예제 #4
0
        private IntPtr WaitForDialogToReplace(IntPtr originalHwnd, Task task)
        {
            IVsUIShell uiShell = GetService <IVsUIShell>(typeof(IVsUIShell));
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            int timeout = task == null ? 10000 : 60000;

            while (timeout > 0 && hwnd == originalHwnd && (task == null || !(task.IsFaulted || task.IsCanceled)))
            {
                timeout -= 500;
                System.Threading.Thread.Sleep(500);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (task != null && (task.IsFaulted || task.IsCanceled))
            {
                return(IntPtr.Zero);
            }

            if (hwnd == originalHwnd)
            {
                DumpElement(AutomationElement.FromHandle(hwnd));
            }
            Assert.AreNotEqual(IntPtr.Zero, hwnd);
            Assert.AreNotEqual(originalHwnd, hwnd, "Main window still has focus");
            return(hwnd);
        }
예제 #5
0
        /// <summary>
        /// Checks the text of a dialog and dismisses it.
        ///
        /// dlgField is the field to check the text of.
        /// buttonId is the button to press to dismiss.
        /// </summary>
        private void CheckAndDismissDialog(string[] text, int dlgField, string buttonId, bool assertIfNoDialog)
        {
            var        handle  = new IntPtr(Dte.MainWindow.HWnd);
            IVsUIShell uiShell = ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 20 && hwnd == handle; i++)
            {
                System.Threading.Thread.Sleep(500);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (!assertIfNoDialog && (hwnd == IntPtr.Zero || hwnd == handle))
            {
                return;
            }

            Assert.AreNotEqual(IntPtr.Zero, hwnd, "hwnd is null, We failed to get the dialog");
            Assert.AreNotEqual(handle, hwnd, "hwnd is Dte.MainWindow, We failed to get the dialog");
            Console.WriteLine("Ending dialog: ");
            var dlg = new AutomationDialog(this, AutomationElement.FromHandle(hwnd));

            AutomationWrapper.DumpElement(dlg.Element);
            Console.WriteLine("--------");

            bool closed = false;

            try {
                string title = dlg.Text;
                if (assertIfNoDialog)
                {
                    AssertUtil.Contains(title, text);
                }
                else if (!text.All(title.Contains))
                {
                    // We do not want to close the dialog now, as it may be expected
                    // by a later part of the test.
                    closed = true;
                }
            } finally {
                if (!closed)
                {
                    if (buttonId == MessageBoxButton.Close.ToString())
                    {
                        dlg.WaitForClosed(TimeSpan.FromSeconds(10.0), dlg.CloseWindow);
                    }
                    else if (!dlg.ClickButtonAndClose(buttonId))
                    {
                        dlg.CloseWindow();
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            var solution = GetService <IVsSolution, SVsSolution>();

            // As the "Edit Links" command is added on the Project menu even when no solution is opened, it must
            // be validated that a solution exists (in case it doesn't, GetSolutionInfo() returns 3 nulled strings).
            string s1, s2, s3;

            ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out s1, out s2, out s3));
            if (s1 != null && s2 != null && s3 != null)
            {
                IVsUIShell uiShell    = GetService <IVsUIShell, SVsUIShell>();
                IntPtr     parentHwnd = IntPtr.Zero;

                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out parentHwnd));

                var window = new ResxPackageWindow(CreateDialog())
                {
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };

                uiShell.EnableModeless(0);
                try
                {
                    WindowHelper.ShowModal(window, parentHwnd);
                }
                finally
                {
                    //this will take place after the window is closed
                    uiShell.EnableModeless(1);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Show a Message Box to prove we were here
            EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));

            IVsUIShell uiShell    = (IVsUIShell)GetService(typeof(SVsUIShell));
            Guid       clsid      = Guid.Empty;
            IntPtr     parentHwnd = IntPtr.Zero;

            uiShell.GetDialogOwnerHwnd(out parentHwnd);

            NativeWindow parentShim = new NativeWindow();

            parentShim.AssignHandle(parentHwnd);
            AttachDialog dialog = new AttachDialog();
            DialogResult result = dialog.ShowDialog(parentShim);

            if (result == DialogResult.OK)
            {
                foreach (int selected_id in dialog.SelectedItems)
                {
                    foreach (EnvDTE90a.Process4 p in dte.Debugger.LocalProcesses)
                    {
                        System.Diagnostics.Debug.WriteLine("Found process {0}", p.ProcessID);
                        if (p.ProcessID != selected_id)
                        {
                            continue;
                        }
                        p.Attach();
                        System.Diagnostics.Debug.WriteLine("Attaching to process successful.");
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            UE4Helper.Initialize(this.package);

            if (!UE4Helper.Instance.CheckHelperRequisites())
            {
                return;
            }

            IVsUIShell    uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            AddFileDialog dialog  = new AddFileDialog(uiShell);
            //get the owner of this dialog
            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            dialog.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                WindowHelper.ShowModal(dialog, hwnd);
            }
            finally
            {
                // This will take place after the window is closed.
                uiShell.EnableModeless(1);
            }
        }
예제 #9
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            // Show a Message Box to prove we were here
            IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
            //Guid clsid = Guid.Empty;
            //int result;
            //Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure( uiShell.ShowMessageBox(
            //                                                                           0,
            //                                                                           ref clsid,
            //                                                                           "UT",
            //                                                                           string.Format( CultureInfo.CurrentCulture,
            //                                                                                          "Inside {0}.MenuItemCallback()",
            //                                                                                          this.ToString() ),
            //                                                                           string.Empty,
            //                                                                           0,
            //                                                                           OLEMSGBUTTON.OLEMSGBUTTON_OK,
            //                                                                           OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
            //                                                                           OLEMSGICON.OLEMSGICON_INFO,
            //                                                                           0,
            //                                                                           // false

            //                                                                           out result ) );

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            // Get an instance of the currently running Visual Studio IDE
            //DTE dte = (DTE) GetService( typeof( DTE ) );
            //if( !dte.Solution.IsOpen )
            //{
            //    return;
            //}

            //var assemblies = new List<string>();
            //foreach( Project project in dte.Solution.Projects )
            //{
            //    var name = project.Name;

            //    if( name.EndsWith( "Test.Unit" ) )
            //    {
            //        assemblies.Add( GetAssemblyPath( project ) );
            //    }
            //}

            const string solution     = "TouchUI";
            var          assemblyList = new List <string>
            {
                @"D:\TFS\IRIDIUM1\bin\Debug\CT.Exam.TouchUI.FE.Test.Unit.dll",
            };
            //var root = AssemblyWalker.BuildTree( dte.Solution.FileName, assemblies );
            var root = AssemblyWalker.BuildTree(solution, assemblyList);

            MainWindow mainWindow = new MainWindow();

            var projects = new UtTreeViewModel(root);

            mainWindow.DataContext = projects;
            WindowHelper.ShowModal(mainWindow, hwnd);
        }
예제 #10
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var txtxMgr = (IVsTextManager)GetService(typeof(SVsTextManager));

                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                IntPtr     mainWnd;
                uiShell.GetDialogOwnerHwnd(out mainWnd);

                var dialog = new Window1();
                WindowInteropHelper helper = new WindowInteropHelper(dialog);
                helper.Owner = mainWnd;

                dialog.ShowDialog();

                if (dialog.SelectedOperation == Window1.Operation.AutoFull)
                {
                    var plugin = new AutoPropertyConverter(txtxMgr);
                    plugin.Execute();
                }
                else if (dialog.SelectedOperation == Window1.Operation.Encapsulate)
                {
                    var plugin = new FieldConverter(txtxMgr);
                    plugin.Execute();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #11
0
        /// <summary>
        /// Waits for no dialog. If a dialog appears before the timeout expires
        /// then the test fails and the dialog is closed.
        /// </summary>
        public void WaitForNoDialog(TimeSpan timeout) {
            IVsUIShell uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
            IntPtr hwnd;
            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 100 && hwnd == _mainWindowHandle; i++) {
                System.Threading.Thread.Sleep((int)timeout.TotalMilliseconds / 100);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (hwnd != (IntPtr)_mainWindowHandle) {
                AutomationWrapper.DumpElement(AutomationElement.FromHandle(hwnd));
                NativeMethods.EndDialog(hwnd, (IntPtr)(int)MessageBoxButton.Cancel);
                Assert.Fail("Dialog appeared - see output for details");
            }
        }
예제 #12
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            IVsUIShell uiShell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell));
            var        w       = new TestWindow(uiShell, mAllItems);

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            w.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            uiShell.EnableModeless(0);
            try
            {
                Microsoft.Internal.VisualStudio.PlatformUI.WindowHelper.ShowModal(w, hwnd);
            }
            catch (System.Exception exc)
            {
                System.Windows.MessageBox.Show("Opening failed: " + exc.Message, "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                w.mWindowToOpen = null;
            }
            finally
            {
                uiShell.EnableModeless(1);
            }
            if (w.mWindowToOpen != null)
            {
                w.mWindowToOpen.Activate();
            }
        }
예제 #13
0
        /// <summary>
        /// Gets the Visual Studio main window.
        /// </summary>
        public static Window GetMainWindow(this IVsUIShell shell)
        {
            IntPtr hwnd;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(shell.GetDialogOwnerHwnd(out hwnd));
            return(HwndSource.FromHwnd(hwnd).RootVisual as Window);
        }
        public IViewAdaper <SaveMethodView, SaveMethodViewResult> GetSaveToArasView(IVsUIShell uiShell, IProjectConfigurationManager projectConfigurationManager, IProjectConfiguraiton projectConfiguration, PackageManager packageManager, MethodInfo methodInformation, string methodCode, string projectConfigPath, string projectName, string projectFullName)
        {
            var view      = new SaveMethodView();
            var viewModel = new SaveMethodViewModel(
                authManager,
                this,
                projectConfigurationManager,
                projectConfiguration,
                packageManager,
                arasDataProvider,
                methodInformation,
                methodCode,
                projectConfigPath,
                projectName,
                projectFullName);

            view.DataContext = viewModel;

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            var windowInteropHelper = new WindowInteropHelper(view);

            windowInteropHelper.Owner = hwnd;

            return(new SaveMethodViewAdapter(view));
        }
예제 #15
0
        private void ShowToolWindow(object sender, EventArgs e)
        {
            try
            {
                // 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.FindToolWindow(typeof(MyToolWindow), 0, true);

                //if ((null == window) || (null == window.Frame))
                //{
                //    throw new NotSupportedException("Can not create tool window.");
                //}
                //IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
                //Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());

                var txtxMgr = (IVsTextManager)GetService(typeof(SVsTextManager));

                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
                IntPtr     mainWnd;
                uiShell.GetDialogOwnerHwnd(out mainWnd);

                var dialog = new ConfigWindow();
                WindowInteropHelper helper = new WindowInteropHelper(dialog);
                helper.Owner = mainWnd;

                dialog.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #16
0
        public static bool? ShowDialog( this Window window, IVsUIShell shell )
        {
            Arg.NotNull( window, nameof( window ) );

            IntPtr owner;

            // if the shell doesn't retrieve the dialog owner or doesn't enter modal mode, just let the dialog do it's normal thing
            if ( shell == null || shell.GetDialogOwnerHwnd( out owner ) != 0 || shell.EnableModeless( 0 ) != 0 )
                return window.ShowDialog();

            var helper = new WindowInteropHelper( window );

            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            helper.Owner = owner;

            try
            {
                return window.ShowDialog();
            }
            finally
            {
                shell.EnableModeless( 1 );
                helper.Owner = IntPtr.Zero;
            }
        }
예제 #17
0
        /// <summary>
        /// Waits for the VS main window to receive the focus.
        /// </summary>
        /// <returns>
        /// True if the main window has the focus. Otherwise, false.
        /// </returns>
        public bool WaitForDialogDismissed(bool assertIfFailed = true, int timeout = 100000) {
            IVsUIShell uiShell = GetService<IVsUIShell>(typeof(IVsUIShell));
            IntPtr hwnd;
            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < (timeout / 100) && hwnd != _mainWindowHandle; i++) {
                System.Threading.Thread.Sleep(100);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            if (assertIfFailed) {
                Assert.AreEqual(_mainWindowHandle, hwnd);
                return true;
            }
            return _mainWindowHandle == hwnd;
        }
예제 #18
0
        /// <summary>
        /// Waits for a modal dialog to take over VS's main window and returns the HWND for the dialog.
        /// </summary>
        /// <returns></returns>
        public IntPtr WaitForDialogDismissed()
        {
            IVsUIShell uiShell = VsIdeTestHostContext.ServiceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
            IntPtr     hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);

            for (int i = 0; i < 100 && hwnd.ToInt32() != Dte.MainWindow.HWnd; i++)
            {
                System.Threading.Thread.Sleep(100);
                uiShell.GetDialogOwnerHwnd(out hwnd);
            }

            Assert.AreEqual(hwnd.ToInt32(), Dte.MainWindow.HWnd);
            return(hwnd);
        }
예제 #19
0
        public static String BrowseForDirectory(IntPtr owner, string initialDirectory = null, string title = null)
        {
            IVsUIShell uiShell = (IVsUIShell)Package.GetGlobalService(typeof(SVsUIShell));

            if (null == uiShell)
            {
                using (var ofd = new FolderBrowserDialog()) {
                    ofd.RootFolder          = Environment.SpecialFolder.Desktop;
                    ofd.SelectedPath        = initialDirectory;
                    ofd.ShowNewFolderButton = false;
                    DialogResult result;
                    if (owner == IntPtr.Zero)
                    {
                        result = ofd.ShowDialog();
                    }
                    else
                    {
                        result = ofd.ShowDialog(NativeWindow.FromHandle(owner));
                    }
                    if (result == DialogResult.OK)
                    {
                        return(ofd.SelectedPath);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            if (owner == IntPtr.Zero)
            {
                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out owner));
            }
            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            browseInfo[0].lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            browseInfo[0].pwzInitialDir = initialDirectory;
            browseInfo[0].pwzDlgTitle   = title;
            browseInfo[0].hwndOwner     = owner;
            browseInfo[0].nMaxDirName   = 260;
            IntPtr pDirName = IntPtr.Zero;

            try {
                browseInfo[0].pwzDirName = pDirName = Marshal.AllocCoTaskMem(520);
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return(null);
                }
                ErrorHandler.ThrowOnFailure(hr);
                return(Marshal.PtrToStringAuto(browseInfo[0].pwzDirName));
            }
            finally {
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
        }
예제 #20
0
        public void SetModalDialogOwner(System.Windows.Window targetWindow)
        {
            IntPtr hWnd;

            _shell.GetDialogOwnerHwnd(out hWnd);
            // ReSharper disable once PossibleNullReferenceException
            var parent = HwndSource.FromHwnd(hWnd).RootVisual;

            targetWindow.Owner = (System.Windows.Window)parent;
        }
예제 #21
0
        internal static void SetOwner(this IVsUIShell uiShell, Window dialog)
        {
            IntPtr owner;

            if (ErrorHandler.Succeeded(uiShell.GetDialogOwnerHwnd(out owner)))
            {
                new WindowInteropHelper(dialog).Owner = owner;
                dialog.WindowStartupLocation          = WindowStartupLocation.CenterScreen;
                dialog.ShowInTaskbar = false;
            }
        }
예제 #22
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 Execute(object sender, EventArgs e)
        {
            this.package.JoinableTaskFactory.RunAsync(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                //ToolWindowPane window = await this.package.ShowToolWindowAsync(typeof(SentryProjectSettingsWindow), 0, true, this.package.DisposalToken);
                IVsUIShell uiShell = (IVsUIShell)await ServiceProvider.GetServiceAsync(typeof(SVsUIShell));
                var window         = new SentryProjectSettingsWindow(package);
                IntPtr hwnd;
                uiShell.GetDialogOwnerHwnd(out hwnd);
                window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                window.Width  = 500;
                window.Height = 600;
                uiShell.EnableModeless(0);
                if ((null == window))
                {
                    throw new NotSupportedException("Cannot create tool window");
                }
                var projectWindow = (SentryProjectSettingsWindow)window;

                try
                {
                    WindowHelper.ShowModal(window, hwnd);
                }
                finally
                {
                    // This will take place after the window is closed.
                    uiShell.EnableModeless(1);
                }

                //var solution = await this.ServiceProvider.GetServiceAsync(typeof(IVsSolution)) as IVsSolution;

                //var hierarchies = GetProjectsInSolution(solution);

                //var guids = hierarchies.Select(x => new {
                //    hierarchy = x,
                //    guid = x.GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out var y) == VSConstants.S_OK ? y : Guid.Empty
                //}).ToList();


                //if(guids.Any(w => w.guid != Guid.Empty))
                //{
                //    var projectId = guids.First(x => x.guid != Guid.Empty).guid;

                //    if(projectId != null)
                //    {
                //        projectWindow.ProjectId = projectId;
                //    }
                //}


                //projectWindow.ProjectId = e.ToString();
            });
        }
예제 #23
0
        internal void SelectDirectory()
        {
            IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell));
            IntPtr     dialogOwner;

            uiShell.GetDialogOwnerHwnd(out dialogOwner);

            string currentDirectory = RToolsSettings.Current.WorkingDirectory;
            string newDirectory     = Dialogs.BrowseForDirectory(dialogOwner, currentDirectory, Resources.ChooseDirectory);

            SetDirectory(newDirectory);
        }
예제 #24
0
        public static Task <IntPtr> GetNewDialogOwnerHwnd()
        {
            IVsUIShell shell = (IVsUIShell)VsIdeTestHostContext.ServiceProvider.GetService(typeof(SVsUIShell));
            IntPtr     oldHwnd;

            Assert.AreEqual(VSConstants.S_OK, shell.GetDialogOwnerHwnd(out oldHwnd));
            return(Task.Factory.StartNew(() =>
            {
                IntPtr newHwnd;
                while (true)
                {
                    Assert.AreEqual(VSConstants.S_OK, shell.GetDialogOwnerHwnd(out newHwnd));
                    if (newHwnd != oldHwnd)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(100);
                }
                return newHwnd;
            }));
        }
        public IMessageBoxWindow GetMessageBoxWindow(IVsUIShell uiShell)
        {
            var view = new MessageBoxWindow();

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            var windowInteropHelper = new WindowInteropHelper(view);

            windowInteropHelper.Owner = hwnd;

            return(view);
        }
        protected override void Handle()
        {
            IVsUIShell uiShell = VsAppShell.Current.GetGlobalService<IVsUIShell>(typeof(SVsUIShell));
            IntPtr dialogOwner;
            uiShell.GetDialogOwnerHwnd(out dialogOwner);

            var currentDirectory = RToolsSettings.Current.WorkingDirectory;
            var newDirectory = Dialogs.BrowseForDirectory(dialogOwner, currentDirectory, Resources.ChooseDirectory);
            if (!string.IsNullOrEmpty(newDirectory)) {
                _workflow.RSession.SetWorkingDirectoryAsync(newDirectory)
                    .SilenceException<RException>()
                    .SilenceException<MessageTransportException>()
                    .DoNotWait();
            }
        }
예제 #27
0
        public string BrowseForFileSave(IntPtr owner, string filter, string initialPath = null, string title = null)
        {
            if (string.IsNullOrEmpty(initialPath))
            {
                initialPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar;
            }

            IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell));

            if (null == uiShell)
            {
                return(null);
            }

            if (owner == IntPtr.Zero)
            {
                ErrorHandler.ThrowOnFailure(uiShell.GetDialogOwnerHwnd(out owner));
            }

            VSSAVEFILENAMEW[] saveInfo = new VSSAVEFILENAMEW[1];
            saveInfo[0].lStructSize  = (uint)Marshal.SizeOf(typeof(VSSAVEFILENAMEW));
            saveInfo[0].dwFlags      = 0x00000002; // OFN_OVERWRITEPROMPT
            saveInfo[0].pwzFilter    = filter.Replace('|', '\0') + "\0";
            saveInfo[0].hwndOwner    = owner;
            saveInfo[0].pwzDlgTitle  = title;
            saveInfo[0].nMaxFileName = 260;
            var pFileName = Marshal.AllocCoTaskMem(520);

            saveInfo[0].pwzFileName   = pFileName;
            saveInfo[0].pwzInitialDir = Path.GetDirectoryName(initialPath);
            var nameArray = (Path.GetFileName(initialPath) + "\0").ToCharArray();

            Marshal.Copy(nameArray, 0, pFileName, nameArray.Length);
            try {
                int hr = uiShell.GetSaveFileNameViaDlg(saveInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    return(null);
                }
                ErrorHandler.ThrowOnFailure(hr);
                return(Marshal.PtrToStringAuto(saveInfo[0].pwzFileName));
            } finally {
                if (pFileName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pFileName);
                }
            }
        }
예제 #28
0
        /// <summary>
        /// Executes Add Search Path menu command.
        /// </summary>
        internal int AddSearchPath()
        {
            // Get a reference to the UIShell.
            IVsUIShell uiShell = GetService(typeof(SVsUIShell)) as IVsUIShell;

            if (null == uiShell)
            {
                return(VSConstants.S_FALSE);
            }
            //Create a fill in a structure that defines Browse for folder dialog
            VSBROWSEINFOW[] browseInfo = new VSBROWSEINFOW[1];
            //Dialog title
            browseInfo[0].pwzDlgTitle = DynamicProjectSR.GetString(DynamicProjectSR.SelectFolderForSearchPath);
            //Initial directory - project directory
            browseInfo[0].pwzInitialDir = _projectDir;
            //Parent window
            uiShell.GetDialogOwnerHwnd(out browseInfo[0].hwndOwner);
            //Max path length
            browseInfo[0].nMaxDirName = NativeMethods.MAX_PATH;
            //This struct size
            browseInfo[0].lStructSize = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW));
            //Memory to write selected directory to.
            //Note: this one allocates unmanaged memory, which must be freed later
            IntPtr pDirName = Marshal.AllocCoTaskMem(NativeMethods.MAX_PATH);

            browseInfo[0].pwzDirName = pDirName;
            try {
                //Show the dialog
                int hr = uiShell.GetDirectoryViaBrowseDlg(browseInfo);
                if (hr == VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    //User cancelled the dialog
                    return(VSConstants.S_OK);
                }
                //Check for any failures
                ErrorHandler.ThrowOnFailure(hr);
                //Get selected directory
                string dirName = Marshal.PtrToStringAuto(browseInfo[0].pwzDirName);
                AddSearchPathEntry(dirName);
            } finally {
                //Free allocated unmanaged memory
                if (pDirName != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pDirName);
                }
            }
            return(VSConstants.S_OK);
        }
        public IViewAdaper <CreatePartialElementView, CreatePartialElementViewResult> GetCreatePartialClassView(IVsUIShell uiShell, bool usedVSFormatting)
        {
            var viewModel = new CreatePartialElementViewModel(usedVSFormatting);
            var view      = new CreatePartialElementView();

            view.DataContext = viewModel;

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            var windowInteropHelper = new WindowInteropHelper(view);

            windowInteropHelper.Owner = hwnd;

            return(new CreatePartialElementViewAdapter(view));
        }
        public IViewAdaper <CreateMethodView, CreateMethodViewResult> GetCreateView(IVsUIShell uiShell, IProjectConfiguraiton projectConfiguration, TemplateLoader templateLoader, PackageManager packageManager, IProjectManager projectManager, string projectLanguage)
        {
            CreateMethodView      view      = new CreateMethodView();
            CreateMethodViewModel viewModel = new CreateMethodViewModel(authManager, this, projectConfiguration, templateLoader, packageManager, projectManager, arasDataProvider, projectLanguage);

            view.DataContext = viewModel;

            IntPtr hwnd;

            uiShell.GetDialogOwnerHwnd(out hwnd);
            var windowInteropHelper = new WindowInteropHelper(view);

            windowInteropHelper.Owner = hwnd;

            return(new CreateMethodViewAdapter(view));
        }
예제 #31
0
        public static IEnumerable <Parser.Result> SelectTypesManually(IEnumerable <Parser.Result> items)
        {
            var dialog = new TypeToMoveSelection(items);

            IVsUIShell uiShell = (IVsUIShell)Global.GetService(typeof(SVsUIShell));
            IntPtr     mainWnd;

            uiShell.GetDialogOwnerHwnd(out mainWnd);

            WindowInteropHelper helper = new WindowInteropHelper(dialog);

            helper.Owner = mainWnd;
            dialog.ShowDialog();

            return(dialog.SelectedItem);
        }