home *** CD-ROM | disk | FTP | other *** search
Text File | 2002-02-04 | 41.8 KB | 1,240 lines |
- /*
- * Xceed Zip for .NET - MiniExplorer Sample Application
- * Copyright (c) 2000-2002 - Xceed Software Inc.
- *
- * [MiniExplorer.cs]
- *
- * This application demonstrates how to use the Xceed FileSystem object model
- * in a generic way.
- *
- * This file is part of Xceed Zip for .NET. The source code in this file
- * is only intended as a supplement to the documentation, and is provided
- * "as is", without warranty of any kind, either expressed or implied.
- */
-
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using Xceed.FileSystem;
- using Xceed.Zip;
-
- namespace Xceed.FileSystem.Samples.MiniExplorer
- {
- /// <summary>
- /// Summary description for MiniExplorer.
- /// </summary>
- public class MiniExplorer : System.Windows.Forms.Form
- {
- private System.Windows.Forms.TreeView FolderTree;
- private System.Windows.Forms.ListView FileList;
- private System.Windows.Forms.ColumnHeader FileListColName;
- private System.Windows.Forms.ColumnHeader FileListColSize;
- private System.Windows.Forms.ColumnHeader FileListColAttributes;
- private System.Windows.Forms.ListBox ResultList;
- private System.Windows.Forms.MainMenu MiniExplorerMenu;
- private System.Windows.Forms.MenuItem FileMenu;
- private System.Windows.Forms.MenuItem EditMenu;
- private System.Windows.Forms.MenuItem HelpMenu;
- private System.Windows.Forms.MenuItem HelpAboutMenu;
- private System.Windows.Forms.MenuItem FileQuitMenu;
- private System.Windows.Forms.MenuItem EditDeleteMenu;
- private System.Windows.Forms.Splitter splitter1;
- private System.Windows.Forms.Splitter splitter2;
- private System.Windows.Forms.Panel ProgressPanel;
- private System.Windows.Forms.MenuItem EditNewMenu;
- private System.Windows.Forms.MenuItem EditNewFolderMenu;
- private System.ComponentModel.IContainer components;
- private System.Windows.Forms.ProgressBar CurrentProgressBar;
- private System.Windows.Forms.ProgressBar AllProgressBar;
- private System.Windows.Forms.ImageList FileSystemItemImages;
- private System.Windows.Forms.MenuItem EditNewFileMenu;
- private System.Windows.Forms.MenuItem EditCopyMenu;
- private System.Windows.Forms.MenuItem EditCutMenu;
- private System.Windows.Forms.MenuItem EditPasteMenu;
- private System.Windows.Forms.MenuItem menuItem5;
- private System.Windows.Forms.MenuItem EditRefreshMenu;
- private System.Windows.Forms.MenuItem menuItem1;
- private System.Windows.Forms.MenuItem EditRenameMenu;
-
- public MiniExplorer()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
-
- // Retrieve all available disk drives
- string[] drives = System.IO.Directory.GetLogicalDrives();
-
- foreach( string drive in drives )
- {
- FolderTreeNode folder = new FolderTreeNode( new DiskFolder( drive ), drive );
- FolderTree.Nodes.Add( folder );
- }
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MiniExplorer));
- this.FolderTree = new System.Windows.Forms.TreeView();
- this.FileSystemItemImages = new System.Windows.Forms.ImageList(this.components);
- this.FileList = new System.Windows.Forms.ListView();
- this.FileListColName = new System.Windows.Forms.ColumnHeader();
- this.FileListColSize = new System.Windows.Forms.ColumnHeader();
- this.FileListColAttributes = new System.Windows.Forms.ColumnHeader();
- this.ResultList = new System.Windows.Forms.ListBox();
- this.MiniExplorerMenu = new System.Windows.Forms.MainMenu();
- this.FileMenu = new System.Windows.Forms.MenuItem();
- this.FileQuitMenu = new System.Windows.Forms.MenuItem();
- this.EditMenu = new System.Windows.Forms.MenuItem();
- this.EditCutMenu = new System.Windows.Forms.MenuItem();
- this.EditCopyMenu = new System.Windows.Forms.MenuItem();
- this.EditPasteMenu = new System.Windows.Forms.MenuItem();
- this.menuItem5 = new System.Windows.Forms.MenuItem();
- this.EditNewMenu = new System.Windows.Forms.MenuItem();
- this.EditNewFolderMenu = new System.Windows.Forms.MenuItem();
- this.EditNewFileMenu = new System.Windows.Forms.MenuItem();
- this.EditRenameMenu = new System.Windows.Forms.MenuItem();
- this.EditDeleteMenu = new System.Windows.Forms.MenuItem();
- this.menuItem1 = new System.Windows.Forms.MenuItem();
- this.EditRefreshMenu = new System.Windows.Forms.MenuItem();
- this.HelpMenu = new System.Windows.Forms.MenuItem();
- this.HelpAboutMenu = new System.Windows.Forms.MenuItem();
- this.splitter1 = new System.Windows.Forms.Splitter();
- this.splitter2 = new System.Windows.Forms.Splitter();
- this.ProgressPanel = new System.Windows.Forms.Panel();
- this.CurrentProgressBar = new System.Windows.Forms.ProgressBar();
- this.AllProgressBar = new System.Windows.Forms.ProgressBar();
- this.ProgressPanel.SuspendLayout();
- this.SuspendLayout();
- //
- // FolderTree
- //
- this.FolderTree.AllowDrop = true;
- this.FolderTree.Dock = System.Windows.Forms.DockStyle.Left;
- this.FolderTree.HideSelection = false;
- this.FolderTree.ImageIndex = 1;
- this.FolderTree.ImageList = this.FileSystemItemImages;
- this.FolderTree.LabelEdit = true;
- this.FolderTree.Name = "FolderTree";
- this.FolderTree.Size = new System.Drawing.Size(200, 363);
- this.FolderTree.TabIndex = 0;
- this.FolderTree.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FolderTree_KeyDown);
- this.FolderTree.DragOver += new System.Windows.Forms.DragEventHandler(this.FolderTree_DragOver);
- this.FolderTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.FolderTree_AfterSelect);
- this.FolderTree.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(this.FolderTree_AfterLabelEdit);
- this.FolderTree.Leave += new System.EventHandler(this.FolderTree_Leave);
- this.FolderTree.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.FolderTree_BeforeExpand);
- this.FolderTree.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.FolderTree_ItemDrag);
- this.FolderTree.DragLeave += new System.EventHandler(this.FolderTree_DragLeave);
- this.FolderTree.DragDrop += new System.Windows.Forms.DragEventHandler(this.FolderTree_DragDrop);
- this.FolderTree.Enter += new System.EventHandler(this.FolderTree_Enter);
- //
- // FileSystemItemImages
- //
- this.FileSystemItemImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
- this.FileSystemItemImages.ImageSize = new System.Drawing.Size(16, 16);
- this.FileSystemItemImages.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("FileSystemItemImages.ImageStream")));
- this.FileSystemItemImages.TransparentColor = System.Drawing.Color.White;
- //
- // FileList
- //
- this.FileList.AllowDrop = true;
- this.FileList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.FileListColName,
- this.FileListColSize,
- this.FileListColAttributes});
- this.FileList.Dock = System.Windows.Forms.DockStyle.Fill;
- this.FileList.FullRowSelect = true;
- this.FileList.HideSelection = false;
- this.FileList.LabelEdit = true;
- this.FileList.Location = new System.Drawing.Point(203, 0);
- this.FileList.Name = "FileList";
- this.FileList.Size = new System.Drawing.Size(485, 363);
- this.FileList.SmallImageList = this.FileSystemItemImages;
- this.FileList.TabIndex = 2;
- this.FileList.View = System.Windows.Forms.View.Details;
- this.FileList.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FileList_KeyDown);
- this.FileList.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.FileList_AfterLabelEdit);
- this.FileList.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.FileList_ItemDrag);
- //
- // FileListColName
- //
- this.FileListColName.Text = "Name";
- this.FileListColName.Width = 285;
- //
- // FileListColSize
- //
- this.FileListColSize.Text = "Size";
- //
- // FileListColAttributes
- //
- this.FileListColAttributes.Text = "Attributes";
- this.FileListColAttributes.Width = 85;
- //
- // ResultList
- //
- this.ResultList.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.ResultList.Location = new System.Drawing.Point(0, 366);
- this.ResultList.Name = "ResultList";
- this.ResultList.Size = new System.Drawing.Size(688, 69);
- this.ResultList.TabIndex = 3;
- //
- // MiniExplorerMenu
- //
- this.MiniExplorerMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.FileMenu,
- this.EditMenu,
- this.HelpMenu});
- //
- // FileMenu
- //
- this.FileMenu.Index = 0;
- this.FileMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.FileQuitMenu});
- this.FileMenu.Text = "&File";
- //
- // FileQuitMenu
- //
- this.FileQuitMenu.Index = 0;
- this.FileQuitMenu.Text = "&Quit";
- this.FileQuitMenu.Click += new System.EventHandler(this.FileQuitMenu_Click);
- //
- // EditMenu
- //
- this.EditMenu.Index = 1;
- this.EditMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.EditCutMenu,
- this.EditCopyMenu,
- this.EditPasteMenu,
- this.menuItem5,
- this.EditNewMenu,
- this.EditRenameMenu,
- this.EditDeleteMenu,
- this.menuItem1,
- this.EditRefreshMenu});
- this.EditMenu.Text = "&Edit";
- //
- // EditCutMenu
- //
- this.EditCutMenu.Index = 0;
- this.EditCutMenu.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
- this.EditCutMenu.Text = "C&ut";
- this.EditCutMenu.Click += new System.EventHandler(this.EditCutMenu_Click);
- //
- // EditCopyMenu
- //
- this.EditCopyMenu.Index = 1;
- this.EditCopyMenu.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
- this.EditCopyMenu.Text = "C&opy";
- this.EditCopyMenu.Click += new System.EventHandler(this.EditCopyMenu_Click);
- //
- // EditPasteMenu
- //
- this.EditPasteMenu.Index = 2;
- this.EditPasteMenu.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
- this.EditPasteMenu.Text = "&Paste";
- this.EditPasteMenu.Click += new System.EventHandler(this.EditPasteMenu_Click);
- //
- // menuItem5
- //
- this.menuItem5.Index = 3;
- this.menuItem5.Text = "-";
- //
- // EditNewMenu
- //
- this.EditNewMenu.Index = 4;
- this.EditNewMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.EditNewFolderMenu,
- this.EditNewFileMenu});
- this.EditNewMenu.Text = "&New";
- //
- // EditNewFolderMenu
- //
- this.EditNewFolderMenu.Index = 0;
- this.EditNewFolderMenu.Text = "&Folder...";
- this.EditNewFolderMenu.Click += new System.EventHandler(this.FileNewFolderMenu_Click);
- //
- // EditNewFileMenu
- //
- this.EditNewFileMenu.Index = 1;
- this.EditNewFileMenu.Text = "Fil&e...";
- this.EditNewFileMenu.Click += new System.EventHandler(this.EditNewFileMenu_Click);
- //
- // EditRenameMenu
- //
- this.EditRenameMenu.Index = 5;
- this.EditRenameMenu.Shortcut = System.Windows.Forms.Shortcut.F2;
- this.EditRenameMenu.Text = "&Rename";
- this.EditRenameMenu.Click += new System.EventHandler(this.EditRenameMenu_Click);
- //
- // EditDeleteMenu
- //
- this.EditDeleteMenu.Index = 6;
- this.EditDeleteMenu.Shortcut = System.Windows.Forms.Shortcut.Del;
- this.EditDeleteMenu.Text = "&Delete";
- this.EditDeleteMenu.Click += new System.EventHandler(this.EditDeleteMenu_Click);
- //
- // menuItem1
- //
- this.menuItem1.Index = 7;
- this.menuItem1.Text = "-";
- //
- // EditRefreshMenu
- //
- this.EditRefreshMenu.Index = 8;
- this.EditRefreshMenu.Shortcut = System.Windows.Forms.Shortcut.F5;
- this.EditRefreshMenu.Text = "R&efresh";
- this.EditRefreshMenu.Click += new System.EventHandler(this.EditRefreshMenu_Click);
- //
- // HelpMenu
- //
- this.HelpMenu.Index = 2;
- this.HelpMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
- this.HelpAboutMenu});
- this.HelpMenu.Text = "&Help";
- //
- // HelpAboutMenu
- //
- this.HelpAboutMenu.Index = 0;
- this.HelpAboutMenu.Text = "&About MiniExplorer";
- this.HelpAboutMenu.Click += new System.EventHandler(this.HelpAboutMenu_Click);
- //
- // splitter1
- //
- this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.splitter1.Location = new System.Drawing.Point(0, 363);
- this.splitter1.Name = "splitter1";
- this.splitter1.Size = new System.Drawing.Size(688, 3);
- this.splitter1.TabIndex = 7;
- this.splitter1.TabStop = false;
- //
- // splitter2
- //
- this.splitter2.Location = new System.Drawing.Point(200, 0);
- this.splitter2.Name = "splitter2";
- this.splitter2.Size = new System.Drawing.Size(3, 363);
- this.splitter2.TabIndex = 8;
- this.splitter2.TabStop = false;
- //
- // ProgressPanel
- //
- this.ProgressPanel.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.CurrentProgressBar,
- this.AllProgressBar});
- this.ProgressPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.ProgressPanel.Location = new System.Drawing.Point(0, 435);
- this.ProgressPanel.Name = "ProgressPanel";
- this.ProgressPanel.Size = new System.Drawing.Size(688, 16);
- this.ProgressPanel.TabIndex = 9;
- //
- // CurrentProgressBar
- //
- this.CurrentProgressBar.Dock = System.Windows.Forms.DockStyle.Left;
- this.CurrentProgressBar.Name = "CurrentProgressBar";
- this.CurrentProgressBar.Size = new System.Drawing.Size(192, 16);
- this.CurrentProgressBar.TabIndex = 8;
- //
- // AllProgressBar
- //
- this.AllProgressBar.Dock = System.Windows.Forms.DockStyle.Fill;
- this.AllProgressBar.Name = "AllProgressBar";
- this.AllProgressBar.Size = new System.Drawing.Size(688, 16);
- this.AllProgressBar.TabIndex = 7;
- //
- // MiniExplorer
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(688, 451);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.FileList,
- this.splitter2,
- this.FolderTree,
- this.splitter1,
- this.ResultList,
- this.ProgressPanel});
- this.Menu = this.MiniExplorerMenu;
- this.Name = "MiniExplorer";
- this.Text = "Xceed MiniExplorer";
- this.Load += new System.EventHandler(this.MiniExplorer_Load);
- this.ProgressPanel.ResumeLayout(false);
- this.ResumeLayout(false);
-
- }
- #endregion
-
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new MiniExplorer());
- }
-
- #region FOLDERTREE EVENTS
-
- private void FolderTree_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e)
- {
- FillFolderTree( ( FolderTreeNode )e.Node );
- }
-
- private void FolderTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
- {
- FillFileList( ( FolderTreeNode ) e.Node );
- }
-
- private void FolderTree_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)
- {
- // We always remove the node that was used to rename this new folder.
- FolderTreeNode node = ( FolderTreeNode )e.Node.Parent;
-
- if( !e.CancelEdit && e.Label != null )
- {
- try
- {
- if( node.Folder.GetFolder( e.Label ).Exists )
- {
- MessageBox.Show( "This folder already exists", "Error creating folder",
- MessageBoxButtons.OK, MessageBoxIcon.Error );
- e.CancelEdit = true;
- e.Node.BeginEdit();
- return;
- }
-
- if( ( ( FolderTreeNode )e.Node ).Folder == null )
- {
- // Create the REAL folder and the node for it.
- AbstractFolder newFolder = node.Folder.CreateFolder( e.Label );
- FolderTreeNode newNode = new FolderTreeNode( newFolder, e.Label );
-
- node.Nodes.Add( newNode );
- }
- else
- {
- // Rename
- ( ( FolderTreeNode )e.Node ).Folder.Name = e.Label;
- }
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
-
- // We remove the dummy node only at the very end
- if( e.Node is FolderTreeNode )
- {
- if( ( ( FolderTreeNode )e.Node ).Folder == null )
- {
- // This was a new folder and not a rename.
- e.Node.Remove();
- }
- }
- }
-
- private void FolderTree_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
- {
- ResultList.Items.Clear();
-
- DataObject data = new DataObject();
- data.SetData( typeof( FolderTreeNode ), e.Item );
- DoDragDrop( data, DragDropEffects.Copy | DragDropEffects.Move );
- }
-
- private void FolderTree_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
- {
- TreeNode node = FolderTree.GetNodeAt( this.PointToClient( new Point( e.X, e.Y ) ) );
- AbstractFolder sourceFolder = null;
-
- e.Effect = DragDropEffects.None;
-
- // We don't allow to drop the file/folder in the source folder
- // Check for this.
- if( e.Data.GetDataPresent( typeof( FolderTreeNode ) ) )
- {
- // Copy/move the folder. The source folder is provided in e.Data
- sourceFolder = ( ( FolderTreeNode )e.Data.GetData( typeof( FolderTreeNode ) ) ).Folder;
- }
- else
- {
- // Copy/move the file(s). The source folder is the selected one.
- sourceFolder = ( ( FolderTreeNode ) FolderTree.SelectedNode ).Folder;
- }
-
- if( node != null && !( ( FolderTreeNode )node ).Folder.Equals( sourceFolder ) )
- {
- if( !node.Equals( m_previousDropNode ) )
- {
- HighlightDropInNode( node );
- }
-
- if( ( e.KeyState & 4 ) > 0 && ( e.AllowedEffect & DragDropEffects.Move ) > 0 )
- e.Effect = DragDropEffects.Move;
- else if( ( e.AllowedEffect & DragDropEffects.Copy ) > 0 )
- e.Effect = DragDropEffects.Copy;
- }
- }
-
- private void FolderTree_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.GetNodeAt( PointToClient( new Point( e.X, e.Y ) ) );
-
- HighlightDropInNode( null );
-
- try
- {
- if( e.Effect == DragDropEffects.Copy )
- {
- PasteFromDataObject( node, e.Data, false );
- }
- else if( e.Effect == DragDropEffects.Move )
- {
- PasteFromDataObject( node, e.Data, true );
- }
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
-
- private void FolderTree_DragLeave(object sender, System.EventArgs e)
- {
- HighlightDropInNode( null );
- }
-
- private void FolderTree_Enter(object sender, System.EventArgs e)
- {
- EditNewFolderMenu.Enabled = true;
- }
-
- private void FolderTree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- // Check if only the Ctrl key is pressed
- if( e.Modifiers == Keys.Control )
- {
- switch( e.KeyCode )
- {
- case Keys.Insert:
- CopyFolderInClipboard( false );
- break;
- }
- }
-
- // Check if only the Shift key is pressed
- if( e.Modifiers == Keys.Shift )
- {
- switch( e.KeyCode )
- {
- case Keys.Insert:
- PasteFromClipboard();
- break;
-
- case Keys.Delete:
- CopyFolderInClipboard( true );
- break;
- }
- }
- }
-
- private void FolderTree_Leave(object sender, System.EventArgs e)
- {
- EditNewFolderMenu.Enabled = false;
- }
-
- #endregion FOLDERTREE EVENTS
-
- #region FILELIST EVENTS
-
- private void FileList_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e)
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.SelectedNode;
-
- // Check if the file already exists
- if( e.Label != null )
- {
- if( node.Folder.GetFile( e.Label ).Exists )
- {
- MessageBox.Show( "This file already exists", "Error creating file",
- MessageBoxButtons.OK, MessageBoxIcon.Error );
- e.CancelEdit = true;
- FileList.Items[ e.Item ].BeginEdit();
- return;
- }
- }
-
- if( !e.CancelEdit && e.Label != null )
- {
- try
- {
- if( ( ( FileListItem ) FileList.Items[ e.Item ] ).File == null )
- {
- // We always remove the node that was used to rename this new zip file.
- FileList.Items[ e.Item ].Remove();
-
- AbstractFile newFile = node.Folder.CreateFile( e.Label, false );
- FileListItem newItem = new FileListItem( newFile );
-
- FileList.Items.Add( newItem );
- }
- else
- {
- // Rename
- ( ( FileListItem ) FileList.Items[ e.Item ] ).File.Name = e.Label;
- }
-
- // We must also refresh the FolderTree since this file may end by ".zip"
- RefreshFolderTree( node );
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
-
- private void FileList_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
- {
- AbstractFile[] files = new AbstractFile[ FileList.SelectedItems.Count ];
- int index = 0;
-
- foreach( FileListItem item in FileList.SelectedItems )
- {
- files[ index++ ] = item.File;
- ResultList.Items.Add( "Dragging " + item.File.FullName );
- }
-
- DataObject data = new DataObject( files );
- DoDragDrop( data, DragDropEffects.Copy | DragDropEffects.Move );
- }
-
-
- private void FileList_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
- {
- // Check if only the Ctrl key is pressed
- if( e.Modifiers == Keys.Control )
- {
- switch( e.KeyCode )
- {
- case Keys.Insert:
- CopyFilesInClipboard( false );
- break;
- }
- }
-
- // Check if only the Shift key is pressed
- if( e.Modifiers == Keys.Shift )
- {
- switch( e.KeyCode )
- {
- case Keys.Insert:
- PasteFromClipboard();
- break;
-
- case Keys.Delete:
- CopyFilesInClipboard( true );
- break;
- }
- }
- }
- #endregion FILELIST EVENTS
-
- #region MENU EVENTS
-
- private void EditCutMenu_Click(object sender, System.EventArgs e)
- {
- if( FolderTree.Focused )
- {
- CopyFolderInClipboard( true );
- }
- else
- {
- if( FileList.Focused )
- {
- CopyFilesInClipboard( true );
- }
- }
- }
-
- private void EditCopyMenu_Click(object sender, System.EventArgs e)
- {
- if( FolderTree.Focused )
- {
- CopyFolderInClipboard( false );
- }
- else
- {
- if( FileList.Focused )
- {
- CopyFilesInClipboard( false);
- }
- }
- }
-
- private void EditPasteMenu_Click(object sender, System.EventArgs e)
- {
- PasteFromClipboard();
- }
-
- private void EditDeleteMenu_Click(object sender, System.EventArgs e)
- {
- if( FolderTree.Focused )
- {
- DeleteCurrentFolder();
- }
- else
- {
- if( FileList.Focused )
- {
- DeleteCurrentFile();
- }
- }
- }
-
- private void EditNewFileMenu_Click(object sender, System.EventArgs e)
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.SelectedNode;
-
- if( node != null )
- {
- FileListItem newFile = new FileListItem( "New file.zip" );
- FileList.Items.Add( newFile );
-
- newFile.BeginEdit();
- }
- }
-
- private void EditRefreshMenu_Click(object sender, System.EventArgs e)
- {
- FillFileList( ( FolderTreeNode )FolderTree.SelectedNode );
- }
-
- private void EditRenameMenu_Click(object sender, System.EventArgs e)
- {
- if( FolderTree.Focused )
- {
- RenameCurrentFolder();
- }
- else
- {
- if( FileList.Focused )
- {
- RenameCurrentFile();
- }
- }
- }
-
- private void FileNewFolderMenu_Click(object sender, System.EventArgs e)
- {
- if( FolderTree.Focused )
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.SelectedNode;
-
- if( node != null )
- {
- node.Expand();
-
- FolderTreeNode newFolder = new FolderTreeNode( "New folder" );
- node.Nodes.Add( newFolder );
-
- // Expand again, without refreshing view, if newly added item is alone
- if( node.Nodes.Count == 1 )
- {
- m_preventTreeUpdate = true;
- node.Expand();
- m_preventTreeUpdate = false;
- }
-
- newFolder.BeginEdit();
- }
- }
- }
-
- private void FileQuitMenu_Click(object sender, System.EventArgs e)
- {
- this.Close();
- }
-
- private void HelpAboutMenu_Click(object sender, System.EventArgs e)
- {
- MessageBox.Show("Xceed Zip for .NET - MiniExplorer Sample Application\n" +
- "Written in C#\n" +
- "Copyrights (c) 2001 - Xceed Software Inc.",
- "About MiniExplorer...", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
-
- #endregion MENU EVENTS
-
- #region FILESYSTEM EVENTS
-
- private void m_fileSystemEvents_ByteProgression(object sender, Xceed.FileSystem.ByteProgressionEventArgs e)
- {
- CurrentProgressBar.Value = e.CurrentFileBytes.Percent;
- AllProgressBar.Value = e.AllFilesBytes.Percent;
-
- if( e.AllFilesBytes.Percent == 100 )
- {
- CurrentProgressBar.Value = 0;
- AllProgressBar.Value = 0;
- }
- }
-
- private void m_fileSystemEvents_ItemException(object sender, Xceed.FileSystem.ItemExceptionEventArgs e)
- {
- if( e.Exception is InvalidDecryptionPasswordException )
- {
- try
- {
- ZipArchive rootZip = ( ZipArchive )( ( ZippedFile )e.CurrentItem ).RootFolder;
- if( m_currentPassword == rootZip.DefaultDecryptionPassword )
- {
- PasswordForm passwordDialog = new PasswordForm();
-
- if( passwordDialog.ShowDialog( this, e.CurrentItem.FullName, ref m_currentPassword ) == DialogResult.OK )
- {
- rootZip.DefaultDecryptionPassword = m_currentPassword;
- e.Action = ItemExceptionAction.Retry;
- }
- }
- else
- {
- rootZip.DefaultDecryptionPassword = m_currentPassword;
- e.Action = ItemExceptionAction.Retry;
- }
- }
- catch( Exception except )
- {
- System.Diagnostics.Debug.WriteLine( except.Message );
- }
- }
- else
- {
- DialogResult answer = MessageBox.Show(
- e.Exception.Message + "\n" + "\nWhat do you wish to do?", e.Exception.GetType().ToString() + "...",
- MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question );
-
- switch( answer )
- {
- case DialogResult.Abort:
- e.Action = ItemExceptionAction.Abort;
- break;
-
- case DialogResult.Retry:
- e.Action = ItemExceptionAction.Retry;
- break;
-
- case DialogResult.Ignore:
- e.Action = ItemExceptionAction.Ignore;
- break;
- }
- }
- }
-
- #endregion FILESYSTEM EVENTS
-
- #region FORM EVENTS
-
- private void MiniExplorer_Load(object sender, System.EventArgs e)
- {
- m_fileSystemEvents = new FileSystemEvents();
- m_fileSystemEvents.ByteProgression += new ByteProgressionEventHandler( m_fileSystemEvents_ByteProgression );
- m_fileSystemEvents.ItemException += new ItemExceptionEventHandler( m_fileSystemEvents_ItemException );
- }
-
- #endregion FORM EVENTS
-
- #region PRIVATE METHODS
-
- private void CopyFolderInClipboard( bool cut )
- {
- m_Clipboard = new DataObject();
-
- m_Clipboard.SetData( typeof( FolderTreeNode ), ( FolderTreeNode )FolderTree.SelectedNode );
- // As a goodie, we provide a textual representation of the Folder in the Clipboard
- m_Clipboard.SetData( DataFormats.Text, ( ( FolderTreeNode )FolderTree.SelectedNode ).Folder.FullName );
- System.Windows.Forms.Clipboard.SetDataObject( m_Clipboard );
-
- m_cutClipboard = cut;
- }
-
- private void CopyFilesInClipboard( bool cut )
- {
- AbstractFile[] files = new AbstractFile[ FileList.SelectedItems.Count ];
- int index = 0;
- System.Text.StringBuilder textContent = new System.Text.StringBuilder();
-
- foreach( FileListItem item in FileList.SelectedItems )
- {
- files[ index++ ] = item.File;
- // As a goodie, we provide a textual representation of each selected file in the Clipboard
- textContent.Append( item.File.FullName + "\r\n" );
- }
-
- m_Clipboard = new DataObject();
-
- m_Clipboard.SetData( typeof( AbstractFile[] ), files );
- m_Clipboard.SetData( DataFormats.Text, textContent );
- Clipboard.SetDataObject( m_Clipboard );
-
- m_cutClipboard = cut;
- }
-
- private void PasteFromClipboard()
- {
- if( FolderTree.Focused || FileList.Focused )
- {
- // We use the m_Clipboard object because of a bug in the Clipboard.GetDataObject().
- PasteFromDataObject( ( FolderTreeNode )FolderTree.SelectedNode, m_Clipboard, m_cutClipboard );
-
- // The potential following "pastes" shall not "cut"
- m_cutClipboard = false;
- }
- }
-
- private void PasteFromDataObject( FolderTreeNode destinationNode, IDataObject dataObject, bool move )
- {
- if( move )
- {
- ResultList.Items.Add( "Moving to folder " + destinationNode.Folder.FullName + "..." );
- }
- else
- {
- ResultList.Items.Add( "Copying to folder " + destinationNode.Folder.FullName + "..." );
- }
-
- IBatchUpdateable batch = destinationNode.Folder.RootFolder as IBatchUpdateable;
-
- Cursor.Current = Cursors.WaitCursor;
- if( batch != null )
- batch.BeginUpdate();
-
- try
- {
- if( dataObject.GetDataPresent( typeof( FolderTreeNode ) ) )
- {
- FolderTreeNode sourceNode = ( FolderTreeNode )dataObject.GetData( typeof( FolderTreeNode ) );
- AbstractFolder folder = sourceNode.Folder;
-
- ResultList.Items.Add( " folder " + folder.FullName );
-
- if( move )
- {
- folder.MoveTo( m_fileSystemEvents, null, destinationNode.Folder, false);
- // We just moved the folder. Refresh its (previous) parent.
- RefreshFolderTree( ( FolderTreeNode )sourceNode.Parent );
- }
- else
- {
- folder.CopyTo( m_fileSystemEvents, null, destinationNode.Folder, false );
- }
- }
- else if( dataObject.GetDataPresent( typeof( AbstractFile[] ) ) )
- {
- foreach( AbstractFile file in ( AbstractFile[] )dataObject.GetData( typeof( AbstractFile[] ) ) )
- {
- ResultList.Items.Add( " file " + file.FullName );
- if( move )
- {
- file.MoveTo( m_fileSystemEvents, null, destinationNode.Folder, true );
- }
- else
- {
- file.CopyTo( m_fileSystemEvents, null, destinationNode.Folder, true );
- }
- }
- }
- else
- {
- ResultList.Items.Add( "Unknown data type." );
- }
- }
- finally
- {
- if( batch != null )
- batch.EndUpdate();
- }
-
- Cursor.Current = Cursors.Default;
- RefreshFolderTree( destinationNode );
- FillFileList( ( FolderTreeNode )FolderTree.SelectedNode );
- }
-
- private void RefreshFolderTree( FolderTreeNode rootNode )
- {
- if( rootNode.IsExpanded )
- {
- rootNode.Collapse();
- rootNode.Expand();
- }
- }
-
- private void RenameCurrentFolder()
- {
- if( FolderTree.SelectedNode != null )
- {
- FolderTree.SelectedNode.BeginEdit();
- }
- }
-
- private void RenameCurrentFile()
- {
- if( FileList.SelectedItems.Count > 0 )
- {
- FileList.SelectedItems[ 0 ].BeginEdit();
- }
- }
-
- private void FillFolderTree( FolderTreeNode node )
- {
- if( !m_preventTreeUpdate )
- {
- Cursor.Current = Cursors.WaitCursor;
- node.Nodes.Clear();
-
- try
- {
- // We want to display zip files as folders
- foreach( AbstractFile file in node.Folder.GetFiles( false, "*.zip" ) )
- {
- try
- {
- FolderTreeNode sub = new FolderTreeNode( new ZipArchive( file ), file.Name );
- sub.ForeColor = Color.Green;
- node.Nodes.Add( sub );
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
-
- try
- {
- // We must not forget normal folders
- foreach( AbstractFolder folder in node.Folder.GetFolders( false ) )
- {
- try
- {
- FolderTreeNode sub = new FolderTreeNode( folder, folder.Name );
- node.Nodes.Add( sub );
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
-
- Cursor.Current = Cursors.Default;
- }
- }
-
- private void FillFileList( FolderTreeNode node )
- {
- FileList.Items.Clear();
-
- if( node != null )
- {
- Cursor.Current = Cursors.WaitCursor;
-
- try
- {
- foreach( AbstractFile file in node.Folder.GetFiles( false ) )
- {
- try
- {
- FileListItem item = new FileListItem( file );
- FileList.Items.Add( item );
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
-
- Cursor.Current = Cursors.Default;
- }
- }
-
- private void HighlightDropInNode( TreeNode node )
- {
- if( node != null )
- {
- node.BackColor = Color.FromKnownColor( KnownColor.Highlight );
- node.ForeColor = Color.FromKnownColor( KnownColor.HighlightText );
- }
-
- if( m_previousDropNode != null )
- {
- if( ( ( FolderTreeNode )m_previousDropNode ).Folder is ZipArchive )
- {
- m_previousDropNode.BackColor = Color.FromKnownColor( KnownColor.Window );
- m_previousDropNode.ForeColor = Color.Green;
- }
- else
- {
- m_previousDropNode.BackColor = Color.FromKnownColor( KnownColor.Window );
- m_previousDropNode.ForeColor = Color.FromKnownColor( KnownColor.WindowText );
- }
- }
-
- m_previousDropNode = node;
- }
-
- private void DeleteCurrentFolder()
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.SelectedNode;
-
- if( node != null )
- {
- string folderName = string.Empty;
-
- if( node.Folder is ZipArchive )
- {
- // The name of the "folder" is the name of the zip file
- folderName = ( ( ZipArchive )node.Folder ).ZipFile.FullName;
- }
- else
- {
- folderName = node.Folder.FullName;
- }
-
- DialogResult result = MessageBox.Show(
- "Please confirm you wish to delete the following folder:\n" + folderName,
- "Deleting folder...", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
-
- if( result == DialogResult.Yes )
- {
- try
- {
- if( node.Folder is ZipArchive )
- {
- // Delete the zip file
- ( ( ZipArchive )node.Folder ).ZipFile.Delete( m_fileSystemEvents, null );
- }
- else
- {
- // Delete the folder
- node.Folder.Delete( m_fileSystemEvents, null );
- }
-
- node.Remove();
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
- }
-
- private void DeleteCurrentFile()
- {
- DialogResult result = DialogResult.No;
-
- if( FileList.SelectedItems.Count == 1 )
- {
- FileListItem item = ( FileListItem )FileList.SelectedItems[ 0 ];
-
- result = MessageBox.Show(
- "Please confirm you wish to delete the following file:\n" + item.File.FullName,
- "Deleting file...", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
- }
- else if( FileList.SelectedItems.Count > 1 )
- {
- result = MessageBox.Show(
- "Please confirm you wish to delete all selected files.",
- "Deleting files...", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
- }
-
- if( result == DialogResult.Yes )
- {
- FolderTreeNode node = ( FolderTreeNode )FolderTree.SelectedNode;
-
- IBatchUpdateable batch = node.Folder.RootFolder as IBatchUpdateable;
-
- if( batch != null )
- batch.BeginUpdate();
-
- try
- {
- foreach( FileListItem item in FileList.SelectedItems )
- {
- try
- {
- item.File.Delete( m_fileSystemEvents, null );
-
- // We delete the file entry in the list view
- FileList.Items.Remove( item );
- }
- catch( Exception except )
- {
- ResultList.Items.Add( except.Message );
- }
- }
- }
- finally
- {
- if( batch != null )
- batch.EndUpdate();
-
- // We must update the FolderTree since we may have deleted zip files.
- RefreshFolderTree( node );
- }
- }
- }
-
- #endregion PRIVATE METHODS
-
- #region PRIVATE FIELDS
-
- private bool m_preventTreeUpdate = false;
- private TreeNode m_previousDropNode = null;
- private DataObject m_Clipboard = null;
- private bool m_cutClipboard = false;
- private FileSystemEvents m_fileSystemEvents = null;
- private string m_currentPassword = string.Empty;
-
- #endregion PRIVATE FIELDS
- }
- }
-