コード例 #1
0
ファイル: MainForm.cs プロジェクト: nithinphilips/SMOz
        private void applyChangesToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if ((redoQueue.Count > 0) && (redoQueue.Peek().Name == Language.ApplyChanges))
            {
                // ...
                Redo();
            }

            List<Command> result = new List<Command>();
            foreach (Command command in undoQueue)
            {
                if (command.Type == SMOz.Commands.CommandType.Group)
                {
                    CommandGroup group = command as CommandGroup;
                    if (group.Name == Language.ApplyChanges)
                    {
                        // Stop when the last Apply Changes is found
                        break;
                    }
                }
                ConvertCommands(result, command);
            }
            if (result.Count <= 0)
            {
                MessageBox.Show(Language.NothingToDoMessage, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            result.Reverse();
            using (ReviewChanges review = new ReviewChanges(false))
            {
                foreach (Command cmd in result)
                {
                    MoveFileCommand cmdMove = cmd as MoveFileCommand;
                    if (cmd.Type == SMOz.Commands.CommandType.IODelete)
                    {
                        review.Add(Command.TypeToString(cmdMove.Type),
                          cmdMove.Source.Replace("Documents and Settings", "...")
                          .Replace("Start Menu\\Programs", "..."), "Trash", cmdMove.MayFail);
                    }
                    else
                    {
                        review.Add(Command.TypeToString(cmdMove.Type),
                          cmdMove.Source.Replace("Documents and Settings", "...")
                          .Replace("Start Menu\\Programs", "..."),
                          "to " + cmdMove.Target.Replace("Documents and Settings", "...")
                          .Replace("Start Menu\\Programs", "..."), cmdMove.MayFail);
                    }
                }
                if (review.ShowDialog(this) == DialogResult.OK)
                {
                    //				localWatcher.EnableRaisingEvents = false;
                    //				userWatcher.EnableRaisingEvents = false;
                    if (ApplyRealChanges(result))
                    {
                        CommandGroup group = new CommandGroup(Language.ApplyChanges, result);
                        AddUndoCommand(group);
                        _statusLabel.Text = "Changes successfully applied";
                    }
                    //				localWatcher.EnableRaisingEvents = true;
                    //				userWatcher.EnableRaisingEvents = true;
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: nithinphilips/SMOz
        private void Paste()
        {
            if (Clipboard.ContainsData(clipboardDataType.Name))
            {
                StartItem[] data;
                IDataObject dataObj = Clipboard.GetDataObject();

                if (dataObj.GetDataPresent(clipboardDataType.Name))
                {
                    data = dataObj.GetData(clipboardDataType.Name) as StartItem[];

                    List<Command> commands = new List<Command>();
                    foreach (StartItem item in data)
                    {
                        if (item.Category != _categoryTree.SelectedNode.Name)
                        {
                            MoveStartItemCommand cmd = new MoveStartItemCommand(item, _categoryTree.SelectedNode.Name);
                            commands.Add(cmd);
                        }
                        _itemList.Items.Add(StartItemToListItem(item, true));
                        startManager.AddItem(item);
                    }

                    if (commands.Count > 0)
                    {
                        CommandGroup group = new CommandGroup(string.Format(Language.MoveItemsFormat, commands.Count), commands);

                        group.Execute();

                        if (group.Commands.Count == 1)
                        {
                            this.AddUndoCommand(group.Commands[0]);
                        }
                        else if (group.Commands.Count > 1)
                        {
                            this.AddUndoCommand(group);
                        }
                    }

                }
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: nithinphilips/SMOz
        private void _categoryTree_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(dragDataType))
            {
                ListView.SelectedListViewItemCollection draggedItems = e.Data.GetData(dragDataType) as ListView.SelectedListViewItemCollection;

                if (draggedItems != null)
                {
                    Point pt = _categoryTree.PointToClient(new Point(e.X, e.Y));
                    TreeNode target = _categoryTree.GetNodeAt(pt);

                    if (target != null)
                    {
                        target.BackColor = SystemColors.Window;
                        CommandGroup group = new CommandGroup(string.Format(Language.MoveItemsFormat, draggedItems.Count));

                        foreach (ListViewItem listItem in draggedItems)
                        {
                            StartItem item = (StartItem)listItem.Tag;
                            // TODO: Check if target exists. 
                            //   Give options: 'Overwrite' or 'Don't Move'
                            // Overwrite:
                            //	 Delete Target, Move File
                            var existingItems = startManager.GetByCategory(target.Name);
                            if (target.Name != item.Category)
                            {
                                MoveStartItemCommand cmd = new MoveStartItemCommand(item, target.Name);
                                DeleteStartItemCommand cmdDelete = null;
                                bool cancel = false;

                                foreach (StartItem existing in existingItems)
                                {
                                    if ((existing.Name == cmd.NewName) && (existing.Type == item.Type))
                                    {
                                        if (MessageBox.Show("An item named '" + existing.Name + "' already exists. Do still want to move?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                                        {
                                            cancel = true;
                                        }
                                        else
                                        {
                                            cmdDelete = new DeleteStartItemCommand(existing, startManager);
                                        }
                                        break;
                                    }
                                }
                                if (cancel) { continue; } // go to next one
                                if (cmdDelete != null) group.Commands.Add(cmdDelete);
                                group.Commands.Add(cmd);
                                _itemList.Items.Remove(listItem);
                            }
                        }

                        group.Execute();


                        if (group.Commands.Count == 1)
                        {
                            this.AddUndoCommand(group.Commands[0]);
                        }
                        else if (group.Commands.Count > 1)
                        {
                            this.AddUndoCommand(group);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: nithinphilips/SMOz
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((_itemList.SelectedItems != null) && (_itemList.SelectedItems.Count > 0))
            {
                CommandGroup group = new CommandGroup(string.Format(Language.DeleteItemsFormat, _itemList.SelectedItems.Count));
                foreach (ListViewItem listItem in _itemList.SelectedItems)
                {
                    StartItem item = (StartItem)listItem.Tag;
                    DeleteStartItemCommand cmd = new DeleteStartItemCommand(item, this.startManager);
                    group.Commands.Add(cmd);
                    _itemList.Items.Remove(listItem);
                }

                group.Execute();


                if (group.Commands.Count == 1)
                {
                    this.AddUndoCommand(group.Commands[0]);
                }
                else if (group.Commands.Count > 1)
                {
                    this.AddUndoCommand(group);
                }
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: nithinphilips/SMOz
        void ApplyTemplate(MoveStartItemCommand[] commands, string name)
        {
            if ((commands == null) || (commands.Length <= 0))
            {
                MessageBox.Show(Language.NothingToDoMessage, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            using (ReviewChanges review = new ReviewChanges(true))
            {
                foreach (MoveStartItemCommand cmd in commands)
                {
                    foreach (string str in AddCategoryToTree(cmd.NewCategory))
                    {
                        // Ensure that the target category is visible to user
                        AddToManager(str);
                    }
                    review.Add("Move", "'" + cmd.OldName + "' to '" + cmd.NewName + "'");
                }

                if (review.ShowDialog(this) == DialogResult.OK)
                {
                    CommandGroup group = new CommandGroup(Language.ApplyTemplate, commands);
                    AddUndoCommand(group, true);
                    UpdateItemList();
                }
            }

        }