OSDN Git Service

デフォルトのUIフォントに MessageBoxText を使用する
[opentween/open-tween.git] / OpenTween / TabsDialog.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System;
23 using System.Collections.Generic;
24 using System.ComponentModel;
25 using System.Data;
26 using System.Drawing;
27 using System.Linq;
28 using System.Text;
29 using System.Windows.Forms;
30
31 namespace OpenTween
32 {
33     public partial class TabsDialog : OTBaseForm
34     {
35         private readonly TabInformations TabInfo;
36
37         private bool _MultiSelect = false;
38         public bool MultiSelect
39         {
40             get { return this._MultiSelect; }
41             set { this._MultiSelect = value; this.UpdateTabList(); }
42         }
43
44         protected internal class TabListItem
45         {
46             public TabClass Tab { get; set; }
47             public string Label { get; set; }
48
49             public override string ToString()
50             {
51                 return this.Label;
52             }
53         }
54
55         public TabsDialog(TabInformations tabinformation)
56         {
57             InitializeComponent();
58
59             this.TabInfo = tabinformation;
60             UpdateTabList();
61         }
62
63         protected void UpdateTabList()
64         {
65             this.TabList.Items.Clear();
66
67             if (this.MultiSelect)
68             {
69                 this.TabList.SelectionMode = SelectionMode.MultiExtended;
70             }
71             else
72             {
73                 this.TabList.SelectionMode = SelectionMode.One;
74
75                 this.TabList.Items.Add(new TabListItem
76                 {
77                     Label = Properties.Resources.AddNewTabText1,
78                     Tab = null,
79                 });
80             }
81
82             foreach (var tab in this.TabInfo.Tabs)
83             {
84                 if (!this.TabInfo.IsDistributableTab(tab.Key)) continue;
85
86                 this.TabList.Items.Add(new TabListItem
87                 {
88                     Label = tab.Key,
89                     Tab = tab.Value,
90                 });
91             }
92         }
93
94         private void TabList_DoubleClick(object sender, EventArgs e)
95         {
96             if (this.TabList.SelectedIndex == -1) return;
97
98             this.DialogResult = DialogResult.OK;
99             this.Close();
100         }
101
102         private void TabList_SelectedValueChanged(object sender, EventArgs e)
103         {
104             if (this.TabList.SelectedIndex == -1)
105                 this.OK_Button.Enabled = false;
106             else
107                 this.OK_Button.Enabled = true;
108         }
109
110         public TabClass SelectedTab
111         {
112             get
113             {
114                 var item = this.TabList.SelectedItem as TabListItem;
115                 if (item == null) return null;
116
117                 return item.Tab;
118             }
119         }
120
121         public TabClass[] SelectedTabs
122         {
123             get
124             {
125                 return this.TabList.SelectedItems
126                     .Cast<TabListItem>()
127                     .Select(x => x.Tab)
128                     .ToArray();
129             }
130         }
131     }
132 }