예제 #1
0
        public override bool IsEnabled(_DTE application)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (fileName != lastFile || DateTime.Now - lastBranchCheck > TimeSpan.FromSeconds(2))
            {
                string newCaption = "&Commit";
                if (enabled)
                {
                    bool showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
                    if (showCurrentBranch && !string.IsNullOrEmpty(fileName))
                    {
                        string head = GitCommands.GetCurrentBranch(fileName);
                        if (!string.IsNullOrEmpty(head))
                        {
                            string headShort;
                            if (head.Length > 27)
                            {
                                headShort = "..." + head.Substring(head.Length - 23);
                            }
                            else
                            {
                                headShort = head;
                            }

                            newCaption = "&Commit (" + headShort + ")";
                        }
                    }

                    lastBranchCheck = DateTime.Now;
                    lastFile        = fileName;
                }

                // This guard required not only for performance, but also for prevent StackOverflowException.
                // IDE.QueryStatus -> Commit.IsEnabled -> Plugin.UpdateCaption -> IDE.QueryStatus ...
                if (_lastUpdatedCaption != newCaption)
                {
                    _lastUpdatedCaption = newCaption;

                    // try apply new caption (operation can fail)
                    if (!PluginHelpers.ChangeCommandCaption(application, PluginHelpers.GitCommandBarName, "Commit changes", newCaption))
                    {
                        _lastUpdatedCaption = null;
                    }
                }
            }

            return(enabled);
        }
예제 #2
0
        public override bool IsEnabled(EnvDTE80.DTE2 application)
        {
            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (showCurrentBranch && (fileName != lastFile || DateTime.Now - lastBranchCheck > new TimeSpan(0, 0, 0, 1, 0)))
            {
                string newCaption = "Commit";
                if (enabled)
                {
                    string head = GitCommands.GetCurrentBranch(fileName);
                    if (!string.IsNullOrEmpty(head))
                    {
                        string headShort;
                        if (head.Length > 27)
                        {
                            headShort = "..." + head.Substring(head.Length - 23);
                        }
                        else
                        {
                            headShort = head;
                        }

                        newCaption = "Commit (" + headShort + ")";
                    }
                }

                // This guard required not only for perfromance, but also for prevent StackOverflowException.
                // IDE.QueryStatus -> Commit.IsEnabled -> Plugin.UpdateCaption -> IDE.QueryStatus ...
                if (_lastUpdatedCaption != newCaption)
                {
                    _lastUpdatedCaption = newCaption;

                    // try apply new caption (operation can fail)
                    if (!Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", newCaption))
                    {
                        _lastUpdatedCaption = null;
                    }
                }

                lastBranchCheck = DateTime.Now;
                lastFile        = fileName;
            }

            return(enabled);
        }
예제 #3
0
        public override bool IsEnabled(EnvDTE80.DTE2 application)
        {
            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (showCurrentBranch && (fileName != lastFile || DateTime.Now - lastBranchCheck > new TimeSpan(0, 0, 0, 1, 0)))
            {
                if (enabled)
                {
                    string head = GitCommands.GetCurrentBranch(fileName);
                    if (!string.IsNullOrEmpty(head))
                    {
                        string headShort;
                        if (head.Length > 27)
                        {
                            headShort = "..." + head.Substring(head.Length - 23);
                        }
                        else
                        {
                            headShort = head;
                        }
                        Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", "Commit (" + headShort + ")");
                    }
                    else
                    {
                        Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", "Commit");
                    }
                }
                else
                {
                    Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", "Commit");
                }

                lastBranchCheck = DateTime.Now;
                lastFile        = fileName;
            }

            return(enabled);
        }
예제 #4
0
        public override void Update(Command command)
        {
            var fileName = GetFileName(SolutionExplorer);

            if (!string.Equals(fileName, lastFile, StringComparison.InvariantCulture) || DateTime.Now - lastBranchCheck > TimeSpan.FromSeconds(2))
            {
                var newCaption = "Commit";
                if (true)
                {
                    var showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
                    if (showCurrentBranch && !string.IsNullOrEmpty(fileName))
                    {
                        var head = GitCommands.GetCurrentBranch(fileName);
                        if (!string.IsNullOrEmpty(head))
                        {
                            var headShort = head.Length > 27 ? $"...{head.Substring(head.Length - 23)}" : head;
                            newCaption = $"Commit ({headShort})";
                        }
                    }

                    lastBranchCheck = DateTime.Now;
                    lastFile        = fileName;
                }

                // This guard required not only for performance, but also for prevent StackOverflowException.
                // IDE.QueryStatus -> Commit.IsEnabled -> Plugin.UpdateCaption -> IDE.QueryStatus ...
                if (!string.Equals(_lastUpdatedCaption, newCaption, StringComparison.InvariantCulture))
                {
                    _lastUpdatedCaption = newCaption;

                    command.Text    = newCaption;
                    command.ToolTip = "Commit changes";
                }
            }

            base.Update(command);
        }
예제 #5
0
        public override bool IsEnabled(EnvDTE80.DTE2 application)
        {
            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (showCurrentBranch != null && lastBranchCheck != null && showCurrentBranch.Value && (fileName != lastFile || DateTime.Now - lastBranchCheck > new TimeSpan(0, 0, 0, 1, 0)))
            {
                if (enabled)
                {
                    Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", "Commit" + GitCommands.GetCurrentBranch(fileName));
                }
                else
                {
                    Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", "Commit");
                }

                lastBranchCheck = DateTime.Now;
                lastFile        = fileName;
            }

            return(enabled);
        }