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 = "";
45 public bool isBack = false;
46 private readonly string startChar = "";
48 public void AddItem(string id)
50 if (!this.TextId.AutoCompleteCustomSource.Contains(id))
52 this.TextId.AutoCompleteCustomSource.Add(id);
56 public void AddRangeItem(string[] ids)
58 foreach (var id in ids)
64 public List<string> GetItemList()
66 var ids = new List<string>();
67 for (var i = 0; i < this.TextId.AutoCompleteCustomSource.Count; ++i)
69 ids.Add(this.TextId.AutoCompleteCustomSource[i]);
75 => this.TextId.AutoCompleteCustomSource.Count;
77 private void ButtonOK_Click(object sender, EventArgs e)
79 inputText = this.TextId.Text;
83 private void ButtonCancel_Click(object sender, EventArgs e)
89 private void TextId_KeyDown(object sender, KeyEventArgs e)
91 if (e.KeyCode == Keys.Back && MyCommon.IsNullOrEmpty(this.TextId.Text))
97 else if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Tab)
99 inputText = this.TextId.Text + " ";
103 else if (e.Control && e.KeyCode == Keys.Delete)
105 if (!MyCommon.IsNullOrEmpty(this.TextId.Text))
107 var idx = this.TextId.AutoCompleteCustomSource.IndexOf(this.TextId.Text);
110 this.TextId.Text = "";
111 this.TextId.AutoCompleteCustomSource.RemoveAt(idx);
117 private void AtIdSupplement_Load(object sender, EventArgs e)
119 if (startChar == "#")
121 this.ClientSize = new Size(this.TextId.Width, this.TextId.Height); //プロパティで切り替えできるように
122 this.TextId.ImeMode = ImeMode.Inherit;
126 private void AtIdSupplement_Shown(object sender, EventArgs e)
128 TextId.Text = startChar;
129 if (!MyCommon.IsNullOrEmpty(this.StartsWith))
131 TextId.Text += this.StartsWith.Substring(0, this.StartsWith.Length);
133 TextId.SelectionStart = TextId.Text.Length;
137 public AtIdSupplement()
138 => this.InitializeComponent();
140 public AtIdSupplement(List<string> ItemList, string startCharacter)
142 InitializeComponent();
144 for (var i = 0; i < ItemList.Count; ++i)
146 this.TextId.AutoCompleteCustomSource.Add(ItemList[i]);
148 startChar = startCharacter;
151 private void TextId_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
153 if (e.KeyCode == Keys.Tab)
155 inputText = this.TextId.Text + " ";
161 private void AtIdSupplement_FormClosed(object sender, FormClosedEventArgs e)
163 this.StartsWith = "";
166 this.DialogResult = DialogResult.Cancel;
170 this.DialogResult = DialogResult.OK;