コード例 #1
0
		public void Detach()
		{
			var textEditor = editor.GetService<TextEditor>();
			if (textEditor != null) {
				var textView = textEditor.TextArea.TextView;
				
				// Unregister our ITextEditorOptions instance from editor
				var optionsService = textView.GetService<ITextEditorOptions>();
				if ((optionsService != null) && (optionsService == options))
					textView.Services.RemoveService(typeof(ITextEditorOptions));
				
				// Reset TextEditor options, too?
				if ((textEditor.Options != null) && (textEditor.Options == options.TextEditorOptions))
					textEditor.Options = originalEditorOptions;
				
				// remove the outline pad
				if (textView != null) {
					if (contentHost != null) {
						textView.Services.RemoveService(typeof(IOutlineContentHost));
						contentHost.Dispose();
						contentHost = null;
					}
					textView.Services.RemoveService(typeof(CSharpTextEditorExtension));
				}
			}
			
			codeManipulation.Dispose();
			
			if (inspectionManager != null) {
				inspectionManager.Dispose();
				inspectionManager = null;
			}
			
			if (contextActionProviders != null) {
				editor.ContextActionProviders.RemoveAll(contextActionProviders.Contains);
			}
			
			renderer.Dispose();
			options = null;
			this.editor = null;
		}
コード例 #2
0
		public void Attach(ITextEditor editor)
		{
			this.editor = editor;
			inspectionManager = new IssueManager(editor);
			codeManipulation = new CodeManipulation(editor);
			renderer = new CaretReferenceHighlightRenderer(editor);
			
			// Patch editor options (indentation) to project-specific settings
			if (!editor.ContextActionProviders.IsReadOnly) {
				contextActionProviders = AddInTree.BuildItems<IContextActionProvider>("/SharpDevelop/ViewContent/TextEditor/C#/ContextActions", null);
				editor.ContextActionProviders.AddRange(contextActionProviders);
			}
			
			
			// Create instance of options adapter and register it as service
			var formattingPolicy = CSharpFormattingPolicies.Instance.GetProjectOptions(SD.ProjectService.FindProjectContainingFile(editor.FileName));
			var textEditor = editor.GetService<TextEditor>();
			
			if (textEditor != null) {
				options = new CodeEditorFormattingOptionsAdapter(textEditor.Options, editor.Options, formattingPolicy.OptionsContainer);
				var textViewServices = textEditor.TextArea.TextView.Services;
				
				// Unregister any previous ITextEditorOptions instance from editor, if existing, register our impl.
				textViewServices.RemoveService(typeof(ITextEditorOptions));
				textViewServices.AddService(typeof(ITextEditorOptions), options);
				
				// Set TextEditor's options to same object
				originalEditorOptions = textEditor.Options;
				textEditor.Options = options.TextEditorOptions;
				
				// add the outline pad
				var textView = textEditor.TextArea.TextView;
				if (textView != null) {
					if (SD.Workbench != null) {		
						// add the CSharpOutlineContentHost, which manages the tree view
						contentHost = new CSharpOutlineContentHost(editor);
						textView.Services.AddService(typeof(IOutlineContentHost), contentHost);
					}
					textView.Services.AddService(typeof(CSharpTextEditorExtension), this);				
				}
			}
		}