OSDN Git Service

PostMultipartRequestクラスを追加
[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 #nullable enable
23
24 using System;
25 using System.Collections.Generic;
26 using System.ComponentModel;
27 using System.Data;
28 using System.Drawing;
29 using System.Linq;
30 using System.Text;
31 using System.Windows.Forms;
32 using OpenTween.Models;
33
34 namespace OpenTween
35 {
36     public partial class TabsDialog : OTBaseForm
37     {
38         private readonly TabInformations tabInfo;
39
40         private bool multiSelect = false;
41
42         public bool MultiSelect
43         {
44             get => this.multiSelect;
45             set
46             {
47                 this.multiSelect = value;
48                 this.UpdateTabList();
49             }
50         }
51
52         protected internal record TabListItem(
53             string Label,
54             FilterTabModel? Tab
55         )
56         {
57             public override string ToString()
58                 => this.Label;
59         }
60
61         public TabsDialog(TabInformations tabinformation)
62         {
63             this.InitializeComponent();
64
65             this.tabInfo = tabinformation;
66             this.UpdateTabList();
67         }
68
69         protected void UpdateTabList()
70         {
71             this.TabList.Items.Clear();
72
73             if (this.MultiSelect)
74             {
75                 this.TabList.SelectionMode = SelectionMode.MultiExtended;
76             }
77             else
78             {
79                 this.TabList.SelectionMode = SelectionMode.One;
80
81                 this.TabList.Items.Add(new TabListItem(
82                     Label: Properties.Resources.AddNewTabText1,
83                     Tab: null
84                 ));
85             }
86
87             var tabs = this.tabInfo.Tabs.Append(this.tabInfo.MuteTab);
88
89             foreach (var tab in tabs.OfType<FilterTabModel>())
90             {
91                 this.TabList.Items.Add(new TabListItem(
92                     Label: tab.TabName,
93                     Tab: tab
94                 ));
95             }
96         }
97
98         private void TabList_DoubleClick(object sender, EventArgs e)
99         {
100             if (this.TabList.SelectedIndex == -1) return;
101
102             this.DialogResult = DialogResult.OK;
103             this.Close();
104         }
105
106         private void TabList_SelectedValueChanged(object sender, EventArgs e)
107         {
108             if (this.TabList.SelectedIndex == -1)
109                 this.OK_Button.Enabled = false;
110             else
111                 this.OK_Button.Enabled = true;
112         }
113
114         public FilterTabModel? SelectedTab
115             => this.TabList.SelectedItem is TabListItem item ? item.Tab : null;
116
117         public FilterTabModel[] SelectedTabs
118             => this.TabList.SelectedItems
119                     .Cast<TabListItem>()
120                     .Select(x => x.Tab)
121                     .OfType<FilterTabModel>()
122                     .ToArray();
123     }
124 }