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.
10 // This file is part of OpenTween.
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)
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
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.
30 using System.Collections.Generic;
31 using System.ComponentModel;
36 using System.Windows.Forms;
40 public partial class AtIdSupplement : OTBaseForm
42 public string StartsWith { get; set; } = "";
44 public string InputText { get; set; } = "";
46 private bool isBack = false;
47 private readonly string startChar = "";
49 public void AddItem(string id)
51 if (!this.TextId.AutoCompleteCustomSource.Contains(id))
53 this.TextId.AutoCompleteCustomSource.Add(id);
57 public void AddRangeItem(string[] ids)
59 foreach (var id in ids)
65 public List<string> GetItemList()
67 var ids = new List<string>();
68 for (var i = 0; i < this.TextId.AutoCompleteCustomSource.Count; ++i)
70 ids.Add(this.TextId.AutoCompleteCustomSource[i]);
76 => this.TextId.AutoCompleteCustomSource.Count;
78 private void ButtonOK_Click(object sender, EventArgs e)
80 this.InputText = this.TextId.Text;
84 private void ButtonCancel_Click(object sender, EventArgs e)
90 private void TextId_KeyDown(object sender, KeyEventArgs e)
92 if (e.KeyCode == Keys.Back && MyCommon.IsNullOrEmpty(this.TextId.Text))
98 else if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Tab)
100 this.InputText = this.TextId.Text + " ";
104 else if (e.Control && e.KeyCode == Keys.Delete)
106 if (!MyCommon.IsNullOrEmpty(this.TextId.Text))
108 var idx = this.TextId.AutoCompleteCustomSource.IndexOf(this.TextId.Text);
111 this.TextId.Text = "";
112 this.TextId.AutoCompleteCustomSource.RemoveAt(idx);
118 private void AtIdSupplement_Load(object sender, EventArgs e)
120 if (this.startChar == "#")
122 this.ClientSize = new Size(this.TextId.Width, this.TextId.Height); // プロパティで切り替えできるように
123 this.TextId.ImeMode = ImeMode.Inherit;
127 private void AtIdSupplement_Shown(object sender, EventArgs e)
129 this.TextId.Text = this.startChar;
130 if (!MyCommon.IsNullOrEmpty(this.StartsWith))
132 this.TextId.Text += this.StartsWith.Substring(0, this.StartsWith.Length);
134 this.TextId.SelectionStart = this.TextId.Text.Length;
138 public AtIdSupplement()
139 => this.InitializeComponent();
141 public AtIdSupplement(List<string> itemList, string startCharacter)
143 this.InitializeComponent();
145 for (var i = 0; i < itemList.Count; ++i)
147 this.TextId.AutoCompleteCustomSource.Add(itemList[i]);
149 this.startChar = startCharacter;
152 private void TextId_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
154 if (e.KeyCode == Keys.Tab)
156 this.InputText = this.TextId.Text + " ";
162 private void AtIdSupplement_FormClosed(object sender, FormClosedEventArgs e)
164 this.StartsWith = "";
167 this.DialogResult = DialogResult.Cancel;
171 this.DialogResult = DialogResult.OK;