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.Reflection;
42 using System.Text.RegularExpressions;
43 using System.Threading;
44 using System.Threading.Tasks;
45 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 _myAdSpDis; //Ad区切り位置
63 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
64 private bool _iconCol; //1列表示の時true(48サイズのとき)
67 private bool _initial; //true:起動時処理中
68 private bool _initialLayout = true;
69 private bool _ignoreConfigSave; //true:起動時処理中
70 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
71 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
72 private Point _tabMouseDownPoint;
73 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
74 private readonly object _syncObject = new object(); //ロック用
75 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
76 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
77 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
78 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
79 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
80 private const string detailHtmlFormatMono6 = ");\"><pre>";
81 private const string detailHtmlFormatMono7 = "</pre></body></html>";
82 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
83 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
84 private const string detailHtmlFormat7 = "</span></p></body></html>";
85 private string detailHtmlFormatHeader;
86 private string detailHtmlFormatFooter;
87 private bool _myStatusError = false;
88 private bool _myStatusOnline = false;
89 private bool soundfileListup = false;
90 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
93 //private SettingToConfig _cfg; //旧
94 private SettingLocal _cfgLocal;
95 private SettingCommon _cfgCommon;
96 private bool _modifySettingLocal = false;
97 private bool _modifySettingCommon = false;
98 private bool _modifySettingAtId = false;
101 private Twitter tw = new Twitter();
104 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
107 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
108 private SearchWord SearchDialog = new SearchWord(); //検索画面インスタンス
109 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
110 private OpenURL UrlDialog = new OpenURL();
111 public AtIdSupplement AtIdSupl; //@id補助
112 public AtIdSupplement HashSupl; //Hashtag補助
113 public HashtagManage HashMgr;
114 private EventViewerDialog evtDialog;
117 private Font _fntUnread; //未読用フォント
118 private Color _clUnread; //未読用文字色
119 private Font _fntReaded; //既読用フォント
120 private Color _clReaded; //既読用文字色
121 private Color _clFav; //Fav用文字色
122 private Color _clOWL; //片思い用文字色
123 private Color _clRetweet; //Retweet用文字色
124 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
125 private Font _fntDetail; //発言詳細部用フォント
126 private Color _clDetail; //発言詳細部用色
127 private Color _clDetailLink; //発言詳細部用リンク文字色
128 private Color _clDetailBackcolor; //発言詳細部用背景色
129 private Color _clSelf; //自分の発言用背景色
130 private Color _clAtSelf; //自分宛返信用背景色
131 private Color _clTarget; //選択発言者の他の発言用背景色
132 private Color _clAtTarget; //選択発言中の返信先用背景色
133 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
134 private Color _clAtTo; //選択発言の唯一@先
135 private Color _clListBackcolor; //リスト部通常発言背景色
136 private Color _clInputBackcolor; //入力欄背景色
137 private Color _clInputFont; //入力欄文字色
138 private Font _fntInputFont; //入力欄フォント
139 private ImageCache IconCache; //アイコン画像リスト
140 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
141 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
142 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
143 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
144 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
145 private Icon MainIcon; //Main.ico 画面左上のアイコン
146 private Icon ReplyIcon; //5g
147 private Icon ReplyIconBlink; //6g
149 private PostClass _anchorPost;
150 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
152 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
153 private int _hisIdx; //発言履歴カレントインデックス
155 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
156 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
157 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
160 private List<DateTime> _postTimestamps = new List<DateTime>();
161 private List<DateTime> _favTimestamps = new List<DateTime>();
162 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
163 private int _tlCount;
166 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
167 private SolidBrush _brsBackColorMine;
168 private SolidBrush _brsBackColorAt;
169 private SolidBrush _brsBackColorYou;
170 private SolidBrush _brsBackColorAtYou;
171 private SolidBrush _brsBackColorAtFromTarget;
172 private SolidBrush _brsBackColorAtTo;
173 private SolidBrush _brsBackColorNone;
174 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
175 private StringFormat sfTab = new StringFormat();
177 //////////////////////////////////////////////////////////////////////////////////////////////////////////
178 private ToolStripAPIGauge _apiGauge;
179 private TabInformations _statuses;
181 // ListViewItem のキャッシュ関連
182 private int _itemCacheIndex;
183 private ListViewItem[] _itemCache;
184 private PostClass[] _postCache;
185 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
187 private TabPage _curTab;
188 private int _curItemIndex;
189 private DetailsListView _curList;
190 private PostClass _curPost;
191 private bool _isColumnChanged = false;
192 private bool _waitTimeline = false;
193 private bool _waitReply = false;
194 private bool _waitDm = false;
195 private bool _waitFav = false;
196 private bool _waitPubSearch = false;
197 private bool _waitUserTimeline = false;
198 private bool _waitLists = false;
199 private BackgroundWorker[] _bw = new BackgroundWorker[20];
200 private BackgroundWorker _bwFollower;
201 private InternetSecurityManager SecurityManager;
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;
211 private Dictionary<string, IMultimediaShareService> pictureService;
213 //////////////////////////////////////////////////////////////////////////////////////////////////////////
214 private string _postBrowserStatusText = "";
216 private bool _colorize = false;
218 private System.Timers.Timer TimerTimeline = new System.Timers.Timer();
220 private ImageListViewItem displayItem;
223 /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
225 protected SizeF currentScaleFactor = new SizeF();
228 private struct urlUndo
230 public string Before;
234 private List<urlUndo> urlUndoBuffer = null;
236 private struct ReplyChain
238 public long OriginalId;
239 public long InReplyToId;
240 public TabPage OriginalTab;
242 public ReplyChain(long originalId, long inReplyToId, TabPage originalTab)
244 this.OriginalId = originalId;
245 this.InReplyToId = inReplyToId;
246 this.OriginalTab = originalTab;
250 private Stack<ReplyChain> replyChains; //[, ]でのリプライ移動の履歴
251 private Stack<Tuple<TabPage, PostClass>> selectPostChains = new Stack<Tuple<TabPage, PostClass>>(); //ポスト選択履歴
253 //Backgroundworkerの処理結果通知用引数構造体
254 private class GetWorkerResult
256 public string retMsg = ""; //処理結果詳細メッセージ。エラー時に値がセットされる
257 public int page; //取得対象ページ番号
258 public int endPage = 0; //取得終了ページ番号(継続可能ならインクリメントされて返る。pageと比較して継続判定)
259 public MyCommon.WORKERTYPE type; //処理種別
260 public Dictionary<string, Image> imgs = null; //新規取得したアイコンイメージ
261 public string tName = ""; //Fav追加・削除時のタブ名
262 public List<long> ids = null; //Fav追加・削除時のID
263 public List<long> sIds = null; //Fav追加・削除成功分のID
264 public bool newDM = false;
266 public PostingStatus status;
269 //Backgroundworkerへ処理内容を通知するための引数用構造体
270 private class GetWorkerArg
272 public int page; //処理対象ページ番号
273 public int endPage; //処理終了ページ番号(起動時の読み込みページ数。通常時はpageと同じ値をセット)
274 public MyCommon.WORKERTYPE type; //処理種別
275 public string url = ""; //URLをブラウザで開くときのアドレス
276 public PostingStatus status = new PostingStatus(); //発言POST時の発言内容
277 public List<long> ids; //Fav追加・削除時のItemIndex
278 public List<long> sIds; //Fav追加・削除成功分のItemIndex
279 public string tName = ""; //Fav追加・削除時のタブ名
283 private enum SEARCHTYPE
290 private class PostingStatus
292 public string status = "";
293 public long? inReplyToId = null;
294 public string inReplyToName = null;
295 public string imageService = ""; //画像投稿サービス名
296 public string imagePath = "";
297 public PostingStatus()
300 public PostingStatus(string status, long? replyToId, string replyToName)
302 this.status = status;
303 this.inReplyToId = replyToId;
304 this.inReplyToName = replyToName;
308 private void TweenMain_Activated(object sender, EventArgs e)
310 //画面がアクティブになったら、発言欄の背景色戻す
311 if (StatusText.Focused)
313 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
317 private void TweenMain_Disposed(object sender, EventArgs e)
320 SettingDialog.Dispose();
321 SearchDialog.Dispose();
324 if (NIconAt != null) NIconAt.Dispose();
325 if (NIconAtRed != null) NIconAtRed.Dispose();
326 if (NIconAtSmoke != null) NIconAtSmoke.Dispose();
327 if (NIconRefresh[0] != null) NIconRefresh[0].Dispose();
328 if (NIconRefresh[1] != null) NIconRefresh[1].Dispose();
329 if (NIconRefresh[2] != null) NIconRefresh[2].Dispose();
330 if (NIconRefresh[3] != null) NIconRefresh[3].Dispose();
331 if (TabIcon != null) TabIcon.Dispose();
332 if (MainIcon != null) MainIcon.Dispose();
333 if (ReplyIcon != null) ReplyIcon.Dispose();
334 if (ReplyIconBlink != null) ReplyIconBlink.Dispose();
335 _brsHighLight.Dispose();
336 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
337 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
338 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
339 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
340 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
341 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
342 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
343 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
346 foreach (BackgroundWorker bw in _bw)
351 if (_bwFollower != null)
353 _bwFollower.Dispose();
355 this._apiGauge.Dispose();
356 if (IconCache != null)
358 this.IconCache.CancelAsync();
359 this.IconCache.Dispose();
361 // 終了時にRemoveHandlerしておかないとメモリリークする
362 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
363 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
366 private void LoadIcon(ref Icon IconInstance, string FileName)
368 string dir = Application.StartupPath;
369 if (File.Exists(Path.Combine(dir, FileName)))
373 IconInstance = new Icon(Path.Combine(dir, FileName));
381 private void LoadIcons()
385 string dir = Application.StartupPath;
387 NIconAt = Properties.Resources.At;
388 NIconAtRed = Properties.Resources.AtRed;
389 NIconAtSmoke = Properties.Resources.AtSmoke;
390 NIconRefresh[0] = Properties.Resources.Refresh;
391 NIconRefresh[1] = Properties.Resources.Refresh2;
392 NIconRefresh[2] = Properties.Resources.Refresh3;
393 NIconRefresh[3] = Properties.Resources.Refresh4;
394 TabIcon = Properties.Resources.TabIcon;
395 MainIcon = Properties.Resources.MIcon;
396 ReplyIcon = Properties.Resources.Reply;
397 ReplyIconBlink = Properties.Resources.ReplyBlink;
399 if (!Directory.Exists(Path.Combine(dir, "Icons")))
402 LoadIcon(ref NIconAt, "Icons\\At.ico");
405 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
408 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
411 //アニメーション対応により4種類読み込み
412 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
413 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
414 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
415 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
418 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
421 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
424 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
427 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
430 private void InitColumns(ListView list, bool startup)
432 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
433 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
434 ColumnHeader _colHd3 = new ColumnHeader(); //本文
435 ColumnHeader _colHd4 = new ColumnHeader(); //日付
436 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
437 ColumnHeader _colHd6 = new ColumnHeader(); //未読
438 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
439 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
443 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
447 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
451 _colHd1.Text = ColumnText[0];
453 _colHd2.Text = ColumnText[1];
455 _colHd3.Text = ColumnText[2];
457 _colHd4.Text = ColumnText[3];
459 _colHd5.Text = ColumnText[4];
461 _colHd6.Text = ColumnText[5];
463 _colHd7.Text = ColumnText[6];
465 _colHd8.Text = ColumnText[7];
468 int[] dispOrder = new int[8];
471 for (int i = 0; i < _curList.Columns.Count; i++)
473 for (int j = 0; j < _curList.Columns.Count; j++)
475 if (_curList.Columns[j].DisplayIndex == i)
482 for (int i = 0; i < _curList.Columns.Count; i++)
484 list.Columns[i].Width = _curList.Columns[i].Width;
485 list.Columns[dispOrder[i]].DisplayIndex = i;
492 list.Columns[0].Width = _cfgLocal.Width1;
493 list.Columns[1].Width = _cfgLocal.Width3;
494 list.Columns[0].DisplayIndex = 0;
495 list.Columns[1].DisplayIndex = 1;
499 for (int i = 0; i <= 7; i++)
501 if (_cfgLocal.DisplayIndex1 == i)
503 else if (_cfgLocal.DisplayIndex2 == i)
505 else if (_cfgLocal.DisplayIndex3 == i)
507 else if (_cfgLocal.DisplayIndex4 == i)
509 else if (_cfgLocal.DisplayIndex5 == i)
511 else if (_cfgLocal.DisplayIndex6 == i)
513 else if (_cfgLocal.DisplayIndex7 == i)
515 else if (_cfgLocal.DisplayIndex8 == i)
518 list.Columns[0].Width = _cfgLocal.Width1;
519 list.Columns[1].Width = _cfgLocal.Width2;
520 list.Columns[2].Width = _cfgLocal.Width3;
521 list.Columns[3].Width = _cfgLocal.Width4;
522 list.Columns[4].Width = _cfgLocal.Width5;
523 list.Columns[5].Width = _cfgLocal.Width6;
524 list.Columns[6].Width = _cfgLocal.Width7;
525 list.Columns[7].Width = _cfgLocal.Width8;
526 for (int i = 0; i <= 7; i++)
528 list.Columns[dispOrder[i]].DisplayIndex = i;
534 private void InitColumnText()
537 ColumnText[1] = Properties.Resources.AddNewTabText2;
538 ColumnText[2] = Properties.Resources.AddNewTabText3;
539 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
540 ColumnText[4] = Properties.Resources.AddNewTabText5;
543 ColumnText[7] = "Source";
545 ColumnOrgText[0] = "";
546 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
547 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
548 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
549 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
550 ColumnOrgText[5] = "";
551 ColumnOrgText[6] = "";
552 ColumnOrgText[7] = "Source";
555 switch (_statuses.SortMode)
557 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
560 case IdComparerClass.ComparerMode.Data: //本文
563 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
566 case IdComparerClass.ComparerMode.Name: //名前
569 case IdComparerClass.ComparerMode.Source: //Source
576 if (_statuses.SortOrder == SortOrder.Descending)
578 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
579 ColumnText[2] = ColumnOrgText[2] + "▾";
583 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
584 ColumnText[2] = ColumnOrgText[2] + "▴";
589 if (_statuses.SortOrder == SortOrder.Descending)
591 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
592 ColumnText[c] = ColumnOrgText[c] + "▾";
596 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
597 ColumnText[c] = ColumnOrgText[c] + "▴";
602 private void InitializeTraceFrag()
605 TraceOutToolStripMenuItem.Checked = true;
606 MyCommon.TraceFlag = true;
608 if (!MyCommon.fileVersion.EndsWith("0"))
610 TraceOutToolStripMenuItem.Checked = true;
611 MyCommon.TraceFlag = true;
615 private void TweenMain_Load(object sender, EventArgs e)
617 _ignoreConfigSave = true;
618 this.Visible = false;
620 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
622 SecurityManager = new InternetSecurityManager(PostBrowser);
623 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
625 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
626 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
628 if (MyApplication.StartupOptions.ContainsKey("d"))
629 MyCommon.TraceFlag = true;
631 Regex.CacheSize = 100;
633 MyCommon.fileVersion = ((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0]).Version;
634 InitializeTraceFrag();
635 LoadIcons(); // アイコン読み込み
637 ThumbnailGenerator.InitializeGenerator();
639 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
640 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
641 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
644 _statuses = TabInformations.GetInstance();
647 this.Icon = MainIcon; //メインフォーム(TweenMain)
648 NotifyIcon1.Icon = NIconAt; //タスクトレイ
649 TabImage.Images.Add(TabIcon); //タブ見出し
651 SettingDialog.Owner = this;;
652 SearchDialog.Owner = this;
653 fltDialog.Owner = this;
654 UrlDialog.Owner = this;
656 _history.Add(new PostingStatus());
659 _reply_to_name = null;
661 //<<<<<<<<<設定関連>>>>>>>>>
669 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
670 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
673 _fntUnread = _cfgLocal.FontUnread;
674 _clUnread = _cfgLocal.ColorUnread;
675 _fntReaded = _cfgLocal.FontRead;
676 _clReaded = _cfgLocal.ColorRead;
677 _clFav = _cfgLocal.ColorFav;
678 _clOWL = _cfgLocal.ColorOWL;
679 _clRetweet = _cfgLocal.ColorRetweet;
680 _fntDetail = _cfgLocal.FontDetail;
681 _clDetail = _cfgLocal.ColorDetail;
682 _clDetailLink = _cfgLocal.ColorDetailLink;
683 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
684 _clSelf = _cfgLocal.ColorSelf;
685 _clAtSelf = _cfgLocal.ColorAtSelf;
686 _clTarget = _cfgLocal.ColorTarget;
687 _clAtTarget = _cfgLocal.ColorAtTarget;
688 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
689 _clAtTo = _cfgLocal.ColorAtTo;
690 _clListBackcolor = _cfgLocal.ColorListBackcolor;
691 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
692 _clInputFont = _cfgLocal.ColorInputFont;
693 _fntInputFont = _cfgLocal.FontInputFont;
695 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
696 if (fontUIGlobal != null)
698 OTBaseForm.GlobalFont = fontUIGlobal;
699 this.Font = fontUIGlobal;
702 _brsBackColorMine = new SolidBrush(_clSelf);
703 _brsBackColorAt = new SolidBrush(_clAtSelf);
704 _brsBackColorYou = new SolidBrush(_clTarget);
705 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
706 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
707 _brsBackColorAtTo = new SolidBrush(_clAtTo);
708 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
709 _brsBackColorNone = new SolidBrush(_clListBackcolor);
711 // StringFormatオブジェクトへの事前設定
712 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
713 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
714 //sf.FormatFlags = StringFormatFlags.LineLimit; //
715 sfTab.Alignment = StringAlignment.Center;
716 sfTab.LineAlignment = StringAlignment.Center;
719 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
720 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
723 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
724 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
726 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
728 SettingDialog.TimelinePeriodInt = _cfgCommon.TimelinePeriod;
729 SettingDialog.ReplyPeriodInt = _cfgCommon.ReplyPeriod;
730 SettingDialog.DMPeriodInt = _cfgCommon.DMPeriod;
731 SettingDialog.PubSearchPeriodInt = _cfgCommon.PubSearchPeriod;
732 SettingDialog.UserTimelinePeriodInt = _cfgCommon.UserTimelinePeriod;
733 SettingDialog.ListsPeriodInt = _cfgCommon.ListsPeriod;
735 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
737 if (SettingDialog.TimelinePeriodInt < 15 && SettingDialog.TimelinePeriodInt > 0) SettingDialog.TimelinePeriodInt = 15;
738 if (SettingDialog.ReplyPeriodInt < 15 && SettingDialog.ReplyPeriodInt > 0) SettingDialog.ReplyPeriodInt = 15;
739 if (SettingDialog.DMPeriodInt < 15 && SettingDialog.DMPeriodInt > 0) SettingDialog.DMPeriodInt = 15;
740 if (SettingDialog.PubSearchPeriodInt < 30 && SettingDialog.PubSearchPeriodInt > 0) SettingDialog.PubSearchPeriodInt = 30;
741 if (SettingDialog.UserTimelinePeriodInt < 15 && SettingDialog.UserTimelinePeriodInt > 0) SettingDialog.UserTimelinePeriodInt = 15;
742 if (SettingDialog.ListsPeriodInt < 15 && SettingDialog.ListsPeriodInt > 0) SettingDialog.ListsPeriodInt = 15;
745 //起動時読み込み分を既読にするか。trueなら既読として処理
746 SettingDialog.Readed = _cfgCommon.Read;
747 //新着取得時のリストスクロールをするか。trueならスクロールしない
748 ListLockMenuItem.Checked = _cfgCommon.ListLock;
749 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
750 SettingDialog.IconSz = _cfgCommon.IconSize;
752 SettingDialog.Status = _cfgLocal.StatusText;
754 SettingDialog.UnreadManage = _cfgCommon.UnreadManage;
756 SettingDialog.PlaySound = _cfgCommon.PlaySound;
757 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
758 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
759 //片思い表示。trueなら片思い表示する
760 SettingDialog.OneWayLove = _cfgCommon.OneWayLove;
762 SettingDialog.FontUnread = _fntUnread;
763 SettingDialog.ColorUnread = _clUnread;
764 SettingDialog.FontReaded = _fntReaded;
765 SettingDialog.ColorReaded = _clReaded;
766 SettingDialog.ColorFav = _clFav;
767 SettingDialog.ColorOWL = _clOWL;
768 SettingDialog.ColorRetweet = _clRetweet;
769 SettingDialog.FontDetail = _fntDetail;
770 SettingDialog.ColorDetail = _clDetail;
771 SettingDialog.ColorDetailLink = _clDetailLink;
772 SettingDialog.ColorDetailBackcolor = _clDetailBackcolor;
773 SettingDialog.ColorSelf = _clSelf;
774 SettingDialog.ColorAtSelf = _clAtSelf;
775 SettingDialog.ColorTarget = _clTarget;
776 SettingDialog.ColorAtTarget = _clAtTarget;
777 SettingDialog.ColorAtFromTarget = _clAtFromTarget;
778 SettingDialog.ColorAtTo = _clAtTo;
779 SettingDialog.ColorListBackcolor = _clListBackcolor;
780 SettingDialog.ColorInputBackcolor = _clInputBackcolor;
781 SettingDialog.ColorInputFont = _clInputFont;
782 SettingDialog.FontInputFont = _fntInputFont;
784 SettingDialog.NameBalloon = _cfgCommon.NameBalloon;
785 SettingDialog.PostCtrlEnter = _cfgCommon.PostCtrlEnter;
786 SettingDialog.PostShiftEnter = _cfgCommon.PostShiftEnter;
788 SettingDialog.CountApi = _cfgCommon.CountApi;
789 SettingDialog.CountApiReply = _cfgCommon.CountApiReply;
790 if (SettingDialog.CountApi < 20 || SettingDialog.CountApi > 200) SettingDialog.CountApi = 60;
791 if (SettingDialog.CountApiReply < 20 || SettingDialog.CountApiReply > 200) SettingDialog.CountApiReply = 40;
793 SettingDialog.BrowserPath = _cfgLocal.BrowserPath;
794 SettingDialog.PostAndGet = _cfgCommon.PostAndGet;
795 SettingDialog.UseRecommendStatus = _cfgLocal.UseRecommendStatus;
796 SettingDialog.DispUsername = _cfgCommon.DispUsername;
797 SettingDialog.CloseToExit = _cfgCommon.CloseToExit;
798 SettingDialog.MinimizeToTray = _cfgCommon.MinimizeToTray;
799 SettingDialog.DispLatestPost = _cfgCommon.DispLatestPost;
800 SettingDialog.SortOrderLock = _cfgCommon.SortOrderLock;
801 SettingDialog.ViewTabBottom = _cfgCommon.ViewTabBottom;
802 SettingDialog.TinyUrlResolve = _cfgCommon.TinyUrlResolve;
804 SettingDialog.SelectedProxyType = _cfgLocal.ProxyType;
805 SettingDialog.ProxyAddress = _cfgLocal.ProxyAddress;
806 SettingDialog.ProxyPort = _cfgLocal.ProxyPort;
807 SettingDialog.ProxyUser = _cfgLocal.ProxyUser;
808 SettingDialog.ProxyPassword = _cfgLocal.ProxyPassword;
810 SettingDialog.StartupVersion = _cfgCommon.StartupVersion;
811 SettingDialog.StartupFollowers = _cfgCommon.StartupFollowers;
812 SettingDialog.RestrictFavCheck = _cfgCommon.RestrictFavCheck;
813 SettingDialog.AlwaysTop = _cfgCommon.AlwaysTop;
814 SettingDialog.UrlConvertAuto = false;
815 //SettingDialog.UrlConvertAuto = _cfgCommon.UrlConvertAuto;
817 SettingDialog.UseUnreadStyle = _cfgCommon.UseUnreadStyle;
818 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
819 SettingDialog.RetweetNoConfirm = _cfgCommon.RetweetNoConfirm;
820 SettingDialog.PlaySound = _cfgCommon.PlaySound;
821 SettingDialog.DateTimeFormat = _cfgCommon.DateTimeFormat;
822 SettingDialog.LimitBalloon = _cfgCommon.LimitBalloon;
823 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
824 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
825 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
826 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
827 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
828 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
829 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
831 //廃止サービスが選択されていた場合bit.lyへ読み替え
832 if (_cfgCommon.AutoShortUrlFirst < 0)
833 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
835 SettingDialog.AutoShortUrlFirst = _cfgCommon.AutoShortUrlFirst;
836 SettingDialog.TabIconDisp = _cfgCommon.TabIconDisp;
837 SettingDialog.ReplyIconState = _cfgCommon.ReplyIconState;
838 SettingDialog.ReadOwnPost = _cfgCommon.ReadOwnPost;
839 SettingDialog.GetFav = _cfgCommon.GetFav;
840 SettingDialog.ReadOldPosts = _cfgCommon.ReadOldPosts;
841 SettingDialog.BitlyUser = _cfgCommon.BilyUser;
842 SettingDialog.BitlyPwd = _cfgCommon.BitlyPwd;
843 SettingDialog.ShowGrid = _cfgCommon.ShowGrid;
844 SettingDialog.Language = _cfgCommon.Language;
845 SettingDialog.UseAtIdSupplement = _cfgCommon.UseAtIdSupplement;
846 SettingDialog.UseHashSupplement = _cfgCommon.UseHashSupplement;
847 SettingDialog.PreviewEnable = _cfgCommon.PreviewEnable;
848 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
850 SettingDialog.IsMonospace = _cfgCommon.IsMonospace;
851 if (SettingDialog.IsMonospace)
853 detailHtmlFormatHeader = detailHtmlFormatMono1;
854 detailHtmlFormatFooter = detailHtmlFormatMono7;
858 detailHtmlFormatHeader = detailHtmlFormat1;
859 detailHtmlFormatFooter = detailHtmlFormat7;
861 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();
862 if (SettingDialog.IsMonospace)
864 detailHtmlFormatHeader += detailHtmlFormatMono6;
868 detailHtmlFormatHeader += detailHtmlFormat6;
870 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
871 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
873 //Regex statregex = new Regex("^0*");
874 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.fileVersion.Replace(".", ""), "^0*", "") + "]";
879 if (DateTime.Now.ToString(SettingDialog.DateTimeFormat).Length == 0)
881 // このブロックは絶対に実行されないはず
882 // 変換が成功した場合にLengthが0にならない
883 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
886 catch (FormatException)
888 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
889 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
892 SettingDialog.Nicoms = _cfgCommon.Nicoms;
893 SettingDialog.HotkeyEnabled = _cfgCommon.HotkeyEnabled;
894 SettingDialog.HotkeyMod = _cfgCommon.HotkeyModifier;
895 SettingDialog.HotkeyKey = _cfgCommon.HotkeyKey;
896 SettingDialog.HotkeyValue = _cfgCommon.HotkeyValue;
898 SettingDialog.BlinkNewMentions = _cfgCommon.BlinkNewMentions;
900 SettingDialog.UseAdditionalCount = _cfgCommon.UseAdditionalCount;
901 SettingDialog.MoreCountApi = _cfgCommon.MoreCountApi;
902 SettingDialog.FirstCountApi = _cfgCommon.FirstCountApi;
903 SettingDialog.SearchCountApi = _cfgCommon.SearchCountApi;
904 SettingDialog.FavoritesCountApi = _cfgCommon.FavoritesCountApi;
905 SettingDialog.UserTimelineCountApi = _cfgCommon.UserTimelineCountApi;
906 SettingDialog.ListCountApi = _cfgCommon.ListCountApi;
908 SettingDialog.UserstreamStartup = _cfgCommon.UserstreamStartup;
909 SettingDialog.UserstreamPeriodInt = _cfgCommon.UserstreamPeriod;
910 SettingDialog.OpenUserTimeline = _cfgCommon.OpenUserTimeline;
911 SettingDialog.ListDoubleClickAction = _cfgCommon.ListDoubleClickAction;
912 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
913 SettingDialog.HideDuplicatedRetweets = _cfgCommon.HideDuplicatedRetweets;
915 SettingDialog.IsPreviewFoursquare = _cfgCommon.IsPreviewFoursquare;
916 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
917 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
918 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
919 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
920 SettingDialog.IsListStatusesIncludeRts = _cfgCommon.IsListsIncludeRts;
921 SettingDialog.TabMouseLock = _cfgCommon.TabMouseLock;
922 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
923 SettingDialog.IsNotifyUseGrowl = _cfgCommon.IsUseNotifyGrowl;
926 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
927 HashMgr = new HashtagManage(HashSupl,
928 _cfgCommon.HashTags.ToArray(),
929 _cfgCommon.HashSelected,
930 _cfgCommon.HashIsPermanent,
931 _cfgCommon.HashIsHead,
932 _cfgCommon.HashIsNotAddToAtReply);
933 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
938 this.IconCache = new ImageCache();
940 bool saveRequired = false;
941 bool firstRun = false;
943 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
944 if (string.IsNullOrEmpty(tw.Username))
948 SettingDialog.ShowInTaskbar = true;
950 //設定せずにキャンセルされた場合はプログラム終了
951 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
953 Application.Exit(); //強制終了
956 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
957 if (string.IsNullOrEmpty(tw.Username))
959 Application.Exit(); //強制終了
962 SettingDialog.ShowInTaskbar = false;
965 _fntUnread = SettingDialog.FontUnread;
966 _clUnread = SettingDialog.ColorUnread;
967 _fntReaded = SettingDialog.FontReaded;
968 _clReaded = SettingDialog.ColorReaded;
969 _clFav = SettingDialog.ColorFav;
970 _clOWL = SettingDialog.ColorOWL;
971 _clRetweet = SettingDialog.ColorRetweet;
972 _fntDetail = SettingDialog.FontDetail;
973 _clDetail = SettingDialog.ColorDetail;
974 _clDetailLink = SettingDialog.ColorDetailLink;
975 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
976 _clSelf = SettingDialog.ColorSelf;
977 _clAtSelf = SettingDialog.ColorAtSelf;
978 _clTarget = SettingDialog.ColorTarget;
979 _clAtTarget = SettingDialog.ColorAtTarget;
980 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
981 _clAtTo = SettingDialog.ColorAtTo;
982 _clListBackcolor = SettingDialog.ColorListBackcolor;
983 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
984 _clInputFont = SettingDialog.ColorInputFont;
985 _fntInputFont = SettingDialog.FontInputFont;
986 _brsBackColorMine.Dispose();
987 _brsBackColorAt.Dispose();
988 _brsBackColorYou.Dispose();
989 _brsBackColorAtYou.Dispose();
990 _brsBackColorAtFromTarget.Dispose();
991 _brsBackColorAtTo.Dispose();
992 _brsBackColorNone.Dispose();
993 _brsBackColorMine = new SolidBrush(_clSelf);
994 _brsBackColorAt = new SolidBrush(_clAtSelf);
995 _brsBackColorYou = new SolidBrush(_clTarget);
996 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
997 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
998 _brsBackColorAtTo = new SolidBrush(_clAtTo);
999 _brsBackColorNone = new SolidBrush(_clListBackcolor);
1001 if (SettingDialog.IsMonospace)
1003 detailHtmlFormatHeader = detailHtmlFormatMono1;
1004 detailHtmlFormatFooter = detailHtmlFormatMono7;
1008 detailHtmlFormatHeader = detailHtmlFormat1;
1009 detailHtmlFormatFooter = detailHtmlFormat7;
1011 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();
1012 if (SettingDialog.IsMonospace)
1014 detailHtmlFormatHeader += detailHtmlFormatMono6;
1018 detailHtmlFormatHeader += detailHtmlFormat6;
1020 //他の設定項目は、随時設定画面で保持している値を読み出して使用
1023 if (SettingDialog.HotkeyEnabled)
1026 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
1027 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
1028 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
1029 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
1030 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
1032 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
1036 HttpConnection.InitializeConnection(SettingDialog.DefaultTimeOut,
1037 SettingDialog.SelectedProxyType,
1038 SettingDialog.ProxyAddress,
1039 SettingDialog.ProxyPort,
1040 SettingDialog.ProxyUser,
1041 SettingDialog.ProxyPassword);
1043 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
1044 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
1045 ShortUrl.IsResolve = SettingDialog.TinyUrlResolve;
1046 ShortUrl.BitlyId = SettingDialog.BitlyUser;
1047 ShortUrl.BitlyKey = SettingDialog.BitlyPwd;
1048 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
1049 tw.TrackWord = _cfgCommon.TrackWord;
1050 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
1051 tw.AllAtReply = _cfgCommon.AllAtReply;
1052 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
1055 this.CreatePictureServices();
1056 SetImageServiceCombo();
1057 ImageSelectionPanel.Enabled = false;
1059 SelectImageServiceComboItem(_cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
1062 this.ClientSize = _cfgLocal.FormSize;
1063 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1064 _myLoc = _cfgLocal.FormLocation;
1066 if (this.WindowState != FormWindowState.Minimized)
1068 this.DesktopLocation = _cfgLocal.FormLocation;
1069 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
1070 bool outOfScreen = true;
1071 if (Screen.AllScreens.Length == 1) //ハングするとの報告
1073 foreach (Screen scr in Screen.AllScreens)
1075 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1077 outOfScreen = false;
1083 this.DesktopLocation = new Point(0, 0);
1084 _myLoc = this.DesktopLocation;
1088 this.TopMost = SettingDialog.AlwaysTop;
1089 _mySpDis = _cfgLocal.SplitterDistance;
1090 _mySpDis2 = _cfgLocal.StatusTextHeight;
1091 _mySpDis3 = _cfgLocal.PreviewDistance;
1092 if (_mySpDis3 == -1)
1094 _mySpDis3 = _mySize.Width - 150;
1095 if (_mySpDis3 < 1) _mySpDis3 = 50;
1096 _cfgLocal.PreviewDistance = _mySpDis3;
1098 _myAdSpDis = _cfgLocal.AdSplitterDistance;
1099 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
1100 //this.Tween_ClientSizeChanged(this, null);
1101 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
1102 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
1104 StatusText.Font = _fntInputFont;
1105 StatusText.ForeColor = _clInputFont;
1107 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
1108 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
1110 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1111 if (SettingDialog.UnreadManage == false)
1113 ReadedStripMenuItem.Enabled = false;
1114 UnreadStripMenuItem.Enabled = false;
1117 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
1120 TimerTimeline.AutoReset = true;
1121 TimerTimeline.SynchronizingObject = this;
1123 TimerTimeline.Interval = 1000;
1124 TimerTimeline.Enabled = true;
1127 TimerRefreshIcon.Interval = 200;
1128 TimerRefreshIcon.Enabled = true;
1131 StatusLabel.Text = "";
1132 StatusLabel.AutoToolTip = false;
1133 StatusLabel.ToolTipText = "";
1135 lblLen.Text = GetRestStatusCount(true, false).ToString();
1137 ////////////////////////////////////////////////////////////////////////////////
1138 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1139 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1140 switch (_cfgCommon.SortColumn)
1142 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1146 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1149 mode = IdComparerClass.ComparerMode.Nickname;
1152 mode = IdComparerClass.ComparerMode.Data;
1155 mode = IdComparerClass.ComparerMode.Id;
1158 mode = IdComparerClass.ComparerMode.Name;
1161 mode = IdComparerClass.ComparerMode.Source;
1164 _statuses.SortMode = mode;
1165 ////////////////////////////////////////////////////////////////////////////////
1167 switch (SettingDialog.IconSz)
1169 case MyCommon.IconSizes.IconNone:
1172 case MyCommon.IconSizes.Icon16:
1175 case MyCommon.IconSizes.Icon24:
1178 case MyCommon.IconSizes.Icon48:
1181 case MyCommon.IconSizes.Icon48_2:
1193 tw.IconSize = _iconSz;
1195 tw.TinyUrlResolve = SettingDialog.TinyUrlResolve;
1197 //発言詳細部アイコンをリストアイコンにサイズ変更
1204 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1205 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1206 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1207 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1208 SourceLinkLabel.Text = ""; //Source部分初期化
1210 //<<<<<<<<タブ関連>>>>>>>
1211 //デフォルトタブの存在チェック、ない場合には追加
1212 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1215 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1217 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1221 tab.TabType = MyCommon.TabUsageType.Home;
1224 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1227 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1229 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1233 tab.TabType = MyCommon.TabUsageType.Mentions;
1236 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1239 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1241 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1245 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1248 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1251 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1253 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1257 tab.TabType = MyCommon.TabUsageType.Favorites;
1260 foreach (string tn in _statuses.Tabs.Keys)
1262 if (_statuses.Tabs[tn].TabType == MyCommon.TabUsageType.Undefined)
1264 _statuses.Tabs[tn].TabType = MyCommon.TabUsageType.UserDefined;
1266 if (!AddNewTab(tn, true, _statuses.Tabs[tn].TabType, _statuses.Tabs[tn].ListInfo)) throw new Exception(Properties.Resources.TweenMain_LoadText1);
1269 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1270 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1271 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1272 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1274 if (SettingDialog.MinimizeToTray == false || this.WindowState != FormWindowState.Minimized)
1276 this.Visible = true;
1278 _curTab = ListTab.SelectedTab;
1280 _curList = (DetailsListView)_curTab.Tag;
1281 SetMainWindowTitle();
1282 SetNotifyIconText();
1284 if (SettingDialog.TabIconDisp)
1286 ListTab.DrawMode = TabDrawMode.Normal;
1290 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1291 ListTab.DrawItem += ListTab_DrawItem;
1292 ListTab.ImageList = null;
1295 _ignoreConfigSave = false;
1296 this.TweenMain_Resize(null, null);
1297 if (saveRequired) SaveConfigsAll(false);
1301 tw.VerifyCredentials();
1302 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1304 if (ua.Username.ToLower() == tw.Username.ToLower())
1306 ua.UserId = tw.UserId;
1311 foreach (UserAccount ua in SettingDialog.UserAccounts)
1313 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1315 ua.UserId = tw.UserId;
1322 // 初回起動時だけ右下のメニューを目立たせる
1323 HashStripSplitButton.ShowDropDown();
1330 private void CreatePictureServices()
1332 if (this.pictureService != null) this.pictureService.Clear();
1333 this.pictureService = null;
1334 this.pictureService = new Dictionary<string, IMultimediaShareService> {
1335 {"TwitPic", new TwitPic(tw)},
1336 {"img.ly", new imgly(tw)},
1337 {"yfrog", new yfrog(tw)},
1338 {"Twitter", new TwitterPhoto(tw)},
1339 {"ついっぷるフォト", new TwipplePhoto(tw)},
1340 {"Imgur", new Imgur(tw)},
1344 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1349 txt = ListTab.TabPages[e.Index].Text;
1356 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1357 if (e.State == DrawItemState.Selected)
1359 e.DrawFocusRectangle();
1364 if (_statuses.Tabs[txt].UnreadCount > 0)
1367 fore = System.Drawing.SystemBrushes.ControlText;
1371 fore = System.Drawing.SystemBrushes.ControlText;
1373 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1376 private void LoadConfig()
1378 _cfgCommon = SettingCommon.Load();
1379 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1381 _cfgCommon.UserAccounts = new List<UserAccount>();
1382 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1384 UserAccount account = new UserAccount();
1385 account.Username = _cfgCommon.UserName;
1386 account.UserId = _cfgCommon.UserId;
1387 account.Token = _cfgCommon.Token;
1388 account.TokenSecret = _cfgCommon.TokenSecret;
1390 _cfgCommon.UserAccounts.Add(account);
1393 _cfgLocal = SettingLocal.Load();
1394 List<TabClass> tabs = SettingTabs.Load().Tabs;
1395 foreach (TabClass tb in tabs)
1399 _statuses.Tabs.Add(tb.TabName, tb);
1403 tb.TabName = _statuses.GetUniqueTabName();
1404 _statuses.Tabs.Add(tb.TabName, tb);
1407 if (_statuses.Tabs.Count == 0)
1409 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1410 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1411 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1412 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1416 private void TimerInterval_Changed(object sender, AppendSettingDialog.IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1418 if (!TimerTimeline.Enabled) return;
1422 private AppendSettingDialog.IntervalChangedEventArgs ResetTimers = new AppendSettingDialog.IntervalChangedEventArgs();
1424 private static int homeCounter = 0;
1425 private static int mentionCounter = 0;
1426 private static int dmCounter = 0;
1427 private static int pubSearchCounter = 0;
1428 private static int userTimelineCounter = 0;
1429 private static int listsCounter = 0;
1430 private static int usCounter = 0;
1431 private static int ResumeWait = 0;
1432 private static int refreshFollowers = 0;
1434 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1436 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1437 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1438 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1439 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1440 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1441 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1442 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1443 Interlocked.Increment(ref refreshFollowers);
1446 if (ResetTimers.Timeline || homeCounter <= 0 && SettingDialog.TimelinePeriodInt > 0)
1448 Interlocked.Exchange(ref homeCounter, SettingDialog.TimelinePeriodInt);
1449 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
1450 ResetTimers.Timeline = false;
1452 if (ResetTimers.Reply || mentionCounter <= 0 && SettingDialog.ReplyPeriodInt > 0)
1454 Interlocked.Exchange(ref mentionCounter, SettingDialog.ReplyPeriodInt);
1455 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
1456 ResetTimers.Reply = false;
1458 if (ResetTimers.DirectMessage || dmCounter <= 0 && SettingDialog.DMPeriodInt > 0)
1460 Interlocked.Exchange(ref dmCounter, SettingDialog.DMPeriodInt);
1461 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
1462 ResetTimers.DirectMessage = false;
1464 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && SettingDialog.PubSearchPeriodInt > 0)
1466 Interlocked.Exchange(ref pubSearchCounter, SettingDialog.PubSearchPeriodInt);
1467 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, "");
1468 ResetTimers.PublicSearch = false;
1470 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && SettingDialog.UserTimelinePeriodInt > 0)
1472 Interlocked.Exchange(ref userTimelineCounter, SettingDialog.UserTimelinePeriodInt);
1473 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, "");
1474 ResetTimers.UserTimeline = false;
1476 if (ResetTimers.Lists || listsCounter <= 0 && SettingDialog.ListsPeriodInt > 0)
1478 Interlocked.Exchange(ref listsCounter, SettingDialog.ListsPeriodInt);
1479 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, "");
1480 ResetTimers.Lists = false;
1482 if (ResetTimers.UserStream || usCounter <= 0 && SettingDialog.UserstreamPeriodInt > 0)
1484 Interlocked.Exchange(ref usCounter, SettingDialog.UserstreamPeriodInt);
1485 if (this._isActiveUserstream) RefreshTimeline(true);
1486 ResetTimers.UserStream = false;
1488 if (refreshFollowers > 6 * 3600)
1490 Interlocked.Exchange(ref refreshFollowers, 0);
1491 doGetFollowersMenu();
1492 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
1493 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
1494 if (InvokeRequired && !IsDisposed) this.Invoke(new MethodInvoker(this.TrimPostChain));
1498 Interlocked.Increment(ref ResumeWait);
1499 if (ResumeWait > 30)
1502 Interlocked.Exchange(ref ResumeWait, 0);
1503 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
1504 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
1505 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
1506 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, "");
1507 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, "");
1508 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, "");
1509 doGetFollowersMenu();
1510 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
1511 if (InvokeRequired && !IsDisposed) this.Invoke(new MethodInvoker(this.TrimPostChain));
1516 private void RefreshTimeline(bool isUserStream)
1518 if (isUserStream) this.RefreshTasktrayIcon(true);
1520 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1521 long topId = GetScrollPos(ref smode);
1522 int befCnt = _curList.VirtualListSize;
1525 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1526 Dictionary<string, long> focusedId = new Dictionary<string, long>();
1527 SaveSelectedStatus(selId, focusedId);
1530 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1533 PostClass[] notifyPosts = null;
1534 string soundFile = "";
1536 bool isMention = false;
1537 bool isDelete = false;
1538 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1540 if (MyCommon._endingFlag) return;
1545 foreach (TabPage tab in ListTab.TabPages)
1547 DetailsListView lst = (DetailsListView)tab.Tag;
1548 TabClass tabInfo = _statuses.Tabs[tab.Text];
1550 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1552 if (lst.Equals(_curList))
1554 this.PurgeListViewItemCache();
1558 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1564 this.SelectListItem(lst,
1565 _statuses.IndexOf(tab.Text, selId[tab.Text]),
1566 _statuses.IndexOf(tab.Text, focusedId[tab.Text]));
1569 if (tabInfo.UnreadCount > 0)
1570 if (SettingDialog.TabIconDisp)
1571 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1573 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
1577 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1586 if (befCnt != _curList.VirtualListSize)
1592 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1596 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1603 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1605 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1606 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1612 catch (Exception ex)
1614 ex.Data["Msg"] = "Ref2";
1620 NotifyNewPosts(notifyPosts,
1623 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1625 SetMainWindowTitle();
1626 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1628 HashSupl.AddRangeItem(tw.GetHashList());
1632 private long GetScrollPos(ref int smode)
1635 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1637 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1639 if (_statuses.SortOrder == SortOrder.Ascending)
1642 if (ListLockMenuItem.Checked)
1647 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1652 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1654 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1655 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1656 if (_item.Index == _curList.VirtualListSize - 1)
1663 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1671 if (ListLockMenuItem.Checked)
1674 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1679 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1682 _item = _curList.GetItemAt(0, 10); //一番上
1683 if (_item == null) _item = _curList.Items[0];
1684 if (_item.Index == 0)
1690 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1699 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1710 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long> focusedId)
1712 if (MyCommon._endingFlag) return;
1713 foreach (TabPage tab in ListTab.TabPages)
1715 DetailsListView lst = (DetailsListView)tab.Tag;
1716 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1718 selId.Add(tab.Text, _statuses.GetId(tab.Text, lst.SelectedIndices));
1722 selId.Add(tab.Text, new long[1] {-2});
1724 if (lst.FocusedItem != null)
1725 focusedId.Add(tab.Text, _statuses.GetId(tab.Text, lst.FocusedItem.Index));
1727 focusedId.Add(tab.Text, -2);
1732 private bool BalloonRequired()
1734 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1735 ev.Eventtype = MyCommon.EVENTTYPE.None;
1737 return BalloonRequired(ev);
1740 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1742 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1745 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1747 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1750 private bool BalloonRequired(Twitter.FormattedEvent ev)
1753 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1754 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1758 SettingDialog.LimitBalloon &&
1760 this.WindowState == FormWindowState.Minimized ||
1762 Form.ActiveForm == null
1765 !SettingDialog.LimitBalloon
1768 !Win32Api.IsScreenSaverRunning())
1778 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1780 if (notifyPosts != null &&
1781 notifyPosts.Length > 0 &&
1782 this.SettingDialog.ReadOwnPost &&
1783 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1789 if (BalloonRequired())
1791 if (notifyPosts != null && notifyPosts.Length > 0)
1793 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1794 if (SettingDialog.IsNotifyUseGrowl)
1796 StringBuilder sb = new StringBuilder();
1800 foreach (PostClass post in notifyPosts)
1802 if (!(notifyPosts.Length > 3))
1808 if (post.IsReply && !post.IsExcludeReply) reply = true;
1809 if (post.IsDm) dm = true;
1810 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1811 switch (SettingDialog.NameBalloon)
1813 case MyCommon.NameBalloonEnum.UserID:
1814 sb.Append(post.ScreenName).Append(" : ");
1816 case MyCommon.NameBalloonEnum.NickName:
1817 sb.Append(post.Nickname).Append(" : ");
1820 sb.Append(post.TextFromApi);
1821 if (notifyPosts.Length > 3)
1823 if (notifyPosts.Last() != post) continue;
1826 StringBuilder title = new StringBuilder();
1827 GrowlHelper.NotifyType nt;
1828 if (SettingDialog.DispUsername)
1830 title.Append(tw.Username);
1831 title.Append(" - ");
1839 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1840 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1841 title.Append(Application.ProductName);
1842 title.Append(" [DM] ");
1843 title.Append(Properties.Resources.RefreshDirectMessageText1);
1845 title.Append(addCount);
1846 title.Append(Properties.Resources.RefreshDirectMessageText2);
1847 nt = GrowlHelper.NotifyType.DirectMessage;
1851 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1852 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1853 title.Append(Application.ProductName);
1854 title.Append(" [Reply!] ");
1855 title.Append(Properties.Resources.RefreshTimelineText1);
1857 title.Append(addCount);
1858 title.Append(Properties.Resources.RefreshTimelineText2);
1859 nt = GrowlHelper.NotifyType.Reply;
1863 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1864 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1865 title.Append(Application.ProductName);
1867 title.Append(Properties.Resources.RefreshTimelineText1);
1869 title.Append(addCount);
1870 title.Append(Properties.Resources.RefreshTimelineText2);
1871 nt = GrowlHelper.NotifyType.Notify;
1873 string bText = sb.ToString();
1874 if (string.IsNullOrEmpty(bText)) return;
1876 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1877 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1882 StringBuilder sb = new StringBuilder();
1885 foreach (PostClass post in notifyPosts)
1887 if (post.IsReply && !post.IsExcludeReply) reply = true;
1888 if (post.IsDm) dm = true;
1889 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1890 switch (SettingDialog.NameBalloon)
1892 case MyCommon.NameBalloonEnum.UserID:
1893 sb.Append(post.ScreenName).Append(" : ");
1895 case MyCommon.NameBalloonEnum.NickName:
1896 sb.Append(post.Nickname).Append(" : ");
1899 sb.Append(post.TextFromApi);
1902 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1903 StringBuilder title = new StringBuilder();
1905 if (SettingDialog.DispUsername)
1907 title.Append(tw.Username);
1908 title.Append(" - ");
1916 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1917 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1918 ntIcon = ToolTipIcon.Warning;
1919 title.Append(Application.ProductName);
1920 title.Append(" [DM] ");
1921 title.Append(Properties.Resources.RefreshDirectMessageText1);
1923 title.Append(addCount);
1924 title.Append(Properties.Resources.RefreshDirectMessageText2);
1928 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1929 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1930 ntIcon = ToolTipIcon.Warning;
1931 title.Append(Application.ProductName);
1932 title.Append(" [Reply!] ");
1933 title.Append(Properties.Resources.RefreshTimelineText1);
1935 title.Append(addCount);
1936 title.Append(Properties.Resources.RefreshTimelineText2);
1940 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1941 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1942 ntIcon = ToolTipIcon.Info;
1943 title.Append(Application.ProductName);
1945 title.Append(Properties.Resources.RefreshTimelineText1);
1947 title.Append(addCount);
1948 title.Append(Properties.Resources.RefreshTimelineText2);
1950 string bText = sb.ToString();
1951 if (string.IsNullOrEmpty(bText)) return;
1952 //NotifyIcon1.BalloonTipText = sb.ToString();
1953 //NotifyIcon1.ShowBalloonTip(500);
1954 NotifyIcon1.BalloonTipTitle = title.ToString();
1955 NotifyIcon1.BalloonTipText = bText;
1956 NotifyIcon1.BalloonTipIcon = ntIcon;
1957 NotifyIcon1.ShowBalloonTip(500);
1963 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(soundFile))
1967 string dir = Application.StartupPath;
1968 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1970 dir = Path.Combine(dir, "Sounds");
1972 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1982 //mentions新着時に画面ブリンク
1983 if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1985 Win32Api.FlashMyWindow(this.Handle, Win32Api.FlashSpecification.FlashTray, 3);
1989 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1991 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1993 _curItemIndex = _curList.SelectedIndices[0];
1994 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1998 _curPost = GetCurTabPost(_curItemIndex);
2000 catch (ArgumentException)
2005 this.PushSelectPostChain();
2007 if (SettingDialog.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
2009 ChangeCacheStyleRead(true, _curItemIndex, _curTab); //既読へ(フォント、文字色)
2015 private void ChangeCacheStyleRead(bool Read, int Index, TabPage Tab)
2017 //Read:true=既読 false=未読
2018 //未読管理していなかったら既読として扱う
2019 if (!_statuses.Tabs[_curTab.Text].UnreadManage ||
2020 !SettingDialog.UnreadManage) Read = true;
2023 ListViewItem itm = null;
2024 PostClass post = null;
2026 if (Tab.Equals(this._curTab))
2028 this.TryGetListViewItemCache(Index, out itm, out post);
2031 if (itm == null || post == null)
2033 itm = ((DetailsListView)Tab.Tag).Items[Index];
2034 post = _statuses[Tab.Text, Index];
2037 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)Tab.Tag));
2040 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
2047 Item.SubItems[5].Text = "";
2052 Item.SubItems[5].Text = "★";
2058 else if (Post.RetweetedId != null)
2060 else if (Post.IsOwl && (Post.IsDm || SettingDialog.OneWayLove))
2062 else if (Read || !SettingDialog.UseUnreadStyle)
2067 if (DList == null || Item.Index == -1)
2069 Item.ForeColor = cl;
2070 if (SettingDialog.UseUnreadStyle)
2076 if (SettingDialog.UseUnreadStyle)
2077 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
2079 DList.ChangeItemForeColor(Item.Index, cl);
2080 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
2084 private void ColorizeList()
2086 //Index:更新対象のListviewItem.Index。Colorを返す。
2087 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2090 _post = _anchorPost;
2094 if (_post == null) return;
2096 var itemColors = new Color[] { };
2099 this.itemCacheLock.EnterReadLock();
2102 if (this._itemCache == null) return;
2105 from i in Enumerable.Range(0, this._itemCache.Length)
2106 select this.JudgeColor(_post, this._postCache[i]);
2108 itemColors = query.ToArray();
2109 itemIndex = _itemCacheIndex;
2111 finally { this.itemCacheLock.ExitReadLock(); }
2113 if (itemIndex < 0) return;
2115 foreach (var backColor in itemColors)
2117 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
2118 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
2119 _curList.ChangeItemBackColor(itemIndex++, backColor);
2123 private void ColorizeList(ListViewItem Item, int Index)
2125 //Index:更新対象のListviewItem.Index。Colorを返す。
2126 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2129 _post = _anchorPost;
2133 PostClass tPost = GetCurTabPost(Index);
2135 if (_post == null) return;
2137 if (Item.Index == -1)
2138 Item.BackColor = JudgeColor(_post, tPost);
2140 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
2143 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
2146 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
2149 else if (TargetPost.IsMe)
2152 else if (TargetPost.IsReply)
2155 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2157 cl = _clAtFromTarget;
2158 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2161 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2166 cl = _clListBackcolor;
2171 private void PostButton_Click(object sender, EventArgs e)
2173 if (StatusText.Text.Trim().Length == 0)
2175 if (!ImageSelectionPanel.Enabled)
2182 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2184 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2186 MessageBoxButtons.YesNoCancel,
2187 MessageBoxIcon.Question);
2190 case DialogResult.Yes:
2191 doReTweetOfficial(false);
2192 StatusText.Text = "";
2194 case DialogResult.Cancel:
2199 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2201 if (SettingDialog.Nicoms)
2203 StatusText.SelectionStart = StatusText.Text.Length;
2204 UrlConvert(MyCommon.UrlConverter.Nicoms);
2206 //if (SettingDialog.UrlConvertAuto)
2208 // StatusText.SelectionStart = StatusText.Text.Length;
2209 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2211 //else if (SettingDialog.Nicoms)
2213 // StatusText.SelectionStart = StatusText.Text.Length;
2214 // UrlConvert(UrlConverter.Nicoms);
2216 StatusText.SelectionStart = StatusText.Text.Length;
2217 GetWorkerArg args = new GetWorkerArg();
2220 args.type = MyCommon.WORKERTYPE.PostMessage;
2221 CheckReplyTo(StatusText.Text);
2224 int adjustCount = 0;
2225 string tmpStatus = StatusText.Text.Trim();
2226 if (ToolStripMenuItemApiCommandEvasion.Checked)
2229 if (Regex.IsMatch(tmpStatus,
2230 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2231 RegexOptions.IgnoreCase)
2232 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2235 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2238 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2241 bool isCutOff = false;
2242 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2243 if (StatusText.Multiline && !SettingDialog.PostCtrlEnter)
2245 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2246 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2248 if (SettingDialog.PostShiftEnter)
2250 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2252 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2254 isRemoveFooter = true;
2256 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2258 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2261 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2262 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2264 isRemoveFooter = true;
2275 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2283 if (HashMgr.IsNotAddToAtReply)
2285 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2288 header = HashMgr.UseHash + " ";
2290 footer = " " + HashMgr.UseHash;
2295 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2298 header = HashMgr.UseHash + " ";
2300 footer = " " + HashMgr.UseHash;
2303 if (!isRemoveFooter)
2305 if (SettingDialog.UseRecommendStatus)
2307 footer += SettingDialog.RecommendStatusText;
2309 // テキストボックスに入力されている文字列を使用する
2310 footer += " " + SettingDialog.Status.Trim();
2313 args.status.status = header + StatusText.Text + footer;
2315 if (ToolStripMenuItemApiCommandEvasion.Checked)
2318 if (Regex.IsMatch(args.status.status,
2319 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2320 RegexOptions.IgnoreCase)
2321 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2324 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2327 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2328 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2331 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2333 // 文中の全角スペースを半角スペース1個にする
2334 args.status.status = args.status.status.Replace(" ", " ");
2337 if (isCutOff && args.status.status.Length > 140)
2339 args.status.status = args.status.status.Substring(0, 140);
2340 string AtId = @"(@|@)[a-z0-9_/]+$";
2341 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2342 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2343 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2344 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2347 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2348 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2350 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2353 args.status.inReplyToId = _reply_to_id;
2354 args.status.inReplyToName = _reply_to_name;
2355 if (ImageSelectionPanel.Visible)
2358 if (ImageSelectedPicture.Image != ImageSelectedPicture.InitialImage &&
2359 ImageServiceCombo.SelectedIndex > -1 &&
2360 !string.IsNullOrEmpty(ImagefilePathText.Text))
2362 if (MessageBox.Show(Properties.Resources.PostPictureConfirm1,
2363 Properties.Resources.PostPictureConfirm2,
2364 MessageBoxButtons.OKCancel,
2365 MessageBoxIcon.Question,
2366 MessageBoxDefaultButton.Button1)
2367 == DialogResult.Cancel)
2369 TimelinePanel.Visible = true;
2370 TimelinePanel.Enabled = true;
2371 ImageSelectionPanel.Visible = false;
2372 ImageSelectionPanel.Enabled = false;
2373 if (_curList != null)
2377 args.status.imageService = ImageServiceCombo.Text;
2378 args.status.imagePath = ImagefilePathText.Text;
2379 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
2380 ImagefilePathText.Text = "";
2381 TimelinePanel.Visible = true;
2382 TimelinePanel.Enabled = true;
2383 ImageSelectionPanel.Visible = false;
2384 ImageSelectionPanel.Enabled = false;
2385 if (_curList != null)
2390 MessageBox.Show(Properties.Resources.PostPictureWarn1, Properties.Resources.PostPictureWarn2);
2398 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2400 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2404 _reply_to_id = null;
2405 _reply_to_name = null;
2406 StatusText.Text = "";
2407 _history.Add(new PostingStatus());
2408 _hisIdx = _history.Count - 1;
2409 if (!ToolStripFocusLockMenuItem.Checked)
2410 ((Control)ListTab.SelectedTab.Tag).Focus();
2411 urlUndoBuffer = null;
2412 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2415 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2417 MyCommon._endingFlag = true;
2421 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2423 if (!SettingDialog.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2425 //_endingFlag=false:フォームの×ボタン
2427 this.Visible = false;
2431 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2432 _ignoreConfigSave = true;
2433 MyCommon._endingFlag = true;
2434 TimerTimeline.Enabled = false;
2435 TimerRefreshIcon.Enabled = false;
2439 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2441 this.Visible = true;
2442 if (this.WindowState == FormWindowState.Minimized)
2444 this.WindowState = FormWindowState.Normal;
2447 this.BringToFront();
2450 private static int errorCount = 0;
2452 private static bool CheckAccountValid()
2454 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2460 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2469 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2471 BackgroundWorker bw = (BackgroundWorker)sender;
2472 if (bw.CancellationPending || MyCommon._endingFlag)
2478 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2480 MyApplication.InitCulture();
2483 GetWorkerResult rslt = new GetWorkerResult();
2485 bool read = !SettingDialog.UnreadManage;
2486 if (_initial && SettingDialog.UnreadManage) read = SettingDialog.Readed;
2488 GetWorkerArg args = (GetWorkerArg)e.Argument;
2490 if (!CheckAccountValid())
2492 rslt.retMsg = "Auth error. Check your account";
2493 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2494 rslt.tName = args.tName;
2499 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2503 case MyCommon.WORKERTYPE.Timeline:
2504 case MyCommon.WORKERTYPE.Reply:
2505 bw.ReportProgress(50, MakeStatusMessage(args, false));
2506 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2508 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && SettingDialog.ReadOldPosts)
2509 _statuses.SetRead();
2511 rslt.addCount = _statuses.DistributePosts();
2513 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2514 bw.ReportProgress(50, MakeStatusMessage(args, false));
2515 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2516 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2517 rslt.addCount = _statuses.DistributePosts();
2520 case MyCommon.WORKERTYPE.FavAdd:
2524 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2526 for (int i = 0; i <= args.ids.Count - 1; i++)
2528 var post = tab.IsInnerStorageTabType
2529 ? tab.Posts[args.ids[i]]
2530 : _statuses[args.ids[i]];
2533 bw.ReportProgress(50, MakeStatusMessage(args, false));
2536 if (post.RetweetedId == null)
2537 ret = tw.PostFavAdd(post.StatusId);
2539 ret = tw.PostFavAdd(post.RetweetedId.Value);
2541 if (ret.Length == 0)
2543 args.sIds.Add(post.StatusId);
2544 post.IsFav = true; //リスト再描画必要
2545 _favTimestamps.Add(DateTime.Now);
2546 if (string.IsNullOrEmpty(post.RelTabName))
2548 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2549 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2553 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2554 if (_statuses.ContainsKey(post.StatusId))
2556 PostClass postTl = _statuses[post.StatusId];
2557 postTl.IsFav = true;
2558 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2561 //検索,リスト,UserTimeline,Relatedの各タブに反映
2562 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2564 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2570 rslt.sIds = args.sIds;
2574 case MyCommon.WORKERTYPE.FavRemove:
2578 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2580 for (int i = 0; i <= args.ids.Count - 1; i++)
2582 var post = tab.IsInnerStorageTabType
2583 ? tab.Posts[args.ids[i]]
2584 : _statuses[args.ids[i]];
2587 bw.ReportProgress(50, MakeStatusMessage(args, false));
2590 if (post.RetweetedId == null)
2591 ret = tw.PostFavRemove(post.StatusId);
2593 ret = tw.PostFavRemove(post.RetweetedId.Value);
2595 if (ret.Length == 0)
2597 args.sIds.Add(post.StatusId);
2598 post.IsFav = false; //リスト再描画必要
2599 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2600 //検索,リスト,UserTimeline,Relatedの各タブに反映
2601 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2603 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2609 rslt.sIds = args.sIds;
2613 case MyCommon.WORKERTYPE.PostMessage:
2614 bw.ReportProgress(200);
2615 if (string.IsNullOrEmpty(args.status.imagePath))
2617 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2621 ret = this.pictureService[args.status.imageService].Upload(ref args.status.imagePath,
2622 ref args.status.status,
2623 args.status.inReplyToId);
2625 bw.ReportProgress(300);
2626 rslt.status = args.status;
2628 case MyCommon.WORKERTYPE.Retweet:
2629 bw.ReportProgress(200);
2630 for (int i = 0; i <= args.ids.Count - 1; i++)
2632 ret = tw.PostRetweet(args.ids[i], read);
2634 bw.ReportProgress(300);
2636 case MyCommon.WORKERTYPE.Follower:
2637 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2640 tw.RefreshFollowerIds();
2642 catch (WebApiException ex) { ret = ex.Message; }
2644 case MyCommon.WORKERTYPE.NoRetweetIds:
2647 tw.RefreshNoRetweetIds();
2649 catch (WebApiException ex) { ret = ex.Message; }
2651 case MyCommon.WORKERTYPE.Configuration:
2654 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2656 catch (WebApiException ex) { ret = ex.Message; }
2658 case MyCommon.WORKERTYPE.Favorites:
2659 bw.ReportProgress(50, MakeStatusMessage(args, false));
2660 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2661 rslt.addCount = _statuses.DistributePosts();
2663 case MyCommon.WORKERTYPE.PublicSearch:
2664 bw.ReportProgress(50, MakeStatusMessage(args, false));
2665 if (string.IsNullOrEmpty(args.tName))
2667 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2669 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2670 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2675 TabClass tb = _statuses.GetTabByName(args.tName);
2678 //ret = tw.GetPhoenixSearch(read, tb, false);
2679 ret = tw.GetSearch(read, tb, false);
2680 if (string.IsNullOrEmpty(ret) && args.page == -1)
2682 //ret = tw.GetPhoenixSearch(read, tb, true)
2683 ret = tw.GetSearch(read, tb, true);
2688 rslt.addCount = _statuses.DistributePosts();
2690 case MyCommon.WORKERTYPE.UserTimeline:
2691 bw.ReportProgress(50, MakeStatusMessage(args, false));
2693 if (SettingDialog.UseAdditionalCount) count = SettingDialog.UserTimelineCountApi;
2694 if (string.IsNullOrEmpty(args.tName))
2696 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2698 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2703 TabClass tb = _statuses.GetTabByName(args.tName);
2706 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2710 rslt.addCount = _statuses.DistributePosts();
2712 case MyCommon.WORKERTYPE.List:
2713 bw.ReportProgress(50, MakeStatusMessage(args, false));
2714 if (string.IsNullOrEmpty(args.tName))
2717 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2719 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2725 TabClass tb = _statuses.GetTabByName(args.tName);
2728 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2732 rslt.addCount = _statuses.DistributePosts();
2735 case MyCommon.WORKERTYPE.Related:
2737 bw.ReportProgress(50, MakeStatusMessage(args, false));
2738 TabClass tab = _statuses.GetTabByName(args.tName);
2739 ret = tw.GetRelatedResult(read, tab);
2740 rslt.addCount = _statuses.DistributePosts();
2744 case MyCommon.WORKERTYPE.BlockIds:
2745 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2748 tw.RefreshBlockIds();
2750 catch (WebApiException ex) { ret = ex.Message; }
2754 if (bw.CancellationPending)
2761 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2763 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2764 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2766 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2768 _favTimestamps.RemoveAt(i);
2772 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2776 DateTime tm = DateTime.Now;
2777 if (_tlTimestamps.ContainsKey(tm))
2778 _tlTimestamps[tm] += rslt.addCount;
2780 _tlTimestamps.Add(tm, rslt.addCount);
2782 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2783 List<DateTime> keys = new List<DateTime>();
2785 foreach (DateTime key in _tlTimestamps.Keys)
2787 if (key.CompareTo(oneHour) < 0)
2793 _tlCount += _tlTimestamps[key];
2796 foreach (DateTime key in keys)
2798 _tlTimestamps.Remove(key);
2805 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2808 rslt.type = args.type;
2809 rslt.tName = args.tName;
2810 if (args.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2811 args.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2812 args.type == MyCommon.WORKERTYPE.Reply ||
2813 args.type == MyCommon.WORKERTYPE.Timeline ||
2814 args.type == MyCommon.WORKERTYPE.Favorites)
2816 rslt.page = args.page - 1; //値が正しいか後でチェック。10ページ毎の継続確認
2822 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2828 switch (AsyncArg.type)
2830 case MyCommon.WORKERTYPE.Timeline:
2831 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2833 case MyCommon.WORKERTYPE.Reply:
2834 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2836 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2837 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2839 case MyCommon.WORKERTYPE.FavAdd:
2840 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2841 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2843 case MyCommon.WORKERTYPE.FavRemove:
2844 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2845 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2847 case MyCommon.WORKERTYPE.Favorites:
2848 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2850 case MyCommon.WORKERTYPE.PublicSearch:
2851 smsg = "Search refreshing...";
2853 case MyCommon.WORKERTYPE.List:
2854 smsg = "List refreshing...";
2856 case MyCommon.WORKERTYPE.Related:
2857 smsg = "Related refreshing...";
2859 case MyCommon.WORKERTYPE.UserTimeline:
2860 smsg = "UserTimeline refreshing...";
2867 switch (AsyncArg.type)
2869 case MyCommon.WORKERTYPE.Timeline:
2870 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2872 case MyCommon.WORKERTYPE.Reply:
2873 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2875 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2876 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2878 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2879 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2881 case MyCommon.WORKERTYPE.FavAdd:
2884 case MyCommon.WORKERTYPE.FavRemove:
2887 case MyCommon.WORKERTYPE.Favorites:
2888 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2890 case MyCommon.WORKERTYPE.Follower:
2891 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2893 case MyCommon.WORKERTYPE.NoRetweetIds:
2894 smsg = "NoRetweetIds refreshed";
2896 case MyCommon.WORKERTYPE.Configuration:
2899 case MyCommon.WORKERTYPE.PublicSearch:
2900 smsg = "Search refreshed";
2902 case MyCommon.WORKERTYPE.List:
2903 smsg = "List refreshed";
2905 case MyCommon.WORKERTYPE.Related:
2906 smsg = "Related refreshed";
2908 case MyCommon.WORKERTYPE.UserTimeline:
2909 smsg = "UserTimeline refreshed";
2911 case MyCommon.WORKERTYPE.BlockIds:
2912 smsg = Properties.Resources.UpdateBlockUserText3;
2919 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2921 if (MyCommon._endingFlag) return;
2922 if (e.ProgressPercentage > 100)
2925 if (e.ProgressPercentage == 200) //開始
2926 StatusLabel.Text = "Posting...";
2927 if (e.ProgressPercentage == 300) //終了
2928 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2932 string smsg = (string)e.UserState;
2933 if (smsg.Length > 0) StatusLabel.Text = smsg;
2937 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2939 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2941 if (e.Error != null)
2943 _myStatusError = true;
2944 _waitTimeline = false;
2948 _waitPubSearch = false;
2949 _waitUserTimeline = false;
2951 throw new Exception("BackgroundWorker Exception", e.Error);
2954 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2957 if (rslt.retMsg.Length > 0)
2959 _myStatusError = true;
2960 StatusLabel.Text = rslt.retMsg;
2963 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2965 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2967 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2971 //bool busy = false;
2972 //foreach (BackgroundWorker bw in _bw)
2974 // if (bw != null && bw.IsBusy)
2980 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2981 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2982 rslt.type == MyCommon.WORKERTYPE.Reply ||
2983 rslt.type == MyCommon.WORKERTYPE.List ||
2984 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2985 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2986 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2987 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2988 rslt.type == MyCommon.WORKERTYPE.Follower ||
2989 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2990 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2991 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2992 rslt.type == MyCommon.WORKERTYPE.Related ||
2993 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2994 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2995 rslt.type == MyCommon.WORKERTYPE.Configuration)
2997 RefreshTimeline(false); //リスト反映
3002 case MyCommon.WORKERTYPE.Timeline:
3003 _waitTimeline = false;
3006 // //API使用時の取得調整は別途考える(カウント調整?)
3009 case MyCommon.WORKERTYPE.Reply:
3011 if (rslt.newDM && !_initial)
3013 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
3016 case MyCommon.WORKERTYPE.Favorites:
3019 case MyCommon.WORKERTYPE.DirectMessegeRcv:
3022 case MyCommon.WORKERTYPE.FavAdd:
3023 case MyCommon.WORKERTYPE.FavRemove:
3024 if (_curList != null && _curTab != null)
3026 _curList.BeginUpdate();
3027 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
3033 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
3035 if (_curTab.Text.Equals(rslt.tName))
3037 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
3040 PostClass post = null;
3041 TabClass tb = _statuses.Tabs[rslt.tName];
3044 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
3046 post = tb.Posts[rslt.sIds[i]];
3050 post = _statuses[rslt.sIds[i]];
3052 ChangeCacheStyleRead(post.IsRead, idx, _curTab);
3054 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
3059 _curList.EndUpdate();
3062 case MyCommon.WORKERTYPE.PostMessage:
3063 if (string.IsNullOrEmpty(rslt.retMsg) ||
3064 rslt.retMsg.StartsWith("OK:") ||
3065 rslt.retMsg == "Warn:Status is a duplicate.")
3067 _postTimestamps.Add(DateTime.Now);
3068 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3069 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3071 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3073 _postTimestamps.RemoveAt(i);
3077 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
3079 HashMgr.ClearHashtag();
3080 this.HashStripSplitButton.Text = "#[-]";
3081 this.HashToggleMenuItem.Checked = false;
3082 this.HashToggleToolStripMenuItem.Checked = false;
3084 SetMainWindowTitle();
3092 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
3093 Properties.Resources.StatusUpdateFailed1,
3094 Properties.Resources.StatusUpdateFailed2),
3095 "Failed to update status",
3096 MessageBoxButtons.RetryCancel,
3097 MessageBoxIcon.Question);
3101 retry = DialogResult.Abort;
3103 if (retry == DialogResult.Retry)
3105 GetWorkerArg args = new GetWorkerArg();
3108 args.type = MyCommon.WORKERTYPE.PostMessage;
3109 args.status = rslt.status;
3114 if (ToolStripFocusLockMenuItem.Checked)
3116 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
3117 StatusText_Enter(StatusText, new EventArgs());
3121 if (rslt.retMsg.Length == 0 && SettingDialog.PostAndGet)
3123 if (_isActiveUserstream)
3125 RefreshTimeline(true);
3129 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3133 case MyCommon.WORKERTYPE.Retweet:
3134 if (rslt.retMsg.Length == 0)
3136 _postTimestamps.Add(DateTime.Now);
3137 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3138 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3140 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3142 _postTimestamps.RemoveAt(i);
3145 if (!_isActiveUserstream && SettingDialog.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3148 case MyCommon.WORKERTYPE.Follower:
3149 //_waitFollower = false;
3150 this.PurgeListViewItemCache();
3151 if (_curList != null) _curList.Refresh();
3153 case MyCommon.WORKERTYPE.NoRetweetIds:
3155 case MyCommon.WORKERTYPE.Configuration:
3156 //_waitFollower = false
3157 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
3159 pictureService["Twitter"].Configuration("MaxUploadFilesize", SettingDialog.TwitterConfiguration.PhotoSizeLimit);
3161 this.PurgeListViewItemCache();
3162 if (_curList != null) _curList.Refresh();
3164 case MyCommon.WORKERTYPE.PublicSearch:
3165 _waitPubSearch = false;
3167 case MyCommon.WORKERTYPE.UserTimeline:
3168 _waitUserTimeline = false;
3170 case MyCommon.WORKERTYPE.List:
3173 case MyCommon.WORKERTYPE.Related:
3174 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
3175 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
3177 foreach (TabPage tp in ListTab.TabPages)
3179 if (tp.Text == tab.TabName)
3181 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
3182 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3191 private void RemovePostFromFavTab(Int64[] ids)
3193 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3195 if (_curTab.Text.Equals(favTabName))
3197 if (_curList.FocusedItem != null)
3198 fidx = _curList.FocusedItem.Index;
3199 else if (_curList.TopItem != null)
3200 fidx = _curList.TopItem.Index;
3205 foreach (long i in ids)
3209 _statuses.RemoveFavPost(i);
3216 if (_curTab != null && _curTab.Text.Equals(favTabName))
3218 this.PurgeListViewItemCache();
3220 //_curItemIndex = -1;
3222 foreach (TabPage tp in ListTab.TabPages)
3224 if (tp.Text == favTabName)
3226 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3230 if (_curTab.Text.Equals(favTabName))
3234 _curList.SelectedIndices.Clear();
3236 while (_curList.SelectedIndices.Count > 0);
3238 if (_statuses.Tabs[favTabName].AllCount > 0)
3240 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3242 _curList.SelectedIndices.Add(fidx);
3246 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3248 if (_curList.SelectedIndices.Count > 0)
3250 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3251 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3257 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3259 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, int toPage, string tabName)
3261 if (!this.IsNetworkAvailable()) return;
3264 GetWorkerArg args = new GetWorkerArg();
3265 args.page = fromPage;
3266 args.endPage = toPage;
3268 args.tName = tabName;
3270 if (!lastTime.ContainsKey(WkType)) lastTime.Add(WkType, new DateTime());
3271 double period = DateTime.Now.Subtract(lastTime[WkType]).TotalSeconds;
3272 if (period > 1 || period < -1)
3274 lastTime[WkType] = DateTime.Now;
3278 //Timeline取得モードの場合はReplyも同時に取得
3279 //if (!SettingDialog.UseAPI &&
3281 // WkType == MyCommon.WORKERTYPE.Timeline &&
3282 // SettingDialog.CheckReply)
3284 // //TimerReply.Enabled = false;
3285 // _mentionCounter = SettingDialog.ReplyPeriodInt;
3286 // GetWorkerArg _args = new GetWorkerArg();
3287 // _args.page = fromPage;
3288 // _args.endPage = toPage;
3289 // _args.type = MyCommon.WORKERTYPE.Reply;
3294 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
3296 if (e.Button == MouseButtons.Left)
3298 this.Visible = true;
3299 if (this.WindowState == FormWindowState.Minimized)
3301 this.WindowState = _formWindowState;
3304 this.BringToFront();
3308 private void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
3310 switch (SettingDialog.ListDoubleClickAction)
3313 MakeReplyOrDirectStatus();
3316 FavoriteChange(true);
3319 if (_curPost != null)
3320 ShowUserStatus(_curPost.ScreenName, false);
3326 ShowRelatedStatusesMenuItem_Click(null, null);
3329 MoveToHomeToolStripMenuItem_Click(null, null);
3332 StatusOpenMenuItem_Click(null, null);
3340 private void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
3342 FavoriteChange(true);
3345 private void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
3347 FavoriteChange(false);
3351 private void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
3353 FavoritesRetweetOriginal();
3356 private void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
3358 FavoritesRetweetUnofficial();
3361 private void FavoriteChange(bool FavAdd , bool multiFavoriteChangeDialogEnable = true)
3363 //trueでFavAdd,falseでFavRemove
3364 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || _curList.SelectedIndices.Count == 0
3365 || !this.ExistCurrentPost) return;
3368 if (_curList.SelectedIndices.Count > 250 && FavAdd)
3370 MessageBox.Show(Properties.Resources.FavoriteLimitCountText);
3371 _DoFavRetweetFlags = false;
3374 else if (multiFavoriteChangeDialogEnable && _curList.SelectedIndices.Count > 1)
3378 string QuestionText = Properties.Resources.FavAddToolStripMenuItem_ClickText1;
3379 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText3;
3380 if (MessageBox.Show(QuestionText, Properties.Resources.FavAddToolStripMenuItem_ClickText2,
3381 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3383 _DoFavRetweetFlags = false;
3389 if (MessageBox.Show(Properties.Resources.FavRemoveToolStripMenuItem_ClickText1, Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
3390 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3397 GetWorkerArg args = new GetWorkerArg();
3398 args.ids = new List<long>();
3399 args.sIds = new List<long>();
3400 args.tName = _curTab.Text;
3403 args.type = MyCommon.WORKERTYPE.FavAdd;
3407 args.type = MyCommon.WORKERTYPE.FavRemove;
3409 foreach (int idx in _curList.SelectedIndices)
3411 PostClass post = GetCurTabPost(idx);
3414 if (!post.IsFav) args.ids.Add(post.StatusId);
3418 if (post.IsFav) args.ids.Add(post.StatusId);
3421 if (args.ids.Count == 0)
3424 StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
3426 StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
3434 private PostClass GetCurTabPost(int Index)
3436 this.itemCacheLock.EnterReadLock();
3439 if (_postCache != null && Index >= _itemCacheIndex && Index < _itemCacheIndex + _postCache.Length)
3440 return _postCache[Index - _itemCacheIndex];
3442 finally { this.itemCacheLock.ExitReadLock(); }
3444 return _statuses[_curTab.Text, Index];
3448 private void MoveToHomeToolStripMenuItem_Click(object sender, EventArgs e)
3450 if (_curList.SelectedIndices.Count > 0)
3451 OpenUriAsync(MyCommon.TwitterUrl + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName);
3452 else if (_curList.SelectedIndices.Count == 0)
3453 OpenUriAsync(MyCommon.TwitterUrl);
3456 private void MoveToFavToolStripMenuItem_Click(object sender, EventArgs e)
3458 if (_curList.SelectedIndices.Count > 0)
3459 OpenUriAsync(MyCommon.TwitterUrl + "#!/" + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName + "/favorites");
3462 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3464 if ((!_initialLayout) && this.Visible)
3466 if (this.WindowState == FormWindowState.Normal)
3468 _mySize = this.ClientSize;
3469 _mySpDis = this.SplitContainer1.SplitterDistance;
3470 _mySpDis3 = this.SplitContainer3.SplitterDistance;
3471 if (StatusText.Multiline) _mySpDis2 = this.StatusText.Height;
3472 _modifySettingLocal = true;
3477 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3479 if (SettingDialog.SortOrderLock) return;
3480 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
3483 mode = IdComparerClass.ComparerMode.Id;
3491 case 6: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
3495 mode = IdComparerClass.ComparerMode.Nickname;
3498 mode = IdComparerClass.ComparerMode.Data;
3501 mode = IdComparerClass.ComparerMode.Id;
3504 mode = IdComparerClass.ComparerMode.Name;
3507 mode = IdComparerClass.ComparerMode.Source;
3511 _statuses.ToggleSortOrder(mode);
3514 DetailsListView list = (DetailsListView)sender;
3517 list.Columns[0].Text = ColumnOrgText[0];
3518 list.Columns[1].Text = ColumnText[2];
3522 for (int i = 0; i <= 7; i++)
3524 list.Columns[i].Text = ColumnOrgText[i];
3526 list.Columns[e.Column].Text = ColumnText[e.Column];
3529 this.PurgeListViewItemCache();
3531 if (_statuses.Tabs[_curTab.Text].AllCount > 0 && _curPost != null)
3533 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_curPost.StatusId);
3536 SelectListItem(_curList, idx);
3537 _curList.EnsureVisible(idx);
3541 _modifySettingCommon = true;
3544 private void TweenMain_LocationChanged(object sender, EventArgs e)
3546 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
3548 _myLoc = this.DesktopLocation;
3549 _modifySettingLocal = true;
3553 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3555 if (ListTab.SelectedTab == null) return;
3556 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
3557 if (!this.ExistCurrentPost)
3559 ReplyStripMenuItem.Enabled = false;
3560 ReplyAllStripMenuItem.Enabled = false;
3561 DMStripMenuItem.Enabled = false;
3562 ShowProfileMenuItem.Enabled = false;
3563 ShowUserTimelineContextMenuItem.Enabled = false;
3564 ListManageUserContextToolStripMenuItem2.Enabled = false;
3565 MoveToFavToolStripMenuItem.Enabled = false;
3566 TabMenuItem.Enabled = false;
3567 IDRuleMenuItem.Enabled = false;
3568 ReadedStripMenuItem.Enabled = false;
3569 UnreadStripMenuItem.Enabled = false;
3573 ShowProfileMenuItem.Enabled = true;
3574 ListManageUserContextToolStripMenuItem2.Enabled = true;
3575 ReplyStripMenuItem.Enabled = true;
3576 ReplyAllStripMenuItem.Enabled = true;
3577 DMStripMenuItem.Enabled = true;
3578 ShowUserTimelineContextMenuItem.Enabled = true;
3579 MoveToFavToolStripMenuItem.Enabled = true;
3580 TabMenuItem.Enabled = true;
3581 IDRuleMenuItem.Enabled = true;
3582 ReadedStripMenuItem.Enabled = true;
3583 UnreadStripMenuItem.Enabled = true;
3585 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3586 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
3588 FavAddToolStripMenuItem.Enabled = false;
3589 FavRemoveToolStripMenuItem.Enabled = false;
3590 StatusOpenMenuItem.Enabled = false;
3591 FavorareMenuItem.Enabled = false;
3592 ShowRelatedStatusesMenuItem.Enabled = false;
3594 ReTweetStripMenuItem.Enabled = false;
3595 ReTweetOriginalStripMenuItem.Enabled = false;
3596 QuoteStripMenuItem.Enabled = false;
3597 FavoriteRetweetContextMenu.Enabled = false;
3598 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3599 if (this.ExistCurrentPost && _curPost.IsDm)
3600 DeleteStripMenuItem.Enabled = true;
3602 DeleteStripMenuItem.Enabled = false;
3606 FavAddToolStripMenuItem.Enabled = true;
3607 FavRemoveToolStripMenuItem.Enabled = true;
3608 StatusOpenMenuItem.Enabled = true;
3609 FavorareMenuItem.Enabled = true;
3610 ShowRelatedStatusesMenuItem.Enabled = true; //PublicSearchの時問題出るかも
3614 ReTweetOriginalStripMenuItem.Enabled = false;
3615 FavoriteRetweetContextMenu.Enabled = false;
3616 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3618 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3622 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3624 DeleteStripMenuItem.Enabled = true;
3628 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3630 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3634 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3636 DeleteStripMenuItem.Enabled = false;
3637 if (_curPost.IsProtect)
3639 ReTweetOriginalStripMenuItem.Enabled = false;
3640 ReTweetStripMenuItem.Enabled = false;
3641 QuoteStripMenuItem.Enabled = false;
3642 FavoriteRetweetContextMenu.Enabled = false;
3643 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3647 ReTweetOriginalStripMenuItem.Enabled = true;
3648 ReTweetStripMenuItem.Enabled = true;
3649 QuoteStripMenuItem.Enabled = true;
3650 FavoriteRetweetContextMenu.Enabled = true;
3651 FavoriteRetweetUnofficialContextMenu.Enabled = true;
3655 //if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
3657 // RefreshMoreStripMenuItem.Enabled = true;
3661 // RefreshMoreStripMenuItem.Enabled = false;
3663 if (!this.ExistCurrentPost
3664 || _curPost.InReplyToStatusId == null)
3666 RepliedStatusOpenMenuItem.Enabled = false;
3670 RepliedStatusOpenMenuItem.Enabled = true;
3672 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
3674 MoveToRTHomeMenuItem.Enabled = false;
3678 MoveToRTHomeMenuItem.Enabled = true;
3682 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3684 MakeReplyOrDirectStatus(false, true);
3687 private void DMStripMenuItem_Click(object sender, EventArgs e)
3689 MakeReplyOrDirectStatus(false, false);
3692 private void doStatusDelete()
3694 if (_curTab == null || _curList == null) return;
3695 if (_statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
3697 bool myPost = false;
3698 foreach (int idx in _curList.SelectedIndices)
3700 if (GetCurTabPost(idx).IsMe ||
3701 GetCurTabPost(idx).RetweetedBy.ToLower() == tw.Username.ToLower())
3707 if (!myPost) return;
3711 if (_curList.SelectedIndices.Count == 0)
3715 string tmp = string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine);
3717 if (MessageBox.Show(tmp, Properties.Resources.DeleteStripMenuItem_ClickText2,
3718 MessageBoxButtons.OKCancel,
3719 MessageBoxIcon.Question) == DialogResult.Cancel) return;
3722 if (_curList.FocusedItem != null)
3723 fidx = _curList.FocusedItem.Index;
3724 else if (_curList.TopItem != null)
3725 fidx = _curList.TopItem.Index;
3731 this.Cursor = Cursors.WaitCursor;
3734 foreach (long Id in _statuses.GetId(_curTab.Text, _curList.SelectedIndices))
3737 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
3739 rtn = tw.RemoveDirectMessage(Id, _statuses[Id]);
3743 if (_statuses[Id].IsMe || _statuses[Id].RetweetedBy.ToLower() == tw.Username.ToLower())
3744 rtn = tw.RemoveStatus(Id);
3755 _statuses.RemovePost(Id);
3760 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; //失敗
3762 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; //成功
3764 this.PurgeListViewItemCache();
3767 foreach (TabPage tb in ListTab.TabPages)
3769 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
3770 if (_curTab.Equals(tb))
3774 _curList.SelectedIndices.Clear();
3776 while (_curList.SelectedIndices.Count > 0);
3778 if (_statuses.Tabs[tb.Text].AllCount > 0)
3780 if (_statuses.Tabs[tb.Text].AllCount - 1 > fidx && fidx > -1)
3781 _curList.SelectedIndices.Add(fidx);
3783 _curList.SelectedIndices.Add(_statuses.Tabs[tb.Text].AllCount - 1);
3785 if (_curList.SelectedIndices.Count > 0)
3787 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3788 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3792 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3794 if (SettingDialog.TabIconDisp)
3796 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3800 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3804 this.Cursor = Cursors.Default;
3808 private void DeleteStripMenuItem_Click(object sender, EventArgs e)
3813 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3815 _curList.BeginUpdate();
3816 if (SettingDialog.UnreadManage)
3818 foreach (int idx in _curList.SelectedIndices)
3820 _statuses.SetReadAllTab(true, _curTab.Text, idx);
3823 foreach (int idx in _curList.SelectedIndices)
3825 ChangeCacheStyleRead(true, idx, _curTab);
3828 _curList.EndUpdate();
3829 foreach (TabPage tb in ListTab.TabPages)
3831 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3833 if (SettingDialog.TabIconDisp)
3835 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3839 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3842 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3844 _curList.BeginUpdate();
3845 if (SettingDialog.UnreadManage)
3847 foreach (int idx in _curList.SelectedIndices)
3849 _statuses.SetReadAllTab(false, _curTab.Text, idx);
3852 foreach (int idx in _curList.SelectedIndices)
3854 ChangeCacheStyleRead(false, idx, _curTab);
3857 _curList.EndUpdate();
3858 foreach (TabPage tb in ListTab.TabPages)
3860 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
3862 if (SettingDialog.TabIconDisp)
3864 if (tb.ImageIndex == -1) tb.ImageIndex = 0; //タブアイコン
3868 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3871 private void RefreshStripMenuItem_Click(object sender, EventArgs e)
3876 private void DoRefresh()
3878 if (_curTab != null)
3880 switch (_statuses.Tabs[_curTab.Text].TabType)
3882 case MyCommon.TabUsageType.Mentions:
3883 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
3885 case MyCommon.TabUsageType.DirectMessage:
3886 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
3888 case MyCommon.TabUsageType.Favorites:
3889 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, 0, "");
3891 //case MyCommon.TabUsageType.Profile:
3893 case MyCommon.TabUsageType.PublicSearch:
3895 TabClass tb = _statuses.Tabs[_curTab.Text];
3896 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3897 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, _curTab.Text);
3899 case MyCommon.TabUsageType.UserTimeline:
3900 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, _curTab.Text);
3902 case MyCommon.TabUsageType.Lists:
3904 TabClass tab = _statuses.Tabs[_curTab.Text];
3905 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3906 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, _curTab.Text);
3909 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3915 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3919 private void DoRefreshMore()
3922 if (_curTab != null)
3924 switch (_statuses.Tabs[_curTab.Text].TabType)
3926 case MyCommon.TabUsageType.Mentions:
3927 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, 0, "");
3929 case MyCommon.TabUsageType.DirectMessage:
3930 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, 0, "");
3932 case MyCommon.TabUsageType.Favorites:
3933 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, 0, "");
3935 case MyCommon.TabUsageType.Profile:
3938 case MyCommon.TabUsageType.PublicSearch:
3940 TabClass tb = _statuses.Tabs[_curTab.Text];
3941 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3942 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, -1, 0, _curTab.Text);
3944 case MyCommon.TabUsageType.UserTimeline:
3945 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, 0, _curTab.Text);
3947 case MyCommon.TabUsageType.Lists:
3949 TabClass tab = _statuses.Tabs[_curTab.Text];
3950 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3951 GetTimeline(MyCommon.WORKERTYPE.List, -1, 0, _curTab.Text);
3954 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, 0, "");
3960 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, 0, "");
3964 private void SettingStripMenuItem_Click(object sender, EventArgs e)
3966 DialogResult result;
3967 string uid = tw.Username.ToLower();
3968 var oldIconSz = SettingDialog.IconSz;
3972 result = SettingDialog.ShowDialog(this);
3979 if (result == DialogResult.OK)
3983 tw.TinyUrlResolve = SettingDialog.TinyUrlResolve;
3984 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
3985 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
3986 ShortUrl.IsResolve = SettingDialog.TinyUrlResolve;
3987 ShortUrl.BitlyId = SettingDialog.BitlyUser;
3988 ShortUrl.BitlyKey = SettingDialog.BitlyPwd;
3989 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3991 HttpConnection.InitializeConnection(SettingDialog.DefaultTimeOut,
3992 SettingDialog.SelectedProxyType,
3993 SettingDialog.ProxyAddress,
3994 SettingDialog.ProxyPort,
3995 SettingDialog.ProxyUser,
3996 SettingDialog.ProxyPassword);
3997 this.CreatePictureServices();
4001 if (SettingDialog.TabIconDisp)
4003 ListTab.DrawItem -= ListTab_DrawItem;
4004 ListTab.DrawMode = TabDrawMode.Normal;
4005 ListTab.ImageList = this.TabImage;
4009 ListTab.DrawItem -= ListTab_DrawItem;
4010 ListTab.DrawItem += ListTab_DrawItem;
4011 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
4012 ListTab.ImageList = null;
4015 catch (Exception ex)
4017 ex.Data["Instance"] = "ListTab(TabIconDisp)";
4018 ex.Data["IsTerminatePermission"] = false;
4024 if (!SettingDialog.UnreadManage)
4026 ReadedStripMenuItem.Enabled = false;
4027 UnreadStripMenuItem.Enabled = false;
4028 if (SettingDialog.TabIconDisp)
4030 foreach (TabPage myTab in ListTab.TabPages)
4032 myTab.ImageIndex = -1;
4038 ReadedStripMenuItem.Enabled = true;
4039 UnreadStripMenuItem.Enabled = true;
4042 catch (Exception ex)
4044 ex.Data["Instance"] = "ListTab(UnreadManage)";
4045 ex.Data["IsTerminatePermission"] = false;
4052 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
4053 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
4054 _fntUnread = SettingDialog.FontUnread;
4055 _clUnread = SettingDialog.ColorUnread;
4056 _fntReaded = SettingDialog.FontReaded;
4057 _clReaded = SettingDialog.ColorReaded;
4058 _clFav = SettingDialog.ColorFav;
4059 _clOWL = SettingDialog.ColorOWL;
4060 _clRetweet = SettingDialog.ColorRetweet;
4061 _fntDetail = SettingDialog.FontDetail;
4062 _clDetail = SettingDialog.ColorDetail;
4063 _clDetailLink = SettingDialog.ColorDetailLink;
4064 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
4065 _clSelf = SettingDialog.ColorSelf;
4066 _clAtSelf = SettingDialog.ColorAtSelf;
4067 _clTarget = SettingDialog.ColorTarget;
4068 _clAtTarget = SettingDialog.ColorAtTarget;
4069 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
4070 _clAtTo = SettingDialog.ColorAtTo;
4071 _clListBackcolor = SettingDialog.ColorListBackcolor;
4072 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
4073 _clInputFont = SettingDialog.ColorInputFont;
4074 _fntInputFont = SettingDialog.FontInputFont;
4075 _brsBackColorMine.Dispose();
4076 _brsBackColorAt.Dispose();
4077 _brsBackColorYou.Dispose();
4078 _brsBackColorAtYou.Dispose();
4079 _brsBackColorAtFromTarget.Dispose();
4080 _brsBackColorAtTo.Dispose();
4081 _brsBackColorNone.Dispose();
4082 _brsBackColorMine = new SolidBrush(_clSelf);
4083 _brsBackColorAt = new SolidBrush(_clAtSelf);
4084 _brsBackColorYou = new SolidBrush(_clTarget);
4085 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
4086 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
4087 _brsBackColorAtTo = new SolidBrush(_clAtTo);
4088 _brsBackColorNone = new SolidBrush(_clListBackcolor);
4092 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
4093 StatusText.Font = _fntInputFont;
4094 StatusText.ForeColor = _clInputFont;
4096 catch (Exception ex)
4098 MessageBox.Show(ex.Message);
4103 if (SettingDialog.IsMonospace)
4105 detailHtmlFormatHeader = detailHtmlFormatMono1;
4106 detailHtmlFormatFooter = detailHtmlFormatMono7;
4110 detailHtmlFormatHeader = detailHtmlFormat1;
4111 detailHtmlFormatFooter = detailHtmlFormat7;
4113 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();
4114 if (SettingDialog.IsMonospace)
4116 detailHtmlFormatHeader += detailHtmlFormatMono6;
4120 detailHtmlFormatHeader += detailHtmlFormat6;
4123 catch (Exception ex)
4125 ex.Data["Instance"] = "Font";
4126 ex.Data["IsTerminatePermission"] = false;
4132 _statuses.SetUnreadManage(SettingDialog.UnreadManage);
4134 catch (Exception ex)
4136 ex.Data["Instance"] = "_statuses";
4137 ex.Data["IsTerminatePermission"] = false;
4143 foreach (TabPage tb in ListTab.TabPages)
4145 if (SettingDialog.TabIconDisp)
4147 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
4154 catch (Exception ex)
4156 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
4157 ex.Data["IsTerminatePermission"] = false;
4163 foreach (TabPage tp in ListTab.TabPages)
4165 DetailsListView lst = (DetailsListView)tp.Tag;
4169 lst.GridLines = SettingDialog.ShowGrid;
4170 lst.Font = _fntReaded;
4171 lst.BackColor = _clListBackcolor;
4173 if (SettingDialog.IconSz != oldIconSz)
4174 ApplyListViewIconSize(lst);
4179 catch (Exception ex)
4181 ex.Data["Instance"] = "ListView(IconSize)";
4182 ex.Data["IsTerminatePermission"] = false;
4186 SetMainWindowTitle();
4187 SetNotifyIconText();
4189 this.PurgeListViewItemCache();
4190 if (_curList != null) _curList.Refresh();
4193 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4194 if (SettingDialog.HotkeyEnabled)
4196 ///グローバルホットキーの登録。設定で変更可能にするかも
4197 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4198 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
4199 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
4200 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
4201 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
4203 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
4206 if (uid != tw.Username) this.doGetFollowersMenu();
4208 SetImageServiceCombo();
4209 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
4212 StatusText_TextChanged(null, null);
4220 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4222 this.TopMost = SettingDialog.AlwaysTop;
4223 SaveConfigsAll(false);
4229 private void SetTabAlignment()
4231 ListTab.Alignment = (SettingDialog.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top);
4234 private void ApplyListViewIconSize(DetailsListView list)
4237 list.SuspendLayout();
4241 switch (SettingDialog.IconSz)
4243 case MyCommon.IconSizes.IconNone:
4246 case MyCommon.IconSizes.Icon16:
4249 case MyCommon.IconSizes.Icon24:
4252 case MyCommon.IconSizes.Icon48:
4255 case MyCommon.IconSizes.Icon48_2:
4267 tw.IconSize = _iconSz;
4272 // ディスプレイの DPI 設定を考慮したサイズを設定する
4273 list.SmallImageList.ImageSize = new Size(
4274 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Width),
4275 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4279 list.SmallImageList.ImageSize = new Size(1, 1);
4283 list.ColumnClick -= MyList_ColumnClick;
4284 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4285 list.ColumnReordered -= MyList_ColumnReordered;
4286 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4288 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4289 list.Columns.Clear();
4290 cols.ForEach(col => col.Dispose());
4293 InitColumns(list, true);
4295 list.ColumnClick += MyList_ColumnClick;
4296 list.DrawColumnHeader += MyList_DrawColumnHeader;
4297 list.ColumnReordered += MyList_ColumnReordered;
4298 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4300 list.ResumeLayout(false);
4304 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4306 if (e.Url.AbsoluteUri != "about:blank")
4309 OpenUriAsync(e.Url.OriginalString);
4313 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4315 if (e.Url.Scheme == "data")
4317 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4319 else if (e.Url.AbsoluteUri != "about:blank")
4323 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4324 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4327 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4328 int i = urlStr.IndexOf('#');
4329 if (i == -1) return;
4331 string hash = urlStr.Substring(i);
4332 HashSupl.AddItem(hash);
4333 HashMgr.AddHashToHistory(hash.Trim(), false);
4334 AddNewTabForSearch(hash);
4339 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4340 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4342 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4343 if (SettingDialog.OpenUserTimeline)
4345 if (MyCommon.IsKeyDown(Keys.Control))
4346 OpenUriAsync(e.Url.OriginalString);
4348 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4352 if (MyCommon.IsKeyDown(Keys.Control))
4353 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4355 OpenUriAsync(e.Url.OriginalString);
4360 OpenUriAsync(e.Url.OriginalString);
4366 public void AddNewTabForSearch(string searchWord)
4368 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4369 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4371 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4373 foreach (TabPage tp in ListTab.TabPages)
4375 if (tb.TabName == tp.Text)
4377 ListTab.SelectedTab = tp;
4384 string tabName = searchWord;
4385 for (int i = 0; i <= 100; i++)
4387 if (_statuses.ContainsTab(tabName))
4393 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4394 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4396 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4398 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4399 cmb.Items.Add(searchWord);
4400 cmb.Text = searchWord;
4403 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4406 private void ShowUserTimeline()
4408 if (!this.ExistCurrentPost) return;
4409 AddNewTabForUserTimeline(_curPost.ScreenName);
4412 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4414 if (e.KeyCode == Keys.Escape)
4416 TabPage relTp = ListTab.SelectedTab;
4417 RemoveSpecifiedTab(relTp.Text, false);
4419 e.SuppressKeyPress = true;
4423 public void AddNewTabForUserTimeline(string user)
4425 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4426 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4428 if (tb.User == user)
4430 foreach (TabPage tp in ListTab.TabPages)
4432 if (tb.TabName == tp.Text)
4434 ListTab.SelectedTab = tp;
4441 string tabName = "user:" + user;
4442 while (_statuses.ContainsTab(tabName))
4447 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4448 _statuses.Tabs[tabName].User = user;
4449 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4451 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4455 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, tabName);
4458 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4461 foreach (TabPage tb in ListTab.TabPages)
4463 if (tb.Text == tabName) return false;
4467 if (tabName == Properties.Resources.AddNewTabText1) return false;
4472 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4473 tabType == MyCommon.TabUsageType.Favorites ||
4474 tabType == MyCommon.TabUsageType.Home ||
4475 tabType == MyCommon.TabUsageType.Mentions ||
4476 tabType == MyCommon.TabUsageType.Related)
4478 if (_statuses.GetTabByType(tabType) != null) return false;
4482 TabPage _tabPage = new TabPage();
4483 DetailsListView _listCustom = new DetailsListView();
4485 int cnt = ListTab.TabPages.Count;
4487 ///ToDo:Create and set controls follow tabtypes
4489 _listCustom.BeginUpdate();
4490 this.SplitContainer1.Panel1.SuspendLayout();
4491 this.SplitContainer1.Panel2.SuspendLayout();
4492 this.SplitContainer1.SuspendLayout();
4493 this.ListTab.SuspendLayout();
4494 this.SuspendLayout();
4496 _tabPage.SuspendLayout();
4500 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4502 label = new Label();
4503 label.Dock = DockStyle.Top;
4504 label.Name = "labelUser";
4505 if (tabType == MyCommon.TabUsageType.Lists)
4507 label.Text = listInfo.ToString();
4511 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4513 label.TextAlign = ContentAlignment.MiddleLeft;
4514 using (ComboBox tmpComboBox = new ComboBox())
4516 label.Height = tmpComboBox.Height;
4518 _tabPage.Controls.Add(label);
4523 if (tabType == MyCommon.TabUsageType.PublicSearch)
4527 Label lbl = new Label();
4528 ComboBox cmb = new ComboBox();
4529 Button btn = new Button();
4530 ComboBox cmbLang = new ComboBox();
4532 pnl.SuspendLayout();
4534 pnl.Controls.Add(cmb);
4535 pnl.Controls.Add(cmbLang);
4536 pnl.Controls.Add(btn);
4537 pnl.Controls.Add(lbl);
4538 pnl.Name = "panelSearch";
4539 pnl.Dock = DockStyle.Top;
4540 pnl.Height = cmb.Height;
4541 pnl.Enter += SearchControls_Enter;
4542 pnl.Leave += SearchControls_Leave;
4545 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4546 cmb.Dock = DockStyle.Fill;
4547 cmb.Name = "comboSearch";
4548 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4549 cmb.ImeMode = ImeMode.NoControl;
4550 cmb.TabStop = false;
4551 cmb.AutoCompleteMode = AutoCompleteMode.None;
4552 cmb.KeyDown += SearchComboBox_KeyDown;
4554 if (_statuses.ContainsTab(tabName))
4556 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4557 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4561 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4562 cmbLang.Dock = DockStyle.Right;
4564 cmbLang.Name = "comboLang";
4565 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4566 cmbLang.TabStop = false;
4567 cmbLang.Items.Add("");
4568 cmbLang.Items.Add("ja");
4569 cmbLang.Items.Add("en");
4570 cmbLang.Items.Add("ar");
4571 cmbLang.Items.Add("da");
4572 cmbLang.Items.Add("nl");
4573 cmbLang.Items.Add("fa");
4574 cmbLang.Items.Add("fi");
4575 cmbLang.Items.Add("fr");
4576 cmbLang.Items.Add("de");
4577 cmbLang.Items.Add("hu");
4578 cmbLang.Items.Add("is");
4579 cmbLang.Items.Add("it");
4580 cmbLang.Items.Add("no");
4581 cmbLang.Items.Add("pl");
4582 cmbLang.Items.Add("pt");
4583 cmbLang.Items.Add("ru");
4584 cmbLang.Items.Add("es");
4585 cmbLang.Items.Add("sv");
4586 cmbLang.Items.Add("th");
4587 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4589 lbl.Text = "Search(C-S-f)";
4590 lbl.Name = "label1";
4591 lbl.Dock = DockStyle.Left;
4593 lbl.Height = cmb.Height;
4594 lbl.TextAlign = ContentAlignment.MiddleLeft;
4596 btn.Text = "Search";
4597 btn.Name = "buttonSearch";
4598 btn.UseVisualStyleBackColor = true;
4599 btn.Dock = DockStyle.Right;
4600 btn.TabStop = false;
4601 btn.Click += SearchButton_Click;
4604 this.ListTab.Controls.Add(_tabPage);
4605 _tabPage.Controls.Add(_listCustom);
4607 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4608 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4610 _tabPage.Location = new Point(4, 4);
4611 _tabPage.Name = "CTab" + cnt.ToString();
4612 _tabPage.Size = new Size(380, 260);
4613 _tabPage.TabIndex = 2 + cnt;
4614 _tabPage.Text = tabName;
4615 _tabPage.UseVisualStyleBackColor = true;
4617 _listCustom.AllowColumnReorder = true;
4618 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4619 _listCustom.Dock = DockStyle.Fill;
4620 _listCustom.FullRowSelect = true;
4621 _listCustom.HideSelection = false;
4622 _listCustom.Location = new Point(0, 0);
4623 _listCustom.Margin = new Padding(0);
4624 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4625 _listCustom.ShowItemToolTips = true;
4626 _listCustom.Size = new Size(380, 260);
4627 _listCustom.UseCompatibleStateImageBehavior = false;
4628 _listCustom.View = View.Details;
4629 _listCustom.OwnerDraw = true;
4630 _listCustom.VirtualMode = true;
4631 _listCustom.Font = _fntReaded;
4632 _listCustom.BackColor = _clListBackcolor;
4634 _listCustom.GridLines = SettingDialog.ShowGrid;
4635 _listCustom.AllowDrop = true;
4637 _listCustom.SmallImageList = new ImageList();
4640 // ディスプレイの DPI 設定を考慮したサイズを設定する
4641 _listCustom.SmallImageList.ImageSize = new Size(
4642 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Width),
4643 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4647 _listCustom.SmallImageList.ImageSize = new Size(1, 1);
4650 InitColumns(_listCustom, startup);
4652 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4653 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4654 _listCustom.ColumnClick += MyList_ColumnClick;
4655 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4656 _listCustom.DragDrop += TweenMain_DragDrop;
4657 _listCustom.DragOver += TweenMain_DragOver;
4658 _listCustom.DrawItem += MyList_DrawItem;
4659 _listCustom.MouseClick += MyList_MouseClick;
4660 _listCustom.ColumnReordered += MyList_ColumnReordered;
4661 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4662 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4663 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4664 _listCustom.DrawSubItem += MyList_DrawSubItem;
4665 _listCustom.HScrolled += MyList_HScrolled;
4667 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4669 _tabPage.ResumeLayout(false);
4671 this.SplitContainer1.Panel1.ResumeLayout(false);
4672 this.SplitContainer1.Panel2.ResumeLayout(false);
4673 this.SplitContainer1.ResumeLayout(false);
4674 this.ListTab.ResumeLayout(false);
4675 this.ResumeLayout(false);
4676 this.PerformLayout();
4677 _listCustom.EndUpdate();
4678 _tabPage.Tag = _listCustom;
4682 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4684 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4688 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4689 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4690 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4696 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4697 if (_tabPage == null) return false;
4699 SetListProperty(); //他のタブに列幅等を反映
4701 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4704 this.SplitContainer1.Panel1.SuspendLayout();
4705 this.SplitContainer1.Panel2.SuspendLayout();
4706 this.SplitContainer1.SuspendLayout();
4707 this.ListTab.SuspendLayout();
4708 this.SuspendLayout();
4710 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4711 _tabPage.Tag = null;
4713 _tabPage.SuspendLayout();
4715 if (this.ListTab.SelectedTab == _tabPage)
4717 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4718 this._beforeSelectedTab = null;
4720 this.ListTab.Controls.Remove(_tabPage);
4723 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4725 using (Control label = _tabPage.Controls["labelUser"])
4727 _tabPage.Controls.Remove(label);
4730 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4732 using (Control pnl = _tabPage.Controls["panelSearch"])
4734 pnl.Enter -= SearchControls_Enter;
4735 pnl.Leave -= SearchControls_Leave;
4736 _tabPage.Controls.Remove(pnl);
4738 foreach (Control ctrl in pnl.Controls)
4740 if (ctrl.Name == "buttonSearch")
4742 ctrl.Click -= SearchButton_Click;
4744 else if (ctrl.Name == "comboSearch")
4746 ctrl.KeyDown -= SearchComboBox_KeyDown;
4748 pnl.Controls.Remove(ctrl);
4754 _tabPage.Controls.Remove(_listCustom);
4756 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4757 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4758 _listCustom.ColumnClick -= MyList_ColumnClick;
4759 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4760 _listCustom.DragDrop -= TweenMain_DragDrop;
4761 _listCustom.DragOver -= TweenMain_DragOver;
4762 _listCustom.DrawItem -= MyList_DrawItem;
4763 _listCustom.MouseClick -= MyList_MouseClick;
4764 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4765 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4766 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4767 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4768 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4769 _listCustom.HScrolled -= MyList_HScrolled;
4771 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4772 _listCustom.Columns.Clear();
4773 cols.ForEach(col => col.Dispose());
4776 _listCustom.ContextMenuStrip = null;
4777 _listCustom.Font = null;
4779 _listCustom.SmallImageList.Dispose();
4780 _listCustom.SmallImageList = null;
4781 _listCustom.ListViewItemSorter = null;
4784 if (_curTab.Equals(_tabPage))
4791 this.PurgeListViewItemCache();
4793 _tabPage.ResumeLayout(false);
4795 this.SplitContainer1.Panel1.ResumeLayout(false);
4796 this.SplitContainer1.Panel2.ResumeLayout(false);
4797 this.SplitContainer1.ResumeLayout(false);
4798 this.ListTab.ResumeLayout(false);
4799 this.ResumeLayout(false);
4800 this.PerformLayout();
4803 _listCustom.Dispose();
4804 _statuses.RemoveTab(TabName);
4806 foreach (TabPage tp in ListTab.TabPages)
4808 DetailsListView lst = (DetailsListView)tp.Tag;
4809 var count = _statuses.Tabs[tp.Text].AllCount;
4810 if (lst.VirtualListSize != count)
4812 lst.VirtualListSize = count;
4819 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4821 this.PurgeListViewItemCache();
4822 _beforeSelectedTab = e.TabPage;
4825 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4829 if (!SettingDialog.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4832 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4833 if (!dragEnableRectangle.Contains(e.Location))
4835 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4836 tn = ListTab.SelectedTab.Text;
4839 if (string.IsNullOrEmpty(tn)) return;
4841 foreach (TabPage tb in ListTab.TabPages)
4845 ListTab.DoDragDrop(tb, DragDropEffects.All);
4855 Point cpos = new Point(e.X, e.Y);
4856 for (int i = 0; i < ListTab.TabPages.Count; i++)
4858 Rectangle rect = ListTab.GetTabRect(i);
4859 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4860 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4862 _rclickTabName = ListTab.TabPages[i].Text;
4868 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4870 //_curList.Refresh();
4872 SetMainWindowTitle();
4873 SetStatusLabelUrl();
4874 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4875 TabMenuControl(ListTab.SelectedTab.Text);
4876 this.PushSelectPostChain();
4879 private void SetListProperty()
4881 //削除などで見つからない場合は処理せず
4882 if (_curList == null) return;
4883 if (!_isColumnChanged) return;
4885 int[] dispOrder = new int[_curList.Columns.Count];
4886 for (int i = 0; i < _curList.Columns.Count; i++)
4888 for (int j = 0; j < _curList.Columns.Count; j++)
4890 if (_curList.Columns[j].DisplayIndex == i)
4899 foreach (TabPage tb in ListTab.TabPages)
4901 if (!tb.Equals(_curTab))
4903 if (tb.Tag != null && tb.Controls.Count > 0)
4905 DetailsListView lst = (DetailsListView)tb.Tag;
4906 for (int i = 0; i < lst.Columns.Count; i++)
4908 lst.Columns[dispOrder[i]].DisplayIndex = i;
4909 lst.Columns[i].Width = _curList.Columns[i].Width;
4915 _isColumnChanged = false;
4918 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4922 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4923 || PostBrowser.StatusText.StartsWith("data"))
4925 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4927 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4929 SetStatusLabelUrl();
4937 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4939 if (e.KeyChar == '@')
4941 if (!SettingDialog.UseAtIdSupplement) return;
4943 int cnt = AtIdSupl.ItemCount;
4944 ShowSuplDialog(StatusText, AtIdSupl);
4945 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4948 else if (e.KeyChar == '#')
4950 if (!SettingDialog.UseHashSupplement) return;
4951 ShowSuplDialog(StatusText, HashSupl);
4956 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4958 ShowSuplDialog(owner, dialog, 0, "");
4961 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4963 ShowSuplDialog(owner, dialog, offset, "");
4966 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4968 dialog.StartsWith = startswith;
4975 dialog.ShowDialog();
4977 this.TopMost = SettingDialog.AlwaysTop;
4978 int selStart = owner.SelectionStart;
4981 if (dialog.DialogResult == DialogResult.OK)
4983 if (!string.IsNullOrEmpty(dialog.inputText))
4987 fHalf = owner.Text.Substring(0, selStart - offset);
4989 if (selStart < owner.Text.Length)
4991 eHalf = owner.Text.Substring(selStart);
4993 owner.Text = fHalf + dialog.inputText + eHalf;
4994 owner.SelectionStart = selStart + dialog.inputText.Length;
5001 fHalf = owner.Text.Substring(0, selStart);
5003 if (selStart < owner.Text.Length)
5005 eHalf = owner.Text.Substring(selStart);
5007 owner.Text = fHalf + eHalf;
5010 owner.SelectionStart = selStart;
5016 private void StatusText_KeyUp(object sender, KeyEventArgs e)
5019 if (!e.Alt && !e.Control && !e.Shift)
5021 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
5023 bool isSpace = false;
5024 foreach (char c in StatusText.Text.ToCharArray())
5026 if (c == ' ' || c == ' ')
5039 StatusText.Text = "";
5040 JumpUnreadMenuItem_Click(null, null);
5044 this.StatusText_TextChanged(null, null);
5047 private void StatusText_TextChanged(object sender, EventArgs e)
5050 int pLen = GetRestStatusCount(true, false);
5051 lblLen.Text = pLen.ToString();
5054 StatusText.ForeColor = Color.Red;
5058 StatusText.ForeColor = _clInputFont;
5060 if (string.IsNullOrEmpty(StatusText.Text))
5062 _reply_to_id = null;
5063 _reply_to_name = null;
5067 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
5070 var statusText = this.StatusText.Text;
5071 statusText = statusText.Replace("\r\n", "\n");
5073 int pLen = 140 - statusText.Length;
5074 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
5075 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && SettingDialog.PostShiftEnter) ||
5076 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !SettingDialog.PostShiftEnter) ||
5077 (!isAuto && isAddFooter))
5079 if (SettingDialog.UseRecommendStatus)
5080 pLen -= SettingDialog.RecommendStatusText.Length;
5081 else if (SettingDialog.Status.Length > 0)
5082 pLen -= SettingDialog.Status.Length + 1;
5084 if (!string.IsNullOrEmpty(HashMgr.UseHash))
5086 pLen -= HashMgr.UseHash.Length + 1;
5088 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
5090 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5092 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
5094 string before = m.Result("${before}");
5095 string url = m.Result("${url}");
5096 string protocol = m.Result("${protocol}");
5097 string domain = m.Result("${domain}");
5098 string path = m.Result("${path}");
5099 if (protocol.Length == 0)
5101 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
5106 bool last_url_invalid_match = false;
5107 string lasturl = null;
5108 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
5110 lasturl = mm.ToString();
5111 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
5112 if (!last_url_invalid_match)
5114 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5118 if (path.Length != 0)
5120 if (last_url_invalid_match)
5122 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5124 pLen += path.Length;
5129 int shortUrlLength = protocol == "https://"
5130 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
5131 : SettingDialog.TwitterConfiguration.ShortUrlLength;
5133 pLen += url.Length - shortUrlLength;
5136 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
5138 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5141 if (ImageSelectionPanel.Visible && ImageSelectedPicture.Tag != null && !string.IsNullOrEmpty(this.ImageService))
5143 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
5148 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
5150 this.itemCacheLock.EnterUpgradeableReadLock();
5153 if (_curList.Equals(sender))
5155 if (_itemCache != null &&
5156 e.StartIndex >= _itemCacheIndex &&
5157 e.EndIndex < _itemCacheIndex + _itemCache.Length)
5159 //If the newly requested cache is a subset of the old cache,
5160 //no need to rebuild everything, so do nothing.
5164 //Now we need to rebuild the cache.
5165 CreateCache(e.StartIndex, e.EndIndex);
5168 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
5171 private void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
5173 ListViewItem cacheItem = null;
5174 PostClass cacheItemPost = null;
5176 this.TryGetListViewItemCache(e.ItemIndex, out cacheItem, out cacheItemPost);
5178 if (cacheItem != null)
5184 //A cache miss, so create a new ListViewItem and pass it back.
5185 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
5188 e.Item = CreateItem(tb,
5189 _statuses[tb.Text, e.ItemIndex],
5195 string[] sitem = {"", "", "", "", "", "", "", ""};
5196 e.Item = new ImageListViewItem(sitem);
5201 private void CreateCache(int StartIndex, int EndIndex)
5203 this.itemCacheLock.EnterWriteLock();
5206 //キャッシュ要求(要求範囲±30を作成)
5208 if (StartIndex < 0) StartIndex = 0;
5210 if (EndIndex >= _statuses.Tabs[_curTab.Text].AllCount) EndIndex = _statuses.Tabs[_curTab.Text].AllCount - 1;
5211 _postCache = _statuses[_curTab.Text, StartIndex, EndIndex]; //配列で取得
5212 _itemCacheIndex = StartIndex;
5214 _itemCache = new ListViewItem[0] {};
5215 Array.Resize(ref _itemCache, _postCache.Length);
5217 for (int i = 0; i < _postCache.Length; i++)
5219 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5224 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5226 _itemCacheIndex = -1;
5229 finally { this.itemCacheLock.ExitWriteLock(); }
5233 /// DetailsListView のための ListViewItem のキャッシュを消去する
5235 private void PurgeListViewItemCache()
5237 this.itemCacheLock.EnterWriteLock();
5240 this._itemCache = null;
5241 this._itemCacheIndex = -1;
5242 this._postCache = null;
5244 finally { this.itemCacheLock.ExitWriteLock(); }
5247 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5249 this.itemCacheLock.EnterReadLock();
5252 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5254 item = this._itemCache[index - _itemCacheIndex];
5255 post = this._postCache[index - _itemCacheIndex];
5259 finally { this.itemCacheLock.ExitReadLock(); }
5266 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5268 StringBuilder mk = new StringBuilder();
5269 //if (Post.IsDeleted) mk.Append("×");
5270 //if (Post.IsMark) mk.Append("♪");
5271 //if (Post.IsProtect) mk.Append("Ю");
5272 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5273 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5274 ImageListViewItem itm;
5275 if (Post.RetweetedId == null)
5277 string[] sitem= {"",
5279 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5280 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5285 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5289 string[] sitem = {"",
5291 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5292 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5293 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5297 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5299 itm.StateImageIndex = Post.StateIndex;
5301 bool read = Post.IsRead;
5302 //未読管理していなかったら既読として扱う
5303 if (!_statuses.Tabs[Tab.Text].UnreadManage || !SettingDialog.UnreadManage) read = true;
5304 ChangeItemStyleRead(read, itm, Post, null);
5305 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5309 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5311 e.DrawDefault = true;
5314 private void MyList_HScrolled(object sender, EventArgs e)
5316 DetailsListView listView = (DetailsListView)sender;
5320 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5322 if (e.State == 0) return;
5323 e.DrawDefault = false;
5324 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5326 SolidBrush brs2 = null;
5328 if (e.Item.BackColor == _clSelf)
5329 brs2 = _brsBackColorMine;
5330 else if (e.Item.BackColor == _clAtSelf)
5331 brs2 = _brsBackColorAt;
5332 else if (e.Item.BackColor == _clTarget)
5333 brs2 = _brsBackColorYou;
5334 else if (e.Item.BackColor == _clAtTarget)
5335 brs2 = _brsBackColorAtYou;
5336 else if (e.Item.BackColor == _clAtFromTarget)
5337 brs2 = _brsBackColorAtFromTarget;
5338 else if (e.Item.BackColor == _clAtTo)
5339 brs2 = _brsBackColorAtTo;
5341 brs2 = _brsBackColorNone;
5343 e.Graphics.FillRectangle(brs2, e.Bounds);
5348 if (((Control)sender).Focused)
5349 e.Graphics.FillRectangle(_brsHighLight, e.Bounds);
5351 e.Graphics.FillRectangle(_brsDeactiveSelection, e.Bounds);
5353 if ((e.State & ListViewItemStates.Focused) == ListViewItemStates.Focused) e.DrawFocusRectangle();
5354 this.DrawListViewItemIcon(e);
5357 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5359 if (e.ItemState == 0) return;
5361 if (e.ColumnIndex > 0)
5364 RectangleF rct = e.Bounds;
5365 rct.Width = e.Header.Width;
5368 rct.Y += e.Item.Font.Height;
5369 rct.Height -= e.Item.Font.Height;
5373 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, e.Item.Font.Height, out heightDiff));
5375 //if (heightDiff > e.Item.Font.Height * 0.7)
5377 // rct.Height += e.Item.Font.Height;
5378 // drawLineCount += 1;
5381 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5382 if (!_iconCol && drawLineCount <= 1)
5384 //rct.Inflate(0, heightDiff / -2);
5385 //rct.Height += e.Item.Font.Height / 2;
5387 else if (heightDiff < e.Item.Font.Height * 0.7)
5389 //最終行が70%以上欠けていたら、最終行は表示しない
5390 //rct.Height = (float)((e.Item.Font.Height * drawLineCount) + (e.Item.Font.Height / 2));
5391 rct.Height = (e.Item.Font.Height * drawLineCount) - 1;
5398 //if (!_iconCol && drawLineCount > 1)
5400 // rct.Y += e.Item.Font.Height * 0.2;
5401 // if (heightDiff >= e.Item.Font.Height * 0.8) rct.Height -= e.Item.Font.Height * 0.2;
5406 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5407 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5412 RectangleF rctB = e.Bounds;
5413 rctB.Width = e.Header.Width;
5414 rctB.Height = e.Item.Font.Height;
5416 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5418 TextRenderer.DrawText(e.Graphics,
5419 e.Item.SubItems[2].Text,
5421 Rectangle.Round(rct),
5423 TextFormatFlags.WordBreak |
5424 TextFormatFlags.EndEllipsis |
5425 TextFormatFlags.GlyphOverhangPadding |
5426 TextFormatFlags.NoPrefix);
5427 TextRenderer.DrawText(e.Graphics,
5428 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 + "]",
5430 Rectangle.Round(rctB),
5432 TextFormatFlags.SingleLine |
5433 TextFormatFlags.EndEllipsis |
5434 TextFormatFlags.GlyphOverhangPadding |
5435 TextFormatFlags.NoPrefix);
5438 else if (drawLineCount == 1)
5440 TextRenderer.DrawText(e.Graphics,
5443 Rectangle.Round(rct),
5445 TextFormatFlags.SingleLine |
5446 TextFormatFlags.EndEllipsis |
5447 TextFormatFlags.GlyphOverhangPadding |
5448 TextFormatFlags.NoPrefix |
5449 TextFormatFlags.VerticalCenter);
5453 TextRenderer.DrawText(e.Graphics,
5456 Rectangle.Round(rct),
5458 TextFormatFlags.WordBreak |
5459 TextFormatFlags.EndEllipsis |
5460 TextFormatFlags.GlyphOverhangPadding |
5461 TextFormatFlags.NoPrefix);
5463 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5468 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5470 ImageListViewItem item = (ImageListViewItem)e.Item;
5472 //e.Bounds.Leftが常に0を指すから自前で計算
5473 Rectangle itemRect = item.Bounds;
5474 itemRect.Width = e.Item.ListView.Columns[0].Width;
5476 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5478 if (clm.DisplayIndex < e.Item.ListView.Columns[0].DisplayIndex)
5479 itemRect.X += clm.Width;
5482 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5483 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5484 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5487 Rectangle stateRect;
5488 if (item.Image != null)
5490 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5491 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5492 stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + iconRect.Width + 2, iconRect.Y), realStateSize), itemRect);
5496 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5497 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5498 stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + iconRect.Width + 2, iconRect.Y), realStateSize), itemRect);
5501 var img = item.Image;
5502 if (img != null && iconRect.Width > 0)
5504 e.Graphics.FillRectangle(Brushes.White, iconRect);
5505 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5508 e.Graphics.DrawImage(img.Image, iconRect);
5510 catch (ArgumentException)
5512 item.RefreshImage();
5516 if (item.StateImageIndex > -1)
5518 if (stateRect.Width > 0)
5520 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5521 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5522 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateImageIndex], stateRect);
5527 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5529 base.ScaleControl(factor, specified);
5531 const int baseDpi = 96;
5533 // デザイン時の DPI (96dpi) との比を更新する
5534 this.currentScaleFactor = new SizeF(
5535 this.CurrentAutoScaleDimensions.Width / baseDpi,
5536 this.CurrentAutoScaleDimensions.Height / baseDpi);
5539 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5541 // ImageListViewItem item = (ImageListViewItem)e.Item;
5542 // if (item.StateImageIndex > -1)
5544 // ////e.Bounds.Leftが常に0を指すから自前で計算
5545 // //Rectangle itemRect = item.Bounds;
5546 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5548 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5550 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5552 // // itemRect.X += clm.Width;
5556 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5557 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5559 // if (rct.Width > 0)
5561 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5562 // //e.Graphics.FillRectangle(Brushes.White, rct);
5563 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5564 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5569 private void DoTabSearch(string _word,
5579 if (_curList.VirtualListSize == 0)
5581 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5584 if (_curList.SelectedIndices.Count > 0)
5586 cidx = _curList.SelectedIndices[0];
5588 toIdx = _curList.VirtualListSize;
5592 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5593 if (_curList.SelectedIndices.Count > 0)
5594 cidx = _curList.SelectedIndices[0];
5598 case SEARCHTYPE.NextSearch: //次を検索
5599 if (_curList.SelectedIndices.Count > 0)
5601 cidx = _curList.SelectedIndices[0] + 1;
5602 if (cidx > toIdx) cidx = toIdx;
5609 case SEARCHTYPE.PrevSearch: //前を検索
5610 if (_curList.SelectedIndices.Count > 0)
5612 cidx = _curList.SelectedIndices[0] - 1;
5613 if (cidx < 0) cidx = 0;
5624 RegexOptions regOpt = RegexOptions.None;
5625 StringComparison fndOpt = StringComparison.Ordinal;
5628 regOpt = RegexOptions.IgnoreCase;
5629 fndOpt = StringComparison.OrdinalIgnoreCase;
5640 _search = new Regex(_word, regOpt);
5641 for (int idx = cidx; idx != toIdx; idx += stp)
5646 post = _statuses[_curTab.Text, idx];
5652 if (_search.IsMatch(post.Nickname)
5653 || _search.IsMatch(post.TextFromApi)
5654 || _search.IsMatch(post.ScreenName))
5656 SelectListItem(_curList, idx);
5657 _curList.EnsureVisible(idx);
5662 catch (ArgumentException)
5664 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5671 for (int idx = cidx; idx != toIdx; idx += stp)
5676 post = _statuses[_curTab.Text, idx];
5682 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5683 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5684 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5686 SelectListItem(_curList, idx);
5687 _curList.EnsureVisible(idx);
5697 case SEARCHTYPE.DialogSearch:
5698 case SEARCHTYPE.NextSearch:
5702 case SEARCHTYPE.PrevSearch:
5704 cidx = _curList.VirtualListSize - 1;
5711 catch (ArgumentOutOfRangeException)
5714 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5717 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5720 SearchDialog.Owner = this;
5721 if (SearchDialog.ShowDialog() == DialogResult.Cancel)
5723 this.TopMost = SettingDialog.AlwaysTop;
5726 this.TopMost = SettingDialog.AlwaysTop;
5728 if (!string.IsNullOrEmpty(SearchDialog.SWord))
5730 DoTabSearch(SearchDialog.SWord,
5731 SearchDialog.CheckCaseSensitive,
5732 SearchDialog.CheckRegex,
5733 SEARCHTYPE.DialogSearch);
5737 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5740 if (string.IsNullOrEmpty(SearchDialog.SWord))
5742 if (SearchDialog.ShowDialog() == DialogResult.Cancel)
5744 this.TopMost = SettingDialog.AlwaysTop;
5747 this.TopMost = SettingDialog.AlwaysTop;
5748 if (string.IsNullOrEmpty(SearchDialog.SWord)) return;
5750 DoTabSearch(SearchDialog.SWord,
5751 SearchDialog.CheckCaseSensitive,
5752 SearchDialog.CheckRegex,
5753 SEARCHTYPE.DialogSearch);
5757 DoTabSearch(SearchDialog.SWord,
5758 SearchDialog.CheckCaseSensitive,
5759 SearchDialog.CheckRegex,
5760 SEARCHTYPE.NextSearch);
5764 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5767 if (string.IsNullOrEmpty(SearchDialog.SWord))
5769 if (SearchDialog.ShowDialog() == DialogResult.Cancel)
5771 this.TopMost = SettingDialog.AlwaysTop;
5774 this.TopMost = SettingDialog.AlwaysTop;
5775 if (string.IsNullOrEmpty(SearchDialog.SWord)) return;
5778 DoTabSearch(SearchDialog.SWord,
5779 SearchDialog.CheckCaseSensitive,
5780 SearchDialog.CheckRegex,
5781 SEARCHTYPE.PrevSearch);
5784 private void AboutMenuItem_Click(object sender, EventArgs e)
5786 using (TweenAboutBox about = new TweenAboutBox())
5788 about.ShowDialog(this);
5790 this.TopMost = SettingDialog.AlwaysTop;
5793 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5795 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5797 DetailsListView lst = null;
5799 if (ImageSelectionPanel.Enabled)
5803 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5806 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5809 ListTab.SelectedIndex = i;
5810 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5811 //_curTab = ListTab.TabPages[i];
5816 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5817 if (idx == -1 && bgnIdx > 0)
5819 for (int i = 0; i < bgnIdx; i++)
5821 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5824 ListTab.SelectedIndex = i;
5825 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5826 //_curTab = ListTab.TabPages[i];
5832 //全部調べたが未読見つからず→先頭タブの最新発言へ
5835 ListTab.SelectedIndex = 0;
5836 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5837 //_curTab = ListTab.TabPages[0];
5838 if (_statuses.SortOrder == SortOrder.Ascending)
5839 idx = lst.VirtualListSize - 1;
5844 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5846 SelectListItem(lst, idx);
5847 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5849 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5850 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5856 lst.EnsureVisible(idx);
5861 lst.EnsureVisible(idx);
5867 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5869 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5871 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5872 OpenUriAsync(MyCommon.GetStatusUrl(post));
5876 private void FavorareMenuItem_Click(object sender, EventArgs e)
5878 if (_curList.SelectedIndices.Count > 0)
5880 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5881 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5885 private void VerUpMenuItem_Click(object sender, EventArgs e)
5890 private void RunTweenUp()
5892 ProcessStartInfo pinfo = new ProcessStartInfo();
5893 pinfo.UseShellExecute = true;
5894 pinfo.WorkingDirectory = MyCommon.settingPath;
5895 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5896 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5899 Process.Start(pinfo);
5903 MessageBox.Show("Failed to execute TweenUp3.exe.");
5907 private void CheckNewVersion(bool startup = false)
5909 if (ApplicationSettings.VersionInfoUrl == null)
5910 return; // 更新チェック無効化
5912 if (string.IsNullOrEmpty(MyCommon.fileVersion))
5920 retMsg = tw.GetVersionInfo();
5927 if (string.IsNullOrEmpty(retMsg))
5929 StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5930 if (!startup) MessageBox.Show(Properties.Resources.CheckNewVersionText10, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5934 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5935 string[] msgPart = retMsg.Split(new string[] {"\n\n", "\r\n\r\n"}, 2, StringSplitOptions.None);
5937 string[] msgHeader = msgPart[0].Split(new string[] {"\n", "\r\n"}, StringSplitOptions.None);
5938 string msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5940 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5942 string currentVersion = msgHeader[0];
5943 string downloadUrl = msgHeader[1];
5945 if (currentVersion.Replace(".", "").CompareTo(MyCommon.fileVersion.Replace(".", "")) > 0)
5947 using (var dialog = new UpdateDialog())
5949 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3, MyCommon.GetReadableVersion(currentVersion));
5950 dialog.DetailsText = msgBody;
5951 if (dialog.ShowDialog(this) == DialogResult.Yes)
5953 this.OpenUriAsync(downloadUrl);
5961 var msgtext = MyCommon.ReplaceAppName(string.Format(Properties.Resources.CheckNewVersionText7, MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(currentVersion)));
5962 MessageBox.Show(msgtext, MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2), MessageBoxButtons.OK, MessageBoxIcon.Information);
5967 private void Colorize()
5971 //件数関連の場合、タイトル即時書き換え
5972 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
5973 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5974 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5975 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5977 SetMainWindowTitle();
5979 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
5980 foreach (TabPage tb in ListTab.TabPages)
5982 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
5984 if (SettingDialog.TabIconDisp)
5986 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
5990 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
5993 public string createDetailHtml(string orgdata)
5995 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
5998 private void DisplayItemImage_Downloaded(object sender, EventArgs e)
6000 if (sender.Equals(displayItem))
6002 this.ClearUserPicture();
6004 var img = displayItem.Image;
6007 UserPicture.Image = img != null ? img.Clone() : null;
6011 UserPicture.ShowErrorImage();
6016 private void DispSelectedPost()
6018 DispSelectedPost(false);
6021 private static PostClass displaypost = new PostClass();
6023 private void DispSelectedPost(bool forceupdate)
6025 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
6028 if (!forceupdate && _curPost.Equals(displaypost))
6031 displaypost = _curPost;
6032 if (displayItem != null)
6034 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
6037 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
6038 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
6040 string dTxt = createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6043 SourceLinkLabel.Tag = null;
6044 SourceLinkLabel.Text = "";
6048 Match mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
6051 string src = mc.Groups["sourceurl"].Value;
6052 SourceLinkLabel.Tag = mc.Groups["sourceurl"].Value;
6053 mc = Regex.Match(src, "^https?://");
6056 src = src.Insert(0, "https://twitter.com");
6058 SourceLinkLabel.Tag = src;
6062 SourceLinkLabel.Tag = null;
6064 if (string.IsNullOrEmpty(_curPost.Source))
6066 SourceLinkLabel.Text = "";
6067 //SourceLinkLabel.Visible = false;
6071 SourceLinkLabel.Text = _curPost.Source;
6072 //SourceLinkLabel.Visible = true;
6075 SourceLinkLabel.TabStop = false;
6077 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && !_curPost.IsOwl)
6079 NameLabel.Text = "DM TO -> ";
6081 else if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
6083 NameLabel.Text = "DM FROM <- ";
6087 NameLabel.Text = "";
6089 NameLabel.Text += _curPost.ScreenName + "/" + _curPost.Nickname;
6090 NameLabel.Tag = _curPost.ScreenName;
6091 if (!string.IsNullOrEmpty(_curPost.RetweetedBy))
6093 NameLabel.Text += " (RT:" + _curPost.RetweetedBy + ")";
6096 this.ClearUserPicture();
6098 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6100 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6103 UserPicture.Image = image != null ? image.Clone() : null;
6107 UserPicture.ShowErrorImage();
6111 NameLabel.ForeColor = System.Drawing.SystemColors.ControlText;
6112 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6113 if (_curPost.IsOwl && (SettingDialog.OneWayLove || _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)) NameLabel.ForeColor = _clOWL;
6114 if (_curPost.RetweetedId != null) NameLabel.ForeColor = _clRetweet;
6115 if (_curPost.IsFav) NameLabel.ForeColor = _clFav;
6117 if (DumpPostClassToolStripMenuItem.Checked)
6119 StringBuilder sb = new StringBuilder(512);
6121 sb.Append("-----Start PostClass Dump<br>");
6122 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6123 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6124 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6125 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6126 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6127 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6128 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6129 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6130 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6131 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6132 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6133 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6134 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6135 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6136 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6138 foreach (string nm in _curPost.ReplyToList)
6140 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6143 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6144 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6145 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6146 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6147 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6148 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6149 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6150 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6151 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6152 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6153 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6154 sb.Append("-----End PostClass Dump<br>");
6156 PostBrowser.Visible = false;
6157 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6158 PostBrowser.Visible = true;
6164 if (PostBrowser.DocumentText != dTxt)
6166 PostBrowser.Visible = false;
6167 PostBrowser.DocumentText = dTxt;
6169 this.SplitContainer3.Panel2Collapsed = true;
6171 if (this.IsPreviewEnable)
6172 this.tweetThumbnail1.ShowThumbnailAsync(_curPost);
6175 catch (System.Runtime.InteropServices.COMException)
6179 catch (UriFormatException)
6181 PostBrowser.DocumentText = dTxt;
6185 PostBrowser.Visible = true;
6190 private void MatomeMenuItem_Click(object sender, EventArgs e)
6192 OpenApplicationWebsite();
6195 private void OpenApplicationWebsite()
6197 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6200 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6202 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6205 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6207 if (ListTab.SelectedTab != null)
6209 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6211 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6212 if (pnl.Controls["comboSearch"].Focused ||
6213 pnl.Controls["comboLang"].Focused ||
6214 pnl.Controls["buttonSearch"].Focused) return;
6216 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6217 if (State == ModifierState.NotFlags) return;
6218 if (State != ModifierState.None) _anchorFlag = false;
6219 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6222 e.SuppressKeyPress = true;
6227 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6229 ModifierState state = ModifierState.None;
6230 if (sControl) state = state | ModifierState.Ctrl;
6231 if (sShift) state = state | ModifierState.Shift;
6232 if (sAlt) state = state | ModifierState.Alt;
6237 private enum ModifierState
6249 //PostBrowser = 102,
6253 private enum FocusedControl : int
6261 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6263 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6264 if (Focused == FocusedControl.ListTab)
6266 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6267 Modifier == ModifierState.Ctrl ||
6268 Modifier == ModifierState.None ||
6269 Modifier == ModifierState.Shift)
6271 if (KeyCode == Keys.J)
6273 SendKeys.Send("{DOWN}");
6276 else if (KeyCode == Keys.K)
6278 SendKeys.Send("{UP}");
6282 if (Modifier == ModifierState.Shift ||
6283 Modifier == ModifierState.None)
6285 if (KeyCode == Keys.F)
6287 SendKeys.Send("{PGDN}");
6290 else if (KeyCode == Keys.B)
6292 SendKeys.Send("{PGUP}");
6301 case ModifierState.None:
6306 OpenApplicationWebsite();
6309 MenuItemSearchNext_Click(null, null);
6315 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
6318 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
6321 if (Focused != FocusedControl.StatusText)
6327 case Keys.ProcessKey:
6328 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6329 JumpUnreadMenuItem_Click(null, null);
6332 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6333 ShowRelatedStatusesMenuItem_Click(null, null);
6337 if (Focused == FocusedControl.ListTab)
6350 case Keys.OemPeriod:
6354 if (this.StatusText.Enabled) this.StatusText.Focus();
6357 MakeReplyOrDirectStatus();
6364 _anchorFlag = false;
6384 // ] in_reply_to参照元へ戻る
6385 GoInReplyToPostTree();
6388 // [ in_reply_toへジャンプ
6389 GoBackInReplyToPostTree();
6392 if (ListTab.SelectedTab != null)
6394 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6395 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6397 TabPage relTp = ListTab.SelectedTab;
6398 RemoveSpecifiedTab(relTp.Text, false);
6406 else if (Focused == FocusedControl.PostBrowser)
6413 //スクロールを発生させるため、true を返す
6418 case ModifierState.Ctrl:
6423 MakeReplyOrDirectStatus(false, true);
6429 MakeReplyOrDirectStatus(false, false);
6432 FavoriteChange(true);
6435 doRepliedStatusOpen();
6441 ReadedStripMenuItem_Click(null, null);
6444 HashManageMenuItem_Click(null, null);
6447 UrlConvertAutoToolStripMenuItem_Click(null, null);
6450 if (Focused != FocusedControl.PostBrowser)
6452 MultiLineMenuItem_Click(null, null);
6457 MenuItemSubSearch_Click(null, null);
6464 MoveToHomeToolStripMenuItem_Click(null, null);
6468 MoveToFavToolStripMenuItem_Click(null, null);
6472 StatusOpenMenuItem_Click(null, null);
6476 OpenURLMenuItem_Click(null, null);
6480 if (Focused == FocusedControl.ListTab)
6487 return false; //スルーする
6505 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6506 int tabNo = KeyCode - Keys.D1;
6507 if (ListTab.TabPages.Count < tabNo)
6509 ListTab.SelectedIndex = tabNo;
6510 ListTabSelect(ListTab.TabPages[tabNo]);
6513 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6514 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6518 else if (Focused == FocusedControl.StatusText)
6524 StatusText.SelectAll();
6528 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6530 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6532 if (KeyCode == Keys.Up)
6535 if (_hisIdx < 0) _hisIdx = 0;
6540 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6542 StatusText.Text = _history[_hisIdx].status;
6543 _reply_to_id = _history[_hisIdx].inReplyToId;
6544 _reply_to_name = _history[_hisIdx].inReplyToName;
6545 StatusText.SelectionStart = StatusText.Text.Length;
6549 if (ListTab.SelectedIndex == 0)
6551 ListTab.SelectedIndex = ListTab.TabCount - 1;
6555 ListTab.SelectedIndex -= 1;
6561 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6563 ListTab.SelectedIndex = 0;
6567 ListTab.SelectedIndex += 1;
6575 //フォーカスPostBrowserもしくは関係なし
6579 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6583 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6584 if (!string.IsNullOrEmpty(_selText))
6588 Clipboard.SetDataObject(_selText, false, 5, 100);
6590 catch (Exception ex)
6592 MessageBox.Show(ex.Message);
6597 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6598 MultiLineMenuItem_Click(null, null);
6603 case ModifierState.Shift:
6608 MenuItemSearchPrev_Click(null, null);
6614 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, 0, "");
6617 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, 0, "");
6621 if (Focused != FocusedControl.StatusText)
6623 if (KeyCode == Keys.R)
6630 if (Focused == FocusedControl.ListTab)
6650 GoBackInReplyToPostTree(true, false);
6653 GoBackInReplyToPostTree(true, true);
6657 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6662 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6666 this.GoBackSelectPostChain();
6671 case ModifierState.Alt:
6675 doReTweetOfficial(true);
6678 if (_curPost != null)
6680 doShowUserStatus(_curPost.ScreenName, false);
6685 ScrollDownPostBrowser(false);
6688 ScrollDownPostBrowser(true);
6691 PageDownPostBrowser(false);
6694 PageDownPostBrowser(true);
6697 if (Focused == FocusedControl.ListTab)
6699 // 別タブの同じ書き込みへ(ALT+←/→)
6700 if (KeyCode == Keys.Right)
6702 GoSamePostToAnotherTab(false);
6705 else if (KeyCode == Keys.Left)
6707 GoSamePostToAnotherTab(true);
6712 case ModifierState.Ctrl | ModifierState.Shift:
6716 MakeReplyOrDirectStatus(false, true, true);
6722 if (ListTab.SelectedTab != null)
6724 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6726 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6732 FavoriteChange(false);
6735 UnreadStripMenuItem_Click(null, null);
6738 HashToggleMenuItem_Click(null, null);
6741 ImageSelectMenuItem_Click(null, null);
6747 FavorareMenuItem_Click(null, null);
6750 if (Focused == FocusedControl.StatusText)
6756 if (_curList != null && _curList.VirtualListSize != 0 &&
6757 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6759 idx = _curList.SelectedIndices[0] - 1;
6760 SelectListItem(_curList, idx);
6761 _curList.EnsureVisible(idx);
6766 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6767 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6769 idx = _curList.SelectedIndices[0] + 1;
6770 SelectListItem(_curList, idx);
6771 _curList.EnsureVisible(idx);
6776 if (StatusText.SelectionStart > 0)
6778 int endidx = StatusText.SelectionStart - 1;
6779 string startstr = "";
6780 bool pressed = false;
6781 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6783 char c = StatusText.Text[i];
6784 if (Char.IsLetterOrDigit(c) || c == '_')
6791 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6792 int cnt = AtIdSupl.ItemCount;
6793 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6794 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6799 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6800 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6812 else if (Focused == FocusedControl.ListTab)
6814 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6826 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6827 int colNo = KeyCode - Keys.D1;
6828 if (lst.Columns.Count < colNo) return false;
6829 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6830 if (col == null) return false;
6831 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6834 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6835 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6840 case ModifierState.Ctrl | ModifierState.Alt:
6841 if (KeyCode == Keys.S)
6843 FavoritesRetweetOriginal();
6846 else if (KeyCode == Keys.R)
6848 FavoritesRetweetUnofficial();
6851 else if (KeyCode == Keys.H)
6853 OpenUserAppointUrl();
6857 case ModifierState.Alt | ModifierState.Shift:
6858 if (Focused == FocusedControl.PostBrowser)
6860 if (KeyCode == Keys.R)
6861 doReTweetUnofficial();
6862 else if (KeyCode == Keys.C)
6869 if (!this.ExistCurrentPost) return false;
6870 doTranslation(_curPost.TextFromApi);
6873 doReTweetUnofficial();
6879 this.tweetThumbnail1.ScrollUp();
6882 this.tweetThumbnail1.ScrollDown();
6885 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6887 if (!this.SplitContainer3.Panel2Collapsed)
6889 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6899 private void ScrollDownPostBrowser(bool forward)
6901 var doc = PostBrowser.Document;
6902 if (doc == null) return;
6904 var tags = doc.GetElementsByTagName("html");
6908 tags[0].ScrollTop += SettingDialog.FontDetail.Height;
6910 tags[0].ScrollTop -= SettingDialog.FontDetail.Height;
6914 private void PageDownPostBrowser(bool forward)
6916 var doc = PostBrowser.Document;
6917 if (doc == null) return;
6919 var tags = doc.GetElementsByTagName("html");
6923 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6925 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6929 private void GoNextTab(bool forward)
6931 int idx = ListTab.SelectedIndex;
6935 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6940 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6942 ListTab.SelectedIndex = idx;
6943 ListTabSelect(ListTab.TabPages[idx]);
6946 private void CopyStot()
6949 StringBuilder sb = new StringBuilder();
6950 bool IsProtected = false;
6952 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6953 foreach (int idx in _curList.SelectedIndices)
6955 PostClass post = _statuses[_curTab.Text, idx];
6961 if (post.IsDeleted) continue;
6964 if (post.RetweetedId != null)
6965 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6967 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6971 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6976 MessageBox.Show(Properties.Resources.CopyStotText1);
6980 clstr = sb.ToString();
6983 Clipboard.SetDataObject(clstr, false, 5, 100);
6985 catch (Exception ex)
6987 MessageBox.Show(ex.Message);
6992 private void CopyIdUri()
6995 StringBuilder sb = new StringBuilder();
6996 if (this._curTab == null) return;
6997 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
6998 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
6999 foreach (int idx in _curList.SelectedIndices)
7001 var post = _statuses[_curTab.Text, idx];
7002 sb.Append(MyCommon.GetStatusUrl(post));
7003 sb.Append(Environment.NewLine);
7007 clstr = sb.ToString();
7010 Clipboard.SetDataObject(clstr, false, 5, 100);
7012 catch (Exception ex)
7014 MessageBox.Show(ex.Message);
7019 private void GoFav(bool forward)
7021 if (_curList.VirtualListSize == 0) return;
7028 if (_curList.SelectedIndices.Count == 0)
7034 fIdx = _curList.SelectedIndices[0] + 1;
7035 if (fIdx > _curList.VirtualListSize - 1) return;
7037 toIdx = _curList.VirtualListSize;
7042 if (_curList.SelectedIndices.Count == 0)
7044 fIdx = _curList.VirtualListSize - 1;
7048 fIdx = _curList.SelectedIndices[0] - 1;
7049 if (fIdx < 0) return;
7055 for (int idx = fIdx; idx != toIdx; idx += stp)
7057 if (_statuses[_curTab.Text, idx].IsFav)
7059 SelectListItem(_curList, idx);
7060 _curList.EnsureVisible(idx);
7066 private void GoSamePostToAnotherTab(bool left)
7068 if (_curList.VirtualListSize == 0) return;
7074 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7075 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7077 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7082 if (ListTab.SelectedIndex == 0)
7088 fIdx = ListTab.SelectedIndex - 1;
7096 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7102 fIdx = ListTab.SelectedIndex + 1;
7104 toIdx = ListTab.TabCount;
7109 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7111 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7112 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7114 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7116 ListTab.SelectedIndex = tabidx;
7117 ListTabSelect(ListTab.TabPages[tabidx]);
7118 SelectListItem(_curList, idx);
7119 _curList.EnsureVisible(idx);
7128 private void GoPost(bool forward)
7130 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7137 fIdx = _curList.SelectedIndices[0] + 1;
7138 if (fIdx > _curList.VirtualListSize - 1) return;
7139 toIdx = _curList.VirtualListSize;
7144 fIdx = _curList.SelectedIndices[0] - 1;
7145 if (fIdx < 0) return;
7151 if (_curPost.RetweetedId == null)
7153 name = _curPost.ScreenName;
7157 name = _curPost.RetweetedBy;
7159 for (int idx = fIdx; idx != toIdx; idx += stp)
7161 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7163 if (_statuses[_curTab.Text, idx].ScreenName == name)
7165 SelectListItem(_curList, idx);
7166 _curList.EnsureVisible(idx);
7172 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7174 SelectListItem(_curList, idx);
7175 _curList.EnsureVisible(idx);
7182 private void GoRelPost(bool forward)
7184 if (_curList.SelectedIndices.Count == 0) return;
7191 fIdx = _curList.SelectedIndices[0] + 1;
7192 if (fIdx > _curList.VirtualListSize - 1) return;
7193 toIdx = _curList.VirtualListSize;
7198 fIdx = _curList.SelectedIndices[0] - 1;
7199 if (fIdx < 0) return;
7206 if (_curPost == null) return;
7207 _anchorPost = _curPost;
7212 if (_anchorPost == null) return;
7215 for (int idx = fIdx; idx != toIdx; idx += stp)
7217 PostClass post = _statuses[_curTab.Text, idx];
7218 if (post.ScreenName == _anchorPost.ScreenName ||
7219 post.RetweetedBy == _anchorPost.ScreenName ||
7220 post.ScreenName == _anchorPost.RetweetedBy ||
7221 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7222 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7223 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7224 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7225 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7227 SelectListItem(_curList, idx);
7228 _curList.EnsureVisible(idx);
7234 private void GoAnchor()
7236 if (_anchorPost == null) return;
7237 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7238 if (idx == -1) return;
7240 SelectListItem(_curList, idx);
7241 _curList.EnsureVisible(idx);
7244 private void GoTopEnd(bool GoTop)
7251 _item = _curList.GetItemAt(0, 25);
7259 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7261 idx = _curList.VirtualListSize - 1;
7265 SelectListItem(_curList, idx);
7268 private void GoMiddle()
7275 _item = _curList.GetItemAt(0, 0);
7285 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7288 idx2 = _curList.VirtualListSize - 1;
7294 idx3 = (idx1 + idx2) / 2;
7296 SelectListItem(_curList, idx3);
7299 private void GoLast()
7301 if (_curList.VirtualListSize == 0) return;
7303 if (_statuses.SortOrder == SortOrder.Ascending)
7305 SelectListItem(_curList, _curList.VirtualListSize - 1);
7306 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7310 SelectListItem(_curList, 0);
7311 _curList.EnsureVisible(0);
7315 private void MoveTop()
7317 if (_curList.SelectedIndices.Count == 0) return;
7318 int idx = _curList.SelectedIndices[0];
7319 if (_statuses.SortOrder == SortOrder.Ascending)
7321 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7325 _curList.EnsureVisible(0);
7327 _curList.EnsureVisible(idx);
7330 private void GoInReplyToPostTree()
7332 if (_curPost == null) return;
7334 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7336 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7338 PostClass post = null;
7339 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7340 if (string.IsNullOrEmpty(r) && post != null)
7342 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7343 _curPost.InReplyToUser = post.InReplyToUser;
7344 _curPost.IsReply = post.IsReply;
7345 this.PurgeListViewItemCache();
7346 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7350 this.StatusLabel.Text = r;
7354 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7356 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7358 replyChains = new Stack<ReplyChain>();
7360 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7363 string inReplyToTabName;
7364 long inReplyToId = _curPost.InReplyToStatusId.Value;
7365 string inReplyToUser = _curPost.InReplyToUser;
7366 Dictionary<long, PostClass> curTabPosts;
7368 if (_statuses.Tabs[_curTab.Text].IsInnerStorageTabType)
7369 curTabPosts = curTabClass.Posts;
7371 curTabPosts = _statuses.Posts;
7373 var inReplyToPosts = from tab in _statuses.Tabs.Values
7374 orderby tab != curTabClass
7375 from post in ((Dictionary<long, PostClass>)(tab.IsInnerStorageTabType ? tab.Posts : _statuses.Posts)).Values
7376 where post.StatusId == inReplyToId
7377 let index = tab.IndexOf(post.StatusId)
7379 select new {Tab = tab, Index = index};
7383 var inReplyPost = inReplyToPosts.First();
7384 inReplyToTabName = inReplyPost.Tab.TabName;
7385 inReplyToIndex = inReplyPost.Index;
7387 catch (InvalidOperationException)
7389 PostClass post = null;
7390 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7391 if (string.IsNullOrEmpty(r) && post != null)
7394 _statuses.AddPost(post);
7395 _statuses.DistributePosts();
7396 //_statuses.SubmitUpdate(null, null, null, false);
7397 this.RefreshTimeline(false);
7400 var inReplyPost = inReplyToPosts.First();
7401 inReplyToTabName = inReplyPost.Tab.TabName;
7402 inReplyToIndex = inReplyPost.Index;
7404 catch (InvalidOperationException)
7406 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7412 this.StatusLabel.Text = r;
7413 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7418 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7419 DetailsListView listView = (DetailsListView)tabPage.Tag;
7421 if (_curTab != tabPage)
7423 this.ListTab.SelectTab(tabPage);
7426 this.SelectListItem(listView, inReplyToIndex);
7427 listView.EnsureVisible(inReplyToIndex);
7430 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7432 if (_curPost == null) return;
7434 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7435 Dictionary<long, PostClass> curTabPosts = curTabClass.IsInnerStorageTabType ? curTabClass.Posts : _statuses.Posts;
7439 if (_curPost.InReplyToStatusId != null)
7441 var posts = from t in _statuses.Tabs
7442 from p in t.Value.IsInnerStorageTabType ? t.Value.Posts : _statuses.Posts
7443 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7444 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7446 orderby isForward ? indexOf : indexOf * -1
7447 orderby t.Value != curTabClass
7448 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7451 var postList = posts.ToList();
7452 for (int i = postList.Count - 1; i >= 0; i--)
7455 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7457 postList.RemoveAt(index);
7460 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7461 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7462 if (post == null) post = postList.First();
7463 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7464 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7465 SelectListItem(listView, post.Index);
7466 listView.EnsureVisible(post.Index);
7468 catch (InvalidOperationException)
7476 if (replyChains == null || replyChains.Count < 1)
7478 var posts = from t in _statuses.Tabs
7479 from p in t.Value.IsInnerStorageTabType ? t.Value.Posts : _statuses.Posts
7480 where p.Value.InReplyToStatusId == _curPost.StatusId
7481 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7484 orderby t.Value != curTabClass
7485 select new {Tab = t.Value, Index = indexOf};
7488 var post = posts.First();
7489 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7490 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7491 SelectListItem(listView, post.Index);
7492 listView.EnsureVisible(post.Index);
7494 catch (InvalidOperationException)
7501 ReplyChain chainHead = replyChains.Pop();
7502 if (chainHead.InReplyToId == _curPost.StatusId)
7504 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7513 ListTab.SelectTab(chainHead.OriginalTab);
7519 SelectListItem(_curList, idx);
7520 _curList.EnsureVisible(idx);
7526 this.GoBackInReplyToPostTree(parallel);
7532 private void GoBackSelectPostChain()
7536 this.selectPostChains.Pop();
7537 Tuple<TabPage, PostClass> tabPostPair = this.selectPostChains.Pop();
7538 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) return;
7539 this.ListTab.SelectedTab = tabPostPair.Item1;
7540 if (tabPostPair.Item2 != null && this._statuses.Tabs[this._curTab.Text].IndexOf(tabPostPair.Item2.StatusId) > -1)
7542 this.SelectListItem(this._curList, this._statuses.Tabs[this._curTab.Text].IndexOf(tabPostPair.Item2.StatusId));
7543 this._curList.EnsureVisible(this._statuses.Tabs[this._curTab.Text].IndexOf(tabPostPair.Item2.StatusId));
7546 catch (InvalidOperationException)
7551 private void PushSelectPostChain()
7553 if (this.selectPostChains.Count == 0 || (this.selectPostChains.Peek().Item1.Text != this._curTab.Text || this._curPost != this.selectPostChains.Peek().Item2))
7555 this.selectPostChains.Push(Tuple.Create(this._curTab, _curPost));
7559 private void TrimPostChain()
7561 if (this.selectPostChains.Count < 2000) return;
7562 Stack<Tuple<TabPage, PostClass>> p = new Stack<Tuple<TabPage, PostClass>>();
7563 for (int i = 0; i < 2000; i++)
7565 p.Push(this.selectPostChains.Pop());
7567 this.selectPostChains.Clear();
7568 for (int i = 0; i < 2000; i++)
7570 this.selectPostChains.Push(p.Pop());
7574 private bool GoStatus(long statusId)
7576 if (statusId == 0) return false;
7577 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7579 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7581 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7582 ListTab.SelectedIndex = tabidx;
7583 ListTabSelect(ListTab.TabPages[tabidx]);
7584 SelectListItem(_curList, idx);
7585 _curList.EnsureVisible(idx);
7592 private bool GoDirectMessage(long statusId)
7594 if (statusId == 0) return false;
7595 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7597 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7599 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7600 ListTab.SelectedIndex = tabidx;
7601 ListTabSelect(ListTab.TabPages[tabidx]);
7602 SelectListItem(_curList, idx);
7603 _curList.EnsureVisible(idx);
7610 private void MyList_MouseClick(object sender, MouseEventArgs e)
7612 _anchorFlag = false;
7615 private void StatusText_Enter(object sender, EventArgs e)
7617 // フォーカスの戻り先を StatusText に設定
7618 this.Tag = StatusText;
7619 StatusText.BackColor = _clInputBackcolor;
7622 public Color InputBackColor
7624 get { return _clInputBackcolor; }
7625 set { _clInputBackcolor = value; }
7628 private void StatusText_Leave(object sender, EventArgs e)
7630 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7631 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7632 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7635 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7637 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7638 if (State == ModifierState.NotFlags) return;
7639 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7642 e.SuppressKeyPress = true;
7645 this.StatusText_TextChanged(null, null);
7648 private void SaveConfigsAll(bool ifModified)
7652 SaveConfigsCommon();
7659 if (_modifySettingCommon) SaveConfigsCommon();
7660 if (_modifySettingLocal) SaveConfigsLocal();
7661 if (_modifySettingAtId) SaveConfigsAtId();
7665 private void SaveConfigsAtId()
7667 if (_ignoreConfigSave || !SettingDialog.UseAtIdSupplement && AtIdSupl == null) return;
7669 _modifySettingAtId = false;
7670 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7674 private void SaveConfigsCommon()
7676 if (_ignoreConfigSave) return;
7678 _modifySettingCommon = false;
7681 _cfgCommon.UserName = tw.Username;
7682 _cfgCommon.UserId = tw.UserId;
7683 _cfgCommon.Password = tw.Password;
7684 _cfgCommon.Token = tw.AccessToken;
7685 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7686 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7687 _cfgCommon.UserstreamStartup = SettingDialog.UserstreamStartup;
7688 _cfgCommon.UserstreamPeriod = SettingDialog.UserstreamPeriodInt;
7689 _cfgCommon.TimelinePeriod = SettingDialog.TimelinePeriodInt;
7690 _cfgCommon.ReplyPeriod = SettingDialog.ReplyPeriodInt;
7691 _cfgCommon.DMPeriod = SettingDialog.DMPeriodInt;
7692 _cfgCommon.PubSearchPeriod = SettingDialog.PubSearchPeriodInt;
7693 _cfgCommon.ListsPeriod = SettingDialog.ListsPeriodInt;
7694 _cfgCommon.UserTimelinePeriod = SettingDialog.UserTimelinePeriodInt;
7695 _cfgCommon.Read = SettingDialog.Readed;
7696 _cfgCommon.IconSize = SettingDialog.IconSz;
7697 _cfgCommon.UnreadManage = SettingDialog.UnreadManage;
7698 _cfgCommon.PlaySound = SettingDialog.PlaySound;
7699 _cfgCommon.OneWayLove = SettingDialog.OneWayLove;
7701 _cfgCommon.NameBalloon = SettingDialog.NameBalloon;
7702 _cfgCommon.PostCtrlEnter = SettingDialog.PostCtrlEnter;
7703 _cfgCommon.PostShiftEnter = SettingDialog.PostShiftEnter;
7704 _cfgCommon.CountApi = SettingDialog.CountApi;
7705 _cfgCommon.CountApiReply = SettingDialog.CountApiReply;
7706 _cfgCommon.PostAndGet = SettingDialog.PostAndGet;
7707 _cfgCommon.DispUsername = SettingDialog.DispUsername;
7708 _cfgCommon.MinimizeToTray = SettingDialog.MinimizeToTray;
7709 _cfgCommon.CloseToExit = SettingDialog.CloseToExit;
7710 _cfgCommon.DispLatestPost = SettingDialog.DispLatestPost;
7711 _cfgCommon.SortOrderLock = SettingDialog.SortOrderLock;
7712 _cfgCommon.ViewTabBottom = SettingDialog.ViewTabBottom;
7713 _cfgCommon.TinyUrlResolve = SettingDialog.TinyUrlResolve;
7714 _cfgCommon.StartupVersion = SettingDialog.StartupVersion;
7715 _cfgCommon.StartupFollowers = SettingDialog.StartupFollowers;
7716 _cfgCommon.RestrictFavCheck = SettingDialog.RestrictFavCheck;
7717 _cfgCommon.AlwaysTop = SettingDialog.AlwaysTop;
7718 _cfgCommon.UrlConvertAuto = SettingDialog.UrlConvertAuto;
7719 _cfgCommon.UseUnreadStyle = SettingDialog.UseUnreadStyle;
7720 _cfgCommon.DateTimeFormat = SettingDialog.DateTimeFormat;
7721 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7722 _cfgCommon.RetweetNoConfirm = SettingDialog.RetweetNoConfirm;
7723 _cfgCommon.LimitBalloon = SettingDialog.LimitBalloon;
7724 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7725 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7726 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7727 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7728 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7729 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7730 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7731 _cfgCommon.AutoShortUrlFirst = SettingDialog.AutoShortUrlFirst;
7732 _cfgCommon.TabIconDisp = SettingDialog.TabIconDisp;
7733 _cfgCommon.ReplyIconState = SettingDialog.ReplyIconState;
7734 _cfgCommon.ReadOwnPost = SettingDialog.ReadOwnPost;
7735 _cfgCommon.GetFav = SettingDialog.GetFav;
7736 _cfgCommon.IsMonospace = SettingDialog.IsMonospace;
7737 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7738 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7740 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7742 _cfgCommon.ReadOldPosts = SettingDialog.ReadOldPosts;
7743 _cfgCommon.BilyUser = SettingDialog.BitlyUser;
7744 _cfgCommon.BitlyPwd = SettingDialog.BitlyPwd;
7745 _cfgCommon.ShowGrid = SettingDialog.ShowGrid;
7746 _cfgCommon.UseAtIdSupplement = SettingDialog.UseAtIdSupplement;
7747 _cfgCommon.UseHashSupplement = SettingDialog.UseHashSupplement;
7748 _cfgCommon.PreviewEnable = SettingDialog.PreviewEnable;
7749 _cfgCommon.Language = SettingDialog.Language;
7751 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7752 switch (_statuses.SortMode)
7754 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7755 _cfgCommon.SortColumn = 1;
7757 case IdComparerClass.ComparerMode.Data: //本文
7758 _cfgCommon.SortColumn = 2;
7760 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7761 _cfgCommon.SortColumn = 3;
7763 case IdComparerClass.ComparerMode.Name: //名前
7764 _cfgCommon.SortColumn = 4;
7766 case IdComparerClass.ComparerMode.Source: //Source
7767 _cfgCommon.SortColumn = 7;
7771 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7772 _cfgCommon.HashTags = HashMgr.HashHistories;
7773 if (HashMgr.IsPermanent)
7775 _cfgCommon.HashSelected = HashMgr.UseHash;
7779 _cfgCommon.HashSelected = "";
7781 _cfgCommon.HashIsHead = HashMgr.IsHead;
7782 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7783 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7784 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7785 _cfgCommon.HotkeyEnabled = SettingDialog.HotkeyEnabled;
7786 _cfgCommon.HotkeyModifier = SettingDialog.HotkeyMod;
7787 _cfgCommon.HotkeyKey = SettingDialog.HotkeyKey;
7788 _cfgCommon.HotkeyValue = SettingDialog.HotkeyValue;
7789 _cfgCommon.BlinkNewMentions = SettingDialog.BlinkNewMentions;
7790 if (ToolStripFocusLockMenuItem != null &&
7791 ToolStripFocusLockMenuItem.IsDisposed == false)
7793 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7795 _cfgCommon.UseAdditionalCount = SettingDialog.UseAdditionalCount;
7796 _cfgCommon.MoreCountApi = SettingDialog.MoreCountApi;
7797 _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi;
7798 _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi;
7799 _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi;
7800 _cfgCommon.UserTimelineCountApi = SettingDialog.UserTimelineCountApi;
7801 _cfgCommon.TrackWord = tw.TrackWord;
7802 _cfgCommon.AllAtReply = tw.AllAtReply;
7803 _cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
7804 _cfgCommon.ListCountApi = SettingDialog.ListCountApi;
7805 _cfgCommon.UseImageService = ImageServiceCombo.SelectedIndex;
7806 _cfgCommon.UseImageServiceName = this.ImageService;
7807 _cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
7808 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7809 _cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
7810 _cfgCommon.IsPreviewFoursquare = SettingDialog.IsPreviewFoursquare;
7811 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7812 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7813 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7814 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7815 _cfgCommon.IsListsIncludeRts = SettingDialog.IsListStatusesIncludeRts;
7816 _cfgCommon.TabMouseLock = SettingDialog.TabMouseLock;
7817 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7818 _cfgCommon.IsUseNotifyGrowl = SettingDialog.IsNotifyUseGrowl;
7824 private void SaveConfigsLocal()
7826 if (_ignoreConfigSave) return;
7829 _modifySettingLocal = false;
7830 _cfgLocal.FormSize = _mySize;
7831 _cfgLocal.FormLocation = _myLoc;
7832 _cfgLocal.SplitterDistance = _mySpDis;
7833 _cfgLocal.PreviewDistance = _mySpDis3;
7834 _cfgLocal.StatusMultiline = StatusText.Multiline;
7835 _cfgLocal.StatusTextHeight = _mySpDis2;
7836 _cfgLocal.AdSplitterDistance = _myAdSpDis;
7837 _cfgLocal.StatusText = SettingDialog.Status;
7839 _cfgLocal.FontUnread = _fntUnread;
7840 _cfgLocal.ColorUnread = _clUnread;
7841 _cfgLocal.FontRead = _fntReaded;
7842 _cfgLocal.ColorRead = _clReaded;
7843 _cfgLocal.FontDetail = _fntDetail;
7844 _cfgLocal.ColorDetail = _clDetail;
7845 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7846 _cfgLocal.ColorDetailLink = _clDetailLink;
7847 _cfgLocal.ColorFav = _clFav;
7848 _cfgLocal.ColorOWL = _clOWL;
7849 _cfgLocal.ColorRetweet = _clRetweet;
7850 _cfgLocal.ColorSelf = _clSelf;
7851 _cfgLocal.ColorAtSelf = _clAtSelf;
7852 _cfgLocal.ColorTarget = _clTarget;
7853 _cfgLocal.ColorAtTarget = _clAtTarget;
7854 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7855 _cfgLocal.ColorAtTo = _clAtTo;
7856 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7857 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7858 _cfgLocal.ColorInputFont = _clInputFont;
7859 _cfgLocal.FontInputFont = _fntInputFont;
7861 _cfgLocal.BrowserPath = SettingDialog.BrowserPath;
7862 _cfgLocal.UseRecommendStatus = SettingDialog.UseRecommendStatus;
7863 _cfgLocal.ProxyType = SettingDialog.SelectedProxyType;
7864 _cfgLocal.ProxyAddress = SettingDialog.ProxyAddress;
7865 _cfgLocal.ProxyPort = SettingDialog.ProxyPort;
7866 _cfgLocal.ProxyUser = SettingDialog.ProxyUser;
7867 _cfgLocal.ProxyPassword = SettingDialog.ProxyPassword;
7868 if (_ignoreConfigSave) return;
7873 private void SaveConfigsTabs()
7875 SettingTabs tabSetting = new SettingTabs();
7876 for (int i = 0; i < ListTab.TabPages.Count; i++)
7878 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7883 private /* async */ void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7886 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7887 if (ret != DialogResult.OK)
7890 var match = Twitter.StatusUrlRegex.Match(inputText);
7893 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7894 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7898 var statusId = long.Parse(match.Groups["StatusId"].Value);
7899 var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
7901 Task.Factory.StartNew(() =>
7903 var post = this._statuses[statusId];
7906 var err = this.tw.GetStatusApi(false, statusId, ref post);
7907 if (!string.IsNullOrEmpty(err))
7908 throw new WebApiException(err);
7911 }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)
7916 t.Exception.Flatten().Handle(x => x is WebApiException);
7918 var message = t.Exception.InnerException.Message;
7919 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7920 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7926 this.OpenRelatedTab(t.Result);
7928 catch (TabException ex)
7930 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7935 private void SaveLogMenuItem_Click(object sender, EventArgs e)
7937 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
7938 Properties.Resources.SaveLogMenuItem_ClickText2,
7939 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
7940 if (rslt == DialogResult.Cancel) return;
7942 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
7943 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
7944 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
7945 SaveFileDialog1.FilterIndex = 0;
7946 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
7947 SaveFileDialog1.RestoreDirectory = true;
7949 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
7951 if (!SaveFileDialog1.ValidateNames) return;
7952 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
7954 if (rslt == DialogResult.Yes)
7957 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
7959 PostClass post = _statuses[_curTab.Text, idx];
7960 string protect = "";
7961 if (post.IsProtect) protect = "Protect";
7962 sw.WriteLine(post.Nickname + "\t" +
7963 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7964 post.CreatedAt.ToString() + "\t" +
7965 post.ScreenName + "\t" +
7966 post.StatusId.ToString() + "\t" +
7967 post.ImageUrl + "\t" +
7968 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7974 foreach (int idx in _curList.SelectedIndices)
7976 PostClass post = _statuses[_curTab.Text, idx];
7977 string protect = "";
7978 if (post.IsProtect) protect = "Protect";
7979 sw.WriteLine(post.Nickname + "\t" +
7980 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7981 post.CreatedAt.ToString() + "\t" +
7982 post.ScreenName + "\t" +
7983 post.StatusId.ToString() + "\t" +
7984 post.ImageUrl + "\t" +
7985 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7991 this.TopMost = SettingDialog.AlwaysTop;
7994 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
7996 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7997 if (State == ModifierState.NotFlags) return;
7998 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
8001 e.IsInputKey = true;
8004 public bool TabRename(ref string tabName)
8007 string newTabText = null;
8008 using (InputTabName inputName = new InputTabName())
8010 inputName.TabName = tabName;
8011 inputName.ShowDialog();
8012 if (inputName.DialogResult == DialogResult.Cancel) return false;
8013 newTabText = inputName.TabName;
8015 this.TopMost = SettingDialog.AlwaysTop;
8016 if (!string.IsNullOrEmpty(newTabText))
8019 for (int i = 0; i < ListTab.TabCount; i++)
8021 if (ListTab.TabPages[i].Text == newTabText)
8023 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
8024 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8028 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
8029 for (int i = 0; i < ListTab.TabCount; i++)
8031 if (ListTab.TabPages[i].Text == tabName)
8033 ListTab.TabPages[i].Text = newTabText;
8036 _statuses.RenameTab(tabName, newTabText);
8038 for (int i = 0; i < ListTab.TabCount; i++)
8040 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
8042 if (ListTab.TabPages[i].Text == tabName)
8044 ListTab.TabPages[i].Text = newTabText;
8048 SaveConfigsCommon();
8050 _rclickTabName = newTabText;
8051 tabName = newTabText;
8060 private void ListTab_MouseClick(object sender, MouseEventArgs e)
8062 if (e.Button == MouseButtons.Middle)
8064 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
8066 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8068 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
8069 this.SaveConfigsTabs();
8076 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
8078 string tn = ListTab.SelectedTab.Text;
8082 private void ListTab_MouseDown(object sender, MouseEventArgs e)
8084 if (SettingDialog.TabMouseLock) return;
8085 Point cpos = new Point(e.X, e.Y);
8086 if (e.Button == MouseButtons.Left)
8088 for (int i = 0; i < ListTab.TabPages.Count; i++)
8090 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8093 _tabMouseDownPoint = e.Location;
8104 private void ListTab_DragEnter(object sender, DragEventArgs e)
8106 if (e.Data.GetDataPresent(typeof(TabPage)))
8107 e.Effect = DragDropEffects.Move;
8109 e.Effect = DragDropEffects.None;
8112 private void ListTab_DragDrop(object sender, DragEventArgs e)
8114 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8119 Point cpos = new Point(e.X, e.Y);
8120 Point spos = ListTab.PointToClient(cpos);
8122 for (i = 0; i < ListTab.TabPages.Count; i++)
8124 Rectangle rect = ListTab.GetTabRect(i);
8125 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8126 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8128 tn = ListTab.TabPages[i].Text;
8129 if (spos.X <= (rect.Left + rect.Right) / 2)
8138 //タブのないところにドロップ->最後尾へ移動
8139 if (string.IsNullOrEmpty(tn))
8141 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8143 i = ListTab.TabPages.Count - 1;
8146 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8147 if (tp.Text == tn) return;
8149 ReOrderTab(tp.Text, tn, bef);
8152 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8155 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8157 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8160 ListTab.SuspendLayout();
8163 for (int j = 0; j < ListTab.TabPages.Count; j++)
8165 if (ListTab.TabPages[j].Text == targetTabText)
8167 mTp = ListTab.TabPages[j];
8168 ListTab.TabPages.Remove(mTp);
8169 if (j < baseIndex) baseIndex -= 1;
8173 if (isBeforeBaseTab)
8174 ListTab.TabPages.Insert(baseIndex, mTp);
8176 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8178 ListTab.ResumeLayout();
8183 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8185 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8186 //isReply:true=@,false=DM
8187 if (!StatusText.Enabled) return;
8188 if (_curList == null) return;
8189 if (_curTab == null) return;
8190 if (!this.ExistCurrentPost) return;
8192 // 複数あてリプライはReplyではなく通常ポスト
8193 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8194 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8195 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8197 if (_curList.SelectedIndices.Count > 0)
8200 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8203 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8206 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8207 StatusText.SelectionStart = StatusText.Text.Length;
8209 _reply_to_id = null;
8210 _reply_to_name = null;
8213 if (string.IsNullOrEmpty(StatusText.Text))
8217 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8218 StatusText.Text = "@" + _curPost.ScreenName + " ";
8219 if (_curPost.RetweetedId != null)
8221 _reply_to_id = _curPost.RetweetedId.Value;
8225 _reply_to_id = _curPost.StatusId;
8227 _reply_to_name = _curPost.ScreenName;
8235 //1件選んでEnter or DoubleClick
8236 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8238 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8241 if (_curPost.RetweetedId != null)
8243 _reply_to_id = _curPost.RetweetedId.Value;
8247 _reply_to_id = _curPost.StatusId;
8249 _reply_to_name = _curPost.ScreenName;
8253 if (!StatusText.Text.StartsWith("@"))
8256 if (StatusText.Text.StartsWith(". "))
8259 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8260 _reply_to_id = null;
8261 _reply_to_name = null;
8266 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8267 if (_curPost.RetweetedId != null)
8269 _reply_to_id = _curPost.RetweetedId.Value;
8273 _reply_to_id = _curPost.StatusId;
8275 _reply_to_name = _curPost.ScreenName;
8282 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8283 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8284 _reply_to_id = null;
8285 _reply_to_name = null;
8290 //1件選んでCtrl-Rの場合(返信先操作せず)
8291 int sidx = StatusText.SelectionStart;
8292 string id = "@" + _curPost.ScreenName + " ";
8295 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8300 StatusText.Text = StatusText.Text.Insert(sidx, id);
8302 //if (StatusText.Text.StartsWith("@"))
8305 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8306 // sidx += 5 + _curPost.ScreenName.Length;
8311 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8312 // sidx += 3 + _curPost.ScreenName.Length;
8314 StatusText.SelectionStart = sidx;
8317 //_reply_to_name = null;
8325 if (!isAuto && !isReply) return;
8327 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8331 //Enter or DoubleClick
8333 string sTxt = StatusText.Text;
8334 if (!sTxt.StartsWith(". "))
8337 _reply_to_id = null;
8338 _reply_to_name = null;
8340 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8342 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8343 if (!sTxt.Contains("@" + post.ScreenName + " "))
8345 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8346 //sTxt = "@" + post.ScreenName + " " + sTxt;
8349 StatusText.Text = sTxt;
8354 if (_curList.SelectedIndices.Count > 1)
8359 int sidx = StatusText.SelectionStart;
8360 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8362 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8363 if (!ids.Contains("@" + post.ScreenName + " ") &&
8364 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8366 ids += "@" + post.ScreenName + " ";
8370 foreach (string nm in post.ReplyToList)
8372 if (!ids.Contains("@" + nm + " ") &&
8373 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8375 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8377 ids += "@" + m.Result("${id}") + " ";
8379 ids += "@" + nm + " ";
8384 if (ids.Length == 0) return;
8385 if (!StatusText.Text.StartsWith(". "))
8387 StatusText.Text = ". " + StatusText.Text;
8389 _reply_to_id = null;
8390 _reply_to_name = null;
8394 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8399 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8401 //if (StatusText.Text.StartsWith("@"))
8403 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8404 // sidx += 2 + ids.Length;
8408 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8409 // sidx += 1 + ids.Length;
8411 StatusText.SelectionStart = sidx;
8417 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8420 int sidx = StatusText.SelectionStart;
8421 PostClass post = _curPost;
8422 if (!ids.Contains("@" + post.ScreenName + " ") &&
8423 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8425 ids += "@" + post.ScreenName + " ";
8427 foreach (string nm in post.ReplyToList)
8429 if (!ids.Contains("@" + nm + " ") &&
8430 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8432 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8434 ids += "@" + m.Result("${id}") + " ";
8436 ids += "@" + nm + " ";
8439 if (!string.IsNullOrEmpty(post.RetweetedBy))
8441 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8442 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8444 ids += "@" + post.RetweetedBy + " ";
8447 if (ids.Length == 0) return;
8448 if (string.IsNullOrEmpty(StatusText.Text))
8451 StatusText.Text = ids;
8452 StatusText.SelectionStart = ids.Length;
8454 if (post.RetweetedId != null)
8456 _reply_to_id = post.RetweetedId.Value;
8460 _reply_to_id = post.StatusId;
8462 _reply_to_name = post.ScreenName;
8468 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8473 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8475 StatusText.SelectionStart = sidx;
8481 StatusText.SelectionStart = StatusText.Text.Length;
8486 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8491 private static int iconCnt = 0;
8492 private static int blinkCnt = 0;
8493 private static bool blink = false;
8494 private static bool idle = false;
8496 private void RefreshTasktrayIcon(bool forceRefresh)
8498 if (_colorize) Colorize();
8499 if (!TimerRefreshIcon.Enabled) return;
8500 //Static usCheckCnt As int = 0
8502 //Static iconDlListTopItem As ListViewItem = null
8504 if (forceRefresh) idle = false;
8506 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8507 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8509 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8511 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8517 //if (usCheckCnt > 300) //1min
8520 // if (!this.IsReceivedUserStream)
8522 // TraceOut("ReconnectUserStream");
8523 // tw.ReconnectUserStream();
8528 foreach (BackgroundWorker bw in this._bw)
8530 if (bw != null && bw.IsBusy)
8545 SaveConfigsAll(true);
8550 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8552 _myStatusError = false;
8556 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8557 if (SettingDialog.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8559 if (blinkCnt > 0) return;
8561 if (blink || SettingDialog.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8563 NotifyIcon1.Icon = ReplyIcon;
8567 NotifyIcon1.Icon = ReplyIconBlink;
8575 //優先度:エラー→オフライン→アイドル
8579 NotifyIcon1.Icon = NIconAtRed;
8582 if (_myStatusOnline)
8584 NotifyIcon1.Icon = NIconAt;
8588 NotifyIcon1.Icon = NIconAtSmoke;
8592 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8595 this.RefreshTasktrayIcon(false);
8598 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8600 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8601 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8603 if (ListTab != null && ListTab.SelectedTab != null)
8604 _rclickTabName = ListTab.SelectedTab.Text;
8609 if (_statuses == null) return;
8610 if (_statuses.Tabs == null) return;
8612 TabClass tb = _statuses.Tabs[_rclickTabName];
8613 if (tb == null) return;
8615 NotifyDispMenuItem.Checked = tb.Notify;
8616 this.NotifyTbMenuItem.Checked = tb.Notify;
8618 soundfileListup = true;
8619 SoundFileComboBox.Items.Clear();
8620 this.SoundFileTbComboBox.Items.Clear();
8621 SoundFileComboBox.Items.Add("");
8622 this.SoundFileTbComboBox.Items.Add("");
8623 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8624 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8626 oDir = oDir.GetDirectories("Sounds")[0];
8628 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8630 SoundFileComboBox.Items.Add(oFile.Name);
8631 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8633 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8634 if (idx == -1) idx = 0;
8635 SoundFileComboBox.SelectedIndex = idx;
8636 this.SoundFileTbComboBox.SelectedIndex = idx;
8637 soundfileListup = false;
8638 UreadManageMenuItem.Checked = tb.UnreadManage;
8639 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8641 TabMenuControl(_rclickTabName);
8644 private void TabMenuControl(string tabName)
8646 this.FilterEditMenuItem.Enabled = true;
8647 this.EditRuleTbMenuItem.Enabled = true;
8649 if (_statuses.IsDefaultTab(tabName))
8651 this.ProtectTabMenuItem.Enabled = false;
8652 this.ProtectTbMenuItem.Enabled = false;
8656 this.ProtectTabMenuItem.Enabled = true;
8657 this.ProtectTbMenuItem.Enabled = true;
8660 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8662 this.ProtectTabMenuItem.Checked = true;
8663 this.ProtectTbMenuItem.Checked = true;
8664 this.DeleteTabMenuItem.Enabled = false;
8665 this.DeleteTbMenuItem.Enabled = false;
8669 this.ProtectTabMenuItem.Checked = false;
8670 this.ProtectTbMenuItem.Checked = false;
8671 this.DeleteTabMenuItem.Enabled = true;
8672 this.DeleteTbMenuItem.Enabled = true;
8676 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8678 var checkState = ((ToolStripMenuItem)sender).Checked;
8681 this.ProtectTbMenuItem.Checked = checkState;
8682 this.ProtectTabMenuItem.Checked = checkState;
8685 this.DeleteTabMenuItem.Enabled = !checkState;
8686 this.DeleteTbMenuItem.Enabled = !checkState;
8688 if (string.IsNullOrEmpty(_rclickTabName)) return;
8689 _statuses.Tabs[_rclickTabName].Protected = checkState;
8694 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8696 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8697 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8699 if (string.IsNullOrEmpty(_rclickTabName)) return;
8700 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8705 public void ChangeTabUnreadManage(string tabName, bool isManage)
8708 for (idx = 0; idx < ListTab.TabCount; idx++)
8710 if (ListTab.TabPages[idx].Text == tabName) break;
8713 _statuses.SetTabUnreadManage(tabName, isManage);
8714 if (SettingDialog.TabIconDisp)
8716 if (_statuses.Tabs[tabName].UnreadCount > 0)
8717 ListTab.TabPages[idx].ImageIndex = 0;
8719 ListTab.TabPages[idx].ImageIndex = -1;
8722 if (_curTab.Text == tabName)
8724 this.PurgeListViewItemCache();
8728 SetMainWindowTitle();
8729 SetStatusLabelUrl();
8730 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8733 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8735 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8736 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8738 if (string.IsNullOrEmpty(_rclickTabName)) return;
8740 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8745 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8747 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8749 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8754 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8756 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8758 RemoveSpecifiedTab(_rclickTabName, true);
8762 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8764 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8765 fltDialog.SetCurrent(_rclickTabName);
8766 fltDialog.ShowDialog(this);
8767 this.TopMost = SettingDialog.AlwaysTop;
8771 this.Cursor = Cursors.WaitCursor;
8772 this.PurgeListViewItemCache();
8775 _statuses.FilterAll();
8776 foreach (TabPage tb in ListTab.TabPages)
8778 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
8779 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
8781 if (SettingDialog.TabIconDisp)
8786 if (SettingDialog.TabIconDisp)
8790 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8794 this.Cursor = Cursors.Default;
8799 private void AddTabMenuItem_Click(object sender, EventArgs e)
8801 string tabName = null;
8802 MyCommon.TabUsageType tabUsage;
8803 using (InputTabName inputName = new InputTabName())
8805 inputName.TabName = _statuses.GetUniqueTabName();
8806 inputName.IsShowUsage = true;
8807 inputName.ShowDialog();
8808 if (inputName.DialogResult == DialogResult.Cancel) return;
8809 tabName = inputName.TabName;
8810 tabUsage = inputName.Usage;
8812 this.TopMost = SettingDialog.AlwaysTop;
8813 if (!string.IsNullOrEmpty(tabName))
8816 ListElement list = null;
8817 if (tabUsage == MyCommon.TabUsageType.Lists)
8819 using (ListAvailable listAvail = new ListAvailable())
8821 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8822 if (listAvail.SelectedList == null) return;
8823 list = listAvail.SelectedList;
8826 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8828 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8829 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8835 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8837 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8838 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8839 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8841 if (tabUsage == MyCommon.TabUsageType.Lists)
8843 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8844 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8845 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, tabName);
8851 private void TabMenuItem_Click(object sender, EventArgs e)
8854 foreach (int idx in _curList.SelectedIndices)
8858 if (!SelectTab(out tabName)) return;
8860 fltDialog.SetCurrent(tabName);
8861 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8863 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8867 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8869 fltDialog.ShowDialog(this);
8870 this.TopMost = SettingDialog.AlwaysTop;
8875 this.Cursor = Cursors.WaitCursor;
8876 this.PurgeListViewItemCache();
8879 _statuses.FilterAll();
8880 foreach (TabPage tb in ListTab.TabPages)
8882 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
8883 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
8885 if (SettingDialog.TabIconDisp)
8890 if (SettingDialog.TabIconDisp)
8894 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8898 this.Cursor = Cursors.Default;
8901 if (this.ListTab.SelectedTab != null &&
8902 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8904 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8908 protected override bool ProcessDialogKey(Keys keyData)
8910 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8911 if ((keyData & Keys.KeyCode) == Keys.Enter)
8913 if (StatusText.Focused)
8915 bool _NewLine = false;
8918 if (SettingDialog.PostCtrlEnter) //Ctrl+Enter投稿時
8920 if (StatusText.Multiline)
8922 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8924 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8928 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8932 else if (SettingDialog.PostShiftEnter) //SHift+Enter投稿時
8934 if (StatusText.Multiline)
8936 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8938 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8942 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8948 if (StatusText.Multiline)
8950 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8952 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8953 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8957 if (((keyData & Keys.Shift) == Keys.Shift) ||
8958 (((keyData & Keys.Control) != Keys.Control) &&
8959 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8965 int pos1 = StatusText.SelectionStart;
8966 if (StatusText.SelectionLength > 0)
8968 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8970 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8971 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8976 PostButton_Click(null, null);
8980 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8981 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8982 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8984 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
8989 return base.ProcessDialogKey(keyData);
8992 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
8994 MakeReplyOrDirectStatus(false, true, true);
8997 private void IDRuleMenuItem_Click(object sender, EventArgs e)
9002 if (_curList.SelectedIndices.Count == 0) return;
9005 if (!SelectTab(out tabName)) return;
9009 MoveOrCopy(ref mv, ref mk);
9011 List<string> ids = new List<string>();
9012 foreach (int idx in _curList.SelectedIndices)
9014 PostClass post = _statuses[_curTab.Text, idx];
9015 if (!ids.Contains(post.ScreenName))
9017 PostFilterRule fc = new PostFilterRule();
9018 ids.Add(post.ScreenName);
9019 if (post.RetweetedId == null)
9021 fc.FilterName = post.ScreenName;
9025 fc.FilterName = post.RetweetedBy;
9027 fc.UseNameField = true;
9028 fc.MoveMatches = mv;
9029 fc.MarkMatches = mk;
9030 fc.UseRegex = false;
9031 fc.FilterByUrl = false;
9032 _statuses.Tabs[tabName].AddFilter(fc);
9037 List<string> atids = new List<string>();
9038 foreach (string id in ids)
9040 atids.Add("@" + id);
9042 int cnt = AtIdSupl.ItemCount;
9043 AtIdSupl.AddRangeItem(atids.ToArray());
9044 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
9049 this.Cursor = Cursors.WaitCursor;
9050 this.PurgeListViewItemCache();
9053 _statuses.FilterAll();
9054 foreach (TabPage tb in ListTab.TabPages)
9056 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
9057 if (_statuses.ContainsTab(tb.Text))
9059 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
9061 if (SettingDialog.TabIconDisp)
9066 if (SettingDialog.TabIconDisp)
9071 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9075 this.Cursor = Cursors.Default;
9080 private bool SelectTab(out string tabName)
9087 using (var dialog = new TabsDialog(_statuses))
9089 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
9091 var selectedTab = dialog.SelectedTab;
9092 tabName = selectedTab == null ? null : selectedTab.TabName;
9095 ListTab.SelectedTab.Focus();
9097 if (tabName == null)
9099 using (InputTabName inputName = new InputTabName())
9101 inputName.TabName = _statuses.GetUniqueTabName();
9102 inputName.ShowDialog();
9103 if (inputName.DialogResult == DialogResult.Cancel) return false;
9104 tabName = inputName.TabName;
9106 this.TopMost = SettingDialog.AlwaysTop;
9107 if (!string.IsNullOrEmpty(tabName))
9109 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
9111 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
9112 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
9130 private void MoveOrCopy(ref bool move, ref bool mark)
9134 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
9135 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9143 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
9144 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9150 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
9155 private void CopyURLMenuItem_Click(object sender, EventArgs e)
9160 private void SelectAllMenuItem_Click(object sender, EventArgs e)
9162 if (StatusText.Focused)
9165 StatusText.SelectAll();
9169 // ListView上でのCtrl+A
9170 for (int i = 0; i < _curList.VirtualListSize; i++)
9172 _curList.SelectedIndices.Add(i);
9177 private void MoveMiddle()
9183 if (_curList.SelectedIndices.Count == 0) return;
9185 int idx = _curList.SelectedIndices[0];
9187 _item = _curList.GetItemAt(0, 25);
9193 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9195 idx2 = _curList.VirtualListSize - 1;
9199 idx -= Math.Abs(idx1 - idx2) / 2;
9200 if (idx < 0) idx = 0;
9202 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9203 _curList.EnsureVisible(idx);
9206 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9208 if (PostBrowser.Document.Links.Count > 0)
9210 UrlDialog.ClearUrl();
9212 string openUrlStr = "";
9214 if (PostBrowser.Document.Links.Count == 1)
9219 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9221 catch (ArgumentException)
9230 if (string.IsNullOrEmpty(urlStr)) return;
9231 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9235 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9238 string linkText = "";
9242 urlStr = linkElm.GetAttribute("title");
9243 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9244 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9245 linkText = linkElm.InnerText;
9246 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9248 linkText = "@" + linkText;
9251 catch (ArgumentException)
9260 if (string.IsNullOrEmpty(urlStr)) continue;
9261 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9265 if (UrlDialog.ShowDialog() == DialogResult.OK)
9267 openUrlStr = UrlDialog.SelectedUrl;
9274 this.TopMost = SettingDialog.AlwaysTop;
9276 if (string.IsNullOrEmpty(openUrlStr)) return;
9278 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9279 openUrlStr.StartsWith("https://twitter.com/search?q="))
9282 string urlStr = Uri.UnescapeDataString(openUrlStr);
9283 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9284 HashSupl.AddItem(hash);
9285 HashMgr.AddHashToHistory(hash.Trim(), false);
9286 AddNewTabForSearch(hash);
9291 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9292 if (SettingDialog.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9293 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9295 OpenUriAsync(openUrlStr);
9301 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9303 if (string.IsNullOrEmpty(_rclickTabName)) return;
9304 ClearTab(_rclickTabName, true);
9307 private void ClearTab(string tabName, bool showWarning)
9311 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9312 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9318 _statuses.ClearTabIds(tabName);
9319 if (ListTab.SelectedTab.Text == tabName)
9322 _anchorFlag = false;
9323 this.PurgeListViewItemCache();
9327 foreach (TabPage tb in ListTab.TabPages)
9329 if (tb.Text == tabName)
9332 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9336 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9338 SetMainWindowTitle();
9339 SetStatusLabelUrl();
9342 private static long followers = 0;
9344 private void SetMainWindowTitle()
9347 StringBuilder ttl = new StringBuilder(256);
9350 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
9351 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9352 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9353 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9355 foreach (string key in _statuses.Tabs.Keys)
9357 ur += _statuses.Tabs[key].UnreadCount;
9358 al += _statuses.Tabs[key].AllCount;
9362 if (SettingDialog.DispUsername) ttl.Append(tw.Username).Append(" - ");
9363 ttl.Append(Application.ProductName);
9365 switch (SettingDialog.DispLatestPost)
9367 case MyCommon.DispTitleEnum.Ver:
9368 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9370 case MyCommon.DispTitleEnum.Post:
9371 if (_history != null && _history.Count > 1)
9372 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9374 case MyCommon.DispTitleEnum.UnreadRepCount:
9375 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9377 case MyCommon.DispTitleEnum.UnreadAllCount:
9378 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9380 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9381 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9383 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9384 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9386 case MyCommon.DispTitleEnum.OwnStatus:
9387 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9388 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9394 this.Text = ttl.ToString();
9396 catch (AccessViolationException)
9398 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9402 private string GetStatusLabelText()
9405 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9406 if (_statuses == null) return "";
9407 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9408 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9409 if (tbRep == null || tbDm == null) return "";
9410 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9415 StringBuilder slbl = new StringBuilder(256);
9418 foreach (string key in _statuses.Tabs.Keys)
9420 ur += _statuses.Tabs[key].UnreadCount;
9421 al += _statuses.Tabs[key].AllCount;
9422 if (key.Equals(_curTab.Text))
9424 tur = _statuses.Tabs[key].UnreadCount;
9425 tal = _statuses.Tabs[key].AllCount;
9435 UnreadAtCounter = urat;
9437 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9438 if (SettingDialog.TimelinePeriodInt == 0)
9440 slbl.Append(Properties.Resources.SetStatusLabelText2);
9444 slbl.Append(SettingDialog.TimelinePeriodInt.ToString() + Properties.Resources.SetStatusLabelText3);
9446 return slbl.ToString();
9449 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9453 if (this.InvokeRequired && !this.IsDisposed)
9455 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9459 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9460 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9462 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9466 catch (ObjectDisposedException)
9470 catch (InvalidOperationException)
9476 private void SetStatusLabelUrl()
9478 StatusLabelUrl.Text = GetStatusLabelText();
9481 public void SetStatusLabel(string text)
9483 StatusLabel.Text = text;
9486 private static StringBuilder ur = new StringBuilder(64);
9488 private void SetNotifyIconText()
9490 // タスクトレイアイコンのツールチップテキスト書き換え
9492 ur.Remove(0, ur.Length);
9493 if (SettingDialog.DispUsername)
9495 ur.Append(tw.Username);
9498 ur.Append(Application.ProductName);
9500 ur.Append("(Debug Build)");
9502 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9505 ur.Append(UnreadCounter);
9507 ur.Append(UnreadAtCounter);
9510 NotifyIcon1.Text = ur.ToString();
9513 internal void CheckReplyTo(string StatusText)
9517 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9519 foreach (Match hm in m)
9521 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9523 hstr += "#" + hm.Result("$3") + " ";
9524 HashSupl.AddItem("#" + hm.Result("$3"));
9527 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9529 hstr += HashMgr.UseHash;
9531 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9533 // 本当にリプライ先指定すべきかどうかの判定
9534 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9536 if (SettingDialog.UseAtIdSupplement)
9538 int bCnt = AtIdSupl.ItemCount;
9539 foreach (Match mid in m)
9541 AtIdSupl.AddItem(mid.Result("${id}"));
9543 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9546 // リプライ先ステータスIDの指定がない場合は指定しない
9547 if (_reply_to_id == null) return;
9549 // リプライ先ユーザー名がない場合も指定しない
9550 if (string.IsNullOrEmpty(_reply_to_name))
9552 _reply_to_id = null;
9557 // 次の条件を満たす場合に in_reply_to_status_id 指定
9558 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9559 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9560 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9564 if (StatusText.StartsWith("@"))
9566 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9570 foreach (Match mid in m)
9572 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9577 _reply_to_id = null;
9578 _reply_to_name = null;
9582 private void TweenMain_Resize(object sender, EventArgs e)
9584 if (!_initialLayout && SettingDialog.MinimizeToTray && WindowState == FormWindowState.Minimized)
9586 this.Visible = false;
9588 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9590 this.ClientSize = _cfgLocal.FormSize;
9591 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9592 this.DesktopLocation = _cfgLocal.FormLocation;
9593 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9594 //if (_cfgLocal.AdSplitterDistance > this.SplitContainer4.Panel1MinSize &&
9595 // _cfgLocal.AdSplitterDistance < this.SplitContainer4.Height - this.SplitContainer4.Panel2MinSize - this.SplitContainer4.SplitterWidth)
9597 // this.SplitContainer4.SplitterDistance = _cfgLocal.AdSplitterDistance; //Splitterの位置設定
9599 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9600 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9602 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9605 StatusText.Multiline = _cfgLocal.StatusMultiline;
9606 if (StatusText.Multiline)
9608 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9609 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9611 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9613 StatusText.Height = _cfgLocal.StatusTextHeight;
9617 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9619 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9622 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9624 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9626 _initialLayout = false;
9628 if (this.WindowState != FormWindowState.Minimized)
9630 _formWindowState = this.WindowState;
9634 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9636 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9637 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9638 if (PlaySoundMenuItem.Checked)
9640 SettingDialog.PlaySound = true;
9644 SettingDialog.PlaySound = false;
9646 _modifySettingCommon = true;
9649 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9651 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9653 _mySpDis = SplitContainer1.SplitterDistance;
9654 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9655 _modifySettingLocal = true;
9659 private void doRepliedStatusOpen()
9661 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9663 if (MyCommon.IsKeyDown(Keys.Shift))
9665 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9668 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9670 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9671 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9675 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9677 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9678 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9679 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9682 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9687 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9689 doRepliedStatusOpen();
9693 /// UserPicture.Image に設定されている画像を破棄します。
9695 private void ClearUserPicture()
9697 if (this.UserPicture.Image != null)
9699 var oldImage = this.UserPicture.Image;
9700 this.UserPicture.Image = null;
9705 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9707 //発言詳細のアイコン右クリック時のメニュー制御
9708 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9710 string name = _curPost.ImageUrl;
9711 if (name != null && name.Length > 0)
9713 int idx = name.LastIndexOf('/');
9716 name = Path.GetFileName(name.Substring(idx));
9717 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9719 name = name.Replace("_normal", "");
9720 this.IconNameToolStripMenuItem.Text = name;
9721 this.IconNameToolStripMenuItem.Enabled = true;
9725 this.IconNameToolStripMenuItem.Enabled = false;
9726 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9731 this.IconNameToolStripMenuItem.Enabled = false;
9732 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9735 this.ReloadIconToolStripMenuItem.Enabled = true;
9737 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9739 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9743 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9748 this.IconNameToolStripMenuItem.Enabled = false;
9749 this.ReloadIconToolStripMenuItem.Enabled = false;
9750 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9751 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9756 this.IconNameToolStripMenuItem.Enabled = false;
9757 this.ReloadIconToolStripMenuItem.Enabled = false;
9758 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9759 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9761 if (NameLabel.Tag != null)
9763 string id = (string)NameLabel.Tag;
9764 if (id == tw.Username)
9766 FollowToolStripMenuItem.Enabled = false;
9767 UnFollowToolStripMenuItem.Enabled = false;
9768 ShowFriendShipToolStripMenuItem.Enabled = false;
9769 ShowUserStatusToolStripMenuItem.Enabled = true;
9770 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9771 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9772 ListManageUserContextToolStripMenuItem3.Enabled = true;
9776 FollowToolStripMenuItem.Enabled = true;
9777 UnFollowToolStripMenuItem.Enabled = true;
9778 ShowFriendShipToolStripMenuItem.Enabled = true;
9779 ShowUserStatusToolStripMenuItem.Enabled = true;
9780 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9781 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9782 ListManageUserContextToolStripMenuItem3.Enabled = true;
9787 FollowToolStripMenuItem.Enabled = false;
9788 UnFollowToolStripMenuItem.Enabled = false;
9789 ShowFriendShipToolStripMenuItem.Enabled = false;
9790 ShowUserStatusToolStripMenuItem.Enabled = false;
9791 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9792 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9793 ListManageUserContextToolStripMenuItem3.Enabled = false;
9797 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9799 if (_curPost == null) return;
9800 string name = _curPost.ImageUrl;
9801 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9804 private /* async */ void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9806 if (this._curPost == null) return;
9808 var imageUrl = this._curPost.ImageUrl;
9809 var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
9811 this.IconCache.DownloadImageAsync(imageUrl, force: true)
9814 this.ClearUserPicture();
9818 t.Exception.Flatten().Handle(x => x is WebException || x is InvalidImageException || x is TaskCanceledException);
9819 this.UserPicture.ShowErrorImage();
9823 this.UserPicture.Image = t.Result.Clone() ;
9828 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9830 if (_curPost == null) return;
9831 string name = _curPost.ImageUrl;
9832 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9834 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9836 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9842 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9844 if (_curPost == null) return;
9845 string name = _curPost.ImageUrl;
9847 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9849 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9853 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9855 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9857 using (Graphics g = Graphics.FromImage(bmp2))
9859 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9860 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9862 bmp2.Save(this.SaveFileDialog1.FileName);
9868 //処理中にキャッシュアウトする可能性あり
9873 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9875 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9876 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9877 _modifySettingLocal = true;
9880 private void StatusText_MultilineChanged(object sender, EventArgs e)
9882 if (this.StatusText.Multiline)
9883 this.StatusText.ScrollBars = ScrollBars.Vertical;
9885 this.StatusText.ScrollBars = ScrollBars.None;
9887 _modifySettingLocal = true;
9890 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9893 StatusText.Multiline = MultiLineMenuItem.Checked;
9894 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9895 if (MultiLineMenuItem.Checked)
9897 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9898 SplitContainer2.SplitterDistance = 0;
9900 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9904 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9906 _modifySettingLocal = true;
9909 private bool UrlConvert(MyCommon.UrlConverter Converter_Type)
9911 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9912 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9914 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9915 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9916 //Appendix A. Collected ABNF for URI
9917 //http://www.ietf.org/rfc/rfc3986.txt
9921 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9923 if (StatusText.SelectionLength > 0)
9925 string tmp = StatusText.SelectedText;
9926 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9927 if (tmp.StartsWith("http"))
9929 // 文字列が選択されている場合はその文字列について処理
9931 //nico.ms使用、nicovideoにマッチしたら変換
9932 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9934 result = nicoms.Shorten(tmp);
9936 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9938 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9939 result = ShortUrl.Make(Converter_Type, tmp);
9940 if (result.Equals("Can't convert"))
9942 StatusLabel.Text = result.Insert(0, Converter_Type.ToString() + ":");
9951 if (!string.IsNullOrEmpty(result))
9953 urlUndo undotmp = new urlUndo();
9955 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9956 StatusText.SelectedText = result;
9959 undotmp.Before = tmp;
9960 undotmp.After = result;
9962 if (urlUndoBuffer == null)
9964 urlUndoBuffer = new List<urlUndo>();
9965 UrlUndoToolStripMenuItem.Enabled = true;
9968 urlUndoBuffer.Add(undotmp);
9974 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9975 @"(?<url>(?<protocol>https?://)" +
9976 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9977 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9978 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9979 // 正規表現にマッチしたURL文字列をtinyurl化
9980 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9982 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9983 string tmp = mt.Result("${url}");
9984 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9985 urlUndo undotmp = new urlUndo();
9988 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9990 //nico.ms使用、nicovideoにマッチしたら変換
9991 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9993 result = nicoms.Shorten(tmp);
9995 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9997 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9998 result = ShortUrl.Make(Converter_Type, tmp);
9999 if (result.Equals("Can't convert"))
10001 StatusLabel.Text = result.Insert(0, Converter_Type.ToString() + ":");
10010 if (!string.IsNullOrEmpty(result))
10012 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
10013 StatusText.SelectedText = result;
10015 undotmp.Before = mt.Result("${url}");
10016 undotmp.After = result;
10018 if (urlUndoBuffer == null)
10020 urlUndoBuffer = new List<urlUndo>();
10021 UrlUndoToolStripMenuItem.Enabled = true;
10024 urlUndoBuffer.Add(undotmp);
10032 private void doUrlUndo()
10034 if (urlUndoBuffer != null)
10036 string tmp = StatusText.Text;
10037 foreach (urlUndo data in urlUndoBuffer)
10039 tmp = tmp.Replace(data.After, data.Before);
10041 StatusText.Text = tmp;
10042 urlUndoBuffer = null;
10043 UrlUndoToolStripMenuItem.Enabled = false;
10044 StatusText.SelectionStart = 0;
10045 StatusText.SelectionLength = 0;
10049 private void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
10051 UrlConvert(MyCommon.UrlConverter.TinyUrl);
10054 private void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
10056 UrlConvert(MyCommon.UrlConverter.Isgd);
10059 private void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
10061 UrlConvert(MyCommon.UrlConverter.Twurl);
10064 private void UxnuMenuItem_Click(object sender, EventArgs e)
10066 UrlConvert(MyCommon.UrlConverter.Uxnu);
10069 private void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
10071 if (!UrlConvert(SettingDialog.AutoShortUrlFirst))
10073 MyCommon.UrlConverter svc = SettingDialog.AutoShortUrlFirst;
10074 Random rnd = new Random();
10075 // 前回使用した短縮URLサービス以外を選択する
10078 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
10080 while (svc == SettingDialog.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
10085 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
10090 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
10092 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10093 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
10094 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
10095 _modifySettingCommon = true;
10098 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
10100 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10101 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
10102 _cfgCommon.ListLock = ListLockMenuItem.Checked;
10103 _modifySettingCommon = true;
10106 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
10108 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
10109 MenuStrip1.Tag = new Object();
10110 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
10113 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
10115 if (this.Tag != null) // 設定された戻り先へ遷移
10117 if (this.Tag == this.ListTab.SelectedTab)
10118 ((Control)this.ListTab.SelectedTab.Tag).Select();
10120 ((Control)this.Tag).Select();
10122 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
10124 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
10126 this.Tag = ListTab.SelectedTab.Tag;
10127 ((Control)this.Tag).Select();
10130 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
10131 MenuStrip1.Tag = null;
10134 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
10136 DetailsListView lst = (DetailsListView)sender;
10137 if (_cfgLocal == null) return;
10141 _cfgLocal.Width1 = lst.Columns[0].Width;
10142 _cfgLocal.Width3 = lst.Columns[1].Width;
10146 int[] darr = new int[lst.Columns.Count];
10147 for (int i = 0; i < lst.Columns.Count; i++)
10149 darr[lst.Columns[i].DisplayIndex] = i;
10151 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
10153 for (int i = 0; i < lst.Columns.Count; i++)
10158 _cfgLocal.DisplayIndex1 = i;
10161 _cfgLocal.DisplayIndex2 = i;
10164 _cfgLocal.DisplayIndex3 = i;
10167 _cfgLocal.DisplayIndex4 = i;
10170 _cfgLocal.DisplayIndex5 = i;
10173 _cfgLocal.DisplayIndex6 = i;
10176 _cfgLocal.DisplayIndex7 = i;
10179 _cfgLocal.DisplayIndex8 = i;
10183 _cfgLocal.Width1 = lst.Columns[0].Width;
10184 _cfgLocal.Width2 = lst.Columns[1].Width;
10185 _cfgLocal.Width3 = lst.Columns[2].Width;
10186 _cfgLocal.Width4 = lst.Columns[3].Width;
10187 _cfgLocal.Width5 = lst.Columns[4].Width;
10188 _cfgLocal.Width6 = lst.Columns[5].Width;
10189 _cfgLocal.Width7 = lst.Columns[6].Width;
10190 _cfgLocal.Width8 = lst.Columns[7].Width;
10192 _modifySettingLocal = true;
10193 _isColumnChanged = true;
10196 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10198 DetailsListView lst = (DetailsListView)sender;
10199 if (_cfgLocal == null) return;
10202 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10204 _cfgLocal.Width1 = lst.Columns[0].Width;
10205 _modifySettingLocal = true;
10206 _isColumnChanged = true;
10208 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10210 _cfgLocal.Width3 = lst.Columns[1].Width;
10211 _modifySettingLocal = true;
10212 _isColumnChanged = true;
10217 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10219 _cfgLocal.Width1 = lst.Columns[0].Width;
10220 _modifySettingLocal = true;
10221 _isColumnChanged = true;
10223 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10225 _cfgLocal.Width2 = lst.Columns[1].Width;
10226 _modifySettingLocal = true;
10227 _isColumnChanged = true;
10229 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10231 _cfgLocal.Width3 = lst.Columns[2].Width;
10232 _modifySettingLocal = true;
10233 _isColumnChanged = true;
10235 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10237 _cfgLocal.Width4 = lst.Columns[3].Width;
10238 _modifySettingLocal = true;
10239 _isColumnChanged = true;
10241 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10243 _cfgLocal.Width5 = lst.Columns[4].Width;
10244 _modifySettingLocal = true;
10245 _isColumnChanged = true;
10247 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10249 _cfgLocal.Width6 = lst.Columns[5].Width;
10250 _modifySettingLocal = true;
10251 _isColumnChanged = true;
10253 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10255 _cfgLocal.Width7 = lst.Columns[6].Width;
10256 _modifySettingLocal = true;
10257 _isColumnChanged = true;
10259 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10261 _cfgLocal.Width8 = lst.Columns[7].Width;
10262 _modifySettingLocal = true;
10263 _isColumnChanged = true;
10266 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10269 // SaveConfigsLocal();
10273 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10275 //発言詳細で「選択文字列をコピー」を行う
10276 //WebBrowserコンポーネントのインスタンスを渡す
10277 Type typ = ComponentInstance.ActiveXInstance.GetType();
10278 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10279 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10280 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10283 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10286 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10289 Clipboard.SetDataObject(_selText, false, 5, 100);
10291 catch (Exception ex)
10293 MessageBox.Show(ex.Message);
10297 private void doSearchToolStrip(string url)
10299 //発言詳細で「選択文字列で検索」(選択文字列取得)
10300 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10302 if (_selText != null)
10304 if (url == Properties.Resources.SearchItem4Url)
10307 AddNewTabForSearch(_selText);
10311 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10316 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10319 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10322 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10324 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10327 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10329 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10332 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10334 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10337 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10341 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10342 foreach (Match m in mc)
10344 if (m.Groups["url"].Value == this._postBrowserStatusText)
10346 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10352 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10354 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10356 catch (Exception ex)
10358 MessageBox.Show(ex.Message);
10362 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10364 // URLコピーの項目の表示/非表示
10365 if (PostBrowser.StatusText.StartsWith("http"))
10367 this._postBrowserStatusText = PostBrowser.StatusText;
10368 string name = GetUserId();
10369 UrlCopyContextMenuItem.Enabled = true;
10372 FollowContextMenuItem.Enabled = true;
10373 RemoveContextMenuItem.Enabled = true;
10374 FriendshipContextMenuItem.Enabled = true;
10375 ShowUserStatusContextMenuItem.Enabled = true;
10376 SearchPostsDetailToolStripMenuItem.Enabled = true;
10377 IdFilterAddMenuItem.Enabled = true;
10378 ListManageUserContextToolStripMenuItem.Enabled = true;
10379 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10383 FollowContextMenuItem.Enabled = false;
10384 RemoveContextMenuItem.Enabled = false;
10385 FriendshipContextMenuItem.Enabled = false;
10386 ShowUserStatusContextMenuItem.Enabled = false;
10387 SearchPostsDetailToolStripMenuItem.Enabled = false;
10388 IdFilterAddMenuItem.Enabled = false;
10389 ListManageUserContextToolStripMenuItem.Enabled = false;
10390 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10393 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10394 UseHashtagMenuItem.Enabled = true;
10396 UseHashtagMenuItem.Enabled = false;
10400 this._postBrowserStatusText = "";
10401 UrlCopyContextMenuItem.Enabled = false;
10402 FollowContextMenuItem.Enabled = false;
10403 RemoveContextMenuItem.Enabled = false;
10404 FriendshipContextMenuItem.Enabled = false;
10405 ShowUserStatusContextMenuItem.Enabled = false;
10406 SearchPostsDetailToolStripMenuItem.Enabled = false;
10407 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10408 UseHashtagMenuItem.Enabled = false;
10409 IdFilterAddMenuItem.Enabled = false;
10410 ListManageUserContextToolStripMenuItem.Enabled = false;
10412 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10413 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10414 if (_selText == null)
10416 SelectionSearchContextMenuItem.Enabled = false;
10417 SelectionCopyContextMenuItem.Enabled = false;
10418 SelectionTranslationToolStripMenuItem.Enabled = false;
10422 SelectionSearchContextMenuItem.Enabled = true;
10423 SelectionCopyContextMenuItem.Enabled = true;
10424 SelectionTranslationToolStripMenuItem.Enabled = true;
10426 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10427 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10428 bool fAllFlag = false;
10429 foreach (Match mu in ma)
10431 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10437 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10439 if (_curPost == null)
10440 TranslationToolStripMenuItem.Enabled = false;
10442 TranslationToolStripMenuItem.Enabled = true;
10447 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10449 //発言詳細の選択文字列で現在のタブを検索
10450 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10452 if (_selText != null)
10454 SearchDialog.SWord = _selText;
10455 SearchDialog.CheckCaseSensitive = false;
10456 SearchDialog.CheckRegex = false;
10458 DoTabSearch(SearchDialog.SWord,
10459 SearchDialog.CheckCaseSensitive,
10460 SearchDialog.CheckRegex,
10461 SEARCHTYPE.NextSearch);
10465 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10467 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10468 _modifySettingLocal = true;
10471 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10473 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10475 ImageSelectionPanel.Visible = true;
10476 ImageSelectionPanel.Enabled = true;
10477 TimelinePanel.Visible = false;
10478 TimelinePanel.Enabled = false;
10479 ImagefilePathText.Text = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
10480 ImageFromSelectedFile();
10482 this.BringToFront();
10483 StatusText.Focus();
10485 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10487 var url = GetUrlFromDataObject(e.Data);
10490 if (url.Item2 == null)
10491 appendText = url.Item1;
10493 appendText = url.Item2 + " " + url.Item1;
10495 if (this.StatusText.TextLength == 0)
10496 this.StatusText.Text = appendText;
10498 this.StatusText.Text += " " + appendText;
10500 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10502 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10503 if (data != null) StatusText.Text += data;
10508 /// IDataObject から URL とタイトルの対を取得します
10511 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10513 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10514 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10515 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10517 if (data.GetDataPresent("text/x-moz-url"))
10519 // Firefox, Google Chrome で利用可能
10520 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10522 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10524 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10525 if (lines.Length < 2)
10526 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10528 return new Tuple<string, string>(lines[0], lines[1]);
10531 else if (data.GetDataPresent("IESiteModeToUrl"))
10533 // Internet Exproler 用
10534 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10536 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10538 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10539 if (lines.Length < 2)
10540 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10542 return new Tuple<string, string>(lines[0], lines[1]);
10545 else if (data.GetDataPresent("UniformResourceLocatorW"))
10549 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10551 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10552 return new Tuple<string, string>(url, null);
10556 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10559 private void TweenMain_DragOver(object sender, DragEventArgs e)
10561 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10563 string filename = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
10564 FileInfo fl = new FileInfo(filename);
10565 string ext = fl.Extension;
10567 if (!string.IsNullOrEmpty(this.ImageService) && this.pictureService[this.ImageService].CheckValidFilesize(ext, fl.Length))
10569 e.Effect = DragDropEffects.Copy;
10572 foreach (string svc in ImageServiceCombo.Items)
10574 if (string.IsNullOrEmpty(svc)) continue;
10575 if (this.pictureService[svc].CheckValidFilesize(ext, fl.Length))
10577 ImageServiceCombo.SelectedItem = svc;
10578 e.Effect = DragDropEffects.Copy;
10582 e.Effect = DragDropEffects.None;
10584 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10586 e.Effect = DragDropEffects.Copy;
10588 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10590 e.Effect = DragDropEffects.Copy;
10594 e.Effect = DragDropEffects.None;
10598 public bool IsNetworkAvailable()
10601 nw = MyCommon.IsNetworkAvailable();
10602 _myStatusOnline = nw;
10606 public Task OpenUriAsync(string UriString)
10608 return Task.Factory.StartNew(() =>
10610 string myPath = UriString;
10614 var configBrowserPath = SettingDialog.BrowserPath;
10615 if (!string.IsNullOrEmpty(configBrowserPath))
10617 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10619 int sep = configBrowserPath.IndexOf("\"", 2);
10620 string browserPath = configBrowserPath.Substring(1, sep - 1);
10622 if (sep < configBrowserPath.Length - 1)
10624 arg = configBrowserPath.Substring(sep + 1);
10626 myPath = arg + " " + myPath;
10627 System.Diagnostics.Process.Start(browserPath, myPath);
10631 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10636 System.Diagnostics.Process.Start(myPath);
10641 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10646 private void ListTabSelect(TabPage _tab)
10650 this.PurgeListViewItemCache();
10653 _curList = (DetailsListView)_tab.Tag;
10654 if (_curList.SelectedIndices.Count > 0)
10656 _curItemIndex = _curList.SelectedIndices[0];
10657 _curPost = GetCurTabPost(_curItemIndex);
10661 _curItemIndex = -1;
10665 _anchorPost = null;
10666 _anchorFlag = false;
10670 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10674 for (int i = 0; i < _curList.Columns.Count; i++)
10676 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10681 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10683 ListTabSelect(e.TabPage);
10686 private void SelectListItem(DetailsListView LView, int Index)
10689 Rectangle bnd = new Rectangle();
10691 if (LView.FocusedItem != null)
10693 bnd = LView.FocusedItem.Bounds;
10699 LView.SelectedIndices.Clear();
10701 while (LView.SelectedIndices.Count > 0);
10702 LView.Items[Index].Selected = true;
10703 //LView.SelectedIndices.Add(Index);
10704 LView.Items[Index].Focused = true;
10706 if (flg) LView.Invalidate(bnd);
10709 private void SelectListItem(DetailsListView LView , int[] Index, int FocusedIndex)
10712 Rectangle bnd = new Rectangle();
10714 if (LView.FocusedItem != null)
10716 bnd = LView.FocusedItem.Bounds;
10721 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10725 LView.SelectedIndices.Clear();
10727 while (LView.SelectedIndices.Count > 0);
10728 foreach (int idx in Index)
10730 if (idx > -1 && LView.VirtualListSize > idx)
10732 LView.SelectedIndices.Add(idx);
10733 if (fIdx == -1) fIdx = idx;
10737 if (FocusedIndex > -1 && LView.VirtualListSize > FocusedIndex)
10739 LView.Items[FocusedIndex].Focused = true;
10741 else if (fIdx > -1)
10743 LView.Items[fIdx].Focused = true;
10745 if (flg) LView.Invalidate(bnd);
10748 private void RunAsync(GetWorkerArg args)
10750 BackgroundWorker bw = null;
10751 if (args.type != MyCommon.WORKERTYPE.Follower)
10753 for (int i = 0; i < _bw.Length; i++)
10755 if (_bw[i] != null && !_bw[i].IsBusy)
10763 for (int i = 0; i < _bw.Length; i++)
10765 if (_bw[i] == null)
10767 _bw[i] = new BackgroundWorker();
10769 bw.WorkerReportsProgress = true;
10770 bw.WorkerSupportsCancellation = true;
10771 bw.DoWork += GetTimelineWorker_DoWork;
10772 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10773 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10781 if (_bwFollower == null)
10783 _bwFollower = new BackgroundWorker();
10785 bw.WorkerReportsProgress = true;
10786 bw.WorkerSupportsCancellation = true;
10787 bw.DoWork += GetTimelineWorker_DoWork;
10788 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10789 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10793 if (_bwFollower.IsBusy == false)
10797 if (bw == null) return;
10799 bw.RunWorkerAsync(args);
10802 private void StartUserStream()
10804 tw.NewPostFromStream += tw_NewPostFromStream;
10805 tw.UserStreamStarted += tw_UserStreamStarted;
10806 tw.UserStreamStopped += tw_UserStreamStopped;
10807 tw.PostDeleted += tw_PostDeleted;
10808 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10810 MenuItemUserStream.Text = "&UserStream ■";
10811 MenuItemUserStream.Enabled = true;
10812 StopToolStripMenuItem.Text = "&Start";
10813 StopToolStripMenuItem.Enabled = true;
10814 if (SettingDialog.UserstreamStartup) tw.StartUserStream();
10817 private void TweenMain_Shown(object sender, EventArgs e)
10821 PostBrowser.Url = new Uri("about:blank");
10822 PostBrowser.DocumentText = ""; //発言詳細部初期化
10828 NotifyIcon1.Visible = true;
10830 if (this.IsNetworkAvailable())
10832 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, 0, "");
10833 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
10834 if (SettingDialog.StartupFollowers)
10836 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, 0, "");
10838 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
10840 _waitTimeline = true;
10841 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 1, "");
10843 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 1, "");
10845 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 1, "");
10846 if (SettingDialog.GetFav)
10849 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, 1, "");
10851 _waitPubSearch = true;
10852 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, ""); //tabname="":全タブ
10853 _waitUserTimeline = true;
10854 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, ""); //tabname="":全タブ
10856 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, ""); //tabname="":全タブ
10859 while (IsInitialRead() && !MyCommon._endingFlag)
10861 System.Threading.Thread.Sleep(100);
10862 Application.DoEvents();
10865 if (j > 1200) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10868 if (MyCommon._endingFlag)
10874 if (MyCommon._endingFlag) return;
10876 if (ApplicationSettings.VersionInfoUrl != null)
10878 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10879 if (SettingDialog.StartupVersion)
10880 CheckNewVersion(true);
10884 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10885 this.VerUpMenuItem.Enabled = false;
10886 this.VerUpMenuItem.Available = false;
10887 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10891 if (!tw.GetFollowersSuccess && SettingDialog.StartupFollowers)
10892 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, 0, "");
10895 if (!tw.GetNoRetweetSuccess)
10896 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
10899 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10900 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
10902 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10903 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10905 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10906 SettingStripMenuItem_Click(null, null);
10913 TimerTimeline.Enabled = true;
10916 private bool IsInitialRead()
10918 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10921 private void doGetFollowersMenu()
10923 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, 0, "");
10924 DispSelectedPost(true);
10927 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10929 doGetFollowersMenu();
10932 private void doReTweetUnofficial()
10935 if (this.ExistCurrentPost)
10937 if (_curPost.IsDm ||
10938 !StatusText.Enabled) return;
10940 if (_curPost.IsProtect)
10942 MessageBox.Show("Protected.");
10945 string rtdata = _curPost.Text;
10946 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10948 this._reply_to_id = null;
10949 this._reply_to_name = null;
10951 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10953 StatusText.SelectionStart = 0;
10954 StatusText.Focus();
10958 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10960 doReTweetUnofficial();
10963 private void doReTweetOfficial(bool isConfirm)
10966 if (this.ExistCurrentPost)
10968 if (_curPost.IsProtect)
10970 MessageBox.Show("Protected.");
10971 _DoFavRetweetFlags = false;
10974 if (_curList.SelectedIndices.Count > 15)
10976 MessageBox.Show(Properties.Resources.RetweetLimitText);
10977 _DoFavRetweetFlags = false;
10980 else if (_curList.SelectedIndices.Count > 1)
10982 string QuestionText = Properties.Resources.RetweetQuestion2;
10983 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10984 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10986 case DialogResult.Cancel:
10987 case DialogResult.No:
10988 _DoFavRetweetFlags = false;
10994 if (_curPost.IsDm || _curPost.IsMe)
10996 _DoFavRetweetFlags = false;
10999 if (!SettingDialog.RetweetNoConfirm)
11001 string Questiontext = Properties.Resources.RetweetQuestion1;
11002 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
11003 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
11005 _DoFavRetweetFlags = false;
11010 GetWorkerArg args = new GetWorkerArg();
11011 args.ids = new List<long>();
11012 args.sIds = new List<long>();
11013 args.tName = _curTab.Text;
11014 args.type = MyCommon.WORKERTYPE.Retweet;
11015 foreach (int idx in _curList.SelectedIndices)
11017 PostClass post = GetCurTabPost(idx);
11018 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
11024 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
11026 doReTweetOfficial(true);
11029 private void FavoritesRetweetOriginal()
11031 if (!this.ExistCurrentPost) return;
11032 _DoFavRetweetFlags = true;
11033 doReTweetOfficial(true);
11034 if (_DoFavRetweetFlags)
11036 _DoFavRetweetFlags = false;
11037 FavoriteChange(true, false);
11041 private void FavoritesRetweetUnofficial()
11043 if (this.ExistCurrentPost && !_curPost.IsDm)
11045 _DoFavRetweetFlags = true;
11046 FavoriteChange(true);
11047 if (!_curPost.IsProtect && _DoFavRetweetFlags)
11049 _DoFavRetweetFlags = false;
11050 doReTweetUnofficial();
11056 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
11058 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
11059 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
11060 /// <returns>復元されたツイート本文</returns>
11061 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
11063 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
11066 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
11068 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11070 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11074 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
11076 statusHtml = statusHtml.Replace("<br>", " ");
11078 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
11079 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
11080 statusHtml = statusHtml.Replace(" ", " ");
11082 return WebUtility.HtmlDecode(statusHtml);
11085 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
11087 if (_curPost != null)
11088 DispSelectedPost(true);
11091 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
11093 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
11094 DebugModeToolStripMenuItem.Visible = true;
11096 DebugModeToolStripMenuItem.Visible = false;
11099 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
11101 SettingDialog.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
11104 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
11106 ToolStripMenuItemUrlAutoShorten.Checked = SettingDialog.UrlConvertAuto;
11109 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
11111 if (TraceOutToolStripMenuItem.Checked)
11112 MyCommon.TraceFlag = true;
11114 MyCommon.TraceFlag = false;
11117 private void TweenMain_Deactivate(object sender, EventArgs e)
11119 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
11120 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
11123 private void TabRenameMenuItem_Click(object sender, EventArgs e)
11125 if (string.IsNullOrEmpty(_rclickTabName)) return;
11126 TabRename(ref _rclickTabName);
11129 private void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
11131 UrlConvert(MyCommon.UrlConverter.Bitly);
11134 private void JmpToolStripMenuItem_Click(object sender, EventArgs e)
11136 UrlConvert(MyCommon.UrlConverter.Jmp);
11140 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
11142 e.Result = tw.GetInfoApi();
11145 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
11147 StringBuilder tmp = new StringBuilder();
11149 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
11153 var result = (TwitterApiStatus)dlg.Result;
11155 if (result == null)
11157 var accessLevel = result.AccessLevel;
11158 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
11159 var mediaLimit = result.MediaUploadLimit;
11161 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
11162 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
11163 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
11164 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
11167 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
11168 SetStatusLabelUrl();
11171 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
11172 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
11173 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
11177 tmp.Append(Properties.Resources.ApiInfo5);
11181 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11184 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11187 if (_curPost != null) id = _curPost.ScreenName;
11191 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11193 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11194 e.Result = arg.tw.PostFollowCommand(arg.id);
11197 private void FollowCommand(string id)
11199 using (InputTabName inputName = new InputTabName())
11201 inputName.FormTitle = "Follow";
11202 inputName.FormDescription = Properties.Resources.FRMessage1;
11203 inputName.TabName = id;
11204 if (inputName.ShowDialog() == DialogResult.OK &&
11205 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11207 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11209 arg.id = inputName.TabName.Trim();
11210 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11211 FollowCommand_DoWork,
11215 _info.ShowDialog();
11216 string ret = (string)_info.Result;
11217 if (!string.IsNullOrEmpty(ret))
11218 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11220 MessageBox.Show(Properties.Resources.FRMessage3);
11226 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11229 if (_curPost != null) id = _curPost.ScreenName;
11230 RemoveCommand(id, false);
11233 private class FollowRemoveCommandArgs
11239 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11241 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11242 e.Result = arg.tw.PostRemoveCommand(arg.id);
11245 private void RemoveCommand(string id, bool skipInput)
11247 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11252 using (InputTabName inputName = new InputTabName())
11254 inputName.FormTitle = "Unfollow";
11255 inputName.FormDescription = Properties.Resources.FRMessage1;
11256 inputName.TabName = id;
11257 if (inputName.ShowDialog() == DialogResult.OK &&
11258 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11261 arg.id = inputName.TabName.Trim();
11270 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11271 RemoveCommand_DoWork,
11275 _info.ShowDialog();
11276 string ret = (string)_info.Result;
11277 if (!string.IsNullOrEmpty(ret))
11278 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11280 MessageBox.Show(Properties.Resources.FRMessage3);
11284 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11287 if (_curPost != null)
11288 id = _curPost.ScreenName;
11290 ShowFriendship(id);
11293 private class ShowFriendshipArgs
11296 public class FriendshipInfo
11298 public string id = "";
11299 public bool isFollowing = false;
11300 public bool isFollowed = false;
11301 public bool isError = false;
11302 public FriendshipInfo(string id)
11307 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11310 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11312 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11313 string result = "";
11314 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11316 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11317 if (!string.IsNullOrEmpty(rt))
11319 if (string.IsNullOrEmpty(result)) result = rt;
11320 fInfo.isError = true;
11326 private void ShowFriendship(string id)
11328 ShowFriendshipArgs args = new ShowFriendshipArgs();
11330 using (InputTabName inputName = new InputTabName())
11332 inputName.FormTitle = "Show Friendships";
11333 inputName.FormDescription = Properties.Resources.FRMessage1;
11334 inputName.TabName = id;
11335 if (inputName.ShowDialog() == DialogResult.OK &&
11336 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11339 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11340 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11341 ShowFriendship_DoWork,
11345 _info.ShowDialog();
11346 ret = (string)_info.Result;
11348 string result = "";
11349 if (string.IsNullOrEmpty(ret))
11351 if (args.ids[0].isFollowing)
11353 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11357 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11359 if (args.ids[0].isFollowed)
11361 result += Properties.Resources.GetFriendshipInfo3;
11365 result += Properties.Resources.GetFriendshipInfo4;
11367 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11373 MessageBox.Show(result);
11378 private void ShowFriendship(string[] ids)
11380 foreach (string id in ids)
11383 ShowFriendshipArgs args = new ShowFriendshipArgs();
11385 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11386 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11387 ShowFriendship_DoWork,
11391 _info.ShowDialog();
11392 ret = (string)_info.Result;
11394 string result = "";
11395 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11397 if (string.IsNullOrEmpty(ret))
11400 if (fInfo.isFollowing)
11402 ff += Properties.Resources.GetFriendshipInfo1;
11406 ff += Properties.Resources.GetFriendshipInfo2;
11409 ff += System.Environment.NewLine + " ";
11410 if (fInfo.isFollowed)
11412 ff += Properties.Resources.GetFriendshipInfo3;
11416 ff += Properties.Resources.GetFriendshipInfo4;
11418 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11419 if (fInfo.isFollowing)
11421 if (MessageBox.Show(
11422 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11423 MessageBoxButtons.YesNo,
11424 MessageBoxIcon.Question,
11425 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11427 RemoveCommand(fInfo.id, true);
11432 MessageBox.Show(result);
11437 MessageBox.Show(ret);
11442 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11444 doShowUserStatus(tw.Username, false);
11445 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11447 // doShowUserStatus(tw.Username, false);
11451 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11456 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11457 // URLから切り出した文字列を渡す
11459 public bool IsTwitterId(string name)
11461 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11462 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11464 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11467 private string GetUserId()
11469 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11470 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11471 return m.Result("${ScreenName}");
11476 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11478 string name = GetUserId();
11479 if (name != null) FollowCommand(name);
11482 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11484 string name = GetUserId();
11485 if (name != null) RemoveCommand(name, false);
11488 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11490 string name = GetUserId();
11491 if (name != null) ShowFriendship(name);
11494 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11496 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11497 List<string> ids = new List<string>();
11498 foreach (Match mu in ma)
11500 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11502 ids.Add(mu.Result("${ScreenName}"));
11505 ShowFriendship(ids.ToArray());
11508 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11510 string name = GetUserId();
11511 if (name != null) ShowUserStatus(name);
11514 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11516 string name = GetUserId();
11517 if (name != null) AddNewTabForUserTimeline(name);
11520 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11522 string name = GetUserId();
11523 if (name != null) AddNewTabForSearch("@" + name);
11526 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11528 _modifySettingCommon = true;
11531 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11533 _modifySettingCommon = true;
11536 private void doQuote()
11540 if (this.ExistCurrentPost)
11542 if (_curPost.IsDm ||
11543 !StatusText.Enabled) return;
11545 if (_curPost.IsProtect)
11547 MessageBox.Show("Protected.");
11550 string rtdata = _curPost.Text;
11551 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11553 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11554 if (_curPost.RetweetedId == null)
11556 _reply_to_id = _curPost.StatusId;
11560 _reply_to_id = _curPost.RetweetedId.Value;
11562 _reply_to_name = _curPost.ScreenName;
11564 StatusText.SelectionStart = 0;
11565 StatusText.Focus();
11569 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11574 private void SearchButton_Click(object sender, EventArgs e)
11577 Control pnl = ((Control)sender).Parent;
11578 if (pnl == null) return;
11579 string tbName = pnl.Parent.Text;
11580 TabClass tb = _statuses.Tabs[tbName];
11581 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11582 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11583 ComboBox cmbusline = (ComboBox)pnl.Controls["comboUserline"];
11584 cmb.Text = cmb.Text.Trim();
11585 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11586 bool Quote = false;
11587 StringBuilder buf = new StringBuilder();
11588 char[] c = cmb.Text.ToCharArray();
11589 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11591 if (cnt > cmb.Text.Length - 4)
11593 buf.Append(cmb.Text.Substring(cnt));
11602 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11604 buf.Append(" OR ");
11609 buf.Append(c[cnt]);
11611 cmb.Text = buf.ToString();
11613 tb.SearchWords = cmb.Text;
11614 tb.SearchLang = cmbLang.Text;
11615 if (string.IsNullOrEmpty(cmb.Text))
11617 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11621 if (tb.IsQueryChanged())
11623 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11624 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11625 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11626 cmb.Text = tb.SearchWords;
11628 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11629 lst.VirtualListSize = 0;
11631 _statuses.ClearTabIds(tbName);
11632 SaveConfigsTabs(); //検索条件の保存
11635 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, tbName);
11636 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11639 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11645 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11647 if (_statuses.RemovedTab.Count == 0)
11649 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11654 TabClass tb = _statuses.RemovedTab.Pop();
11655 if (tb.TabType == MyCommon.TabUsageType.Related)
11657 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11658 if (relatedTab != null)
11660 // 関連発言なら既存のタブを置き換える
11661 tb.TabName = relatedTab.TabName;
11662 this.ClearTab(tb.TabName, false);
11663 _statuses.Tabs[tb.TabName] = tb;
11664 for (int i = 0; i < ListTab.TabPages.Count; i++)
11666 if (tb.TabName == ListTab.TabPages[i].Text)
11668 ListTab.SelectedIndex = i;
11669 ListTabSelect(ListTab.TabPages[i]);
11676 const string TabName = "Related Tweets";
11677 string renamed = TabName;
11678 for (int i = 2; i <= 100; i++)
11680 if (!_statuses.ContainsTab(renamed)) break;
11681 renamed = TabName + i.ToString();
11683 tb.TabName = renamed;
11684 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11685 _statuses.Tabs.Add(renamed, tb); // 後に
11686 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11687 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11692 string renamed = tb.TabName;
11693 for (int i = 1; i < int.MaxValue; i++)
11695 if (!_statuses.ContainsTab(renamed)) break;
11696 renamed = tb.TabName + "(" + i.ToString() + ")";
11698 tb.TabName = renamed;
11699 _statuses.Tabs.Add(renamed, tb); // 先に
11700 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11701 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11702 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11708 private void doMoveToRTHome()
11710 if (_curList.SelectedIndices.Count > 0)
11712 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11713 if (post.RetweetedId != null)
11715 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11720 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11725 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11727 string name = GetUserId();
11733 if (_curList.SelectedIndices.Count == 0) return;
11736 if (!SelectTab(out tabName)) return;
11740 MoveOrCopy(ref mv, ref mk);
11742 PostFilterRule fc = new PostFilterRule();
11743 fc.FilterName = name;
11744 fc.UseNameField = true;
11745 fc.MoveMatches = mv;
11746 fc.MarkMatches = mk;
11747 fc.UseRegex = false;
11748 fc.FilterByUrl = false;
11749 _statuses.Tabs[tabName].AddFilter(fc);
11753 this.Cursor = Cursors.WaitCursor;
11754 this.PurgeListViewItemCache();
11756 _curItemIndex = -1;
11757 _statuses.FilterAll();
11758 foreach (TabPage tb in ListTab.TabPages)
11760 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
11761 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
11763 if (SettingDialog.TabIconDisp)
11768 if (SettingDialog.TabIconDisp)
11769 tb.ImageIndex = -1;
11772 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
11776 this.Cursor = Cursors.Default;
11782 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11786 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11788 if (menuItem.Owner == this.ContextMenuPostBrowser)
11790 user = GetUserId();
11791 if (user == null) return;
11793 else if (this._curPost != null)
11795 user = this._curPost.ScreenName;
11802 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11804 string res = this.tw.GetListsApi();
11806 if (!string.IsNullOrEmpty(res))
11808 MessageBox.Show("Failed to get lists. (" + res + ")");
11813 using (MyLists listSelectForm = new MyLists(user, this.tw))
11815 listSelectForm.ShowDialog(this);
11819 private void SearchControls_Enter(object sender, EventArgs e)
11821 Control pnl = (Control)sender;
11822 foreach (Control ctl in pnl.Controls)
11824 ctl.TabStop = true;
11828 private void SearchControls_Leave(object sender, EventArgs e)
11830 Control pnl = (Control)sender;
11831 foreach (Control ctl in pnl.Controls)
11833 ctl.TabStop = false;
11837 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11839 if (ListTab.SelectedTab != null)
11841 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11842 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11846 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11848 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11851 HashMgr.SetPermanentHash("#" + m.Result("${hash}"));
11852 HashStripSplitButton.Text = HashMgr.UseHash;
11853 HashToggleMenuItem.Checked = true;
11854 HashToggleToolStripMenuItem.Checked = true;
11856 _modifySettingCommon = true;
11860 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11862 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11865 private void HashManageMenuItem_Click(object sender, EventArgs e)
11867 DialogResult rslt = DialogResult.Cancel;
11870 rslt = HashMgr.ShowDialog();
11876 this.TopMost = SettingDialog.AlwaysTop;
11877 if (rslt == DialogResult.Cancel) return;
11878 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11880 HashStripSplitButton.Text = HashMgr.UseHash;
11881 HashToggleMenuItem.Checked = true;
11882 HashToggleToolStripMenuItem.Checked = true;
11886 HashStripSplitButton.Text = "#[-]";
11887 HashToggleMenuItem.Checked = false;
11888 HashToggleToolStripMenuItem.Checked = false;
11890 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11892 // int sidx = StatusText.SelectionStart;
11893 // string hash = HashMgr.UseHash + " ";
11896 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11897 // hash = " " + hash;
11899 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11900 // sidx += hash.Length;
11901 // StatusText.SelectionStart = sidx;
11902 // StatusText.Focus();
11904 _modifySettingCommon = true;
11905 this.StatusText_TextChanged(null, null);
11908 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11910 HashMgr.ToggleHash();
11911 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11913 HashStripSplitButton.Text = HashMgr.UseHash;
11914 HashToggleMenuItem.Checked = true;
11915 HashToggleToolStripMenuItem.Checked = true;
11919 HashStripSplitButton.Text = "#[-]";
11920 HashToggleMenuItem.Checked = false;
11921 HashToggleToolStripMenuItem.Checked = false;
11923 _modifySettingCommon = true;
11924 this.StatusText_TextChanged(null, null);
11927 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11929 HashToggleMenuItem_Click(null, null);
11932 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11934 if (ListTab.SelectedTab == null) return;
11935 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11936 if (!this.ExistCurrentPost)
11938 this.ReplyOpMenuItem.Enabled = false;
11939 this.ReplyAllOpMenuItem.Enabled = false;
11940 this.DmOpMenuItem.Enabled = false;
11941 this.ShowProfMenuItem.Enabled = false;
11942 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11943 this.ListManageMenuItem.Enabled = false;
11944 this.OpenFavOpMenuItem.Enabled = false;
11945 this.CreateTabRuleOpMenuItem.Enabled = false;
11946 this.CreateIdRuleOpMenuItem.Enabled = false;
11947 this.ReadOpMenuItem.Enabled = false;
11948 this.UnreadOpMenuItem.Enabled = false;
11952 this.ReplyOpMenuItem.Enabled = true;
11953 this.ReplyAllOpMenuItem.Enabled = true;
11954 this.DmOpMenuItem.Enabled = true;
11955 this.ShowProfMenuItem.Enabled = true;
11956 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11957 this.ListManageMenuItem.Enabled = true;
11958 this.OpenFavOpMenuItem.Enabled = true;
11959 this.CreateTabRuleOpMenuItem.Enabled = true;
11960 this.CreateIdRuleOpMenuItem.Enabled = true;
11961 this.ReadOpMenuItem.Enabled = true;
11962 this.UnreadOpMenuItem.Enabled = true;
11965 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11967 this.FavOpMenuItem.Enabled = false;
11968 this.UnFavOpMenuItem.Enabled = false;
11969 this.OpenStatusOpMenuItem.Enabled = false;
11970 this.OpenFavotterOpMenuItem.Enabled = false;
11971 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11972 this.RtOpMenuItem.Enabled = false;
11973 this.RtUnOpMenuItem.Enabled = false;
11974 this.QtOpMenuItem.Enabled = false;
11975 this.FavoriteRetweetMenuItem.Enabled = false;
11976 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11977 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11981 this.FavOpMenuItem.Enabled = true;
11982 this.UnFavOpMenuItem.Enabled = true;
11983 this.OpenStatusOpMenuItem.Enabled = true;
11984 this.OpenFavotterOpMenuItem.Enabled = true;
11985 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11989 this.RtOpMenuItem.Enabled = false;
11990 this.FavoriteRetweetMenuItem.Enabled = false;
11991 this.DelOpMenuItem.Enabled = true;
11995 this.DelOpMenuItem.Enabled = false;
11996 if (_curPost.IsProtect)
11998 this.RtOpMenuItem.Enabled = false;
11999 this.RtUnOpMenuItem.Enabled = false;
12000 this.QtOpMenuItem.Enabled = false;
12001 this.FavoriteRetweetMenuItem.Enabled = false;
12002 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
12006 this.RtOpMenuItem.Enabled = true;
12007 this.RtUnOpMenuItem.Enabled = true;
12008 this.QtOpMenuItem.Enabled = true;
12009 this.FavoriteRetweetMenuItem.Enabled = true;
12010 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
12015 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
12017 this.RefreshPrevOpMenuItem.Enabled = true;
12021 this.RefreshPrevOpMenuItem.Enabled = false;
12023 if (!this.ExistCurrentPost
12024 || _curPost.InReplyToStatusId == null)
12026 OpenRepSourceOpMenuItem.Enabled = false;
12030 OpenRepSourceOpMenuItem.Enabled = true;
12032 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
12034 OpenRterHomeMenuItem.Enabled = false;
12038 OpenRterHomeMenuItem.Enabled = true;
12042 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
12044 ContextMenuTabProperty_Opening(sender, null);
12047 public Twitter TwitterInstance
12052 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
12054 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
12056 _mySpDis3 = SplitContainer3.SplitterDistance;
12057 _modifySettingLocal = true;
12061 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
12063 if (_statuses.RemovedTab.Count == 0)
12065 UndoRemoveTabMenuItem.Enabled = false;
12069 UndoRemoveTabMenuItem.Enabled = true;
12071 if (ListTab.SelectedTab != null)
12073 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
12074 PublicSearchQueryMenuItem.Enabled = true;
12076 PublicSearchQueryMenuItem.Enabled = false;
12080 PublicSearchQueryMenuItem.Enabled = false;
12082 if (!this.ExistCurrentPost)
12084 this.CopySTOTMenuItem.Enabled = false;
12085 this.CopyURLMenuItem.Enabled = false;
12086 this.CopyUserIdStripMenuItem.Enabled = false;
12090 this.CopySTOTMenuItem.Enabled = true;
12091 this.CopyURLMenuItem.Enabled = true;
12092 this.CopyUserIdStripMenuItem.Enabled = true;
12093 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
12094 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
12098 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
12100 SetNotifyIconText();
12103 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12106 if (_curPost != null)
12108 id = _curPost.ScreenName;
12110 ShowUserStatus(id);
12113 private class GetUserInfoArgs
12117 public TwitterDataModel.User user;
12120 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
12122 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
12123 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
12126 private void doShowUserStatus(string id, bool ShowInputDialog)
12128 TwitterDataModel.User user = null;
12129 GetUserInfoArgs args = new GetUserInfoArgs();
12130 if (ShowInputDialog)
12132 using (InputTabName inputName = new InputTabName())
12134 inputName.FormTitle = "Show UserStatus";
12135 inputName.FormDescription = Properties.Resources.FRMessage1;
12136 inputName.TabName = id;
12137 if (inputName.ShowDialog() == DialogResult.OK &&
12138 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12140 id = inputName.TabName.Trim();
12144 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12145 GetUserInfo_DoWork,
12149 _info.ShowDialog();
12150 string ret = (string)_info.Result;
12151 if (string.IsNullOrEmpty(ret))
12152 doShowUserStatus(args.user);
12154 MessageBox.Show(ret);
12164 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12165 GetUserInfo_DoWork,
12169 _info.ShowDialog();
12170 string ret = (string)_info.Result;
12171 if (string.IsNullOrEmpty(ret))
12173 doShowUserStatus(args.user);
12177 MessageBox.Show(ret);
12183 private void doShowUserStatus(TwitterDataModel.User user)
12185 using (ShowUserInfo userinfo = new ShowUserInfo())
12187 userinfo.Owner = this;
12188 userinfo.User = user;
12189 userinfo.ShowDialog(this);
12191 this.BringToFront();
12195 private void ShowUserStatus(string id, bool ShowInputDialog)
12197 doShowUserStatus(id, ShowInputDialog);
12200 private void ShowUserStatus(string id)
12202 doShowUserStatus(id, true);
12205 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12207 if (NameLabel.Tag != null)
12209 string id = (string)NameLabel.Tag;
12210 if (id != tw.Username)
12217 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12219 if (NameLabel.Tag != null)
12221 string id = (string)NameLabel.Tag;
12222 if (id != tw.Username)
12224 RemoveCommand(id, false);
12229 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12231 if (NameLabel.Tag != null)
12233 string id = (string)NameLabel.Tag;
12234 if (id != tw.Username)
12236 ShowFriendship(id);
12241 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12243 if (NameLabel.Tag != null)
12245 string id = (string)NameLabel.Tag;
12246 ShowUserStatus(id, false);
12250 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12252 if (NameLabel.Tag != null)
12254 string id = (string)NameLabel.Tag;
12255 AddNewTabForUserTimeline(id);
12259 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12261 if (NameLabel.Tag != null)
12263 string id = (string)NameLabel.Tag;
12264 AddNewTabForSearch("@" + id);
12268 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12270 if (_curPost != null)
12272 ShowUserStatus(_curPost.ScreenName, false);
12276 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12281 if (_curPost.RetweetedId != null)
12283 statusid = _curPost.RetweetedId.Value;
12287 statusid = _curPost.StatusId;
12289 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12291 e.Result = counter;
12294 private void RtCountMenuItem_Click(object sender, EventArgs e)
12296 if (this.ExistCurrentPost)
12298 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12299 GetRetweet_DoWork))
12301 int retweet_count = 0;
12304 _info.ShowDialog();
12305 retweet_count = (int)_info.Result;
12306 if (retweet_count < 0)
12308 MessageBox.Show(Properties.Resources.RtCountText2);
12312 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12318 private HookGlobalHotkey _hookGlobalHotkey;
12321 _hookGlobalHotkey = new HookGlobalHotkey(this);
12322 // この呼び出しは、Windows フォーム デザイナで必要です。
12323 InitializeComponent();
12325 // InitializeComponent() 呼び出しの後で初期化を追加します。
12327 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12328 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12329 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12330 this.gh.NotifyClicked += GrowlHelper_Callback;
12332 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12333 this.ListTab.HandleCreated += (s, e) => Win32Api.SetMinTabWidth((TabControl)s, 40);
12335 this._apiGauge = new ToolStripAPIGauge();
12336 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12337 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12339 this.ReplaceAppName();
12342 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12344 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12347 this.Visible = false;
12349 else if (Form.ActiveForm == null)
12351 this.Visible = true;
12352 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12354 this.BringToFront();
12355 this.StatusText.Focus();
12359 private void UserPicture_MouseEnter(object sender, EventArgs e)
12361 this.UserPicture.Cursor = Cursors.Hand;
12364 private void UserPicture_MouseLeave(object sender, EventArgs e)
12366 this.UserPicture.Cursor = Cursors.Default;
12369 private void UserPicture_DoubleClick(object sender, EventArgs e)
12371 if (NameLabel.Tag != null)
12373 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12377 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12379 this.MultiLineMenuItem.PerformClick();
12382 public PostClass CurPost
12384 get { return _curPost; }
12387 public bool IsPreviewEnable
12389 get { return SettingDialog.PreviewEnable; }
12393 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12395 if (ImageSelectionPanel.Visible == true)
12397 ImagefilePathText.CausesValidation = false;
12398 TimelinePanel.Visible = true;
12399 TimelinePanel.Enabled = true;
12400 ImageSelectionPanel.Visible = false;
12401 ImageSelectionPanel.Enabled = false;
12402 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12403 ImagefilePathText.CausesValidation = true;
12407 ImageSelectionPanel.Visible = true;
12408 ImageSelectionPanel.Enabled = true;
12409 TimelinePanel.Visible = false;
12410 TimelinePanel.Enabled = false;
12411 ImagefilePathText.Focus();
12415 private void FilePickButton_Click(object sender, EventArgs e)
12417 if (string.IsNullOrEmpty(this.ImageService)) return;
12418 OpenFileDialog1.Filter = this.pictureService[this.ImageService].GetFileOpenDialogFilter();
12419 OpenFileDialog1.Title = Properties.Resources.PickPictureDialog1;
12420 OpenFileDialog1.FileName = "";
12424 this.AllowDrop = false;
12425 if (OpenFileDialog1.ShowDialog() == DialogResult.Cancel) return;
12429 this.AllowDrop = true;
12432 ImagefilePathText.Text = OpenFileDialog1.FileName;
12433 ImageFromSelectedFile();
12436 private void ImagefilePathText_Validating(object sender, CancelEventArgs e)
12438 if (ImageCancelButton.Focused)
12440 ImagefilePathText.CausesValidation = false;
12443 ImagefilePathText.Text = ImagefilePathText.Text.Trim();
12444 if (string.IsNullOrEmpty(ImagefilePathText.Text))
12446 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12447 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12451 ImageFromSelectedFile();
12455 private void ImageFromSelectedFile()
12459 if (string.IsNullOrEmpty(ImagefilePathText.Text.Trim()) || string.IsNullOrEmpty(this.ImageService))
12461 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12462 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12463 ImagefilePathText.Text = "";
12467 FileInfo fl = new FileInfo(ImagefilePathText.Text.Trim());
12468 if (!this.pictureService[this.ImageService].CheckValidExtension(fl.Extension))
12471 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12472 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12473 ImagefilePathText.Text = "";
12477 if (!this.pictureService[this.ImageService].CheckValidFilesize(fl.Extension, fl.Length))
12480 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12481 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12482 ImagefilePathText.Text = "";
12483 MessageBox.Show("File is too large.");
12487 switch (this.pictureService[this.ImageService].GetFileType(fl.Extension))
12489 case MyCommon.UploadFileType.Invalid:
12490 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12491 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12492 ImagefilePathText.Text = "";
12494 case MyCommon.UploadFileType.Picture:
12496 using (FileStream fs = new FileStream(ImagefilePathText.Text, FileMode.Open, FileAccess.Read))
12498 img = Image.FromStream(fs);
12500 ImageSelectedPicture.Image = (new HttpVarious()).CheckValidImage(
12504 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Picture;
12506 case MyCommon.UploadFileType.MultiMedia:
12507 ImageSelectedPicture.Image = Properties.Resources.MultiMediaImage;
12508 ImageSelectedPicture.Tag = MyCommon.UploadFileType.MultiMedia;
12511 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12512 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12513 ImagefilePathText.Text = "";
12517 catch (FileNotFoundException)
12519 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12520 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12521 ImagefilePathText.Text = "";
12522 MessageBox.Show("File not found.");
12526 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12527 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12528 ImagefilePathText.Text = "";
12529 MessageBox.Show("The type of this file is not image.");
12533 private void ImageSelection_KeyDown(object sender, KeyEventArgs e)
12535 if (e.KeyCode == Keys.Escape)
12537 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12538 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12539 TimelinePanel.Visible = true;
12540 TimelinePanel.Enabled = true;
12541 ImageSelectionPanel.Visible = false;
12542 ImageSelectionPanel.Enabled = false;
12543 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12544 ImagefilePathText.CausesValidation = true;
12548 private void ImageSelection_KeyPress(object sender, KeyPressEventArgs e)
12550 if (Convert.ToInt32(e.KeyChar) == 0x1B)
12552 ImagefilePathText.CausesValidation = false;
12557 private void ImageSelection_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
12559 if (e.KeyCode == Keys.Escape)
12561 ImagefilePathText.CausesValidation = false;
12565 private void SetImageServiceCombo()
12568 if (ImageServiceCombo.SelectedIndex > -1) svc = ImageServiceCombo.SelectedItem.ToString();
12569 ImageServiceCombo.Items.Clear();
12571 // Add service names to combobox
12572 foreach (var key in pictureService.Keys)
12574 ImageServiceCombo.Items.Add(key);
12577 SelectImageServiceComboItem(svc);
12580 private void SelectImageServiceComboItem(string svc, int? index = null)
12583 if (string.IsNullOrEmpty(svc))
12589 idx = ImageServiceCombo.Items.IndexOf(svc);
12590 if (idx == -1) idx = index ?? 0;
12595 ImageServiceCombo.SelectedIndex = idx;
12597 catch (ArgumentOutOfRangeException)
12599 ImageServiceCombo.SelectedIndex = 0;
12603 private string ImageService
12605 get { return ImageServiceCombo.SelectedItem.ToString(); }
12608 private void ImageCancelButton_Click(object sender, EventArgs e)
12610 ImagefilePathText.CausesValidation = false;
12611 TimelinePanel.Visible = true;
12612 TimelinePanel.Enabled = true;
12613 ImageSelectionPanel.Visible = false;
12614 ImageSelectionPanel.Enabled = false;
12615 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12616 ImagefilePathText.CausesValidation = true;
12619 private void ImageServiceCombo_SelectedIndexChanged(object sender, EventArgs e)
12621 if (ImageSelectedPicture.Tag != null && !string.IsNullOrEmpty(this.ImageService))
12625 FileInfo fi = new FileInfo(ImagefilePathText.Text.Trim());
12626 if (!this.pictureService[this.ImageService].CheckValidFilesize(fi.Extension, fi.Length))
12628 ImagefilePathText.Text = "";
12629 ImageSelectedPicture.Image = ImageSelectedPicture.InitialImage;
12630 ImageSelectedPicture.Tag = MyCommon.UploadFileType.Invalid;
12636 _modifySettingCommon = true;
12637 SaveConfigsAll(false);
12638 if (this.ImageService == "Twitter")
12640 this.StatusText_TextChanged(null, null);
12646 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12648 using (ListManage form = new ListManage(tw))
12650 form.ShowDialog(this);
12654 public bool ModifySettingCommon
12656 set { _modifySettingCommon = value; }
12659 public bool ModifySettingLocal
12661 set { _modifySettingLocal = value; }
12664 public bool ModifySettingAtId
12666 set { _modifySettingAtId = value; }
12669 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12671 string link = (string)SourceLinkLabel.Tag;
12672 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12674 OpenUriAsync(link);
12678 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12680 string link = (string)SourceLinkLabel.Tag;
12681 if (!string.IsNullOrEmpty(link))
12683 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12687 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12689 SetStatusLabelUrl();
12692 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12694 if (this.ExistCurrentPost && !_curPost.IsDm)
12695 RtCountMenuItem.Enabled = true;
12697 RtCountMenuItem.Enabled = false;
12699 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12700 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12702 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12705 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12710 private void CopyUserId()
12712 if (_curPost == null) return;
12713 string clstr = _curPost.ScreenName;
12716 Clipboard.SetDataObject(clstr, false, 5, 100);
12718 catch (Exception ex)
12720 MessageBox.Show(ex.Message);
12724 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12726 if (this.ExistCurrentPost && !_curPost.IsDm)
12730 this.OpenRelatedTab(this._curPost);
12732 catch (TabException ex)
12734 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12740 /// 指定されたツイートに対する関連発言タブを開きます
12742 /// <param name="post">表示する対象となるツイート</param>
12743 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12744 private void OpenRelatedTab(PostClass post)
12746 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12749 if (tabRelated == null)
12751 tabName = this._statuses.MakeTabName("Related Tweets");
12753 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12754 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12756 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12757 tabRelated.UnreadManage = false;
12758 tabRelated.Notify = false;
12762 tabName = tabRelated.TabName;
12765 tabRelated.RelationTargetPost = post;
12766 this.ClearTab(tabName, false);
12768 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12770 var tabPage = this.ListTab.TabPages[i];
12771 if (tabName == tabPage.Text)
12773 this.ListTab.SelectedIndex = i;
12774 this.ListTabSelect(tabPage);
12779 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, 1, tabName);
12782 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12784 StringBuilder buf = new StringBuilder();
12785 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12786 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12787 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12788 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12789 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12792 private void tw_UserIdChanged()
12794 this._modifySettingCommon = true;
12797 #region "Userstream"
12798 private bool _isActiveUserstream = false;
12800 private void tw_PostDeleted(long id)
12804 if (InvokeRequired && !IsDisposed)
12806 Invoke((Action) (() =>
12808 _statuses.RemovePostReserve(id);
12809 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(id))
12811 this.PurgeListViewItemCache();
12812 ((DetailsListView)_curTab.Tag).Update();
12813 if (_curPost != null && _curPost.StatusId == id) DispSelectedPost(true);
12819 catch (ObjectDisposedException)
12823 catch (InvalidOperationException)
12829 private void tw_NewPostFromStream()
12831 if (SettingDialog.ReadOldPosts)
12833 _statuses.SetRead(); //新着時未読クリア
12836 int rsltAddCount = _statuses.DistributePosts();
12839 DateTime tm = DateTime.Now;
12840 if (_tlTimestamps.ContainsKey(tm))
12842 _tlTimestamps[tm] += rsltAddCount;
12846 _tlTimestamps.Add(tm, rsltAddCount);
12848 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12849 List<DateTime> keys = new List<DateTime>();
12851 foreach (DateTime key in _tlTimestamps.Keys)
12853 if (key.CompareTo(oneHour) < 0)
12856 _tlCount += _tlTimestamps[key];
12858 foreach (DateTime key in keys)
12860 _tlTimestamps.Remove(key);
12864 //Static DateTime before = Now;
12865 //if (before.Subtract(Now).Seconds > -5) return;
12869 if (SettingDialog.UserstreamPeriodInt > 0) return;
12873 if (InvokeRequired && !IsDisposed)
12875 Invoke(new Action<bool>(RefreshTimeline), true);
12879 catch (ObjectDisposedException)
12883 catch (InvalidOperationException)
12889 private void tw_UserStreamStarted()
12891 this._isActiveUserstream = true;
12894 if (InvokeRequired && !IsDisposed)
12896 Invoke(new MethodInvoker(tw_UserStreamStarted));
12900 catch (ObjectDisposedException)
12904 catch (InvalidOperationException)
12909 MenuItemUserStream.Text = "&UserStream ▶";
12910 MenuItemUserStream.Enabled = true;
12911 StopToolStripMenuItem.Text = "&Stop";
12912 StopToolStripMenuItem.Enabled = true;
12914 StatusLabel.Text = "UserStream Started.";
12917 private void tw_UserStreamStopped()
12919 this._isActiveUserstream = false;
12922 if (InvokeRequired && !IsDisposed)
12924 Invoke(new MethodInvoker(tw_UserStreamStopped));
12928 catch (ObjectDisposedException)
12932 catch (InvalidOperationException)
12937 MenuItemUserStream.Text = "&UserStream ■";
12938 MenuItemUserStream.Enabled = true;
12939 StopToolStripMenuItem.Text = "&Start";
12940 StopToolStripMenuItem.Enabled = true;
12942 StatusLabel.Text = "UserStream Stopped.";
12945 private void tw_UserStreamEventArrived(Twitter.FormattedEvent ev)
12949 if (InvokeRequired && !IsDisposed)
12951 Invoke(new Action<Twitter.FormattedEvent>(tw_UserStreamEventArrived), ev);
12955 catch (ObjectDisposedException)
12959 catch (InvalidOperationException)
12963 StatusLabel.Text = "Event: " + ev.Event;
12964 //if (ev.Event == "favorite")
12966 // NotifyFavorite(ev);
12969 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12971 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12973 this.PurgeListViewItemCache();
12974 ((DetailsListView)_curTab.Tag).Update();
12976 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12978 RemovePostFromFavTab(new long[] {ev.Id});
12983 private void NotifyEvent(Twitter.FormattedEvent ev)
12986 if (BalloonRequired(ev))
12988 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12989 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12990 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12991 StringBuilder title = new StringBuilder();
12992 if (SettingDialog.DispUsername)
12994 title.Append(tw.Username);
12995 title.Append(" - ");
13001 title.Append(Application.ProductName);
13002 title.Append(" [");
13003 title.Append(ev.Event.ToUpper());
13004 title.Append("] by ");
13005 if (!string.IsNullOrEmpty(ev.Username))
13007 title.Append(ev.Username.ToString());
13011 //title.Append("");
13014 if (!string.IsNullOrEmpty(ev.Target))
13016 //NotifyIcon1.BalloonTipText = ev.Target;
13021 //NotifyIcon1.BalloonTipText = " ";
13024 //NotifyIcon1.ShowBalloonTip(500);
13025 if (SettingDialog.IsNotifyUseGrowl)
13027 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
13028 ev.Id.ToString(), title.ToString(), text);
13032 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
13033 NotifyIcon1.BalloonTipTitle = title.ToString();
13034 NotifyIcon1.BalloonTipText = text;
13035 NotifyIcon1.ShowBalloonTip(500);
13040 string snd = SettingDialog.EventSoundFile;
13041 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(snd))
13043 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
13047 string dir = Application.StartupPath;
13048 if (Directory.Exists(Path.Combine(dir, "Sounds")))
13050 dir = Path.Combine(dir, "Sounds");
13052 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
13064 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
13066 MenuItemUserStream.Enabled = false;
13067 if (StopRefreshAllMenuItem.Checked)
13069 StopRefreshAllMenuItem.Checked = false;
13072 if (this._isActiveUserstream)
13074 tw.StopUserStream();
13078 tw.StartUserStream();
13082 private static string inputTrack = "";
13084 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
13086 if (TrackToolStripMenuItem.Checked)
13088 using (InputTabName inputForm = new InputTabName())
13090 inputForm.TabName = inputTrack;
13091 inputForm.FormTitle = "Input track word";
13092 inputForm.FormDescription = "Track word";
13093 if (inputForm.ShowDialog() != DialogResult.OK)
13095 TrackToolStripMenuItem.Checked = false;
13098 inputTrack = inputForm.TabName.Trim();
13100 if (!inputTrack.Equals(tw.TrackWord))
13102 tw.TrackWord = inputTrack;
13103 this._modifySettingCommon = true;
13104 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
13105 tw.ReconnectUserStream();
13111 tw.ReconnectUserStream();
13113 this._modifySettingCommon = true;
13116 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
13118 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
13119 this._modifySettingCommon = true;
13120 tw.ReconnectUserStream();
13123 private void EventViewerMenuItem_Click(object sender, EventArgs e)
13125 if (evtDialog == null || evtDialog.IsDisposed)
13128 evtDialog = new EventViewerDialog();
13129 evtDialog.Owner = this;
13131 Point pos = evtDialog.Location;
13132 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
13133 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
13134 evtDialog.Location = pos;
13136 evtDialog.EventSource = tw.StoredEvent;
13137 if (!evtDialog.Visible)
13139 evtDialog.Show(this);
13143 evtDialog.Activate();
13145 this.TopMost = this.SettingDialog.AlwaysTop;
13149 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
13151 MyCommon._endingFlag = true;
13155 Application.Restart();
13159 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
13163 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
13165 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
13168 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
13170 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
13173 private void doTranslation(string str)
13175 Bing _bing = new Bing();
13177 if (string.IsNullOrEmpty(str)) return;
13178 string srclng = "";
13179 string dstlng = SettingDialog.TranslateLanguage;
13181 if (srclng != dstlng && _bing.Translate("", dstlng, str, out buf))
13183 PostBrowser.DocumentText = createDetailHtml(buf);
13187 if (msg.StartsWith("Err:"))
13188 StatusLabel.Text = msg;
13192 private void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
13194 if (!this.ExistCurrentPost) return;
13195 doTranslation(_curPost.TextFromApi);
13198 private void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
13200 doTranslation(WebBrowser_GetSelectionText(ref PostBrowser));
13203 private bool ExistCurrentPost
13207 if (_curPost == null) return false;
13208 if (_curPost.IsDeleted) return false;
13213 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13215 ShowUserTimeline();
13218 public bool FavEventChangeUnread
13220 get { return SettingDialog.FavEventUnread; }
13223 private string GetUserIdFromCurPostOrInput(string caption)
13226 if (_curPost != null)
13228 id = _curPost.ScreenName;
13230 using (InputTabName inputName = new InputTabName())
13232 inputName.FormTitle = caption;
13233 inputName.FormDescription = Properties.Resources.FRMessage1;
13234 inputName.TabName = id;
13235 if (inputName.ShowDialog() == DialogResult.OK &&
13236 !string.IsNullOrEmpty(inputName.TabName.Trim()))
13238 id = inputName.TabName.Trim();
13248 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13250 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
13251 if (!string.IsNullOrEmpty(id))
13253 AddNewTabForUserTimeline(id);
13257 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
13259 string id = GetUserIdFromCurPostOrInput("Show Favstar");
13260 if (!string.IsNullOrEmpty(id))
13262 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
13266 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
13268 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
13271 private void TimelineRefreshEnableChange(bool isEnable)
13275 tw.StartUserStream();
13279 tw.StopUserStream();
13281 TimerTimeline.Enabled = isEnable;
13284 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
13286 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
13289 private void OpenUserAppointUrl()
13291 if (SettingDialog.UserAppointUrl != null)
13293 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
13295 if (_curPost != null)
13297 string xUrl = SettingDialog.UserAppointUrl;
13298 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
13299 if (_curPost.RetweetedId != null)
13301 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
13305 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
13307 OpenUriAsync(xUrl);
13312 OpenUriAsync(SettingDialog.UserAppointUrl);
13317 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
13319 OpenUserAppointUrl();
13322 private void ImageSelectionPanel_VisibleChanged(object sender, EventArgs e)
13324 this.StatusText_TextChanged(null, null);
13327 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
13329 string selText = SourceLinkLabel.Text;
13332 Clipboard.SetDataObject(selText, false, 5, 100);
13334 catch (Exception ex)
13336 MessageBox.Show(ex.Message);
13340 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
13342 string selText = (string)SourceLinkLabel.Tag;
13345 Clipboard.SetDataObject(selText, false, 5, 100);
13347 catch (Exception ex)
13349 MessageBox.Show(ex.Message);
13353 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
13355 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
13357 SourceCopyMenuItem.Enabled = false;
13358 SourceUrlCopyMenuItem.Enabled = false;
13362 SourceCopyMenuItem.Enabled = true;
13363 SourceUrlCopyMenuItem.Enabled = true;
13367 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
13369 if (Form.ActiveForm == null)
13371 this.BeginInvoke((Action) (() =>
13373 this.Visible = true;
13374 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
13376 this.BringToFront();
13377 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
13379 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
13383 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13389 private void ReplaceAppName()
13391 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13392 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13395 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13397 this.SplitContainer3.Panel2Collapsed = false;
13400 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13402 this.OpenThumbnailPicture(e.Thumbnail);
13405 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13407 this.OpenUriAsync(e.ImageUrl);
13410 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13412 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13415 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13417 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13420 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13422 if (e.KeyCode == Keys.Space)
13424 this.JumpUnreadMenuItem_Click(null, null);
13426 e.SuppressKeyPress = true;