OSDN Git Service

PostClass.CreatedAtの型をDateTimeUtcに変更
[opentween/open-tween.git] / OpenTween / AtIdSupplement.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      Egtra (@egtra) <http://dev.activebasic.com/egtra/>
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
36 namespace OpenTween
37 {
38     public partial class AtIdSupplement : OTBaseForm
39     {
40         public string inputText = "";
41         public bool isBack = false;
42         private string startChar = "";
43         //    private bool tabkeyFix = false;
44
45         private string _StartsWith = "";
46
47         public void AddItem(string id)
48         {
49             if (!this.TextId.AutoCompleteCustomSource.Contains(id))
50             {
51                 this.TextId.AutoCompleteCustomSource.Add(id);
52             }
53         }
54
55         public void AddRangeItem(string[] ids)
56         {
57             foreach (var id in ids)
58             {
59                 this.AddItem(id);
60             }
61         }
62
63         public List<string> GetItemList()
64         {
65             var ids = new List<string>();
66             for (int i = 0; i < this.TextId.AutoCompleteCustomSource.Count; ++i)
67             {
68                 ids.Add(this.TextId.AutoCompleteCustomSource[i]);
69             }
70             return ids;
71         }
72
73         public int ItemCount
74         {
75             get
76             {
77                 return this.TextId.AutoCompleteCustomSource.Count;
78             }
79         }
80
81         private void ButtonOK_Click(object sender, EventArgs e) /*Handles ButtonOK.Click*/
82         {
83             inputText = this.TextId.Text;
84             isBack = false;
85         }
86
87         private void ButtonCancel_Click(object sender, EventArgs e) /*Handles ButtonCancel.Click*/
88         {
89             inputText = "";
90             isBack = false;
91         }
92
93         private void TextId_KeyDown(object sender, KeyEventArgs e) /*Handles TextId.KeyDown*/
94         {
95             if (e.KeyCode == Keys.Back && string.IsNullOrEmpty(this.TextId.Text))
96             {
97                 inputText = "";
98                 isBack = true;
99                 this.Close();
100             }
101             else if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Tab)
102             {
103                 inputText = this.TextId.Text + " ";
104                 isBack = false;
105                 this.Close();
106             }
107             else if (e.Control && e.KeyCode == Keys.Delete)
108             {
109                 if (!string.IsNullOrEmpty(this.TextId.Text))
110                 {
111                     var idx = this.TextId.AutoCompleteCustomSource.IndexOf(this.TextId.Text);
112                     if (idx > -1)
113                     {
114                         this.TextId.Text = "";
115                         this.TextId.AutoCompleteCustomSource.RemoveAt(idx);
116                     }
117                 }
118             }
119         }
120
121         private void AtIdSupplement_Load(object sender, EventArgs e) /*Handles this.Load*/
122         {
123             if (startChar == "#")
124             {
125                 this.ClientSize = new Size(this.TextId.Width, this.TextId.Height); //プロパティで切り替えできるように
126                 this.TextId.ImeMode = ImeMode.Inherit;
127             }
128         }
129
130         private void AtIdSupplement_Shown(object sender, EventArgs e) /*Handles this.Shown*/
131         {
132             TextId.Text = startChar;
133             if (!string.IsNullOrEmpty(_StartsWith))
134             {
135                 TextId.Text += _StartsWith.Substring(0, _StartsWith.Length);
136             }
137             TextId.SelectionStart = TextId.Text.Length;
138             TextId.Focus();
139         }
140
141         public AtIdSupplement()
142         {
143             InitializeComponent();
144         }
145
146         public AtIdSupplement(List<string> ItemList, string startCharacter)
147         {
148             InitializeComponent();
149
150             for (int i = 0; i < ItemList.Count; ++i)
151             {
152                 this.TextId.AutoCompleteCustomSource.Add(ItemList[i]);
153             }
154             startChar = startCharacter;
155         }
156
157         private void TextId_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) /*Handles TextId.PreviewKeyDown*/
158         {
159             if (e.KeyCode == Keys.Tab)
160             {
161                 inputText = this.TextId.Text + " ";
162                 isBack = false;
163                 this.Close();
164             }
165         }
166
167         public string StartsWith
168         {
169             get
170             {
171                 return _StartsWith;
172             }
173             set
174             {
175                 _StartsWith = value;
176             }
177         }
178
179         private void AtIdSupplement_FormClosed(object sender, FormClosedEventArgs e) /*Handles MyBase.FormClosed*/
180         {
181             _StartsWith = "";
182             if (isBack)
183             {
184                 this.DialogResult = DialogResult.Cancel;
185             }
186             else
187             {
188                 this.DialogResult = DialogResult.OK;
189             }
190         }
191     }
192 }