private void NaviBoxEvent_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            string newName = CurrentDirectoryPath + e.Label;

            if (e.Label == null)
            {
                return;
            }
            ASCIIEncoding AE = new ASCIIEncoding();

            char[] temp = e.Label.ToCharArray();

            for (int x = 0; x < temp.Length; x++)
            {
                byte[] bc = AE.GetBytes(temp[x].ToString());

                if (bc[0] > 47 && bc[0] < 58)
                {
                    e.CancelEdit = true;
                    MessageBox.Show("The text for the item cannot contain numerical values.");
                    return;
                }
            }
            if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
            {
                FileAndDirOperations.RenameDirectory(NavigatorBoxControl.SelectionPath, newName);
            }
            FileAndDirOperations.RenameFile(NavigatorBoxControl.SelectionPath, newName);
            NavigatorBoxControl.SelectionPath = newName;
        }
        private void NaviBoxEvent_DragDrop(object sender, DragEventArgs e)
        {
            if (NaviBox.SelectedItems.Count == 0)
            {
                return;
            }
            Point        cp         = NaviBox.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y);

            if (dragToItem == null)
            {
                return;
            }

            int dragIndex = dragToItem.Index;

            ListViewItem[] selection = new ListViewItem[NaviBox.SelectedItems.Count];

            for (int i = 0; i <= NaviBox.SelectedItems.Count - 1; i++)
            {
                selection[i] = NaviBox.SelectedItems[i];
            }
            for (int i = 0; i < selection.GetLength(0); i++)
            {
                ListViewItem dragItem  = selection[i];
                int          itemIndex = dragIndex;
                if (itemIndex == dragItem.Index)
                {
                    return;
                }
                if (dragItem.Index < itemIndex)
                {
                    itemIndex++;
                }
                else
                {
                    itemIndex = dragIndex + i;
                }
            }

            int targetIndex = NaviBox.InsertionMark.Index;

            if (targetIndex == -1)
            {
                return;
            }

            if (NaviBox.InsertionMark.AppearsAfterItem)
            {
                targetIndex++;
            }

            if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
            {
                NavigatorBoxControl.CopyDirectory(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget);
                return;
            }
            NavigatorBoxControl.CopyFile(NavigatorBoxControl.SelectionPath, NavigatorBoxControl.CopyTarget);
        }
        public bool KeyPressed(Keys key)
        {
            if (key == Keys.Enter)
            {
                return(true);
            }

            if (key == Keys.Back)
            {
                NavigateOneDirectoryUp();
            }

            if (key == Keys.F2 && NaviBox.SelectedItems.Count > 0)
            {
                NaviBox.SelectedItems[0].BeginEdit();
            }

            if (key == Keys.F3)
            {
                FileAndDirOperations.PackFile(NavigatorBoxControl.MakeFileInfoFromPath());
            }

            if (key == Keys.F4)
            {
                FileAndDirOperations.UnpackFile(NavigatorBoxControl.MakeFileInfoFromPath());
            }

            if (key == Keys.F5)
            {
                NavigatorBoxControl.ShowFileProperties(NavigatorBoxControl.SelectionPath);
            }

            if (key == Keys.Delete)
            {
                if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
                {
                    FileAndDirOperations.DeleteDirectory(NavigatorBoxControl.SelectionPath);
                }
                FileAndDirOperations.DeleteFile(NavigatorBoxControl.SelectionPath);
            }

            if (key == Keys.Escape)
            {
                Application.Exit();
            }
            return(false);
        }
        private void NaviBoxEvent_DragOver(object sender, DragEventArgs e)
        {
            Point targetPoint = NaviBox.PointToClient(new Point(e.X, e.Y));

            int targetIndex = NaviBox.InsertionMark.NearestIndex(targetPoint);

            if (targetIndex > -1)
            {
                Rectangle itemBounds = NaviBox.GetItemRect(targetIndex);
                if (targetPoint.X > itemBounds.Left + (itemBounds.Width / 2))
                {
                    NaviBox.InsertionMark.AppearsAfterItem = true;
                }
                else
                {
                    NaviBox.InsertionMark.AppearsAfterItem = false;
                }
            }
            NaviBox.InsertionMark.Index = targetIndex;
            // setting target path to the location of the cursor
            Point        cp         = NaviBox.PointToClient(new Point(e.X, e.Y));
            ListViewItem dragToItem = NaviBox.GetItemAt(cp.X, cp.Y);

            try
            {
                if (NavigatorBoxControl.IsItADirectory(NavigatorBoxControl.SelectionPath))
                {
                    DirectoryInfo srcDirInfo = new DirectoryInfo(NavigatorBoxControl.SelectionPath);
                    DirectoryInfo tarDirInfo = new DirectoryInfo(dragToItem.ListView.Columns[0].Text);
                    NavigatorBoxControl.CopyTarget = tarDirInfo.FullName + dragToItem.Text + @"\" + srcDirInfo.Name;
                }
                else
                {
                    FileInfo srcFileInfo = new FileInfo(NavigatorBoxControl.SelectionPath);
                    FileInfo tarFileInfo = new FileInfo(dragToItem.ListView.Columns[0].Text);
                    NavigatorBoxControl.CopyTarget = tarFileInfo.FullName + dragToItem.Text + @"\" + srcFileInfo.Name;
                }
            }
            catch { }
        }
 public void ChooseNavigateOrExecute()
 {
     CurrentSelection = new FileInfo(CurrentDirectoryPath + NaviBox.SelectedItems[0].Text);
     if (NavigatorBoxControl.IsItADirectory(CurrentSelection.FullName))
     {
         WillNavigateIntoDirectory(true);
         currentDirectoryInfo = new DirectoryInfo(CurrentDirectoryPath);
         ListContent();
     }
     else
     {
         currentDirectoryInfo = Directory.GetParent(CurrentDirectoryPath);
         try
         {
             Process.Start(CurrentSelection.FullName);
         }
         catch
         {
             CustomDialog.ErrorMessage("ERROR: Could not open file.", "Error");
         }
     }
 }