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 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
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.
28 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
29 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
32 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Diagnostics;
40 using System.Net.Http;
41 using System.Reflection;
43 using System.Text.RegularExpressions;
44 using System.Threading;
45 using System.Threading.Tasks;
46 using System.Windows.Forms;
48 using OpenTween.Connection;
49 using OpenTween.OpenTweenCustomControl;
50 using OpenTween.Thumbnail;
54 public partial class TweenMain : OTBaseForm
57 private Size _mySize; //画面サイズ
58 private Point _myLoc; //画面位置
59 private int _mySpDis; //区切り位置
60 private int _mySpDis2; //発言欄区切り位置
61 private int _mySpDis3; //プレビュー区切り位置
62 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
63 private bool _iconCol; //1列表示の時true(48サイズのとき)
66 private bool _initial; //true:起動時処理中
67 private bool _initialLayout = true;
68 private bool _ignoreConfigSave; //true:起動時処理中
69 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
70 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
71 private Point _tabMouseDownPoint;
72 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
73 private readonly object _syncObject = new object(); //ロック用
74 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
75 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
76 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
77 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
78 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
79 private const string detailHtmlFormatMono6 = ");\"><pre>";
80 private const string detailHtmlFormatMono7 = "</pre></body></html>";
81 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
82 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
83 private const string detailHtmlFormat7 = "</span></p></body></html>";
84 private string detailHtmlFormatHeader;
85 private string detailHtmlFormatFooter;
86 private bool _myStatusError = false;
87 private bool _myStatusOnline = false;
88 private bool soundfileListup = false;
89 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
92 //private SettingToConfig _cfg; //旧
93 private SettingLocal _cfgLocal;
94 private SettingCommon _cfgCommon;
95 private bool _modifySettingLocal = false;
96 private bool _modifySettingCommon = false;
97 private bool _modifySettingAtId = false;
100 private Twitter tw = new Twitter();
103 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
106 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
107 private SearchWordDialog SearchDialog = new SearchWordDialog(); //検索画面インスタンス
108 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
109 private OpenURL UrlDialog = new OpenURL();
110 public AtIdSupplement AtIdSupl; //@id補助
111 public AtIdSupplement HashSupl; //Hashtag補助
112 public HashtagManage HashMgr;
113 private EventViewerDialog evtDialog;
116 private Font _fntUnread; //未読用フォント
117 private Color _clUnread; //未読用文字色
118 private Font _fntReaded; //既読用フォント
119 private Color _clReaded; //既読用文字色
120 private Color _clFav; //Fav用文字色
121 private Color _clOWL; //片思い用文字色
122 private Color _clRetweet; //Retweet用文字色
123 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
124 private Font _fntDetail; //発言詳細部用フォント
125 private Color _clDetail; //発言詳細部用色
126 private Color _clDetailLink; //発言詳細部用リンク文字色
127 private Color _clDetailBackcolor; //発言詳細部用背景色
128 private Color _clSelf; //自分の発言用背景色
129 private Color _clAtSelf; //自分宛返信用背景色
130 private Color _clTarget; //選択発言者の他の発言用背景色
131 private Color _clAtTarget; //選択発言中の返信先用背景色
132 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
133 private Color _clAtTo; //選択発言の唯一@先
134 private Color _clListBackcolor; //リスト部通常発言背景色
135 private Color _clInputBackcolor; //入力欄背景色
136 private Color _clInputFont; //入力欄文字色
137 private Font _fntInputFont; //入力欄フォント
138 private ImageCache IconCache; //アイコン画像リスト
139 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
140 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
141 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
142 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
143 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
144 private Icon MainIcon; //Main.ico 画面左上のアイコン
145 private Icon ReplyIcon; //5g
146 private Icon ReplyIconBlink; //6g
148 private ImageList _listViewImageList = new ImageList(); //ListViewItemの高さ変更用
150 private PostClass _anchorPost;
151 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
153 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
154 private int _hisIdx; //発言履歴カレントインデックス
156 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
157 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
158 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
161 private List<DateTime> _postTimestamps = new List<DateTime>();
162 private List<DateTime> _favTimestamps = new List<DateTime>();
163 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
164 private int _tlCount;
167 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
168 private SolidBrush _brsBackColorMine;
169 private SolidBrush _brsBackColorAt;
170 private SolidBrush _brsBackColorYou;
171 private SolidBrush _brsBackColorAtYou;
172 private SolidBrush _brsBackColorAtFromTarget;
173 private SolidBrush _brsBackColorAtTo;
174 private SolidBrush _brsBackColorNone;
175 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
176 private StringFormat sfTab = new StringFormat();
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////
179 private ToolStripAPIGauge _apiGauge;
180 private TabInformations _statuses;
182 // ListViewItem のキャッシュ関連
183 private int _itemCacheIndex;
184 private ListViewItem[] _itemCache;
185 private PostClass[] _postCache;
186 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
188 private TabPage _curTab;
189 private int _curItemIndex;
190 private DetailsListView _curList;
191 private PostClass _curPost;
192 private bool _isColumnChanged = false;
193 private bool _waitTimeline = false;
194 private bool _waitReply = false;
195 private bool _waitDm = false;
196 private bool _waitFav = false;
197 private bool _waitPubSearch = false;
198 private bool _waitUserTimeline = false;
199 private bool _waitLists = false;
200 private BackgroundWorker[] _bw = new BackgroundWorker[20];
201 private BackgroundWorker _bwFollower;
203 private int UnreadCounter = -1;
204 private int UnreadAtCounter = -1;
206 private string[] ColumnOrgText = new string[9];
207 private string[] ColumnText = new string[9];
209 private bool _DoFavRetweetFlags = false;
210 private bool osResumed = false;
212 //////////////////////////////////////////////////////////////////////////////////////////////////////////
213 private string _postBrowserStatusText = "";
215 private bool _colorize = false;
217 private System.Timers.Timer TimerTimeline = new System.Timers.Timer();
219 private ImageListViewItem displayItem;
222 /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
224 protected SizeF currentScaleFactor = new SizeF();
227 private struct urlUndo
229 public string Before;
233 private List<urlUndo> urlUndoBuffer = null;
235 private struct ReplyChain
237 public long OriginalId;
238 public long InReplyToId;
239 public TabPage OriginalTab;
241 public ReplyChain(long originalId, long inReplyToId, TabPage originalTab)
243 this.OriginalId = originalId;
244 this.InReplyToId = inReplyToId;
245 this.OriginalTab = originalTab;
249 private Stack<ReplyChain> replyChains; //[, ]でのリプライ移動の履歴
250 private Stack<Tuple<TabPage, PostClass>> selectPostChains = new Stack<Tuple<TabPage, PostClass>>(); //ポスト選択履歴
252 //Backgroundworkerの処理結果通知用引数構造体
253 private class GetWorkerResult
255 public string retMsg = ""; //処理結果詳細メッセージ。エラー時に値がセットされる
256 public MyCommon.WORKERTYPE type; //処理種別
257 public string tName = ""; //Fav追加・削除時のタブ名
258 public List<long> sIds = null; //Fav追加・削除成功分のID
259 public bool newDM = false;
261 public PostingStatus status;
264 //Backgroundworkerへ処理内容を通知するための引数用構造体
265 private class GetWorkerArg
267 public int page; //処理対象ページ番号
268 public MyCommon.WORKERTYPE type; //処理種別
269 public PostingStatus status = new PostingStatus(); //発言POST時の発言内容
270 public List<long> ids; //Fav追加・削除時のItemIndex
271 public List<long> sIds; //Fav追加・削除成功分のItemIndex
272 public string tName = ""; //Fav追加・削除時のタブ名
276 private enum SEARCHTYPE
283 private class PostingStatus
285 public string status = "";
286 public long? inReplyToId = null;
287 public string inReplyToName = null;
288 public string imageService = ""; //画像投稿サービス名
289 public string[] imagePath = null;
290 public PostingStatus()
293 public PostingStatus(string status, long? replyToId, string replyToName)
295 this.status = status;
296 this.inReplyToId = replyToId;
297 this.inReplyToName = replyToName;
301 private void TweenMain_Activated(object sender, EventArgs e)
303 //画面がアクティブになったら、発言欄の背景色戻す
304 if (StatusText.Focused)
306 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
310 private bool disposed = false;
313 /// 使用中のリソースをすべてクリーンアップします。
315 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
316 protected override void Dispose(bool disposing)
318 base.Dispose(disposing);
325 if (this.components != null)
326 this.components.Dispose();
329 SettingDialog.Dispose();
330 SearchDialog.Dispose();
333 if (NIconAt != null) NIconAt.Dispose();
334 if (NIconAtRed != null) NIconAtRed.Dispose();
335 if (NIconAtSmoke != null) NIconAtSmoke.Dispose();
336 if (NIconRefresh[0] != null) NIconRefresh[0].Dispose();
337 if (NIconRefresh[1] != null) NIconRefresh[1].Dispose();
338 if (NIconRefresh[2] != null) NIconRefresh[2].Dispose();
339 if (NIconRefresh[3] != null) NIconRefresh[3].Dispose();
340 if (TabIcon != null) TabIcon.Dispose();
341 if (MainIcon != null) MainIcon.Dispose();
342 if (ReplyIcon != null) ReplyIcon.Dispose();
343 if (ReplyIconBlink != null) ReplyIconBlink.Dispose();
344 _listViewImageList.Dispose();
345 _brsHighLight.Dispose();
346 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
347 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
348 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
349 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
350 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
351 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
352 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
353 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
356 foreach (BackgroundWorker bw in _bw)
361 if (_bwFollower != null)
363 _bwFollower.Dispose();
365 this._apiGauge.Dispose();
366 if (IconCache != null)
368 this.IconCache.CancelAsync();
369 this.IconCache.Dispose();
372 if (this.thumbnailTokenSource != null)
373 this.thumbnailTokenSource.Dispose();
375 this.itemCacheLock.Dispose();
377 this._hookGlobalHotkey.Dispose();
380 // 終了時にRemoveHandlerしておかないとメモリリークする
381 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
382 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
384 this.disposed = true;
387 private void LoadIcon(ref Icon IconInstance, string FileName)
389 string dir = Application.StartupPath;
390 if (File.Exists(Path.Combine(dir, FileName)))
394 IconInstance = new Icon(Path.Combine(dir, FileName));
402 private void LoadIcons()
406 string dir = Application.StartupPath;
408 NIconAt = Properties.Resources.At;
409 NIconAtRed = Properties.Resources.AtRed;
410 NIconAtSmoke = Properties.Resources.AtSmoke;
411 NIconRefresh[0] = Properties.Resources.Refresh;
412 NIconRefresh[1] = Properties.Resources.Refresh2;
413 NIconRefresh[2] = Properties.Resources.Refresh3;
414 NIconRefresh[3] = Properties.Resources.Refresh4;
415 TabIcon = Properties.Resources.TabIcon;
416 MainIcon = Properties.Resources.MIcon;
417 ReplyIcon = Properties.Resources.Reply;
418 ReplyIconBlink = Properties.Resources.ReplyBlink;
420 if (!Directory.Exists(Path.Combine(dir, "Icons")))
423 LoadIcon(ref NIconAt, "Icons\\At.ico");
426 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
429 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
432 //アニメーション対応により4種類読み込み
433 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
434 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
435 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
436 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
439 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
442 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
445 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
448 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
451 private void InitColumns(ListView list, bool startup)
453 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
454 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
455 ColumnHeader _colHd3 = new ColumnHeader(); //本文
456 ColumnHeader _colHd4 = new ColumnHeader(); //日付
457 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
458 ColumnHeader _colHd6 = new ColumnHeader(); //未読
459 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
460 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
464 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
468 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
472 _colHd1.Text = ColumnText[0];
474 _colHd2.Text = ColumnText[1];
476 _colHd3.Text = ColumnText[2];
478 _colHd4.Text = ColumnText[3];
480 _colHd5.Text = ColumnText[4];
482 _colHd6.Text = ColumnText[5];
484 _colHd7.Text = ColumnText[6];
486 _colHd8.Text = ColumnText[7];
489 int[] dispOrder = new int[8];
492 for (int i = 0; i < _curList.Columns.Count; i++)
494 for (int j = 0; j < _curList.Columns.Count; j++)
496 if (_curList.Columns[j].DisplayIndex == i)
503 for (int i = 0; i < _curList.Columns.Count; i++)
505 list.Columns[i].Width = _curList.Columns[i].Width;
506 list.Columns[dispOrder[i]].DisplayIndex = i;
513 list.Columns[0].Width = _cfgLocal.Width1;
514 list.Columns[1].Width = _cfgLocal.Width3;
515 list.Columns[0].DisplayIndex = 0;
516 list.Columns[1].DisplayIndex = 1;
520 for (int i = 0; i <= 7; i++)
522 if (_cfgLocal.DisplayIndex1 == i)
524 else if (_cfgLocal.DisplayIndex2 == i)
526 else if (_cfgLocal.DisplayIndex3 == i)
528 else if (_cfgLocal.DisplayIndex4 == i)
530 else if (_cfgLocal.DisplayIndex5 == i)
532 else if (_cfgLocal.DisplayIndex6 == i)
534 else if (_cfgLocal.DisplayIndex7 == i)
536 else if (_cfgLocal.DisplayIndex8 == i)
539 list.Columns[0].Width = _cfgLocal.Width1;
540 list.Columns[1].Width = _cfgLocal.Width2;
541 list.Columns[2].Width = _cfgLocal.Width3;
542 list.Columns[3].Width = _cfgLocal.Width4;
543 list.Columns[4].Width = _cfgLocal.Width5;
544 list.Columns[5].Width = _cfgLocal.Width6;
545 list.Columns[6].Width = _cfgLocal.Width7;
546 list.Columns[7].Width = _cfgLocal.Width8;
547 for (int i = 0; i <= 7; i++)
549 list.Columns[dispOrder[i]].DisplayIndex = i;
555 private void InitColumnText()
558 ColumnText[1] = Properties.Resources.AddNewTabText2;
559 ColumnText[2] = Properties.Resources.AddNewTabText3;
560 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
561 ColumnText[4] = Properties.Resources.AddNewTabText5;
564 ColumnText[7] = "Source";
566 ColumnOrgText[0] = "";
567 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
568 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
569 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
570 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
571 ColumnOrgText[5] = "";
572 ColumnOrgText[6] = "";
573 ColumnOrgText[7] = "Source";
576 switch (_statuses.SortMode)
578 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
581 case IdComparerClass.ComparerMode.Data: //本文
584 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
587 case IdComparerClass.ComparerMode.Name: //名前
590 case IdComparerClass.ComparerMode.Source: //Source
597 if (_statuses.SortOrder == SortOrder.Descending)
599 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
600 ColumnText[2] = ColumnOrgText[2] + "▾";
604 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
605 ColumnText[2] = ColumnOrgText[2] + "▴";
610 if (_statuses.SortOrder == SortOrder.Descending)
612 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
613 ColumnText[c] = ColumnOrgText[c] + "▾";
617 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
618 ColumnText[c] = ColumnOrgText[c] + "▴";
623 private void InitializeTraceFrag()
626 TraceOutToolStripMenuItem.Checked = true;
627 MyCommon.TraceFlag = true;
629 if (!MyCommon.FileVersion.EndsWith("0"))
631 TraceOutToolStripMenuItem.Checked = true;
632 MyCommon.TraceFlag = true;
636 private void TweenMain_Load(object sender, EventArgs e)
638 _ignoreConfigSave = true;
639 this.Visible = false;
641 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
643 new InternetSecurityManager(PostBrowser);
644 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
646 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
647 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
649 if (MyApplication.StartupOptions.ContainsKey("d"))
650 MyCommon.TraceFlag = true;
652 Regex.CacheSize = 100;
654 InitializeTraceFrag();
655 LoadIcons(); // アイコン読み込み
658 _statuses = TabInformations.GetInstance();
661 this.Icon = MainIcon; //メインフォーム(TweenMain)
662 NotifyIcon1.Icon = NIconAt; //タスクトレイ
663 TabImage.Images.Add(TabIcon); //タブ見出し
665 SettingDialog.Owner = this;;
666 SearchDialog.Owner = this;
667 fltDialog.Owner = this;
668 UrlDialog.Owner = this;
670 _history.Add(new PostingStatus());
673 _reply_to_name = null;
675 //<<<<<<<<<設定関連>>>>>>>>>
682 ThumbnailGenerator.InitializeGenerator();
684 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
685 imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
686 imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
688 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
689 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
690 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
693 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
694 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
697 _fntUnread = _cfgLocal.FontUnread;
698 _clUnread = _cfgLocal.ColorUnread;
699 _fntReaded = _cfgLocal.FontRead;
700 _clReaded = _cfgLocal.ColorRead;
701 _clFav = _cfgLocal.ColorFav;
702 _clOWL = _cfgLocal.ColorOWL;
703 _clRetweet = _cfgLocal.ColorRetweet;
704 _fntDetail = _cfgLocal.FontDetail;
705 _clDetail = _cfgLocal.ColorDetail;
706 _clDetailLink = _cfgLocal.ColorDetailLink;
707 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
708 _clSelf = _cfgLocal.ColorSelf;
709 _clAtSelf = _cfgLocal.ColorAtSelf;
710 _clTarget = _cfgLocal.ColorTarget;
711 _clAtTarget = _cfgLocal.ColorAtTarget;
712 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
713 _clAtTo = _cfgLocal.ColorAtTo;
714 _clListBackcolor = _cfgLocal.ColorListBackcolor;
715 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
716 _clInputFont = _cfgLocal.ColorInputFont;
717 _fntInputFont = _cfgLocal.FontInputFont;
719 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
720 if (fontUIGlobal != null)
722 OTBaseForm.GlobalFont = fontUIGlobal;
723 this.Font = fontUIGlobal;
726 // StringFormatオブジェクトへの事前設定
727 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
728 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
729 //sf.FormatFlags = StringFormatFlags.LineLimit; //
730 sfTab.Alignment = StringAlignment.Center;
731 sfTab.LineAlignment = StringAlignment.Center;
734 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
736 if (this._cfgCommon.TimelinePeriod < 15 && this._cfgCommon.TimelinePeriod > 0)
737 this._cfgCommon.TimelinePeriod = 15;
739 if (this._cfgCommon.ReplyPeriod < 15 && this._cfgCommon.ReplyPeriod > 0)
740 this._cfgCommon.ReplyPeriod = 15;
742 if (this._cfgCommon.DMPeriod < 15 && this._cfgCommon.DMPeriod > 0)
743 this._cfgCommon.DMPeriod = 15;
745 if (this._cfgCommon.PubSearchPeriod < 30 && this._cfgCommon.PubSearchPeriod > 0)
746 this._cfgCommon.PubSearchPeriod = 30;
748 if (this._cfgCommon.UserTimelinePeriod < 15 && this._cfgCommon.UserTimelinePeriod > 0)
749 this._cfgCommon.UserTimelinePeriod = 15;
751 if (this._cfgCommon.ListsPeriod < 15 && this._cfgCommon.ListsPeriod > 0)
752 this._cfgCommon.ListsPeriod = 15;
755 if (this._cfgCommon.CountApi < 20 || this._cfgCommon.CountApi > 200)
756 this._cfgCommon.CountApi = 60;
757 if (this._cfgCommon.CountApiReply < 20 || this._cfgCommon.CountApiReply > 200)
758 this._cfgCommon.CountApiReply = 40;
761 this.SettingDialog.LoadConfig(this._cfgCommon, this._cfgLocal);
762 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
763 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
766 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
767 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
769 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
771 //新着取得時のリストスクロールをするか。trueならスクロールしない
772 ListLockMenuItem.Checked = _cfgCommon.ListLock;
773 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
775 this.PlaySoundMenuItem.Checked = this._cfgCommon.PlaySound;
776 this.PlaySoundFileMenuItem.Checked = this._cfgCommon.PlaySound;
778 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
779 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
780 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
781 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
782 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
783 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
784 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
785 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
787 //廃止サービスが選択されていた場合bit.lyへ読み替え
788 if (_cfgCommon.AutoShortUrlFirst < 0)
789 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
791 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
793 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
794 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
796 //Regex statregex = new Regex("^0*");
797 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
799 SettingDialog.Nicoms = _cfgCommon.Nicoms;
801 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
803 SettingDialog.EnableImgAzyobuziNet = _cfgCommon.EnableImgAzyobuziNet;
804 SettingDialog.ImgAzyobuziNetDisabledInDM = _cfgCommon.ImgAzyobuziNetDisabledInDM;
805 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
806 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
807 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
808 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
809 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
812 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
813 HashMgr = new HashtagManage(HashSupl,
814 _cfgCommon.HashTags.ToArray(),
815 _cfgCommon.HashSelected,
816 _cfgCommon.HashIsPermanent,
817 _cfgCommon.HashIsHead,
818 _cfgCommon.HashIsNotAddToAtReply);
819 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
823 Networking.Initialize();
826 this.IconCache = new ImageCache();
828 bool saveRequired = false;
829 bool firstRun = false;
831 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
832 if (string.IsNullOrEmpty(tw.Username))
836 SettingDialog.ShowInTaskbar = true;
838 //設定せずにキャンセルされた場合はプログラム終了
839 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
841 Application.Exit(); //強制終了
844 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
845 if (string.IsNullOrEmpty(tw.Username))
847 Application.Exit(); //強制終了
850 SettingDialog.ShowInTaskbar = false;
854 _fntUnread = this._cfgLocal.FontUnread;
855 _clUnread = this._cfgLocal.ColorUnread;
856 _fntReaded = this._cfgLocal.FontRead;
857 _clReaded = this._cfgLocal.ColorRead;
858 _clFav = this._cfgLocal.ColorFav;
859 _clOWL = this._cfgLocal.ColorOWL;
860 _clRetweet = this._cfgLocal.ColorRetweet;
861 _fntDetail = this._cfgLocal.FontDetail;
862 _clDetail = this._cfgLocal.ColorDetail;
863 _clDetailLink = this._cfgLocal.ColorDetailLink;
864 _clDetailBackcolor = this._cfgLocal.ColorDetailBackcolor;
865 _clSelf = this._cfgLocal.ColorSelf;
866 _clAtSelf = this._cfgLocal.ColorAtSelf;
867 _clTarget = this._cfgLocal.ColorTarget;
868 _clAtTarget = this._cfgLocal.ColorAtTarget;
869 _clAtFromTarget = this._cfgLocal.ColorAtFromTarget;
870 _clAtTo = this._cfgLocal.ColorAtTo;
871 _clListBackcolor = this._cfgLocal.ColorListBackcolor;
872 _clInputBackcolor = this._cfgLocal.ColorInputBackcolor;
873 _clInputFont = this._cfgLocal.ColorInputFont;
874 _fntInputFont = this._cfgLocal.FontInputFont;
876 //他の設定項目は、随時設定画面で保持している値を読み出して使用
879 _brsBackColorMine = new SolidBrush(_clSelf);
880 _brsBackColorAt = new SolidBrush(_clAtSelf);
881 _brsBackColorYou = new SolidBrush(_clTarget);
882 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
883 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
884 _brsBackColorAtTo = new SolidBrush(_clAtTo);
885 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
886 _brsBackColorNone = new SolidBrush(_clListBackcolor);
888 InitDetailHtmlFormat();
890 if (this._cfgCommon.HotkeyEnabled)
893 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
894 if ((this._cfgCommon.HotkeyModifier & Keys.Alt) == Keys.Alt)
895 modKey |= HookGlobalHotkey.ModKeys.Alt;
896 if ((this._cfgCommon.HotkeyModifier & Keys.Control) == Keys.Control)
897 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
898 if ((this._cfgCommon.HotkeyModifier & Keys.Shift) == Keys.Shift)
899 modKey |= HookGlobalHotkey.ModKeys.Shift;
900 if ((this._cfgCommon.HotkeyModifier & Keys.LWin) == Keys.LWin)
901 modKey |= HookGlobalHotkey.ModKeys.Win;
903 _hookGlobalHotkey.RegisterOriginalHotkey(this._cfgCommon.HotkeyKey, this._cfgCommon.HotkeyValue, modKey);
907 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
908 Networking.SetWebProxy(this._cfgLocal.ProxyType,
909 this._cfgLocal.ProxyAddress, this._cfgLocal.ProxyPort,
910 this._cfgLocal.ProxyUser, this._cfgLocal.ProxyPassword);
912 tw.RestrictFavCheck = this._cfgCommon.RestrictFavCheck;
913 tw.ReadOwnPost = this._cfgCommon.ReadOwnPost;
914 ShortUrl.Instance.DisableExpanding = !this._cfgCommon.TinyUrlResolve;
915 ShortUrl.Instance.BitlyId = this._cfgCommon.BilyUser;
916 ShortUrl.Instance.BitlyKey = this._cfgCommon.BitlyPwd;
917 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
918 tw.TrackWord = _cfgCommon.TrackWord;
919 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
920 tw.AllAtReply = _cfgCommon.AllAtReply;
921 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
924 ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
927 this.ClientSize = _cfgLocal.FormSize;
928 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
929 _myLoc = _cfgLocal.FormLocation;
931 if (this.WindowState != FormWindowState.Minimized)
933 this.DesktopLocation = _cfgLocal.FormLocation;
934 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
935 bool outOfScreen = true;
936 if (Screen.AllScreens.Length == 1) //ハングするとの報告
938 foreach (Screen scr in Screen.AllScreens)
940 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
948 this.DesktopLocation = new Point(0, 0);
949 _myLoc = this.DesktopLocation;
953 this.TopMost = this._cfgCommon.AlwaysTop;
954 _mySpDis = _cfgLocal.SplitterDistance;
955 _mySpDis2 = _cfgLocal.StatusTextHeight;
956 _mySpDis3 = _cfgLocal.PreviewDistance;
959 _mySpDis3 = _mySize.Width - 150;
960 if (_mySpDis3 < 1) _mySpDis3 = 50;
961 _cfgLocal.PreviewDistance = _mySpDis3;
963 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
964 //this.Tween_ClientSizeChanged(this, null);
965 this.PlaySoundMenuItem.Checked = this._cfgCommon.PlaySound;
966 this.PlaySoundFileMenuItem.Checked = this._cfgCommon.PlaySound;
968 StatusText.Font = _fntInputFont;
969 StatusText.ForeColor = _clInputFont;
971 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
972 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
974 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
975 SplitContainer1.IsPanelInverted = !this._cfgCommon.StatusAreaAtBottom;
977 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
978 if (this._cfgCommon.UnreadManage == false)
980 ReadedStripMenuItem.Enabled = false;
981 UnreadStripMenuItem.Enabled = false;
984 if (this._cfgCommon.IsUseNotifyGrowl)
988 TimerTimeline.AutoReset = true;
989 TimerTimeline.SynchronizingObject = this;
991 TimerTimeline.Interval = 1000;
992 TimerTimeline.Enabled = true;
995 TimerRefreshIcon.Interval = 200;
996 TimerRefreshIcon.Enabled = true;
999 StatusLabel.Text = "";
1000 StatusLabel.AutoToolTip = false;
1001 StatusLabel.ToolTipText = "";
1003 lblLen.Text = GetRestStatusCount(true, false).ToString();
1005 ////////////////////////////////////////////////////////////////////////////////
1006 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1007 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1008 switch (_cfgCommon.SortColumn)
1010 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1014 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1017 mode = IdComparerClass.ComparerMode.Nickname;
1020 mode = IdComparerClass.ComparerMode.Data;
1023 mode = IdComparerClass.ComparerMode.Id;
1026 mode = IdComparerClass.ComparerMode.Name;
1029 mode = IdComparerClass.ComparerMode.Source;
1032 _statuses.SortMode = mode;
1033 ////////////////////////////////////////////////////////////////////////////////
1035 ApplyListViewIconSize(this._cfgCommon.IconSize);
1037 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1038 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1039 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1040 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1041 SourceLinkLabel.Text = ""; //Source部分初期化
1043 //<<<<<<<<タブ関連>>>>>>>
1044 //デフォルトタブの存在チェック、ない場合には追加
1045 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1048 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1050 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1054 tab.TabType = MyCommon.TabUsageType.Home;
1057 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1060 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1062 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1066 tab.TabType = MyCommon.TabUsageType.Mentions;
1069 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1072 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1074 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1078 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1081 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1084 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1086 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1090 tab.TabType = MyCommon.TabUsageType.Favorites;
1093 foreach (var tab in _statuses.Tabs.Values)
1095 if (tab.TabType == MyCommon.TabUsageType.Undefined)
1097 tab.TabType = MyCommon.TabUsageType.UserDefined;
1099 if (!AddNewTab(tab.TabName, true, tab.TabType, tab.ListInfo))
1100 throw new TabException(Properties.Resources.TweenMain_LoadText1);
1103 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1104 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1105 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1106 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1108 if (!this._cfgCommon.MinimizeToTray || this.WindowState != FormWindowState.Minimized)
1110 this.Visible = true;
1112 _curTab = ListTab.SelectedTab;
1114 _curList = (DetailsListView)_curTab.Tag;
1115 SetMainWindowTitle();
1116 SetNotifyIconText();
1118 if (this._cfgCommon.TabIconDisp)
1120 ListTab.DrawMode = TabDrawMode.Normal;
1124 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1125 ListTab.DrawItem += ListTab_DrawItem;
1126 ListTab.ImageList = null;
1129 _ignoreConfigSave = false;
1130 this.TweenMain_Resize(null, null);
1131 if (saveRequired) SaveConfigsAll(false);
1135 tw.VerifyCredentials();
1136 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1138 if (ua.Username.ToLower() == tw.Username.ToLower())
1140 ua.UserId = tw.UserId;
1145 foreach (UserAccount ua in SettingDialog.UserAccounts)
1147 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1149 ua.UserId = tw.UserId;
1156 // 初回起動時だけ右下のメニューを目立たせる
1157 HashStripSplitButton.ShowDropDown();
1164 private void InitDetailHtmlFormat()
1166 if (this._cfgCommon.IsMonospace)
1168 detailHtmlFormatHeader = detailHtmlFormatMono1;
1169 detailHtmlFormatFooter = detailHtmlFormatMono7;
1173 detailHtmlFormatHeader = detailHtmlFormat1;
1174 detailHtmlFormatFooter = detailHtmlFormat7;
1176 detailHtmlFormatHeader += _fntDetail.Name + detailHtmlFormat2 + _fntDetail.Size.ToString() + detailHtmlFormat3 + _clDetail.R.ToString() + "," + _clDetail.G.ToString() + "," + _clDetail.B.ToString() + detailHtmlFormat4 + _clDetailLink.R.ToString() + "," + _clDetailLink.G.ToString() + "," + _clDetailLink.B.ToString() + detailHtmlFormat5 + _clDetailBackcolor.R.ToString() + "," + _clDetailBackcolor.G.ToString() + "," + _clDetailBackcolor.B.ToString();
1177 if (this._cfgCommon.IsMonospace)
1179 detailHtmlFormatHeader += detailHtmlFormatMono6;
1183 detailHtmlFormatHeader += detailHtmlFormat6;
1187 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1192 txt = ListTab.TabPages[e.Index].Text;
1199 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1200 if (e.State == DrawItemState.Selected)
1202 e.DrawFocusRectangle();
1207 if (_statuses.Tabs[txt].UnreadCount > 0)
1210 fore = System.Drawing.SystemBrushes.ControlText;
1214 fore = System.Drawing.SystemBrushes.ControlText;
1216 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1219 private void LoadConfig()
1221 _cfgCommon = SettingCommon.Load();
1222 SettingCommon.Instance = this._cfgCommon;
1223 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1225 _cfgCommon.UserAccounts = new List<UserAccount>();
1226 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1228 UserAccount account = new UserAccount();
1229 account.Username = _cfgCommon.UserName;
1230 account.UserId = _cfgCommon.UserId;
1231 account.Token = _cfgCommon.Token;
1232 account.TokenSecret = _cfgCommon.TokenSecret;
1234 _cfgCommon.UserAccounts.Add(account);
1237 _cfgLocal = SettingLocal.Load();
1238 List<TabClass> tabs = SettingTabs.Load().Tabs;
1239 foreach (TabClass tb in tabs)
1243 _statuses.Tabs.Add(tb.TabName, tb);
1247 tb.TabName = _statuses.GetUniqueTabName();
1248 _statuses.Tabs.Add(tb.TabName, tb);
1251 if (_statuses.Tabs.Count == 0)
1253 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1254 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1255 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1256 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1260 private void TimerInterval_Changed(object sender, IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1262 if (!TimerTimeline.Enabled) return;
1266 private IntervalChangedEventArgs ResetTimers = new IntervalChangedEventArgs();
1268 private static int homeCounter = 0;
1269 private static int mentionCounter = 0;
1270 private static int dmCounter = 0;
1271 private static int pubSearchCounter = 0;
1272 private static int userTimelineCounter = 0;
1273 private static int listsCounter = 0;
1274 private static int usCounter = 0;
1275 private static int ResumeWait = 0;
1276 private static int refreshFollowers = 0;
1278 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1280 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1281 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1282 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1283 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1284 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1285 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1286 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1287 Interlocked.Increment(ref refreshFollowers);
1290 if (ResetTimers.Timeline || homeCounter <= 0 && this._cfgCommon.TimelinePeriod > 0)
1292 Interlocked.Exchange(ref homeCounter, this._cfgCommon.TimelinePeriod);
1293 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1294 ResetTimers.Timeline = false;
1296 if (ResetTimers.Reply || mentionCounter <= 0 && this._cfgCommon.ReplyPeriod > 0)
1298 Interlocked.Exchange(ref mentionCounter, this._cfgCommon.ReplyPeriod);
1299 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1300 ResetTimers.Reply = false;
1302 if (ResetTimers.DirectMessage || dmCounter <= 0 && this._cfgCommon.DMPeriod > 0)
1304 Interlocked.Exchange(ref dmCounter, this._cfgCommon.DMPeriod);
1305 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1306 ResetTimers.DirectMessage = false;
1308 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && this._cfgCommon.PubSearchPeriod > 0)
1310 Interlocked.Exchange(ref pubSearchCounter, this._cfgCommon.PubSearchPeriod);
1311 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1312 ResetTimers.PublicSearch = false;
1314 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && this._cfgCommon.UserTimelinePeriod > 0)
1316 Interlocked.Exchange(ref userTimelineCounter, this._cfgCommon.UserTimelinePeriod);
1317 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1318 ResetTimers.UserTimeline = false;
1320 if (ResetTimers.Lists || listsCounter <= 0 && this._cfgCommon.ListsPeriod > 0)
1322 Interlocked.Exchange(ref listsCounter, this._cfgCommon.ListsPeriod);
1323 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1324 ResetTimers.Lists = false;
1326 if (ResetTimers.UserStream || usCounter <= 0 && this._cfgCommon.UserstreamPeriod > 0)
1328 Interlocked.Exchange(ref usCounter, this._cfgCommon.UserstreamPeriod);
1329 if (this._isActiveUserstream) RefreshTimeline(true);
1330 ResetTimers.UserStream = false;
1332 if (refreshFollowers > 6 * 3600)
1334 Interlocked.Exchange(ref refreshFollowers, 0);
1335 doGetFollowersMenu();
1336 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
1337 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1341 Interlocked.Increment(ref ResumeWait);
1342 if (ResumeWait > 30)
1345 Interlocked.Exchange(ref ResumeWait, 0);
1346 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1347 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1348 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1349 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1350 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1351 GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1352 doGetFollowersMenu();
1353 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1358 private void RefreshTimeline(bool isUserStream)
1360 if (isUserStream) this.RefreshTasktrayIcon(true);
1362 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1363 long topId = GetScrollPos(ref smode);
1364 int befCnt = _curList.VirtualListSize;
1367 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1368 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
1369 SaveSelectedStatus(selId, focusedId);
1372 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1375 PostClass[] notifyPosts = null;
1376 string soundFile = "";
1378 bool isMention = false;
1379 bool isDelete = false;
1380 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1382 if (MyCommon._endingFlag) return;
1387 foreach (TabPage tab in ListTab.TabPages)
1389 DetailsListView lst = (DetailsListView)tab.Tag;
1390 TabClass tabInfo = _statuses.Tabs[tab.Text];
1391 using (ControlTransaction.Update(lst))
1393 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1395 if (lst.Equals(_curList))
1397 this.PurgeListViewItemCache();
1401 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1407 this.SelectListItem(lst,
1408 tabInfo.IndexOf(selId[tab.Text]),
1409 tabInfo.IndexOf(focusedId[tab.Text]));
1412 if (tabInfo.UnreadCount > 0)
1413 if (this._cfgCommon.TabIconDisp)
1414 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1416 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
1420 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1429 if (befCnt != _curList.VirtualListSize)
1435 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1439 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1446 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1448 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1449 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1455 catch (Exception ex)
1457 ex.Data["Msg"] = "Ref2";
1463 NotifyNewPosts(notifyPosts,
1466 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1468 SetMainWindowTitle();
1469 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1471 HashSupl.AddRangeItem(tw.GetHashList());
1475 private long GetScrollPos(ref int smode)
1478 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1480 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1482 if (_statuses.SortOrder == SortOrder.Ascending)
1485 if (ListLockMenuItem.Checked)
1490 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1495 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1497 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1498 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1499 if (_item.Index == _curList.VirtualListSize - 1)
1506 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1514 if (ListLockMenuItem.Checked)
1517 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1522 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1525 _item = _curList.GetItemAt(0, 10); //一番上
1526 if (_item == null) _item = _curList.Items[0];
1527 if (_item.Index == 0)
1533 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1542 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1553 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long[]> focusedId)
1555 if (MyCommon._endingFlag) return;
1556 foreach (TabPage tab in ListTab.TabPages)
1558 var lst = (DetailsListView)tab.Tag;
1559 var tabInfo = _statuses.Tabs[tab.Text];
1560 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1562 selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
1566 selId.Add(tab.Text, new long[1] {-2});
1569 var fIds = new long[2]; // 0 = focus, 1 = selection mark
1570 var item = lst.FocusedItem;
1571 fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
1572 var mIdx = lst.SelectionMark;
1573 fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
1574 focusedId.Add(tab.Text, fIds);
1579 private bool BalloonRequired()
1581 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1582 ev.Eventtype = MyCommon.EVENTTYPE.None;
1584 return BalloonRequired(ev);
1587 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1589 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1592 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1594 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1597 private bool BalloonRequired(Twitter.FormattedEvent ev)
1600 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1601 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1605 this._cfgCommon.LimitBalloon &&
1607 this.WindowState == FormWindowState.Minimized ||
1609 Form.ActiveForm == null
1612 !this._cfgCommon.LimitBalloon
1615 !NativeMethods.IsScreenSaverRunning())
1625 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1627 if (notifyPosts != null &&
1628 notifyPosts.Length > 0 &&
1629 this._cfgCommon.ReadOwnPost &&
1630 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1636 if (BalloonRequired())
1638 if (notifyPosts != null && notifyPosts.Length > 0)
1640 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1641 if (this._cfgCommon.IsUseNotifyGrowl)
1643 StringBuilder sb = new StringBuilder();
1647 foreach (PostClass post in notifyPosts)
1649 if (!(notifyPosts.Length > 3))
1655 if (post.IsReply && !post.IsExcludeReply) reply = true;
1656 if (post.IsDm) dm = true;
1657 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1658 switch (this._cfgCommon.NameBalloon)
1660 case MyCommon.NameBalloonEnum.UserID:
1661 sb.Append(post.ScreenName).Append(" : ");
1663 case MyCommon.NameBalloonEnum.NickName:
1664 sb.Append(post.Nickname).Append(" : ");
1667 sb.Append(post.TextFromApi);
1668 if (notifyPosts.Length > 3)
1670 if (notifyPosts.Last() != post) continue;
1673 StringBuilder title = new StringBuilder();
1674 GrowlHelper.NotifyType nt;
1675 if (this._cfgCommon.DispUsername)
1677 title.Append(tw.Username);
1678 title.Append(" - ");
1686 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1687 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1688 title.Append(Application.ProductName);
1689 title.Append(" [DM] ");
1690 title.Append(Properties.Resources.RefreshDirectMessageText1);
1692 title.Append(addCount);
1693 title.Append(Properties.Resources.RefreshDirectMessageText2);
1694 nt = GrowlHelper.NotifyType.DirectMessage;
1698 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1699 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1700 title.Append(Application.ProductName);
1701 title.Append(" [Reply!] ");
1702 title.Append(Properties.Resources.RefreshTimelineText1);
1704 title.Append(addCount);
1705 title.Append(Properties.Resources.RefreshTimelineText2);
1706 nt = GrowlHelper.NotifyType.Reply;
1710 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1711 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1712 title.Append(Application.ProductName);
1714 title.Append(Properties.Resources.RefreshTimelineText1);
1716 title.Append(addCount);
1717 title.Append(Properties.Resources.RefreshTimelineText2);
1718 nt = GrowlHelper.NotifyType.Notify;
1720 string bText = sb.ToString();
1721 if (string.IsNullOrEmpty(bText)) return;
1723 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1724 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1729 StringBuilder sb = new StringBuilder();
1732 foreach (PostClass post in notifyPosts)
1734 if (post.IsReply && !post.IsExcludeReply) reply = true;
1735 if (post.IsDm) dm = true;
1736 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1737 switch (this._cfgCommon.NameBalloon)
1739 case MyCommon.NameBalloonEnum.UserID:
1740 sb.Append(post.ScreenName).Append(" : ");
1742 case MyCommon.NameBalloonEnum.NickName:
1743 sb.Append(post.Nickname).Append(" : ");
1746 sb.Append(post.TextFromApi);
1749 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1750 StringBuilder title = new StringBuilder();
1752 if (this._cfgCommon.DispUsername)
1754 title.Append(tw.Username);
1755 title.Append(" - ");
1763 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1764 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1765 ntIcon = ToolTipIcon.Warning;
1766 title.Append(Application.ProductName);
1767 title.Append(" [DM] ");
1768 title.Append(Properties.Resources.RefreshDirectMessageText1);
1770 title.Append(addCount);
1771 title.Append(Properties.Resources.RefreshDirectMessageText2);
1775 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1776 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1777 ntIcon = ToolTipIcon.Warning;
1778 title.Append(Application.ProductName);
1779 title.Append(" [Reply!] ");
1780 title.Append(Properties.Resources.RefreshTimelineText1);
1782 title.Append(addCount);
1783 title.Append(Properties.Resources.RefreshTimelineText2);
1787 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1788 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1789 ntIcon = ToolTipIcon.Info;
1790 title.Append(Application.ProductName);
1792 title.Append(Properties.Resources.RefreshTimelineText1);
1794 title.Append(addCount);
1795 title.Append(Properties.Resources.RefreshTimelineText2);
1797 string bText = sb.ToString();
1798 if (string.IsNullOrEmpty(bText)) return;
1799 //NotifyIcon1.BalloonTipText = sb.ToString();
1800 //NotifyIcon1.ShowBalloonTip(500);
1801 NotifyIcon1.BalloonTipTitle = title.ToString();
1802 NotifyIcon1.BalloonTipText = bText;
1803 NotifyIcon1.BalloonTipIcon = ntIcon;
1804 NotifyIcon1.ShowBalloonTip(500);
1810 if (!_initial && this._cfgCommon.PlaySound && !string.IsNullOrEmpty(soundFile))
1814 string dir = Application.StartupPath;
1815 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1817 dir = Path.Combine(dir, "Sounds");
1819 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1829 //mentions新着時に画面ブリンク
1830 if (!_initial && this._cfgCommon.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1832 NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
1836 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1838 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1840 _curItemIndex = _curList.SelectedIndices[0];
1841 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1845 _curPost = GetCurTabPost(_curItemIndex);
1847 catch (ArgumentException)
1852 this.PushSelectPostChain();
1854 if (this._cfgCommon.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
1856 ChangeCacheStyleRead(true, _curItemIndex); //既読へ(フォント、文字色)
1862 private void ChangeCacheStyleRead(bool Read, int Index)
1864 var tabInfo = _statuses.Tabs[_curTab.Text];
1865 //Read:true=既読 false=未読
1866 //未読管理していなかったら既読として扱う
1867 if (!tabInfo.UnreadManage ||
1868 !this._cfgCommon.UnreadManage) Read = true;
1871 ListViewItem itm = null;
1872 PostClass post = null;
1874 this.TryGetListViewItemCache(Index, out itm, out post);
1876 if (itm == null || post == null)
1878 itm = ((DetailsListView)_curTab.Tag).Items[Index];
1879 post = tabInfo[Index];
1882 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
1885 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
1892 Item.SubItems[5].Text = "";
1897 Item.SubItems[5].Text = "★";
1903 else if (Post.RetweetedId != null)
1905 else if (Post.IsOwl && (Post.IsDm || this._cfgCommon.OneWayLove))
1907 else if (Read || !this._cfgCommon.UseUnreadStyle)
1912 if (DList == null || Item.Index == -1)
1914 Item.ForeColor = cl;
1915 if (this._cfgCommon.UseUnreadStyle)
1921 if (this._cfgCommon.UseUnreadStyle)
1922 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
1924 DList.ChangeItemForeColor(Item.Index, cl);
1925 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
1929 private void ColorizeList()
1931 //Index:更新対象のListviewItem.Index。Colorを返す。
1932 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
1935 _post = _anchorPost;
1939 if (_post == null) return;
1941 var itemColors = new Color[] { };
1944 this.itemCacheLock.EnterReadLock();
1947 if (this._itemCache == null) return;
1950 from i in Enumerable.Range(0, this._itemCache.Length)
1951 select this.JudgeColor(_post, this._postCache[i]);
1953 itemColors = query.ToArray();
1954 itemIndex = _itemCacheIndex;
1956 finally { this.itemCacheLock.ExitReadLock(); }
1958 if (itemIndex < 0) return;
1960 foreach (var backColor in itemColors)
1962 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
1963 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
1964 _curList.ChangeItemBackColor(itemIndex++, backColor);
1968 private void ColorizeList(ListViewItem Item, int Index)
1970 //Index:更新対象のListviewItem.Index。Colorを返す。
1971 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
1974 _post = _anchorPost;
1978 PostClass tPost = GetCurTabPost(Index);
1980 if (_post == null) return;
1982 if (Item.Index == -1)
1983 Item.BackColor = JudgeColor(_post, tPost);
1985 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
1988 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
1991 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
1994 else if (TargetPost.IsMe)
1997 else if (TargetPost.IsReply)
2000 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2002 cl = _clAtFromTarget;
2003 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2006 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2011 cl = _clListBackcolor;
2016 private async void PostButton_Click(object sender, EventArgs e)
2018 if (StatusText.Text.Trim().Length == 0)
2020 if (!ImageSelector.Enabled)
2027 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2029 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2031 MessageBoxButtons.YesNoCancel,
2032 MessageBoxIcon.Question);
2035 case DialogResult.Yes:
2036 doReTweetOfficial(false);
2037 StatusText.Text = "";
2039 case DialogResult.Cancel:
2044 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2046 if (SettingDialog.Nicoms)
2048 StatusText.SelectionStart = StatusText.Text.Length;
2049 await UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2051 //if (SettingDialog.UrlConvertAuto)
2053 // StatusText.SelectionStart = StatusText.Text.Length;
2054 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2056 //else if (SettingDialog.Nicoms)
2058 // StatusText.SelectionStart = StatusText.Text.Length;
2059 // UrlConvert(UrlConverter.Nicoms);
2061 StatusText.SelectionStart = StatusText.Text.Length;
2062 GetWorkerArg args = new GetWorkerArg();
2064 args.type = MyCommon.WORKERTYPE.PostMessage;
2065 CheckReplyTo(StatusText.Text);
2068 int adjustCount = 0;
2069 string tmpStatus = StatusText.Text.Trim();
2070 if (ToolStripMenuItemApiCommandEvasion.Checked)
2073 if (Regex.IsMatch(tmpStatus,
2074 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2075 RegexOptions.IgnoreCase)
2076 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2079 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2082 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2085 bool isCutOff = false;
2086 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2087 if (StatusText.Multiline && !this._cfgCommon.PostCtrlEnter)
2089 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2090 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2092 if (this._cfgCommon.PostShiftEnter)
2094 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2096 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2098 isRemoveFooter = true;
2100 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2102 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2105 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2106 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2108 isRemoveFooter = true;
2119 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2127 if (HashMgr.IsNotAddToAtReply)
2129 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2132 header = HashMgr.UseHash + " ";
2134 footer = " " + HashMgr.UseHash;
2139 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2142 header = HashMgr.UseHash + " ";
2144 footer = " " + HashMgr.UseHash;
2147 if (!isRemoveFooter)
2149 if (this._cfgLocal.UseRecommendStatus)
2151 footer += SettingDialog.RecommendStatusText;
2153 // テキストボックスに入力されている文字列を使用する
2154 footer += " " + this._cfgLocal.StatusText.Trim();
2157 args.status.status = header + StatusText.Text + footer;
2159 if (ToolStripMenuItemApiCommandEvasion.Checked)
2162 if (Regex.IsMatch(args.status.status,
2163 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2164 RegexOptions.IgnoreCase)
2165 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2168 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2171 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2172 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2175 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2177 // 文中の全角スペースを半角スペース1個にする
2178 args.status.status = args.status.status.Replace(" ", " ");
2181 if (isCutOff && args.status.status.Length > 140)
2183 args.status.status = args.status.status.Substring(0, 140);
2184 string AtId = @"(@|@)[a-z0-9_/]+$";
2185 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2186 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2187 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2188 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2191 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2192 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2194 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2197 args.status.inReplyToId = _reply_to_id;
2198 args.status.inReplyToName = _reply_to_name;
2199 if (ImageSelector.Visible)
2202 if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
2208 _reply_to_id = null;
2209 _reply_to_name = null;
2210 StatusText.Text = "";
2211 _history.Add(new PostingStatus());
2212 _hisIdx = _history.Count - 1;
2213 if (!ToolStripFocusLockMenuItem.Checked)
2214 ((Control)ListTab.SelectedTab.Tag).Focus();
2215 urlUndoBuffer = null;
2216 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2219 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2221 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2222 await this.OpenUriAsync(tmp);
2226 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2228 MyCommon._endingFlag = true;
2232 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2234 if (!this._cfgCommon.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2236 //_endingFlag=false:フォームの×ボタン
2238 this.Visible = false;
2242 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2243 _ignoreConfigSave = true;
2244 MyCommon._endingFlag = true;
2245 TimerTimeline.Enabled = false;
2246 TimerRefreshIcon.Enabled = false;
2250 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2252 this.Visible = true;
2253 if (this.WindowState == FormWindowState.Minimized)
2255 this.WindowState = FormWindowState.Normal;
2258 this.BringToFront();
2261 private static int errorCount = 0;
2263 private static bool CheckAccountValid()
2265 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2271 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2280 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2282 BackgroundWorker bw = (BackgroundWorker)sender;
2283 if (bw.CancellationPending || MyCommon._endingFlag)
2289 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2291 MyApplication.InitCulture();
2294 GetWorkerResult rslt = new GetWorkerResult();
2296 bool read = !this._cfgCommon.UnreadManage;
2297 if (_initial && this._cfgCommon.UnreadManage) read = this._cfgCommon.Read;
2299 GetWorkerArg args = (GetWorkerArg)e.Argument;
2301 if (!CheckAccountValid())
2303 rslt.retMsg = "Auth error. Check your account";
2304 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2305 rslt.tName = args.tName;
2310 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2314 case MyCommon.WORKERTYPE.Timeline:
2315 case MyCommon.WORKERTYPE.Reply:
2316 bw.ReportProgress(50, MakeStatusMessage(args, false));
2317 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2319 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && this._cfgCommon.ReadOldPosts)
2320 _statuses.SetRead();
2322 rslt.addCount = _statuses.DistributePosts();
2324 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2325 bw.ReportProgress(50, MakeStatusMessage(args, false));
2326 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2327 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2328 rslt.addCount = _statuses.DistributePosts();
2331 case MyCommon.WORKERTYPE.FavAdd:
2335 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2337 for (int i = 0; i <= args.ids.Count - 1; i++)
2339 var post = tab.Posts[args.ids[i]];
2342 bw.ReportProgress(50, MakeStatusMessage(args, false));
2345 if (post.RetweetedId == null)
2346 ret = tw.PostFavAdd(post.StatusId);
2348 ret = tw.PostFavAdd(post.RetweetedId.Value);
2350 if (ret.Length == 0)
2352 args.sIds.Add(post.StatusId);
2353 post.IsFav = true; //リスト再描画必要
2354 _favTimestamps.Add(DateTime.Now);
2355 if (string.IsNullOrEmpty(post.RelTabName))
2357 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2358 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2362 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2363 if (_statuses.ContainsKey(post.StatusId))
2365 PostClass postTl = _statuses[post.StatusId];
2366 postTl.IsFav = true;
2367 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2370 //検索,リスト,UserTimeline,Relatedの各タブに反映
2371 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2373 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2379 rslt.sIds = args.sIds;
2383 case MyCommon.WORKERTYPE.FavRemove:
2387 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2389 for (int i = 0; i <= args.ids.Count - 1; i++)
2391 var post = tab.Posts[args.ids[i]];
2394 bw.ReportProgress(50, MakeStatusMessage(args, false));
2397 if (post.RetweetedId == null)
2398 ret = tw.PostFavRemove(post.StatusId);
2400 ret = tw.PostFavRemove(post.RetweetedId.Value);
2402 if (ret.Length == 0)
2404 args.sIds.Add(post.StatusId);
2405 post.IsFav = false; //リスト再描画必要
2406 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2407 //検索,リスト,UserTimeline,Relatedの各タブに反映
2408 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2410 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2416 rslt.sIds = args.sIds;
2420 case MyCommon.WORKERTYPE.PostMessage:
2421 bw.ReportProgress(200);
2422 if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
2424 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2428 var service = ImageSelector.GetService(args.status.imageService);
2431 service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
2434 catch (AggregateException ex)
2436 ret = ex.InnerException.Message;
2439 bw.ReportProgress(300);
2440 rslt.status = args.status;
2442 case MyCommon.WORKERTYPE.Retweet:
2443 bw.ReportProgress(200);
2444 for (int i = 0; i <= args.ids.Count - 1; i++)
2446 ret = tw.PostRetweet(args.ids[i], read);
2448 bw.ReportProgress(300);
2450 case MyCommon.WORKERTYPE.Follower:
2451 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2454 tw.RefreshFollowerIds();
2456 catch (WebApiException ex) { ret = ex.Message; }
2458 case MyCommon.WORKERTYPE.NoRetweetIds:
2461 tw.RefreshNoRetweetIds();
2463 catch (WebApiException ex) { ret = ex.Message; }
2465 case MyCommon.WORKERTYPE.Configuration:
2468 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2470 catch (WebApiException ex) { ret = ex.Message; }
2472 case MyCommon.WORKERTYPE.Favorites:
2473 bw.ReportProgress(50, MakeStatusMessage(args, false));
2474 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2475 rslt.addCount = _statuses.DistributePosts();
2477 case MyCommon.WORKERTYPE.PublicSearch:
2478 bw.ReportProgress(50, MakeStatusMessage(args, false));
2479 if (string.IsNullOrEmpty(args.tName))
2481 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2483 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2484 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2489 TabClass tb = _statuses.GetTabByName(args.tName);
2492 //ret = tw.GetPhoenixSearch(read, tb, false);
2493 ret = tw.GetSearch(read, tb, false);
2494 if (string.IsNullOrEmpty(ret) && args.page == -1)
2496 //ret = tw.GetPhoenixSearch(read, tb, true)
2497 ret = tw.GetSearch(read, tb, true);
2502 rslt.addCount = _statuses.DistributePosts();
2504 case MyCommon.WORKERTYPE.UserTimeline:
2505 bw.ReportProgress(50, MakeStatusMessage(args, false));
2507 if (this._cfgCommon.UseAdditionalCount) count = this._cfgCommon.UserTimelineCountApi;
2508 if (string.IsNullOrEmpty(args.tName))
2510 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2512 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2517 TabClass tb = _statuses.GetTabByName(args.tName);
2520 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2524 rslt.addCount = _statuses.DistributePosts();
2526 case MyCommon.WORKERTYPE.List:
2527 bw.ReportProgress(50, MakeStatusMessage(args, false));
2528 if (string.IsNullOrEmpty(args.tName))
2531 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2533 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2539 TabClass tb = _statuses.GetTabByName(args.tName);
2542 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2546 rslt.addCount = _statuses.DistributePosts();
2549 case MyCommon.WORKERTYPE.Related:
2551 bw.ReportProgress(50, MakeStatusMessage(args, false));
2552 TabClass tab = _statuses.GetTabByName(args.tName);
2553 ret = tw.GetRelatedResult(read, tab);
2554 rslt.addCount = _statuses.DistributePosts();
2558 case MyCommon.WORKERTYPE.BlockIds:
2559 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2562 tw.RefreshBlockIds();
2564 catch (WebApiException ex) { ret = ex.Message; }
2568 if (bw.CancellationPending)
2575 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2577 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2578 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2580 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2582 _favTimestamps.RemoveAt(i);
2586 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2590 DateTime tm = DateTime.Now;
2591 if (_tlTimestamps.ContainsKey(tm))
2592 _tlTimestamps[tm] += rslt.addCount;
2594 _tlTimestamps.Add(tm, rslt.addCount);
2596 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2597 List<DateTime> keys = new List<DateTime>();
2599 foreach (DateTime key in _tlTimestamps.Keys)
2601 if (key.CompareTo(oneHour) < 0)
2607 _tlCount += _tlTimestamps[key];
2610 foreach (DateTime key in keys)
2612 _tlTimestamps.Remove(key);
2619 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2622 rslt.type = args.type;
2623 rslt.tName = args.tName;
2628 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2634 switch (AsyncArg.type)
2636 case MyCommon.WORKERTYPE.Timeline:
2637 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2639 case MyCommon.WORKERTYPE.Reply:
2640 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2642 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2643 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2645 case MyCommon.WORKERTYPE.FavAdd:
2646 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2647 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2649 case MyCommon.WORKERTYPE.FavRemove:
2650 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2651 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2653 case MyCommon.WORKERTYPE.Favorites:
2654 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2656 case MyCommon.WORKERTYPE.PublicSearch:
2657 smsg = "Search refreshing...";
2659 case MyCommon.WORKERTYPE.List:
2660 smsg = "List refreshing...";
2662 case MyCommon.WORKERTYPE.Related:
2663 smsg = "Related refreshing...";
2665 case MyCommon.WORKERTYPE.UserTimeline:
2666 smsg = "UserTimeline refreshing...";
2673 switch (AsyncArg.type)
2675 case MyCommon.WORKERTYPE.Timeline:
2676 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2678 case MyCommon.WORKERTYPE.Reply:
2679 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2681 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2682 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2684 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2685 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2687 case MyCommon.WORKERTYPE.FavAdd:
2690 case MyCommon.WORKERTYPE.FavRemove:
2693 case MyCommon.WORKERTYPE.Favorites:
2694 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2696 case MyCommon.WORKERTYPE.Follower:
2697 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2699 case MyCommon.WORKERTYPE.NoRetweetIds:
2700 smsg = "NoRetweetIds refreshed";
2702 case MyCommon.WORKERTYPE.Configuration:
2705 case MyCommon.WORKERTYPE.PublicSearch:
2706 smsg = "Search refreshed";
2708 case MyCommon.WORKERTYPE.List:
2709 smsg = "List refreshed";
2711 case MyCommon.WORKERTYPE.Related:
2712 smsg = "Related refreshed";
2714 case MyCommon.WORKERTYPE.UserTimeline:
2715 smsg = "UserTimeline refreshed";
2717 case MyCommon.WORKERTYPE.BlockIds:
2718 smsg = Properties.Resources.UpdateBlockUserText3;
2725 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2727 if (MyCommon._endingFlag) return;
2728 if (e.ProgressPercentage > 100)
2731 if (e.ProgressPercentage == 200) //開始
2732 StatusLabel.Text = "Posting...";
2733 if (e.ProgressPercentage == 300) //終了
2734 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2738 string smsg = (string)e.UserState;
2739 if (smsg.Length > 0) StatusLabel.Text = smsg;
2743 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2745 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2747 if (e.Error != null)
2749 _myStatusError = true;
2750 _waitTimeline = false;
2754 _waitPubSearch = false;
2755 _waitUserTimeline = false;
2757 throw new Exception("BackgroundWorker Exception", e.Error);
2760 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2763 if (rslt.retMsg.Length > 0)
2765 _myStatusError = true;
2766 StatusLabel.Text = rslt.retMsg;
2769 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2771 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2773 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2777 //bool busy = false;
2778 //foreach (BackgroundWorker bw in _bw)
2780 // if (bw != null && bw.IsBusy)
2786 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2787 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2788 rslt.type == MyCommon.WORKERTYPE.Reply ||
2789 rslt.type == MyCommon.WORKERTYPE.List ||
2790 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2791 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2792 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2793 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2794 rslt.type == MyCommon.WORKERTYPE.Follower ||
2795 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2796 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2797 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2798 rslt.type == MyCommon.WORKERTYPE.Related ||
2799 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2800 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2801 rslt.type == MyCommon.WORKERTYPE.Configuration)
2803 RefreshTimeline(false); //リスト反映
2808 case MyCommon.WORKERTYPE.Timeline:
2809 _waitTimeline = false;
2812 // //API使用時の取得調整は別途考える(カウント調整?)
2815 case MyCommon.WORKERTYPE.Reply:
2817 if (rslt.newDM && !_initial)
2819 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
2822 case MyCommon.WORKERTYPE.Favorites:
2825 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2828 case MyCommon.WORKERTYPE.FavAdd:
2829 case MyCommon.WORKERTYPE.FavRemove:
2830 if (_curList != null && _curTab != null)
2832 using (ControlTransaction.Update(this._curList))
2834 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
2840 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
2842 if (_curTab.Text.Equals(rslt.tName))
2844 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
2847 PostClass post = null;
2848 TabClass tb = _statuses.Tabs[rslt.tName];
2851 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
2853 post = tb.Posts[rslt.sIds[i]];
2857 post = _statuses[rslt.sIds[i]];
2859 ChangeCacheStyleRead(post.IsRead, idx);
2861 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
2869 case MyCommon.WORKERTYPE.PostMessage:
2870 if (string.IsNullOrEmpty(rslt.retMsg) ||
2871 rslt.retMsg.StartsWith("OK:") ||
2872 rslt.retMsg == "Warn:Status is a duplicate.")
2874 _postTimestamps.Add(DateTime.Now);
2875 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2876 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2878 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2880 _postTimestamps.RemoveAt(i);
2884 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
2886 HashMgr.ClearHashtag();
2887 this.HashStripSplitButton.Text = "#[-]";
2888 this.HashToggleMenuItem.Checked = false;
2889 this.HashToggleToolStripMenuItem.Checked = false;
2891 SetMainWindowTitle();
2899 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
2900 Properties.Resources.StatusUpdateFailed1,
2901 Properties.Resources.StatusUpdateFailed2),
2902 "Failed to update status",
2903 MessageBoxButtons.RetryCancel,
2904 MessageBoxIcon.Question);
2908 retry = DialogResult.Abort;
2910 if (retry == DialogResult.Retry)
2912 GetWorkerArg args = new GetWorkerArg();
2914 args.type = MyCommon.WORKERTYPE.PostMessage;
2915 args.status = rslt.status;
2920 if (ToolStripFocusLockMenuItem.Checked)
2922 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
2923 StatusText_Enter(StatusText, new EventArgs());
2927 if (rslt.retMsg.Length == 0 && this._cfgCommon.PostAndGet)
2929 if (_isActiveUserstream)
2931 RefreshTimeline(true);
2935 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
2939 case MyCommon.WORKERTYPE.Retweet:
2940 if (rslt.retMsg.Length == 0)
2942 _postTimestamps.Add(DateTime.Now);
2943 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2944 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2946 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2948 _postTimestamps.RemoveAt(i);
2951 if (!_isActiveUserstream && this._cfgCommon.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
2954 case MyCommon.WORKERTYPE.Follower:
2955 //_waitFollower = false;
2956 this.PurgeListViewItemCache();
2957 if (_curList != null) _curList.Refresh();
2959 case MyCommon.WORKERTYPE.NoRetweetIds:
2961 case MyCommon.WORKERTYPE.Configuration:
2962 //_waitFollower = false
2963 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
2965 foreach (var service in this.ImageSelector.GetServices())
2967 service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
2970 this.PurgeListViewItemCache();
2971 if (_curList != null) _curList.Refresh();
2973 case MyCommon.WORKERTYPE.PublicSearch:
2974 _waitPubSearch = false;
2976 case MyCommon.WORKERTYPE.UserTimeline:
2977 _waitUserTimeline = false;
2979 case MyCommon.WORKERTYPE.List:
2982 case MyCommon.WORKERTYPE.Related:
2983 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
2984 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
2986 foreach (TabPage tp in ListTab.TabPages)
2988 if (tp.Text == tab.TabName)
2990 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
2991 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3000 private async Task RefreshMuteUserIdsAsync()
3002 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
3006 await tw.RefreshMuteUserIdsAsync();
3008 catch (WebApiException ex)
3010 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
3014 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
3017 private void RemovePostFromFavTab(Int64[] ids)
3019 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3021 if (_curTab.Text.Equals(favTabName))
3023 if (_curList.FocusedItem != null)
3024 fidx = _curList.FocusedItem.Index;
3025 else if (_curList.TopItem != null)
3026 fidx = _curList.TopItem.Index;
3031 foreach (long i in ids)
3035 _statuses.RemoveFavPost(i);
3042 if (_curTab != null && _curTab.Text.Equals(favTabName))
3044 this.PurgeListViewItemCache();
3046 //_curItemIndex = -1;
3048 foreach (TabPage tp in ListTab.TabPages)
3050 if (tp.Text == favTabName)
3052 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3056 if (_curTab.Text.Equals(favTabName))
3060 _curList.SelectedIndices.Clear();
3062 while (_curList.SelectedIndices.Count > 0);
3064 if (_statuses.Tabs[favTabName].AllCount > 0)
3066 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3068 _curList.SelectedIndices.Add(fidx);
3072 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3074 if (_curList.SelectedIndices.Count > 0)
3076 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3077 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3083 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3085 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, string tabName)
3087 if (!this.IsNetworkAvailable()) return;
3090 GetWorkerArg args = new GetWorkerArg();
3091 args.page = fromPage;
3093 args.tName = tabName;
3095 if (!lastTime.ContainsKey(WkType)) lastTime.Add(WkType, new DateTime());
3096 double period = DateTime.Now.Subtract(lastTime[WkType]).TotalSeconds;
3097 if (period > 1 || period < -1)
3099 lastTime[WkType] = DateTime.Now;
3103 //Timeline取得モードの場合はReplyも同時に取得
3104 //if (!SettingDialog.UseAPI &&
3106 // WkType == MyCommon.WORKERTYPE.Timeline &&
3107 // SettingDialog.CheckReply)
3109 // //TimerReply.Enabled = false;
3110 // _mentionCounter = SettingDialog.ReplyPeriodInt;
3111 // GetWorkerArg _args = new GetWorkerArg();
3112 // _args.page = fromPage;
3113 // _args.endPage = toPage;
3114 // _args.type = MyCommon.WORKERTYPE.Reply;
3119 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
3121 if (e.Button == MouseButtons.Left)
3123 this.Visible = true;
3124 if (this.WindowState == FormWindowState.Minimized)
3126 this.WindowState = _formWindowState;
3129 this.BringToFront();
3133 private void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
3135 switch (this._cfgCommon.ListDoubleClickAction)
3138 MakeReplyOrDirectStatus();
3141 FavoriteChange(true);
3144 if (_curPost != null)
3145 ShowUserStatus(_curPost.ScreenName, false);
3151 ShowRelatedStatusesMenuItem_Click(null, null);
3154 MoveToHomeToolStripMenuItem_Click(null, null);
3157 StatusOpenMenuItem_Click(null, null);
3165 private void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
3167 FavoriteChange(true);
3170 private void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
3172 FavoriteChange(false);
3176 private void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
3178 FavoritesRetweetOriginal();
3181 private void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
3183 FavoritesRetweetUnofficial();
3186 private void FavoriteChange(bool FavAdd , bool multiFavoriteChangeDialogEnable = true)
3188 //trueでFavAdd,falseでFavRemove
3189 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || _curList.SelectedIndices.Count == 0
3190 || !this.ExistCurrentPost) return;
3193 if (_curList.SelectedIndices.Count > 250 && FavAdd)
3195 MessageBox.Show(Properties.Resources.FavoriteLimitCountText);
3196 _DoFavRetweetFlags = false;
3199 else if (multiFavoriteChangeDialogEnable && _curList.SelectedIndices.Count > 1)
3203 string QuestionText = Properties.Resources.FavAddToolStripMenuItem_ClickText1;
3204 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText3;
3205 if (MessageBox.Show(QuestionText, Properties.Resources.FavAddToolStripMenuItem_ClickText2,
3206 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3208 _DoFavRetweetFlags = false;
3214 if (MessageBox.Show(Properties.Resources.FavRemoveToolStripMenuItem_ClickText1, Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
3215 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3222 GetWorkerArg args = new GetWorkerArg();
3223 args.ids = new List<long>();
3224 args.sIds = new List<long>();
3225 args.tName = _curTab.Text;
3228 args.type = MyCommon.WORKERTYPE.FavAdd;
3232 args.type = MyCommon.WORKERTYPE.FavRemove;
3234 foreach (int idx in _curList.SelectedIndices)
3236 PostClass post = GetCurTabPost(idx);
3239 if (!post.IsFav) args.ids.Add(post.StatusId);
3243 if (post.IsFav) args.ids.Add(post.StatusId);
3246 if (args.ids.Count == 0)
3249 StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
3251 StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
3259 private PostClass GetCurTabPost(int Index)
3261 this.itemCacheLock.EnterReadLock();
3264 if (_postCache != null && Index >= _itemCacheIndex && Index < _itemCacheIndex + _postCache.Length)
3265 return _postCache[Index - _itemCacheIndex];
3267 finally { this.itemCacheLock.ExitReadLock(); }
3269 return _statuses[_curTab.Text, Index];
3273 private void MoveToHomeToolStripMenuItem_Click(object sender, EventArgs e)
3275 if (_curList.SelectedIndices.Count > 0)
3276 OpenUriAsync(MyCommon.TwitterUrl + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName);
3277 else if (_curList.SelectedIndices.Count == 0)
3278 OpenUriAsync(MyCommon.TwitterUrl);
3281 private void MoveToFavToolStripMenuItem_Click(object sender, EventArgs e)
3283 if (_curList.SelectedIndices.Count > 0)
3284 OpenUriAsync(MyCommon.TwitterUrl + "#!/" + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName + "/favorites");
3287 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3289 if ((!_initialLayout) && this.Visible)
3291 if (this.WindowState == FormWindowState.Normal)
3293 _mySize = this.ClientSize;
3294 _mySpDis = this.SplitContainer1.SplitterDistance;
3295 _mySpDis3 = this.SplitContainer3.SplitterDistance;
3296 if (StatusText.Multiline) _mySpDis2 = this.StatusText.Height;
3297 _modifySettingLocal = true;
3302 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3304 if (this._cfgCommon.SortOrderLock) return;
3305 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
3308 mode = IdComparerClass.ComparerMode.Id;
3316 case 6: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
3320 mode = IdComparerClass.ComparerMode.Nickname;
3323 mode = IdComparerClass.ComparerMode.Data;
3326 mode = IdComparerClass.ComparerMode.Id;
3329 mode = IdComparerClass.ComparerMode.Name;
3332 mode = IdComparerClass.ComparerMode.Source;
3336 _statuses.ToggleSortOrder(mode);
3339 DetailsListView list = (DetailsListView)sender;
3342 list.Columns[0].Text = ColumnOrgText[0];
3343 list.Columns[1].Text = ColumnText[2];
3347 for (int i = 0; i <= 7; i++)
3349 list.Columns[i].Text = ColumnOrgText[i];
3351 list.Columns[e.Column].Text = ColumnText[e.Column];
3354 this.PurgeListViewItemCache();
3356 if (_statuses.Tabs[_curTab.Text].AllCount > 0 && _curPost != null)
3358 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_curPost.StatusId);
3361 SelectListItem(_curList, idx);
3362 _curList.EnsureVisible(idx);
3366 _modifySettingCommon = true;
3369 private void TweenMain_LocationChanged(object sender, EventArgs e)
3371 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
3373 _myLoc = this.DesktopLocation;
3374 _modifySettingLocal = true;
3378 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3380 if (ListTab.SelectedTab == null) return;
3381 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
3382 if (!this.ExistCurrentPost)
3384 ReplyStripMenuItem.Enabled = false;
3385 ReplyAllStripMenuItem.Enabled = false;
3386 DMStripMenuItem.Enabled = false;
3387 ShowProfileMenuItem.Enabled = false;
3388 ShowUserTimelineContextMenuItem.Enabled = false;
3389 ListManageUserContextToolStripMenuItem2.Enabled = false;
3390 MoveToFavToolStripMenuItem.Enabled = false;
3391 TabMenuItem.Enabled = false;
3392 IDRuleMenuItem.Enabled = false;
3393 ReadedStripMenuItem.Enabled = false;
3394 UnreadStripMenuItem.Enabled = false;
3398 ShowProfileMenuItem.Enabled = true;
3399 ListManageUserContextToolStripMenuItem2.Enabled = true;
3400 ReplyStripMenuItem.Enabled = true;
3401 ReplyAllStripMenuItem.Enabled = true;
3402 DMStripMenuItem.Enabled = true;
3403 ShowUserTimelineContextMenuItem.Enabled = true;
3404 MoveToFavToolStripMenuItem.Enabled = true;
3405 TabMenuItem.Enabled = true;
3406 IDRuleMenuItem.Enabled = true;
3407 ReadedStripMenuItem.Enabled = true;
3408 UnreadStripMenuItem.Enabled = true;
3410 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3411 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
3413 FavAddToolStripMenuItem.Enabled = false;
3414 FavRemoveToolStripMenuItem.Enabled = false;
3415 StatusOpenMenuItem.Enabled = false;
3416 FavorareMenuItem.Enabled = false;
3417 ShowRelatedStatusesMenuItem.Enabled = false;
3419 ReTweetStripMenuItem.Enabled = false;
3420 ReTweetOriginalStripMenuItem.Enabled = false;
3421 QuoteStripMenuItem.Enabled = false;
3422 FavoriteRetweetContextMenu.Enabled = false;
3423 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3424 if (this.ExistCurrentPost && _curPost.IsDm)
3425 DeleteStripMenuItem.Enabled = true;
3427 DeleteStripMenuItem.Enabled = false;
3431 FavAddToolStripMenuItem.Enabled = true;
3432 FavRemoveToolStripMenuItem.Enabled = true;
3433 StatusOpenMenuItem.Enabled = true;
3434 FavorareMenuItem.Enabled = true;
3435 ShowRelatedStatusesMenuItem.Enabled = true; //PublicSearchの時問題出るかも
3439 ReTweetOriginalStripMenuItem.Enabled = false;
3440 FavoriteRetweetContextMenu.Enabled = false;
3441 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3443 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3447 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3449 DeleteStripMenuItem.Enabled = true;
3453 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3455 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3459 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3461 DeleteStripMenuItem.Enabled = false;
3462 if (_curPost.IsProtect)
3464 ReTweetOriginalStripMenuItem.Enabled = false;
3465 ReTweetStripMenuItem.Enabled = false;
3466 QuoteStripMenuItem.Enabled = false;
3467 FavoriteRetweetContextMenu.Enabled = false;
3468 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3472 ReTweetOriginalStripMenuItem.Enabled = true;
3473 ReTweetStripMenuItem.Enabled = true;
3474 QuoteStripMenuItem.Enabled = true;
3475 FavoriteRetweetContextMenu.Enabled = true;
3476 FavoriteRetweetUnofficialContextMenu.Enabled = true;
3480 //if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
3482 // RefreshMoreStripMenuItem.Enabled = true;
3486 // RefreshMoreStripMenuItem.Enabled = false;
3488 if (!this.ExistCurrentPost
3489 || _curPost.InReplyToStatusId == null)
3491 RepliedStatusOpenMenuItem.Enabled = false;
3495 RepliedStatusOpenMenuItem.Enabled = true;
3497 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
3499 MoveToRTHomeMenuItem.Enabled = false;
3503 MoveToRTHomeMenuItem.Enabled = true;
3507 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3509 MakeReplyOrDirectStatus(false, true);
3512 private void DMStripMenuItem_Click(object sender, EventArgs e)
3514 MakeReplyOrDirectStatus(false, false);
3517 private void doStatusDelete()
3519 if (_curTab == null || _curList == null) return;
3520 if (_statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
3522 bool myPost = false;
3523 foreach (int idx in _curList.SelectedIndices)
3525 if (GetCurTabPost(idx).IsMe ||
3526 GetCurTabPost(idx).RetweetedBy.ToLower() == tw.Username.ToLower())
3532 if (!myPost) return;
3536 if (_curList.SelectedIndices.Count == 0)
3540 string tmp = string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine);
3542 if (MessageBox.Show(tmp, Properties.Resources.DeleteStripMenuItem_ClickText2,
3543 MessageBoxButtons.OKCancel,
3544 MessageBoxIcon.Question) == DialogResult.Cancel) return;
3547 if (_curList.FocusedItem != null)
3548 fidx = _curList.FocusedItem.Index;
3549 else if (_curList.TopItem != null)
3550 fidx = _curList.TopItem.Index;
3556 this.Cursor = Cursors.WaitCursor;
3559 foreach (long Id in _statuses.GetId(_curTab.Text, _curList.SelectedIndices))
3562 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
3564 rtn = tw.RemoveDirectMessage(Id, _statuses[Id]);
3568 if (_statuses[Id].IsMe || _statuses[Id].RetweetedBy.ToLower() == tw.Username.ToLower())
3569 rtn = tw.RemoveStatus(Id);
3580 _statuses.RemovePost(Id);
3585 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; //失敗
3587 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; //成功
3589 this.PurgeListViewItemCache();
3592 foreach (TabPage tb in ListTab.TabPages)
3594 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
3595 if (_curTab.Equals(tb))
3599 _curList.SelectedIndices.Clear();
3601 while (_curList.SelectedIndices.Count > 0);
3603 if (_statuses.Tabs[tb.Text].AllCount > 0)
3605 if (_statuses.Tabs[tb.Text].AllCount - 1 > fidx && fidx > -1)
3606 _curList.SelectedIndices.Add(fidx);
3608 _curList.SelectedIndices.Add(_statuses.Tabs[tb.Text].AllCount - 1);
3610 if (_curList.SelectedIndices.Count > 0)
3612 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3613 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3617 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3619 if (this._cfgCommon.TabIconDisp)
3621 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3625 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
3629 this.Cursor = Cursors.Default;
3633 private void DeleteStripMenuItem_Click(object sender, EventArgs e)
3638 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3640 using (ControlTransaction.Update(this._curList))
3642 if (this._cfgCommon.UnreadManage)
3644 foreach (int idx in _curList.SelectedIndices)
3646 _statuses.SetReadAllTab(true, _curTab.Text, idx);
3649 foreach (int idx in _curList.SelectedIndices)
3651 ChangeCacheStyleRead(true, idx);
3655 foreach (TabPage tb in ListTab.TabPages)
3657 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3659 if (this._cfgCommon.TabIconDisp)
3661 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3665 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
3668 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3670 using (ControlTransaction.Update(this._curList))
3672 if (this._cfgCommon.UnreadManage)
3674 foreach (int idx in _curList.SelectedIndices)
3676 _statuses.SetReadAllTab(false, _curTab.Text, idx);
3679 foreach (int idx in _curList.SelectedIndices)
3681 ChangeCacheStyleRead(false, idx);
3685 foreach (TabPage tb in ListTab.TabPages)
3687 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
3689 if (this._cfgCommon.TabIconDisp)
3691 if (tb.ImageIndex == -1) tb.ImageIndex = 0; //タブアイコン
3695 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
3698 private void RefreshStripMenuItem_Click(object sender, EventArgs e)
3703 private void DoRefresh()
3705 if (_curTab != null)
3707 switch (_statuses.Tabs[_curTab.Text].TabType)
3709 case MyCommon.TabUsageType.Mentions:
3710 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
3712 case MyCommon.TabUsageType.DirectMessage:
3713 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
3715 case MyCommon.TabUsageType.Favorites:
3716 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
3718 //case MyCommon.TabUsageType.Profile:
3720 case MyCommon.TabUsageType.PublicSearch:
3722 TabClass tb = _statuses.Tabs[_curTab.Text];
3723 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3724 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, _curTab.Text);
3726 case MyCommon.TabUsageType.UserTimeline:
3727 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, _curTab.Text);
3729 case MyCommon.TabUsageType.Lists:
3731 TabClass tab = _statuses.Tabs[_curTab.Text];
3732 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3733 GetTimeline(MyCommon.WORKERTYPE.List, 1, _curTab.Text);
3736 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3742 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3746 private void DoRefreshMore()
3749 if (_curTab != null)
3751 switch (_statuses.Tabs[_curTab.Text].TabType)
3753 case MyCommon.TabUsageType.Mentions:
3754 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
3756 case MyCommon.TabUsageType.DirectMessage:
3757 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
3759 case MyCommon.TabUsageType.Favorites:
3760 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, "");
3762 case MyCommon.TabUsageType.Profile:
3765 case MyCommon.TabUsageType.PublicSearch:
3767 TabClass tb = _statuses.Tabs[_curTab.Text];
3768 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3769 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, -1, _curTab.Text);
3771 case MyCommon.TabUsageType.UserTimeline:
3772 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, _curTab.Text);
3774 case MyCommon.TabUsageType.Lists:
3776 TabClass tab = _statuses.Tabs[_curTab.Text];
3777 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3778 GetTimeline(MyCommon.WORKERTYPE.List, -1, _curTab.Text);
3781 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3787 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3791 private void SettingStripMenuItem_Click(object sender, EventArgs e)
3793 DialogResult result;
3794 string uid = tw.Username.ToLower();
3798 result = SettingDialog.ShowDialog(this);
3805 if (result == DialogResult.OK)
3809 var oldIconSz = this._cfgCommon.IconSize;
3811 this.SettingDialog.SaveConfig(this._cfgCommon, this._cfgLocal);
3813 tw.RestrictFavCheck = this._cfgCommon.RestrictFavCheck;
3814 tw.ReadOwnPost = this._cfgCommon.ReadOwnPost;
3815 ShortUrl.Instance.DisableExpanding = !this._cfgCommon.TinyUrlResolve;
3816 ShortUrl.Instance.BitlyId = this._cfgCommon.BilyUser;
3817 ShortUrl.Instance.BitlyKey = this._cfgCommon.BitlyPwd;
3818 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3820 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
3821 Networking.SetWebProxy(this._cfgLocal.ProxyType,
3822 this._cfgLocal.ProxyAddress, this._cfgLocal.ProxyPort,
3823 this._cfgLocal.ProxyUser, this._cfgLocal.ProxyPassword);
3825 ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
3829 if (this._cfgCommon.TabIconDisp)
3831 ListTab.DrawItem -= ListTab_DrawItem;
3832 ListTab.DrawMode = TabDrawMode.Normal;
3833 ListTab.ImageList = this.TabImage;
3837 ListTab.DrawItem -= ListTab_DrawItem;
3838 ListTab.DrawItem += ListTab_DrawItem;
3839 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3840 ListTab.ImageList = null;
3843 catch (Exception ex)
3845 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3846 ex.Data["IsTerminatePermission"] = false;
3852 if (!this._cfgCommon.UnreadManage)
3854 ReadedStripMenuItem.Enabled = false;
3855 UnreadStripMenuItem.Enabled = false;
3856 if (this._cfgCommon.TabIconDisp)
3858 foreach (TabPage myTab in ListTab.TabPages)
3860 myTab.ImageIndex = -1;
3866 ReadedStripMenuItem.Enabled = true;
3867 UnreadStripMenuItem.Enabled = true;
3870 catch (Exception ex)
3872 ex.Data["Instance"] = "ListTab(UnreadManage)";
3873 ex.Data["IsTerminatePermission"] = false;
3880 SplitContainer1.IsPanelInverted = !this._cfgCommon.StatusAreaAtBottom;
3882 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3883 imgazyobizinet.Enabled = this.SettingDialog.EnableImgAzyobuziNet;
3884 imgazyobizinet.DisabledInDM = this.SettingDialog.ImgAzyobuziNetDisabledInDM;
3886 this.PlaySoundMenuItem.Checked = this._cfgCommon.PlaySound;
3887 this.PlaySoundFileMenuItem.Checked = this._cfgCommon.PlaySound;
3888 _fntUnread = this._cfgLocal.FontUnread;
3889 _clUnread = this._cfgLocal.ColorUnread;
3890 _fntReaded = this._cfgLocal.FontRead;
3891 _clReaded = this._cfgLocal.ColorRead;
3892 _clFav = this._cfgLocal.ColorFav;
3893 _clOWL = this._cfgLocal.ColorOWL;
3894 _clRetweet = this._cfgLocal.ColorRetweet;
3895 _fntDetail = this._cfgLocal.FontDetail;
3896 _clDetail = this._cfgLocal.ColorDetail;
3897 _clDetailLink = this._cfgLocal.ColorDetailLink;
3898 _clDetailBackcolor = this._cfgLocal.ColorDetailBackcolor;
3899 _clSelf = this._cfgLocal.ColorSelf;
3900 _clAtSelf = this._cfgLocal.ColorAtSelf;
3901 _clTarget = this._cfgLocal.ColorTarget;
3902 _clAtTarget = this._cfgLocal.ColorAtTarget;
3903 _clAtFromTarget = this._cfgLocal.ColorAtFromTarget;
3904 _clAtTo = this._cfgLocal.ColorAtTo;
3905 _clListBackcolor = this._cfgLocal.ColorListBackcolor;
3906 _clInputBackcolor = this._cfgLocal.ColorInputBackcolor;
3907 _clInputFont = this._cfgLocal.ColorInputFont;
3908 _fntInputFont = this._cfgLocal.FontInputFont;
3909 _brsBackColorMine.Dispose();
3910 _brsBackColorAt.Dispose();
3911 _brsBackColorYou.Dispose();
3912 _brsBackColorAtYou.Dispose();
3913 _brsBackColorAtFromTarget.Dispose();
3914 _brsBackColorAtTo.Dispose();
3915 _brsBackColorNone.Dispose();
3916 _brsBackColorMine = new SolidBrush(_clSelf);
3917 _brsBackColorAt = new SolidBrush(_clAtSelf);
3918 _brsBackColorYou = new SolidBrush(_clTarget);
3919 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
3920 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
3921 _brsBackColorAtTo = new SolidBrush(_clAtTo);
3922 _brsBackColorNone = new SolidBrush(_clListBackcolor);
3926 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
3927 StatusText.Font = _fntInputFont;
3928 StatusText.ForeColor = _clInputFont;
3930 catch (Exception ex)
3932 MessageBox.Show(ex.Message);
3937 InitDetailHtmlFormat();
3939 catch (Exception ex)
3941 ex.Data["Instance"] = "Font";
3942 ex.Data["IsTerminatePermission"] = false;
3948 _statuses.SetUnreadManage(this._cfgCommon.UnreadManage);
3950 catch (Exception ex)
3952 ex.Data["Instance"] = "_statuses";
3953 ex.Data["IsTerminatePermission"] = false;
3959 foreach (TabPage tb in ListTab.TabPages)
3961 if (this._cfgCommon.TabIconDisp)
3963 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3970 catch (Exception ex)
3972 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
3973 ex.Data["IsTerminatePermission"] = false;
3979 var oldIconCol = _iconCol;
3981 if (this._cfgCommon.IconSize != oldIconSz)
3982 ApplyListViewIconSize(this._cfgCommon.IconSize);
3984 foreach (TabPage tp in ListTab.TabPages)
3986 DetailsListView lst = (DetailsListView)tp.Tag;
3988 using (ControlTransaction.Update(lst))
3990 lst.GridLines = this._cfgCommon.ShowGrid;
3991 lst.Font = _fntReaded;
3992 lst.BackColor = _clListBackcolor;
3994 if (_iconCol != oldIconCol)
3999 catch (Exception ex)
4001 ex.Data["Instance"] = "ListView(IconSize)";
4002 ex.Data["IsTerminatePermission"] = false;
4006 SetMainWindowTitle();
4007 SetNotifyIconText();
4009 this.PurgeListViewItemCache();
4010 if (_curList != null) _curList.Refresh();
4013 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4014 if (this._cfgCommon.HotkeyEnabled)
4016 ///グローバルホットキーの登録。設定で変更可能にするかも
4017 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4018 if ((this._cfgCommon.HotkeyModifier & Keys.Alt) == Keys.Alt)
4019 modKey |= HookGlobalHotkey.ModKeys.Alt;
4020 if ((this._cfgCommon.HotkeyModifier & Keys.Control) == Keys.Control)
4021 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
4022 if ((this._cfgCommon.HotkeyModifier & Keys.Shift) == Keys.Shift)
4023 modKey |= HookGlobalHotkey.ModKeys.Shift;
4024 if ((this._cfgCommon.HotkeyModifier & Keys.LWin) == Keys.LWin)
4025 modKey |= HookGlobalHotkey.ModKeys.Win;
4027 _hookGlobalHotkey.RegisterOriginalHotkey(this._cfgCommon.HotkeyKey, this._cfgCommon.HotkeyValue, modKey);
4030 if (uid != tw.Username) this.doGetFollowersMenu();
4032 if (this._cfgCommon.IsUseNotifyGrowl) gh.RegisterGrowl();
4035 StatusText_TextChanged(null, null);
4043 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4045 this.TopMost = this._cfgCommon.AlwaysTop;
4046 SaveConfigsAll(false);
4052 private void SetTabAlignment()
4054 var newAlignment = this._cfgCommon.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
4055 if (ListTab.Alignment == newAlignment) return;
4058 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
4059 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
4060 SaveSelectedStatus(selId, focusedId);
4062 ListTab.Alignment = newAlignment;
4065 foreach (TabPage tab in ListTab.TabPages)
4067 DetailsListView lst = (DetailsListView)tab.Tag;
4068 TabClass tabInfo = _statuses.Tabs[tab.Text];
4069 using (ControlTransaction.Update(lst))
4071 this.SelectListItem(lst,
4072 tabInfo.IndexOf(selId[tab.Text]),
4073 tabInfo.IndexOf(focusedId[tab.Text]));
4078 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
4084 case MyCommon.IconSizes.IconNone:
4087 case MyCommon.IconSizes.Icon16:
4090 case MyCommon.IconSizes.Icon24:
4093 case MyCommon.IconSizes.Icon48:
4096 case MyCommon.IconSizes.Icon48_2:
4104 // ディスプレイの DPI 設定を考慮したサイズを設定する
4105 _listViewImageList.ImageSize = new Size(
4107 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4111 _listViewImageList.ImageSize = new Size(1, 1);
4115 private void ResetColumns(DetailsListView list)
4117 using (ControlTransaction.Update(list))
4118 using (ControlTransaction.Layout(list, false))
4121 list.ColumnClick -= MyList_ColumnClick;
4122 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4123 list.ColumnReordered -= MyList_ColumnReordered;
4124 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4126 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4127 list.Columns.Clear();
4128 cols.ForEach(col => col.Dispose());
4131 InitColumns(list, true);
4133 list.ColumnClick += MyList_ColumnClick;
4134 list.DrawColumnHeader += MyList_DrawColumnHeader;
4135 list.ColumnReordered += MyList_ColumnReordered;
4136 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4140 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4142 if (e.Url.AbsoluteUri != "about:blank")
4145 OpenUriAsync(e.Url.OriginalString);
4149 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4151 if (e.Url.Scheme == "data")
4153 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4155 else if (e.Url.AbsoluteUri != "about:blank")
4159 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4160 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4163 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4164 int i = urlStr.IndexOf('#');
4165 if (i == -1) return;
4167 string hash = urlStr.Substring(i);
4168 HashSupl.AddItem(hash);
4169 HashMgr.AddHashToHistory(hash.Trim(), false);
4170 AddNewTabForSearch(hash);
4175 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4176 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4178 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4179 if (this._cfgCommon.OpenUserTimeline)
4181 if (MyCommon.IsKeyDown(Keys.Control))
4182 OpenUriAsync(e.Url.OriginalString);
4184 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4188 if (MyCommon.IsKeyDown(Keys.Control))
4189 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4191 OpenUriAsync(e.Url.OriginalString);
4196 OpenUriAsync(e.Url.OriginalString);
4202 public void AddNewTabForSearch(string searchWord)
4204 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4205 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4207 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4209 foreach (TabPage tp in ListTab.TabPages)
4211 if (tb.TabName == tp.Text)
4213 ListTab.SelectedTab = tp;
4220 string tabName = searchWord;
4221 for (int i = 0; i <= 100; i++)
4223 if (_statuses.ContainsTab(tabName))
4229 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4230 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4232 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4234 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4235 cmb.Items.Add(searchWord);
4236 cmb.Text = searchWord;
4239 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4242 private void ShowUserTimeline()
4244 if (!this.ExistCurrentPost) return;
4245 AddNewTabForUserTimeline(_curPost.ScreenName);
4248 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4250 if (e.KeyCode == Keys.Escape)
4252 TabPage relTp = ListTab.SelectedTab;
4253 RemoveSpecifiedTab(relTp.Text, false);
4255 e.SuppressKeyPress = true;
4259 public void AddNewTabForUserTimeline(string user)
4261 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4262 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4264 if (tb.User == user)
4266 foreach (TabPage tp in ListTab.TabPages)
4268 if (tb.TabName == tp.Text)
4270 ListTab.SelectedTab = tp;
4277 string tabName = "user:" + user;
4278 while (_statuses.ContainsTab(tabName))
4283 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4284 _statuses.Tabs[tabName].User = user;
4285 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4287 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4291 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, tabName);
4294 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4297 foreach (TabPage tb in ListTab.TabPages)
4299 if (tb.Text == tabName) return false;
4303 if (tabName == Properties.Resources.AddNewTabText1) return false;
4308 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4309 tabType == MyCommon.TabUsageType.Favorites ||
4310 tabType == MyCommon.TabUsageType.Home ||
4311 tabType == MyCommon.TabUsageType.Mentions ||
4312 tabType == MyCommon.TabUsageType.Related)
4314 if (_statuses.GetTabByType(tabType) != null) return false;
4318 TabPage _tabPage = new TabPage();
4319 DetailsListView _listCustom = new DetailsListView();
4321 int cnt = ListTab.TabPages.Count;
4323 ///ToDo:Create and set controls follow tabtypes
4325 using (ControlTransaction.Update(_listCustom))
4326 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4327 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4328 using (ControlTransaction.Layout(this.SplitContainer1, false))
4329 using (ControlTransaction.Layout(this.ListTab, false))
4330 using (ControlTransaction.Layout(this))
4331 using (ControlTransaction.Layout(_tabPage, false))
4335 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4337 label = new Label();
4338 label.Dock = DockStyle.Top;
4339 label.Name = "labelUser";
4340 if (tabType == MyCommon.TabUsageType.Lists)
4342 label.Text = listInfo.ToString();
4346 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4348 label.TextAlign = ContentAlignment.MiddleLeft;
4349 using (ComboBox tmpComboBox = new ComboBox())
4351 label.Height = tmpComboBox.Height;
4353 _tabPage.Controls.Add(label);
4358 if (tabType == MyCommon.TabUsageType.PublicSearch)
4362 Label lbl = new Label();
4363 ComboBox cmb = new ComboBox();
4364 Button btn = new Button();
4365 ComboBox cmbLang = new ComboBox();
4367 pnl.SuspendLayout();
4369 pnl.Controls.Add(cmb);
4370 pnl.Controls.Add(cmbLang);
4371 pnl.Controls.Add(btn);
4372 pnl.Controls.Add(lbl);
4373 pnl.Name = "panelSearch";
4374 pnl.Dock = DockStyle.Top;
4375 pnl.Height = cmb.Height;
4376 pnl.Enter += SearchControls_Enter;
4377 pnl.Leave += SearchControls_Leave;
4380 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4381 cmb.Dock = DockStyle.Fill;
4382 cmb.Name = "comboSearch";
4383 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4384 cmb.ImeMode = ImeMode.NoControl;
4385 cmb.TabStop = false;
4386 cmb.AutoCompleteMode = AutoCompleteMode.None;
4387 cmb.KeyDown += SearchComboBox_KeyDown;
4389 if (_statuses.ContainsTab(tabName))
4391 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4392 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4396 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4397 cmbLang.Dock = DockStyle.Right;
4399 cmbLang.Name = "comboLang";
4400 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4401 cmbLang.TabStop = false;
4402 cmbLang.Items.Add("");
4403 cmbLang.Items.Add("ja");
4404 cmbLang.Items.Add("en");
4405 cmbLang.Items.Add("ar");
4406 cmbLang.Items.Add("da");
4407 cmbLang.Items.Add("nl");
4408 cmbLang.Items.Add("fa");
4409 cmbLang.Items.Add("fi");
4410 cmbLang.Items.Add("fr");
4411 cmbLang.Items.Add("de");
4412 cmbLang.Items.Add("hu");
4413 cmbLang.Items.Add("is");
4414 cmbLang.Items.Add("it");
4415 cmbLang.Items.Add("no");
4416 cmbLang.Items.Add("pl");
4417 cmbLang.Items.Add("pt");
4418 cmbLang.Items.Add("ru");
4419 cmbLang.Items.Add("es");
4420 cmbLang.Items.Add("sv");
4421 cmbLang.Items.Add("th");
4422 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4424 lbl.Text = "Search(C-S-f)";
4425 lbl.Name = "label1";
4426 lbl.Dock = DockStyle.Left;
4428 lbl.Height = cmb.Height;
4429 lbl.TextAlign = ContentAlignment.MiddleLeft;
4431 btn.Text = "Search";
4432 btn.Name = "buttonSearch";
4433 btn.UseVisualStyleBackColor = true;
4434 btn.Dock = DockStyle.Right;
4435 btn.TabStop = false;
4436 btn.Click += SearchButton_Click;
4439 this.ListTab.Controls.Add(_tabPage);
4440 _tabPage.Controls.Add(_listCustom);
4442 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4443 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4445 _tabPage.Location = new Point(4, 4);
4446 _tabPage.Name = "CTab" + cnt.ToString();
4447 _tabPage.Size = new Size(380, 260);
4448 _tabPage.TabIndex = 2 + cnt;
4449 _tabPage.Text = tabName;
4450 _tabPage.UseVisualStyleBackColor = true;
4452 _listCustom.AllowColumnReorder = true;
4453 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4454 _listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4455 _listCustom.Dock = DockStyle.Fill;
4456 _listCustom.FullRowSelect = true;
4457 _listCustom.HideSelection = false;
4458 _listCustom.Location = new Point(0, 0);
4459 _listCustom.Margin = new Padding(0);
4460 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4461 _listCustom.ShowItemToolTips = true;
4462 _listCustom.Size = new Size(380, 260);
4463 _listCustom.UseCompatibleStateImageBehavior = false;
4464 _listCustom.View = View.Details;
4465 _listCustom.OwnerDraw = true;
4466 _listCustom.VirtualMode = true;
4467 _listCustom.Font = _fntReaded;
4468 _listCustom.BackColor = _clListBackcolor;
4470 _listCustom.GridLines = this._cfgCommon.ShowGrid;
4471 _listCustom.AllowDrop = true;
4473 _listCustom.SmallImageList = _listViewImageList;
4475 InitColumns(_listCustom, startup);
4477 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4478 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4479 _listCustom.ColumnClick += MyList_ColumnClick;
4480 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4481 _listCustom.DragDrop += TweenMain_DragDrop;
4482 _listCustom.DragEnter += TweenMain_DragEnter;
4483 _listCustom.DragOver += TweenMain_DragOver;
4484 _listCustom.DrawItem += MyList_DrawItem;
4485 _listCustom.MouseClick += MyList_MouseClick;
4486 _listCustom.ColumnReordered += MyList_ColumnReordered;
4487 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4488 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4489 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4490 _listCustom.DrawSubItem += MyList_DrawSubItem;
4491 _listCustom.HScrolled += MyList_HScrolled;
4493 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4496 _tabPage.Tag = _listCustom;
4500 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4502 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4506 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4507 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4508 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4514 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4515 if (_tabPage == null) return false;
4517 SetListProperty(); //他のタブに列幅等を反映
4519 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4522 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4523 _tabPage.Tag = null;
4525 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4526 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4527 using (ControlTransaction.Layout(this.SplitContainer1, false))
4528 using (ControlTransaction.Layout(this.ListTab, false))
4529 using (ControlTransaction.Layout(this))
4530 using (ControlTransaction.Layout(_tabPage, false))
4532 if (this.ListTab.SelectedTab == _tabPage)
4534 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4535 this._beforeSelectedTab = null;
4537 this.ListTab.Controls.Remove(_tabPage);
4540 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4542 using (Control label = _tabPage.Controls["labelUser"])
4544 _tabPage.Controls.Remove(label);
4547 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4549 using (Control pnl = _tabPage.Controls["panelSearch"])
4551 pnl.Enter -= SearchControls_Enter;
4552 pnl.Leave -= SearchControls_Leave;
4553 _tabPage.Controls.Remove(pnl);
4555 foreach (Control ctrl in pnl.Controls)
4557 if (ctrl.Name == "buttonSearch")
4559 ctrl.Click -= SearchButton_Click;
4561 else if (ctrl.Name == "comboSearch")
4563 ctrl.KeyDown -= SearchComboBox_KeyDown;
4565 pnl.Controls.Remove(ctrl);
4571 _tabPage.Controls.Remove(_listCustom);
4573 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4574 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4575 _listCustom.ColumnClick -= MyList_ColumnClick;
4576 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4577 _listCustom.DragDrop -= TweenMain_DragDrop;
4578 _listCustom.DragEnter -= TweenMain_DragEnter;
4579 _listCustom.DragOver -= TweenMain_DragOver;
4580 _listCustom.DrawItem -= MyList_DrawItem;
4581 _listCustom.MouseClick -= MyList_MouseClick;
4582 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4583 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4584 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4585 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4586 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4587 _listCustom.HScrolled -= MyList_HScrolled;
4589 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4590 _listCustom.Columns.Clear();
4591 cols.ForEach(col => col.Dispose());
4594 _listCustom.ContextMenuStrip = null;
4595 _listCustom.ColumnHeaderContextMenuStrip = null;
4596 _listCustom.Font = null;
4598 _listCustom.SmallImageList = null;
4599 _listCustom.ListViewItemSorter = null;
4602 if (_curTab.Equals(_tabPage))
4609 this.PurgeListViewItemCache();
4613 _listCustom.Dispose();
4614 _statuses.RemoveTab(TabName);
4616 foreach (TabPage tp in ListTab.TabPages)
4618 DetailsListView lst = (DetailsListView)tp.Tag;
4619 var count = _statuses.Tabs[tp.Text].AllCount;
4620 if (lst.VirtualListSize != count)
4622 lst.VirtualListSize = count;
4629 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4631 this.PurgeListViewItemCache();
4632 _beforeSelectedTab = e.TabPage;
4635 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4639 if (!this._cfgCommon.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4642 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4643 if (!dragEnableRectangle.Contains(e.Location))
4645 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4646 tn = ListTab.SelectedTab.Text;
4649 if (string.IsNullOrEmpty(tn)) return;
4651 foreach (TabPage tb in ListTab.TabPages)
4655 ListTab.DoDragDrop(tb, DragDropEffects.All);
4665 Point cpos = new Point(e.X, e.Y);
4666 for (int i = 0; i < ListTab.TabPages.Count; i++)
4668 Rectangle rect = ListTab.GetTabRect(i);
4669 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4670 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4672 _rclickTabName = ListTab.TabPages[i].Text;
4678 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4680 //_curList.Refresh();
4682 SetMainWindowTitle();
4683 SetStatusLabelUrl();
4684 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4685 TabMenuControl(ListTab.SelectedTab.Text);
4686 this.PushSelectPostChain();
4689 private void SetListProperty()
4691 //削除などで見つからない場合は処理せず
4692 if (_curList == null) return;
4693 if (!_isColumnChanged) return;
4695 int[] dispOrder = new int[_curList.Columns.Count];
4696 for (int i = 0; i < _curList.Columns.Count; i++)
4698 for (int j = 0; j < _curList.Columns.Count; j++)
4700 if (_curList.Columns[j].DisplayIndex == i)
4709 foreach (TabPage tb in ListTab.TabPages)
4711 if (!tb.Equals(_curTab))
4713 if (tb.Tag != null && tb.Controls.Count > 0)
4715 DetailsListView lst = (DetailsListView)tb.Tag;
4716 for (int i = 0; i < lst.Columns.Count; i++)
4718 lst.Columns[dispOrder[i]].DisplayIndex = i;
4719 lst.Columns[i].Width = _curList.Columns[i].Width;
4725 _isColumnChanged = false;
4728 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4732 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4733 || PostBrowser.StatusText.StartsWith("data"))
4735 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4737 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4739 SetStatusLabelUrl();
4747 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4749 if (e.KeyChar == '@')
4751 if (!this._cfgCommon.UseAtIdSupplement) return;
4753 int cnt = AtIdSupl.ItemCount;
4754 ShowSuplDialog(StatusText, AtIdSupl);
4755 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4758 else if (e.KeyChar == '#')
4760 if (!this._cfgCommon.UseHashSupplement) return;
4761 ShowSuplDialog(StatusText, HashSupl);
4766 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4768 ShowSuplDialog(owner, dialog, 0, "");
4771 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4773 ShowSuplDialog(owner, dialog, offset, "");
4776 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4778 dialog.StartsWith = startswith;
4785 dialog.ShowDialog();
4787 this.TopMost = this._cfgCommon.AlwaysTop;
4788 int selStart = owner.SelectionStart;
4791 if (dialog.DialogResult == DialogResult.OK)
4793 if (!string.IsNullOrEmpty(dialog.inputText))
4797 fHalf = owner.Text.Substring(0, selStart - offset);
4799 if (selStart < owner.Text.Length)
4801 eHalf = owner.Text.Substring(selStart);
4803 owner.Text = fHalf + dialog.inputText + eHalf;
4804 owner.SelectionStart = selStart + dialog.inputText.Length;
4811 fHalf = owner.Text.Substring(0, selStart);
4813 if (selStart < owner.Text.Length)
4815 eHalf = owner.Text.Substring(selStart);
4817 owner.Text = fHalf + eHalf;
4820 owner.SelectionStart = selStart;
4826 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4829 if (!e.Alt && !e.Control && !e.Shift)
4831 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4833 bool isSpace = false;
4834 foreach (char c in StatusText.Text.ToCharArray())
4836 if (c == ' ' || c == ' ')
4849 StatusText.Text = "";
4850 JumpUnreadMenuItem_Click(null, null);
4854 this.StatusText_TextChanged(null, null);
4857 private void StatusText_TextChanged(object sender, EventArgs e)
4860 int pLen = GetRestStatusCount(true, false);
4861 lblLen.Text = pLen.ToString();
4864 StatusText.ForeColor = Color.Red;
4868 StatusText.ForeColor = _clInputFont;
4870 if (string.IsNullOrEmpty(StatusText.Text))
4872 _reply_to_id = null;
4873 _reply_to_name = null;
4877 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
4880 var statusText = this.StatusText.Text;
4881 statusText = statusText.Replace("\r\n", "\n");
4883 int pLen = 140 - statusText.Length;
4884 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
4885 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && this._cfgCommon.PostShiftEnter) ||
4886 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !this._cfgCommon.PostShiftEnter) ||
4887 (!isAuto && isAddFooter))
4889 if (this._cfgLocal.UseRecommendStatus)
4890 pLen -= SettingDialog.RecommendStatusText.Length;
4891 else if (this._cfgLocal.StatusText.Length > 0)
4892 pLen -= this._cfgLocal.StatusText.Length + 1;
4894 if (!string.IsNullOrEmpty(HashMgr.UseHash))
4896 pLen -= HashMgr.UseHash.Length + 1;
4898 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
4900 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4902 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
4904 string before = m.Result("${before}");
4905 string url = m.Result("${url}");
4906 string protocol = m.Result("${protocol}");
4907 string domain = m.Result("${domain}");
4908 string path = m.Result("${path}");
4909 if (protocol.Length == 0)
4911 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
4916 bool last_url_invalid_match = false;
4917 string lasturl = null;
4918 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
4920 lasturl = mm.ToString();
4921 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
4922 if (!last_url_invalid_match)
4924 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4928 if (path.Length != 0)
4930 if (last_url_invalid_match)
4932 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4934 pLen += path.Length;
4939 int shortUrlLength = protocol == "https://"
4940 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
4941 : SettingDialog.TwitterConfiguration.ShortUrlLength;
4943 pLen += url.Length - shortUrlLength;
4946 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
4948 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4951 if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
4953 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
4958 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
4960 this.itemCacheLock.EnterUpgradeableReadLock();
4963 if (_curList.Equals(sender))
4965 if (_itemCache != null &&
4966 e.StartIndex >= _itemCacheIndex &&
4967 e.EndIndex < _itemCacheIndex + _itemCache.Length)
4969 //If the newly requested cache is a subset of the old cache,
4970 //no need to rebuild everything, so do nothing.
4974 //Now we need to rebuild the cache.
4975 CreateCache(e.StartIndex, e.EndIndex);
4978 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
4981 private async void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
4983 ListViewItem item = null;
4984 PostClass cacheItemPost = null;
4986 if (_curList.Equals(sender))
4987 this.TryGetListViewItemCache(e.ItemIndex, out item, out cacheItemPost);
4991 //A cache miss, so create a new ListViewItem and pass it back.
4992 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
4995 item = this.CreateItem(tb, _statuses[tb.Text, e.ItemIndex], e.ItemIndex);
5000 string[] sitem = {"", "", "", "", "", "", "", ""};
5001 item = new ImageListViewItem(sitem);
5005 // e.Item に値をセットする前に await しないこと
5008 await ((ImageListViewItem)item).GetImageAsync();
5011 private void CreateCache(int StartIndex, int EndIndex)
5013 this.itemCacheLock.EnterWriteLock();
5016 var tabInfo = _statuses.Tabs[_curTab.Text];
5018 //キャッシュ要求(要求範囲±30を作成)
5020 if (StartIndex < 0) StartIndex = 0;
5022 if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
5023 _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
5024 _itemCacheIndex = StartIndex;
5026 _itemCache = new ListViewItem[0] {};
5027 Array.Resize(ref _itemCache, _postCache.Length);
5029 for (int i = 0; i < _postCache.Length; i++)
5031 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5036 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5038 _itemCacheIndex = -1;
5041 finally { this.itemCacheLock.ExitWriteLock(); }
5045 /// DetailsListView のための ListViewItem のキャッシュを消去する
5047 private void PurgeListViewItemCache()
5049 this.itemCacheLock.EnterWriteLock();
5052 this._itemCache = null;
5053 this._itemCacheIndex = -1;
5054 this._postCache = null;
5056 finally { this.itemCacheLock.ExitWriteLock(); }
5059 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5061 this.itemCacheLock.EnterReadLock();
5064 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5066 item = this._itemCache[index - _itemCacheIndex];
5067 post = this._postCache[index - _itemCacheIndex];
5071 finally { this.itemCacheLock.ExitReadLock(); }
5078 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5080 StringBuilder mk = new StringBuilder();
5081 //if (Post.IsDeleted) mk.Append("×");
5082 //if (Post.IsMark) mk.Append("♪");
5083 //if (Post.IsProtect) mk.Append("Ю");
5084 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5085 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5086 ImageListViewItem itm;
5087 if (Post.RetweetedId == null)
5089 string[] sitem= {"",
5091 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5092 Post.CreatedAt.ToString(this._cfgCommon.DateTimeFormat),
5097 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5101 string[] sitem = {"",
5103 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5104 Post.CreatedAt.ToString(this._cfgCommon.DateTimeFormat),
5105 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5109 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5111 itm.StateIndex = Post.StateIndex;
5113 bool read = Post.IsRead;
5114 //未読管理していなかったら既読として扱う
5115 if (!_statuses.Tabs[Tab.Text].UnreadManage || !this._cfgCommon.UnreadManage) read = true;
5116 ChangeItemStyleRead(read, itm, Post, null);
5117 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5122 /// 全てのタブの振り分けルールを反映し直します
5124 private void ApplyPostFilters()
5128 this.Cursor = Cursors.WaitCursor;
5130 this.PurgeListViewItemCache();
5131 this._curPost = null;
5132 this._curItemIndex = -1;
5133 this._statuses.FilterAll();
5135 foreach (TabPage tabPage in this.ListTab.TabPages)
5137 var tab = this._statuses.Tabs[tabPage.Text];
5139 var listview = (DetailsListView)tabPage.Tag;
5140 listview.VirtualListSize = tab.AllCount;
5142 if (this._cfgCommon.TabIconDisp)
5144 if (tab.UnreadCount > 0)
5145 tabPage.ImageIndex = 0;
5147 tabPage.ImageIndex = -1;
5151 if (!this._cfgCommon.TabIconDisp)
5152 this.ListTab.Refresh();
5156 this.Cursor = Cursors.Default;
5160 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5162 e.DrawDefault = true;
5165 private void MyList_HScrolled(object sender, EventArgs e)
5167 DetailsListView listView = (DetailsListView)sender;
5171 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5173 if (e.State == 0) return;
5174 e.DrawDefault = false;
5176 SolidBrush brs2 = null;
5177 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5179 if (e.Item.BackColor == _clSelf)
5180 brs2 = _brsBackColorMine;
5181 else if (e.Item.BackColor == _clAtSelf)
5182 brs2 = _brsBackColorAt;
5183 else if (e.Item.BackColor == _clTarget)
5184 brs2 = _brsBackColorYou;
5185 else if (e.Item.BackColor == _clAtTarget)
5186 brs2 = _brsBackColorAtYou;
5187 else if (e.Item.BackColor == _clAtFromTarget)
5188 brs2 = _brsBackColorAtFromTarget;
5189 else if (e.Item.BackColor == _clAtTo)
5190 brs2 = _brsBackColorAtTo;
5192 brs2 = _brsBackColorNone;
5197 if (((Control)sender).Focused)
5198 brs2 = _brsHighLight;
5200 brs2 = _brsDeactiveSelection;
5202 e.Graphics.FillRectangle(brs2, e.Bounds);
5203 e.DrawFocusRectangle();
5204 this.DrawListViewItemIcon(e);
5207 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5209 if (e.ItemState == 0) return;
5211 if (e.ColumnIndex > 0)
5214 RectangleF rct = e.Bounds;
5215 rct.Width = e.Header.Width;
5216 int fontHeight = e.Item.Font.Height;
5219 rct.Y += fontHeight;
5220 rct.Height -= fontHeight;
5224 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out heightDiff));
5226 //if (heightDiff > fontHeight * 0.7)
5228 // rct.Height += fontHeight;
5229 // drawLineCount += 1;
5232 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5233 if (!_iconCol && drawLineCount <= 1)
5235 //rct.Inflate(0, heightDiff / -2);
5236 //rct.Height += fontHeight / 2;
5238 else if (heightDiff < fontHeight * 0.7)
5240 //最終行が70%以上欠けていたら、最終行は表示しない
5241 //rct.Height = (float)((fontHeight * drawLineCount) + (fontHeight / 2));
5242 rct.Height = (fontHeight * drawLineCount) - 1;
5249 //if (!_iconCol && drawLineCount > 1)
5251 // rct.Y += fontHeight * 0.2;
5252 // if (heightDiff >= fontHeight * 0.8) rct.Height -= fontHeight * 0.2;
5257 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5258 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5263 Rectangle rctB = e.Bounds;
5264 rctB.Width = e.Header.Width;
5265 rctB.Height = fontHeight;
5267 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5269 TextRenderer.DrawText(e.Graphics,
5270 e.Item.SubItems[2].Text,
5272 Rectangle.Round(rct),
5274 TextFormatFlags.WordBreak |
5275 TextFormatFlags.EndEllipsis |
5276 TextFormatFlags.GlyphOverhangPadding |
5277 TextFormatFlags.NoPrefix);
5278 TextRenderer.DrawText(e.Graphics,
5279 e.Item.SubItems[4].Text + " / " + e.Item.SubItems[1].Text + " (" + e.Item.SubItems[3].Text + ") " + e.Item.SubItems[5].Text + e.Item.SubItems[6].Text + " [" + e.Item.SubItems[7].Text + "]",
5283 TextFormatFlags.SingleLine |
5284 TextFormatFlags.EndEllipsis |
5285 TextFormatFlags.GlyphOverhangPadding |
5286 TextFormatFlags.NoPrefix);
5289 else if (drawLineCount == 1)
5291 TextRenderer.DrawText(e.Graphics,
5294 Rectangle.Round(rct),
5296 TextFormatFlags.SingleLine |
5297 TextFormatFlags.EndEllipsis |
5298 TextFormatFlags.GlyphOverhangPadding |
5299 TextFormatFlags.NoPrefix |
5300 TextFormatFlags.VerticalCenter);
5304 TextRenderer.DrawText(e.Graphics,
5307 Rectangle.Round(rct),
5309 TextFormatFlags.WordBreak |
5310 TextFormatFlags.EndEllipsis |
5311 TextFormatFlags.GlyphOverhangPadding |
5312 TextFormatFlags.NoPrefix);
5314 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5319 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5321 if (_iconSz == 0) return;
5323 ImageListViewItem item = (ImageListViewItem)e.Item;
5325 //e.Bounds.Leftが常に0を指すから自前で計算
5326 Rectangle itemRect = item.Bounds;
5327 var col0 = e.Item.ListView.Columns[0];
5328 itemRect.Width = col0.Width;
5330 if (col0.DisplayIndex > 0)
5332 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5334 if (clm.DisplayIndex < col0.DisplayIndex)
5335 itemRect.X += clm.Width;
5339 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5340 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5341 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5344 var img = item.Image;
5347 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5348 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5350 if (iconRect.Width > 0)
5352 e.Graphics.FillRectangle(Brushes.White, iconRect);
5353 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5356 e.Graphics.DrawImage(img.Image, iconRect);
5358 catch (ArgumentException)
5360 item.RefreshImageAsync();
5366 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5367 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5370 if (item.StateIndex > -1)
5372 Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5373 if (stateRect.Width > 0)
5375 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5376 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5377 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5382 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5384 base.ScaleControl(factor, specified);
5386 const int baseDpi = 96;
5388 // デザイン時の DPI (96dpi) との比を更新する
5389 this.currentScaleFactor = new SizeF(
5390 this.CurrentAutoScaleDimensions.Width / baseDpi,
5391 this.CurrentAutoScaleDimensions.Height / baseDpi);
5394 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5396 // ImageListViewItem item = (ImageListViewItem)e.Item;
5397 // if (item.StateImageIndex > -1)
5399 // ////e.Bounds.Leftが常に0を指すから自前で計算
5400 // //Rectangle itemRect = item.Bounds;
5401 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5403 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5405 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5407 // // itemRect.X += clm.Width;
5411 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5412 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5414 // if (rct.Width > 0)
5416 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5417 // //e.Graphics.FillRectangle(Brushes.White, rct);
5418 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5419 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5424 private void DoTabSearch(string _word,
5434 if (_curList.VirtualListSize == 0)
5436 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5439 if (_curList.SelectedIndices.Count > 0)
5441 cidx = _curList.SelectedIndices[0];
5443 toIdx = _curList.VirtualListSize;
5447 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5448 if (_curList.SelectedIndices.Count > 0)
5449 cidx = _curList.SelectedIndices[0];
5453 case SEARCHTYPE.NextSearch: //次を検索
5454 if (_curList.SelectedIndices.Count > 0)
5456 cidx = _curList.SelectedIndices[0] + 1;
5457 if (cidx > toIdx) cidx = toIdx;
5464 case SEARCHTYPE.PrevSearch: //前を検索
5465 if (_curList.SelectedIndices.Count > 0)
5467 cidx = _curList.SelectedIndices[0] - 1;
5468 if (cidx < 0) cidx = 0;
5479 RegexOptions regOpt = RegexOptions.None;
5480 StringComparison fndOpt = StringComparison.Ordinal;
5483 regOpt = RegexOptions.IgnoreCase;
5484 fndOpt = StringComparison.OrdinalIgnoreCase;
5495 _search = new Regex(_word, regOpt);
5496 for (int idx = cidx; idx != toIdx; idx += stp)
5501 post = _statuses[_curTab.Text, idx];
5507 if (_search.IsMatch(post.Nickname)
5508 || _search.IsMatch(post.TextFromApi)
5509 || _search.IsMatch(post.ScreenName))
5511 SelectListItem(_curList, idx);
5512 _curList.EnsureVisible(idx);
5517 catch (ArgumentException)
5519 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5526 for (int idx = cidx; idx != toIdx; idx += stp)
5531 post = _statuses[_curTab.Text, idx];
5537 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5538 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5539 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5541 SelectListItem(_curList, idx);
5542 _curList.EnsureVisible(idx);
5552 case SEARCHTYPE.DialogSearch:
5553 case SEARCHTYPE.NextSearch:
5557 case SEARCHTYPE.PrevSearch:
5559 cidx = _curList.VirtualListSize - 1;
5566 catch (ArgumentOutOfRangeException)
5569 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5572 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5575 this.ShowSearchDialog();
5578 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5580 var previousSearch = this.SearchDialog.ResultOptions;
5581 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5583 this.SearchDialog.Reset();
5584 this.ShowSearchDialog();
5590 previousSearch.Query,
5591 previousSearch.CaseSensitive,
5592 previousSearch.UseRegex,
5593 SEARCHTYPE.NextSearch);
5596 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5598 var previousSearch = this.SearchDialog.ResultOptions;
5599 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5601 this.SearchDialog.Reset();
5602 this.ShowSearchDialog();
5608 previousSearch.Query,
5609 previousSearch.CaseSensitive,
5610 previousSearch.UseRegex,
5611 SEARCHTYPE.PrevSearch);
5615 /// 検索ダイアログを表示し、検索を実行します
5617 private void ShowSearchDialog()
5619 // Recentタブの検索時以外では「新規タブに表示」ボタンを無効化する
5620 if (this._statuses.Tabs[this._curTab.Text].TabType == MyCommon.TabUsageType.Home)
5621 this.SearchDialog.DisableNewTabButton = false;
5623 this.SearchDialog.DisableNewTabButton = true;
5625 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5627 this.TopMost = this._cfgCommon.AlwaysTop;
5630 this.TopMost = this._cfgCommon.AlwaysTop;
5632 var searchOptions = this.SearchDialog.ResultOptions;
5633 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5635 if (searchOptions.NewTab)
5637 var tabName = searchOptions.Query;
5641 tabName = this._statuses.MakeTabName(tabName);
5643 catch (TabException ex)
5645 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5648 this.AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined);
5649 this._statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
5651 var filter = new PostFilterRule
5653 FilterBody = new[] { searchOptions.Query },
5654 UseRegex = searchOptions.UseRegex,
5655 CaseSensitive = searchOptions.CaseSensitive,
5657 this._statuses.Tabs[tabName].AddFilter(filter);
5659 var tabPage = this.ListTab.TabPages.Cast<TabPage>()
5660 .First(x => x.Text == tabName);
5662 this.ListTab.SelectedTab = tabPage;
5663 this.ListTabSelect(tabPage);
5665 this.ApplyPostFilters();
5666 this.SaveConfigsTabs();
5671 searchOptions.Query,
5672 searchOptions.CaseSensitive,
5673 searchOptions.UseRegex,
5674 SEARCHTYPE.DialogSearch);
5677 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5679 this.AddNewTabForSearch(searchOptions.Query);
5683 private void AboutMenuItem_Click(object sender, EventArgs e)
5685 using (TweenAboutBox about = new TweenAboutBox())
5687 about.ShowDialog(this);
5689 this.TopMost = this._cfgCommon.AlwaysTop;
5692 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5694 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5696 DetailsListView lst = null;
5698 if (ImageSelector.Enabled)
5702 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5705 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5708 ListTab.SelectedIndex = i;
5709 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5710 //_curTab = ListTab.TabPages[i];
5715 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5716 if (idx == -1 && bgnIdx > 0)
5718 for (int i = 0; i < bgnIdx; i++)
5720 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5723 ListTab.SelectedIndex = i;
5724 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5725 //_curTab = ListTab.TabPages[i];
5731 //全部調べたが未読見つからず→先頭タブの最新発言へ
5734 ListTab.SelectedIndex = 0;
5735 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5736 //_curTab = ListTab.TabPages[0];
5737 if (_statuses.SortOrder == SortOrder.Ascending)
5738 idx = lst.VirtualListSize - 1;
5743 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5745 SelectListItem(lst, idx);
5746 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5748 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5749 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5755 lst.EnsureVisible(idx);
5760 lst.EnsureVisible(idx);
5766 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5768 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5770 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5771 OpenUriAsync(MyCommon.GetStatusUrl(post));
5775 private void FavorareMenuItem_Click(object sender, EventArgs e)
5777 if (_curList.SelectedIndices.Count > 0)
5779 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5780 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5784 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5786 await this.CheckNewVersion(false);
5789 private void RunTweenUp()
5791 ProcessStartInfo pinfo = new ProcessStartInfo();
5792 pinfo.UseShellExecute = true;
5793 pinfo.WorkingDirectory = MyCommon.settingPath;
5794 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5795 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5798 Process.Start(pinfo);
5802 MessageBox.Show("Failed to execute TweenUp3.exe.");
5806 public class VersionInfo
5808 public Version Version { get; set; }
5809 public Uri DownloadUri { get; set; }
5810 public string ReleaseNote { get; set; }
5814 /// OpenTween の最新バージョンの情報を取得します
5816 public async Task<VersionInfo> GetVersionInfoAsync()
5818 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5819 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5821 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5822 .ConfigureAwait(false);
5824 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5825 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5827 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5828 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5830 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5832 return new VersionInfo
5834 Version = Version.Parse(msgHeader[0]),
5835 DownloadUri = new Uri(msgHeader[1]),
5836 ReleaseNote = msgBody,
5840 private async Task CheckNewVersion(bool startup = false)
5842 if (ApplicationSettings.VersionInfoUrl == null)
5843 return; // 更新チェック無効化
5847 var versionInfo = await this.GetVersionInfoAsync();
5849 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5854 var msgtext = string.Format(Properties.Resources.CheckNewVersionText7,
5855 MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version));
5856 msgtext = MyCommon.ReplaceAppName(msgtext);
5858 MessageBox.Show(msgtext,
5859 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5860 MessageBoxButtons.OK, MessageBoxIcon.Information);
5865 using (var dialog = new UpdateDialog())
5867 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5868 MyCommon.GetReadableVersion(versionInfo.Version));
5869 dialog.DetailsText = versionInfo.ReleaseNote;
5871 if (dialog.ShowDialog(this) == DialogResult.Yes)
5873 await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString);
5879 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5882 MessageBox.Show(Properties.Resources.CheckNewVersionText10,
5883 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5884 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5889 private void Colorize()
5893 //件数関連の場合、タイトル即時書き換え
5894 if (this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.None &&
5895 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5896 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5897 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5899 SetMainWindowTitle();
5901 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
5902 foreach (TabPage tb in ListTab.TabPages)
5904 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
5906 if (this._cfgCommon.TabIconDisp)
5908 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
5912 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
5915 public string createDetailHtml(string orgdata)
5917 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
5920 private async void DisplayItemImage_Downloaded(object sender, EventArgs e)
5922 if (sender.Equals(displayItem))
5924 this.ClearUserPicture();
5926 var img = displayItem.Image;
5930 img = await img.CloneAsync();
5932 UserPicture.Image = img;
5936 UserPicture.ShowErrorImage();
5941 private void DispSelectedPost()
5943 DispSelectedPost(false);
5946 private PostClass displayPost = new PostClass();
5949 /// サムネイルの表示処理を表すタスク
5951 private Task thumbnailTask = null;
5954 /// サムネイル表示に使用する CancellationToken の生成元
5956 private CancellationTokenSource thumbnailTokenSource = null;
5958 private void DispSelectedPost(bool forceupdate)
5960 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
5963 var oldDisplayPost = this.displayPost;
5964 this.displayPost = this._curPost;
5966 if (!forceupdate && this._curPost.Equals(oldDisplayPost))
5969 if (displayItem != null)
5971 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
5974 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
5975 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
5977 using (ControlTransaction.Update(this.TableLayoutPanel1))
5979 var sourceText = "";
5980 string sourceUrl = null;
5983 var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
5986 var src = mc.Groups["sourceurl"].Value;
5987 if (Regex.IsMatch(src, "^https?://"))
5990 sourceUrl = "https://twitter.com/" + src;
5993 if (_curPost.Source != null)
5994 sourceText = _curPost.Source;
5996 SourceLinkLabel.Text = sourceText;
5997 SourceLinkLabel.Tag = sourceUrl;
5998 SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
6004 nameText = "DM FROM <- ";
6006 nameText = "DM TO -> ";
6012 nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
6013 if (_curPost.RetweetedId != null)
6014 nameText += " (RT:" + _curPost.RetweetedBy + ")";
6016 NameLabel.Text = nameText;
6017 NameLabel.Tag = _curPost.ScreenName;
6019 var nameForeColor = SystemColors.ControlText;
6020 if (_curPost.IsOwl && (this._cfgCommon.OneWayLove || _curPost.IsDm))
6021 nameForeColor = this._clOWL;
6022 if (_curPost.RetweetedId != null)
6023 nameForeColor = this._clRetweet;
6025 nameForeColor = this._clFav;
6026 NameLabel.ForeColor = nameForeColor;
6028 this.ClearUserPicture();
6030 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6032 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6035 UserPicture.Image = image != null ? image.Clone() : null;
6039 UserPicture.ShowErrorImage();
6043 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6045 if (DumpPostClassToolStripMenuItem.Checked)
6047 StringBuilder sb = new StringBuilder(512);
6049 sb.Append("-----Start PostClass Dump<br>");
6050 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6051 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6052 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6053 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6054 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6055 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6056 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6057 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6058 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6059 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6060 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6061 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6062 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6063 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6064 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6066 foreach (string nm in _curPost.ReplyToList)
6068 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6071 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6072 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6073 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6074 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6075 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6076 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6077 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6078 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6079 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6080 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6081 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6082 sb.Append("-----End PostClass Dump<br>");
6084 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6088 // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
6089 // (同一ツイートの RT は文面が同じであるため同様に更新しない)
6090 if (_curPost.StatusId != oldDisplayPost.StatusId)
6092 this.PostBrowser.DocumentText =
6093 this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6095 this.PostBrowser.Document.Window.ScrollTo(0, 0);
6097 this.SplitContainer3.Panel2Collapsed = true;
6099 if (this._cfgCommon.PreviewEnable)
6101 if (this.thumbnailTokenSource != null)
6103 var oldTokenSource = this.thumbnailTokenSource;
6105 var cancelTask = Task.Run(() => oldTokenSource.Cancel());
6107 Task.WhenAll(this.thumbnailTask, cancelTask)
6108 .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
6111 this.thumbnailTokenSource = new CancellationTokenSource();
6113 var token = this.thumbnailTokenSource.Token;
6114 this.thumbnailTask = this.tweetThumbnail1.ShowThumbnailAsync(_curPost, token);
6121 private void MatomeMenuItem_Click(object sender, EventArgs e)
6123 OpenApplicationWebsite();
6126 private void OpenApplicationWebsite()
6128 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6131 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6133 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6136 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6138 if (ListTab.SelectedTab != null)
6140 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6142 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6143 if (pnl.Controls["comboSearch"].Focused ||
6144 pnl.Controls["comboLang"].Focused ||
6145 pnl.Controls["buttonSearch"].Focused) return;
6147 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6148 if (State == ModifierState.NotFlags) return;
6149 if (State != ModifierState.None) _anchorFlag = false;
6150 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6153 e.SuppressKeyPress = true;
6158 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6160 ModifierState state = ModifierState.None;
6161 if (sControl) state = state | ModifierState.Ctrl;
6162 if (sShift) state = state | ModifierState.Shift;
6163 if (sAlt) state = state | ModifierState.Alt;
6168 private enum ModifierState
6180 //PostBrowser = 102,
6184 private enum FocusedControl : int
6192 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6194 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6195 if (Focused == FocusedControl.ListTab)
6197 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6198 Modifier == ModifierState.Ctrl ||
6199 Modifier == ModifierState.None ||
6200 Modifier == ModifierState.Shift)
6202 if (KeyCode == Keys.J)
6204 SendKeys.Send("{DOWN}");
6207 else if (KeyCode == Keys.K)
6209 SendKeys.Send("{UP}");
6213 if (Modifier == ModifierState.Shift ||
6214 Modifier == ModifierState.None)
6216 if (KeyCode == Keys.F)
6218 SendKeys.Send("{PGDN}");
6221 else if (KeyCode == Keys.B)
6223 SendKeys.Send("{PGUP}");
6232 case ModifierState.None:
6237 OpenApplicationWebsite();
6240 MenuItemSearchNext_Click(null, null);
6246 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
6249 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
6252 if (Focused != FocusedControl.StatusText)
6258 case Keys.ProcessKey:
6259 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6260 JumpUnreadMenuItem_Click(null, null);
6263 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6264 ShowRelatedStatusesMenuItem_Click(null, null);
6268 if (Focused == FocusedControl.ListTab)
6281 case Keys.OemPeriod:
6285 if (this.StatusText.Enabled) this.StatusText.Focus();
6288 MakeReplyOrDirectStatus();
6295 _anchorFlag = false;
6315 // ] in_reply_to参照元へ戻る
6316 GoInReplyToPostTree();
6319 // [ in_reply_toへジャンプ
6320 GoBackInReplyToPostTree();
6323 if (ListTab.SelectedTab != null)
6325 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6326 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6328 TabPage relTp = ListTab.SelectedTab;
6329 RemoveSpecifiedTab(relTp.Text, false);
6337 else if (Focused == FocusedControl.PostBrowser)
6344 //スクロールを発生させるため、true を返す
6349 case ModifierState.Ctrl:
6354 MakeReplyOrDirectStatus(false, true);
6360 MakeReplyOrDirectStatus(false, false);
6363 FavoriteChange(true);
6366 doRepliedStatusOpen();
6372 ReadedStripMenuItem_Click(null, null);
6375 HashManageMenuItem_Click(null, null);
6378 UrlConvertAutoToolStripMenuItem_Click(null, null);
6381 if (Focused != FocusedControl.PostBrowser)
6383 MultiLineMenuItem_Click(null, null);
6388 MenuItemSubSearch_Click(null, null);
6395 MoveToHomeToolStripMenuItem_Click(null, null);
6399 MoveToFavToolStripMenuItem_Click(null, null);
6403 StatusOpenMenuItem_Click(null, null);
6407 OpenURLMenuItem_Click(null, null);
6411 if (Focused == FocusedControl.ListTab)
6418 return false; //スルーする
6436 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6437 int tabNo = KeyCode - Keys.D1;
6438 if (ListTab.TabPages.Count < tabNo)
6440 ListTab.SelectedIndex = tabNo;
6441 ListTabSelect(ListTab.TabPages[tabNo]);
6444 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6445 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6449 else if (Focused == FocusedControl.StatusText)
6455 StatusText.SelectAll();
6459 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6461 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6463 if (KeyCode == Keys.Up)
6466 if (_hisIdx < 0) _hisIdx = 0;
6471 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6473 StatusText.Text = _history[_hisIdx].status;
6474 _reply_to_id = _history[_hisIdx].inReplyToId;
6475 _reply_to_name = _history[_hisIdx].inReplyToName;
6476 StatusText.SelectionStart = StatusText.Text.Length;
6480 if (ListTab.SelectedIndex == 0)
6482 ListTab.SelectedIndex = ListTab.TabCount - 1;
6486 ListTab.SelectedIndex -= 1;
6492 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6494 ListTab.SelectedIndex = 0;
6498 ListTab.SelectedIndex += 1;
6506 //フォーカスPostBrowserもしくは関係なし
6510 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6514 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6515 if (!string.IsNullOrEmpty(_selText))
6519 Clipboard.SetDataObject(_selText, false, 5, 100);
6521 catch (Exception ex)
6523 MessageBox.Show(ex.Message);
6528 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6529 MultiLineMenuItem_Click(null, null);
6534 case ModifierState.Shift:
6539 MenuItemSearchPrev_Click(null, null);
6545 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
6548 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
6552 if (Focused != FocusedControl.StatusText)
6554 if (KeyCode == Keys.R)
6561 if (Focused == FocusedControl.ListTab)
6581 GoBackInReplyToPostTree(true, false);
6584 GoBackInReplyToPostTree(true, true);
6588 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6593 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6597 this.GoBackSelectPostChain();
6602 case ModifierState.Alt:
6606 doReTweetOfficial(true);
6609 if (_curPost != null)
6611 doShowUserStatus(_curPost.ScreenName, false);
6616 ScrollDownPostBrowser(false);
6619 ScrollDownPostBrowser(true);
6622 PageDownPostBrowser(false);
6625 PageDownPostBrowser(true);
6628 if (Focused == FocusedControl.ListTab)
6630 // 別タブの同じ書き込みへ(ALT+←/→)
6631 if (KeyCode == Keys.Right)
6633 GoSamePostToAnotherTab(false);
6636 else if (KeyCode == Keys.Left)
6638 GoSamePostToAnotherTab(true);
6643 case ModifierState.Ctrl | ModifierState.Shift:
6647 MakeReplyOrDirectStatus(false, true, true);
6653 if (ListTab.SelectedTab != null)
6655 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6657 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6663 FavoriteChange(false);
6666 UnreadStripMenuItem_Click(null, null);
6669 HashToggleMenuItem_Click(null, null);
6672 ImageSelectMenuItem_Click(null, null);
6678 FavorareMenuItem_Click(null, null);
6681 if (Focused == FocusedControl.StatusText)
6687 if (_curList != null && _curList.VirtualListSize != 0 &&
6688 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6690 idx = _curList.SelectedIndices[0] - 1;
6691 SelectListItem(_curList, idx);
6692 _curList.EnsureVisible(idx);
6697 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6698 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6700 idx = _curList.SelectedIndices[0] + 1;
6701 SelectListItem(_curList, idx);
6702 _curList.EnsureVisible(idx);
6707 if (StatusText.SelectionStart > 0)
6709 int endidx = StatusText.SelectionStart - 1;
6710 string startstr = "";
6711 bool pressed = false;
6712 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6714 char c = StatusText.Text[i];
6715 if (Char.IsLetterOrDigit(c) || c == '_')
6722 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6723 int cnt = AtIdSupl.ItemCount;
6724 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6725 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6730 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6731 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6743 else if (Focused == FocusedControl.ListTab)
6745 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6757 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6758 int colNo = KeyCode - Keys.D1;
6759 if (lst.Columns.Count < colNo) return false;
6760 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6761 if (col == null) return false;
6762 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6765 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6766 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6771 case ModifierState.Ctrl | ModifierState.Alt:
6772 if (KeyCode == Keys.S)
6774 FavoritesRetweetOriginal();
6777 else if (KeyCode == Keys.R)
6779 FavoritesRetweetUnofficial();
6782 else if (KeyCode == Keys.H)
6784 OpenUserAppointUrl();
6788 case ModifierState.Alt | ModifierState.Shift:
6789 if (Focused == FocusedControl.PostBrowser)
6791 if (KeyCode == Keys.R)
6792 doReTweetUnofficial();
6793 else if (KeyCode == Keys.C)
6800 if (!this.ExistCurrentPost) return false;
6801 doTranslation(_curPost.TextFromApi);
6804 doReTweetUnofficial();
6810 this.tweetThumbnail1.ScrollUp();
6813 this.tweetThumbnail1.ScrollDown();
6816 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6818 if (!this.SplitContainer3.Panel2Collapsed)
6820 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6830 private void ScrollDownPostBrowser(bool forward)
6832 var doc = PostBrowser.Document;
6833 if (doc == null) return;
6835 var tags = doc.GetElementsByTagName("html");
6839 tags[0].ScrollTop += this._fntDetail.Height;
6841 tags[0].ScrollTop -= this._fntDetail.Height;
6845 private void PageDownPostBrowser(bool forward)
6847 var doc = PostBrowser.Document;
6848 if (doc == null) return;
6850 var tags = doc.GetElementsByTagName("html");
6854 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - this._fntDetail.Height;
6856 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - this._fntDetail.Height;
6860 private void GoNextTab(bool forward)
6862 int idx = ListTab.SelectedIndex;
6866 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6871 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6873 ListTab.SelectedIndex = idx;
6874 ListTabSelect(ListTab.TabPages[idx]);
6877 private void CopyStot()
6880 StringBuilder sb = new StringBuilder();
6881 bool IsProtected = false;
6883 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6884 foreach (int idx in _curList.SelectedIndices)
6886 PostClass post = _statuses[_curTab.Text, idx];
6892 if (post.IsDeleted) continue;
6895 if (post.RetweetedId != null)
6896 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6898 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6902 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6907 MessageBox.Show(Properties.Resources.CopyStotText1);
6911 clstr = sb.ToString();
6914 Clipboard.SetDataObject(clstr, false, 5, 100);
6916 catch (Exception ex)
6918 MessageBox.Show(ex.Message);
6923 private void CopyIdUri()
6926 StringBuilder sb = new StringBuilder();
6927 if (this._curTab == null) return;
6928 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
6929 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
6930 foreach (int idx in _curList.SelectedIndices)
6932 var post = _statuses[_curTab.Text, idx];
6933 sb.Append(MyCommon.GetStatusUrl(post));
6934 sb.Append(Environment.NewLine);
6938 clstr = sb.ToString();
6941 Clipboard.SetDataObject(clstr, false, 5, 100);
6943 catch (Exception ex)
6945 MessageBox.Show(ex.Message);
6950 private void GoFav(bool forward)
6952 if (_curList.VirtualListSize == 0) return;
6959 if (_curList.SelectedIndices.Count == 0)
6965 fIdx = _curList.SelectedIndices[0] + 1;
6966 if (fIdx > _curList.VirtualListSize - 1) return;
6968 toIdx = _curList.VirtualListSize;
6973 if (_curList.SelectedIndices.Count == 0)
6975 fIdx = _curList.VirtualListSize - 1;
6979 fIdx = _curList.SelectedIndices[0] - 1;
6980 if (fIdx < 0) return;
6986 for (int idx = fIdx; idx != toIdx; idx += stp)
6988 if (_statuses[_curTab.Text, idx].IsFav)
6990 SelectListItem(_curList, idx);
6991 _curList.EnsureVisible(idx);
6997 private void GoSamePostToAnotherTab(bool left)
6999 if (_curList.VirtualListSize == 0) return;
7005 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7006 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7008 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7013 if (ListTab.SelectedIndex == 0)
7019 fIdx = ListTab.SelectedIndex - 1;
7027 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7033 fIdx = ListTab.SelectedIndex + 1;
7035 toIdx = ListTab.TabCount;
7040 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7042 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7043 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7045 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7047 ListTab.SelectedIndex = tabidx;
7048 ListTabSelect(ListTab.TabPages[tabidx]);
7049 SelectListItem(_curList, idx);
7050 _curList.EnsureVisible(idx);
7059 private void GoPost(bool forward)
7061 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7068 fIdx = _curList.SelectedIndices[0] + 1;
7069 if (fIdx > _curList.VirtualListSize - 1) return;
7070 toIdx = _curList.VirtualListSize;
7075 fIdx = _curList.SelectedIndices[0] - 1;
7076 if (fIdx < 0) return;
7082 if (_curPost.RetweetedId == null)
7084 name = _curPost.ScreenName;
7088 name = _curPost.RetweetedBy;
7090 for (int idx = fIdx; idx != toIdx; idx += stp)
7092 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7094 if (_statuses[_curTab.Text, idx].ScreenName == name)
7096 SelectListItem(_curList, idx);
7097 _curList.EnsureVisible(idx);
7103 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7105 SelectListItem(_curList, idx);
7106 _curList.EnsureVisible(idx);
7113 private void GoRelPost(bool forward)
7115 if (_curList.SelectedIndices.Count == 0) return;
7122 fIdx = _curList.SelectedIndices[0] + 1;
7123 if (fIdx > _curList.VirtualListSize - 1) return;
7124 toIdx = _curList.VirtualListSize;
7129 fIdx = _curList.SelectedIndices[0] - 1;
7130 if (fIdx < 0) return;
7137 if (_curPost == null) return;
7138 _anchorPost = _curPost;
7143 if (_anchorPost == null) return;
7146 for (int idx = fIdx; idx != toIdx; idx += stp)
7148 PostClass post = _statuses[_curTab.Text, idx];
7149 if (post.ScreenName == _anchorPost.ScreenName ||
7150 post.RetweetedBy == _anchorPost.ScreenName ||
7151 post.ScreenName == _anchorPost.RetweetedBy ||
7152 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7153 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7154 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7155 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7156 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7158 SelectListItem(_curList, idx);
7159 _curList.EnsureVisible(idx);
7165 private void GoAnchor()
7167 if (_anchorPost == null) return;
7168 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7169 if (idx == -1) return;
7171 SelectListItem(_curList, idx);
7172 _curList.EnsureVisible(idx);
7175 private void GoTopEnd(bool GoTop)
7182 _item = _curList.GetItemAt(0, 25);
7190 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7192 idx = _curList.VirtualListSize - 1;
7196 SelectListItem(_curList, idx);
7199 private void GoMiddle()
7206 _item = _curList.GetItemAt(0, 0);
7216 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7219 idx2 = _curList.VirtualListSize - 1;
7225 idx3 = (idx1 + idx2) / 2;
7227 SelectListItem(_curList, idx3);
7230 private void GoLast()
7232 if (_curList.VirtualListSize == 0) return;
7234 if (_statuses.SortOrder == SortOrder.Ascending)
7236 SelectListItem(_curList, _curList.VirtualListSize - 1);
7237 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7241 SelectListItem(_curList, 0);
7242 _curList.EnsureVisible(0);
7246 private void MoveTop()
7248 if (_curList.SelectedIndices.Count == 0) return;
7249 int idx = _curList.SelectedIndices[0];
7250 if (_statuses.SortOrder == SortOrder.Ascending)
7252 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7256 _curList.EnsureVisible(0);
7258 _curList.EnsureVisible(idx);
7261 private void GoInReplyToPostTree()
7263 if (_curPost == null) return;
7265 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7267 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7269 PostClass post = null;
7270 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7271 if (string.IsNullOrEmpty(r) && post != null)
7273 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7274 _curPost.InReplyToUser = post.InReplyToUser;
7275 _curPost.IsReply = post.IsReply;
7276 this.PurgeListViewItemCache();
7277 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7281 this.StatusLabel.Text = r;
7285 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7287 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7289 replyChains = new Stack<ReplyChain>();
7291 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7294 string inReplyToTabName;
7295 long inReplyToId = _curPost.InReplyToStatusId.Value;
7296 string inReplyToUser = _curPost.InReplyToUser;
7297 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7299 var inReplyToPosts = from tab in _statuses.Tabs.Values
7300 orderby tab != curTabClass
7301 from post in tab.Posts.Values
7302 where post.StatusId == inReplyToId
7303 let index = tab.IndexOf(post.StatusId)
7305 select new {Tab = tab, Index = index};
7309 var inReplyPost = inReplyToPosts.First();
7310 inReplyToTabName = inReplyPost.Tab.TabName;
7311 inReplyToIndex = inReplyPost.Index;
7313 catch (InvalidOperationException)
7315 PostClass post = null;
7316 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7317 if (string.IsNullOrEmpty(r) && post != null)
7320 _statuses.AddPost(post);
7321 _statuses.DistributePosts();
7322 //_statuses.SubmitUpdate(null, null, null, false);
7323 this.RefreshTimeline(false);
7326 var inReplyPost = inReplyToPosts.First();
7327 inReplyToTabName = inReplyPost.Tab.TabName;
7328 inReplyToIndex = inReplyPost.Index;
7330 catch (InvalidOperationException)
7332 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7338 this.StatusLabel.Text = r;
7339 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7344 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7345 DetailsListView listView = (DetailsListView)tabPage.Tag;
7347 if (_curTab != tabPage)
7349 this.ListTab.SelectTab(tabPage);
7352 this.SelectListItem(listView, inReplyToIndex);
7353 listView.EnsureVisible(inReplyToIndex);
7356 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7358 if (_curPost == null) return;
7360 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7361 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7365 if (_curPost.InReplyToStatusId != null)
7367 var posts = from t in _statuses.Tabs
7368 from p in t.Value.Posts
7369 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7370 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7372 orderby isForward ? indexOf : indexOf * -1
7373 orderby t.Value != curTabClass
7374 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7377 var postList = posts.ToList();
7378 for (int i = postList.Count - 1; i >= 0; i--)
7381 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7383 postList.RemoveAt(index);
7386 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7387 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7388 if (post == null) post = postList.First();
7389 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7390 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7391 SelectListItem(listView, post.Index);
7392 listView.EnsureVisible(post.Index);
7394 catch (InvalidOperationException)
7402 if (replyChains == null || replyChains.Count < 1)
7404 var posts = from t in _statuses.Tabs
7405 from p in t.Value.Posts
7406 where p.Value.InReplyToStatusId == _curPost.StatusId
7407 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7410 orderby t.Value != curTabClass
7411 select new {Tab = t.Value, Index = indexOf};
7414 var post = posts.First();
7415 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7416 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7417 SelectListItem(listView, post.Index);
7418 listView.EnsureVisible(post.Index);
7420 catch (InvalidOperationException)
7427 ReplyChain chainHead = replyChains.Pop();
7428 if (chainHead.InReplyToId == _curPost.StatusId)
7430 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7439 ListTab.SelectTab(chainHead.OriginalTab);
7445 SelectListItem(_curList, idx);
7446 _curList.EnsureVisible(idx);
7452 this.GoBackInReplyToPostTree(parallel);
7458 private void GoBackSelectPostChain()
7460 if (this.selectPostChains.Count > 1)
7469 this.selectPostChains.Pop();
7470 var tabPostPair = this.selectPostChains.Peek();
7472 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) continue; //該当タブが存在しないので無視
7474 if (tabPostPair.Item2 != null)
7476 idx = this._statuses.Tabs[tabPostPair.Item1.Text].IndexOf(tabPostPair.Item2.StatusId);
7477 if (idx == -1) continue; //該当ポストが存在しないので無視
7480 tp = tabPostPair.Item1;
7482 this.selectPostChains.Pop();
7484 catch (InvalidOperationException)
7490 while (this.selectPostChains.Count > 1);
7495 //履歴が残り1つであればクリアしておく
7496 if (this.selectPostChains.Count == 1)
7497 this.selectPostChains.Clear();
7501 DetailsListView lst = (DetailsListView)tp.Tag;
7502 this.ListTab.SelectedTab = tp;
7505 SelectListItem(lst, idx);
7506 lst.EnsureVisible(idx);
7512 private void PushSelectPostChain()
7514 int count = this.selectPostChains.Count;
7517 var p = this.selectPostChains.Peek();
7518 if (p.Item1 == this._curTab)
7520 if (p.Item2 == this._curPost) return; //最新の履歴と同一
7521 if (p.Item2 == null) this.selectPostChains.Pop(); //置き換えるため削除
7524 if (count >= 2500) TrimPostChain();
7525 this.selectPostChains.Push(Tuple.Create(this._curTab, this._curPost));
7528 private void TrimPostChain()
7530 if (this.selectPostChains.Count <= 2000) return;
7531 var p = new Stack<Tuple<TabPage, PostClass>>(2000);
7532 for (int i = 0; i < 2000; i++)
7534 p.Push(this.selectPostChains.Pop());
7536 this.selectPostChains.Clear();
7537 for (int i = 0; i < 2000; i++)
7539 this.selectPostChains.Push(p.Pop());
7543 private bool GoStatus(long statusId)
7545 if (statusId == 0) return false;
7546 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7548 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7550 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7551 ListTab.SelectedIndex = tabidx;
7552 ListTabSelect(ListTab.TabPages[tabidx]);
7553 SelectListItem(_curList, idx);
7554 _curList.EnsureVisible(idx);
7561 private bool GoDirectMessage(long statusId)
7563 if (statusId == 0) return false;
7564 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7566 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7568 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7569 ListTab.SelectedIndex = tabidx;
7570 ListTabSelect(ListTab.TabPages[tabidx]);
7571 SelectListItem(_curList, idx);
7572 _curList.EnsureVisible(idx);
7579 private void MyList_MouseClick(object sender, MouseEventArgs e)
7581 _anchorFlag = false;
7584 private void StatusText_Enter(object sender, EventArgs e)
7586 // フォーカスの戻り先を StatusText に設定
7587 this.Tag = StatusText;
7588 StatusText.BackColor = _clInputBackcolor;
7591 public Color InputBackColor
7593 get { return _clInputBackcolor; }
7594 set { _clInputBackcolor = value; }
7597 private void StatusText_Leave(object sender, EventArgs e)
7599 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7600 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7601 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7604 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7606 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7607 if (State == ModifierState.NotFlags) return;
7608 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7611 e.SuppressKeyPress = true;
7614 this.StatusText_TextChanged(null, null);
7617 private void SaveConfigsAll(bool ifModified)
7621 SaveConfigsCommon();
7628 if (_modifySettingCommon) SaveConfigsCommon();
7629 if (_modifySettingLocal) SaveConfigsLocal();
7630 if (_modifySettingAtId) SaveConfigsAtId();
7634 private void SaveConfigsAtId()
7636 if (_ignoreConfigSave || !this._cfgCommon.UseAtIdSupplement && AtIdSupl == null) return;
7638 _modifySettingAtId = false;
7639 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7643 private void SaveConfigsCommon()
7645 if (_ignoreConfigSave) return;
7647 _modifySettingCommon = false;
7650 _cfgCommon.UserName = tw.Username;
7651 _cfgCommon.UserId = tw.UserId;
7652 _cfgCommon.Password = tw.Password;
7653 _cfgCommon.Token = tw.AccessToken;
7654 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7655 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7657 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7658 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7659 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7660 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7661 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7662 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7663 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7664 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7665 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7666 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7668 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7671 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7672 switch (_statuses.SortMode)
7674 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7675 _cfgCommon.SortColumn = 1;
7677 case IdComparerClass.ComparerMode.Data: //本文
7678 _cfgCommon.SortColumn = 2;
7680 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7681 _cfgCommon.SortColumn = 3;
7683 case IdComparerClass.ComparerMode.Name: //名前
7684 _cfgCommon.SortColumn = 4;
7686 case IdComparerClass.ComparerMode.Source: //Source
7687 _cfgCommon.SortColumn = 7;
7691 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7692 _cfgCommon.HashTags = HashMgr.HashHistories;
7693 if (HashMgr.IsPermanent)
7695 _cfgCommon.HashSelected = HashMgr.UseHash;
7699 _cfgCommon.HashSelected = "";
7701 _cfgCommon.HashIsHead = HashMgr.IsHead;
7702 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7703 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7704 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7705 if (ToolStripFocusLockMenuItem != null &&
7706 ToolStripFocusLockMenuItem.IsDisposed == false)
7708 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7710 _cfgCommon.TrackWord = tw.TrackWord;
7711 _cfgCommon.AllAtReply = tw.AllAtReply;
7712 _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
7713 _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
7714 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7715 _cfgCommon.EnableImgAzyobuziNet = SettingDialog.EnableImgAzyobuziNet;
7716 _cfgCommon.ImgAzyobuziNetDisabledInDM = SettingDialog.ImgAzyobuziNetDisabledInDM;
7717 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7718 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7719 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7720 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7721 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7727 private void SaveConfigsLocal()
7729 if (_ignoreConfigSave) return;
7732 _modifySettingLocal = false;
7733 _cfgLocal.FormSize = _mySize;
7734 _cfgLocal.FormLocation = _myLoc;
7735 _cfgLocal.SplitterDistance = _mySpDis;
7736 _cfgLocal.PreviewDistance = _mySpDis3;
7737 _cfgLocal.StatusMultiline = StatusText.Multiline;
7738 _cfgLocal.StatusTextHeight = _mySpDis2;
7740 _cfgLocal.FontUnread = _fntUnread;
7741 _cfgLocal.ColorUnread = _clUnread;
7742 _cfgLocal.FontRead = _fntReaded;
7743 _cfgLocal.ColorRead = _clReaded;
7744 _cfgLocal.FontDetail = _fntDetail;
7745 _cfgLocal.ColorDetail = _clDetail;
7746 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7747 _cfgLocal.ColorDetailLink = _clDetailLink;
7748 _cfgLocal.ColorFav = _clFav;
7749 _cfgLocal.ColorOWL = _clOWL;
7750 _cfgLocal.ColorRetweet = _clRetweet;
7751 _cfgLocal.ColorSelf = _clSelf;
7752 _cfgLocal.ColorAtSelf = _clAtSelf;
7753 _cfgLocal.ColorTarget = _clTarget;
7754 _cfgLocal.ColorAtTarget = _clAtTarget;
7755 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7756 _cfgLocal.ColorAtTo = _clAtTo;
7757 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7758 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7759 _cfgLocal.ColorInputFont = _clInputFont;
7760 _cfgLocal.FontInputFont = _fntInputFont;
7762 if (_ignoreConfigSave) return;
7767 private void SaveConfigsTabs()
7769 SettingTabs tabSetting = new SettingTabs();
7770 for (int i = 0; i < ListTab.TabPages.Count; i++)
7772 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7777 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7780 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7781 if (ret != DialogResult.OK)
7784 var match = Twitter.StatusUrlRegex.Match(inputText);
7787 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7788 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7792 var statusId = long.Parse(match.Groups["StatusId"].Value);
7794 var post = this._statuses[statusId];
7799 post = await Task.Run(() =>
7801 PostClass newPost = null;
7803 var err = this.tw.GetStatusApi(false, statusId, ref newPost);
7804 if (!string.IsNullOrEmpty(err))
7805 throw new WebApiException(err);
7810 catch (WebApiException ex)
7812 var message = ex.Message;
7813 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7814 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7821 this.OpenRelatedTab(post);
7823 catch (TabException ex)
7825 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7829 private void SaveLogMenuItem_Click(object sender, EventArgs e)
7831 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
7832 Properties.Resources.SaveLogMenuItem_ClickText2,
7833 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
7834 if (rslt == DialogResult.Cancel) return;
7836 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
7837 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
7838 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
7839 SaveFileDialog1.FilterIndex = 0;
7840 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
7841 SaveFileDialog1.RestoreDirectory = true;
7843 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
7845 if (!SaveFileDialog1.ValidateNames) return;
7846 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
7848 if (rslt == DialogResult.Yes)
7851 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
7853 PostClass post = _statuses[_curTab.Text, idx];
7854 string protect = "";
7855 if (post.IsProtect) protect = "Protect";
7856 sw.WriteLine(post.Nickname + "\t" +
7857 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7858 post.CreatedAt.ToString() + "\t" +
7859 post.ScreenName + "\t" +
7860 post.StatusId.ToString() + "\t" +
7861 post.ImageUrl + "\t" +
7862 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7868 foreach (int idx in _curList.SelectedIndices)
7870 PostClass post = _statuses[_curTab.Text, idx];
7871 string protect = "";
7872 if (post.IsProtect) protect = "Protect";
7873 sw.WriteLine(post.Nickname + "\t" +
7874 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7875 post.CreatedAt.ToString() + "\t" +
7876 post.ScreenName + "\t" +
7877 post.StatusId.ToString() + "\t" +
7878 post.ImageUrl + "\t" +
7879 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7885 this.TopMost = this._cfgCommon.AlwaysTop;
7888 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
7890 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7891 if (State == ModifierState.NotFlags) return;
7892 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
7895 e.IsInputKey = true;
7898 public bool TabRename(ref string tabName)
7901 string newTabText = null;
7902 using (InputTabName inputName = new InputTabName())
7904 inputName.TabName = tabName;
7905 inputName.ShowDialog();
7906 if (inputName.DialogResult == DialogResult.Cancel) return false;
7907 newTabText = inputName.TabName;
7909 this.TopMost = this._cfgCommon.AlwaysTop;
7910 if (!string.IsNullOrEmpty(newTabText))
7913 for (int i = 0; i < ListTab.TabCount; i++)
7915 if (ListTab.TabPages[i].Text == newTabText)
7917 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
7918 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
7922 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
7923 for (int i = 0; i < ListTab.TabCount; i++)
7925 if (ListTab.TabPages[i].Text == tabName)
7927 ListTab.TabPages[i].Text = newTabText;
7930 _statuses.RenameTab(tabName, newTabText);
7932 for (int i = 0; i < ListTab.TabCount; i++)
7934 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
7936 if (ListTab.TabPages[i].Text == tabName)
7938 ListTab.TabPages[i].Text = newTabText;
7942 SaveConfigsCommon();
7944 _rclickTabName = newTabText;
7945 tabName = newTabText;
7954 private void ListTab_MouseClick(object sender, MouseEventArgs e)
7956 if (e.Button == MouseButtons.Middle)
7958 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
7960 if (this.ListTab.GetTabRect(i).Contains(e.Location))
7962 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
7963 this.SaveConfigsTabs();
7970 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
7972 string tn = ListTab.SelectedTab.Text;
7976 private void ListTab_MouseDown(object sender, MouseEventArgs e)
7978 if (this._cfgCommon.TabMouseLock) return;
7979 Point cpos = new Point(e.X, e.Y);
7980 if (e.Button == MouseButtons.Left)
7982 for (int i = 0; i < ListTab.TabPages.Count; i++)
7984 if (this.ListTab.GetTabRect(i).Contains(e.Location))
7987 _tabMouseDownPoint = e.Location;
7998 private void ListTab_DragEnter(object sender, DragEventArgs e)
8000 if (e.Data.GetDataPresent(typeof(TabPage)))
8001 e.Effect = DragDropEffects.Move;
8003 e.Effect = DragDropEffects.None;
8006 private void ListTab_DragDrop(object sender, DragEventArgs e)
8008 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8013 Point cpos = new Point(e.X, e.Y);
8014 Point spos = ListTab.PointToClient(cpos);
8016 for (i = 0; i < ListTab.TabPages.Count; i++)
8018 Rectangle rect = ListTab.GetTabRect(i);
8019 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8020 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8022 tn = ListTab.TabPages[i].Text;
8023 if (spos.X <= (rect.Left + rect.Right) / 2)
8032 //タブのないところにドロップ->最後尾へ移動
8033 if (string.IsNullOrEmpty(tn))
8035 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8037 i = ListTab.TabPages.Count - 1;
8040 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8041 if (tp.Text == tn) return;
8043 ReOrderTab(tp.Text, tn, bef);
8046 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8049 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8051 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8054 using (ControlTransaction.Layout(this.ListTab))
8057 for (int j = 0; j < ListTab.TabPages.Count; j++)
8059 if (ListTab.TabPages[j].Text == targetTabText)
8061 mTp = ListTab.TabPages[j];
8062 ListTab.TabPages.Remove(mTp);
8063 if (j < baseIndex) baseIndex -= 1;
8067 if (isBeforeBaseTab)
8068 ListTab.TabPages.Insert(baseIndex, mTp);
8070 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8076 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8078 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8079 //isReply:true=@,false=DM
8080 if (!StatusText.Enabled) return;
8081 if (_curList == null) return;
8082 if (_curTab == null) return;
8083 if (!this.ExistCurrentPost) return;
8085 // 複数あてリプライはReplyではなく通常ポスト
8086 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8087 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8088 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8090 if (_curList.SelectedIndices.Count > 0)
8093 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8096 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8099 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8100 StatusText.SelectionStart = StatusText.Text.Length;
8102 _reply_to_id = null;
8103 _reply_to_name = null;
8106 if (string.IsNullOrEmpty(StatusText.Text))
8110 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8111 StatusText.Text = "@" + _curPost.ScreenName + " ";
8112 if (_curPost.RetweetedId != null)
8114 _reply_to_id = _curPost.RetweetedId.Value;
8118 _reply_to_id = _curPost.StatusId;
8120 _reply_to_name = _curPost.ScreenName;
8128 //1件選んでEnter or DoubleClick
8129 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8131 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8134 if (_curPost.RetweetedId != null)
8136 _reply_to_id = _curPost.RetweetedId.Value;
8140 _reply_to_id = _curPost.StatusId;
8142 _reply_to_name = _curPost.ScreenName;
8146 if (!StatusText.Text.StartsWith("@"))
8149 if (StatusText.Text.StartsWith(". "))
8152 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8153 _reply_to_id = null;
8154 _reply_to_name = null;
8159 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8160 if (_curPost.RetweetedId != null)
8162 _reply_to_id = _curPost.RetweetedId.Value;
8166 _reply_to_id = _curPost.StatusId;
8168 _reply_to_name = _curPost.ScreenName;
8175 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8176 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8177 _reply_to_id = null;
8178 _reply_to_name = null;
8183 //1件選んでCtrl-Rの場合(返信先操作せず)
8184 int sidx = StatusText.SelectionStart;
8185 string id = "@" + _curPost.ScreenName + " ";
8188 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8193 StatusText.Text = StatusText.Text.Insert(sidx, id);
8195 //if (StatusText.Text.StartsWith("@"))
8198 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8199 // sidx += 5 + _curPost.ScreenName.Length;
8204 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8205 // sidx += 3 + _curPost.ScreenName.Length;
8207 StatusText.SelectionStart = sidx;
8210 //_reply_to_name = null;
8218 if (!isAuto && !isReply) return;
8220 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8224 //Enter or DoubleClick
8226 string sTxt = StatusText.Text;
8227 if (!sTxt.StartsWith(". "))
8230 _reply_to_id = null;
8231 _reply_to_name = null;
8233 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8235 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8236 if (!sTxt.Contains("@" + post.ScreenName + " "))
8238 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8239 //sTxt = "@" + post.ScreenName + " " + sTxt;
8242 StatusText.Text = sTxt;
8247 if (_curList.SelectedIndices.Count > 1)
8252 int sidx = StatusText.SelectionStart;
8253 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8255 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8256 if (!ids.Contains("@" + post.ScreenName + " ") &&
8257 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8259 ids += "@" + post.ScreenName + " ";
8263 foreach (string nm in post.ReplyToList)
8265 if (!ids.Contains("@" + nm + " ") &&
8266 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8268 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8270 ids += "@" + m.Result("${id}") + " ";
8272 ids += "@" + nm + " ";
8277 if (ids.Length == 0) return;
8278 if (!StatusText.Text.StartsWith(". "))
8280 StatusText.Text = ". " + StatusText.Text;
8282 _reply_to_id = null;
8283 _reply_to_name = null;
8287 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8292 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8294 //if (StatusText.Text.StartsWith("@"))
8296 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8297 // sidx += 2 + ids.Length;
8301 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8302 // sidx += 1 + ids.Length;
8304 StatusText.SelectionStart = sidx;
8310 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8313 int sidx = StatusText.SelectionStart;
8314 PostClass post = _curPost;
8315 if (!ids.Contains("@" + post.ScreenName + " ") &&
8316 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8318 ids += "@" + post.ScreenName + " ";
8320 foreach (string nm in post.ReplyToList)
8322 if (!ids.Contains("@" + nm + " ") &&
8323 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8325 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8327 ids += "@" + m.Result("${id}") + " ";
8329 ids += "@" + nm + " ";
8332 if (!string.IsNullOrEmpty(post.RetweetedBy))
8334 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8335 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8337 ids += "@" + post.RetweetedBy + " ";
8340 if (ids.Length == 0) return;
8341 if (string.IsNullOrEmpty(StatusText.Text))
8344 StatusText.Text = ids;
8345 StatusText.SelectionStart = ids.Length;
8347 if (post.RetweetedId != null)
8349 _reply_to_id = post.RetweetedId.Value;
8353 _reply_to_id = post.StatusId;
8355 _reply_to_name = post.ScreenName;
8361 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8366 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8368 StatusText.SelectionStart = sidx;
8374 StatusText.SelectionStart = StatusText.Text.Length;
8379 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8384 private static int iconCnt = 0;
8385 private static int blinkCnt = 0;
8386 private static bool blink = false;
8387 private static bool idle = false;
8389 private void RefreshTasktrayIcon(bool forceRefresh)
8391 if (_colorize) Colorize();
8392 if (!TimerRefreshIcon.Enabled) return;
8393 //Static usCheckCnt As int = 0
8395 //Static iconDlListTopItem As ListViewItem = null
8397 if (forceRefresh) idle = false;
8399 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8400 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8402 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8404 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8410 //if (usCheckCnt > 300) //1min
8413 // if (!this.IsReceivedUserStream)
8415 // TraceOut("ReconnectUserStream");
8416 // tw.ReconnectUserStream();
8421 foreach (BackgroundWorker bw in this._bw)
8423 if (bw != null && bw.IsBusy)
8438 SaveConfigsAll(true);
8443 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8445 _myStatusError = false;
8449 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8450 if (this._cfgCommon.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8452 if (blinkCnt > 0) return;
8454 if (blink || this._cfgCommon.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8456 NotifyIcon1.Icon = ReplyIcon;
8460 NotifyIcon1.Icon = ReplyIconBlink;
8468 //優先度:エラー→オフライン→アイドル
8472 NotifyIcon1.Icon = NIconAtRed;
8475 if (_myStatusOnline)
8477 NotifyIcon1.Icon = NIconAt;
8481 NotifyIcon1.Icon = NIconAtSmoke;
8485 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8488 this.RefreshTasktrayIcon(false);
8491 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8493 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8494 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8496 if (ListTab != null && ListTab.SelectedTab != null)
8497 _rclickTabName = ListTab.SelectedTab.Text;
8502 if (_statuses == null) return;
8503 if (_statuses.Tabs == null) return;
8505 TabClass tb = _statuses.Tabs[_rclickTabName];
8506 if (tb == null) return;
8508 NotifyDispMenuItem.Checked = tb.Notify;
8509 this.NotifyTbMenuItem.Checked = tb.Notify;
8511 soundfileListup = true;
8512 SoundFileComboBox.Items.Clear();
8513 this.SoundFileTbComboBox.Items.Clear();
8514 SoundFileComboBox.Items.Add("");
8515 this.SoundFileTbComboBox.Items.Add("");
8516 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8517 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8519 oDir = oDir.GetDirectories("Sounds")[0];
8521 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8523 SoundFileComboBox.Items.Add(oFile.Name);
8524 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8526 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8527 if (idx == -1) idx = 0;
8528 SoundFileComboBox.SelectedIndex = idx;
8529 this.SoundFileTbComboBox.SelectedIndex = idx;
8530 soundfileListup = false;
8531 UreadManageMenuItem.Checked = tb.UnreadManage;
8532 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8534 TabMenuControl(_rclickTabName);
8537 private void TabMenuControl(string tabName)
8539 this.FilterEditMenuItem.Enabled = true;
8540 this.EditRuleTbMenuItem.Enabled = true;
8542 if (_statuses.IsDefaultTab(tabName))
8544 this.ProtectTabMenuItem.Enabled = false;
8545 this.ProtectTbMenuItem.Enabled = false;
8549 this.ProtectTabMenuItem.Enabled = true;
8550 this.ProtectTbMenuItem.Enabled = true;
8553 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8555 this.ProtectTabMenuItem.Checked = true;
8556 this.ProtectTbMenuItem.Checked = true;
8557 this.DeleteTabMenuItem.Enabled = false;
8558 this.DeleteTbMenuItem.Enabled = false;
8562 this.ProtectTabMenuItem.Checked = false;
8563 this.ProtectTbMenuItem.Checked = false;
8564 this.DeleteTabMenuItem.Enabled = true;
8565 this.DeleteTbMenuItem.Enabled = true;
8569 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8571 var checkState = ((ToolStripMenuItem)sender).Checked;
8574 this.ProtectTbMenuItem.Checked = checkState;
8575 this.ProtectTabMenuItem.Checked = checkState;
8578 this.DeleteTabMenuItem.Enabled = !checkState;
8579 this.DeleteTbMenuItem.Enabled = !checkState;
8581 if (string.IsNullOrEmpty(_rclickTabName)) return;
8582 _statuses.Tabs[_rclickTabName].Protected = checkState;
8587 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8589 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8590 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8592 if (string.IsNullOrEmpty(_rclickTabName)) return;
8593 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8598 public void ChangeTabUnreadManage(string tabName, bool isManage)
8601 for (idx = 0; idx < ListTab.TabCount; idx++)
8603 if (ListTab.TabPages[idx].Text == tabName) break;
8606 _statuses.SetTabUnreadManage(tabName, isManage);
8607 if (this._cfgCommon.TabIconDisp)
8609 if (_statuses.Tabs[tabName].UnreadCount > 0)
8610 ListTab.TabPages[idx].ImageIndex = 0;
8612 ListTab.TabPages[idx].ImageIndex = -1;
8615 if (_curTab.Text == tabName)
8617 this.PurgeListViewItemCache();
8621 SetMainWindowTitle();
8622 SetStatusLabelUrl();
8623 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
8626 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8628 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8629 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8631 if (string.IsNullOrEmpty(_rclickTabName)) return;
8633 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8638 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8640 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8642 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8647 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8649 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8651 RemoveSpecifiedTab(_rclickTabName, true);
8655 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8657 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8658 fltDialog.SetCurrent(_rclickTabName);
8659 fltDialog.ShowDialog(this);
8660 this.TopMost = this._cfgCommon.AlwaysTop;
8662 this.ApplyPostFilters();
8666 private void AddTabMenuItem_Click(object sender, EventArgs e)
8668 string tabName = null;
8669 MyCommon.TabUsageType tabUsage;
8670 using (InputTabName inputName = new InputTabName())
8672 inputName.TabName = _statuses.GetUniqueTabName();
8673 inputName.IsShowUsage = true;
8674 inputName.ShowDialog();
8675 if (inputName.DialogResult == DialogResult.Cancel) return;
8676 tabName = inputName.TabName;
8677 tabUsage = inputName.Usage;
8679 this.TopMost = this._cfgCommon.AlwaysTop;
8680 if (!string.IsNullOrEmpty(tabName))
8683 ListElement list = null;
8684 if (tabUsage == MyCommon.TabUsageType.Lists)
8686 using (ListAvailable listAvail = new ListAvailable())
8688 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8689 if (listAvail.SelectedList == null) return;
8690 list = listAvail.SelectedList;
8693 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8695 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8696 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8702 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8704 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8705 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8706 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8708 if (tabUsage == MyCommon.TabUsageType.Lists)
8710 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8711 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8712 GetTimeline(MyCommon.WORKERTYPE.List, 1, tabName);
8718 private void TabMenuItem_Click(object sender, EventArgs e)
8721 foreach (int idx in _curList.SelectedIndices)
8725 if (!SelectTab(out tabName)) return;
8727 fltDialog.SetCurrent(tabName);
8728 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8730 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8734 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8736 fltDialog.ShowDialog(this);
8737 this.TopMost = this._cfgCommon.AlwaysTop;
8740 this.ApplyPostFilters();
8742 if (this.ListTab.SelectedTab != null &&
8743 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8745 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8749 protected override bool ProcessDialogKey(Keys keyData)
8751 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8752 if ((keyData & Keys.KeyCode) == Keys.Enter)
8754 if (StatusText.Focused)
8756 bool _NewLine = false;
8759 if (this._cfgCommon.PostCtrlEnter) //Ctrl+Enter投稿時
8761 if (StatusText.Multiline)
8763 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8765 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8769 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8773 else if (this._cfgCommon.PostShiftEnter) //SHift+Enter投稿時
8775 if (StatusText.Multiline)
8777 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8779 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8783 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8789 if (StatusText.Multiline)
8791 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8793 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8794 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8798 if (((keyData & Keys.Shift) == Keys.Shift) ||
8799 (((keyData & Keys.Control) != Keys.Control) &&
8800 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8806 int pos1 = StatusText.SelectionStart;
8807 if (StatusText.SelectionLength > 0)
8809 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8811 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8812 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8817 PostButton_Click(null, null);
8821 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8822 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8823 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8825 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
8830 return base.ProcessDialogKey(keyData);
8833 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
8835 MakeReplyOrDirectStatus(false, true, true);
8838 private void IDRuleMenuItem_Click(object sender, EventArgs e)
8843 if (_curList.SelectedIndices.Count == 0) return;
8846 if (!SelectTab(out tabName)) return;
8850 MoveOrCopy(ref mv, ref mk);
8852 List<string> ids = new List<string>();
8853 foreach (int idx in _curList.SelectedIndices)
8855 PostClass post = _statuses[_curTab.Text, idx];
8856 if (!ids.Contains(post.ScreenName))
8858 PostFilterRule fc = new PostFilterRule();
8859 ids.Add(post.ScreenName);
8860 if (post.RetweetedId == null)
8862 fc.FilterName = post.ScreenName;
8866 fc.FilterName = post.RetweetedBy;
8868 fc.UseNameField = true;
8869 fc.MoveMatches = mv;
8870 fc.MarkMatches = mk;
8871 fc.UseRegex = false;
8872 fc.FilterByUrl = false;
8873 _statuses.Tabs[tabName].AddFilter(fc);
8878 List<string> atids = new List<string>();
8879 foreach (string id in ids)
8881 atids.Add("@" + id);
8883 int cnt = AtIdSupl.ItemCount;
8884 AtIdSupl.AddRangeItem(atids.ToArray());
8885 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
8888 this.ApplyPostFilters();
8892 private bool SelectTab(out string tabName)
8899 using (var dialog = new TabsDialog(_statuses))
8901 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
8903 var selectedTab = dialog.SelectedTab;
8904 tabName = selectedTab == null ? null : selectedTab.TabName;
8907 ListTab.SelectedTab.Focus();
8909 if (tabName == null)
8911 using (InputTabName inputName = new InputTabName())
8913 inputName.TabName = _statuses.GetUniqueTabName();
8914 inputName.ShowDialog();
8915 if (inputName.DialogResult == DialogResult.Cancel) return false;
8916 tabName = inputName.TabName;
8918 this.TopMost = this._cfgCommon.AlwaysTop;
8919 if (!string.IsNullOrEmpty(tabName))
8921 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
8923 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
8924 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8942 private void MoveOrCopy(ref bool move, ref bool mark)
8946 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
8947 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
8955 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
8956 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
8962 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
8967 private void CopyURLMenuItem_Click(object sender, EventArgs e)
8972 private void SelectAllMenuItem_Click(object sender, EventArgs e)
8974 if (StatusText.Focused)
8977 StatusText.SelectAll();
8981 // ListView上でのCtrl+A
8982 for (int i = 0; i < _curList.VirtualListSize; i++)
8984 _curList.SelectedIndices.Add(i);
8989 private void MoveMiddle()
8995 if (_curList.SelectedIndices.Count == 0) return;
8997 int idx = _curList.SelectedIndices[0];
8999 _item = _curList.GetItemAt(0, 25);
9005 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9007 idx2 = _curList.VirtualListSize - 1;
9011 idx -= Math.Abs(idx1 - idx2) / 2;
9012 if (idx < 0) idx = 0;
9014 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9015 _curList.EnsureVisible(idx);
9018 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9020 if (PostBrowser.Document.Links.Count > 0)
9022 UrlDialog.ClearUrl();
9024 string openUrlStr = "";
9026 if (PostBrowser.Document.Links.Count == 1)
9031 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9033 catch (ArgumentException)
9042 if (string.IsNullOrEmpty(urlStr)) return;
9043 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9047 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9050 string linkText = "";
9054 urlStr = linkElm.GetAttribute("title");
9055 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9056 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9057 linkText = linkElm.InnerText;
9058 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9060 linkText = "@" + linkText;
9063 catch (ArgumentException)
9072 if (string.IsNullOrEmpty(urlStr)) continue;
9073 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9077 if (UrlDialog.ShowDialog() == DialogResult.OK)
9079 openUrlStr = UrlDialog.SelectedUrl;
9086 this.TopMost = this._cfgCommon.AlwaysTop;
9088 if (string.IsNullOrEmpty(openUrlStr)) return;
9090 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9091 openUrlStr.StartsWith("https://twitter.com/search?q="))
9094 string urlStr = Uri.UnescapeDataString(openUrlStr);
9095 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9096 HashSupl.AddItem(hash);
9097 HashMgr.AddHashToHistory(hash.Trim(), false);
9098 AddNewTabForSearch(hash);
9103 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9104 if (this._cfgCommon.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9105 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9107 OpenUriAsync(openUrlStr);
9113 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9115 if (string.IsNullOrEmpty(_rclickTabName)) return;
9116 ClearTab(_rclickTabName, true);
9119 private void ClearTab(string tabName, bool showWarning)
9123 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9124 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9130 _statuses.ClearTabIds(tabName);
9131 if (ListTab.SelectedTab.Text == tabName)
9134 _anchorFlag = false;
9135 this.PurgeListViewItemCache();
9139 foreach (TabPage tb in ListTab.TabPages)
9141 if (tb.Text == tabName)
9144 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9148 if (!this._cfgCommon.TabIconDisp) ListTab.Refresh();
9150 SetMainWindowTitle();
9151 SetStatusLabelUrl();
9154 private static long followers = 0;
9156 private void SetMainWindowTitle()
9159 StringBuilder ttl = new StringBuilder(256);
9162 if (this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.None &&
9163 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9164 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9165 this._cfgCommon.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9167 foreach (var tab in _statuses.Tabs.Values)
9169 ur += tab.UnreadCount;
9174 if (this._cfgCommon.DispUsername) ttl.Append(tw.Username).Append(" - ");
9175 ttl.Append(Application.ProductName);
9177 switch (this._cfgCommon.DispLatestPost)
9179 case MyCommon.DispTitleEnum.Ver:
9180 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9182 case MyCommon.DispTitleEnum.Post:
9183 if (_history != null && _history.Count > 1)
9184 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9186 case MyCommon.DispTitleEnum.UnreadRepCount:
9187 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9189 case MyCommon.DispTitleEnum.UnreadAllCount:
9190 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9192 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9193 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9195 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9196 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9198 case MyCommon.DispTitleEnum.OwnStatus:
9199 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9200 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9206 this.Text = ttl.ToString();
9208 catch (AccessViolationException)
9210 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9214 private string GetStatusLabelText()
9217 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9218 if (_statuses == null) return "";
9219 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9220 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9221 if (tbRep == null || tbDm == null) return "";
9222 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9227 StringBuilder slbl = new StringBuilder(256);
9230 foreach (var tab in _statuses.Tabs.Values)
9232 ur += tab.UnreadCount;
9234 if (_curTab != null && tab.TabName.Equals(_curTab.Text))
9236 tur = tab.UnreadCount;
9247 UnreadAtCounter = urat;
9249 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9250 if (this._cfgCommon.TimelinePeriod == 0)
9252 slbl.Append(Properties.Resources.SetStatusLabelText2);
9256 slbl.Append(this._cfgCommon.TimelinePeriod + Properties.Resources.SetStatusLabelText3);
9258 return slbl.ToString();
9261 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9265 if (this.InvokeRequired && !this.IsDisposed)
9267 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9271 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9272 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9274 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9278 catch (ObjectDisposedException)
9282 catch (InvalidOperationException)
9288 private void SetStatusLabelUrl()
9290 StatusLabelUrl.Text = GetStatusLabelText();
9293 public void SetStatusLabel(string text)
9295 StatusLabel.Text = text;
9298 private static StringBuilder ur = new StringBuilder(64);
9300 private void SetNotifyIconText()
9302 // タスクトレイアイコンのツールチップテキスト書き換え
9304 ur.Remove(0, ur.Length);
9305 if (this._cfgCommon.DispUsername)
9307 ur.Append(tw.Username);
9310 ur.Append(Application.ProductName);
9312 ur.Append("(Debug Build)");
9314 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9317 ur.Append(UnreadCounter);
9319 ur.Append(UnreadAtCounter);
9322 NotifyIcon1.Text = ur.ToString();
9325 internal void CheckReplyTo(string StatusText)
9329 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9331 foreach (Match hm in m)
9333 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9335 hstr += "#" + hm.Result("$3") + " ";
9336 HashSupl.AddItem("#" + hm.Result("$3"));
9339 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9341 hstr += HashMgr.UseHash;
9343 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9345 // 本当にリプライ先指定すべきかどうかの判定
9346 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9348 if (this._cfgCommon.UseAtIdSupplement)
9350 int bCnt = AtIdSupl.ItemCount;
9351 foreach (Match mid in m)
9353 AtIdSupl.AddItem(mid.Result("${id}"));
9355 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9358 // リプライ先ステータスIDの指定がない場合は指定しない
9359 if (_reply_to_id == null) return;
9361 // リプライ先ユーザー名がない場合も指定しない
9362 if (string.IsNullOrEmpty(_reply_to_name))
9364 _reply_to_id = null;
9369 // 次の条件を満たす場合に in_reply_to_status_id 指定
9370 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9371 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9372 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9376 if (StatusText.StartsWith("@"))
9378 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9382 foreach (Match mid in m)
9384 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9389 _reply_to_id = null;
9390 _reply_to_name = null;
9394 private void TweenMain_Resize(object sender, EventArgs e)
9396 if (!_initialLayout && this._cfgCommon.MinimizeToTray && WindowState == FormWindowState.Minimized)
9398 this.Visible = false;
9400 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9402 this.ClientSize = _cfgLocal.FormSize;
9403 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9404 this.DesktopLocation = _cfgLocal.FormLocation;
9405 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9406 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9407 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9409 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9412 StatusText.Multiline = _cfgLocal.StatusMultiline;
9413 if (StatusText.Multiline)
9415 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9416 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9418 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9420 StatusText.Height = _cfgLocal.StatusTextHeight;
9424 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9426 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9429 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9431 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9433 _initialLayout = false;
9435 if (this.WindowState != FormWindowState.Minimized)
9437 _formWindowState = this.WindowState;
9441 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9443 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9444 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9445 if (PlaySoundMenuItem.Checked)
9447 this._cfgCommon.PlaySound = true;
9451 this._cfgCommon.PlaySound = false;
9453 _modifySettingCommon = true;
9456 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9458 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9460 _mySpDis = SplitContainer1.SplitterDistance;
9461 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9462 _modifySettingLocal = true;
9466 private void doRepliedStatusOpen()
9468 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9470 if (MyCommon.IsKeyDown(Keys.Shift))
9472 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9475 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9477 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9478 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9482 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9484 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9485 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9486 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9489 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9494 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9496 doRepliedStatusOpen();
9500 /// UserPicture.Image に設定されている画像を破棄します。
9502 private void ClearUserPicture()
9504 if (this.UserPicture.Image != null)
9506 var oldImage = this.UserPicture.Image;
9507 this.UserPicture.Image = null;
9512 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9514 //発言詳細のアイコン右クリック時のメニュー制御
9515 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9517 string name = _curPost.ImageUrl;
9518 if (name != null && name.Length > 0)
9520 int idx = name.LastIndexOf('/');
9523 name = Path.GetFileName(name.Substring(idx));
9524 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9526 name = name.Replace("_normal", "");
9527 this.IconNameToolStripMenuItem.Text = name;
9528 this.IconNameToolStripMenuItem.Enabled = true;
9532 this.IconNameToolStripMenuItem.Enabled = false;
9533 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9538 this.IconNameToolStripMenuItem.Enabled = false;
9539 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9542 this.ReloadIconToolStripMenuItem.Enabled = true;
9544 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9546 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9550 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9555 this.IconNameToolStripMenuItem.Enabled = false;
9556 this.ReloadIconToolStripMenuItem.Enabled = false;
9557 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9558 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9563 this.IconNameToolStripMenuItem.Enabled = false;
9564 this.ReloadIconToolStripMenuItem.Enabled = false;
9565 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9566 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9568 if (NameLabel.Tag != null)
9570 string id = (string)NameLabel.Tag;
9571 if (id == tw.Username)
9573 FollowToolStripMenuItem.Enabled = false;
9574 UnFollowToolStripMenuItem.Enabled = false;
9575 ShowFriendShipToolStripMenuItem.Enabled = false;
9576 ShowUserStatusToolStripMenuItem.Enabled = true;
9577 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9578 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9579 ListManageUserContextToolStripMenuItem3.Enabled = true;
9583 FollowToolStripMenuItem.Enabled = true;
9584 UnFollowToolStripMenuItem.Enabled = true;
9585 ShowFriendShipToolStripMenuItem.Enabled = true;
9586 ShowUserStatusToolStripMenuItem.Enabled = true;
9587 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9588 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9589 ListManageUserContextToolStripMenuItem3.Enabled = true;
9594 FollowToolStripMenuItem.Enabled = false;
9595 UnFollowToolStripMenuItem.Enabled = false;
9596 ShowFriendShipToolStripMenuItem.Enabled = false;
9597 ShowUserStatusToolStripMenuItem.Enabled = false;
9598 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9599 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9600 ListManageUserContextToolStripMenuItem3.Enabled = false;
9604 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9606 if (_curPost == null) return;
9607 string name = _curPost.ImageUrl;
9608 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9611 private async void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9613 if (this._curPost == null) return;
9615 await this.UserPicture.SetImageFromTask(async () =>
9617 var imageUrl = this._curPost.ImageUrl;
9619 var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
9620 .ConfigureAwait(false);
9622 return await image.CloneAsync()
9623 .ConfigureAwait(false);
9627 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9629 if (_curPost == null) return;
9630 string name = _curPost.ImageUrl;
9631 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9633 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9635 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9641 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9643 if (_curPost == null) return;
9644 string name = _curPost.ImageUrl;
9646 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9648 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9652 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9654 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9656 using (Graphics g = Graphics.FromImage(bmp2))
9658 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9659 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9661 bmp2.Save(this.SaveFileDialog1.FileName);
9667 //処理中にキャッシュアウトする可能性あり
9672 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9674 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9675 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9676 _modifySettingLocal = true;
9679 private void StatusText_MultilineChanged(object sender, EventArgs e)
9681 if (this.StatusText.Multiline)
9682 this.StatusText.ScrollBars = ScrollBars.Vertical;
9684 this.StatusText.ScrollBars = ScrollBars.None;
9686 _modifySettingLocal = true;
9689 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9692 StatusText.Multiline = MultiLineMenuItem.Checked;
9693 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9694 if (MultiLineMenuItem.Checked)
9696 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9697 SplitContainer2.SplitterDistance = 0;
9699 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9703 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9705 _modifySettingLocal = true;
9708 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
9710 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9711 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9713 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9714 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9715 //Appendix A. Collected ABNF for URI
9716 //http://www.ietf.org/rfc/rfc3986.txt
9720 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9722 if (StatusText.SelectionLength > 0)
9724 string tmp = StatusText.SelectedText;
9725 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9726 if (tmp.StartsWith("http"))
9728 // 文字列が選択されている場合はその文字列について処理
9730 //nico.ms使用、nicovideoにマッチしたら変換
9731 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9733 result = nicoms.Shorten(tmp);
9735 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9737 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9740 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9741 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9742 result = resultUri.ToString();
9744 catch (WebApiException e)
9746 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9749 catch (UriFormatException e)
9751 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9760 if (!string.IsNullOrEmpty(result))
9762 urlUndo undotmp = new urlUndo();
9764 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9765 StatusText.SelectedText = result;
9768 undotmp.Before = tmp;
9769 undotmp.After = result;
9771 if (urlUndoBuffer == null)
9773 urlUndoBuffer = new List<urlUndo>();
9774 UrlUndoToolStripMenuItem.Enabled = true;
9777 urlUndoBuffer.Add(undotmp);
9783 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9784 @"(?<url>(?<protocol>https?://)" +
9785 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9786 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9787 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9788 // 正規表現にマッチしたURL文字列をtinyurl化
9789 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9791 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9792 string tmp = mt.Result("${url}");
9793 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9794 urlUndo undotmp = new urlUndo();
9797 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9799 //nico.ms使用、nicovideoにマッチしたら変換
9800 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9802 result = nicoms.Shorten(tmp);
9804 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9806 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9809 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9810 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9811 result = resultUri.ToString();
9813 catch (HttpRequestException e)
9815 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
9816 // のように長いので「:」が含まれていればそれ以降のみを抽出する
9817 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
9819 this.StatusLabel.Text = Converter_Type + ":" + message;
9822 catch (WebApiException e)
9824 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9827 catch (UriFormatException e)
9829 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9838 if (!string.IsNullOrEmpty(result))
9840 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9841 StatusText.SelectedText = result;
9843 undotmp.Before = mt.Result("${url}");
9844 undotmp.After = result;
9846 if (urlUndoBuffer == null)
9848 urlUndoBuffer = new List<urlUndo>();
9849 UrlUndoToolStripMenuItem.Enabled = true;
9852 urlUndoBuffer.Add(undotmp);
9860 private void doUrlUndo()
9862 if (urlUndoBuffer != null)
9864 string tmp = StatusText.Text;
9865 foreach (urlUndo data in urlUndoBuffer)
9867 tmp = tmp.Replace(data.After, data.Before);
9869 StatusText.Text = tmp;
9870 urlUndoBuffer = null;
9871 UrlUndoToolStripMenuItem.Enabled = false;
9872 StatusText.SelectionStart = 0;
9873 StatusText.SelectionLength = 0;
9877 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
9879 await UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
9882 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
9884 await UrlConvertAsync(MyCommon.UrlConverter.Isgd);
9887 private async void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
9889 await UrlConvertAsync(MyCommon.UrlConverter.Twurl);
9892 private async void UxnuMenuItem_Click(object sender, EventArgs e)
9894 await UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
9897 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
9899 if (!await UrlConvertAsync(this._cfgCommon.AutoShortUrlFirst))
9901 MyCommon.UrlConverter svc = this._cfgCommon.AutoShortUrlFirst;
9902 Random rnd = new Random();
9903 // 前回使用した短縮URLサービス以外を選択する
9906 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
9908 while (svc == this._cfgCommon.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
9909 await UrlConvertAsync(svc);
9913 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
9918 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
9920 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9921 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
9922 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
9923 _modifySettingCommon = true;
9926 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
9928 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9929 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
9930 _cfgCommon.ListLock = ListLockMenuItem.Checked;
9931 _modifySettingCommon = true;
9934 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
9936 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
9937 MenuStrip1.Tag = new Object();
9938 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
9941 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
9943 if (this.Tag != null) // 設定された戻り先へ遷移
9945 if (this.Tag == this.ListTab.SelectedTab)
9946 ((Control)this.ListTab.SelectedTab.Tag).Select();
9948 ((Control)this.Tag).Select();
9950 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
9952 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
9954 this.Tag = ListTab.SelectedTab.Tag;
9955 ((Control)this.Tag).Select();
9958 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
9959 MenuStrip1.Tag = null;
9962 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
9964 DetailsListView lst = (DetailsListView)sender;
9965 if (_cfgLocal == null) return;
9969 _cfgLocal.Width1 = lst.Columns[0].Width;
9970 _cfgLocal.Width3 = lst.Columns[1].Width;
9974 int[] darr = new int[lst.Columns.Count];
9975 for (int i = 0; i < lst.Columns.Count; i++)
9977 darr[lst.Columns[i].DisplayIndex] = i;
9979 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
9981 for (int i = 0; i < lst.Columns.Count; i++)
9986 _cfgLocal.DisplayIndex1 = i;
9989 _cfgLocal.DisplayIndex2 = i;
9992 _cfgLocal.DisplayIndex3 = i;
9995 _cfgLocal.DisplayIndex4 = i;
9998 _cfgLocal.DisplayIndex5 = i;
10001 _cfgLocal.DisplayIndex6 = i;
10004 _cfgLocal.DisplayIndex7 = i;
10007 _cfgLocal.DisplayIndex8 = i;
10011 _cfgLocal.Width1 = lst.Columns[0].Width;
10012 _cfgLocal.Width2 = lst.Columns[1].Width;
10013 _cfgLocal.Width3 = lst.Columns[2].Width;
10014 _cfgLocal.Width4 = lst.Columns[3].Width;
10015 _cfgLocal.Width5 = lst.Columns[4].Width;
10016 _cfgLocal.Width6 = lst.Columns[5].Width;
10017 _cfgLocal.Width7 = lst.Columns[6].Width;
10018 _cfgLocal.Width8 = lst.Columns[7].Width;
10020 _modifySettingLocal = true;
10021 _isColumnChanged = true;
10024 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10026 DetailsListView lst = (DetailsListView)sender;
10027 if (_cfgLocal == null) return;
10030 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10032 _cfgLocal.Width1 = lst.Columns[0].Width;
10033 _modifySettingLocal = true;
10034 _isColumnChanged = true;
10036 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10038 _cfgLocal.Width3 = lst.Columns[1].Width;
10039 _modifySettingLocal = true;
10040 _isColumnChanged = true;
10045 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10047 _cfgLocal.Width1 = lst.Columns[0].Width;
10048 _modifySettingLocal = true;
10049 _isColumnChanged = true;
10051 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10053 _cfgLocal.Width2 = lst.Columns[1].Width;
10054 _modifySettingLocal = true;
10055 _isColumnChanged = true;
10057 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10059 _cfgLocal.Width3 = lst.Columns[2].Width;
10060 _modifySettingLocal = true;
10061 _isColumnChanged = true;
10063 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10065 _cfgLocal.Width4 = lst.Columns[3].Width;
10066 _modifySettingLocal = true;
10067 _isColumnChanged = true;
10069 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10071 _cfgLocal.Width5 = lst.Columns[4].Width;
10072 _modifySettingLocal = true;
10073 _isColumnChanged = true;
10075 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10077 _cfgLocal.Width6 = lst.Columns[5].Width;
10078 _modifySettingLocal = true;
10079 _isColumnChanged = true;
10081 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10083 _cfgLocal.Width7 = lst.Columns[6].Width;
10084 _modifySettingLocal = true;
10085 _isColumnChanged = true;
10087 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10089 _cfgLocal.Width8 = lst.Columns[7].Width;
10090 _modifySettingLocal = true;
10091 _isColumnChanged = true;
10094 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10097 // SaveConfigsLocal();
10101 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10103 //発言詳細で「選択文字列をコピー」を行う
10104 //WebBrowserコンポーネントのインスタンスを渡す
10105 Type typ = ComponentInstance.ActiveXInstance.GetType();
10106 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10107 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10108 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10111 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10114 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10117 Clipboard.SetDataObject(_selText, false, 5, 100);
10119 catch (Exception ex)
10121 MessageBox.Show(ex.Message);
10125 private void doSearchToolStrip(string url)
10127 //発言詳細で「選択文字列で検索」(選択文字列取得)
10128 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10130 if (_selText != null)
10132 if (url == Properties.Resources.SearchItem4Url)
10135 AddNewTabForSearch(_selText);
10139 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10144 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10147 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10150 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10152 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10155 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10157 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10160 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10162 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10165 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10169 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10170 foreach (Match m in mc)
10172 if (m.Groups["url"].Value == this._postBrowserStatusText)
10174 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10180 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10182 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10184 catch (Exception ex)
10186 MessageBox.Show(ex.Message);
10190 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10192 // URLコピーの項目の表示/非表示
10193 if (PostBrowser.StatusText.StartsWith("http"))
10195 this._postBrowserStatusText = PostBrowser.StatusText;
10196 string name = GetUserId();
10197 UrlCopyContextMenuItem.Enabled = true;
10200 FollowContextMenuItem.Enabled = true;
10201 RemoveContextMenuItem.Enabled = true;
10202 FriendshipContextMenuItem.Enabled = true;
10203 ShowUserStatusContextMenuItem.Enabled = true;
10204 SearchPostsDetailToolStripMenuItem.Enabled = true;
10205 IdFilterAddMenuItem.Enabled = true;
10206 ListManageUserContextToolStripMenuItem.Enabled = true;
10207 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10211 FollowContextMenuItem.Enabled = false;
10212 RemoveContextMenuItem.Enabled = false;
10213 FriendshipContextMenuItem.Enabled = false;
10214 ShowUserStatusContextMenuItem.Enabled = false;
10215 SearchPostsDetailToolStripMenuItem.Enabled = false;
10216 IdFilterAddMenuItem.Enabled = false;
10217 ListManageUserContextToolStripMenuItem.Enabled = false;
10218 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10221 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10222 UseHashtagMenuItem.Enabled = true;
10224 UseHashtagMenuItem.Enabled = false;
10228 this._postBrowserStatusText = "";
10229 UrlCopyContextMenuItem.Enabled = false;
10230 FollowContextMenuItem.Enabled = false;
10231 RemoveContextMenuItem.Enabled = false;
10232 FriendshipContextMenuItem.Enabled = false;
10233 ShowUserStatusContextMenuItem.Enabled = false;
10234 SearchPostsDetailToolStripMenuItem.Enabled = false;
10235 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10236 UseHashtagMenuItem.Enabled = false;
10237 IdFilterAddMenuItem.Enabled = false;
10238 ListManageUserContextToolStripMenuItem.Enabled = false;
10240 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10241 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10242 if (_selText == null)
10244 SelectionSearchContextMenuItem.Enabled = false;
10245 SelectionCopyContextMenuItem.Enabled = false;
10246 SelectionTranslationToolStripMenuItem.Enabled = false;
10250 SelectionSearchContextMenuItem.Enabled = true;
10251 SelectionCopyContextMenuItem.Enabled = true;
10252 SelectionTranslationToolStripMenuItem.Enabled = true;
10254 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10255 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10256 bool fAllFlag = false;
10257 foreach (Match mu in ma)
10259 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10265 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10267 if (_curPost == null)
10268 TranslationToolStripMenuItem.Enabled = false;
10270 TranslationToolStripMenuItem.Enabled = true;
10275 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10277 //発言詳細の選択文字列で現在のタブを検索
10278 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10280 if (_selText != null)
10282 var searchOptions = new SearchWordDialog.SearchOptions(
10283 SearchWordDialog.SearchType.Timeline,
10286 caseSensitive: false,
10289 this.SearchDialog.ResultOptions = searchOptions;
10292 searchOptions.Query,
10293 searchOptions.CaseSensitive,
10294 searchOptions.UseRegex,
10295 SEARCHTYPE.NextSearch);
10299 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10301 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10302 _modifySettingLocal = true;
10305 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10307 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10309 SelectMedia_DragDrop(e);
10311 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10313 var url = GetUrlFromDataObject(e.Data);
10316 if (url.Item2 == null)
10317 appendText = url.Item1;
10319 appendText = url.Item2 + " " + url.Item1;
10321 if (this.StatusText.TextLength == 0)
10322 this.StatusText.Text = appendText;
10324 this.StatusText.Text += " " + appendText;
10326 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10328 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10329 if (data != null) StatusText.Text += data;
10334 /// IDataObject から URL とタイトルの対を取得します
10337 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10339 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10340 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10341 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10343 if (data.GetDataPresent("text/x-moz-url"))
10345 // Firefox, Google Chrome で利用可能
10346 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10348 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10350 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10351 if (lines.Length < 2)
10352 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10354 return new Tuple<string, string>(lines[0], lines[1]);
10357 else if (data.GetDataPresent("IESiteModeToUrl"))
10359 // Internet Exproler 用
10360 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10362 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10364 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10365 if (lines.Length < 2)
10366 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10368 return new Tuple<string, string>(lines[0], lines[1]);
10371 else if (data.GetDataPresent("UniformResourceLocatorW"))
10375 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10377 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10378 return new Tuple<string, string>(url, null);
10382 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10385 private void TweenMain_DragEnter(object sender, DragEventArgs e)
10387 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10389 SelectMedia_DragEnter(e);
10393 private void TweenMain_DragOver(object sender, DragEventArgs e)
10395 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10397 SelectMedia_DragOver(e);
10399 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10401 e.Effect = DragDropEffects.Copy;
10403 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10405 e.Effect = DragDropEffects.Copy;
10409 e.Effect = DragDropEffects.None;
10413 public bool IsNetworkAvailable()
10416 nw = MyCommon.IsNetworkAvailable();
10417 _myStatusOnline = nw;
10421 public Task OpenUriAsync(string UriString)
10423 return Task.Run(() =>
10425 string myPath = UriString;
10429 var configBrowserPath = this._cfgLocal.BrowserPath;
10430 if (!string.IsNullOrEmpty(configBrowserPath))
10432 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10434 int sep = configBrowserPath.IndexOf("\"", 2);
10435 string browserPath = configBrowserPath.Substring(1, sep - 1);
10437 if (sep < configBrowserPath.Length - 1)
10439 arg = configBrowserPath.Substring(sep + 1);
10441 myPath = arg + " " + myPath;
10442 System.Diagnostics.Process.Start(browserPath, myPath);
10446 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10451 System.Diagnostics.Process.Start(myPath);
10456 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10461 private void ListTabSelect(TabPage _tab)
10465 this.PurgeListViewItemCache();
10468 _curList = (DetailsListView)_tab.Tag;
10469 if (_curList.SelectedIndices.Count > 0)
10471 _curItemIndex = _curList.SelectedIndices[0];
10472 _curPost = GetCurTabPost(_curItemIndex);
10476 _curItemIndex = -1;
10480 _anchorPost = null;
10481 _anchorFlag = false;
10485 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10489 for (int i = 0; i < _curList.Columns.Count; i++)
10491 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10496 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10498 ListTabSelect(e.TabPage);
10501 private void SelectListItem(DetailsListView LView, int Index)
10504 Rectangle bnd = new Rectangle();
10506 var item = LView.FocusedItem;
10515 LView.SelectedIndices.Clear();
10517 while (LView.SelectedIndices.Count > 0);
10518 item = LView.Items[Index];
10519 item.Selected = true;
10520 item.Focused = true;
10522 if (flg) LView.Invalidate(bnd);
10525 private void SelectListItem(DetailsListView LView , int[] Index, int[] FocusedIndex)
10528 Rectangle bnd = new Rectangle();
10530 var item = LView.FocusedItem;
10538 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10542 LView.SelectedIndices.Clear();
10544 while (LView.SelectedIndices.Count > 0);
10545 foreach (int idx in Index)
10547 if (idx > -1 && LView.VirtualListSize > idx)
10549 LView.SelectedIndices.Add(idx);
10550 if (fIdx == -1) fIdx = idx;
10554 if (FocusedIndex[1] > -1 && LView.VirtualListSize > FocusedIndex[1])
10556 LView.SelectionMark = FocusedIndex[1];
10558 if (FocusedIndex[0] > -1 && LView.VirtualListSize > FocusedIndex[0])
10560 LView.Items[FocusedIndex[0]].Focused = true;
10562 else if (fIdx > -1)
10564 LView.Items[fIdx].Focused = true;
10567 if (flg) LView.Invalidate(bnd);
10570 private void RunAsync(GetWorkerArg args)
10572 BackgroundWorker bw = null;
10573 if (args.type != MyCommon.WORKERTYPE.Follower)
10575 for (int i = 0; i < _bw.Length; i++)
10577 if (_bw[i] != null && !_bw[i].IsBusy)
10585 for (int i = 0; i < _bw.Length; i++)
10587 if (_bw[i] == null)
10589 _bw[i] = new BackgroundWorker();
10591 bw.WorkerReportsProgress = true;
10592 bw.WorkerSupportsCancellation = true;
10593 bw.DoWork += GetTimelineWorker_DoWork;
10594 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10595 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10603 if (_bwFollower == null)
10605 _bwFollower = new BackgroundWorker();
10607 bw.WorkerReportsProgress = true;
10608 bw.WorkerSupportsCancellation = true;
10609 bw.DoWork += GetTimelineWorker_DoWork;
10610 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10611 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10615 if (_bwFollower.IsBusy == false)
10619 if (bw == null) return;
10621 bw.RunWorkerAsync(args);
10624 private void StartUserStream()
10626 tw.NewPostFromStream += tw_NewPostFromStream;
10627 tw.UserStreamStarted += tw_UserStreamStarted;
10628 tw.UserStreamStopped += tw_UserStreamStopped;
10629 tw.PostDeleted += tw_PostDeleted;
10630 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10632 MenuItemUserStream.Text = "&UserStream ■";
10633 MenuItemUserStream.Enabled = true;
10634 StopToolStripMenuItem.Text = "&Start";
10635 StopToolStripMenuItem.Enabled = true;
10636 if (this._cfgCommon.UserstreamStartup) tw.StartUserStream();
10639 private async void TweenMain_Shown(object sender, EventArgs e)
10643 PostBrowser.Url = new Uri("about:blank");
10644 PostBrowser.DocumentText = ""; //発言詳細部初期化
10650 NotifyIcon1.Visible = true;
10652 if (this.IsNetworkAvailable())
10654 this.RefreshMuteUserIdsAsync();
10655 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, "");
10656 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10657 if (this._cfgCommon.StartupFollowers)
10659 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10661 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10663 _waitTimeline = true;
10664 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
10666 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
10668 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
10669 if (this._cfgCommon.GetFav)
10672 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
10674 _waitPubSearch = true;
10675 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, ""); //tabname="":全タブ
10676 _waitUserTimeline = true;
10677 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, ""); //tabname="":全タブ
10679 GetTimeline(MyCommon.WORKERTYPE.List, 1, ""); //tabname="":全タブ
10682 while (this.IsInitialRead())
10684 await Task.Delay(5000);
10687 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10689 if (MyCommon._endingFlag)
10693 if (MyCommon._endingFlag) return;
10695 if (ApplicationSettings.VersionInfoUrl != null)
10697 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10698 if (this._cfgCommon.StartupVersion)
10699 await this.CheckNewVersion(true);
10703 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10704 this.VerUpMenuItem.Enabled = false;
10705 this.VerUpMenuItem.Available = false;
10706 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10710 if (!tw.GetFollowersSuccess && this._cfgCommon.StartupFollowers)
10711 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10714 if (!tw.GetNoRetweetSuccess)
10715 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10718 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10719 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10721 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10722 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10724 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10725 SettingStripMenuItem_Click(null, null);
10732 TimerTimeline.Enabled = true;
10735 private bool IsInitialRead()
10737 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10740 private void doGetFollowersMenu()
10742 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, "");
10743 DispSelectedPost(true);
10746 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10748 doGetFollowersMenu();
10751 private void doReTweetUnofficial()
10754 if (this.ExistCurrentPost)
10756 if (_curPost.IsDm ||
10757 !StatusText.Enabled) return;
10759 if (_curPost.IsProtect)
10761 MessageBox.Show("Protected.");
10764 string rtdata = _curPost.Text;
10765 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10767 this._reply_to_id = null;
10768 this._reply_to_name = null;
10770 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10772 StatusText.SelectionStart = 0;
10773 StatusText.Focus();
10777 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10779 doReTweetUnofficial();
10782 private void doReTweetOfficial(bool isConfirm)
10785 if (this.ExistCurrentPost)
10787 if (_curPost.IsProtect)
10789 MessageBox.Show("Protected.");
10790 _DoFavRetweetFlags = false;
10793 if (_curList.SelectedIndices.Count > 15)
10795 MessageBox.Show(Properties.Resources.RetweetLimitText);
10796 _DoFavRetweetFlags = false;
10799 else if (_curList.SelectedIndices.Count > 1)
10801 string QuestionText = Properties.Resources.RetweetQuestion2;
10802 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10803 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10805 case DialogResult.Cancel:
10806 case DialogResult.No:
10807 _DoFavRetweetFlags = false;
10813 if (_curPost.IsDm || _curPost.IsMe)
10815 _DoFavRetweetFlags = false;
10818 if (!this._cfgCommon.RetweetNoConfirm)
10820 string Questiontext = Properties.Resources.RetweetQuestion1;
10821 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
10822 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
10824 _DoFavRetweetFlags = false;
10829 GetWorkerArg args = new GetWorkerArg();
10830 args.ids = new List<long>();
10831 args.sIds = new List<long>();
10832 args.tName = _curTab.Text;
10833 args.type = MyCommon.WORKERTYPE.Retweet;
10834 foreach (int idx in _curList.SelectedIndices)
10836 PostClass post = GetCurTabPost(idx);
10837 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
10843 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
10845 doReTweetOfficial(true);
10848 private void FavoritesRetweetOriginal()
10850 if (!this.ExistCurrentPost) return;
10851 _DoFavRetweetFlags = true;
10852 doReTweetOfficial(true);
10853 if (_DoFavRetweetFlags)
10855 _DoFavRetweetFlags = false;
10856 FavoriteChange(true, false);
10860 private void FavoritesRetweetUnofficial()
10862 if (this.ExistCurrentPost && !_curPost.IsDm)
10864 _DoFavRetweetFlags = true;
10865 FavoriteChange(true);
10866 if (!_curPost.IsProtect && _DoFavRetweetFlags)
10868 _DoFavRetweetFlags = false;
10869 doReTweetUnofficial();
10875 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
10877 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
10878 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
10879 /// <returns>復元されたツイート本文</returns>
10880 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
10882 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
10885 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
10887 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
10889 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
10893 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
10895 statusHtml = statusHtml.Replace("<br>", " ");
10897 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
10898 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
10899 statusHtml = statusHtml.Replace(" ", " ");
10901 return WebUtility.HtmlDecode(statusHtml);
10904 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
10906 if (_curPost != null)
10907 DispSelectedPost(true);
10910 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
10912 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
10913 DebugModeToolStripMenuItem.Visible = true;
10915 DebugModeToolStripMenuItem.Visible = false;
10918 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
10920 this._cfgCommon.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
10923 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
10925 ToolStripMenuItemUrlAutoShorten.Checked = this._cfgCommon.UrlConvertAuto;
10928 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
10930 if (TraceOutToolStripMenuItem.Checked)
10931 MyCommon.TraceFlag = true;
10933 MyCommon.TraceFlag = false;
10936 private void TweenMain_Deactivate(object sender, EventArgs e)
10938 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
10939 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
10942 private void TabRenameMenuItem_Click(object sender, EventArgs e)
10944 if (string.IsNullOrEmpty(_rclickTabName)) return;
10945 TabRename(ref _rclickTabName);
10948 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
10950 await UrlConvertAsync(MyCommon.UrlConverter.Bitly);
10953 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
10955 await UrlConvertAsync(MyCommon.UrlConverter.Jmp);
10959 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
10961 e.Result = tw.GetInfoApi();
10964 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
10966 StringBuilder tmp = new StringBuilder();
10968 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
10972 var result = (TwitterApiStatus)dlg.Result;
10974 if (result == null)
10976 var accessLevel = result.AccessLevel;
10977 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
10978 var mediaLimit = result.MediaUploadLimit;
10980 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
10981 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
10982 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
10983 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
10986 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
10987 SetStatusLabelUrl();
10990 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
10991 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
10992 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
10996 tmp.Append(Properties.Resources.ApiInfo5);
11000 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11003 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11006 if (_curPost != null) id = _curPost.ScreenName;
11010 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11012 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11013 e.Result = arg.tw.PostFollowCommand(arg.id);
11016 private void FollowCommand(string id)
11018 using (InputTabName inputName = new InputTabName())
11020 inputName.FormTitle = "Follow";
11021 inputName.FormDescription = Properties.Resources.FRMessage1;
11022 inputName.TabName = id;
11023 if (inputName.ShowDialog() == DialogResult.OK &&
11024 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11026 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11028 arg.id = inputName.TabName.Trim();
11029 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11030 FollowCommand_DoWork,
11034 _info.ShowDialog();
11035 string ret = (string)_info.Result;
11036 if (!string.IsNullOrEmpty(ret))
11037 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11039 MessageBox.Show(Properties.Resources.FRMessage3);
11045 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11048 if (_curPost != null) id = _curPost.ScreenName;
11049 RemoveCommand(id, false);
11052 private class FollowRemoveCommandArgs
11058 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11060 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11061 e.Result = arg.tw.PostRemoveCommand(arg.id);
11064 private void RemoveCommand(string id, bool skipInput)
11066 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11071 using (InputTabName inputName = new InputTabName())
11073 inputName.FormTitle = "Unfollow";
11074 inputName.FormDescription = Properties.Resources.FRMessage1;
11075 inputName.TabName = id;
11076 if (inputName.ShowDialog() == DialogResult.OK &&
11077 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11080 arg.id = inputName.TabName.Trim();
11089 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11090 RemoveCommand_DoWork,
11094 _info.ShowDialog();
11095 string ret = (string)_info.Result;
11096 if (!string.IsNullOrEmpty(ret))
11097 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11099 MessageBox.Show(Properties.Resources.FRMessage3);
11103 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11106 if (_curPost != null)
11107 id = _curPost.ScreenName;
11109 ShowFriendship(id);
11112 private class ShowFriendshipArgs
11115 public class FriendshipInfo
11117 public string id = "";
11118 public bool isFollowing = false;
11119 public bool isFollowed = false;
11120 public FriendshipInfo(string id)
11125 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11128 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11130 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11131 string result = "";
11132 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11134 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11135 if (!string.IsNullOrEmpty(rt))
11137 if (string.IsNullOrEmpty(result)) result = rt;
11143 private void ShowFriendship(string id)
11145 ShowFriendshipArgs args = new ShowFriendshipArgs();
11147 using (InputTabName inputName = new InputTabName())
11149 inputName.FormTitle = "Show Friendships";
11150 inputName.FormDescription = Properties.Resources.FRMessage1;
11151 inputName.TabName = id;
11152 if (inputName.ShowDialog() == DialogResult.OK &&
11153 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11156 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11157 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11158 ShowFriendship_DoWork,
11162 _info.ShowDialog();
11163 ret = (string)_info.Result;
11165 string result = "";
11166 if (string.IsNullOrEmpty(ret))
11168 if (args.ids[0].isFollowing)
11170 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11174 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11176 if (args.ids[0].isFollowed)
11178 result += Properties.Resources.GetFriendshipInfo3;
11182 result += Properties.Resources.GetFriendshipInfo4;
11184 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11190 MessageBox.Show(result);
11195 private void ShowFriendship(string[] ids)
11197 foreach (string id in ids)
11200 ShowFriendshipArgs args = new ShowFriendshipArgs();
11202 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11203 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11204 ShowFriendship_DoWork,
11208 _info.ShowDialog();
11209 ret = (string)_info.Result;
11211 string result = "";
11212 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11214 if (string.IsNullOrEmpty(ret))
11217 if (fInfo.isFollowing)
11219 ff += Properties.Resources.GetFriendshipInfo1;
11223 ff += Properties.Resources.GetFriendshipInfo2;
11226 ff += System.Environment.NewLine + " ";
11227 if (fInfo.isFollowed)
11229 ff += Properties.Resources.GetFriendshipInfo3;
11233 ff += Properties.Resources.GetFriendshipInfo4;
11235 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11236 if (fInfo.isFollowing)
11238 if (MessageBox.Show(
11239 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11240 MessageBoxButtons.YesNo,
11241 MessageBoxIcon.Question,
11242 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11244 RemoveCommand(fInfo.id, true);
11249 MessageBox.Show(result);
11254 MessageBox.Show(ret);
11259 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11261 doShowUserStatus(tw.Username, false);
11262 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11264 // doShowUserStatus(tw.Username, false);
11268 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11273 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11274 // URLから切り出した文字列を渡す
11276 public bool IsTwitterId(string name)
11278 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11279 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11281 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11284 private string GetUserId()
11286 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11287 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11288 return m.Result("${ScreenName}");
11293 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11295 string name = GetUserId();
11296 if (name != null) FollowCommand(name);
11299 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11301 string name = GetUserId();
11302 if (name != null) RemoveCommand(name, false);
11305 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11307 string name = GetUserId();
11308 if (name != null) ShowFriendship(name);
11311 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11313 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11314 List<string> ids = new List<string>();
11315 foreach (Match mu in ma)
11317 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11319 ids.Add(mu.Result("${ScreenName}"));
11322 ShowFriendship(ids.ToArray());
11325 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11327 string name = GetUserId();
11328 if (name != null) ShowUserStatus(name);
11331 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11333 string name = GetUserId();
11334 if (name != null) AddNewTabForUserTimeline(name);
11337 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11339 string name = GetUserId();
11340 if (name != null) AddNewTabForSearch("@" + name);
11343 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11345 _modifySettingCommon = true;
11348 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11350 _modifySettingCommon = true;
11353 private void doQuote()
11357 if (this.ExistCurrentPost)
11359 if (_curPost.IsDm ||
11360 !StatusText.Enabled) return;
11362 if (_curPost.IsProtect)
11364 MessageBox.Show("Protected.");
11367 string rtdata = _curPost.Text;
11368 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11370 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11371 if (_curPost.RetweetedId == null)
11373 _reply_to_id = _curPost.StatusId;
11377 _reply_to_id = _curPost.RetweetedId.Value;
11379 _reply_to_name = _curPost.ScreenName;
11381 StatusText.SelectionStart = 0;
11382 StatusText.Focus();
11386 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11391 private void SearchButton_Click(object sender, EventArgs e)
11394 Control pnl = ((Control)sender).Parent;
11395 if (pnl == null) return;
11396 string tbName = pnl.Parent.Text;
11397 TabClass tb = _statuses.Tabs[tbName];
11398 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11399 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11400 cmb.Text = cmb.Text.Trim();
11401 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11402 bool Quote = false;
11403 StringBuilder buf = new StringBuilder();
11404 char[] c = cmb.Text.ToCharArray();
11405 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11407 if (cnt > cmb.Text.Length - 4)
11409 buf.Append(cmb.Text.Substring(cnt));
11418 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11420 buf.Append(" OR ");
11425 buf.Append(c[cnt]);
11427 cmb.Text = buf.ToString();
11429 tb.SearchWords = cmb.Text;
11430 tb.SearchLang = cmbLang.Text;
11431 if (string.IsNullOrEmpty(cmb.Text))
11433 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11437 if (tb.IsQueryChanged())
11439 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11440 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11441 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11442 cmb.Text = tb.SearchWords;
11444 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11445 this.PurgeListViewItemCache();
11446 lst.VirtualListSize = 0;
11447 _statuses.ClearTabIds(tbName);
11448 SaveConfigsTabs(); //検索条件の保存
11451 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, tbName);
11452 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11455 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11461 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11463 if (_statuses.RemovedTab.Count == 0)
11465 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11470 TabClass tb = _statuses.RemovedTab.Pop();
11471 if (tb.TabType == MyCommon.TabUsageType.Related)
11473 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11474 if (relatedTab != null)
11476 // 関連発言なら既存のタブを置き換える
11477 tb.TabName = relatedTab.TabName;
11478 this.ClearTab(tb.TabName, false);
11479 _statuses.Tabs[tb.TabName] = tb;
11480 for (int i = 0; i < ListTab.TabPages.Count; i++)
11482 if (tb.TabName == ListTab.TabPages[i].Text)
11484 ListTab.SelectedIndex = i;
11485 ListTabSelect(ListTab.TabPages[i]);
11492 const string TabName = "Related Tweets";
11493 string renamed = TabName;
11494 for (int i = 2; i <= 100; i++)
11496 if (!_statuses.ContainsTab(renamed)) break;
11497 renamed = TabName + i.ToString();
11499 tb.TabName = renamed;
11500 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11501 _statuses.Tabs.Add(renamed, tb); // 後に
11502 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11503 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11508 string renamed = tb.TabName;
11509 for (int i = 1; i < int.MaxValue; i++)
11511 if (!_statuses.ContainsTab(renamed)) break;
11512 renamed = tb.TabName + "(" + i.ToString() + ")";
11514 tb.TabName = renamed;
11515 _statuses.Tabs.Add(renamed, tb); // 先に
11516 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11517 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11518 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11524 private void doMoveToRTHome()
11526 if (_curList.SelectedIndices.Count > 0)
11528 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11529 if (post.RetweetedId != null)
11531 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11536 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11541 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11543 string name = GetUserId();
11549 if (_curList.SelectedIndices.Count == 0) return;
11552 if (!SelectTab(out tabName)) return;
11556 MoveOrCopy(ref mv, ref mk);
11558 PostFilterRule fc = new PostFilterRule();
11559 fc.FilterName = name;
11560 fc.UseNameField = true;
11561 fc.MoveMatches = mv;
11562 fc.MarkMatches = mk;
11563 fc.UseRegex = false;
11564 fc.FilterByUrl = false;
11565 _statuses.Tabs[tabName].AddFilter(fc);
11567 this.ApplyPostFilters();
11572 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11576 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11578 if (menuItem.Owner == this.ContextMenuPostBrowser)
11580 user = GetUserId();
11581 if (user == null) return;
11583 else if (this._curPost != null)
11585 user = this._curPost.ScreenName;
11592 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11594 string res = this.tw.GetListsApi();
11596 if (!string.IsNullOrEmpty(res))
11598 MessageBox.Show("Failed to get lists. (" + res + ")");
11603 using (MyLists listSelectForm = new MyLists(user, this.tw))
11605 listSelectForm.ShowDialog(this);
11609 private void SearchControls_Enter(object sender, EventArgs e)
11611 Control pnl = (Control)sender;
11612 foreach (Control ctl in pnl.Controls)
11614 ctl.TabStop = true;
11618 private void SearchControls_Leave(object sender, EventArgs e)
11620 Control pnl = (Control)sender;
11621 foreach (Control ctl in pnl.Controls)
11623 ctl.TabStop = false;
11627 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11629 if (ListTab.SelectedTab != null)
11631 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11632 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11636 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11638 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11641 HashMgr.SetPermanentHash("#" + Uri.UnescapeDataString(m.Result("${hash}")));
11642 HashStripSplitButton.Text = HashMgr.UseHash;
11643 HashToggleMenuItem.Checked = true;
11644 HashToggleToolStripMenuItem.Checked = true;
11646 _modifySettingCommon = true;
11650 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11652 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11655 private void HashManageMenuItem_Click(object sender, EventArgs e)
11657 DialogResult rslt = DialogResult.Cancel;
11660 rslt = HashMgr.ShowDialog();
11666 this.TopMost = this._cfgCommon.AlwaysTop;
11667 if (rslt == DialogResult.Cancel) return;
11668 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11670 HashStripSplitButton.Text = HashMgr.UseHash;
11671 HashToggleMenuItem.Checked = true;
11672 HashToggleToolStripMenuItem.Checked = true;
11676 HashStripSplitButton.Text = "#[-]";
11677 HashToggleMenuItem.Checked = false;
11678 HashToggleToolStripMenuItem.Checked = false;
11680 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11682 // int sidx = StatusText.SelectionStart;
11683 // string hash = HashMgr.UseHash + " ";
11686 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11687 // hash = " " + hash;
11689 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11690 // sidx += hash.Length;
11691 // StatusText.SelectionStart = sidx;
11692 // StatusText.Focus();
11694 _modifySettingCommon = true;
11695 this.StatusText_TextChanged(null, null);
11698 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11700 HashMgr.ToggleHash();
11701 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11703 HashStripSplitButton.Text = HashMgr.UseHash;
11704 HashToggleMenuItem.Checked = true;
11705 HashToggleToolStripMenuItem.Checked = true;
11709 HashStripSplitButton.Text = "#[-]";
11710 HashToggleMenuItem.Checked = false;
11711 HashToggleToolStripMenuItem.Checked = false;
11713 _modifySettingCommon = true;
11714 this.StatusText_TextChanged(null, null);
11717 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11719 HashToggleMenuItem_Click(null, null);
11722 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11724 if (ListTab.SelectedTab == null) return;
11725 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11726 if (!this.ExistCurrentPost)
11728 this.ReplyOpMenuItem.Enabled = false;
11729 this.ReplyAllOpMenuItem.Enabled = false;
11730 this.DmOpMenuItem.Enabled = false;
11731 this.ShowProfMenuItem.Enabled = false;
11732 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11733 this.ListManageMenuItem.Enabled = false;
11734 this.OpenFavOpMenuItem.Enabled = false;
11735 this.CreateTabRuleOpMenuItem.Enabled = false;
11736 this.CreateIdRuleOpMenuItem.Enabled = false;
11737 this.ReadOpMenuItem.Enabled = false;
11738 this.UnreadOpMenuItem.Enabled = false;
11742 this.ReplyOpMenuItem.Enabled = true;
11743 this.ReplyAllOpMenuItem.Enabled = true;
11744 this.DmOpMenuItem.Enabled = true;
11745 this.ShowProfMenuItem.Enabled = true;
11746 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11747 this.ListManageMenuItem.Enabled = true;
11748 this.OpenFavOpMenuItem.Enabled = true;
11749 this.CreateTabRuleOpMenuItem.Enabled = true;
11750 this.CreateIdRuleOpMenuItem.Enabled = true;
11751 this.ReadOpMenuItem.Enabled = true;
11752 this.UnreadOpMenuItem.Enabled = true;
11755 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11757 this.FavOpMenuItem.Enabled = false;
11758 this.UnFavOpMenuItem.Enabled = false;
11759 this.OpenStatusOpMenuItem.Enabled = false;
11760 this.OpenFavotterOpMenuItem.Enabled = false;
11761 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11762 this.RtOpMenuItem.Enabled = false;
11763 this.RtUnOpMenuItem.Enabled = false;
11764 this.QtOpMenuItem.Enabled = false;
11765 this.FavoriteRetweetMenuItem.Enabled = false;
11766 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11767 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11771 this.FavOpMenuItem.Enabled = true;
11772 this.UnFavOpMenuItem.Enabled = true;
11773 this.OpenStatusOpMenuItem.Enabled = true;
11774 this.OpenFavotterOpMenuItem.Enabled = true;
11775 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11779 this.RtOpMenuItem.Enabled = false;
11780 this.FavoriteRetweetMenuItem.Enabled = false;
11781 this.DelOpMenuItem.Enabled = true;
11785 this.DelOpMenuItem.Enabled = false;
11786 if (_curPost.IsProtect)
11788 this.RtOpMenuItem.Enabled = false;
11789 this.RtUnOpMenuItem.Enabled = false;
11790 this.QtOpMenuItem.Enabled = false;
11791 this.FavoriteRetweetMenuItem.Enabled = false;
11792 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11796 this.RtOpMenuItem.Enabled = true;
11797 this.RtUnOpMenuItem.Enabled = true;
11798 this.QtOpMenuItem.Enabled = true;
11799 this.FavoriteRetweetMenuItem.Enabled = true;
11800 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
11805 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
11807 this.RefreshPrevOpMenuItem.Enabled = true;
11811 this.RefreshPrevOpMenuItem.Enabled = false;
11813 if (!this.ExistCurrentPost
11814 || _curPost.InReplyToStatusId == null)
11816 OpenRepSourceOpMenuItem.Enabled = false;
11820 OpenRepSourceOpMenuItem.Enabled = true;
11822 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
11824 OpenRterHomeMenuItem.Enabled = false;
11828 OpenRterHomeMenuItem.Enabled = true;
11832 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
11834 ContextMenuTabProperty_Opening(sender, null);
11837 public Twitter TwitterInstance
11842 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
11844 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
11846 _mySpDis3 = SplitContainer3.SplitterDistance;
11847 _modifySettingLocal = true;
11851 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
11853 if (_statuses.RemovedTab.Count == 0)
11855 UndoRemoveTabMenuItem.Enabled = false;
11859 UndoRemoveTabMenuItem.Enabled = true;
11861 if (ListTab.SelectedTab != null)
11863 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
11864 PublicSearchQueryMenuItem.Enabled = true;
11866 PublicSearchQueryMenuItem.Enabled = false;
11870 PublicSearchQueryMenuItem.Enabled = false;
11872 if (!this.ExistCurrentPost)
11874 this.CopySTOTMenuItem.Enabled = false;
11875 this.CopyURLMenuItem.Enabled = false;
11876 this.CopyUserIdStripMenuItem.Enabled = false;
11880 this.CopySTOTMenuItem.Enabled = true;
11881 this.CopyURLMenuItem.Enabled = true;
11882 this.CopyUserIdStripMenuItem.Enabled = true;
11883 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
11884 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
11888 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
11890 SetNotifyIconText();
11893 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
11896 if (_curPost != null)
11898 id = _curPost.ScreenName;
11900 ShowUserStatus(id);
11903 private class GetUserInfoArgs
11907 public TwitterUser user;
11910 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
11912 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
11913 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
11916 private void doShowUserStatus(string id, bool ShowInputDialog)
11918 TwitterUser user = null;
11919 GetUserInfoArgs args = new GetUserInfoArgs();
11920 if (ShowInputDialog)
11922 using (InputTabName inputName = new InputTabName())
11924 inputName.FormTitle = "Show UserStatus";
11925 inputName.FormDescription = Properties.Resources.FRMessage1;
11926 inputName.TabName = id;
11927 if (inputName.ShowDialog() == DialogResult.OK &&
11928 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11930 id = inputName.TabName.Trim();
11934 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
11935 GetUserInfo_DoWork,
11939 _info.ShowDialog();
11940 string ret = (string)_info.Result;
11941 if (string.IsNullOrEmpty(ret))
11942 doShowUserStatus(args.user);
11944 MessageBox.Show(ret);
11954 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
11955 GetUserInfo_DoWork,
11959 _info.ShowDialog();
11960 string ret = (string)_info.Result;
11961 if (string.IsNullOrEmpty(ret))
11963 doShowUserStatus(args.user);
11967 MessageBox.Show(ret);
11973 private async void doShowUserStatus(TwitterUser user)
11975 using (var userDialog = new UserInfoDialog(this, this.tw))
11977 var showUserTask = userDialog.ShowUserAsync(user);
11978 userDialog.ShowDialog(this);
11981 this.BringToFront();
11983 // ユーザー情報の表示が完了するまで userDialog を破棄しない
11984 await showUserTask;
11988 private void ShowUserStatus(string id, bool ShowInputDialog)
11990 doShowUserStatus(id, ShowInputDialog);
11993 private void ShowUserStatus(string id)
11995 doShowUserStatus(id, true);
11998 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12000 if (NameLabel.Tag != null)
12002 string id = (string)NameLabel.Tag;
12003 if (id != tw.Username)
12010 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12012 if (NameLabel.Tag != null)
12014 string id = (string)NameLabel.Tag;
12015 if (id != tw.Username)
12017 RemoveCommand(id, false);
12022 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12024 if (NameLabel.Tag != null)
12026 string id = (string)NameLabel.Tag;
12027 if (id != tw.Username)
12029 ShowFriendship(id);
12034 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12036 if (NameLabel.Tag != null)
12038 string id = (string)NameLabel.Tag;
12039 ShowUserStatus(id, false);
12043 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12045 if (NameLabel.Tag != null)
12047 string id = (string)NameLabel.Tag;
12048 AddNewTabForUserTimeline(id);
12052 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12054 if (NameLabel.Tag != null)
12056 string id = (string)NameLabel.Tag;
12057 AddNewTabForSearch("@" + id);
12061 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12063 if (_curPost != null)
12065 ShowUserStatus(_curPost.ScreenName, false);
12069 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12074 if (_curPost.RetweetedId != null)
12076 statusid = _curPost.RetweetedId.Value;
12080 statusid = _curPost.StatusId;
12082 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12084 e.Result = counter;
12087 private void RtCountMenuItem_Click(object sender, EventArgs e)
12089 if (this.ExistCurrentPost)
12091 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12092 GetRetweet_DoWork))
12094 int retweet_count = 0;
12097 _info.ShowDialog();
12098 retweet_count = (int)_info.Result;
12099 if (retweet_count < 0)
12101 MessageBox.Show(Properties.Resources.RtCountText2);
12105 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12111 private HookGlobalHotkey _hookGlobalHotkey;
12114 _hookGlobalHotkey = new HookGlobalHotkey(this);
12116 // この呼び出しは、Windows フォーム デザイナで必要です。
12117 InitializeComponent();
12119 // InitializeComponent() 呼び出しの後で初期化を追加します。
12121 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12122 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12123 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12124 this.gh.NotifyClicked += GrowlHelper_Callback;
12126 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12127 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
12129 this._apiGauge = new ToolStripAPIGauge();
12130 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12131 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12133 this.ImageSelector.Visible = false;
12134 this.ImageSelector.Enabled = false;
12135 this.ImageSelector.FilePickDialog = OpenFileDialog1;
12137 this.ReplaceAppName();
12140 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12142 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12145 this.Visible = false;
12147 else if (Form.ActiveForm == null)
12149 this.Visible = true;
12150 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12152 this.BringToFront();
12153 this.StatusText.Focus();
12157 private void UserPicture_MouseEnter(object sender, EventArgs e)
12159 this.UserPicture.Cursor = Cursors.Hand;
12162 private void UserPicture_MouseLeave(object sender, EventArgs e)
12164 this.UserPicture.Cursor = Cursors.Default;
12167 private void UserPicture_DoubleClick(object sender, EventArgs e)
12169 if (NameLabel.Tag != null)
12171 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12175 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12177 this.MultiLineMenuItem.PerformClick();
12180 public PostClass CurPost
12182 get { return _curPost; }
12186 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12188 if (ImageSelector.Visible)
12189 ImageSelector.EndSelection();
12191 ImageSelector.BeginSelection();
12194 private void SelectMedia_DragEnter(DragEventArgs e)
12196 if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0], true))
12198 e.Effect = DragDropEffects.Copy;
12201 e.Effect = DragDropEffects.None;
12204 private void SelectMedia_DragOver(DragEventArgs e)
12209 private void SelectMedia_DragDrop(DragEventArgs e)
12212 this.BringToFront();
12213 ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
12214 StatusText.Focus();
12217 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
12219 TimelinePanel.Visible = false;
12220 TimelinePanel.Enabled = false;
12223 private void ImageSelector_EndSelecting(object sender, EventArgs e)
12225 TimelinePanel.Visible = true;
12226 TimelinePanel.Enabled = true;
12227 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12230 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
12232 this.AllowDrop = false;
12235 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
12237 this.AllowDrop = true;
12240 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
12242 if (ImageSelector.Visible)
12244 _modifySettingCommon = true;
12245 SaveConfigsAll(true);
12247 if (ImageSelector.ServiceName.Equals("Twitter"))
12248 this.StatusText_TextChanged(null, null);
12252 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
12254 this.StatusText_TextChanged(null, null);
12258 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12260 using (ListManage form = new ListManage(tw))
12262 form.ShowDialog(this);
12266 public bool ModifySettingCommon
12268 set { _modifySettingCommon = value; }
12271 public bool ModifySettingLocal
12273 set { _modifySettingLocal = value; }
12276 public bool ModifySettingAtId
12278 set { _modifySettingAtId = value; }
12281 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12283 string link = (string)SourceLinkLabel.Tag;
12284 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12286 OpenUriAsync(link);
12290 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12292 string link = (string)SourceLinkLabel.Tag;
12293 if (!string.IsNullOrEmpty(link))
12295 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12299 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12301 SetStatusLabelUrl();
12304 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12306 if (this.ExistCurrentPost && !_curPost.IsDm)
12307 RtCountMenuItem.Enabled = true;
12309 RtCountMenuItem.Enabled = false;
12311 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12312 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12314 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12317 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12322 private void CopyUserId()
12324 if (_curPost == null) return;
12325 string clstr = _curPost.ScreenName;
12328 Clipboard.SetDataObject(clstr, false, 5, 100);
12330 catch (Exception ex)
12332 MessageBox.Show(ex.Message);
12336 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12338 if (this.ExistCurrentPost && !_curPost.IsDm)
12342 this.OpenRelatedTab(this._curPost);
12344 catch (TabException ex)
12346 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12352 /// 指定されたツイートに対する関連発言タブを開きます
12354 /// <param name="post">表示する対象となるツイート</param>
12355 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12356 private void OpenRelatedTab(PostClass post)
12358 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12361 if (tabRelated == null)
12363 tabName = this._statuses.MakeTabName("Related Tweets");
12365 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12366 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12368 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12369 tabRelated.UnreadManage = false;
12370 tabRelated.Notify = false;
12374 tabName = tabRelated.TabName;
12377 tabRelated.RelationTargetPost = post;
12378 this.ClearTab(tabName, false);
12380 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12382 var tabPage = this.ListTab.TabPages[i];
12383 if (tabName == tabPage.Text)
12385 this.ListTab.SelectedIndex = i;
12386 this.ListTabSelect(tabPage);
12391 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, tabName);
12394 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12396 StringBuilder buf = new StringBuilder();
12397 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12398 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12399 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12400 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12401 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12404 private void tw_UserIdChanged()
12406 this._modifySettingCommon = true;
12409 #region "Userstream"
12410 private bool _isActiveUserstream = false;
12412 private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
12416 if (InvokeRequired && !IsDisposed)
12418 Invoke((Action) (() =>
12420 _statuses.RemovePostReserve(e.StatusId);
12421 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
12423 this.PurgeListViewItemCache();
12424 ((DetailsListView)_curTab.Tag).Update();
12425 if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
12431 catch (ObjectDisposedException)
12435 catch (InvalidOperationException)
12441 private void tw_NewPostFromStream(object sender, EventArgs e)
12443 if (this._cfgCommon.ReadOldPosts)
12445 _statuses.SetRead(); //新着時未読クリア
12448 int rsltAddCount = _statuses.DistributePosts();
12451 DateTime tm = DateTime.Now;
12452 if (_tlTimestamps.ContainsKey(tm))
12454 _tlTimestamps[tm] += rsltAddCount;
12458 _tlTimestamps.Add(tm, rsltAddCount);
12460 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12461 List<DateTime> keys = new List<DateTime>();
12463 foreach (DateTime key in _tlTimestamps.Keys)
12465 if (key.CompareTo(oneHour) < 0)
12468 _tlCount += _tlTimestamps[key];
12470 foreach (DateTime key in keys)
12472 _tlTimestamps.Remove(key);
12476 //Static DateTime before = Now;
12477 //if (before.Subtract(Now).Seconds > -5) return;
12481 if (this._cfgCommon.UserstreamPeriod > 0) return;
12485 if (InvokeRequired && !IsDisposed)
12487 Invoke(new Action<bool>(RefreshTimeline), true);
12491 catch (ObjectDisposedException)
12495 catch (InvalidOperationException)
12501 private void tw_UserStreamStarted(object sender, EventArgs e)
12503 this._isActiveUserstream = true;
12506 if (InvokeRequired && !IsDisposed)
12508 Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
12512 catch (ObjectDisposedException)
12516 catch (InvalidOperationException)
12521 MenuItemUserStream.Text = "&UserStream ▶";
12522 MenuItemUserStream.Enabled = true;
12523 StopToolStripMenuItem.Text = "&Stop";
12524 StopToolStripMenuItem.Enabled = true;
12526 StatusLabel.Text = "UserStream Started.";
12529 private void tw_UserStreamStopped(object sender, EventArgs e)
12531 this._isActiveUserstream = false;
12534 if (InvokeRequired && !IsDisposed)
12536 Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
12540 catch (ObjectDisposedException)
12544 catch (InvalidOperationException)
12549 MenuItemUserStream.Text = "&UserStream ■";
12550 MenuItemUserStream.Enabled = true;
12551 StopToolStripMenuItem.Text = "&Start";
12552 StopToolStripMenuItem.Enabled = true;
12554 StatusLabel.Text = "UserStream Stopped.";
12557 private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
12561 if (InvokeRequired && !IsDisposed)
12563 Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
12567 catch (ObjectDisposedException)
12571 catch (InvalidOperationException)
12575 var ev = e.EventData;
12576 StatusLabel.Text = "Event: " + ev.Event;
12577 //if (ev.Event == "favorite")
12579 // NotifyFavorite(ev);
12582 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12584 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12586 this.PurgeListViewItemCache();
12587 ((DetailsListView)_curTab.Tag).Update();
12589 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12591 RemovePostFromFavTab(new long[] {ev.Id});
12596 private void NotifyEvent(Twitter.FormattedEvent ev)
12599 if (BalloonRequired(ev))
12601 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12602 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12603 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12604 StringBuilder title = new StringBuilder();
12605 if (this._cfgCommon.DispUsername)
12607 title.Append(tw.Username);
12608 title.Append(" - ");
12614 title.Append(Application.ProductName);
12615 title.Append(" [");
12616 title.Append(ev.Event.ToUpper());
12617 title.Append("] by ");
12618 if (!string.IsNullOrEmpty(ev.Username))
12620 title.Append(ev.Username.ToString());
12624 //title.Append("");
12627 if (!string.IsNullOrEmpty(ev.Target))
12629 //NotifyIcon1.BalloonTipText = ev.Target;
12634 //NotifyIcon1.BalloonTipText = " ";
12637 //NotifyIcon1.ShowBalloonTip(500);
12638 if (this._cfgCommon.IsUseNotifyGrowl)
12640 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
12641 ev.Id.ToString(), title.ToString(), text);
12645 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12646 NotifyIcon1.BalloonTipTitle = title.ToString();
12647 NotifyIcon1.BalloonTipText = text;
12648 NotifyIcon1.ShowBalloonTip(500);
12653 string snd = SettingDialog.EventSoundFile;
12654 if (!_initial && this._cfgCommon.PlaySound && !string.IsNullOrEmpty(snd))
12656 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
12660 string dir = Application.StartupPath;
12661 if (Directory.Exists(Path.Combine(dir, "Sounds")))
12663 dir = Path.Combine(dir, "Sounds");
12665 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
12677 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
12679 MenuItemUserStream.Enabled = false;
12680 if (StopRefreshAllMenuItem.Checked)
12682 StopRefreshAllMenuItem.Checked = false;
12685 if (this._isActiveUserstream)
12687 tw.StopUserStream();
12691 tw.StartUserStream();
12695 private static string inputTrack = "";
12697 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
12699 if (TrackToolStripMenuItem.Checked)
12701 using (InputTabName inputForm = new InputTabName())
12703 inputForm.TabName = inputTrack;
12704 inputForm.FormTitle = "Input track word";
12705 inputForm.FormDescription = "Track word";
12706 if (inputForm.ShowDialog() != DialogResult.OK)
12708 TrackToolStripMenuItem.Checked = false;
12711 inputTrack = inputForm.TabName.Trim();
12713 if (!inputTrack.Equals(tw.TrackWord))
12715 tw.TrackWord = inputTrack;
12716 this._modifySettingCommon = true;
12717 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
12718 tw.ReconnectUserStream();
12724 tw.ReconnectUserStream();
12726 this._modifySettingCommon = true;
12729 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
12731 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
12732 this._modifySettingCommon = true;
12733 tw.ReconnectUserStream();
12736 private void EventViewerMenuItem_Click(object sender, EventArgs e)
12738 if (evtDialog == null || evtDialog.IsDisposed)
12741 evtDialog = new EventViewerDialog();
12742 evtDialog.Owner = this;
12744 Point pos = evtDialog.Location;
12745 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
12746 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
12747 evtDialog.Location = pos;
12749 evtDialog.EventSource = tw.StoredEvent;
12750 if (!evtDialog.Visible)
12752 evtDialog.Show(this);
12756 evtDialog.Activate();
12758 this.TopMost = this._cfgCommon.AlwaysTop;
12762 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
12764 MyCommon._endingFlag = true;
12768 Application.Restart();
12772 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
12776 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
12778 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
12781 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
12783 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
12786 private async Task doTranslation(string str)
12788 if (string.IsNullOrEmpty(str))
12791 var bing = new Bing();
12794 var translatedText = await bing.TranslateAsync(str,
12796 langTo: this.SettingDialog.TranslateLanguage);
12798 this.PostBrowser.DocumentText = this.createDetailHtml(translatedText);
12800 catch (HttpRequestException e)
12802 this.StatusLabel.Text = "Err:" + e.Message;
12806 private async void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
12808 if (!this.ExistCurrentPost)
12811 await this.doTranslation(this._curPost.TextFromApi);
12814 private async void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
12816 var text = this.WebBrowser_GetSelectionText(ref this.PostBrowser);
12817 await this.doTranslation(text);
12820 private bool ExistCurrentPost
12824 if (_curPost == null) return false;
12825 if (_curPost.IsDeleted) return false;
12830 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
12832 ShowUserTimeline();
12835 public bool FavEventChangeUnread
12837 get { return SettingDialog.FavEventUnread; }
12840 private string GetUserIdFromCurPostOrInput(string caption)
12843 if (_curPost != null)
12845 id = _curPost.ScreenName;
12847 using (InputTabName inputName = new InputTabName())
12849 inputName.FormTitle = caption;
12850 inputName.FormDescription = Properties.Resources.FRMessage1;
12851 inputName.TabName = id;
12852 if (inputName.ShowDialog() == DialogResult.OK &&
12853 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12855 id = inputName.TabName.Trim();
12865 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
12867 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
12868 if (!string.IsNullOrEmpty(id))
12870 AddNewTabForUserTimeline(id);
12874 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
12876 string id = GetUserIdFromCurPostOrInput("Show Favstar");
12877 if (!string.IsNullOrEmpty(id))
12879 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
12883 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
12885 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
12888 private void TimelineRefreshEnableChange(bool isEnable)
12892 tw.StartUserStream();
12896 tw.StopUserStream();
12898 TimerTimeline.Enabled = isEnable;
12901 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
12903 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
12906 private void OpenUserAppointUrl()
12908 if (SettingDialog.UserAppointUrl != null)
12910 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
12912 if (_curPost != null)
12914 string xUrl = SettingDialog.UserAppointUrl;
12915 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
12916 if (_curPost.RetweetedId != null)
12918 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
12922 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
12924 OpenUriAsync(xUrl);
12929 OpenUriAsync(SettingDialog.UserAppointUrl);
12934 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
12936 OpenUserAppointUrl();
12939 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
12941 string selText = SourceLinkLabel.Text;
12944 Clipboard.SetDataObject(selText, false, 5, 100);
12946 catch (Exception ex)
12948 MessageBox.Show(ex.Message);
12952 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
12954 string selText = (string)SourceLinkLabel.Tag;
12957 Clipboard.SetDataObject(selText, false, 5, 100);
12959 catch (Exception ex)
12961 MessageBox.Show(ex.Message);
12965 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
12967 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
12969 SourceCopyMenuItem.Enabled = false;
12970 SourceUrlCopyMenuItem.Enabled = false;
12974 SourceCopyMenuItem.Enabled = true;
12975 SourceUrlCopyMenuItem.Enabled = true;
12979 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
12981 if (Form.ActiveForm == null)
12983 this.BeginInvoke((Action) (() =>
12985 this.Visible = true;
12986 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12988 this.BringToFront();
12989 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
12991 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
12995 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13001 private void ReplaceAppName()
13003 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13004 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13007 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13009 this.SplitContainer3.Panel2Collapsed = false;
13011 // PreviewDistance が起動のたびに広がっていく問題の回避策
13012 // FixedPanel が Panel2 に設定された状態で Panel2 を開くと、初回だけ SplitterDistance が再計算されておかしくなるため、
13013 // None で開いた後に設定するようにする
13014 if (this.SplitContainer3.FixedPanel == FixedPanel.None)
13015 this.SplitContainer3.FixedPanel = FixedPanel.Panel2;
13018 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13020 this.OpenThumbnailPicture(e.Thumbnail);
13023 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13025 this.OpenUriAsync(e.ImageUrl);
13028 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13030 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13033 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13035 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13038 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13040 if (e.KeyCode == Keys.Space)
13042 this.JumpUnreadMenuItem_Click(null, null);
13044 e.SuppressKeyPress = true;
13048 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
13050 this.IconSizeNoneToolStripMenuItem.Checked = this._cfgCommon.IconSize == MyCommon.IconSizes.IconNone;
13051 this.IconSize16ToolStripMenuItem.Checked = this._cfgCommon.IconSize == MyCommon.IconSizes.Icon16;
13052 this.IconSize24ToolStripMenuItem.Checked = this._cfgCommon.IconSize == MyCommon.IconSizes.Icon24;
13053 this.IconSize48ToolStripMenuItem.Checked = this._cfgCommon.IconSize == MyCommon.IconSizes.Icon48;
13054 this.IconSize48_2ToolStripMenuItem.Checked = this._cfgCommon.IconSize == MyCommon.IconSizes.Icon48_2;
13056 this.LockListSortOrderToolStripMenuItem.Checked = this._cfgCommon.SortOrderLock;
13059 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
13061 ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
13064 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
13066 ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
13069 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
13071 ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
13074 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
13076 ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
13079 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
13081 ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
13084 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
13086 if (this._cfgCommon.IconSize == iconSize) return;
13088 var oldIconCol = _iconCol;
13090 this._cfgCommon.IconSize = iconSize;
13091 ApplyListViewIconSize(iconSize);
13093 if (_iconCol != oldIconCol)
13095 foreach (TabPage tp in ListTab.TabPages)
13097 ResetColumns((DetailsListView)tp.Tag);
13101 if (_curList != null) _curList.Refresh();
13103 _modifySettingCommon = true;
13106 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
13108 var state = this.LockListSortOrderToolStripMenuItem.Checked;
13109 if (this._cfgCommon.SortOrderLock == state) return;
13111 this._cfgCommon.SortOrderLock = state;
13113 _modifySettingCommon = true;