[Mono-devel-list] A larger patch for the monodoc-browser

Philip Van Hoof spamfrommailing at freax.org
Wed May 14 16:08:54 EDT 2003


Hi there,

Because I wanted to learn gtk-sharp I decided to work on the monodoc-
browser. I added a few things and cleaned up the code a little bit.

- I added a few menu-items
  (I've already send a patch with these changes a few hours ago)

	File->Exit
	Edit->Copy
	Edit->Select All
	View->Expand All
	View->Collapse All
	Help->About


- I learned myself gtk-sharp ;)

- I finished the "Index"-tabpage: If you type in "System" and enter then
  the listbox will be filled with all the classes in the namespace
  "System". Clicking on such an item will take you to it's
  documentation. Note: You can use Regular Expressions here.

- I added a About-box

I will take a look at the "Search"-tab sooner or later (I will need it
for my own purposes anyway). Probably using a thread (searching can take
long depending on how much documentation you have installed)


A.t.m. there is one problem : You need to collapse the root-tree before
searching ("Look for" on the Index tab) will work. I'll fix this issue
soon (can't be that hard).

ps. The current Authors (Miguel and Duncan) are in CC

ps. The patch was created this way :

[freax at pluisje monodoc]# pwd
/home/freax/cvs/monodoc
[freax at pluisje monodoc]# cvs diff -u > /home/freax/monodoc_patch_02.diff
...
[freax at pluisje monodoc]#

ps. All new code inherits the license(s) of the monodoc-browser if you
want to put this in CVS.


Have fun

-- 
Philip Van Hoof a.k.a. freax
me at freax dot org
http://www.freax.be -- http://www.freax.eu.org -- http://www.freax.org


-------------- next part --------------
? Makefile.in
? autom4te.cache
? file.zip
? mod
? browser/Makefile.in
? browser/browser.gladep
? browser/tree.zip
? class/Makefile.in
? class/tmp
? extras/Makefile.in
? extras/filesource
? extras/filetree
? extras/filezip
Index: AUTHORS
===================================================================
RCS file: /mono/monodoc/AUTHORS,v
retrieving revision 1.1
diff -u -r1.1 AUTHORS
--- AUTHORS	4 Apr 2003 04:33:59 -0000	1.1
+++ AUTHORS	14 May 2003 19:51:50 -0000
@@ -1,2 +1,3 @@
 Miguel de Icaza (miguel at ximian.com)
 Duncan Mak (duncan at ximian.com)
+Philip Van Hoof (me at freax.org)
Index: ChangeLog
===================================================================
RCS file: /mono/monodoc/ChangeLog,v
retrieving revision 1.3
diff -u -r1.3 ChangeLog
--- ChangeLog	14 Apr 2003 22:34:48 -0000	1.3
+++ ChangeLog	14 May 2003 19:51:50 -0000
@@ -1,3 +1,8 @@
+2003-04-14  Philip Van Hoof  <me at freax.org>
+	* Added some menus
+	* Finished the "Look For"-tabpage
+	* Cleanup
+
 2003-04-14  Miguel de Icaza  <miguel at ximian.com>
 
 	* Makefile.am (bin_SCRIPTS): Install a script `mod' that can be
Index: browser/Makefile.am
===================================================================
RCS file: /mono/monodoc/browser/Makefile.am,v
retrieving revision 1.8
diff -u -r1.8 Makefile.am
--- browser/Makefile.am	19 Apr 2003 22:52:22 -0000	1.8
+++ browser/Makefile.am	14 May 2003 19:51:50 -0000
@@ -6,7 +6,7 @@
 assembler_sources = $(srcdir)/assembler.cs $(shared_sources)
 dump_sources      = $(srcdir)/dump.cs $(shared_sources)
 browser_sources   = $(srcdir)/browser.cs $(srcdir)/history.cs $(shared_sources)
-browser_assemblies = -r:gtk-sharp.dll -r:glade-sharp.dll -r:glib-sharp.dll -r:ICSharpCode.SharpZipLib.dll
+browser_assemblies = -r:gtk-sharp.dll -r:gdk-sharp.dll -r:glade-sharp.dll -r:glib-sharp.dll -r:gnome-sharp.dll -r:ICSharpCode.SharpZipLib.dll
 
 EXTRA_DIST = $(assembler_sources) $(dump_sources) $(browser_sources) browser.glade monodoc.xml mono-ecma.xsl
 
Index: browser/browser.cs
===================================================================
RCS file: /mono/monodoc/browser/browser.cs,v
retrieving revision 1.21
diff -u -r1.21 browser.cs
--- browser/browser.cs	15 Apr 2003 05:23:52 -0000	1.21
+++ browser/browser.cs	14 May 2003 19:51:51 -0000
@@ -14,10 +14,15 @@
 //
 using GLib;
 using Gtk;
+using Gnome;
+using Gdk;
 using GtkSharp;
 using Glade;
 using System;
+using System.IO;
 using System.Collections;
+using System.Text.RegularExpressions;
+using System.Text;
 
 class Browser {
 	Glade.XML ui;
@@ -67,6 +72,9 @@
 	TreeView reference_tree;
 
 	[Glade.Widget]
+	TreeView lookfor_tree;
+
+	[Glade.Widget]
 	Box help_container;
 
 	[Glade.Widget]
@@ -81,6 +89,9 @@
 	[Glade.Widget]
 	Button forward_button;
 
+	[Glade.Widget]
+	Gtk.Entry index_entry;
+
 	public History history;
 	
 	HTML html;
@@ -105,7 +116,7 @@
 		//html_container = (ScrolledWindow) ui ["html_container"];
 
 		help_tree = RootTree.LoadTree ();
-		tree_browser = new TreeBrowser (help_tree, reference_tree, this);
+		tree_browser = new TreeBrowser (help_tree, reference_tree, lookfor_tree, this);
 
 		html = new HTML ();
 		html.Show ();
@@ -136,7 +147,7 @@
 		}
 	}
 	
-        void LinkClicked (object o, LinkClickedArgs args)
+	void LinkClicked (object o, LinkClickedArgs args)
 	{
 		LoadUrl (args.Url);
 	}
@@ -207,57 +218,116 @@
 	{
 		Application.Quit ();
 	}
+	
+	public void on_quit_activate (object o, EventArgs e) {
+		Application.Quit ();
+	}
+
+	public void on_copy_activate (object o, EventArgs e) {
+		this.html.Copy ();
+	}
+
+	public void on_about_activate (object o, EventArgs e) {
+		string[] authors = {
+			"Miguel De Icaza <miguel at ximian.com>",
+			"Duncan Mak <duncan at ximian.com>",
+			"Philip Van Hoof <me at freax.org>"
+		};
+		string[] documenters = {};
+		Pixbuf logo = new Pixbuf ("/usr/share/pixmaps/gnome-about-logo.png");
+		// TODO: I have no idea how to do this correctly (how do I know what the --prefix was
+		// and stuff like that?)
+		// Pixbuf logo = new Pixbuf ("pixmaps" + Path.DirectorySeparatorChar + "monodoc-logo.png");
+		About about = new About("MonoDoc-browser", "CVS", "Copyright (C) 2003", 
+		"This tool displays documentation in the format used by the ECMA specification",
+		authors, documenters, "", logo);
+		about.Show ();
+	}
+
+	public void on_select_all_activate (object o, EventArgs e) {
+		this.html.SelectAll ();
+	}
+
+	public void on_expand_all_activate (object o, EventArgs e) {
+		this.reference_tree.ExpandAll ();
+	}
+
+	public void on_collapse_all_activate (object o, EventArgs e) {
+		this.reference_tree.CollapseAll ();
+	}
+
+	public void on_index_entry_activate (object o, EventArgs e) {
+		tree_browser.LookFor(index_entry.Text);
+	}
 }
 
-//
+
+
 // This class implements the tree browser
-//
 class TreeBrowser {
-	Browser browser;
+	private Browser browser;
+	private TreeView tree_view;
+	private TreeView lookfor_tree;
+	private TreeStore lookfor_store;
+	private TreeStore store;
+	private RootTree help_tree;
+	private TreeIter root_iter;
 
-	TreeView tree_view;
-	
-	TreeStore store;
-	RootTree help_tree;
-	TreeIter root_iter;
-
-	//
 	// This hashtable maps an iter to its node.
-	//
-	Hashtable iter_to_node;
+	private Hashtable iter_to_node;
 
-	//
 	// This hashtable maps the node to its iter
-	//
-	Hashtable node_to_iter;
+	private Hashtable node_to_iter;
 
-	//
 	// Maps a node to its TreeIter parent
-	//
-	Hashtable node_parent;
+	private Hashtable node_parent;
+
+	// This hashtable maps an iter to its node (for the lookfor-treeview).
+	private Hashtable iter_to_lookfornode;
+
+	// Temporary variable
+	private Regex regex;
+
+	private Hashtable populated = new Hashtable ();
+	private bool IgnoreRowActivated = false;
 
-	public TreeBrowser (RootTree help_tree, TreeView reference_tree, Browser browser)
+	public TreeBrowser (RootTree help_tree, TreeView reference_tree, TreeView lookfor_tree, Browser browser)
 	{
 		this.browser = browser;
-		tree_view = reference_tree;
+		this.tree_view = reference_tree;
+		this.lookfor_tree = lookfor_tree;
 		iter_to_node = new Hashtable ();
 		node_to_iter = new Hashtable ();
 		node_parent = new Hashtable ();
+		iter_to_lookfornode = new Hashtable ();
 
-		// Setup the TreeView
+		// Setup the normal TreeView
 		TreeViewColumn name_col = new TreeViewColumn ();
 		CellRenderer name_render = new CellRendererText ();
 		name_col.PackStart (name_render, true);
 		name_col.AddAttribute (name_render, "text", 0);
 		tree_view.AppendColumn (name_col);
 
-		// Bind events
+		// Setup the LookFor-TreeView
+		TreeViewColumn lname_col = new TreeViewColumn ();
+		CellRenderer lname_render = new CellRendererText ();
+		lname_col.PackStart (lname_render, true);
+		lname_col.AddAttribute (lname_render, "text", 0);
+		lookfor_tree.AppendColumn (lname_col);
+
+		// Bind events for the normal TreeView
 		tree_view.RowExpanded += new GtkSharp.RowExpandedHandler (RowExpanded);
 		tree_view.Selection.Changed += new EventHandler (RowActivated);
 
-		// Setup the model
+		// Bind events for the LookFor-TreeView
+		// This TreeView will be a simple ListBox, so a RowExpanded-handler is not needed
+		// lookfor_tree.RowExpanded += new GtkSharp.RowExpandedHandler (RowExpanded);
+		lookfor_tree.Selection.Changed += new EventHandler (LookForRowActivated);
+
+		// Setup the models of both TreeView
 		this.help_tree = help_tree;
 		store = new TreeStore ((int) TypeFundamentals.TypeString);
+		lookfor_store = new TreeStore ((int) TypeFundamentals.TypeString);
 
 		store.Append (out root_iter);
 		store.SetValue (root_iter, 0, new Value ("Mono Documentation"));
@@ -266,6 +336,7 @@
 		PopulateNode (help_tree, root_iter);
 
 		reference_tree.Model = store;
+		lookfor_tree.Model = lookfor_store;
 	}
 
 	void PopulateNode (Node node, TreeIter parent)
@@ -283,12 +354,9 @@
 		}
 	}
 
-	Hashtable populated = new Hashtable ();
-	
 	void RowExpanded (object o, GtkSharp.RowExpandedArgs args)
 	{
 		Node result = iter_to_node [args.Iter] as Node;
-
 		Open (result);
 	}
 
@@ -301,10 +369,8 @@
 
 		if (populated.Contains (node))
 			return;
-		
-		//
+
 		// We need to populate data on a second level
-		//
 		if (node.Nodes == null)
 			return;
 
@@ -313,7 +379,7 @@
 		}
 		populated [node] = true;
 	}
-	
+
 	void PopulateTreeFor (Node n)
 	{
 		if (populated [n] == null){
@@ -331,7 +397,7 @@
 		TreeIter iter = (TreeIter) node_to_iter [n];
 		TreePath path = store.GetPath (iter);
 	}
-	
+
 	public void ShowNode (Node n)
 	{
 		if (node_to_iter [n] == null){
@@ -345,9 +411,7 @@
 		TreeIter iter = (TreeIter) node_to_iter [n];
 		TreePath path = store.GetPath (iter);
 
-		//
 		// HACK until we upgrade Gtk# to Gtk 2.2
-		//
 		int depth = path.Depth;
 		for (int i = 0; i < depth; i++){
 			TreePath p = store.GetPath (iter);
@@ -364,7 +428,8 @@
 		tree_view.ScrollToCell (path, null, true, 0.5f, 0.5f);
 	}
 	
-	class NodePageVisit : PageVisit {
+	class NodePageVisit : PageVisit
+	{
 		Browser browser;
 		Node n;
 		string url;
@@ -388,53 +453,94 @@
 		}
 	}
 
-	bool IgnoreRowActivated = false;
-	
-	//
 	// This has to handle two kinds of urls: those encoded in the tree
 	// file, which are used to quickly lookup information precisely
 	// (things like "ecma:0"), and if that fails, it uses the more expensive
 	// mechanism that walks trees to find matches
-	//
-	void RowActivated  (object sender, EventArgs a)
+	void LoadNode (Node n)
+	{
+		Console.Error.WriteLine ("Loading url: " + n.URL);
+		if (n.tree.HelpSource == null)
+			return;
+
+		string url = n.URL;
+
+		// Try the tree-based urls first.
+		Node match;
+		string s = n.tree.HelpSource.GetText (url, out match);
+		if (s != null){
+			((Browser)browser).Render (s, match, url);
+			browser.history.AppendHistory (new NodePageVisit (browser, n, url));
+			return;
+		}
+
+		// Try the url resolver next
+		s = help_tree.RenderUrl (url, out match);
+		if (s != null){
+			((Browser)browser).Render (s, match, url);
+			browser.history.AppendHistory (new Browser.LinkPageVisit (browser, url));
+			return;
+		}
+
+		((Browser)browser).Render ("<b>Unhandled URL</b> " + n.URL, null, url);
+	}
+
+	void RowActivated (object sender, EventArgs a)
 	{
 		if (IgnoreRowActivated)
 			return;
-		
+
 		Gtk.TreeIter iter = new Gtk.TreeIter ();
 		Gtk.TreeModel model;
 
-		if (tree_view.Selection.GetSelected (out model, ref iter)){
+		if (tree_view.Selection.GetSelected (out model, ref iter)) {
 			Node n = (Node) iter_to_node [iter];
+			if (n != null)
+				this.LoadNode(n);
+		}
+	}
 
-			Console.Error.WriteLine ("Loading url: " + n.URL);
-			if (n.tree.HelpSource == null)
-				return;
+	void LookForRowActivated (object sender, EventArgs a)
+	{
+		if (IgnoreRowActivated)
+			return;
 
-			string url = n.URL;
-			
-			//
-			// Try the tree-based urls first.
-			//
-			Node match;
-			string s = n.tree.HelpSource.GetText (url, out match);
-			if (s != null){
-				((Browser)browser).Render (s, match, url);
-				browser.history.AppendHistory (new NodePageVisit (browser, n, url));
-				return;
-			}
+		Gtk.TreeIter iter = new Gtk.TreeIter ();
+		Gtk.TreeModel model;
 
-			//
-			// Try the url resolver next
-			//
-			s = help_tree.RenderUrl (url, out match);
-			if (s != null){
-				((Browser)browser).Render (s, match, url);
-				browser.history.AppendHistory (new Browser.LinkPageVisit (browser, url));
-				return;
-			}
+		if (lookfor_tree.Selection.GetSelected (out model, ref iter)) {
+			Node n = (Node) iter_to_lookfornode [iter];
+			if (n != null)
+				this.LoadNode(n);
+		}
+	}
+	
+	public bool on_treeview_foreach (Gtk.TreeModel model, Gtk.TreePath path, Gtk.TreeIter iter)
+	{
+		GLib.Value value;
+		model.GetValue(iter, 0, out value);
+		string nodename = (string) value;
 
-			((Browser)browser).Render ("<b>Unhandled URL</b> " + n.URL, null, url);
+		if (this.regex.Match(nodename).Success) {
+			TreeIter myiter;
+			lookfor_store.Append (out myiter);
+			lookfor_store.SetValue (myiter, 0, new Value (nodename));
+			iter_to_lookfornode [myiter] = (Node) iter_to_node [iter];
 		}
+
+		return false;
+	}
+
+	public void LookFor (string searchfor)
+	{
+		lookfor_store.Clear ();
+		TreeModel model = this.store;
+
+		// Compile a regular expression for this search
+		this.regex = new Regex(".*"+searchfor+".*");
+
+		// Loop each node
+		model.Foreach(new TreeModelForeachFunc (on_treeview_foreach));
 	}
+
 }
Index: browser/browser.glade
===================================================================
RCS file: /mono/monodoc/browser/browser.glade,v
retrieving revision 1.9
diff -u -r1.9 browser.glade
--- browser/browser.glade	4 Apr 2003 23:49:39 -0000	1.9
+++ browser/browser.glade	14 May 2003 19:51:52 -0000
@@ -2,6 +2,7 @@
 <!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
 
 <glade-interface>
+<requires lib="gnome"/>
 
 <widget class="GtkWindow" id="window1">
   <property name="visible">True</property>
@@ -29,6 +30,19 @@
 	      <property name="visible">True</property>
 	      <property name="label" translatable="yes">_File</property>
 	      <property name="use_underline">True</property>
+
+	      <child>
+		<widget class="GtkMenu" id="menuitem4_menu">
+
+		  <child>
+		    <widget class="GtkImageMenuItem" id="quit">
+		      <property name="visible">True</property>
+		      <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
+		      <signal name="activate" handler="on_quit_activate" last_modification_time="Wed, 14 May 2003 11:12:29 GMT"/>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
 	    </widget>
 	  </child>
 
@@ -37,6 +51,27 @@
 	      <property name="visible">True</property>
 	      <property name="label" translatable="yes">_Edit</property>
 	      <property name="use_underline">True</property>
+
+	      <child>
+		<widget class="GtkMenu" id="menuitem5_menu">
+
+		  <child>
+		    <widget class="GtkImageMenuItem" id="copy">
+		      <property name="visible">True</property>
+		      <property name="stock_item">GNOMEUIINFO_MENU_COPY_ITEM</property>
+		      <signal name="activate" handler="on_copy_activate" last_modification_time="Wed, 14 May 2003 11:12:29 GMT"/>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkMenuItem" id="select_all">
+		      <property name="visible">True</property>
+		      <property name="stock_item">GNOMEUIINFO_MENU_SELECT_ALL_ITEM</property>
+		      <signal name="activate" handler="on_select_all_activate" last_modification_time="Wed, 14 May 2003 11:12:29 GMT"/>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
 	    </widget>
 	  </child>
 
@@ -45,6 +80,29 @@
 	      <property name="visible">True</property>
 	      <property name="label" translatable="yes">_View</property>
 	      <property name="use_underline">True</property>
+
+	      <child>
+		<widget class="GtkMenu" id="menuitem6_menu">
+
+		  <child>
+		    <widget class="GtkMenuItem" id="collapse_all">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Collapse All</property>
+		      <property name="use_underline">True</property>
+		      <signal name="activate" handler="on_collapse_all_activate" last_modification_time="Wed, 14 May 2003 12:06:22 GMT"/>
+		    </widget>
+		  </child>
+
+		  <child>
+		    <widget class="GtkMenuItem" id="expand_all">
+		      <property name="visible">True</property>
+		      <property name="label" translatable="yes">Expand All</property>
+		      <property name="use_underline">True</property>
+		      <signal name="activate" handler="on_expand_all_activate" last_modification_time="Wed, 14 May 2003 12:07:02 GMT"/>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
 	    </widget>
 	  </child>
 
@@ -53,6 +111,19 @@
 	      <property name="visible">True</property>
 	      <property name="label" translatable="yes">_Help</property>
 	      <property name="use_underline">True</property>
+
+	      <child>
+		<widget class="GtkMenu" id="menuitem7_menu">
+
+		  <child>
+		    <widget class="GtkImageMenuItem" id="about">
+		      <property name="visible">True</property>
+		      <property name="stock_item">GNOMEUIINFO_MENU_ABOUT_ITEM</property>
+		      <signal name="activate" handler="on_about_activate" last_modification_time="Wed, 14 May 2003 11:12:29 GMT"/>
+		    </widget>
+		  </child>
+		</widget>
+	      </child>
 	    </widget>
 	  </child>
 	</widget>
@@ -197,6 +268,7 @@
 		      <property name="has_frame">True</property>
 		      <property name="invisible_char" translatable="yes">*</property>
 		      <property name="activates_default">False</property>
+		      <signal name="activate" handler="on_index_entry_activate" last_modification_time="Wed, 14 May 2003 16:16:12 GMT"/>
 		    </widget>
 		    <packing>
 		      <property name="padding">4</property>
@@ -215,7 +287,7 @@
 		      <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
 		      <child>
-			<widget class="GtkTreeView" id="treeview1">
+			<widget class="GtkTreeView" id="lookfor_tree">
 			  <property name="visible">True</property>
 			  <property name="can_focus">True</property>
 			  <property name="headers_visible">False</property>


More information about the Mono-devel-list mailing list