Widget MonoDevelop.DesignerSupport.IOutlinedDocument.GetOutlineWidget ()
		{
			if (outlineTreeView != null)
				return outlineTreeView;

			outlineTreeStore = new TreeStore (typeof(object));

			// Initialize sorted tree model

			outlineTreeModelSort = new TreeModelSort (outlineTreeStore);

			sortingProperties = PropertyService.Get (
				ClassOutlineSortingProperties.SORTING_PROPERTY_NAME,
				ClassOutlineSortingProperties.GetDefaultInstance ());

			comparer = new ClassOutlineNodeComparer (GetAmbience (), sortingProperties, outlineTreeModelSort);

			outlineTreeModelSort.SetSortFunc (0, comparer.CompareNodes);
			outlineTreeModelSort.SetSortColumnId (0, SortType.Ascending);

			outlineTreeView = new MonoDevelop.Ide.Gui.Components.PadTreeView (outlineTreeStore);

			var pixRenderer = new CellRendererPixbuf ();
			pixRenderer.Xpad = 0;
			pixRenderer.Ypad = 0;

			outlineTreeView.TextRenderer.Xpad = 0;
			outlineTreeView.TextRenderer.Ypad = 0;

			TreeViewColumn treeCol = new TreeViewColumn ();
			treeCol.PackStart (pixRenderer, false);

			treeCol.SetCellDataFunc (pixRenderer, new TreeCellDataFunc (OutlineTreeIconFunc));
			treeCol.PackStart (outlineTreeView.TextRenderer, true);

			treeCol.SetCellDataFunc (outlineTreeView.TextRenderer, new TreeCellDataFunc (OutlineTreeTextFunc));
			outlineTreeView.AppendColumn (treeCol);

			outlineTreeView.HeadersVisible = false;

			outlineTreeView.Selection.Changed += delegate {
				JumpToDeclaration (false);
			};
			
			outlineTreeView.RowActivated += delegate {
				JumpToDeclaration (true);
			};

			this.lastCU = Document.ParsedDocument;

			outlineTreeView.Realized += delegate { RefillOutlineStore (); };

			// Register for property changes (e.g. preferences dialog)

			sortingProperties.EventSortingPropertiesChanged += OnSortingPropertiesChanged;

			UpdateSorting ();

			var sw = new CompactScrolledWindow ();
			sw.Add (outlineTreeView);
			sw.ShowAll ();
			return sw;
		}
		/// <summary>
		/// Returns a default initialized instance.
		/// </summary>
		/// <returns>
		/// Instance with sorting disabled and default sort keys.
		/// </returns>
		public static ClassOutlineSortingProperties GetDefaultInstance ()
		{
			if (defaultInstance == null) {

				defaultInstance = new ClassOutlineSortingProperties {

					IsGrouping              = false,
					IsSortingAlphabetically = false
				};
			}

			return defaultInstance;
		}
		void MonoDevelop.DesignerSupport.IOutlinedDocument.ReleaseOutlineWidget ()
		{
			if (outlineTreeView == null)
				return;
			ScrolledWindow w = (ScrolledWindow)outlineTreeView.Parent;
			w.Destroy ();
			outlineTreeModelSort.Dispose ();
			outlineTreeModelSort = null;
			outlineTreeStore.Dispose ();
			outlineTreeStore = null;
			outlineTreeView = null;

			// De-register from property changes

			sortingProperties.EventSortingPropertiesChanged -= OnSortingPropertiesChanged;

			sortingProperties = null;
			comparer = null;
		}