public void Exec(object sender, EventArgs e) { string sourceItem = string.Empty; string targetItem = string.Empty; try { OleDynamicCommand invokedCommand = (OleDynamicCommand)sender; sourceItem = tfsVersionControl.SCESelectedItems[0]; targetItem = invokedCommand.Text; logger.Log(string.Format("Compare to branch: {0} {1}", sourceItem, targetItem), LogLevel.Verbose); if (tfsVersionControl.SelectedItemsAllFolders) { tfsVersionControl.CompareFolders(sourceItem, targetItem); } else { tfsVersionControl.CompareFiles(sourceItem, targetItem); } } catch (Exception ex) { logger.Log(string.Format("Error Compare to branch: {0} {1}\n {2}", sourceItem, targetItem, ex.ToString()), LogLevel.Error); } }
public void QueryStatus(object sender, EventArgs e) { try { OleDynamicCommand matchedCommand = (OleDynamicCommand)sender; if (branches.Count == 0) { matchedCommand.Enabled = false; matchedCommand.Visible = false; return; } else { matchedCommand.Enabled = true; matchedCommand.Visible = true; } // Find out whether the command ID is 0, which is the ID of the root item. // If it is the root item, it matches the constructed DynamicItemMenuCommand, // and IsValidDynamicItem won't be called. bool isRootItem = (matchedCommand.MatchedCommandId == 0); int index = (isRootItem ? 0 : (matchedCommand.MatchedCommandId - (int)PkgCmdIDList.cmdIdDynamicCompareToBranchCommand)); matchedCommand.Text = branches[index]; // Clear the ID because we are done with this item. matchedCommand.MatchedCommandId = 0; } catch (Exception ex) { logger.Log(string.Format("Error QueryStatus CompareToBranchCommand\n {0}", ex.ToString()), LogLevel.Error); } }
public CompareToBranchCommand(IMenuCommandService menuCommandService, ILogger _logger, ITFSVersionControl _tfs) { branches = new List <string>(); logger = _logger; tfsVersionControl = _tfs; CommandID compareToBranchId = new CommandID(GuidList.guidTFSProductivityPackCmdSet, PkgCmdIDList.cmdIdDynamicCompareToBranchCommand); compareToBranchOleCommand = new OleDynamicCommand(compareToBranchId, IsValidDynamicItem, Exec, QueryStatus); menuCommandService.AddCommand(compareToBranchOleCommand); }