Пример #1
0
        private object BackEndInsert(String name, RightClickShellType type, String Target, String Source)
        {
            RightClickShell added;
            RightClickShell parent = (DirectoryShell)treeView1.SelectedNode.Tag;

            switch (type)
            {
            case RightClickShellType.DirectoryShell:
                added = new DirectoryShell()
                {
                    Name = name
                };
                insert_deleted.Add(ref parent, ref added);
                break;

            case RightClickShellType.ExecutableShell:
                added = new ExecutableShell()
                {
                    Name = name, Command = ExecutableShell.CreateCommandFromSorceAndTarget(target: txtTarget.Text, source: txtSource.Text), HaveIcon = txtSource.Text + "\\" + txtTarget.Text
                };
                insert_deleted.Add(ref parent, ref added);
                break;

            default:
                added = new DirectoryShell()
                {
                    Name = name
                };
                throw new Exception("not a intended rightclickshelltype");
            }
            return(added);
        }
Пример #2
0
 private void btnCancel_Click(object sender, EventArgs e)
 {
     treeView1.Nodes.Clear();
     insert_deleted.Changes.Clear();
     try
     {
         root = DeSerializeTree(); //lấy cây đã lưu.
     }
     catch
     {
         fs.Close();
         MessageBox.Show("this is a new tree.", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Information);
         root = new DirectoryShell()
         {
             Name = "Directory\\Background"
         };                                 // tạo cây mới.
     }
     root.SetParentForChild();              // vì quá kém cõi nên phải set cha thủ công, ko thể tự động.
     cursor         = (DirectoryShell)root; // đây là con trỏ hiện tại để tui test.
     insert_deleted = new InsertDeleteManager((DirectoryShell)root);
     view_root      = new TreeNode()
     {
         Tag = root, Text = "Root"
     };
     CreateViewRoot();
     treeView1.Nodes.Add(view_root);
 }
Пример #3
0
        public Form1()
        {
            InitializeComponent();
            try
            {
                root = DeSerializeTree(); //lấy cây đã lưu.
            }
            catch
            {
                fs.Close();
                MessageBox.Show("this is a new tree.", "Caution", MessageBoxButtons.OK, MessageBoxIcon.Information);
                root = new DirectoryShell()
                {
                    Name = "Directory\\Background"
                };                    // tạo cây mới.
            }
            root.SetParentForChild(); // vì quá kém cõi nên phải set cha thủ công, ko thể tự động
            insert_deleted = new InsertDeleteManager((DirectoryShell)root);
            view_root      = new TreeNode()
            {
                Tag = root, Text = "Root"
            };

            treeView1.Nodes.Add(view_root);
            treeView1.ImageList = new ImageList();
            treeView1.ImageList.Images.Add(new Bitmap(1, 1));
            btnCancel.Hide();
            btnApplyofEdit.Hide();
            CreateViewRoot();
        }
Пример #4
0
        private static void Insert()
        {
            Console.Write("Name:");
            String name = Console.ReadLine();

            Console.Write("Type:");
            RightClickShellType type = (RightClickShellType)int.Parse(Console.ReadLine());
            RightClickShell     added;

            switch (type)
            {
            case RightClickShellType.DirectoryShell:
                added = new DirectoryShell()
                {
                    Name = name
                };
                insert_deleted.Add(ref cursor, ref added);
                break;

            case RightClickShellType.ExecutableShell:
                added = new ExecutableShell()
                {
                    Name = name, Command = "MyCommand"
                };
                insert_deleted.Add(ref cursor, ref added);
                break;
            }
        }
Пример #5
0
        private static void Delete()
        {
            DirectoryShell p = cursor.Parent;

            insert_deleted.Delete(ref cursor);
            //cursor = p;
            //cursor.Parent.Children.Remove(cursor);
        }
Пример #6
0
        public DirectoryShell DeSerializeTree()
        {
            XmlSerializer xmlSerializer_background = new XmlSerializer(typeof(DirectoryShell));

            fs = new FileStream("BackGroundShortcuts.xml", FileMode.OpenOrCreate);
            DirectoryShell res = (DirectoryShell)xmlSerializer_background.Deserialize(fs);

            fs.Close();
            return(res);
        }
Пример #7
0
        static void Main(string[] args)
        {
            try
            {
                root = DeSerializeTree(); //lấy cây đã lưu.
            }
            catch
            {
                fs.Close();
                Console.WriteLine("this is a new tree.");
                root = new DirectoryShell()
                {
                    Name = "Directory\\Background"
                };                         // tạo cây mới.
            }
            root.SetParentForChild();      // vì quá kém cõi nên phải set cha thủ công, ko thể tự động.
            cursor = (DirectoryShell)root; // đây là con trỏ hiện tại để tui test.
            while (true)
            {
                int input;
                PrintMenu();// in menu lệnh chưa hoàn chỉnh.
                input = int.Parse(Console.ReadLine());
                switch (input)
                {
                case 1:
                    Insert();    // thêm, dựa theo cursor
                    break;

                case 2:
                    Delete();    // xóa cursor khỏi cây.
                    break;

                case 3:
                    PrintTree((DirectoryShell)root);
                    break;

                case 4:
                    CursorAccess(ref cursor);    // duyệt cây theo user.
                    break;

                default:

                    break;
                }
                if (input == 0)
                {
                    break;
                }
            }
        }
Пример #8
0
        public static void PrintTree(DirectoryShell root, String level_header = "")
        {
            RightClickShell         current;
            Stack <RightClickShell> queue = new Stack <RightClickShell>();

            queue.Push(root);
            while (queue.Count > 0)
            {
                current = queue.Pop();
                switch (current.Type)
                {
                case RightClickShellType.DirectoryShell:
                    foreach (RightClickShell sub in ((DirectoryShell)current).Children)
                    {
                        queue.Push(sub);
                    }
                    break;

                default:
                    break;
                }
                Console.WriteLine(current.getRegistryPath());
            }
        }