Exemplo n.º 1
0
        public static void Delete()
        {
            int result = MessageBox.Query(50, 7, "Warning!", string.Format("Are you sure? Do you want to permanently delete selected {0}?", MyDrive.SelectedItem.IsDirectory ? "directory" : "file"), "Yes", "No");

            switch (result)
            {
            case 0:
                Utils.Drive.Delete(MyDrive.SelectedItem.Id).ContinueWith((task) =>
                {
                    if (task.Result)
                    {
                        Application.MainLoop.Invoke(() =>
                        {
                            var selectedItemIndex = MyDrive.Files.IndexOf(MyDrive.SelectedItem);

                            if (selectedItemIndex == (MyDrive.Files.Count - 1))
                            {
                                MyDrive.SelectItem(MyDrive.Files[selectedItemIndex - 1]);
                            }

                            MyDrive.Files.Remove(MyDrive.SelectedItem);

                            Application.Top.SetFocus(MyDrive.Window);
                            Application.Refresh();
                        });
                    }
                });
                break;

            case 1:
                Application.Top.SetFocus(MyDrive.Window);
                break;
            }
        }
Exemplo n.º 2
0
        public static void SortOrder()
        {
            Dialog     dialog     = new Dialog("Sort By", 25, 10);
            RadioGroup radioGroup = new RadioGroup(3, 1, new string[] { "Ascending", "Descending" }, (int)Utils.Settings.SortOrder);

            dialog.Add(radioGroup);

            Button btnOk = new Button("OK", true);

            btnOk.Clicked = delegate()
            {
                Utils.Settings.SortOrder = (Utils.SortOrder)radioGroup.Selected;
                Utils.Settings.Save();

                MyDrive.SortItems();

                dialog.Running = false;
                Application.Top.SetFocus(MyDrive.Window);
            };
            Button btnCancel = new Button("Cancel");

            btnCancel.Clicked = delegate()
            {
                dialog.Running = false;
                Application.Top.SetFocus(MyDrive.Window);
            };
            dialog.AddButton(btnOk);
            dialog.AddButton(btnCancel);

            Application.Run(dialog);
            Application.Refresh();
        }
Exemplo n.º 3
0
        public static void NewFolder()
        {
            string newFolderName  = "New Folder";
            int    newFolderCount = 0;

            while (MyDrive.Files != null && MyDrive.Files.Find((file) => file.Name.Equals(newFolderName)) != null)
            {
                newFolderName = string.Format("New Folder ({0})", ++newFolderCount);
            }

            Dialog    dialog    = new Dialog("Enter Folder Name", 50, 8);
            TextField textField = new TextField(newFolderName)
            {
                X     = 1,
                Y     = 1,
                Width = Dim.Fill(1)
            };

            dialog.Add(textField);

            Button btnOk = new Button("OK", true);

            btnOk.Clicked = delegate()
            {
                Utils.Drive.NewFolder(MyDrive.CurrentDirectory.Id, textField.Text.ToString()).ContinueWith((task) =>
                {
                    Application.MainLoop.Invoke(() =>
                    {
                        MyDrive.Files.Add(task.Result);

                        MyDrive.SortItems();

                        MyDrive.SelectItem(task.Result);

                        dialog.Running = false;
                        Application.Top.SetFocus(MyDrive.Window);
                    });
                });
            };
            Button btnCancel = new Button("Cancel");

            btnCancel.Clicked = delegate()
            {
                dialog.Running = false;
                Application.Top.SetFocus(MyDrive.Window);
            };
            dialog.AddButton(btnOk);
            dialog.AddButton(btnCancel);

            Application.Run(dialog);
            Application.Refresh();
        }
Exemplo n.º 4
0
 public DriveView(MyDrive drive)
 {
     InitializeComponent();
     this.drive          = drive;
     DriveNameBlock.Text = drive.Path;
 }
Exemplo n.º 5
0
Arquivo: Form1.cs Projeto: taitung/lba
        private void PopulatePhysicalDrives()
        {
            cbDriveInfos.Items.Clear();
            System.Collections.Generic.IList<MyDrive> physicalDrives =
                new System.Collections.Generic.List<MyDrive>();
            ManagementClass devices = new ManagementClass(@"Win32_DiskDrive");
            ManagementObjectCollection objects = devices.GetInstances();
            foreach (ManagementObject obj in objects)
            {
                MyDrive myDrive = new MyDrive();

                // fields refer to https://msdn.microsoft.com/en-us/library/aa394132%28v=vs.85%29.aspx
                myDrive.DeviceID = (string)obj["DeviceID"];
                myDrive.Caption = (string)obj["Caption"];
                myDrive.Name = (string)obj["Name"];

                foreach (ManagementObject b in obj.GetRelated("Win32_DiskPartition"))
                {
                    foreach (ManagementBaseObject c in b.GetRelated("Win32_LogicalDisk"))
                    {
                        myDrive.DriveLetter = (string)c["Name"];
                        myDrive.Caption += "(" +myDrive.DriveLetter+ ")";
                    }

                }
                physicalDrives.Add(myDrive);
            }

            MyDrive myDrive1 = new MyDrive();
            myDrive1.Caption = "Please select one...";
            myDrive1.DeviceID = "-1";
            physicalDrives.Insert(0, myDrive1);
            cbDriveInfos.DataSource = physicalDrives;
            cbDriveInfos.DisplayMember = "Caption";
        }