Пример #1
0
 public Commit()
 {
     if (lastFile == null)
     {
         lastFile = string.Empty;
     }
     showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
 }
Пример #2
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);
        }
Пример #3
0
 public Commit()
     : base(true, true)
 {
     if (lastBranchCheck == null)
     {
         lastBranchCheck = DateTime.MinValue;
     }
     if (lastFile == null)
     {
         lastFile = string.Empty;
     }
     if (showCurrentBranch == null)
     {
         showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
     }
 }
Пример #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);
        }