private void AddBranchSpecificActions(Menu.MenuItemCollection items, bool needsLeadingSeparator) { var selectedRows = branchGrid.Grid.SelectedRows; if (selectedRows.Count > 0) { if (needsLeadingSeparator) { items.AddSeparator(); } var row = selectedRows[0].DataRow; var branchId = row["ID"]; var taskId = row["TaskID"]; var builtInActions = new[] { new MenuAction("defaultInspect", "&Inspect", true, () => SetCurrentBranch(branchId, taskId)), new MenuAction("defaultOpen", "&Work on this", row["BasePath"] != DBNull.Value, () => StartWorkOnBranch(branchId, taskId)), }; items.AddActions(builtInActions); var specificActions = _sourceRepository.GetBranchActions(branchId); if (specificActions.Count > 0) { items.AddSeparator(); items.AddActions(specificActions); } } }
private void AddTaskSpecificActions(Menu.MenuItemCollection items, bool needsLeadingSeparator) { var taskId = taskGrid.FindSelectedId(); if (taskId != null) { var specificActions = _taskRepository.GetTaskActions(taskId); if (specificActions.Count > 0) { if (needsLeadingSeparator) { items.AddSeparator(); } items.AddActions(specificActions); } if (_sourceRepository != null) { if (specificActions.Count > 0) { items.AddSeparator(); } items.AddActions( new MenuAction("createBranch", "Create branch for task {0}".FormatInvariant(taskId), true, () => CreateBranch(taskId)), new MenuAction("goToBranch", "Go to branch for task {0}".FormatInvariant(taskId), true, () => GoToBranchFor(taskId)) ); } } }
private void AddBuildSpecificActions(Menu.MenuItemCollection items, bool needsLeadingSeparator) { var selectedItems = builds.Grid.SelectedRows; if (selectedItems.Count > 0) { if (needsLeadingSeparator) { items.AddSeparator(); } var row = selectedItems[0].DataRow; var buildId = row["ID"]; var buildName = row["Name"]; var builtInActions = new[] { new MenuAction("defaultOpen", "&Open", true, () => SetCurrentBuild(buildId, buildName)), }; items.AddActions(builtInActions); var specificActions = _buildRepository.GetBuildActions(buildId); if (specificActions.Count > 0) { items.AddSeparator(); items.AddActions(specificActions); } } }
private void AddShelvesetSpecificActions(Menu.MenuItemCollection items, bool needsLeadingSeparator) { var selectedItems = shelvesetGrid.Grid.SelectedRows; if (selectedItems.Count > 0) { if (needsLeadingSeparator) { items.AddSeparator(); } var row = selectedItems[0].DataRow; var shelvesetId = row["ID"]; var shelvesetName = (string)row["Name"]; var builtInActions = new[] { new MenuAction("defaultInspect", "&Inspect", true, () => SetCurrentShelveset(shelvesetId, shelvesetName)), }; items.AddActions(builtInActions); var specificActions = _shelvesetRepository.GetShelvesetActions(shelvesetId); if (specificActions.Count > 0) { items.AddSeparator(); items.AddActions(specificActions); } } }
public static void AddAction(this Menu.MenuItemCollection items, MenuAction action) { MenuItem item; if (action.IsSeparator) { items.AddSeparator(); } else { item = new MenuItem { Name = action.Name, Text = action.Caption, Enabled = action.Enabled, // TODO: see if MenuItem supports this: Image = action.Image, }; // TODO: execute safely (i.e. catch exceptions to report errors) and maybe asynchronously item.Click += (clickSender, eventArgs) => { var result = action.Execute(); if (result) { var menuItem = (MenuItem)clickSender; var parentMenu = menuItem.GetContextMenu(); Debug.Assert(parentMenu != null); var parentControl = parentMenu.SourceControl; while (parentControl != null && !(parentControl is IHistoryContainer)) { parentControl = parentControl.Parent; } if (parentControl != null) { var historyContainer = (IHistoryContainer)parentControl; var currentHistoryItem = historyContainer.Current; currentHistoryItem.Reload(); } } }; items.Add(item); } }
private void AddRevisionSpecificActions(Menu.MenuItemCollection items, bool needsLeadingSeparator) { var selectedItems = activityRevisions.Grid.SelectedRows; if (selectedItems.Count > 0) { if (needsLeadingSeparator) { items.AddSeparator(); } var row = selectedItems[0].DataRow; var revisionId = row["ID"]; var builtInActions = new[] { new MenuAction("defaultOpen", "&Open", true, () => SetCurrentRevision(revisionId)), }; items.AddActions(builtInActions); // TODO: Should there be specific actions per revision? Maybe an external view, like TFS has... } }