OSDN Git Service

TabsDialogのOKボタンが反応しなくなっている問題の修正
[opentween/open-tween.git] / OpenTween / TabsDialog.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2011      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 // 
10 // This file is part of OpenTween.
11 // 
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 // 
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details. 
21 // 
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 using System;
28 using System.Collections.Generic;
29 using System.ComponentModel;
30 using System.Data;
31 using System.Drawing;
32 using System.Linq;
33 using System.Text;
34 using System.Windows.Forms;
35 using System.Collections.Specialized;
36
37 namespace OpenTween
38 {
39     public partial class TabsDialog : Form
40     {
41         private bool _multiSelect = false;
42         private string _newtabItem = Properties.Resources.AddNewTabText1;
43
44         public TabsDialog()
45         {
46             InitializeComponent();
47         }
48
49         public TabsDialog(bool multiselect)
50         {
51             // この呼び出しはデザイナーで必要です。
52             InitializeComponent();
53
54             // InitializeComponent() 呼び出しの後で初期化を追加します。
55
56             this.MultiSelect = true;
57
58         }
59
60         private void TabsDialog_Load(object sender, EventArgs e)
61         {
62             if (_multiSelect)
63             {
64                 TabList.SelectedIndex = -1;
65             }
66             else
67             {
68                 if (TabList.SelectedIndex == -1) TabList.SelectedIndex = 0;
69             }
70         }
71
72         public void AddTab(string tabName)
73         {
74             foreach (string obj in TabList.Items)
75             {
76                 if (obj == tabName) return;
77             }
78             TabList.Items.Add(tabName);
79         }
80
81         public void RemoveTab(string tabName)
82         {
83             for (int i = 0; i < TabList.Items.Count; i++)
84             {
85                 if (((string)TabList.Items[i]) == tabName)
86                 {
87                     TabList.Items.RemoveAt(i);
88                     return;
89                 }
90             }
91         }
92
93         public void ClearTab()
94         {
95             int startidx = 1;
96
97             if (_multiSelect)
98             {
99                 startidx = 0;
100             }
101             for (int i = startidx; i < TabList.Items.Count; i++)
102             {
103                 TabList.Items.RemoveAt(0);
104             }
105         }
106
107         public string SelectedTabName
108         {
109             get
110             {
111                 if (TabList.SelectedIndex == -1)
112                     return "";
113                 else
114                     return (string)TabList.SelectedItem;
115             }
116         }
117
118         public StringCollection SelectedTabNames
119         {
120             get
121             {
122                 if (TabList.SelectedIndex == -1)
123                 {
124                     return null;
125                 }
126                 else
127                 {
128                     StringCollection ret = new StringCollection();
129                     foreach (object selitem in TabList.SelectedItems)
130                     {
131                         ret.Add((string)selitem);
132                     }
133                     return ret;
134                 }
135             }
136         }
137
138         public bool MultiSelect
139         {
140             get { return _multiSelect; }
141             set
142             {
143                 _multiSelect = value;
144                 if (value)
145                 {
146                     this.TabList.SelectionMode = SelectionMode.MultiExtended;
147                     if (this.TabList.Items[0].ToString() == Properties.Resources.AddNewTabText1)
148                     {
149                         this.TabList.Items.RemoveAt(0);
150                     }
151                 }
152                 else
153                 {
154                     this.TabList.SelectionMode = SelectionMode.One;
155                     if (this.TabList.Items[0].ToString() != Properties.Resources.AddNewTabText1)
156                     {
157                         this.TabList.Items.Insert(0, Properties.Resources.AddNewTabText1);
158                     }
159                 }
160             }
161         }
162
163         private void TabList_SelectedIndexChanged(object sender, EventArgs e)
164         {
165         }
166
167         private void TabList_DoubleClick(object sender, EventArgs e)
168         {
169             if (TabList.SelectedItem == null)
170             {
171                 return;
172             }
173
174             if (TabList.IndexFromPoint(TabList.PointToClient(Control.MousePosition)) == ListBox.NoMatches)
175             {
176                 return;
177             }
178
179             this.DialogResult = DialogResult.OK;
180             this.Close();
181         }
182
183         private void TabsDialog_Shown(object sender, EventArgs e)
184         {
185             TabList.Focus();
186         }
187     }
188 }