ContainerOptions.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:10k
- /*
- * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
- * $Id: ContainerOptions.cs,v 1.2 2005/04/20 08:45:44 okajima Exp $
- */
- using System;
- using System.IO;
- using System.Diagnostics;
- using System.Collections;
- using System.Drawing;
- using System.Text;
- using System.Reflection;
- using System.Globalization;
- using System.Windows.Forms;
- using Poderosa.Toolkit;
- using Poderosa.Communication;
- using Poderosa.Terminal;
- namespace Poderosa.Config {
- internal class ContainerOptions : CommonOptions {
- protected Language _envLanguage; //Windows偺娐嫬偵婎偯偔尵岅 曐懚偼偝傟側偄
- protected Commands _commands;
- protected Rectangle _framePosition;
- [ConfigEnumElement(typeof(OptionPreservePlace), InitialAsInt=(int)OptionPreservePlace.InstalledDir)]
- protected OptionPreservePlace _optionPreservePlace;
- [ConfigStringElement(Initial="")] protected string _defaultKeyDir;
- [ConfigStringElement(Initial="")] protected string _defaultFileDir;
- [ConfigEnumElement(typeof(FormWindowState), InitialAsInt=(int)FormWindowState.Normal)]
- protected FormWindowState _frameState;
- [ConfigBoolElement(Initial=false)] protected bool _guevaraMode;
- [ConfigBoolElement(Initial=true)] protected bool _showWelcomeDialog;
- [ConfigBoolElement(Initial=false)] protected bool _hideDialogForSP1Issue;
-
- [ConfigEnumElement(typeof(GFrameStyle), InitialAsInt=(int)GFrameStyle.Single)]
- protected GFrameStyle _frameStyle;
- [ConfigEnumElement(typeof(TabBarStyle), InitialAsInt=(int)TabBarStyle.MultiRow)]
- protected TabBarStyle _tabBarStyle;
- [ConfigBoolElement(Initial=false)] protected bool _splitterPreservesRatio; //僼儗乕儉傪儕僒僀僘偟偨偲偒僗僾儕僢僞偑楢摦偡傞偐偳偆偐
- [ConfigBoolElement(Initial=true)] protected bool _showToolBar;
- [ConfigBoolElement(Initial=true)] protected bool _showTabBar;
- [ConfigBoolElement(Initial=true)] protected bool _showStatusBar;
- [ConfigIntElement(Initial=8)] protected int _MRUSize;
- [ConfigIntElement(Initial=4)] protected int _serialCount;
-
- [ConfigEnumElement(typeof(CID), InitialAsInt=(int)CID.NOP)] protected CID _actionOnLaunch;
- private static ArrayList _configAttributes;
- public Commands Commands {
- get {
- return _commands;
- }
- set {
- _commands = value;
- GApp.Frame.ApplyHotKeys(value);
- }
- }
- public bool GuevaraMode {
- get {
- return _guevaraMode;
- }
- set {
- _guevaraMode = value;
- }
- }
- public bool HideDialogForSP1Issue {
- get {
- return _hideDialogForSP1Issue;
- }
- set {
- _hideDialogForSP1Issue = value;
- }
- }
- public GFrameStyle FrameStyle {
- get {
- return _frameStyle;
- }
- set {
- _frameStyle = value;
- }
- }
- public Rectangle FramePosition {
- get {
- return _framePosition;
- }
- set {
- _framePosition = value;
- }
- }
- public string DefaultKeyDir {
- get {
- return _defaultKeyDir;
- }
- set {
- _defaultKeyDir = value;
- }
- }
- public string DefaultFileDir {
- get {
- return _defaultFileDir;
- }
- set {
- _defaultFileDir = value;
- }
- }
- public FormWindowState FrameState {
- get {
- return _frameState;
- }
- set {
- _frameState = value;
- }
- }
- public OptionPreservePlace OptionPreservePlace {
- get {
- return _optionPreservePlace;
- }
- set {
- _optionPreservePlace = value;
- }
- }
- public int MRUSize {
- get {
- return _MRUSize;
- }
- set {
- if(value<0 || value>20)
- throw new InvalidOptionException(GApp.Strings.GetString("Message.MRULimit"));
- _MRUSize = value;
- }
- }
- public int SerialCount {
- get {
- return _serialCount;
- }
- set {
- if(value<1 || value>99)
- throw new InvalidOptionException(GApp.Strings.GetString("Message.SerialLimit"));
- _serialCount = value;
- }
- }
- public CID ActionOnLaunch {
- get {
- return _actionOnLaunch;
- }
- set {
- _actionOnLaunch = value;
- }
- }
- public bool SplitterPreservesRatio {
- get {
- return _splitterPreservesRatio;
- }
- set {
- _splitterPreservesRatio = value;
- }
- }
- public bool ShowToolBar {
- get {
- return _showToolBar;
- }
- set {
- _showToolBar = value;
- }
- }
- public bool ShowTabBar {
- get {
- return _showTabBar;
- }
- set {
- _showTabBar = value;
- }
- }
- public bool ShowStatusBar {
- get {
- return _showStatusBar;
- }
- set {
- _showStatusBar = value;
- }
- }
- public TabBarStyle TabBarStyle {
- get {
- return _tabBarStyle;
- }
- set {
- _tabBarStyle = value;
- }
- }
- public Language EnvLanguage {
- get {
- return _envLanguage;
- }
- set {
- _envLanguage = value;
- }
- }
- public bool ShowWelcomeDialog {
- get {
- return _showWelcomeDialog;
- }
- set {
- _showWelcomeDialog = value;
- }
- }
- public ContainerOptions() {
- _envLanguage = GUtil.CurrentLanguage;
- if(_configAttributes==null) InitConfigAttributes();
- }
- public override object Clone() {
- ContainerOptions o = new ContainerOptions();
- CopyTo(o);
- return o;
- }
- public void CopyTo(ContainerOptions o) {
- base.CopyTo(o);
- o._defaultKeyDir = _defaultKeyDir;
- o._defaultFileDir = _defaultFileDir;
- o._framePosition = _framePosition;
- o._frameState = _frameState;
- o._optionPreservePlace = _optionPreservePlace;
- o._frameStyle = _frameStyle;
- o._splitterPreservesRatio = _splitterPreservesRatio;
- o._showToolBar = _showToolBar;
- o._showTabBar = _showTabBar;
- o._showStatusBar = _showStatusBar;
- o._tabBarStyle = _tabBarStyle;
- o._actionOnLaunch = _actionOnLaunch;
- o._MRUSize = _MRUSize;
- o._serialCount = _serialCount;
- o._language = _language;
- o._envLanguage = _envLanguage;
- o._guevaraMode = _guevaraMode;
- o._commands = (Commands)_commands.Clone();
- o._showWelcomeDialog = _showWelcomeDialog;
- }
- private static void InitConfigAttributes() {
- FieldInfo[] fields = typeof(ContainerOptions).GetFields(BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.DeclaredOnly);
- _configAttributes = new ArrayList(fields.Length);
- foreach(FieldInfo field in fields) {
- object[] attrs = field.GetCustomAttributes(typeof(ConfigElementAttribute), true);
- if(attrs.Length!=0) {
- ConfigElementAttribute attr = (ConfigElementAttribute)attrs[0];
- attr.FieldInfo = field;
- _configAttributes.Add(attr);
- }
- }
- }
- public override sealed void Save(ConfigNode parent) {
- ConfigNode node = new ConfigNode("poderosa-container");
- foreach(ConfigElementAttribute attr in _configAttributes) {
- attr.ExportTo(this, node);
- }
- node["framePosition"] = String.Format("{0},{1},{2},{3}", _framePosition.X, _framePosition.Y, _framePosition.Width, _framePosition.Height);
- parent.AddChild(node);
- _commands.Save(parent);
- base.Save(parent);
- }
- public override sealed void Load(ConfigNode parent) {
- ConfigNode node = parent.FindChildConfigNode("poderosa-container");
- if(node!=null) {
- //婎杮偺傾僩儕價儏乕僩
- foreach(ConfigElementAttribute attr in _configAttributes) {
- attr.ImportFrom(this, node);
- }
- }
- //frame state偼暿偺埖偄
- string frame_pos = node==null? null : node.GetValue("framePosition", null);
- bool frame_filled = false;
- if(_frameState==FormWindowState.Normal && frame_pos!=null) {
- string[] t = frame_pos.Split(',');
- if(t.Length==4) {
- _framePosition.X = GUtil.ParseInt(t[0], 0);
- _framePosition.Y = GUtil.ParseInt(t[1], 0);
- _framePosition.Width = GUtil.ParseInt(t[2], 640);
- _framePosition.Height = GUtil.ParseInt(t[3], 480);
- frame_filled = true;
- }
- }
-
- if(!frame_filled) {
- if(_frameState==FormWindowState.Minimized) _frameState = FormWindowState.Normal; //嵟彫壔偱婲摦偟偰傕巇曽側偄偺偱僲乕儅儖偵偡傞
- Rectangle r = Screen.PrimaryScreen.Bounds;
- _framePosition.X = r.Width / 6;
- _framePosition.Y = r.Height / 6;
- _framePosition.Width = r.Width*2 / 3;
- _framePosition.Height = r.Height*2 / 3;
- }
- _commands = new Commands();
- _commands.Load(parent);
- base.Load(parent);
- }
- public override void Init() {
- foreach(ConfigElementAttribute attr in _configAttributes) {
- attr.Reset(this);
- }
-
- Rectangle r = Screen.PrimaryScreen.Bounds;
- _framePosition.X = r.Width / 6;
- _framePosition.Y = r.Height / 6;
- _framePosition.Width = r.Width*2 / 3;
- _framePosition.Height = r.Height*2 / 3;
- _commands = new Commands();
- _commands.Init();
- base.Init();
- }
- }
- /// <summary>
- /// 僼儗乕儉偺僗僞僀儖
- /// </summary>
- /// <remarks>
- /// GFrameStyle偲偄偆柤慜偵側偭偰偄傞偺偼丄System.Windows.Forms偵FrameStyle偲偄偆柤慜偺楍嫇懱偑偡偱偵偁傞偐傜偱偡丅
- /// </remarks>
- [EnumDesc(typeof(GFrameStyle))]
- public enum GFrameStyle {
- /// <summary>
- /// 僔儞僌儖
- /// </summary>
- [EnumValue(Description="Enum.GFrameStyle.Single")] Single, //侾搙偵堦偮偺傒昞帵
- /// <summary>
- /// 嵍塃偵俀暘妱
- /// </summary>
- [EnumValue(Description="Enum.GFrameStyle.DivVertical")] DivVertical, //嵍塃暘妱
- /// <summary>
- /// 忋壓偵俀暘妱
- /// </summary>
- [EnumValue(Description="Enum.GFrameStyle.DivHorizontal")] DivHorizontal, //忋壓暘妱
- [EnumValue(Description="Enum.GFrameStyle.DivVertical3")] DivVertical3, //嵍塃俁暘妱
- [EnumValue(Description="Enum.GFrameStyle.DivHorizontal3")] DivHorizontal3, //忋壓俁暘妱
- [EnumValue(Description="Enum.GFrameStyle.DivQuad")] DivQuad //係暘妱
- }
- [EnumDesc(typeof(TabBarStyle))]
- public enum TabBarStyle {
- [EnumValue(Description="Enum.TabBarStyle.MultiRow")] MultiRow,
- [EnumValue(Description="Enum.TabBarStyle.ScrollButton")] ScrollButton
- }
- [EnumDesc(typeof(OptionPreservePlace))]
- public enum OptionPreservePlace {
- [EnumValue(Description="Enum.OptionPreservePlace.InstalledDir")] InstalledDir,
- [EnumValue(Description="Enum.OptionPreservePlace.AppData")] AppData
- }
- }