private void RemoveCommand(ICommandVM cmd) { var coll = FindCommandCollection(cmd); coll.Commands.Remove(cmd); if (Groups.Commands.Count == 1 && Groups.Commands[0].Commands.Commands.Count == 0)//TODO: temp solution until Tree View can have selected element binding { return; } SelectedElement = null; }
private void InsertNewCommand(ICommandVM cmd, bool after) { ICommandsCollection coll; var index = CalculateCommandIndex(cmd, after, out coll); if (!after) { index++;//insert to current position } coll.AddNewCommand(index); }
private int CalculateCommandIndex(ICommandVM cmd, bool forward, out ICommandsCollection coll) { var offset = forward ? 1 : -1; coll = FindCommandCollection(cmd); var index = coll.Commands.IndexOf(cmd); if (index == -1) { throw new IndexOutOfRangeException("Index of the command is not found"); } return(index + offset); }
private void RemoveCommand(ICommandVM cmd) { var coll = FindCommandCollection(cmd); coll.Commands.Remove(cmd); if (coll.Commands.Count > 0) { SelectedElement = coll.Commands[0] as ICommandVM; } else { SelectedElement = null; } }
private void MoveCommand(ICommandVM cmd, bool forward) { ICommandsCollection coll; var index = CalculateCommandIndex(cmd, forward, out coll); var cmds = coll.Commands; if (index < 0 || index >= cmds.Count) { throw new IndexOutOfRangeException("Index is outside the boundaries of the commands collection"); } cmds.Remove(cmd); cmds.Insert(index, cmd); SelectedElement = cmd; }
private ICommandVM GetCommandAtLocation(TreeView treeView, Point location) { ICommandVM foundCmd = null; var hitTestResults = VisualTreeHelper.HitTest(treeView, location); if (hitTestResults.VisualHit is FrameworkElement) { var dataObject = (hitTestResults.VisualHit as FrameworkElement).DataContext; if (dataObject is ICommandVM) { foundCmd = (ICommandVM)dataObject; } } return(foundCmd); }
private void AssignDefaultTitle(ICommandVM newCmd) { int index = 0; var title = ""; do { index++; if (newCmd is CommandMacroVM) { title = $"Macro {index}"; } else if (newCmd is CommandGroupVM) { title = $"Toolbar {index}"; } } while (Commands.FirstOrDefault( x => string.Equals(x.Title, title, StringComparison.CurrentCultureIgnoreCase)) != null); newCmd.Title = title; }
private ICommandsCollection FindCommandCollection(ICommandVM targetCmd) { foreach (var grp in Groups.Commands) { if (grp == targetCmd) { return(Groups); } else { foreach (var cmd in grp.Commands.Commands) { if (cmd == targetCmd) { return(grp.Commands); } } } } throw new NullReferenceException("Failed to find the command"); }
private void OnNewCommandCreated(ICommandVM cmd) { SelectedElement = cmd; }
internal MacroDropArgs(string[] filePaths, ICommandVM targetCmd) { FilePaths = filePaths; TargetCommand = targetCmd; }
private void RemoveCommand(ICommandVM cmd) { var coll = FindCommandCollection(cmd); coll.Commands.Remove(cmd); }
private void OnNewCommandCreated(ICommandVM cmd) { SelectedElement = cmd; cmd.WorkingDirectory = WorkingDirectory; }