Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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;
            }
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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");
        }
Esempio n. 9
0
 private void OnNewCommandCreated(ICommandVM cmd)
 {
     SelectedElement = cmd;
 }
Esempio n. 10
0
 internal MacroDropArgs(string[] filePaths, ICommandVM targetCmd)
 {
     FilePaths     = filePaths;
     TargetCommand = targetCmd;
 }
Esempio n. 11
0
        private void RemoveCommand(ICommandVM cmd)
        {
            var coll = FindCommandCollection(cmd);

            coll.Commands.Remove(cmd);
        }
Esempio n. 12
0
 private void OnNewCommandCreated(ICommandVM cmd)
 {
     SelectedElement      = cmd;
     cmd.WorkingDirectory = WorkingDirectory;
 }