Revision | b34bc4e15708c54345e7db4472fc9a677478c50d (tree) |
---|---|
Zeit | 2011-02-19 14:14:19 |
Autor | azyobuzin <azyobuzin@user...> |
Commiter | azyobuzin |
・@#補完完成
・SortOrderを使うようにした
・SelectCaseのバグを修正
@@ -55,8 +55,9 @@ namespace Azyobuzi.Twirunrun | ||
55 | 55 | this.SelectedIndices.Clear(); |
56 | 56 | indexes.Select(oldIndex => oldIndex + |
57 | 57 | (int)Settings.Instance.OrderType.SelectCase() |
58 | - .Case(OrderTypes.Ascending, () => -1) | |
59 | - .Case(OrderTypes.Descending, () => +1) | |
58 | + .Case(SortOrder.Ascending, () => -1) | |
59 | + .Case(SortOrder.Descending, () => +1) | |
60 | + .Default(() => 0) | |
60 | 61 | .Result |
61 | 62 | ) |
62 | 63 | .ForEach(newIndex => this.SelectedIndices.Add(newIndex)); |
@@ -65,6 +65,7 @@ | ||
65 | 65 | this.textBox1.Name = "textBox1"; |
66 | 66 | this.textBox1.Size = new System.Drawing.Size(150, 150); |
67 | 67 | this.textBox1.TabIndex = 0; |
68 | + this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged); | |
68 | 69 | this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown); |
69 | 70 | this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress); |
70 | 71 | // |
@@ -77,6 +78,7 @@ | ||
77 | 78 | this.listBox1.Name = "listBox1"; |
78 | 79 | this.listBox1.Size = new System.Drawing.Size(96, 100); |
79 | 80 | this.listBox1.TabIndex = 0; |
81 | + this.listBox1.TabStop = false; | |
80 | 82 | // |
81 | 83 | // UpdateStatusTextBox |
82 | 84 | // |
@@ -14,7 +14,19 @@ namespace Azyobuzi.Twirunrun | ||
14 | 14 | public UpdateStatusTextBox() |
15 | 15 | { |
16 | 16 | InitializeComponent(); |
17 | - listBox1.DataSource = Settings.Instance.AtHashtagList; | |
17 | + Settings.Instance.PropertyChanged += (sender, e) => | |
18 | + { | |
19 | + if (e.PropertyName == "AtHashtagList") | |
20 | + { | |
21 | + listBox1.Invoke((MethodInvoker)(() => | |
22 | + { | |
23 | + var selected = listBox1.SelectedItem; | |
24 | + listBox1.Items.Clear(); | |
25 | + listBox1.Items.AddRange(Settings.Instance.AtHashtagList); | |
26 | + listBox1.SelectedItem = selected; | |
27 | + })); | |
28 | + } | |
29 | + }; | |
18 | 30 | } |
19 | 31 | |
20 | 32 | public void Clear() |
@@ -36,26 +48,43 @@ namespace Azyobuzi.Twirunrun | ||
36 | 48 | } |
37 | 49 | } |
38 | 50 | |
39 | - private void textBox1_KeyPress(object sender, KeyPressEventArgs e) | |
51 | + private void textBox1_KeyPress(object sender, KeyPressEventArgs e)//読みにくくて辛い | |
40 | 52 | { |
41 | 53 | if (e.KeyChar == (char)Keys.Back) |
42 | 54 | { |
43 | 55 | if (textBox1.SelectionStart > 0 && "@@##".Contains(textBox1.Text[textBox1.SelectionStart - 1])) |
56 | + { | |
44 | 57 | splitContainer1.Panel2Collapsed = true; |
45 | - else | |
46 | - return; | |
58 | + } | |
59 | + return; | |
47 | 60 | } |
48 | - else if (e.KeyChar == (char)Keys.Delete) | |
61 | + else if (e.KeyChar == (char)Keys.Escape) | |
49 | 62 | { |
50 | - if (textBox1.SelectionStart != textBox1.TextLength && "@@##".Contains(textBox1.Text[textBox1.SelectionStart])) | |
51 | - splitContainer1.Panel2Collapsed = true; | |
52 | - else | |
53 | - return; | |
63 | + splitContainer1.Panel2Collapsed = true; | |
64 | + return; | |
65 | + } | |
66 | + else if (e.KeyChar == (char)Keys.Enter) | |
67 | + { | |
68 | + splitContainer1.Panel2Collapsed = true; | |
69 | + if ((Control.ModifierKeys & Keys.Shift) != Keys.Shift && listBox1.SelectedIndex != -1) | |
70 | + { | |
71 | + int atHashtagStart = textBox1.Text.LastIndexOfAny("@@##".ToArray(), textBox1.SelectionStart - 1); | |
72 | + var selected = listBox1.SelectedItem.ToString(); | |
73 | + textBox1.Text = textBox1.Text.Substring(0, atHashtagStart) + selected + textBox1.Text.Substring(textBox1.SelectionStart); | |
74 | + textBox1.SelectionStart = atHashtagStart + selected.Length; | |
75 | + e.Handled = true; | |
76 | + } | |
77 | + return; | |
54 | 78 | } |
55 | 79 | |
56 | 80 | if ("@@##".Contains(e.KeyChar)) |
57 | - splitContainer1.Panel2Collapsed = false; | |
58 | - else if (!"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ_-0123456789".Contains(e.KeyChar)) | |
81 | + { | |
82 | + if (Settings.Instance.AutoComplete) | |
83 | + splitContainer1.Panel2Collapsed = false; | |
84 | + return; | |
85 | + } | |
86 | + | |
87 | + if (!"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWSYZ_-0123456789".Contains(e.KeyChar)) | |
59 | 88 | splitContainer1.Panel2Collapsed = true; |
60 | 89 | } |
61 | 90 |
@@ -76,11 +105,26 @@ namespace Azyobuzi.Twirunrun | ||
76 | 105 | { |
77 | 106 | if (!splitContainer1.Panel2Collapsed) |
78 | 107 | { |
79 | - if (e.KeyCode == Keys.Down && listBox1.SelectedIndex != listBox1.Items.Count - 1) | |
108 | + if (e.KeyCode == Keys.Down) | |
80 | 109 | listBox1.SelectedIndex++; |
81 | - else if (e.KeyCode == Keys.Up && listBox1.SelectedIndex > -1) | |
110 | + else if (e.KeyCode == Keys.Up) | |
82 | 111 | listBox1.SelectedIndex--; |
83 | 112 | } |
84 | 113 | } |
114 | + | |
115 | + private void textBox1_TextChanged(object sender, EventArgs e) | |
116 | + { | |
117 | + if (!splitContainer1.Panel2Collapsed) | |
118 | + { | |
119 | + int atHashtagStart = textBox1.Text.LastIndexOfAny("@@##".ToArray(), textBox1.SelectionStart - 1); | |
120 | + listBox1.SelectedItem = Settings.Instance.AtHashtagList | |
121 | + .FirstOrDefault(_ => | |
122 | + _.StartsWith( | |
123 | + textBox1.Text.Substring(atHashtagStart, textBox1.SelectionStart - atHashtagStart) | |
124 | + ) | |
125 | + ) | |
126 | + ?? listBox1.SelectedItem; | |
127 | + } | |
128 | + } | |
85 | 129 | } |
86 | 130 | } |
@@ -72,20 +72,16 @@ namespace Azyobuzi.Twirunrun | ||
72 | 72 | #endregion |
73 | 73 | |
74 | 74 | #region OrderByの拡張 |
75 | - public static OrderedParallelQuery<TSource> OrderBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, OrderTypes orderType) | |
75 | + public static ParallelQuery<TSource> OrderBy<TSource, TKey>(this ParallelQuery<TSource> source, Func<TSource, TKey> keySelector, SortOrder orderType) | |
76 | 76 | { |
77 | - var re = (OrderedParallelQuery<TSource>)orderType.SelectCase() | |
78 | - .Case(OrderTypes.Ascending, () => source.OrderBy(keySelector)) | |
79 | - .Case(OrderTypes.Descending, () => source.OrderByDescending(keySelector)) | |
80 | - .Result; | |
81 | - | |
82 | - if (re == null) | |
83 | - throw new ArgumentException("orderTypeが正しくありません。"); | |
84 | - | |
85 | - return re; | |
77 | + return orderType.SelectCase() | |
78 | + .Case(SortOrder.Ascending, () => source.OrderBy(keySelector)) | |
79 | + .Case(SortOrder.Descending, () => source.OrderByDescending(keySelector)) | |
80 | + .Default(() => source) | |
81 | + .Result as ParallelQuery<TSource>; | |
86 | 82 | } |
87 | 83 | |
88 | - public static OrderedParallelQuery<T> OrderBy<T>(this ParallelQuery<T> source, OrderTypes orderType) | |
84 | + public static ParallelQuery<T> OrderBy<T>(this ParallelQuery<T> source, SortOrder orderType) | |
89 | 85 | { |
90 | 86 | return OrderBy(source, o => o, orderType); |
91 | 87 | } |
@@ -308,51 +304,6 @@ namespace Azyobuzi.Twirunrun | ||
308 | 304 | } |
309 | 305 | } |
310 | 306 | |
311 | - //public class StringRegex | |
312 | - //{ | |
313 | - // public StringRegex(string source) | |
314 | - // { | |
315 | - // this._source = source; | |
316 | - // } | |
317 | - | |
318 | - // private string _source; | |
319 | - | |
320 | - // public bool IsMatch(string pattern) | |
321 | - // { | |
322 | - // return Regex.IsMatch(_source, pattern); | |
323 | - // } | |
324 | - | |
325 | - // public Match Match(string pattern) | |
326 | - // { | |
327 | - // return Regex.Match(_source, pattern); | |
328 | - // } | |
329 | - | |
330 | - // public IEnumerable<Match> Matches(string pattern) | |
331 | - // { | |
332 | - // return Regex.Matches(_source, pattern).Cast<Match>(); | |
333 | - // } | |
334 | - | |
335 | - // public string Replace(string pattern, string replacement) | |
336 | - // { | |
337 | - // return Regex.Replace(_source, pattern, replacement); | |
338 | - // } | |
339 | - | |
340 | - // public string Replace(string pattern, MatchEvaluator evaluator) | |
341 | - // { | |
342 | - // return Regex.Replace(_source, pattern, evaluator); | |
343 | - // } | |
344 | - | |
345 | - // public string[] Split(string pattern) | |
346 | - // { | |
347 | - // return Regex.Split(_source, pattern); | |
348 | - // } | |
349 | - | |
350 | - // public override string ToString() | |
351 | - // { | |
352 | - // return _source; | |
353 | - // } | |
354 | - //} | |
355 | - | |
356 | 307 | public class Selecting<T> |
357 | 308 | { |
358 | 309 | public Selecting(T selectObj, Func<T, T, bool> equalsFunc) |
@@ -389,15 +340,21 @@ namespace Azyobuzi.Twirunrun | ||
389 | 340 | |
390 | 341 | public Selecting<T> Default(Action<T> action) |
391 | 342 | { |
392 | - flag = true; | |
393 | - action(selectObj); | |
343 | + if (!flag) | |
344 | + { | |
345 | + flag = true; | |
346 | + action(selectObj); | |
347 | + } | |
394 | 348 | return this; |
395 | 349 | } |
396 | 350 | |
397 | 351 | public Selecting<T> Default(Action action) |
398 | 352 | { |
399 | - flag = true; | |
400 | - action(); | |
353 | + if (!flag) | |
354 | + { | |
355 | + flag = true; | |
356 | + action(); | |
357 | + } | |
401 | 358 | return this; |
402 | 359 | } |
403 | 360 |
@@ -423,15 +380,21 @@ namespace Azyobuzi.Twirunrun | ||
423 | 380 | |
424 | 381 | public Selecting<T> Default(Func<T, object> action) |
425 | 382 | { |
426 | - flag = true; | |
427 | - Result = action(selectObj); | |
383 | + if (!flag) | |
384 | + { | |
385 | + flag = true; | |
386 | + Result = action(selectObj); | |
387 | + } | |
428 | 388 | return this; |
429 | 389 | } |
430 | 390 | |
431 | 391 | public Selecting<T> Default(Func<object> action) |
432 | 392 | { |
433 | - flag = true; | |
434 | - Result = action(); | |
393 | + if (!flag) | |
394 | + { | |
395 | + flag = true; | |
396 | + Result = action(); | |
397 | + } | |
435 | 398 | return this; |
436 | 399 | } |
437 | 400 | } |
@@ -12,6 +12,7 @@ using System.Threading.Tasks; | ||
12 | 12 | using System.Net; |
13 | 13 | using System.Reflection; |
14 | 14 | using Azyobuzi.UserStreamEx; |
15 | +using System.Text.RegularExpressions; | |
15 | 16 | |
16 | 17 | namespace Azyobuzi.Twirunrun |
17 | 18 | { |
@@ -146,10 +147,38 @@ namespace Azyobuzi.Twirunrun | ||
146 | 147 | #endregion |
147 | 148 | timelineTabs.TabPages.AddRange(Settings.Instance.Tabs.Select(tab => tab.CreateTabPage(timelineTabs)).ToArray()); |
148 | 149 | |
150 | + RecentStatusesCollection.Instance.CollectionChanged += (_sender, _e) => | |
151 | + { | |
152 | + var newAtHashtagList = Settings.Instance.AtHashtagList.Concat( | |
153 | + _e.NewItems.Cast<StatusInfo>().SelectMany(_ => | |
154 | + new[] { "@" + _.User.Identifier.ScreenName } | |
155 | + .Concat(_.Text.RegexMatches(@"[@@][a-zA-Z0-9_]+") | |
156 | + .Cast<Match>() | |
157 | + .Select(atMatch => atMatch.ToString()) | |
158 | + .Concat(_.Text.RegexMatches(@"(^|[^\w&])([##][a-zA-Z0-9_\-]+)") | |
159 | + .Cast<Match>() | |
160 | + .Select(hashtagMatch => hashtagMatch.Groups[2].ToString()) | |
161 | + ) | |
162 | + ) | |
163 | + ) | |
164 | + ) | |
165 | + .Select(_ => | |
166 | + { | |
167 | + if (_.FirstOrDefault() == '@') | |
168 | + return "@" + _.Substring(1); | |
169 | + else if (_.FirstOrDefault() == '#') | |
170 | + return "#" + _.Substring(1); | |
171 | + else | |
172 | + return _; | |
173 | + }) | |
174 | + .Distinct() | |
175 | + .ToArray(); | |
176 | + Array.Sort(newAtHashtagList); | |
177 | + Settings.Instance.AtHashtagList = newAtHashtagList; | |
178 | + }; | |
179 | + | |
149 | 180 | Settings.Instance.PropertyChanged += Settings_PropertyChanged; |
150 | - //全設定項目でSettings_PropertyChangedを呼び出す | |
151 | - typeof(Settings).GetProperties().ForEach(property => | |
152 | - Settings_PropertyChanged(Settings.Instance, new PropertyChangedEventArgs(property.Name))); | |
181 | + Settings.Instance.RaiseAllEvents(); | |
153 | 182 | |
154 | 183 | statusBrowser1.Navigate(statusBrowserUri); |
155 | 184 | } |
@@ -1,8 +1,8 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Drawing; |
4 | -using System.Windows.Forms; | |
5 | 4 | using System.Linq; |
5 | +using System.Windows.Forms; | |
6 | 6 | using System.Xml.Serialization; |
7 | 7 | |
8 | 8 | namespace Azyobuzi.Twirunrun |
@@ -513,8 +513,8 @@ namespace Azyobuzi.Twirunrun | ||
513 | 513 | // |
514 | 514 | //並べ替え順 |
515 | 515 | // |
516 | - private OrderTypes orderType = OrderTypes.Descending; | |
517 | - public OrderTypes OrderType | |
516 | + private SortOrder orderType = SortOrder.Descending; | |
517 | + public SortOrder OrderType | |
518 | 518 | { |
519 | 519 | set |
520 | 520 | { |
@@ -773,17 +773,17 @@ namespace Azyobuzi.Twirunrun | ||
773 | 773 | |
774 | 774 | |
775 | 775 | // |
776 | - //@・#の履歴 | |
776 | + //@・#補完 | |
777 | 777 | // |
778 | - private List<string> atHashtagList = new List<string>(); | |
779 | - public List<string> AtHashtagList | |
778 | + private string[] atHashtagList = new string[] { }; | |
779 | + public string[] AtHashtagList | |
780 | 780 | { |
781 | 781 | set |
782 | 782 | { |
783 | 783 | if (!atHashtagList.SequenceEqual(value)) |
784 | 784 | { |
785 | 785 | atHashtagList = value; |
786 | - OnPropertyChanged("AtHashtagList");//あんまり意味無い | |
786 | + OnPropertyChanged("AtHashtagList"); | |
787 | 787 | } |
788 | 788 | } |
789 | 789 | get |
@@ -791,6 +791,23 @@ namespace Azyobuzi.Twirunrun | ||
791 | 791 | return atHashtagList; |
792 | 792 | } |
793 | 793 | } |
794 | + | |
795 | + private bool autoComplete = true; | |
796 | + public bool AutoComplete | |
797 | + { | |
798 | + set | |
799 | + { | |
800 | + if (autoComplete != value) | |
801 | + { | |
802 | + autoComplete = value; | |
803 | + OnPropertyChanged("AutoComplete"); | |
804 | + } | |
805 | + } | |
806 | + get | |
807 | + { | |
808 | + return autoComplete; | |
809 | + } | |
810 | + } | |
794 | 811 | } |
795 | 812 | |
796 | 813 | public class FormSettings : IEquatable<FormSettings> |
@@ -822,20 +839,7 @@ namespace Azyobuzi.Twirunrun | ||
822 | 839 | public enum PostKeys |
823 | 840 | { |
824 | 841 | Enter, |
825 | - CtrlEnter, | |
826 | - ShiftEnter | |
827 | - } | |
828 | - | |
829 | - public enum OrderTypes | |
830 | - { | |
831 | - /// <summary> | |
832 | - /// 昇順 | |
833 | - /// </summary> | |
834 | - Ascending, | |
835 | - /// <summary> | |
836 | - /// 降順 | |
837 | - /// </summary> | |
838 | - Descending | |
842 | + CtrlEnter | |
839 | 843 | } |
840 | 844 | |
841 | 845 | public enum NameTypes |
@@ -1,5 +1,6 @@ | ||
1 | 1 | using System.ComponentModel; |
2 | 2 | using System.IO; |
3 | +using System.Linq; | |
3 | 4 | using System.Windows.Forms; |
4 | 5 | using System.Xml.Serialization; |
5 | 6 |
@@ -61,5 +62,15 @@ namespace Azyobuzi.Twirunrun | ||
61 | 62 | if (PropertyChanged != null) |
62 | 63 | PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
63 | 64 | } |
65 | + | |
66 | + /// <summary> | |
67 | + /// このクラスのすべてのプロパティ名を使用してPropertyChangedイベントを発生させる | |
68 | + /// </summary> | |
69 | + public void RaiseAllEvents() | |
70 | + { | |
71 | + this.GetType().GetProperties() | |
72 | + .Select(property => property.Name) | |
73 | + .ForEach(OnPropertyChanged); | |
74 | + } | |
64 | 75 | } |
65 | 76 | } |