/// <summary>
        /// レイアウト設定ファイルを読み込み
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static LayoutParam Load(string fileName)
        {
            LayoutParam param = new LayoutParam();

            try
            {
                var xml = XDocument.Load(fileName);

                var layout = xml.Element(ElementNameLayout);

                var tabs = layout.Elements(ElementNameTab);

                param.Tabs = new List <LayoutParam.Tab>();
                foreach (var tab in tabs)
                {
                    var layoutTab = new LayoutParam.Tab();
                    layoutTab.Label   = tab.Attribute(AttributeLabel)?.Value;
                    layoutTab.Name    = tab.Attribute(AttributeName)?.Value;
                    layoutTab.KeySets = new List <LayoutParam.KeySet>();

                    var keysets = tab.Elements(ElementNameKeySet);
                    foreach (var keyset in keysets)
                    {
                        var layoutKeyset = new LayoutParam.KeySet();
                        layoutKeyset.Label   = keyset.Attribute(AttributeLabel)?.Value;
                        layoutKeyset.Name    = keyset.Attribute(AttributeName)?.Value;
                        layoutKeyset.KeyText = keyset.Value;
                        layoutTab.KeySets.Add(layoutKeyset);
                    }
                    param.Tabs.Add(layoutTab);
                }

                var skin       = layout.Element(ElementNameSkin);
                var skinSet    = new LayoutParam.SkinSet();
                var skinKeyset = skin?.Element(ElementNameKeySet);
                skinSet.KeyColor            = new LayoutParam.SkinSet.Key();
                skinSet.KeyColor.Label      = TranslateColor(skinKeyset?.Element(ElementNameLabel)?.Value, SystemColors.ControlText);
                skinSet.KeyColor.Text       = TranslateColor(skinKeyset?.Element(ElementNameText)?.Value, SystemColors.ControlText);
                skinSet.KeyColor.Textbox    = TranslateColor(skinKeyset?.Element(ElementNameTextbox)?.Value, SystemColors.Control);
                skinSet.KeyColor.Background = TranslateColor(skinKeyset?.Element(ElementNameBackground)?.Value, SystemColors.Window);
                var skinPanel = skin?.Element(ElementNamePanel);
                skinSet.PanelColor            = new LayoutParam.SkinSet.Panel();
                skinSet.PanelColor.Label      = TranslateColor(skinPanel?.Element(ElementNameLabel)?.Value, SystemColors.ControlText);
                skinSet.PanelColor.Background = TranslateColor(skinPanel?.Element(ElementNameBackground)?.Value, SystemColors.Control);

                param.Skin = skinSet;
            }
            catch
            {
                return(null);
            }
            return(param);
        }
Exemplo n.º 2
0
        /// <summary>
        /// LayoutParam が正しいかをチェックする
        /// </summary>
        /// <param name="layout"></param>
        /// <returns></returns>
        private bool CheckLayoutParam(LayoutParam layout)
        {
            if (layout == null)
            {
                MessageBox.Show(
                    "レイアウト設定ファイルの読み込みに失敗しました。",
                    Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            foreach (var layoutTabA in layout.Tabs)
            {
                if (string.IsNullOrWhiteSpace(layoutTabA.Name))
                {
                    MessageBox.Show(
                        "「" + layoutTabA.Label + "」の識別名が未入力です。",
                        Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (var layoutTabB in layout.Tabs)
                {
                    if (layoutTabA == layoutTabB)
                    {
                        continue;
                    }

                    if (layoutTabA.Name == layoutTabB.Name)
                    {
                        MessageBox.Show(
                            "「" + layoutTabA.Label + "」と「" + layoutTabB.Label + "」の識別名が重複しています。",
                            Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }
            }

            foreach (var layoutTab in layout.Tabs)
            {
                foreach (var layoutKeySetA in layoutTab.KeySets)
                {
                    if (string.IsNullOrWhiteSpace(layoutKeySetA.Name))
                    {
                        MessageBox.Show(
                            "タブ「" + layoutTab.Label + "」の「" + layoutKeySetA.Label + "」の識別名が未入力です。",
                            Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }

                    foreach (var layoutKeySetB in layoutTab.KeySets)
                    {
                        if (layoutKeySetA == layoutKeySetB)
                        {
                            continue;
                        }

                        if (layoutKeySetA.Name == layoutKeySetB.Name)
                        {
                            MessageBox.Show(
                                "タブ「" + layoutTab.Label + "」の「" + layoutKeySetA.Label + "」と「" + layoutKeySetB.Label + "」の識別名が重複しています。",
                                Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }