OSDN Git Service

using var を使用する
[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 using OpenTween.Models;
31
32 namespace OpenTween
33 {
34     public partial class TabsDialog : OTBaseForm
35     {
36         private readonly TabInformations TabInfo;
37
38         private bool _MultiSelect = false;
39         public bool MultiSelect
40         {
41             get => this._MultiSelect;
42             set { this._MultiSelect = value; this.UpdateTabList(); }
43         }
44
45         protected internal class TabListItem
46         {
47             public TabModel Tab { get; set; }
48             public string Label { get; set; }
49
50             public override string ToString()
51                 => this.Label;
52         }
53
54         public TabsDialog(TabInformations tabinformation)
55         {
56             InitializeComponent();
57
58             this.TabInfo = tabinformation;
59             UpdateTabList();
60         }
61
62         protected void UpdateTabList()
63         {
64             this.TabList.Items.Clear();
65
66             if (this.MultiSelect)
67             {
68                 this.TabList.SelectionMode = SelectionMode.MultiExtended;
69             }
70             else
71             {
72                 this.TabList.SelectionMode = SelectionMode.One;
73
74                 this.TabList.Items.Add(new TabListItem
75                 {
76                     Label = Properties.Resources.AddNewTabText1,
77                     Tab = null,
78                 });
79             }
80
81             foreach (var tab in this.TabInfo.Tabs)
82             {
83                 if (!tab.IsDistributableTabType) continue;
84
85                 this.TabList.Items.Add(new TabListItem
86                 {
87                     Label = tab.TabName,
88                     Tab = tab,
89                 });
90             }
91         }
92
93         private void TabList_DoubleClick(object sender, EventArgs e)
94         {
95             if (this.TabList.SelectedIndex == -1) return;
96
97             this.DialogResult = DialogResult.OK;
98             this.Close();
99         }
100
101         private void TabList_SelectedValueChanged(object sender, EventArgs e)
102         {
103             if (this.TabList.SelectedIndex == -1)
104                 this.OK_Button.Enabled = false;
105             else
106                 this.OK_Button.Enabled = true;
107         }
108
109         public TabModel SelectedTab
110             => this.TabList.SelectedItem is TabListItem item ? item.Tab : null;
111
112         public TabModel[] SelectedTabs
113             => this.TabList.SelectedItems
114                     .Cast<TabListItem>()
115                     .Select(x => x.Tab)
116                     .ToArray();
117     }
118 }