Hey guys,

   This is the patch to add preview to the editor.  If someone has input
on how to fix my bugs, I would love to hear from you ;-)

Miguel.
-- 
Miguel de Icaza <[EMAIL PROTECTED]>
? .ecma-provider.cs.swp
? .provider.cs.swp
? b.cs
? browser.gladep
? copy.glade
? copy2.glade
? file
? hello.png
? index
? index.html
? monodoc_edits.patch
? page-header.html
? sources
? website-handler.cs
? x
Index: browser.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/browser.cs,v
retrieving revision 1.61
diff -u -u -r1.61 browser.cs
--- browser.cs  6 Sep 2003 00:42:29 -0000       1.61
+++ browser.cs  7 Sep 2003 15:42:09 -0000
@@ -99,6 +99,7 @@
        //
        [Glade.Widget] Notebook html_and_editor_notebook;
        [Glade.Widget] TextView text_editor;
+       [Glade.Widget] ScrolledWindow html_preview_container;
 
        [Glade.Widget] EventBox bar_eb, index_eb;
        [Glade.Widget] Label subtitle_label;
@@ -117,11 +118,12 @@
 
        public History history;
 
-       //
        // Where we render the contents
-       //
        HTML html;
 
+       // Our HTML preview during editing.
+       HTML html_preview;
+
         //
        // Left-hand side Browsers
        //
@@ -182,6 +184,11 @@
                // Text editor (for editing the documentation).
                //
                html_and_editor_notebook.ShowTabs = false;
+               html_preview = new HTML ();
+               html_preview.Show ();
+               html_preview_container.Add (html_preview);
+
+               text_editor.Buffer.Changed += new EventHandler (EditedTextChanged);
                
                //
                // Other bits
@@ -556,6 +563,31 @@
        {
                SetMode (Mode.Viewer);
                history.ActivateCurrent ();
+       }
+
+       void EditedTextChanged (object sender, EventArgs args)
+       {
+               Text.StringBuilder sb = new Text.StringBuilder ();
+               sb.Append ("<?xml version=\"1.0\"?><docs>");
+               sb.Append (text_editor.Buffer.Text);
+               sb.Append ("</docs>");
+               Xml.XmlDocument d = new Xml.XmlDocument ();
+               string html_text = "";
+               try {
+                       d.LoadXml (sb.ToString ());
+                       html_text = EcmaHelpSource.Htmlize (d);
+               } catch (Exception e) {
+                       statusbar.Pop (context_id);
+                       statusbar.Push (context_id, e.Message);
+                       return;
+               }
+               statusbar.Pop (context_id);
+               statusbar.Push (context_id, "XML OK");
+               Gtk.HTMLStream s = html_preview.Begin ("text/html");
+               s.Write ("<html><body>");
+               s.Write (html_text);
+               s.Write ("</body></html>");
+               html_preview.End (s, HTMLStreamStatus.Ok);
        }
 }
 
Index: browser.glade
===================================================================
RCS file: /cvs/public/monodoc/browser/browser.glade,v
retrieving revision 1.27
diff -u -u -r1.27 browser.glade
--- browser.glade       5 Sep 2003 04:47:33 -0000       1.27
+++ browser.glade       7 Sep 2003 15:42:11 -0000
@@ -784,30 +784,91 @@
                          <property name="spacing">0</property>
 
                          <child>
-                           <widget class="GtkScrolledWindow" id="scrolledwindow2">
+                           <widget class="GtkVBox" id="vbox7">
                              <property name="visible">True</property>
-                             <property name="can_focus">True</property>
-                             <property 
name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
-                             <property 
name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
-                             <property name="shadow_type">GTK_SHADOW_NONE</property>
-                             <property 
name="window_placement">GTK_CORNER_TOP_LEFT</property>
+                             <property name="homogeneous">False</property>
+                             <property name="spacing">0</property>
 
                              <child>
-                               <widget class="GtkTextView" id="text_editor">
+                               <widget class="GtkScrolledWindow" id="scrolledwindow2">
                                  <property name="visible">True</property>
                                  <property name="can_focus">True</property>
-                                 <property name="editable">True</property>
-                                 <property 
name="justification">GTK_JUSTIFY_LEFT</property>
-                                 <property name="wrap_mode">GTK_WRAP_NONE</property>
-                                 <property name="cursor_visible">True</property>
-                                 <property name="pixels_above_lines">0</property>
-                                 <property name="pixels_below_lines">0</property>
-                                 <property name="pixels_inside_wrap">0</property>
-                                 <property name="left_margin">0</property>
-                                 <property name="right_margin">0</property>
-                                 <property name="indent">0</property>
-                                 <property name="text" translatable="yes"></property>
+                                 <property 
name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                                 <property 
name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                                 <property 
name="shadow_type">GTK_SHADOW_NONE</property>
+                                 <property 
name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+                                 <child>
+                                   <widget class="GtkTextView" id="text_editor">
+                                     <property name="visible">True</property>
+                                     <property name="can_focus">True</property>
+                                     <property name="editable">True</property>
+                                     <property 
name="justification">GTK_JUSTIFY_LEFT</property>
+                                     <property 
name="wrap_mode">GTK_WRAP_NONE</property>
+                                     <property name="cursor_visible">True</property>
+                                     <property name="pixels_above_lines">0</property>
+                                     <property name="pixels_below_lines">0</property>
+                                     <property name="pixels_inside_wrap">0</property>
+                                     <property name="left_margin">0</property>
+                                     <property name="right_margin">0</property>
+                                     <property name="indent">0</property>
+                                     <property name="text" 
translatable="yes"></property>
+                                   </widget>
+                                 </child>
+                               </widget>
+                               <packing>
+                                 <property name="padding">0</property>
+                                 <property name="expand">True</property>
+                                 <property name="fill">True</property>
+                               </packing>
+                             </child>
+
+                             <child>
+                               <widget class="GtkFrame" id="html_preview_frame">
+                                 <property name="visible">True</property>
+                                 <property name="label_xalign">0</property>
+                                 <property name="label_yalign">0.5</property>
+                                 <property 
name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+
+                                 <child>
+                                   <widget class="GtkScrolledWindow" 
id="html_preview_container">
+                                     <property name="visible">True</property>
+                                     <property name="can_focus">True</property>
+                                     <property 
name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                                     <property 
name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+                                     <property 
name="shadow_type">GTK_SHADOW_NONE</property>
+                                     <property 
name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+                                     <child>
+                                       <placeholder/>
+                                     </child>
+                                   </widget>
+                                 </child>
+
+                                 <child>
+                                   <widget class="GtkLabel" id="label18">
+                                     <property name="visible">True</property>
+                                     <property name="label" 
translatable="yes">Preview</property>
+                                     <property name="use_underline">False</property>
+                                     <property name="use_markup">False</property>
+                                     <property 
name="justify">GTK_JUSTIFY_LEFT</property>
+                                     <property name="wrap">False</property>
+                                     <property name="selectable">False</property>
+                                     <property name="xalign">0.5</property>
+                                     <property name="yalign">0.5</property>
+                                     <property name="xpad">0</property>
+                                     <property name="ypad">0</property>
+                                   </widget>
+                                   <packing>
+                                     <property name="type">label_item</property>
+                                   </packing>
+                                 </child>
                                </widget>
+                               <packing>
+                                 <property name="padding">0</property>
+                                 <property name="expand">True</property>
+                                 <property name="fill">True</property>
+                               </packing>
                              </child>
                            </widget>
                            <packing>
Index: ecma-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/ecma-provider.cs,v
retrieving revision 1.67
diff -u -u -r1.67 ecma-provider.cs
--- ecma-provider.cs    5 Sep 2003 00:47:30 -0000       1.67
+++ ecma-provider.cs    7 Sep 2003 15:42:12 -0000
@@ -10,7 +10,6 @@
 //
 // TODO:
 //   Should cluster together constructors
-//   Should cluster together methods with the same name (overloads)
 //
 // Easy:
 //   Should render attributes on the signature.
@@ -86,9 +85,12 @@
                if (!type.StartsWith ("System."))
                        return type;
 
-               if (type.EndsWith ("*")) return ConvertCTSName(type.Substring(0, 
type.Length - 1)) + "*";
-               if (type.EndsWith ("&")) return ConvertCTSName(type.Substring(0, 
type.Length - 1)) + "&";
-               if (type.EndsWith ("[]")) return ConvertCTSName(type.Substring(0, 
type.Length - 2)) + "[]";
+               if (type.EndsWith ("*"))
+                       return ConvertCTSName(type.Substring(0, type.Length - 1)) + 
"*";
+               if (type.EndsWith ("&"))
+                       return ConvertCTSName(type.Substring(0, type.Length - 1)) + 
"&";
+               if (type.EndsWith ("[]"))
+                       return ConvertCTSName(type.Substring(0, type.Length - 2)) + 
"[]";
 
                switch (type) {
                case "System.Byte": return "byte";
@@ -112,7 +114,8 @@
                case "System.Void":  return "void";
                }
 
-               if (type.LastIndexOf(".") == 6) return type.Substring(7);
+               if (type.LastIndexOf(".") == 6)
+                       return type.Substring(7);
                
                return type;
        }
@@ -479,7 +482,8 @@
 
        string RenderMemberLookup (string typename, string member, ref Node type_node)
        {
-               if (type_node.Nodes == null) return null;
+               if (type_node.Nodes == null)
+                       return null;
 
                string lasturl = "";
                XmlNode doc = null;
@@ -655,7 +659,8 @@
                                        match_node = type_node;
                                        if (type == cname){
                                                string ret = RenderMemberLookup (type, 
member, ref match_node);
-                                               if (ret == null) return GetTextFromUrl 
(type_node.URL);
+                                               if (ret == null)
+                                                       return GetTextFromUrl 
(type_node.URL);
                                                return ret;
 
                                        } else if (type [p] == '/'){
@@ -790,7 +795,7 @@
 
        static XslTransform ecma_transform;
 
-       static string Htmlize (IXPathNavigable ecma_xml)
+       public static string Htmlize (IXPathNavigable ecma_xml)
        {
                return Htmlize(ecma_xml, null);
        }
@@ -806,7 +811,8 @@
                        ecma_transform.Load (xml_reader);
                }
                
-               if (ecma_xml == null) return "";
+               if (ecma_xml == null)
+                       return "";
 
                StringWriter output = new StringWriter ();
                ecma_transform.Transform (ecma_xml, args, output);
@@ -824,8 +830,10 @@
                // Used by stylesheet to nicely reformat the <see cref=> tags. 
                public string MakeNiceSignature(string sig)
                {
-                       if (sig.Length < 3) return sig;
-                       if (sig[1] != ':') return sig;
+                       if (sig.Length < 3)
+                               return sig;
+                       if (sig[1] != ':')
+                               return sig;
 
                        char s = sig[0];
                        sig = sig.Substring(2);
@@ -889,14 +897,18 @@
 
                                Type t = assembly.GetType(typename, false);
                                if (t == null) {
-                                       if (strlong) return typename + " has not been 
implemented.";
-                                       else return "Not implemented.";
+                                       if (strlong)
+                                               return typename + " has not been 
implemented.";
+                                       else
+                                               return "Not implemented.";
                                }
 
                                MemberInfo[] mis = t.GetMember(membername, BF.Static | 
BF.Instance | BF.Public | BF.NonPublic);
 
-                               if (mis.Length == 0) return "This member has not been 
implemented.";
-                               if (mis.Length == 1) return MonoImpInfo(mis[0], 
"member", strlong);
+                               if (mis.Length == 0)
+                                       return "This member has not been implemented.";
+                               if (mis.Length == 1)
+                                       return MonoImpInfo(mis[0], "member", strlong);
 
                                // Scan for the appropriate member
                                foreach (MemberInfo mi in mis) {
@@ -949,18 +961,23 @@
                public string MonoImpInfo(string assemblyname, string typename, bool 
strlong)
                {
                        try {
-                               if (assemblyname == "") return "";
+                               if (assemblyname == "")
+                                       return "";
 
                                Assembly assembly = Assembly.Load(assemblyname);
                                if (assembly == null) {
-                                       if (strlong) return "The assembly " + 
assemblyname + " is not available to MonoDoc.";
-                                       else return "";
+                                       if (strlong)
+                                               return "The assembly " + assemblyname 
+ " is not available to MonoDoc.";
+                                       else
+                                               return "";
                                }
 
                                Type t = assembly.GetType(typename, false);
                                if (t == null) {
-                                       if (strlong) return typename + " has not been 
implemented.";
-                                       else return "Not implemented.";
+                                       if (strlong)
+                                               return typename + " has not been 
implemented.";
+                                       else
+                                               return "Not implemented.";
                                }
 
                                string s = MonoImpInfo(t, "type", strlong);
@@ -989,11 +1006,14 @@
                public string GetInheritance(string assemblyname, string typename)
                {
                        try {
-                               if (assemblyname == "") return "";
+                               if (assemblyname == "")
+                                       return "";
                                Assembly assembly = Assembly.Load(assemblyname);
-                               if (assembly == null) return "";
+                               if (assembly == null)
+                                       return "";
                                Type t = assembly.GetType(typename, false);
-                               if (t == null) return "";
+                               if (t == null)
+                                       return "";
                                
                                StringBuilder b = new StringBuilder();
                                

Reply via email to