Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / tools / monodoc / Monodoc / provider.cs
index 74c685d3e8f19b5335f6d325cef4f3e65241b33a..d79ce079e192b68c007443df35e503136f3997f1 100644 (file)
@@ -5,6 +5,8 @@
 //   Miguel de Icaza (miguel@ximian.com)
 //
 // (C) 2002, Ximian, Inc.
+// Copyright 2003-2011 Novell
+// Copyright 2011 Xamarin Inc
 //
 // TODO:
 //   Each node should have a provider link
@@ -22,7 +24,6 @@ using System.Collections;
 using System.Diagnostics;
 using System.Configuration;
 using System.Reflection;
-using System.Text.RegularExpressions;
 using System.Xml;
 using System.Xml.XPath;
 using ICSharpCode.SharpZipLib.Zip;
@@ -131,6 +132,7 @@ public class Node : IComparable {
        Node parent;
        protected ArrayList nodes;
        protected internal int position;
+       string compare_key;
 
        static ArrayList empty = ArrayList.ReadOnly(new ArrayList(0));
 
@@ -392,14 +394,19 @@ public class Node : IComparable {
                        LoadNode ();
                if (other.position < 0)
                        other.LoadNode ();
-
-               Regex digits = new Regex (@"([\d]+)|([^\d]+)");
-               MatchEvaluator eval = delegate (Match m) {
-                       return (m.Value.Length > 0 && char.IsDigit (m.Value [0])) 
+               if (compare_key == null || other.compare_key == null) {
+                       Regex digits = new Regex (@"([\d]+)|([^\d]+)");
+                       MatchEvaluator eval = delegate (Match m) {
+                               return (m.Value.Length > 0 && char.IsDigit (m.Value [0]))
                                ? m.Value.PadLeft (System.Math.Max (caption.Length, other.caption.Length)) 
                                : m.Value;
-               };
-               return digits.Replace (caption, eval).CompareTo (digits.Replace (other.caption, eval));
+                       };
+                       if (compare_key == null)
+                               compare_key = digits.Replace (caption, eval);
+                       if (other.compare_key == null)
+                               other.compare_key = digits.Replace (other.caption, eval);
+               }
+               return compare_key.CompareTo (other.compare_key);
        }
 }
 
@@ -446,6 +453,7 @@ public class HelpSource {
        int source_id;
        DateTime zipFileWriteTime;
        string name;
+       string basepath;
        TraceLevel trace_level = TraceLevel.Warning;
        protected bool nozip;
        protected string base_dir;
@@ -453,6 +461,7 @@ public class HelpSource {
        public HelpSource (string base_filename, bool create)
        {
                this.name = Path.GetFileName (base_filename);
+               this.basepath = Path.GetDirectoryName (base_filename);
                tree_filename = base_filename + ".tree";
                zip_filename = base_filename + ".zip";
                base_dir = XmlDocUtils.GetCacheDirectory (base_filename);
@@ -497,6 +506,13 @@ public class HelpSource {
                }
        }
 
+       /* This gives the full path of the source/ directory */
+       public string BaseFilePath {
+               get {
+                       return basepath;
+               }
+       }
+
        public TraceLevel TraceLevel {
                get { return trace_level; }
                set { trace_level = value; }
@@ -546,7 +562,7 @@ public class HelpSource {
        {
                if (nozip) {
                        Stream s = File.OpenRead (XmlDocUtils.GetCachedFileName (base_dir, id));
-                       string url = "monodoc:///" + SourceID + "@" + System.Web.HttpUtility.UrlEncode (id) + "@";
+                       string url = "monodoc:///" + SourceID + "@" + Uri.EscapeUriString (id) + "@";
                        return new XmlTextReader (url, s);
                }
 
@@ -556,7 +572,7 @@ public class HelpSource {
                ZipEntry entry = zip_file.GetEntry (id);
                if (entry != null) {
                        Stream s = zip_file.GetInputStream (entry);
-                       string url = "monodoc:///" + SourceID + "@" + System.Web.HttpUtility.UrlEncode (id) + "@";
+                       string url = "monodoc:///" + SourceID + "@" + Uri.EscapeUriString (id) + "@";
                        return new XmlTextReader (url, s);
                }
                return null;
@@ -566,7 +582,7 @@ public class HelpSource {
        {
                if (nozip) {
                        Stream s = File.OpenRead (XmlDocUtils.GetCachedFileName (base_dir, id));
-                       string url = "monodoc:///" + SourceID + "@" + System.Web.HttpUtility.UrlEncode (id) + "@";
+                       string url = "monodoc:///" + SourceID + "@" + Uri.EscapeUriString (id) + "@";
                        XmlReader r = new XmlTextReader (url, s);
                        XmlDocument ret = new XmlDocument ();
                        ret.Load (r);
@@ -579,7 +595,7 @@ public class HelpSource {
                ZipEntry entry = zip_file.GetEntry (id);
                if (entry != null) {
                        Stream s = zip_file.GetInputStream (entry);
-                       string url = "monodoc:///" + SourceID + "@" + System.Web.HttpUtility.UrlEncode (id) + "@";
+                       string url = "monodoc:///" + SourceID + "@" + Uri.EscapeUriString (id) + "@";
                        XmlReader r = new XmlTextReader (url, s);
                        XmlDocument ret = new XmlDocument ();
                        ret.Load (r);
@@ -887,7 +903,6 @@ public class RootTree : Tree {
                                }
                        }
                }
-               Console.WriteLine ("Basedir={0}", basedir);
 
                //
                // Load the layout
@@ -906,7 +921,6 @@ public class RootTree : Tree {
                                .Concat (osxExternalSources));
        }
 
-
        // Compatibility shim w/ Mono 2.6
        public static RootTree LoadTree (string indexDir, XmlDocument docTree, IEnumerable sourceFiles)
        {
@@ -946,9 +960,8 @@ public class RootTree : Tree {
                //
                // Load the sources
                //
-               foreach (var sourceFile in sourceFiles){
+               foreach (var sourceFile in sourceFiles)
                        root.AddSourceFile (sourceFile);
-               }
                
                foreach (string path in UncompiledHelpSources) {
                        EcmaUncompiledHelpSource hs = new EcmaUncompiledHelpSource(path);
@@ -1215,7 +1228,7 @@ public class RootTree : Tree {
                        return lastHelpSourceTime;
                }
        }
-       
+
        public static bool GetNamespaceAndType (string url, out string ns, out string type)
        {
                int nsidx = -1;
@@ -1642,7 +1655,7 @@ public class RootTree : Tree {
                        // No octal in C#, how lame is that
                        chmod (path, 0x1a4);
                }
-               Console.WriteLine ("Documentation index updated");
+               Console.WriteLine ("Documentation index at {0} updated", path);
        }
 
        static bool IsUnix {