📄 options.cs
字号:
// Options.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Xml;
using System.Windows.Forms;
using System.Reflection;
namespace SharpDevelop.Tool.Data {
public enum IndentStyle {
None,
Auto,
Smart
};
public enum BracketHighlightingStyle {
None,
OnBracket,
AfterBracket
};
/// <summary>
/// This class handles the Options for the IDE, all what can be configured should be
/// loaded/saved by this class
/// </summary>
public class Option
{
static string OPTIONFILENAME = "SharpDevelop-options.xml";
static string OPTIONFILEVERSION = "2.1";
static Hashtable property = new Hashtable();
public static object GetProperty(string key, object defaultvalue)
{
if (!property.ContainsKey(key)) {
property[key] = defaultvalue;
return defaultvalue;
}
return property[key];
}
public static void SetProperty(string key, object val)
{
property[key] = val;
}
public static void WriteOptionsToStream(Stream s)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<?xml version=\"1.0\"?>\n<OPTIONS VERSION = \"" + OPTIONFILEVERSION + "\" />");
XmlElement editoroptions = doc.CreateElement("PROPERTY");
XmlElement specialoptions = doc.CreateElement("SPECIAL");
foreach (DictionaryEntry entry in property) {
if (entry.Value is XmlConvertable) {
XmlConvertable xc = (XmlConvertable)entry.Value;
XmlElement element = xc.ToXmlElement(doc);
XmlElement info = doc.CreateElement("INFO");
XmlAttribute key = doc.CreateAttribute("KEY");
key.InnerText = entry.Key.ToString();
info.Attributes.Append(key);
XmlAttribute type = doc.CreateAttribute("TYPE");
type.InnerText = xc.GetType().ToString();
info.Attributes.Append(type);
info.AppendChild(element);
specialoptions.AppendChild(info);
} else {
XmlElement el = doc.CreateElement(entry.Key.ToString());
el.InnerText = entry.Value.ToString();
editoroptions.AppendChild(el);
}
}
doc.DocumentElement.AppendChild(editoroptions);
doc.DocumentElement.AppendChild(specialoptions);
doc.Save(new StreamWriter(s));
}
public static bool LoadOptionsFromStream(string filename)
{
try {
XmlDocument doc = new XmlDocument();
doc.Load(filename);
if (doc.DocumentElement.Attributes["VERSION"].InnerText != OPTIONFILEVERSION)
return false;
XmlNodeList nodes = doc.DocumentElement["PROPERTY"].ChildNodes;
foreach (XmlElement el in nodes) {
property[el.Name] = el.InnerText;
}
nodes = doc.DocumentElement["SPECIAL"].ChildNodes;
foreach (XmlElement el in nodes) {
string key = el.Attributes["KEY"].InnerText;
string type = el.Attributes["TYPE"].InnerText;
XmlElement node = (XmlElement)el.FirstChild;
XmlConvertable xc = (XmlConvertable)Assembly.GetCallingAssembly().CreateInstance(type);
property[key] = xc.FromXmlElement(node);
}
} catch (Exception e) {
Console.WriteLine(e.StackTrace);
return false;
}
return true;
}
public static void LoadOptions()
{
if (!LoadOptionsFromStream(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\" + OPTIONFILENAME)) {
Console.WriteLine("Options: can't load user defaults, reading system defaults");
if (!LoadOptionsFromStream(Application.StartupPath + "\\options\\" + OPTIONFILENAME)) {
MessageBox.Show("Can't load options file", "Warning",MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
public static void SaveOptions()
{
WriteOptionsToStream(File.Create(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\" + OPTIONFILENAME));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -