OSDN Git Service

pbs.twimg.com の画像URLのフォーマット変更に対応
[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 #nullable enable
28
29 using System;
30 using System.Collections.Generic;
31 using System.ComponentModel;
32 using System.Data;
33 using System.Drawing;
34 using System.Linq;
35 using System.Text;
36 using System.Windows.Forms;
37
38 namespace OpenTween
39 {
40     public partial class AtIdSupplement : OTBaseForm
41     {
42         public string StartsWith { get; set; } = "";
43
44         public string inputText = "";
45         public bool isBack = false;
46         private readonly string startChar = "";
47
48         public void AddItem(string id)
49         {
50             if (!this.TextId.AutoCompleteCustomSource.Contains(id))
51             {
52                 this.TextId.AutoCompleteCustomSource.Add(id);
53             }
54         }
55
56         public void AddRangeItem(string[] ids)
57         {
58             foreach (var id in ids)
59             {
60                 this.AddItem(id);
61             }
62         }
63
64         public List<string> GetItemList()
65         {
66             var ids = new List<string>();
67             for (var i = 0; i < this.TextId.AutoCompleteCustomSource.Count; ++i)
68             {
69                 ids.Add(this.TextId.AutoCompleteCustomSource[i]);
70             }
71             return ids;
72         }
73
74         public int ItemCount
75             => this.TextId.AutoCompleteCustomSource.Count;
76
77         private void ButtonOK_Click(object sender, EventArgs e)
78         {
79             inputText = this.TextId.Text;
80             isBack = false;
81         }
82
83         private void ButtonCancel_Click(object sender, EventArgs e)
84         {
85             inputText = "";
86             isBack = false;
87         }
88
89         private void TextId_KeyDown(object sender, KeyEventArgs e)
90         {
91             if (e.KeyCode == Keys.Back && MyCommon.IsNullOrEmpty(this.TextId.Text))
92             {
93                 inputText = "";
94                 isBack = true;
95                 this.Close();
96             }
97             else if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Tab)
98             {
99                 inputText = this.TextId.Text + " ";
100                 isBack = false;
101                 this.Close();
102             }
103             else if (e.Control && e.KeyCode == Keys.Delete)
104             {
105                 if (!MyCommon.IsNullOrEmpty(this.TextId.Text))
106                 {
107                     var idx = this.TextId.AutoCompleteCustomSource.IndexOf(this.TextId.Text);
108                     if (idx > -1)
109                     {
110                         this.TextId.Text = "";
111                         this.TextId.AutoCompleteCustomSource.RemoveAt(idx);
112                     }
113                 }
114             }
115         }
116
117         private void AtIdSupplement_Load(object sender, EventArgs e)
118         {
119             if (startChar == "#")
120             {
121                 this.ClientSize = new Size(this.TextId.Width, this.TextId.Height); //プロパティで切り替えできるように
122                 this.TextId.ImeMode = ImeMode.Inherit;
123             }
124         }
125
126         private void AtIdSupplement_Shown(object sender, EventArgs e)
127         {
128             TextId.Text = startChar;
129             if (!MyCommon.IsNullOrEmpty(this.StartsWith))
130             {
131                 TextId.Text += this.StartsWith.Substring(0, this.StartsWith.Length);
132             }
133             TextId.SelectionStart = TextId.Text.Length;
134             TextId.Focus();
135         }
136
137         public AtIdSupplement()
138             => this.InitializeComponent();
139
140         public AtIdSupplement(List<string> ItemList, string startCharacter)
141         {
142             InitializeComponent();
143
144             for (var i = 0; i < ItemList.Count; ++i)
145             {
146                 this.TextId.AutoCompleteCustomSource.Add(ItemList[i]);
147             }
148             startChar = startCharacter;
149         }
150
151         private void TextId_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
152         {
153             if (e.KeyCode == Keys.Tab)
154             {
155                 inputText = this.TextId.Text + " ";
156                 isBack = false;
157                 this.Close();
158             }
159         }
160
161         private void AtIdSupplement_FormClosed(object sender, FormClosedEventArgs e)
162         {
163             this.StartsWith = "";
164             if (isBack)
165             {
166                 this.DialogResult = DialogResult.Cancel;
167             }
168             else
169             {
170                 this.DialogResult = DialogResult.OK;
171             }
172         }
173     }
174 }