Click here to Skip to main content
15,893,588 members
Articles / Desktop Programming / WPF

Zip My Code

Rate me:
Please Sign up or sign in to vote.
4.78/5 (17 votes)
20 Dec 2009CPOL3 min read 72K   2K   48  
A utility stripping your source code to the essential core and then compressing it to a nice CodeProject article attachment.
using System;
using System.Windows.Forms;
using FormsFolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog;

namespace ZipMyCode.Service.FrameworkDialogs.FolderBrowse
{
	/// <summary>
	/// Class wrapping System.Windows.Forms.FolderBrowserDialog, making it accept a ViewModel.
	/// </summary>
	class FolderBrowserDialog : IDisposable
	{
		private FormsFolderBrowserDialog folderBrowserDialog;
		private FolderBrowserDialogViewModel viewModel;


		/// <summary>
		/// Initializes a new instance of the <see cref="FolderBrowserDialog"/> class.
		/// </summary>
		/// <param name="viewModel">The ViewModel representing the folder browser dialog.</param>
		public FolderBrowserDialog(FolderBrowserDialogViewModel viewModel)
		{
			this.viewModel = viewModel;

			// Create FolderBrowserDialog
			folderBrowserDialog = new FormsFolderBrowserDialog
			{
				Description = viewModel.Description,
				SelectedPath = viewModel.SelectedPath,
				ShowNewFolderButton = viewModel.ShowNewFolderButton
			};
		}


		/// <summary>
		/// Runs a common dialog box with the specified owner.
		/// </summary>
		/// <param name="owner">
		/// Any object that implements System.Windows.Forms.IWin32Window that represents the top-level
		/// window that will own the modal dialog box.
		/// </param>
		/// <returns>
		/// System.Windows.Forms.DialogResult.OK if the user clicks OK in the dialog box; otherwise,
		/// System.Windows.Forms.DialogResult.Cancel.
		/// </returns>
		public DialogResult ShowDialog(IWin32Window owner)
		{
			DialogResult result = folderBrowserDialog.ShowDialog(owner);

			// Update ViewModel
			viewModel.SelectedPath = folderBrowserDialog.SelectedPath;

			return result;
		}


		#region IDisposable Members

		/// <summary>
		/// Performs application-defined tasks associated with freeing, releasing, or resetting
		/// unmanaged resources.
		/// </summary>
		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
		}


		~FolderBrowserDialog()
		{
			Dispose(false);
		}


		protected virtual void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (folderBrowserDialog != null)
				{
					folderBrowserDialog.Dispose();
					folderBrowserDialog = null;
				}
			}
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Axis Communications
Sweden Sweden
Got my first computer in the 90's and loved it even though it sounded like a coffeemaker.

Now getting paid for designing cool applications, and drinks the coffee instead of listening to it being made.

Comments and Discussions