0:   // Resource.cs
1:   // Copyright (C) 2001 Mike Krueger
2:   //
3:   // This program is free software; you can redistribute it and/or modify
4:   // it under the terms of the GNU General Public License as published by
5:   // the Free Software Foundation; either version 2 of the License, or
6:   // (at your option) any later version.
7:   //
8:   // This program is distributed in the hope that it will be useful,
9:   // but WITHOUT ANY WARRANTY; without even the implied warranty of
10:   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11:   // GNU General Public License for more details.
12:   //
13:   // You should have received a copy of the GNU General Public License
14:   // along with this program; if not, write to the Free Software
15:   // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16:  
17:   using System;
18:   using System.IO;
19:   using System.Windows.Forms;
20:   using System.Collections;
21:   using System.Threading;
22:   using System.Resources;
23:   using System.Drawing;
24:   using System.Diagnostics;
25:   using System.Reflection;
26:   using System.Xml;
27:  
28:   namespace SharpDevelop.Tool.Data {
29:       
30:       /// <summary>
31:       /// This Class contains two common ResourceManagers, which are
32:       /// used in many cases.
33:       /// </summary>
34:       public class Resource
35:       {
36:           static ResourceManager strings null;
37:           static ResourceManager icon    null;
38:           
39:           static Hashtable       localstrings null;
40:           static Hashtable       localicons   null;
41:           
42:           static Resource() 
43:           {
44:               strings new ResourceManager("StringResources"Assembly.GetCallingAssembly());
45:               icon    new ResourceManager("IconResources",   Assembly.GetCallingAssembly());
46:               string language  Options.GetProperty("SharpDevelop.Gui.UILanguage"Thread.CurrentThread.CurrentUICulture.Name).ToString();
47:                   
48:               localstrings Load("StringResources"language);
49:               if (localstrings == null && language.IndexOf('-') > 0)
50:                   localstrings Load("StringResources"language.Split(new char[] {'-'})[0]);
51:               
52:               localicons Load("IconResources"language);
53:               if (localicons == null && language.IndexOf('-') > 0)
54:                   localicons Load("IconResources"language.Split(new char[] {'-'})[0]);
55:           }
56:           
57:           static Hashtable Load(string namestring language)
58:           {
59:               string fname Application.StartupPath 
60:                              Path.DirectorySeparatorChar ".." +
61:                              Path.DirectorySeparatorChar "data" 
62:                              Path.DirectorySeparatorChar "resources" 
63:                              Path.DirectorySeparatorChar name "." language ".resources";
64:               if (File.Exists(fname)) {
65:                       Hashtable resources new Hashtable();
66:                       ResourceReader rr new ResourceReader(fname);
67:                       foreach (DictionaryEntry entry in rr) {
68:                           resources.Add(entry.Keyentry.Value);
69:                       }
70:                       rr.Close();
71:                       return resources;
72:               
73:               return null;
74:           }
75:           
76:           public static string GetString(string name)
77:           {
78:               if (localstrings != null && localstrings[name] != null)
79:                   return localstrings[name].ToString();
80:               return strings.GetString(name);
81:           }
82:           
83:           public static Icon GetIcon(string name)
84:           {
85:               object iconobj null;
86:               if (localicons != null && localicons[name] != null) {
87:                   iconobj localicons[name];
88:               else
89:                   iconobj icon.GetObject(name);
90:               
91:               if (iconobj is Icon)
92:                   return (Icon)iconobj;
93:               else 
94:                   return Icon.FromHandle(((Bitmap)iconobj).GetHicon());
95:           }
96:           
97:           public static Bitmap GetBitmap(string name)
98:           {
99:               if (localicons != null && localicons[name] != null)
100:                   return (Bitmap)localicons[name];
101:               return (Bitmap)icon.GetObject(name);
102:           }
103:           
104:   //        /// <returns>ResourceManager != null</returns>
105:   //        public static ResourceManager Strings {
106:   //            get {
107:   //                Debug.Assert(strings != null, "SharpDevelop.Tool.Data.Resources : ResourceManager strings == null");
108:   //                return strings;
109:   //            }
110:   //        }
111:   //        /// <returns>ResourceManager != null</returns>
112:   //        public static ResourceManager Icon {
113:   //            get {
114:   //                Debug.Assert(icon != null, "SharpDevelop.Tool.Data.Resources : ResourceManager icon   == null");
115:   //                return icon;
116:   //            }
117:   //        }
118:           
119:   //        public static XmlDocument StringToXmlDocument(string str)
120:   //        {
121:   //            XmlDocument document = new XmlDocument();
122:   //            document.LoadXml(str);
123:   //            return document;
124:   //        }
125:       }
126:   }

This page was automatically generated by SharpDevelop.