コード例 #1
0
        /// <summary>
        /// Returns a standard VS color or a system color, if the VS colors service is not available
        /// </summary>
        /// <param name="visualStudioColor">Color enum</param>
        /// <returns>The color itself</returns>
        internal static Color GetVsColor(Vs2010Color visualStudioColor)
        {
            uint        win32Color = 0;
            IVsUIShell2 vsuiShell2 = WixPackage.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell2;

            if (vsuiShell2 != null && vsuiShell2.GetVSSysColorEx((Int32)visualStudioColor, out win32Color) == VSConstants.S_OK)
            {
                Color color = ColorTranslator.FromWin32((int)win32Color);
                return(color);
            }

            // We need to fall back to some reasonable colors when we're not running in VS
            // to keep the forms/property pages editable in the designers
            switch (visualStudioColor)
            {
            case Vs2010Color.VSCOLOR_BUTTONFACE:
                return(SystemColors.ButtonFace);

            case Vs2010Color.VSCOLOR_BUTTONTEXT:
                return(SystemColors.ControlText);

            case Vs2010Color.VSCOLOR_WINDOW:
                return(SystemColors.Window);

            default:
                return(Color.Red);
            }
        }
コード例 #2
0
        public static string GetDirectoryViaBrowseDialog(this IVsUIShell2 shell, IntPtr parentWindow, Guid persistenceSlot, string title, string initialDirectory, bool overridePersistedInitialDirectory)
        {
            if (shell == null)
            {
                throw new ArgumentNullException("shell");
            }
            if (title == null)
            {
                throw new ArgumentNullException("title");
            }

            const int MaxDirName    = 10000;
            IntPtr    dirNameBuffer = Marshal.AllocCoTaskMem((MaxDirName + 1) * sizeof(char));

            try
            {
                VSBROWSEINFOW[] browse = new VSBROWSEINFOW[]
                {
                    new VSBROWSEINFOW
                    {
                        pwzDlgTitle   = title,
                        dwFlags       = (uint)BrowseInfoFlags.ReturnOnlyFileSystemDirectories,
                        hwndOwner     = parentWindow,
                        pwzInitialDir = GetInitialDirectoryToUse(initialDirectory, overridePersistedInitialDirectory, persistenceSlot),
                        nMaxDirName   = MaxDirName,
                        lStructSize   = (uint)Marshal.SizeOf(typeof(VSBROWSEINFOW)),
                        pwzDirName    = dirNameBuffer,
                        dwHelpTopic   = 0
                    }
                };

                string             helpTopic       = string.Empty;
                string             openButtonLabel = null;
                string             ceilingDir      = null;
                VSNSEBROWSEINFOW[] nseBrowseInfo   = null;

                ErrorHandler.ThrowOnFailure(shell.GetDirectoryViaBrowseDlgEx(browse, helpTopic, openButtonLabel, ceilingDir, nseBrowseInfo));
                string folder = Marshal.PtrToStringUni(browse[0].pwzDirName);
                if (!string.IsNullOrEmpty(folder))
                {
                    PersistLastUseDirectory(persistenceSlot, folder);
                }

                return(folder);
            }
            catch (COMException ex) when(ex.ErrorCode == VSConstants.OLE_E_PROMPTSAVECANCELLED)
            {
            }
            finally
            {
                if (dirNameBuffer != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dirNameBuffer);
                    dirNameBuffer = IntPtr.Zero;
                }
            }

            return(null);
        }
コード例 #3
0
        private Color getVSColor(IVsUIShell2 uiShell2, __VSSYSCOLOREX color)
        {
            //get the COLORREF structure
            uint win32Color;

            uiShell2.GetVSSysColorEx((int)color, out win32Color);
            //translate it to a managed Color structure
            return(ColorTranslator.FromWin32((int)win32Color));
        }
コード例 #4
0
ファイル: ShellHelper.cs プロジェクト: zy26/tytannet
        /// <summary>
        /// Gets the Visual Studio Shell main interface.
        /// </summary>
        public static IVsUIShell2 GetShellService(IServiceProvider provider)
        {
            if (serviceProvider == null)
            {
                return(null);
            }

            return(shell ?? (shell = provider.GetService(typeof(SVsUIShell)) as IVsUIShell2));
        }
コード例 #5
0
        public ContentPreviewToolWindowControl()
        {
            InitializeComponent();

            IVsUIShell2 shell = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell));
            uint        vsBackColor;

            shell.GetVSSysColorEx((int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_BACKGROUND,
                                  out vsBackColor);
            System.Drawing.Color backColor = System.Drawing.ColorTranslator.FromWin32((int)vsBackColor);
            graphicsDeviceControl.BackColor = backColor;
        }
コード例 #6
0
        /// <summary>
        /// Return a compatible <see cref="Brush"/> for the ToolWindowTextColorKey
        /// </summary>
        /// <param name="iVsUiShell2">The <see cref="IVsUIShell2"/> for surface handling inside Visual Studio</param>
        /// <returns>A compatible <see cref="Brush"/></returns>
        internal static Brush GetWindowTextColor(IVsUIShell2 iVsUiShell2 = null)
        {
            if (iVsUiShell2 == null)
            {
                return(Brushes.Black);
            }

            const int systemColor = (int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_TEXT;

            uint color;

            return(iVsUiShell2.GetVSSysColorEx(systemColor, out color) == VSConstants.S_OK
                ? GetThemedBrush(color)
                : Brushes.Black);
        }
コード例 #7
0
        /// <summary>
        /// Update the used Visual Studio object
        /// </summary>
        /// <param name="dte2">The Visual Studio object</param>
        /// <param name="iVsUiShell2">The <see cref="IVsUIShell2"/> for surface handling inside Visual Studio</param>
        internal void UpdateDte2(DTE2 dte2, IVsUIShell2 iVsUiShell2)
        {
            if (dte2 == null)
            {
                return;
            }

            if (Model.OutputPane == null)
            {
                Model.OutputPane = dte2.ToolWindows.OutputWindow.OutputWindowPanes.Add("Git submodules");
                Model.OutputPane.Activate();
            }

            Model.Foreground = ThemeHelper.GetWindowTextColor(iVsUiShell2);

            if ((dte2.Solution == null) || (Model.CurrentSolutionFullName == dte2.Solution.FullName))
            {
                return;
            }

            Model.GitCounter++;
            Model.ListOfSubmodules        = null;
            Model.CanExecuteCommand       = false;
            Model.CurrentSolutionFullName = dte2.Solution.FullName;
            Model.CurrentSolutionPath     = string.Empty;
            Model.ListOfBranches          = new Collection <string>();
            Model.CountOfBranches         = "Branch (of 0)";
            Model.CurrentBranch           = string.Empty;

            if (string.IsNullOrEmpty(Model.CurrentSolutionFullName))
            {
                Model.CurrentSolutionPath = "No solution opend";
                WriteToOutputWindow(Category.Debug, "No solution opend");
                return;
            }

            if (!CheckSolutionIsAGitRepository() || !Model.GitIsPresent)
            {
                return;
            }

            DoStartGit(SubmoduleCommand.OtherBranchList);
            DoStartGit(SubmoduleCommand.AllFetch);
        }
コード例 #8
0
        private Dictionary <string, Color> GetVisualStudioDetailedColorList()
        {
            IVsUIShell2 uiShell = (IVsUIShell2)ChangesetViewerPackage.GetGlobalService(typeof(IVsUIShell));

            Dictionary <string, Color> result = new Dictionary <string, Color>();

            foreach (__VSSYSCOLOREX vsSysColor in Enum.GetValues(typeof(__VSSYSCOLOREX)))
            {
                uint win32Color;
                uiShell.GetVSSysColorEx((int)vsSysColor, out win32Color);
                Color color = ColorTranslator.FromWin32((int)win32Color);

                if (!result.Any(c => c.Key == vsSysColor.ToString()))
                {
                    result.Add(vsSysColor.ToString(), color);
                }
            }

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Brings up the browse folder dialog.
        /// </summary>
        /// <param name="sender">The browse button.</param>
        /// <param name="e">The <see cref="EventArgs"/> object that contains the event data.</param>
        private void OnBrowseButtonClick(object sender, EventArgs e)
        {
            // initialize the dialog to the current directory (if it exists)
            bool   overridePersistedInitialDirectory = false;
            string initialDirectory = null;

            if (Directory.Exists(FullPath))
            {
                initialDirectory = FullPath;
                overridePersistedInitialDirectory = true;
            }

            IntPtr      parentWindow    = Handle;
            Guid        persistenceSlot = typeof(FileBrowserTextBox).GUID;
            IVsUIShell2 shell           = (IVsUIShell2)Package.GetGlobalService(typeof(SVsUIShell));
            // show the dialog
            string path = shell.GetDirectoryViaBrowseDialog(parentWindow, persistenceSlot, "Select folder", initialDirectory, overridePersistedInitialDirectory);

            if (path != null)
            {
                if (MakeRelative && !string.IsNullOrEmpty(RootFolder))
                {
                    string rootFolder = Path.GetFullPath(RootFolder);
                    if (Directory.Exists(rootFolder))
                    {
                        if (!rootFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) && !rootFolder.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
                        {
                            rootFolder = rootFolder + Path.DirectorySeparatorChar;
                        }

                        path = new Url(rootFolder).MakeRelative(new Url(path));
                    }
                }

                this.folderTextBox.Text = path;
            }
        }
コード例 #10
0
        public static void SetTheme(string chosen = null)
        {
            try
            {
                if (chosen == null)
                {
                    chosen = Repository.Instance.Settings.FetchSettings <string>(Constants.Settings.SelectedThemeKey);
                }
                var         oldTheme     = _themeDic;
                var         oldBaseTheme = _baseThemeDic;
                IVsUIShell2 uiShell      = _package.GetService(typeof(SVsUIShell)) as IVsUIShell2;
                uint        rgb;
                uiShell.GetVSSysColorEx((int)__VSSYSCOLOREX.VSCOLOR_TOOLWINDOW_BACKGROUND, out rgb);
                var col = System.Drawing.ColorTranslator.FromWin32((int)rgb);

                if (col.GetBrightness() < 0.5)
                {
                    IsDarkTheme = true;
                    _themeDic   = new System.Windows.ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml")
                    };
                    _baseThemeDic = new System.Windows.ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml")
                    };
                }
                else
                {
                    IsDarkTheme = false;
                    _themeDic   = new System.Windows.ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml")
                    };
                    _baseThemeDic = new System.Windows.ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml")
                    };
                }

                if (chosen != null && MahApps.Metro.ThemeManager.Accents.Any(accent => accent.Name == chosen))
                {
                    _themeDic = new System.Windows.ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Accents/" + chosen + ".xaml")
                    };
                }

                foreach (var control in _themedControls)
                {
                    if (control.Resources.MergedDictionaries.Contains(oldTheme))
                    {
                        control.Resources.MergedDictionaries.Remove(oldTheme);
                    }
                    if (control.Resources.MergedDictionaries.Contains(oldBaseTheme))
                    {
                        control.Resources.MergedDictionaries.Remove(oldBaseTheme);
                    }
                    if (!control.Resources.MergedDictionaries.Contains(_themeDic))
                    {
                        control.Resources.MergedDictionaries.Add(_themeDic);
                    }
                    if (!control.Resources.MergedDictionaries.Contains(_baseThemeDic))
                    {
                        control.Resources.MergedDictionaries.Add(_baseThemeDic);
                    }
                    control.UpdateDefaultStyle();
                }
            }
            catch (Exception ex)
            {
                SimpleLogger.Log(ex);
            }
        }
コード例 #11
0
ファイル: ORMFontsAndColors.cs プロジェクト: cjheath/NORMA
			private Color TranslateColorValue(uint colorValue)
			{
				if (0 != (colorValue & AllSpecialColorBits))
				{
					uint coreColorValue = colorValue & ~AllSpecialColorBits;
					switch (colorValue & AllSpecialColorBits)
					{
						case StandardPaletteBit:
							Color knownColor = Color.Empty;
							switch ((COLORINDEX)coreColorValue)
							{
								case COLORINDEX.CI_USERTEXT_FG:
									EnsureUserTextColors();
									knownColor = myUserForeColor;
									break;
								case COLORINDEX.CI_USERTEXT_BK:
									EnsureUserTextColors();
									knownColor = myUserBackColor;
									break;

								case COLORINDEX.CI_BLACK:
									knownColor = Color.Black;
									break;
								case COLORINDEX.CI_WHITE:
									knownColor = Color.White;
									break;
								case COLORINDEX.CI_MAROON:
									knownColor = Color.Maroon;
									break;
								case COLORINDEX.CI_DARKGREEN:
									knownColor = Color.DarkGreen;
									break;
								case COLORINDEX.CI_BROWN:
									knownColor = Color.Brown;
									break;
								case COLORINDEX.CI_DARKBLUE:
									knownColor = Color.DarkBlue;
									break;
								case COLORINDEX.CI_PURPLE:
									knownColor = Color.Purple;
									break;
								case COLORINDEX.CI_AQUAMARINE:
									knownColor = Color.Aquamarine;
									break;
								case COLORINDEX.CI_LIGHTGRAY:
									knownColor = Color.LightGray;
									break;
								case COLORINDEX.CI_DARKGRAY:
									knownColor = Color.DarkGray;
									break;
								case COLORINDEX.CI_RED:
									knownColor = Color.Red;
									break;
								case COLORINDEX.CI_GREEN:
									knownColor = Color.Green;
									break;
								case COLORINDEX.CI_YELLOW:
									knownColor = Color.Yellow;
									break;
								case COLORINDEX.CI_BLUE:
									knownColor = Color.Blue;
									break;
								case COLORINDEX.CI_MAGENTA:
									knownColor = Color.Magenta;
									break;
								case COLORINDEX.CI_CYAN:
									knownColor = Color.Cyan;
									break;

								case COLORINDEX.CI_SYSSEL_FG:
									knownColor = SystemColors.HighlightText;
									break;
								case COLORINDEX.CI_SYSSEL_BK:
									knownColor = SystemColors.Highlight;
									break;
								case COLORINDEX.CI_SYSINACTSEL_FG:
									knownColor = SystemColors.InactiveCaptionText;
									break;
								case COLORINDEX.CI_SYSINACTSEL_BK:
									knownColor = SystemColors.InactiveCaption;
									break;
								case COLORINDEX.CI_SYSWIDGETMGN_BK:
									knownColor = SystemColors.ButtonFace;
									break;
								case COLORINDEX.CI_SYSPLAINTEXT_FG:
									knownColor = SystemColors.WindowText;
									break;
								case COLORINDEX.CI_SYSPLAINTEXT_BK:
									knownColor = SystemColors.Window;
									break;
							}
							return knownColor;
						case SystemColorBit:
							colorValue = GetSysColor((int)coreColorValue);
							break;
						case VsColorBit:
							if (myShell == null)
							{
								myShell = (IVsUIShell2)myServiceProvider.GetService(typeof(IVsUIShell));
							}
							ErrorHandler.ThrowOnFailure(myShell.GetVSSysColorEx((int)coreColorValue, out colorValue));
							break;
						case TrackForegroundColorBit:
							{
								ColorableItemInfo[] myGetItemParam = new ColorableItemInfo[1];
								ErrorHandler.ThrowOnFailure(myStorage.GetItem(myIndexConverter((int)coreColorValue), myGetItemParam));
								return TranslateColorValue(myGetItemParam[0].crForeground);
							}
						case TrackBackgroundColorBit:
							{
								ColorableItemInfo[] myGetItemParam = new ColorableItemInfo[1];
								ErrorHandler.ThrowOnFailure(myStorage.GetItem(myIndexConverter((int)coreColorValue), myGetItemParam));
								return TranslateColorValue(myGetItemParam[0].crBackground);
							}
					}
				}
				return ColorTranslator.FromWin32((int)colorValue);
			}