예제 #1
0
        public ListViewPanel(Form parent)
        {
            this.Parent = parent;

            Size      = new Size(this.Parent.Width / 2, this.Parent.Height - 100);
            this.Dock = DockStyle.Right;

            _listView           = new ListView();
            _listView.Parent    = this;
            _listView.Dock      = DockStyle.Fill;
            _listView.View      = View.LargeIcon;
            _listView.LabelEdit = true;

            _listViewController = new ListViewController(this);

            _statusBar        = new StatusBar();
            _statusBar.Parent = this;
            _statusBar.Dock   = DockStyle.Bottom;

            //_contextMenuStrip = new ContextMenuStrip ();
            //_contextMenuStrip = _listView.ContextMenuStrip;
            _listView.ContextMenuStrip  = new ContextMenuStrip();
            _contextMenuStrip           = _listView.ContextMenuStrip;
            _contextMenuStrip.AutoClose = true;

            ToolStripMenuItem itemCheckMem = new ToolStripMenuItem("&CheckMemory");

            _contextMenuStrip.Items.Add(itemCheckMem);

            ToolStripMenuItem itemCheckMem100 = new ToolStripMenuItem("&CheckMemory100");

            _contextMenuStrip.Items.Add(itemCheckMem100);

            ToolStripMenuItem itemDelete = new ToolStripMenuItem("&Delete");

            itemDelete.Enabled = false;
            _contextMenuStrip.Items.Add(itemDelete);

            ToolStripMenuItem itemCopy = new ToolStripMenuItem("&Copy");

            _contextMenuStrip.Items.Add(itemCopy);
            itemCopy.Enabled = false;

            ToolStripMenuItem itemRename = new ToolStripMenuItem("&Rename");

            _contextMenuStrip.Items.Add(itemRename);
            itemRename.Enabled = false;

            ToolStripMenuItem itemMove = new ToolStripMenuItem("&Move");

            _contextMenuStrip.Items.Add(itemMove);
            itemMove.Enabled = false;

            _contextMenuStrip.ItemClicked += (object sender, ToolStripItemClickedEventArgs e) =>
            {
                if (((ContextMenuStrip)sender).Items[Constants.CHECKMEM] == e.ClickedItem)
                {
                    ThreadArgs args   = new ThreadArgs(_listViewController.CurrentDirectory);
                    Thread     thread = new Thread(CalculateMemoryThread);
                    thread.IsBackground = true;
                    thread.Start(args);
                    if (thread.ThreadState == System.Threading.ThreadState.Stopped)
                    {
                        _statusBar.Text = "Finished";
                    }
                }
                else if (((ContextMenuStrip)sender).Items[Constants.CHECKMEM100] == e.ClickedItem)
                {
                    ListboxForm lform = new ListboxForm(_listViewController.CurrentDirectory);
                    lform.Show();
                }
                else if (((ContextMenuStrip)sender).Items[Constants.DELETE] == e.ClickedItem)
                {
                    FileController ufile = new FileController(_listViewController.CurrentDirectory.FullName + Path.DirectorySeparatorChar +
                                                              (_listViewController.GetListViewItem().Text));
                    ufile.Delete();

                    _listViewController.Refresh();
                }
                else if (((ContextMenuStrip)sender).Items[Constants.COPY] == e.ClickedItem)
                {
                    FolderBrowserDialog fd = new FolderBrowserDialog();
                    fd.ShowNewFolderButton = false;
                    fd.ShowDialog();

                    FileController ufile = new FileController(_listViewController.CurrentDirectory.FullName + Path.DirectorySeparatorChar +
                                                              (_listViewController.GetListViewItem().Text));

                    ufile.CopyTo(fd.SelectedPath + Path.DirectorySeparatorChar);

                    _listViewController.Refresh();
                }
                else if (((ContextMenuStrip)sender).Items[Constants.RENAME] == e.ClickedItem)
                {
                    FileController ufile = new FileController(_listViewController.CurrentDirectory.FullName + Path.DirectorySeparatorChar +
                                                              (_listViewController.GetListViewItem().Text));

                    PopoutForm pForm = new PopoutForm(ufile);
                    pForm.Show();

                    ufile.Rename(ufile.NewName);

                    _listViewController.Refresh();
                }
                else if (((ContextMenuStrip)sender).Items[Constants.MOVE] == e.ClickedItem)
                {
                    FolderBrowserDialog fd = new FolderBrowserDialog();
                    fd.ShowNewFolderButton = false;
                    fd.ShowDialog();

                    FileController ufile = new FileController(_listViewController.CurrentDirectory.FullName + Path.DirectorySeparatorChar +
                                                              (_listViewController.GetListViewItem().Text));

                    ufile.MoveTo(fd.SelectedPath + Path.DirectorySeparatorChar);

                    _listViewController.Refresh();
                }
            };

            _listView.AfterLabelEdit += (object sender, LabelEditEventArgs e) =>
            {
                FileController ufile = new FileController(_listViewController.CurrentDirectory.FullName +
                                                          Path.DirectorySeparatorChar + e.Label);
                string newName = e.Label;
                newName = newName.Replace(Environment.NewLine, "");

                ufile.Rename(newName);
            };

            _listView.ItemSelectionChanged += (object sender, ListViewItemSelectionChangedEventArgs e) =>
            {
                string path = _listViewController.CurrentDirectory.FullName + Path.DirectorySeparatorChar + e.Item.Text;
                try{
                    if (!Directory.Exists(path))
                    {
                        Process.Start(path);
                    }
                }catch (Exception ee) {
                    Console.WriteLine(ee.Message);
                }

                _listViewController.SetListViewItem(e.Item);

                if (_listViewController.GetListViewItem() != null)
                {
                    foreach (ToolStripMenuItem item in _contextMenuStrip.Items)
                    {
                        item.Enabled = true;
                    }
                }
            };
        }