void InitializeFields(ExtractInterfaceOptions o)
		{
			this.options = o;

			this.txtInterfaceName.Text = o.NewInterfaceName;
			this.txtNewFileName.Text = o.SuggestedFileName;
			this.txtGeneratedName.Text = o.FullyQualifiedName;
			
			IClass c = o.ClassEntity;
			foreach (IMethod m in c.Methods) {
				if (m.IsPublic && !m.IsConstructor && !m.IsConst && !m.IsStatic) {
					this.possibleInterfaceMembers.Add(m);
					this.selectMembersListBox.Items.Add(FormatMemberForDisplay(m), CheckState.Checked);
				}
			}
			foreach (IProperty p in c.Properties) {
				if (p.IsPublic && !p.IsConst && !p.IsStatic) {
					this.possibleInterfaceMembers.Add(p);
					this.selectMembersListBox.Items.Add(FormatMemberForDisplay(p), CheckState.Checked);
				}
			}
			foreach (IEvent classEvent in c.Events) {
				if (classEvent.IsPublic && !classEvent.IsStatic) {
					this.possibleInterfaceMembers.Add(classEvent);
					this.selectMembersListBox.Items.Add(FormatMemberForDisplay(classEvent), CheckState.Checked);
				}
			}
		}
		public static void ExtractInterface(IClass c)
		{
			ExtractInterfaceOptions extractInterface = new ExtractInterfaceOptions(c);
			using (ExtractInterfaceDialog eid = new ExtractInterfaceDialog()) {
				extractInterface = eid.ShowDialog(extractInterface);
				if (extractInterface.IsCancelled) {
					return;
				}
				
				// do rename
				/*
				 MessageService.ShowMessageFormatted("Extracting interface",
				                                    @"Extracting {0} [{1}] from {2} into {3}",
				                                    extractInterface.NewInterfaceName,
				                                    extractInterface.FullyQualifiedName,
				                                    extractInterface.ClassEntity.Name,
				                                    extractInterface.NewFileName
				                                   );
`				*/
			}
			
			string newInterfaceFileName = Path.Combine(Path.GetDirectoryName(c.CompilationUnit.FileName),
			                                           extractInterface.NewFileName);
			if (File.Exists(newInterfaceFileName)) {
				int confirmReplace = MessageService.ShowCustomDialog("Extract Interface",
				                                                     newInterfaceFileName+" already exists!",
				                                                     0,
				                                                     1,
				                                                     "${res:Global.ReplaceButtonText}",
				                                                     "${res:Global.AbortButtonText}");
				if (confirmReplace != 0) {
					return;
				}
			}
			
			LanguageProperties language = c.ProjectContent.Language;
			string classFileName = c.CompilationUnit.FileName;
			string existingClassCode = ParserService.GetParseableFileContent(classFileName).Text;
			
			// build the new interface...
			string newInterfaceCode = language.RefactoringProvider.GenerateInterfaceForClass(extractInterface.NewInterfaceName,
			                                                                                 existingClassCode,
			                                                                                 extractInterface.ChosenMembers,
			                                                                                 c, extractInterface.IncludeComments);
			if (newInterfaceCode == null)
				return;
			
			// ...dump it to a file...
			IViewContent viewContent = FileService.GetOpenFile(newInterfaceFileName);
			ITextEditorProvider editable = viewContent as ITextEditorProvider;
			
			if (viewContent != null && editable != null) {
				// simply update it
				editable.TextEditor.Document.Text = newInterfaceCode;
				viewContent.PrimaryFile.SaveToDisk();
			} else {
				// create it
				viewContent = FileService.NewFile(newInterfaceFileName, newInterfaceCode);
				viewContent.PrimaryFile.SaveToDisk(newInterfaceFileName);

				// ... and add it to the project
				IProject project = (IProject)c.ProjectContent.Project;
				if (project != null) {
					FileProjectItem projectItem = new FileProjectItem(project, ItemType.Compile);
					projectItem.FileName = newInterfaceFileName;
					ProjectService.AddProjectItem(project, projectItem);
					FileService.FireFileCreated(newInterfaceFileName, false);
					project.Save();
					ProjectBrowserPad.RefreshViewAsync();
				}
			}
			
			ICompilationUnit newCompilationUnit = ParserService.ParseFile(newInterfaceFileName).CompilationUnit;
			IClass newInterfaceDef = newCompilationUnit.Classes[0];
			
			// finally, add the interface to the base types of the class that we're extracting from
			if (extractInterface.AddInterfaceToClass) {
				string modifiedClassCode = language.RefactoringProvider.AddBaseTypeToClass(existingClassCode, c, newInterfaceDef);
				if (modifiedClassCode == null) {
					return;
				}
				
				// TODO: replacing the whole text is not an option, we would loose all breakpoints/bookmarks.
				viewContent = FileService.OpenFile(classFileName);
				editable = viewContent as ITextEditorProvider;
				if (editable == null) {
					return;
				}
				editable.TextEditor.Document.Text = modifiedClassCode;
			}
		}
		/// <summary>
		/// A custom ShowDialog routine that handles pass-through deserialization and reserialization
		/// of a <see cref="ExtractInterfaceOptions"/> object to encapsulate this operation's
		/// parameters.
		/// </summary>
		/// <param name="options">
		/// A <see cref="ExtractInterfaceOptions"/> containing initial, default values for the operation.
		/// </param>
		/// <returns>
		/// A <see cref="ExtractInterfaceOptions"/> reference encapsulating the dialog's parameters.
		/// </returns>
		public ExtractInterfaceOptions ShowDialog(ExtractInterfaceOptions options)
		{
			InitializeFields(options);
			options.IsCancelled = (base.ShowDialog() == DialogResult.Cancel);
			return options;
		}
		/// <summary>
		/// A custom ShowDialog routine that handles pass-through deserialization and reserialization
		/// of a <see cref="ExtractInterfaceOptions"/> object to encapsulate this operation's
		/// parameters.
		/// </summary>
		/// <param name="options">
		/// A <see cref="ExtractInterfaceOptions"/> containing initial, default values for the operation.
		/// </param>
		/// <returns>
		/// A <see cref="ExtractInterfaceOptions"/> reference encapsulating the dialog's parameters.
		/// </returns>
		public ExtractInterfaceOptions ShowDialog(ExtractInterfaceOptions options)
		{
			InitializeFields(options);
			options.IsCancelled = (base.ShowDialog(WorkbenchSingleton.MainWin32Window) == DialogResult.Cancel);
			return options;
		}