コード例 #1
0
 private void Iterate(List <IDiscElement> directoryElements)
 {
     //Iterate in directory
     try
     {
         foreach (IDiscElement element in directoryElements)
         {
             //For each element create an view to describe it
             FileView display = new FileView(element);
             //Subscribing to an event, if invoked execute FileView_DisplayFilesEvent;
             display.DirectoryOpenedEvent += FileView_DisplayFilesEvent;
             //File open on doubleclick
             display.FileOpenedEvent += FileView_OpenFileEvent;
             //File Preview event
             display.FilePreviewedEvent += FileView_PreviewFile;
             //And add it to the list
             FileList.Items.Add(display);
         }
     }
     catch (Exception e)
     {
         //Error Box
         MessageBox.Show(e.ToString());
         DisplayFiles(DriveList.SelectedItem.ToString());
         return;
     }
 }
コード例 #2
0
        /// <summary>
        /// Displays info at the bottom about selected file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Display prepared info at the bottom
            SelectedInfo.Text = "Selected: " + (FileList.SelectedIndex + 1).ToString() + " of " + FileList.Items.Count;
            FileView selectedItem = FileList.SelectedItem as FileView;

            try
            {
                if (selectedItem.file is MyDirectory)
                {
                    currentSelectedItem     = (selectedItem.file as MyDirectory).Name;
                    currentSelectedItemType = "dir";
                    MainWindow.currentPath  = (selectedItem.file as MyDirectory).Path;
                }
                else
                {
                    currentSelectedItem     = (selectedItem.file as MyFile).Name;
                    currentSelectedItemType = "file";
                    MainWindow.currentPath  = (selectedItem.file as MyFile).Path;
                }
            }
            catch
            {
                return;
            }
        }
コード例 #3
0
        /// <summary>
        /// Deletes a file
        /// </summary>

        private void FileDeleteOperation()
        {
            FileView toDelete = (FileList.SelectedItem as FileView);

            try
            {
                if (toDelete.file is MyFile)
                {
                    File.Delete((toDelete.file as MyFile).Path);
                }
                else if (toDelete.file is MyDirectory)
                {
                    Directory.Delete((toDelete.file as MyDirectory).Path);
                }
                MessageBox.Show("Deleted");
            }catch (NullReferenceException nEx)
            {
                return;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }