1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
29 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
32 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Diagnostics;
40 using System.Net.Http;
41 using System.Reflection;
43 using System.Text.RegularExpressions;
44 using System.Threading;
45 using System.Threading.Tasks;
46 using System.Windows.Forms;
48 using OpenTween.Connection;
49 using OpenTween.OpenTweenCustomControl;
50 using OpenTween.Thumbnail;
54 public partial class TweenMain : OTBaseForm
57 private Size _mySize; //画面サイズ
58 private Point _myLoc; //画面位置
59 private int _mySpDis; //区切り位置
60 private int _mySpDis2; //発言欄区切り位置
61 private int _mySpDis3; //プレビュー区切り位置
62 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
63 private bool _iconCol; //1列表示の時true(48サイズのとき)
66 private bool _initial; //true:起動時処理中
67 private bool _initialLayout = true;
68 private bool _ignoreConfigSave; //true:起動時処理中
69 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
70 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
71 private Point _tabMouseDownPoint;
72 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
73 private readonly object _syncObject = new object(); //ロック用
74 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
75 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
76 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
77 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
78 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
79 private const string detailHtmlFormatMono6 = ");\"><pre>";
80 private const string detailHtmlFormatMono7 = "</pre></body></html>";
81 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
82 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
83 private const string detailHtmlFormat7 = "</span></p></body></html>";
84 private string detailHtmlFormatHeader;
85 private string detailHtmlFormatFooter;
86 private bool _myStatusError = false;
87 private bool _myStatusOnline = false;
88 private bool soundfileListup = false;
89 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
92 //private SettingToConfig _cfg; //旧
93 private SettingLocal _cfgLocal;
94 private SettingCommon _cfgCommon;
95 private bool _modifySettingLocal = false;
96 private bool _modifySettingCommon = false;
97 private bool _modifySettingAtId = false;
100 private Twitter tw = new Twitter();
103 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
106 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
107 private SearchWordDialog SearchDialog = new SearchWordDialog(); //検索画面インスタンス
108 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
109 private OpenURL UrlDialog = new OpenURL();
110 public AtIdSupplement AtIdSupl; //@id補助
111 public AtIdSupplement HashSupl; //Hashtag補助
112 public HashtagManage HashMgr;
113 private EventViewerDialog evtDialog;
116 private Font _fntUnread; //未読用フォント
117 private Color _clUnread; //未読用文字色
118 private Font _fntReaded; //既読用フォント
119 private Color _clReaded; //既読用文字色
120 private Color _clFav; //Fav用文字色
121 private Color _clOWL; //片思い用文字色
122 private Color _clRetweet; //Retweet用文字色
123 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
124 private Font _fntDetail; //発言詳細部用フォント
125 private Color _clDetail; //発言詳細部用色
126 private Color _clDetailLink; //発言詳細部用リンク文字色
127 private Color _clDetailBackcolor; //発言詳細部用背景色
128 private Color _clSelf; //自分の発言用背景色
129 private Color _clAtSelf; //自分宛返信用背景色
130 private Color _clTarget; //選択発言者の他の発言用背景色
131 private Color _clAtTarget; //選択発言中の返信先用背景色
132 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
133 private Color _clAtTo; //選択発言の唯一@先
134 private Color _clListBackcolor; //リスト部通常発言背景色
135 private Color _clInputBackcolor; //入力欄背景色
136 private Color _clInputFont; //入力欄文字色
137 private Font _fntInputFont; //入力欄フォント
138 private ImageCache IconCache; //アイコン画像リスト
139 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
140 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
141 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
142 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
143 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
144 private Icon MainIcon; //Main.ico 画面左上のアイコン
145 private Icon ReplyIcon; //5g
146 private Icon ReplyIconBlink; //6g
148 private ImageList _listViewImageList = new ImageList(); //ListViewItemの高さ変更用
150 private PostClass _anchorPost;
151 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
153 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
154 private int _hisIdx; //発言履歴カレントインデックス
156 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
157 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
158 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
161 private List<DateTime> _postTimestamps = new List<DateTime>();
162 private List<DateTime> _favTimestamps = new List<DateTime>();
163 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
164 private int _tlCount;
167 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
168 private SolidBrush _brsBackColorMine;
169 private SolidBrush _brsBackColorAt;
170 private SolidBrush _brsBackColorYou;
171 private SolidBrush _brsBackColorAtYou;
172 private SolidBrush _brsBackColorAtFromTarget;
173 private SolidBrush _brsBackColorAtTo;
174 private SolidBrush _brsBackColorNone;
175 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
176 private StringFormat sfTab = new StringFormat();
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////
179 private ToolStripAPIGauge _apiGauge;
180 private TabInformations _statuses;
182 // ListViewItem のキャッシュ関連
183 private int _itemCacheIndex;
184 private ListViewItem[] _itemCache;
185 private PostClass[] _postCache;
186 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
188 private TabPage _curTab;
189 private int _curItemIndex;
190 private DetailsListView _curList;
191 private PostClass _curPost;
192 private bool _isColumnChanged = false;
193 private bool _waitTimeline = false;
194 private bool _waitReply = false;
195 private bool _waitDm = false;
196 private bool _waitFav = false;
197 private bool _waitPubSearch = false;
198 private bool _waitUserTimeline = false;
199 private bool _waitLists = false;
200 private BackgroundWorker[] _bw = new BackgroundWorker[20];
201 private BackgroundWorker _bwFollower;
202 private InternetSecurityManager SecurityManager;
204 private int UnreadCounter = -1;
205 private int UnreadAtCounter = -1;
207 private string[] ColumnOrgText = new string[9];
208 private string[] ColumnText = new string[9];
210 private bool _DoFavRetweetFlags = false;
211 private bool osResumed = false;
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 = null;
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 _listViewImageList.Dispose();
336 _brsHighLight.Dispose();
337 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
338 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
339 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
340 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
341 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
342 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
343 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
344 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
347 foreach (BackgroundWorker bw in _bw)
352 if (_bwFollower != null)
354 _bwFollower.Dispose();
356 this._apiGauge.Dispose();
357 if (IconCache != null)
359 this.IconCache.CancelAsync();
360 this.IconCache.Dispose();
363 // 終了時にRemoveHandlerしておかないとメモリリークする
364 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
365 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
368 private void LoadIcon(ref Icon IconInstance, string FileName)
370 string dir = Application.StartupPath;
371 if (File.Exists(Path.Combine(dir, FileName)))
375 IconInstance = new Icon(Path.Combine(dir, FileName));
383 private void LoadIcons()
387 string dir = Application.StartupPath;
389 NIconAt = Properties.Resources.At;
390 NIconAtRed = Properties.Resources.AtRed;
391 NIconAtSmoke = Properties.Resources.AtSmoke;
392 NIconRefresh[0] = Properties.Resources.Refresh;
393 NIconRefresh[1] = Properties.Resources.Refresh2;
394 NIconRefresh[2] = Properties.Resources.Refresh3;
395 NIconRefresh[3] = Properties.Resources.Refresh4;
396 TabIcon = Properties.Resources.TabIcon;
397 MainIcon = Properties.Resources.MIcon;
398 ReplyIcon = Properties.Resources.Reply;
399 ReplyIconBlink = Properties.Resources.ReplyBlink;
401 if (!Directory.Exists(Path.Combine(dir, "Icons")))
404 LoadIcon(ref NIconAt, "Icons\\At.ico");
407 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
410 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
413 //アニメーション対応により4種類読み込み
414 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
415 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
416 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
417 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
420 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
423 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
426 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
429 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
432 private void InitColumns(ListView list, bool startup)
434 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
435 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
436 ColumnHeader _colHd3 = new ColumnHeader(); //本文
437 ColumnHeader _colHd4 = new ColumnHeader(); //日付
438 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
439 ColumnHeader _colHd6 = new ColumnHeader(); //未読
440 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
441 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
445 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
449 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
453 _colHd1.Text = ColumnText[0];
455 _colHd2.Text = ColumnText[1];
457 _colHd3.Text = ColumnText[2];
459 _colHd4.Text = ColumnText[3];
461 _colHd5.Text = ColumnText[4];
463 _colHd6.Text = ColumnText[5];
465 _colHd7.Text = ColumnText[6];
467 _colHd8.Text = ColumnText[7];
470 int[] dispOrder = new int[8];
473 for (int i = 0; i < _curList.Columns.Count; i++)
475 for (int j = 0; j < _curList.Columns.Count; j++)
477 if (_curList.Columns[j].DisplayIndex == i)
484 for (int i = 0; i < _curList.Columns.Count; i++)
486 list.Columns[i].Width = _curList.Columns[i].Width;
487 list.Columns[dispOrder[i]].DisplayIndex = i;
494 list.Columns[0].Width = _cfgLocal.Width1;
495 list.Columns[1].Width = _cfgLocal.Width3;
496 list.Columns[0].DisplayIndex = 0;
497 list.Columns[1].DisplayIndex = 1;
501 for (int i = 0; i <= 7; i++)
503 if (_cfgLocal.DisplayIndex1 == i)
505 else if (_cfgLocal.DisplayIndex2 == i)
507 else if (_cfgLocal.DisplayIndex3 == i)
509 else if (_cfgLocal.DisplayIndex4 == i)
511 else if (_cfgLocal.DisplayIndex5 == i)
513 else if (_cfgLocal.DisplayIndex6 == i)
515 else if (_cfgLocal.DisplayIndex7 == i)
517 else if (_cfgLocal.DisplayIndex8 == i)
520 list.Columns[0].Width = _cfgLocal.Width1;
521 list.Columns[1].Width = _cfgLocal.Width2;
522 list.Columns[2].Width = _cfgLocal.Width3;
523 list.Columns[3].Width = _cfgLocal.Width4;
524 list.Columns[4].Width = _cfgLocal.Width5;
525 list.Columns[5].Width = _cfgLocal.Width6;
526 list.Columns[6].Width = _cfgLocal.Width7;
527 list.Columns[7].Width = _cfgLocal.Width8;
528 for (int i = 0; i <= 7; i++)
530 list.Columns[dispOrder[i]].DisplayIndex = i;
536 private void InitColumnText()
539 ColumnText[1] = Properties.Resources.AddNewTabText2;
540 ColumnText[2] = Properties.Resources.AddNewTabText3;
541 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
542 ColumnText[4] = Properties.Resources.AddNewTabText5;
545 ColumnText[7] = "Source";
547 ColumnOrgText[0] = "";
548 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
549 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
550 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
551 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
552 ColumnOrgText[5] = "";
553 ColumnOrgText[6] = "";
554 ColumnOrgText[7] = "Source";
557 switch (_statuses.SortMode)
559 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
562 case IdComparerClass.ComparerMode.Data: //本文
565 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
568 case IdComparerClass.ComparerMode.Name: //名前
571 case IdComparerClass.ComparerMode.Source: //Source
578 if (_statuses.SortOrder == SortOrder.Descending)
580 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
581 ColumnText[2] = ColumnOrgText[2] + "▾";
585 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
586 ColumnText[2] = ColumnOrgText[2] + "▴";
591 if (_statuses.SortOrder == SortOrder.Descending)
593 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
594 ColumnText[c] = ColumnOrgText[c] + "▾";
598 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
599 ColumnText[c] = ColumnOrgText[c] + "▴";
604 private void InitializeTraceFrag()
607 TraceOutToolStripMenuItem.Checked = true;
608 MyCommon.TraceFlag = true;
610 if (!MyCommon.FileVersion.EndsWith("0"))
612 TraceOutToolStripMenuItem.Checked = true;
613 MyCommon.TraceFlag = true;
617 private void TweenMain_Load(object sender, EventArgs e)
619 _ignoreConfigSave = true;
620 this.Visible = false;
622 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
624 SecurityManager = new InternetSecurityManager(PostBrowser);
625 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
627 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
628 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
630 if (MyApplication.StartupOptions.ContainsKey("d"))
631 MyCommon.TraceFlag = true;
633 Regex.CacheSize = 100;
635 InitializeTraceFrag();
636 LoadIcons(); // アイコン読み込み
639 _statuses = TabInformations.GetInstance();
642 this.Icon = MainIcon; //メインフォーム(TweenMain)
643 NotifyIcon1.Icon = NIconAt; //タスクトレイ
644 TabImage.Images.Add(TabIcon); //タブ見出し
646 SettingDialog.Owner = this;;
647 SearchDialog.Owner = this;
648 fltDialog.Owner = this;
649 UrlDialog.Owner = this;
651 _history.Add(new PostingStatus());
654 _reply_to_name = null;
656 //<<<<<<<<<設定関連>>>>>>>>>
663 ThumbnailGenerator.InitializeGenerator();
665 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
666 imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
667 imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
669 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
670 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
671 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
674 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
675 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
678 _fntUnread = _cfgLocal.FontUnread;
679 _clUnread = _cfgLocal.ColorUnread;
680 _fntReaded = _cfgLocal.FontRead;
681 _clReaded = _cfgLocal.ColorRead;
682 _clFav = _cfgLocal.ColorFav;
683 _clOWL = _cfgLocal.ColorOWL;
684 _clRetweet = _cfgLocal.ColorRetweet;
685 _fntDetail = _cfgLocal.FontDetail;
686 _clDetail = _cfgLocal.ColorDetail;
687 _clDetailLink = _cfgLocal.ColorDetailLink;
688 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
689 _clSelf = _cfgLocal.ColorSelf;
690 _clAtSelf = _cfgLocal.ColorAtSelf;
691 _clTarget = _cfgLocal.ColorTarget;
692 _clAtTarget = _cfgLocal.ColorAtTarget;
693 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
694 _clAtTo = _cfgLocal.ColorAtTo;
695 _clListBackcolor = _cfgLocal.ColorListBackcolor;
696 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
697 _clInputFont = _cfgLocal.ColorInputFont;
698 _fntInputFont = _cfgLocal.FontInputFont;
700 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
701 if (fontUIGlobal != null)
703 OTBaseForm.GlobalFont = fontUIGlobal;
704 this.Font = fontUIGlobal;
707 // StringFormatオブジェクトへの事前設定
708 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
709 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
710 //sf.FormatFlags = StringFormatFlags.LineLimit; //
711 sfTab.Alignment = StringAlignment.Center;
712 sfTab.LineAlignment = StringAlignment.Center;
715 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
716 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
719 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
720 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
722 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
724 SettingDialog.TimelinePeriodInt = _cfgCommon.TimelinePeriod;
725 SettingDialog.ReplyPeriodInt = _cfgCommon.ReplyPeriod;
726 SettingDialog.DMPeriodInt = _cfgCommon.DMPeriod;
727 SettingDialog.PubSearchPeriodInt = _cfgCommon.PubSearchPeriod;
728 SettingDialog.UserTimelinePeriodInt = _cfgCommon.UserTimelinePeriod;
729 SettingDialog.ListsPeriodInt = _cfgCommon.ListsPeriod;
731 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
733 if (SettingDialog.TimelinePeriodInt < 15 && SettingDialog.TimelinePeriodInt > 0) SettingDialog.TimelinePeriodInt = 15;
734 if (SettingDialog.ReplyPeriodInt < 15 && SettingDialog.ReplyPeriodInt > 0) SettingDialog.ReplyPeriodInt = 15;
735 if (SettingDialog.DMPeriodInt < 15 && SettingDialog.DMPeriodInt > 0) SettingDialog.DMPeriodInt = 15;
736 if (SettingDialog.PubSearchPeriodInt < 30 && SettingDialog.PubSearchPeriodInt > 0) SettingDialog.PubSearchPeriodInt = 30;
737 if (SettingDialog.UserTimelinePeriodInt < 15 && SettingDialog.UserTimelinePeriodInt > 0) SettingDialog.UserTimelinePeriodInt = 15;
738 if (SettingDialog.ListsPeriodInt < 15 && SettingDialog.ListsPeriodInt > 0) SettingDialog.ListsPeriodInt = 15;
741 //起動時読み込み分を既読にするか。trueなら既読として処理
742 SettingDialog.Readed = _cfgCommon.Read;
743 //新着取得時のリストスクロールをするか。trueならスクロールしない
744 ListLockMenuItem.Checked = _cfgCommon.ListLock;
745 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
746 SettingDialog.IconSz = _cfgCommon.IconSize;
748 SettingDialog.Status = _cfgLocal.StatusText;
750 SettingDialog.UnreadManage = _cfgCommon.UnreadManage;
752 SettingDialog.PlaySound = _cfgCommon.PlaySound;
753 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
754 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
755 //片思い表示。trueなら片思い表示する
756 SettingDialog.OneWayLove = _cfgCommon.OneWayLove;
758 SettingDialog.FontUnread = _fntUnread;
759 SettingDialog.ColorUnread = _clUnread;
760 SettingDialog.FontReaded = _fntReaded;
761 SettingDialog.ColorReaded = _clReaded;
762 SettingDialog.ColorFav = _clFav;
763 SettingDialog.ColorOWL = _clOWL;
764 SettingDialog.ColorRetweet = _clRetweet;
765 SettingDialog.FontDetail = _fntDetail;
766 SettingDialog.ColorDetail = _clDetail;
767 SettingDialog.ColorDetailLink = _clDetailLink;
768 SettingDialog.ColorDetailBackcolor = _clDetailBackcolor;
769 SettingDialog.ColorSelf = _clSelf;
770 SettingDialog.ColorAtSelf = _clAtSelf;
771 SettingDialog.ColorTarget = _clTarget;
772 SettingDialog.ColorAtTarget = _clAtTarget;
773 SettingDialog.ColorAtFromTarget = _clAtFromTarget;
774 SettingDialog.ColorAtTo = _clAtTo;
775 SettingDialog.ColorListBackcolor = _clListBackcolor;
776 SettingDialog.ColorInputBackcolor = _clInputBackcolor;
777 SettingDialog.ColorInputFont = _clInputFont;
778 SettingDialog.FontInputFont = _fntInputFont;
780 SettingDialog.NameBalloon = _cfgCommon.NameBalloon;
781 SettingDialog.PostCtrlEnter = _cfgCommon.PostCtrlEnter;
782 SettingDialog.PostShiftEnter = _cfgCommon.PostShiftEnter;
784 SettingDialog.CountApi = _cfgCommon.CountApi;
785 SettingDialog.CountApiReply = _cfgCommon.CountApiReply;
786 if (SettingDialog.CountApi < 20 || SettingDialog.CountApi > 200) SettingDialog.CountApi = 60;
787 if (SettingDialog.CountApiReply < 20 || SettingDialog.CountApiReply > 200) SettingDialog.CountApiReply = 40;
789 SettingDialog.BrowserPath = _cfgLocal.BrowserPath;
790 SettingDialog.PostAndGet = _cfgCommon.PostAndGet;
791 SettingDialog.UseRecommendStatus = _cfgLocal.UseRecommendStatus;
792 SettingDialog.DispUsername = _cfgCommon.DispUsername;
793 SettingDialog.CloseToExit = _cfgCommon.CloseToExit;
794 SettingDialog.MinimizeToTray = _cfgCommon.MinimizeToTray;
795 SettingDialog.DispLatestPost = _cfgCommon.DispLatestPost;
796 SettingDialog.SortOrderLock = _cfgCommon.SortOrderLock;
797 SettingDialog.ViewTabBottom = _cfgCommon.ViewTabBottom;
798 SettingDialog.TinyUrlResolve = _cfgCommon.TinyUrlResolve;
800 SettingDialog.SelectedProxyType = _cfgLocal.ProxyType;
801 SettingDialog.ProxyAddress = _cfgLocal.ProxyAddress;
802 SettingDialog.ProxyPort = _cfgLocal.ProxyPort;
803 SettingDialog.ProxyUser = _cfgLocal.ProxyUser;
804 SettingDialog.ProxyPassword = _cfgLocal.ProxyPassword;
806 SettingDialog.StartupVersion = _cfgCommon.StartupVersion;
807 SettingDialog.StartupFollowers = _cfgCommon.StartupFollowers;
808 SettingDialog.RestrictFavCheck = _cfgCommon.RestrictFavCheck;
809 SettingDialog.AlwaysTop = _cfgCommon.AlwaysTop;
810 SettingDialog.UrlConvertAuto = false;
811 //SettingDialog.UrlConvertAuto = _cfgCommon.UrlConvertAuto;
813 SettingDialog.UseUnreadStyle = _cfgCommon.UseUnreadStyle;
814 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
815 SettingDialog.RetweetNoConfirm = _cfgCommon.RetweetNoConfirm;
816 SettingDialog.PlaySound = _cfgCommon.PlaySound;
817 SettingDialog.DateTimeFormat = _cfgCommon.DateTimeFormat;
818 SettingDialog.LimitBalloon = _cfgCommon.LimitBalloon;
819 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
820 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
821 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
822 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
823 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
824 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
825 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
827 //廃止サービスが選択されていた場合bit.lyへ読み替え
828 if (_cfgCommon.AutoShortUrlFirst < 0)
829 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
831 SettingDialog.AutoShortUrlFirst = _cfgCommon.AutoShortUrlFirst;
832 SettingDialog.TabIconDisp = _cfgCommon.TabIconDisp;
833 SettingDialog.ReplyIconState = _cfgCommon.ReplyIconState;
834 SettingDialog.ReadOwnPost = _cfgCommon.ReadOwnPost;
835 SettingDialog.GetFav = _cfgCommon.GetFav;
836 SettingDialog.ReadOldPosts = _cfgCommon.ReadOldPosts;
837 SettingDialog.BitlyUser = _cfgCommon.BilyUser;
838 SettingDialog.BitlyPwd = _cfgCommon.BitlyPwd;
839 SettingDialog.ShowGrid = _cfgCommon.ShowGrid;
840 SettingDialog.Language = _cfgCommon.Language;
841 SettingDialog.UseAtIdSupplement = _cfgCommon.UseAtIdSupplement;
842 SettingDialog.UseHashSupplement = _cfgCommon.UseHashSupplement;
843 SettingDialog.PreviewEnable = _cfgCommon.PreviewEnable;
844 SettingDialog.StatusAreaAtBottom = _cfgCommon.StatusAreaAtBottom;
845 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
847 SettingDialog.IsMonospace = _cfgCommon.IsMonospace;
849 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
850 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
852 //Regex statregex = new Regex("^0*");
853 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
858 if (DateTime.Now.ToString(SettingDialog.DateTimeFormat).Length == 0)
860 // このブロックは絶対に実行されないはず
861 // 変換が成功した場合にLengthが0にならない
862 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
865 catch (FormatException)
867 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
868 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
871 SettingDialog.Nicoms = _cfgCommon.Nicoms;
872 SettingDialog.HotkeyEnabled = _cfgCommon.HotkeyEnabled;
873 SettingDialog.HotkeyMod = _cfgCommon.HotkeyModifier;
874 SettingDialog.HotkeyKey = _cfgCommon.HotkeyKey;
875 SettingDialog.HotkeyValue = _cfgCommon.HotkeyValue;
877 SettingDialog.BlinkNewMentions = _cfgCommon.BlinkNewMentions;
879 SettingDialog.UseAdditionalCount = _cfgCommon.UseAdditionalCount;
880 SettingDialog.MoreCountApi = _cfgCommon.MoreCountApi;
881 SettingDialog.FirstCountApi = _cfgCommon.FirstCountApi;
882 SettingDialog.SearchCountApi = _cfgCommon.SearchCountApi;
883 SettingDialog.FavoritesCountApi = _cfgCommon.FavoritesCountApi;
884 SettingDialog.UserTimelineCountApi = _cfgCommon.UserTimelineCountApi;
885 SettingDialog.ListCountApi = _cfgCommon.ListCountApi;
887 SettingDialog.UserstreamStartup = _cfgCommon.UserstreamStartup;
888 SettingDialog.UserstreamPeriodInt = _cfgCommon.UserstreamPeriod;
889 SettingDialog.OpenUserTimeline = _cfgCommon.OpenUserTimeline;
890 SettingDialog.ListDoubleClickAction = _cfgCommon.ListDoubleClickAction;
891 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
892 SettingDialog.HideDuplicatedRetweets = _cfgCommon.HideDuplicatedRetweets;
894 SettingDialog.EnableImgAzyobuziNet = _cfgCommon.EnableImgAzyobuziNet;
895 SettingDialog.ImgAzyobuziNetDisabledInDM = _cfgCommon.ImgAzyobuziNetDisabledInDM;
896 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
897 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
898 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
899 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
900 SettingDialog.IsListStatusesIncludeRts = _cfgCommon.IsListsIncludeRts;
901 SettingDialog.TabMouseLock = _cfgCommon.TabMouseLock;
902 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
903 SettingDialog.IsNotifyUseGrowl = _cfgCommon.IsUseNotifyGrowl;
906 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
907 HashMgr = new HashtagManage(HashSupl,
908 _cfgCommon.HashTags.ToArray(),
909 _cfgCommon.HashSelected,
910 _cfgCommon.HashIsPermanent,
911 _cfgCommon.HashIsHead,
912 _cfgCommon.HashIsNotAddToAtReply);
913 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
917 Networking.Initialize();
920 this.IconCache = new ImageCache();
922 bool saveRequired = false;
923 bool firstRun = false;
925 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
926 if (string.IsNullOrEmpty(tw.Username))
930 SettingDialog.ShowInTaskbar = true;
932 //設定せずにキャンセルされた場合はプログラム終了
933 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
935 Application.Exit(); //強制終了
938 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
939 if (string.IsNullOrEmpty(tw.Username))
941 Application.Exit(); //強制終了
944 SettingDialog.ShowInTaskbar = false;
948 _fntUnread = SettingDialog.FontUnread;
949 _clUnread = SettingDialog.ColorUnread;
950 _fntReaded = SettingDialog.FontReaded;
951 _clReaded = SettingDialog.ColorReaded;
952 _clFav = SettingDialog.ColorFav;
953 _clOWL = SettingDialog.ColorOWL;
954 _clRetweet = SettingDialog.ColorRetweet;
955 _fntDetail = SettingDialog.FontDetail;
956 _clDetail = SettingDialog.ColorDetail;
957 _clDetailLink = SettingDialog.ColorDetailLink;
958 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
959 _clSelf = SettingDialog.ColorSelf;
960 _clAtSelf = SettingDialog.ColorAtSelf;
961 _clTarget = SettingDialog.ColorTarget;
962 _clAtTarget = SettingDialog.ColorAtTarget;
963 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
964 _clAtTo = SettingDialog.ColorAtTo;
965 _clListBackcolor = SettingDialog.ColorListBackcolor;
966 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
967 _clInputFont = SettingDialog.ColorInputFont;
968 _fntInputFont = SettingDialog.FontInputFont;
970 //他の設定項目は、随時設定画面で保持している値を読み出して使用
973 _brsBackColorMine = new SolidBrush(_clSelf);
974 _brsBackColorAt = new SolidBrush(_clAtSelf);
975 _brsBackColorYou = new SolidBrush(_clTarget);
976 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
977 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
978 _brsBackColorAtTo = new SolidBrush(_clAtTo);
979 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
980 _brsBackColorNone = new SolidBrush(_clListBackcolor);
982 InitDetailHtmlFormat();
984 if (SettingDialog.HotkeyEnabled)
987 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
988 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
989 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
990 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
991 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
993 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
997 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
998 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
999 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
1000 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
1002 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
1003 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
1004 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
1005 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
1006 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
1007 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
1008 tw.TrackWord = _cfgCommon.TrackWord;
1009 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
1010 tw.AllAtReply = _cfgCommon.AllAtReply;
1011 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
1014 ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
1017 this.ClientSize = _cfgLocal.FormSize;
1018 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1019 _myLoc = _cfgLocal.FormLocation;
1021 if (this.WindowState != FormWindowState.Minimized)
1023 this.DesktopLocation = _cfgLocal.FormLocation;
1024 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
1025 bool outOfScreen = true;
1026 if (Screen.AllScreens.Length == 1) //ハングするとの報告
1028 foreach (Screen scr in Screen.AllScreens)
1030 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1032 outOfScreen = false;
1038 this.DesktopLocation = new Point(0, 0);
1039 _myLoc = this.DesktopLocation;
1043 this.TopMost = SettingDialog.AlwaysTop;
1044 _mySpDis = _cfgLocal.SplitterDistance;
1045 _mySpDis2 = _cfgLocal.StatusTextHeight;
1046 _mySpDis3 = _cfgLocal.PreviewDistance;
1047 if (_mySpDis3 == -1)
1049 _mySpDis3 = _mySize.Width - 150;
1050 if (_mySpDis3 < 1) _mySpDis3 = 50;
1051 _cfgLocal.PreviewDistance = _mySpDis3;
1053 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
1054 //this.Tween_ClientSizeChanged(this, null);
1055 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
1056 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
1058 StatusText.Font = _fntInputFont;
1059 StatusText.ForeColor = _clInputFont;
1061 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
1062 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
1064 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
1065 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
1067 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1068 if (SettingDialog.UnreadManage == false)
1070 ReadedStripMenuItem.Enabled = false;
1071 UnreadStripMenuItem.Enabled = false;
1074 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
1077 TimerTimeline.AutoReset = true;
1078 TimerTimeline.SynchronizingObject = this;
1080 TimerTimeline.Interval = 1000;
1081 TimerTimeline.Enabled = true;
1084 TimerRefreshIcon.Interval = 200;
1085 TimerRefreshIcon.Enabled = true;
1088 StatusLabel.Text = "";
1089 StatusLabel.AutoToolTip = false;
1090 StatusLabel.ToolTipText = "";
1092 lblLen.Text = GetRestStatusCount(true, false).ToString();
1094 ////////////////////////////////////////////////////////////////////////////////
1095 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1096 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1097 switch (_cfgCommon.SortColumn)
1099 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1103 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1106 mode = IdComparerClass.ComparerMode.Nickname;
1109 mode = IdComparerClass.ComparerMode.Data;
1112 mode = IdComparerClass.ComparerMode.Id;
1115 mode = IdComparerClass.ComparerMode.Name;
1118 mode = IdComparerClass.ComparerMode.Source;
1121 _statuses.SortMode = mode;
1122 ////////////////////////////////////////////////////////////////////////////////
1124 ApplyListViewIconSize(SettingDialog.IconSz);
1126 tw.TinyUrlResolve = SettingDialog.TinyUrlResolve;
1128 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1129 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1130 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1131 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1132 SourceLinkLabel.Text = ""; //Source部分初期化
1134 //<<<<<<<<タブ関連>>>>>>>
1135 //デフォルトタブの存在チェック、ない場合には追加
1136 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1139 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1141 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1145 tab.TabType = MyCommon.TabUsageType.Home;
1148 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1151 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1153 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1157 tab.TabType = MyCommon.TabUsageType.Mentions;
1160 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1163 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1165 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1169 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1172 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1175 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1177 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1181 tab.TabType = MyCommon.TabUsageType.Favorites;
1184 foreach (var tab in _statuses.Tabs.Values)
1186 if (tab.TabType == MyCommon.TabUsageType.Undefined)
1188 tab.TabType = MyCommon.TabUsageType.UserDefined;
1190 if (!AddNewTab(tab.TabName, true, tab.TabType, tab.ListInfo)) throw new Exception(Properties.Resources.TweenMain_LoadText1);
1193 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1194 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1195 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1196 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1198 if (SettingDialog.MinimizeToTray == false || this.WindowState != FormWindowState.Minimized)
1200 this.Visible = true;
1202 _curTab = ListTab.SelectedTab;
1204 _curList = (DetailsListView)_curTab.Tag;
1205 SetMainWindowTitle();
1206 SetNotifyIconText();
1208 if (SettingDialog.TabIconDisp)
1210 ListTab.DrawMode = TabDrawMode.Normal;
1214 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1215 ListTab.DrawItem += ListTab_DrawItem;
1216 ListTab.ImageList = null;
1219 _ignoreConfigSave = false;
1220 this.TweenMain_Resize(null, null);
1221 if (saveRequired) SaveConfigsAll(false);
1225 tw.VerifyCredentials();
1226 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1228 if (ua.Username.ToLower() == tw.Username.ToLower())
1230 ua.UserId = tw.UserId;
1235 foreach (UserAccount ua in SettingDialog.UserAccounts)
1237 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1239 ua.UserId = tw.UserId;
1246 // 初回起動時だけ右下のメニューを目立たせる
1247 HashStripSplitButton.ShowDropDown();
1254 private void InitDetailHtmlFormat()
1256 if (SettingDialog.IsMonospace)
1258 detailHtmlFormatHeader = detailHtmlFormatMono1;
1259 detailHtmlFormatFooter = detailHtmlFormatMono7;
1263 detailHtmlFormatHeader = detailHtmlFormat1;
1264 detailHtmlFormatFooter = detailHtmlFormat7;
1266 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();
1267 if (SettingDialog.IsMonospace)
1269 detailHtmlFormatHeader += detailHtmlFormatMono6;
1273 detailHtmlFormatHeader += detailHtmlFormat6;
1277 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1282 txt = ListTab.TabPages[e.Index].Text;
1289 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1290 if (e.State == DrawItemState.Selected)
1292 e.DrawFocusRectangle();
1297 if (_statuses.Tabs[txt].UnreadCount > 0)
1300 fore = System.Drawing.SystemBrushes.ControlText;
1304 fore = System.Drawing.SystemBrushes.ControlText;
1306 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1309 private void LoadConfig()
1311 _cfgCommon = SettingCommon.Load();
1312 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1314 _cfgCommon.UserAccounts = new List<UserAccount>();
1315 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1317 UserAccount account = new UserAccount();
1318 account.Username = _cfgCommon.UserName;
1319 account.UserId = _cfgCommon.UserId;
1320 account.Token = _cfgCommon.Token;
1321 account.TokenSecret = _cfgCommon.TokenSecret;
1323 _cfgCommon.UserAccounts.Add(account);
1326 _cfgLocal = SettingLocal.Load();
1327 List<TabClass> tabs = SettingTabs.Load().Tabs;
1328 foreach (TabClass tb in tabs)
1332 _statuses.Tabs.Add(tb.TabName, tb);
1336 tb.TabName = _statuses.GetUniqueTabName();
1337 _statuses.Tabs.Add(tb.TabName, tb);
1340 if (_statuses.Tabs.Count == 0)
1342 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1343 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1344 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1345 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1349 private void TimerInterval_Changed(object sender, AppendSettingDialog.IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1351 if (!TimerTimeline.Enabled) return;
1355 private AppendSettingDialog.IntervalChangedEventArgs ResetTimers = new AppendSettingDialog.IntervalChangedEventArgs();
1357 private static int homeCounter = 0;
1358 private static int mentionCounter = 0;
1359 private static int dmCounter = 0;
1360 private static int pubSearchCounter = 0;
1361 private static int userTimelineCounter = 0;
1362 private static int listsCounter = 0;
1363 private static int usCounter = 0;
1364 private static int ResumeWait = 0;
1365 private static int refreshFollowers = 0;
1367 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1369 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1370 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1371 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1372 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1373 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1374 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1375 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1376 Interlocked.Increment(ref refreshFollowers);
1379 if (ResetTimers.Timeline || homeCounter <= 0 && SettingDialog.TimelinePeriodInt > 0)
1381 Interlocked.Exchange(ref homeCounter, SettingDialog.TimelinePeriodInt);
1382 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
1383 ResetTimers.Timeline = false;
1385 if (ResetTimers.Reply || mentionCounter <= 0 && SettingDialog.ReplyPeriodInt > 0)
1387 Interlocked.Exchange(ref mentionCounter, SettingDialog.ReplyPeriodInt);
1388 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
1389 ResetTimers.Reply = false;
1391 if (ResetTimers.DirectMessage || dmCounter <= 0 && SettingDialog.DMPeriodInt > 0)
1393 Interlocked.Exchange(ref dmCounter, SettingDialog.DMPeriodInt);
1394 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
1395 ResetTimers.DirectMessage = false;
1397 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && SettingDialog.PubSearchPeriodInt > 0)
1399 Interlocked.Exchange(ref pubSearchCounter, SettingDialog.PubSearchPeriodInt);
1400 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, "");
1401 ResetTimers.PublicSearch = false;
1403 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && SettingDialog.UserTimelinePeriodInt > 0)
1405 Interlocked.Exchange(ref userTimelineCounter, SettingDialog.UserTimelinePeriodInt);
1406 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, "");
1407 ResetTimers.UserTimeline = false;
1409 if (ResetTimers.Lists || listsCounter <= 0 && SettingDialog.ListsPeriodInt > 0)
1411 Interlocked.Exchange(ref listsCounter, SettingDialog.ListsPeriodInt);
1412 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, "");
1413 ResetTimers.Lists = false;
1415 if (ResetTimers.UserStream || usCounter <= 0 && SettingDialog.UserstreamPeriodInt > 0)
1417 Interlocked.Exchange(ref usCounter, SettingDialog.UserstreamPeriodInt);
1418 if (this._isActiveUserstream) RefreshTimeline(true);
1419 ResetTimers.UserStream = false;
1421 if (refreshFollowers > 6 * 3600)
1423 Interlocked.Exchange(ref refreshFollowers, 0);
1424 doGetFollowersMenu();
1425 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
1426 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
1430 Interlocked.Increment(ref ResumeWait);
1431 if (ResumeWait > 30)
1434 Interlocked.Exchange(ref ResumeWait, 0);
1435 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
1436 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
1437 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
1438 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, "");
1439 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, "");
1440 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, "");
1441 doGetFollowersMenu();
1442 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
1447 private void RefreshTimeline(bool isUserStream)
1449 if (isUserStream) this.RefreshTasktrayIcon(true);
1451 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1452 long topId = GetScrollPos(ref smode);
1453 int befCnt = _curList.VirtualListSize;
1456 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1457 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
1458 SaveSelectedStatus(selId, focusedId);
1461 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1464 PostClass[] notifyPosts = null;
1465 string soundFile = "";
1467 bool isMention = false;
1468 bool isDelete = false;
1469 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1471 if (MyCommon._endingFlag) return;
1476 foreach (TabPage tab in ListTab.TabPages)
1478 DetailsListView lst = (DetailsListView)tab.Tag;
1479 TabClass tabInfo = _statuses.Tabs[tab.Text];
1480 using (ControlTransaction.Update(lst))
1482 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1484 if (lst.Equals(_curList))
1486 this.PurgeListViewItemCache();
1490 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1496 this.SelectListItem(lst,
1497 tabInfo.IndexOf(selId[tab.Text]),
1498 tabInfo.IndexOf(focusedId[tab.Text]));
1501 if (tabInfo.UnreadCount > 0)
1502 if (SettingDialog.TabIconDisp)
1503 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1505 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
1509 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1518 if (befCnt != _curList.VirtualListSize)
1524 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1528 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1535 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1537 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1538 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1544 catch (Exception ex)
1546 ex.Data["Msg"] = "Ref2";
1552 NotifyNewPosts(notifyPosts,
1555 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1557 SetMainWindowTitle();
1558 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1560 HashSupl.AddRangeItem(tw.GetHashList());
1564 private long GetScrollPos(ref int smode)
1567 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1569 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1571 if (_statuses.SortOrder == SortOrder.Ascending)
1574 if (ListLockMenuItem.Checked)
1579 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1584 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1586 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1587 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1588 if (_item.Index == _curList.VirtualListSize - 1)
1595 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1603 if (ListLockMenuItem.Checked)
1606 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1611 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1614 _item = _curList.GetItemAt(0, 10); //一番上
1615 if (_item == null) _item = _curList.Items[0];
1616 if (_item.Index == 0)
1622 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1631 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1642 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long[]> focusedId)
1644 if (MyCommon._endingFlag) return;
1645 foreach (TabPage tab in ListTab.TabPages)
1647 var lst = (DetailsListView)tab.Tag;
1648 var tabInfo = _statuses.Tabs[tab.Text];
1649 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1651 selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
1655 selId.Add(tab.Text, new long[1] {-2});
1658 var fIds = new long[2]; // 0 = focus, 1 = selection mark
1659 var item = lst.FocusedItem;
1660 fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
1661 var mIdx = lst.SelectionMark;
1662 fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
1663 focusedId.Add(tab.Text, fIds);
1668 private bool BalloonRequired()
1670 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1671 ev.Eventtype = MyCommon.EVENTTYPE.None;
1673 return BalloonRequired(ev);
1676 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1678 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1681 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1683 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1686 private bool BalloonRequired(Twitter.FormattedEvent ev)
1689 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1690 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1694 SettingDialog.LimitBalloon &&
1696 this.WindowState == FormWindowState.Minimized ||
1698 Form.ActiveForm == null
1701 !SettingDialog.LimitBalloon
1704 !NativeMethods.IsScreenSaverRunning())
1714 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1716 if (notifyPosts != null &&
1717 notifyPosts.Length > 0 &&
1718 this.SettingDialog.ReadOwnPost &&
1719 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1725 if (BalloonRequired())
1727 if (notifyPosts != null && notifyPosts.Length > 0)
1729 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1730 if (SettingDialog.IsNotifyUseGrowl)
1732 StringBuilder sb = new StringBuilder();
1736 foreach (PostClass post in notifyPosts)
1738 if (!(notifyPosts.Length > 3))
1744 if (post.IsReply && !post.IsExcludeReply) reply = true;
1745 if (post.IsDm) dm = true;
1746 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1747 switch (SettingDialog.NameBalloon)
1749 case MyCommon.NameBalloonEnum.UserID:
1750 sb.Append(post.ScreenName).Append(" : ");
1752 case MyCommon.NameBalloonEnum.NickName:
1753 sb.Append(post.Nickname).Append(" : ");
1756 sb.Append(post.TextFromApi);
1757 if (notifyPosts.Length > 3)
1759 if (notifyPosts.Last() != post) continue;
1762 StringBuilder title = new StringBuilder();
1763 GrowlHelper.NotifyType nt;
1764 if (SettingDialog.DispUsername)
1766 title.Append(tw.Username);
1767 title.Append(" - ");
1775 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1776 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1777 title.Append(Application.ProductName);
1778 title.Append(" [DM] ");
1779 title.Append(Properties.Resources.RefreshDirectMessageText1);
1781 title.Append(addCount);
1782 title.Append(Properties.Resources.RefreshDirectMessageText2);
1783 nt = GrowlHelper.NotifyType.DirectMessage;
1787 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1788 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1789 title.Append(Application.ProductName);
1790 title.Append(" [Reply!] ");
1791 title.Append(Properties.Resources.RefreshTimelineText1);
1793 title.Append(addCount);
1794 title.Append(Properties.Resources.RefreshTimelineText2);
1795 nt = GrowlHelper.NotifyType.Reply;
1799 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1800 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1801 title.Append(Application.ProductName);
1803 title.Append(Properties.Resources.RefreshTimelineText1);
1805 title.Append(addCount);
1806 title.Append(Properties.Resources.RefreshTimelineText2);
1807 nt = GrowlHelper.NotifyType.Notify;
1809 string bText = sb.ToString();
1810 if (string.IsNullOrEmpty(bText)) return;
1812 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1813 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1818 StringBuilder sb = new StringBuilder();
1821 foreach (PostClass post in notifyPosts)
1823 if (post.IsReply && !post.IsExcludeReply) reply = true;
1824 if (post.IsDm) dm = true;
1825 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1826 switch (SettingDialog.NameBalloon)
1828 case MyCommon.NameBalloonEnum.UserID:
1829 sb.Append(post.ScreenName).Append(" : ");
1831 case MyCommon.NameBalloonEnum.NickName:
1832 sb.Append(post.Nickname).Append(" : ");
1835 sb.Append(post.TextFromApi);
1838 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1839 StringBuilder title = new StringBuilder();
1841 if (SettingDialog.DispUsername)
1843 title.Append(tw.Username);
1844 title.Append(" - ");
1852 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1853 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1854 ntIcon = ToolTipIcon.Warning;
1855 title.Append(Application.ProductName);
1856 title.Append(" [DM] ");
1857 title.Append(Properties.Resources.RefreshDirectMessageText1);
1859 title.Append(addCount);
1860 title.Append(Properties.Resources.RefreshDirectMessageText2);
1864 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1865 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1866 ntIcon = ToolTipIcon.Warning;
1867 title.Append(Application.ProductName);
1868 title.Append(" [Reply!] ");
1869 title.Append(Properties.Resources.RefreshTimelineText1);
1871 title.Append(addCount);
1872 title.Append(Properties.Resources.RefreshTimelineText2);
1876 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1877 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1878 ntIcon = ToolTipIcon.Info;
1879 title.Append(Application.ProductName);
1881 title.Append(Properties.Resources.RefreshTimelineText1);
1883 title.Append(addCount);
1884 title.Append(Properties.Resources.RefreshTimelineText2);
1886 string bText = sb.ToString();
1887 if (string.IsNullOrEmpty(bText)) return;
1888 //NotifyIcon1.BalloonTipText = sb.ToString();
1889 //NotifyIcon1.ShowBalloonTip(500);
1890 NotifyIcon1.BalloonTipTitle = title.ToString();
1891 NotifyIcon1.BalloonTipText = bText;
1892 NotifyIcon1.BalloonTipIcon = ntIcon;
1893 NotifyIcon1.ShowBalloonTip(500);
1899 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(soundFile))
1903 string dir = Application.StartupPath;
1904 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1906 dir = Path.Combine(dir, "Sounds");
1908 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1918 //mentions新着時に画面ブリンク
1919 if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1921 NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
1925 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1927 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1929 _curItemIndex = _curList.SelectedIndices[0];
1930 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1934 _curPost = GetCurTabPost(_curItemIndex);
1936 catch (ArgumentException)
1941 this.PushSelectPostChain();
1943 if (SettingDialog.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
1945 ChangeCacheStyleRead(true, _curItemIndex); //既読へ(フォント、文字色)
1951 private void ChangeCacheStyleRead(bool Read, int Index)
1953 var tabInfo = _statuses.Tabs[_curTab.Text];
1954 //Read:true=既読 false=未読
1955 //未読管理していなかったら既読として扱う
1956 if (!tabInfo.UnreadManage ||
1957 !SettingDialog.UnreadManage) Read = true;
1960 ListViewItem itm = null;
1961 PostClass post = null;
1963 this.TryGetListViewItemCache(Index, out itm, out post);
1965 if (itm == null || post == null)
1967 itm = ((DetailsListView)_curTab.Tag).Items[Index];
1968 post = tabInfo[Index];
1971 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
1974 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
1981 Item.SubItems[5].Text = "";
1986 Item.SubItems[5].Text = "★";
1992 else if (Post.RetweetedId != null)
1994 else if (Post.IsOwl && (Post.IsDm || SettingDialog.OneWayLove))
1996 else if (Read || !SettingDialog.UseUnreadStyle)
2001 if (DList == null || Item.Index == -1)
2003 Item.ForeColor = cl;
2004 if (SettingDialog.UseUnreadStyle)
2010 if (SettingDialog.UseUnreadStyle)
2011 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
2013 DList.ChangeItemForeColor(Item.Index, cl);
2014 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
2018 private void ColorizeList()
2020 //Index:更新対象のListviewItem.Index。Colorを返す。
2021 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2024 _post = _anchorPost;
2028 if (_post == null) return;
2030 var itemColors = new Color[] { };
2033 this.itemCacheLock.EnterReadLock();
2036 if (this._itemCache == null) return;
2039 from i in Enumerable.Range(0, this._itemCache.Length)
2040 select this.JudgeColor(_post, this._postCache[i]);
2042 itemColors = query.ToArray();
2043 itemIndex = _itemCacheIndex;
2045 finally { this.itemCacheLock.ExitReadLock(); }
2047 if (itemIndex < 0) return;
2049 foreach (var backColor in itemColors)
2051 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
2052 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
2053 _curList.ChangeItemBackColor(itemIndex++, backColor);
2057 private void ColorizeList(ListViewItem Item, int Index)
2059 //Index:更新対象のListviewItem.Index。Colorを返す。
2060 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2063 _post = _anchorPost;
2067 PostClass tPost = GetCurTabPost(Index);
2069 if (_post == null) return;
2071 if (Item.Index == -1)
2072 Item.BackColor = JudgeColor(_post, tPost);
2074 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
2077 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
2080 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
2083 else if (TargetPost.IsMe)
2086 else if (TargetPost.IsReply)
2089 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2091 cl = _clAtFromTarget;
2092 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2095 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2100 cl = _clListBackcolor;
2105 private async void PostButton_Click(object sender, EventArgs e)
2107 if (StatusText.Text.Trim().Length == 0)
2109 if (!ImageSelector.Enabled)
2116 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2118 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2120 MessageBoxButtons.YesNoCancel,
2121 MessageBoxIcon.Question);
2124 case DialogResult.Yes:
2125 doReTweetOfficial(false);
2126 StatusText.Text = "";
2128 case DialogResult.Cancel:
2133 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2135 if (SettingDialog.Nicoms)
2137 StatusText.SelectionStart = StatusText.Text.Length;
2138 await UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2140 //if (SettingDialog.UrlConvertAuto)
2142 // StatusText.SelectionStart = StatusText.Text.Length;
2143 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2145 //else if (SettingDialog.Nicoms)
2147 // StatusText.SelectionStart = StatusText.Text.Length;
2148 // UrlConvert(UrlConverter.Nicoms);
2150 StatusText.SelectionStart = StatusText.Text.Length;
2151 GetWorkerArg args = new GetWorkerArg();
2154 args.type = MyCommon.WORKERTYPE.PostMessage;
2155 CheckReplyTo(StatusText.Text);
2158 int adjustCount = 0;
2159 string tmpStatus = StatusText.Text.Trim();
2160 if (ToolStripMenuItemApiCommandEvasion.Checked)
2163 if (Regex.IsMatch(tmpStatus,
2164 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2165 RegexOptions.IgnoreCase)
2166 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2169 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2172 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2175 bool isCutOff = false;
2176 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2177 if (StatusText.Multiline && !SettingDialog.PostCtrlEnter)
2179 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2180 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2182 if (SettingDialog.PostShiftEnter)
2184 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2186 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2188 isRemoveFooter = true;
2190 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2192 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2195 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2196 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2198 isRemoveFooter = true;
2209 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2217 if (HashMgr.IsNotAddToAtReply)
2219 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2222 header = HashMgr.UseHash + " ";
2224 footer = " " + HashMgr.UseHash;
2229 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2232 header = HashMgr.UseHash + " ";
2234 footer = " " + HashMgr.UseHash;
2237 if (!isRemoveFooter)
2239 if (SettingDialog.UseRecommendStatus)
2241 footer += SettingDialog.RecommendStatusText;
2243 // テキストボックスに入力されている文字列を使用する
2244 footer += " " + SettingDialog.Status.Trim();
2247 args.status.status = header + StatusText.Text + footer;
2249 if (ToolStripMenuItemApiCommandEvasion.Checked)
2252 if (Regex.IsMatch(args.status.status,
2253 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2254 RegexOptions.IgnoreCase)
2255 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2258 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2261 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2262 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2265 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2267 // 文中の全角スペースを半角スペース1個にする
2268 args.status.status = args.status.status.Replace(" ", " ");
2271 if (isCutOff && args.status.status.Length > 140)
2273 args.status.status = args.status.status.Substring(0, 140);
2274 string AtId = @"(@|@)[a-z0-9_/]+$";
2275 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2276 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2277 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2278 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2281 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2282 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2284 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2287 args.status.inReplyToId = _reply_to_id;
2288 args.status.inReplyToName = _reply_to_name;
2289 if (ImageSelector.Visible)
2292 if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
2298 _reply_to_id = null;
2299 _reply_to_name = null;
2300 StatusText.Text = "";
2301 _history.Add(new PostingStatus());
2302 _hisIdx = _history.Count - 1;
2303 if (!ToolStripFocusLockMenuItem.Checked)
2304 ((Control)ListTab.SelectedTab.Tag).Focus();
2305 urlUndoBuffer = null;
2306 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2309 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2311 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2312 await this.OpenUriAsync(tmp);
2316 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2318 MyCommon._endingFlag = true;
2322 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2324 if (!SettingDialog.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2326 //_endingFlag=false:フォームの×ボタン
2328 this.Visible = false;
2332 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2333 _ignoreConfigSave = true;
2334 MyCommon._endingFlag = true;
2335 TimerTimeline.Enabled = false;
2336 TimerRefreshIcon.Enabled = false;
2340 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2342 this.Visible = true;
2343 if (this.WindowState == FormWindowState.Minimized)
2345 this.WindowState = FormWindowState.Normal;
2348 this.BringToFront();
2351 private static int errorCount = 0;
2353 private static bool CheckAccountValid()
2355 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2361 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2370 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2372 BackgroundWorker bw = (BackgroundWorker)sender;
2373 if (bw.CancellationPending || MyCommon._endingFlag)
2379 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2381 MyApplication.InitCulture();
2384 GetWorkerResult rslt = new GetWorkerResult();
2386 bool read = !SettingDialog.UnreadManage;
2387 if (_initial && SettingDialog.UnreadManage) read = SettingDialog.Readed;
2389 GetWorkerArg args = (GetWorkerArg)e.Argument;
2391 if (!CheckAccountValid())
2393 rslt.retMsg = "Auth error. Check your account";
2394 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2395 rslt.tName = args.tName;
2400 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2404 case MyCommon.WORKERTYPE.Timeline:
2405 case MyCommon.WORKERTYPE.Reply:
2406 bw.ReportProgress(50, MakeStatusMessage(args, false));
2407 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2409 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && SettingDialog.ReadOldPosts)
2410 _statuses.SetRead();
2412 rslt.addCount = _statuses.DistributePosts();
2414 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2415 bw.ReportProgress(50, MakeStatusMessage(args, false));
2416 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2417 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2418 rslt.addCount = _statuses.DistributePosts();
2421 case MyCommon.WORKERTYPE.FavAdd:
2425 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2427 for (int i = 0; i <= args.ids.Count - 1; i++)
2429 var post = tab.Posts[args.ids[i]];
2432 bw.ReportProgress(50, MakeStatusMessage(args, false));
2435 if (post.RetweetedId == null)
2436 ret = tw.PostFavAdd(post.StatusId);
2438 ret = tw.PostFavAdd(post.RetweetedId.Value);
2440 if (ret.Length == 0)
2442 args.sIds.Add(post.StatusId);
2443 post.IsFav = true; //リスト再描画必要
2444 _favTimestamps.Add(DateTime.Now);
2445 if (string.IsNullOrEmpty(post.RelTabName))
2447 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2448 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2452 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2453 if (_statuses.ContainsKey(post.StatusId))
2455 PostClass postTl = _statuses[post.StatusId];
2456 postTl.IsFav = true;
2457 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2460 //検索,リスト,UserTimeline,Relatedの各タブに反映
2461 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2463 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2469 rslt.sIds = args.sIds;
2473 case MyCommon.WORKERTYPE.FavRemove:
2477 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2479 for (int i = 0; i <= args.ids.Count - 1; i++)
2481 var post = tab.Posts[args.ids[i]];
2484 bw.ReportProgress(50, MakeStatusMessage(args, false));
2487 if (post.RetweetedId == null)
2488 ret = tw.PostFavRemove(post.StatusId);
2490 ret = tw.PostFavRemove(post.RetweetedId.Value);
2492 if (ret.Length == 0)
2494 args.sIds.Add(post.StatusId);
2495 post.IsFav = false; //リスト再描画必要
2496 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2497 //検索,リスト,UserTimeline,Relatedの各タブに反映
2498 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2500 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2506 rslt.sIds = args.sIds;
2510 case MyCommon.WORKERTYPE.PostMessage:
2511 bw.ReportProgress(200);
2512 if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
2514 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2518 var service = ImageSelector.GetService(args.status.imageService);
2521 service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
2524 catch (AggregateException ex)
2526 ret = ex.InnerException.Message;
2529 bw.ReportProgress(300);
2530 rslt.status = args.status;
2532 case MyCommon.WORKERTYPE.Retweet:
2533 bw.ReportProgress(200);
2534 for (int i = 0; i <= args.ids.Count - 1; i++)
2536 ret = tw.PostRetweet(args.ids[i], read);
2538 bw.ReportProgress(300);
2540 case MyCommon.WORKERTYPE.Follower:
2541 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2544 tw.RefreshFollowerIds();
2546 catch (WebApiException ex) { ret = ex.Message; }
2548 case MyCommon.WORKERTYPE.NoRetweetIds:
2551 tw.RefreshNoRetweetIds();
2553 catch (WebApiException ex) { ret = ex.Message; }
2555 case MyCommon.WORKERTYPE.Configuration:
2558 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2560 catch (WebApiException ex) { ret = ex.Message; }
2562 case MyCommon.WORKERTYPE.Favorites:
2563 bw.ReportProgress(50, MakeStatusMessage(args, false));
2564 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2565 rslt.addCount = _statuses.DistributePosts();
2567 case MyCommon.WORKERTYPE.PublicSearch:
2568 bw.ReportProgress(50, MakeStatusMessage(args, false));
2569 if (string.IsNullOrEmpty(args.tName))
2571 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2573 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2574 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2579 TabClass tb = _statuses.GetTabByName(args.tName);
2582 //ret = tw.GetPhoenixSearch(read, tb, false);
2583 ret = tw.GetSearch(read, tb, false);
2584 if (string.IsNullOrEmpty(ret) && args.page == -1)
2586 //ret = tw.GetPhoenixSearch(read, tb, true)
2587 ret = tw.GetSearch(read, tb, true);
2592 rslt.addCount = _statuses.DistributePosts();
2594 case MyCommon.WORKERTYPE.UserTimeline:
2595 bw.ReportProgress(50, MakeStatusMessage(args, false));
2597 if (SettingDialog.UseAdditionalCount) count = SettingDialog.UserTimelineCountApi;
2598 if (string.IsNullOrEmpty(args.tName))
2600 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2602 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2607 TabClass tb = _statuses.GetTabByName(args.tName);
2610 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2614 rslt.addCount = _statuses.DistributePosts();
2616 case MyCommon.WORKERTYPE.List:
2617 bw.ReportProgress(50, MakeStatusMessage(args, false));
2618 if (string.IsNullOrEmpty(args.tName))
2621 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2623 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2629 TabClass tb = _statuses.GetTabByName(args.tName);
2632 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2636 rslt.addCount = _statuses.DistributePosts();
2639 case MyCommon.WORKERTYPE.Related:
2641 bw.ReportProgress(50, MakeStatusMessage(args, false));
2642 TabClass tab = _statuses.GetTabByName(args.tName);
2643 ret = tw.GetRelatedResult(read, tab);
2644 rslt.addCount = _statuses.DistributePosts();
2648 case MyCommon.WORKERTYPE.BlockIds:
2649 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2652 tw.RefreshBlockIds();
2654 catch (WebApiException ex) { ret = ex.Message; }
2658 if (bw.CancellationPending)
2665 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2667 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2668 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2670 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2672 _favTimestamps.RemoveAt(i);
2676 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2680 DateTime tm = DateTime.Now;
2681 if (_tlTimestamps.ContainsKey(tm))
2682 _tlTimestamps[tm] += rslt.addCount;
2684 _tlTimestamps.Add(tm, rslt.addCount);
2686 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2687 List<DateTime> keys = new List<DateTime>();
2689 foreach (DateTime key in _tlTimestamps.Keys)
2691 if (key.CompareTo(oneHour) < 0)
2697 _tlCount += _tlTimestamps[key];
2700 foreach (DateTime key in keys)
2702 _tlTimestamps.Remove(key);
2709 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2712 rslt.type = args.type;
2713 rslt.tName = args.tName;
2714 if (args.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2715 args.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2716 args.type == MyCommon.WORKERTYPE.Reply ||
2717 args.type == MyCommon.WORKERTYPE.Timeline ||
2718 args.type == MyCommon.WORKERTYPE.Favorites)
2720 rslt.page = args.page - 1; //値が正しいか後でチェック。10ページ毎の継続確認
2726 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2732 switch (AsyncArg.type)
2734 case MyCommon.WORKERTYPE.Timeline:
2735 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2737 case MyCommon.WORKERTYPE.Reply:
2738 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2740 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2741 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2743 case MyCommon.WORKERTYPE.FavAdd:
2744 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2745 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2747 case MyCommon.WORKERTYPE.FavRemove:
2748 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2749 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2751 case MyCommon.WORKERTYPE.Favorites:
2752 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2754 case MyCommon.WORKERTYPE.PublicSearch:
2755 smsg = "Search refreshing...";
2757 case MyCommon.WORKERTYPE.List:
2758 smsg = "List refreshing...";
2760 case MyCommon.WORKERTYPE.Related:
2761 smsg = "Related refreshing...";
2763 case MyCommon.WORKERTYPE.UserTimeline:
2764 smsg = "UserTimeline refreshing...";
2771 switch (AsyncArg.type)
2773 case MyCommon.WORKERTYPE.Timeline:
2774 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2776 case MyCommon.WORKERTYPE.Reply:
2777 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2779 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2780 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2782 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2783 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2785 case MyCommon.WORKERTYPE.FavAdd:
2788 case MyCommon.WORKERTYPE.FavRemove:
2791 case MyCommon.WORKERTYPE.Favorites:
2792 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2794 case MyCommon.WORKERTYPE.Follower:
2795 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2797 case MyCommon.WORKERTYPE.NoRetweetIds:
2798 smsg = "NoRetweetIds refreshed";
2800 case MyCommon.WORKERTYPE.Configuration:
2803 case MyCommon.WORKERTYPE.PublicSearch:
2804 smsg = "Search refreshed";
2806 case MyCommon.WORKERTYPE.List:
2807 smsg = "List refreshed";
2809 case MyCommon.WORKERTYPE.Related:
2810 smsg = "Related refreshed";
2812 case MyCommon.WORKERTYPE.UserTimeline:
2813 smsg = "UserTimeline refreshed";
2815 case MyCommon.WORKERTYPE.BlockIds:
2816 smsg = Properties.Resources.UpdateBlockUserText3;
2823 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2825 if (MyCommon._endingFlag) return;
2826 if (e.ProgressPercentage > 100)
2829 if (e.ProgressPercentage == 200) //開始
2830 StatusLabel.Text = "Posting...";
2831 if (e.ProgressPercentage == 300) //終了
2832 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2836 string smsg = (string)e.UserState;
2837 if (smsg.Length > 0) StatusLabel.Text = smsg;
2841 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2843 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2845 if (e.Error != null)
2847 _myStatusError = true;
2848 _waitTimeline = false;
2852 _waitPubSearch = false;
2853 _waitUserTimeline = false;
2855 throw new Exception("BackgroundWorker Exception", e.Error);
2858 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2861 if (rslt.retMsg.Length > 0)
2863 _myStatusError = true;
2864 StatusLabel.Text = rslt.retMsg;
2867 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2869 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2871 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2875 //bool busy = false;
2876 //foreach (BackgroundWorker bw in _bw)
2878 // if (bw != null && bw.IsBusy)
2884 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2885 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2886 rslt.type == MyCommon.WORKERTYPE.Reply ||
2887 rslt.type == MyCommon.WORKERTYPE.List ||
2888 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2889 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2890 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2891 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2892 rslt.type == MyCommon.WORKERTYPE.Follower ||
2893 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2894 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2895 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2896 rslt.type == MyCommon.WORKERTYPE.Related ||
2897 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2898 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2899 rslt.type == MyCommon.WORKERTYPE.Configuration)
2901 RefreshTimeline(false); //リスト反映
2906 case MyCommon.WORKERTYPE.Timeline:
2907 _waitTimeline = false;
2910 // //API使用時の取得調整は別途考える(カウント調整?)
2913 case MyCommon.WORKERTYPE.Reply:
2915 if (rslt.newDM && !_initial)
2917 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
2920 case MyCommon.WORKERTYPE.Favorites:
2923 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2926 case MyCommon.WORKERTYPE.FavAdd:
2927 case MyCommon.WORKERTYPE.FavRemove:
2928 if (_curList != null && _curTab != null)
2930 using (ControlTransaction.Update(this._curList))
2932 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
2938 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
2940 if (_curTab.Text.Equals(rslt.tName))
2942 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
2945 PostClass post = null;
2946 TabClass tb = _statuses.Tabs[rslt.tName];
2949 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
2951 post = tb.Posts[rslt.sIds[i]];
2955 post = _statuses[rslt.sIds[i]];
2957 ChangeCacheStyleRead(post.IsRead, idx);
2959 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
2967 case MyCommon.WORKERTYPE.PostMessage:
2968 if (string.IsNullOrEmpty(rslt.retMsg) ||
2969 rslt.retMsg.StartsWith("OK:") ||
2970 rslt.retMsg == "Warn:Status is a duplicate.")
2972 _postTimestamps.Add(DateTime.Now);
2973 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2974 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2976 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2978 _postTimestamps.RemoveAt(i);
2982 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
2984 HashMgr.ClearHashtag();
2985 this.HashStripSplitButton.Text = "#[-]";
2986 this.HashToggleMenuItem.Checked = false;
2987 this.HashToggleToolStripMenuItem.Checked = false;
2989 SetMainWindowTitle();
2997 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
2998 Properties.Resources.StatusUpdateFailed1,
2999 Properties.Resources.StatusUpdateFailed2),
3000 "Failed to update status",
3001 MessageBoxButtons.RetryCancel,
3002 MessageBoxIcon.Question);
3006 retry = DialogResult.Abort;
3008 if (retry == DialogResult.Retry)
3010 GetWorkerArg args = new GetWorkerArg();
3013 args.type = MyCommon.WORKERTYPE.PostMessage;
3014 args.status = rslt.status;
3019 if (ToolStripFocusLockMenuItem.Checked)
3021 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
3022 StatusText_Enter(StatusText, new EventArgs());
3026 if (rslt.retMsg.Length == 0 && SettingDialog.PostAndGet)
3028 if (_isActiveUserstream)
3030 RefreshTimeline(true);
3034 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3038 case MyCommon.WORKERTYPE.Retweet:
3039 if (rslt.retMsg.Length == 0)
3041 _postTimestamps.Add(DateTime.Now);
3042 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3043 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3045 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3047 _postTimestamps.RemoveAt(i);
3050 if (!_isActiveUserstream && SettingDialog.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3053 case MyCommon.WORKERTYPE.Follower:
3054 //_waitFollower = false;
3055 this.PurgeListViewItemCache();
3056 if (_curList != null) _curList.Refresh();
3058 case MyCommon.WORKERTYPE.NoRetweetIds:
3060 case MyCommon.WORKERTYPE.Configuration:
3061 //_waitFollower = false
3062 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
3064 foreach (var service in this.ImageSelector.GetServices())
3066 service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
3069 this.PurgeListViewItemCache();
3070 if (_curList != null) _curList.Refresh();
3072 case MyCommon.WORKERTYPE.PublicSearch:
3073 _waitPubSearch = false;
3075 case MyCommon.WORKERTYPE.UserTimeline:
3076 _waitUserTimeline = false;
3078 case MyCommon.WORKERTYPE.List:
3081 case MyCommon.WORKERTYPE.Related:
3082 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
3083 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
3085 foreach (TabPage tp in ListTab.TabPages)
3087 if (tp.Text == tab.TabName)
3089 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
3090 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3099 private async Task RefreshMuteUserIdsAsync()
3101 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
3105 await tw.RefreshMuteUserIdsAsync();
3107 catch (WebApiException ex)
3109 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
3113 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
3116 private void RemovePostFromFavTab(Int64[] ids)
3118 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3120 if (_curTab.Text.Equals(favTabName))
3122 if (_curList.FocusedItem != null)
3123 fidx = _curList.FocusedItem.Index;
3124 else if (_curList.TopItem != null)
3125 fidx = _curList.TopItem.Index;
3130 foreach (long i in ids)
3134 _statuses.RemoveFavPost(i);
3141 if (_curTab != null && _curTab.Text.Equals(favTabName))
3143 this.PurgeListViewItemCache();
3145 //_curItemIndex = -1;
3147 foreach (TabPage tp in ListTab.TabPages)
3149 if (tp.Text == favTabName)
3151 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3155 if (_curTab.Text.Equals(favTabName))
3159 _curList.SelectedIndices.Clear();
3161 while (_curList.SelectedIndices.Count > 0);
3163 if (_statuses.Tabs[favTabName].AllCount > 0)
3165 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3167 _curList.SelectedIndices.Add(fidx);
3171 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3173 if (_curList.SelectedIndices.Count > 0)
3175 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3176 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3182 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3184 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, int toPage, string tabName)
3186 if (!this.IsNetworkAvailable()) return;
3189 GetWorkerArg args = new GetWorkerArg();
3190 args.page = fromPage;
3191 args.endPage = toPage;
3193 args.tName = tabName;
3195 if (!lastTime.ContainsKey(WkType)) lastTime.Add(WkType, new DateTime());
3196 double period = DateTime.Now.Subtract(lastTime[WkType]).TotalSeconds;
3197 if (period > 1 || period < -1)
3199 lastTime[WkType] = DateTime.Now;
3203 //Timeline取得モードの場合はReplyも同時に取得
3204 //if (!SettingDialog.UseAPI &&
3206 // WkType == MyCommon.WORKERTYPE.Timeline &&
3207 // SettingDialog.CheckReply)
3209 // //TimerReply.Enabled = false;
3210 // _mentionCounter = SettingDialog.ReplyPeriodInt;
3211 // GetWorkerArg _args = new GetWorkerArg();
3212 // _args.page = fromPage;
3213 // _args.endPage = toPage;
3214 // _args.type = MyCommon.WORKERTYPE.Reply;
3219 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
3221 if (e.Button == MouseButtons.Left)
3223 this.Visible = true;
3224 if (this.WindowState == FormWindowState.Minimized)
3226 this.WindowState = _formWindowState;
3229 this.BringToFront();
3233 private void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
3235 switch (SettingDialog.ListDoubleClickAction)
3238 MakeReplyOrDirectStatus();
3241 FavoriteChange(true);
3244 if (_curPost != null)
3245 ShowUserStatus(_curPost.ScreenName, false);
3251 ShowRelatedStatusesMenuItem_Click(null, null);
3254 MoveToHomeToolStripMenuItem_Click(null, null);
3257 StatusOpenMenuItem_Click(null, null);
3265 private void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
3267 FavoriteChange(true);
3270 private void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
3272 FavoriteChange(false);
3276 private void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
3278 FavoritesRetweetOriginal();
3281 private void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
3283 FavoritesRetweetUnofficial();
3286 private void FavoriteChange(bool FavAdd , bool multiFavoriteChangeDialogEnable = true)
3288 //trueでFavAdd,falseでFavRemove
3289 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || _curList.SelectedIndices.Count == 0
3290 || !this.ExistCurrentPost) return;
3293 if (_curList.SelectedIndices.Count > 250 && FavAdd)
3295 MessageBox.Show(Properties.Resources.FavoriteLimitCountText);
3296 _DoFavRetweetFlags = false;
3299 else if (multiFavoriteChangeDialogEnable && _curList.SelectedIndices.Count > 1)
3303 string QuestionText = Properties.Resources.FavAddToolStripMenuItem_ClickText1;
3304 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText3;
3305 if (MessageBox.Show(QuestionText, Properties.Resources.FavAddToolStripMenuItem_ClickText2,
3306 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3308 _DoFavRetweetFlags = false;
3314 if (MessageBox.Show(Properties.Resources.FavRemoveToolStripMenuItem_ClickText1, Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
3315 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3322 GetWorkerArg args = new GetWorkerArg();
3323 args.ids = new List<long>();
3324 args.sIds = new List<long>();
3325 args.tName = _curTab.Text;
3328 args.type = MyCommon.WORKERTYPE.FavAdd;
3332 args.type = MyCommon.WORKERTYPE.FavRemove;
3334 foreach (int idx in _curList.SelectedIndices)
3336 PostClass post = GetCurTabPost(idx);
3339 if (!post.IsFav) args.ids.Add(post.StatusId);
3343 if (post.IsFav) args.ids.Add(post.StatusId);
3346 if (args.ids.Count == 0)
3349 StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
3351 StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
3359 private PostClass GetCurTabPost(int Index)
3361 this.itemCacheLock.EnterReadLock();
3364 if (_postCache != null && Index >= _itemCacheIndex && Index < _itemCacheIndex + _postCache.Length)
3365 return _postCache[Index - _itemCacheIndex];
3367 finally { this.itemCacheLock.ExitReadLock(); }
3369 return _statuses[_curTab.Text, Index];
3373 private void MoveToHomeToolStripMenuItem_Click(object sender, EventArgs e)
3375 if (_curList.SelectedIndices.Count > 0)
3376 OpenUriAsync(MyCommon.TwitterUrl + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName);
3377 else if (_curList.SelectedIndices.Count == 0)
3378 OpenUriAsync(MyCommon.TwitterUrl);
3381 private void MoveToFavToolStripMenuItem_Click(object sender, EventArgs e)
3383 if (_curList.SelectedIndices.Count > 0)
3384 OpenUriAsync(MyCommon.TwitterUrl + "#!/" + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName + "/favorites");
3387 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3389 if ((!_initialLayout) && this.Visible)
3391 if (this.WindowState == FormWindowState.Normal)
3393 _mySize = this.ClientSize;
3394 _mySpDis = this.SplitContainer1.SplitterDistance;
3395 _mySpDis3 = this.SplitContainer3.SplitterDistance;
3396 if (StatusText.Multiline) _mySpDis2 = this.StatusText.Height;
3397 _modifySettingLocal = true;
3402 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3404 if (SettingDialog.SortOrderLock) return;
3405 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
3408 mode = IdComparerClass.ComparerMode.Id;
3416 case 6: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
3420 mode = IdComparerClass.ComparerMode.Nickname;
3423 mode = IdComparerClass.ComparerMode.Data;
3426 mode = IdComparerClass.ComparerMode.Id;
3429 mode = IdComparerClass.ComparerMode.Name;
3432 mode = IdComparerClass.ComparerMode.Source;
3436 _statuses.ToggleSortOrder(mode);
3439 DetailsListView list = (DetailsListView)sender;
3442 list.Columns[0].Text = ColumnOrgText[0];
3443 list.Columns[1].Text = ColumnText[2];
3447 for (int i = 0; i <= 7; i++)
3449 list.Columns[i].Text = ColumnOrgText[i];
3451 list.Columns[e.Column].Text = ColumnText[e.Column];
3454 this.PurgeListViewItemCache();
3456 if (_statuses.Tabs[_curTab.Text].AllCount > 0 && _curPost != null)
3458 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_curPost.StatusId);
3461 SelectListItem(_curList, idx);
3462 _curList.EnsureVisible(idx);
3466 _modifySettingCommon = true;
3469 private void TweenMain_LocationChanged(object sender, EventArgs e)
3471 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
3473 _myLoc = this.DesktopLocation;
3474 _modifySettingLocal = true;
3478 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3480 if (ListTab.SelectedTab == null) return;
3481 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
3482 if (!this.ExistCurrentPost)
3484 ReplyStripMenuItem.Enabled = false;
3485 ReplyAllStripMenuItem.Enabled = false;
3486 DMStripMenuItem.Enabled = false;
3487 ShowProfileMenuItem.Enabled = false;
3488 ShowUserTimelineContextMenuItem.Enabled = false;
3489 ListManageUserContextToolStripMenuItem2.Enabled = false;
3490 MoveToFavToolStripMenuItem.Enabled = false;
3491 TabMenuItem.Enabled = false;
3492 IDRuleMenuItem.Enabled = false;
3493 ReadedStripMenuItem.Enabled = false;
3494 UnreadStripMenuItem.Enabled = false;
3498 ShowProfileMenuItem.Enabled = true;
3499 ListManageUserContextToolStripMenuItem2.Enabled = true;
3500 ReplyStripMenuItem.Enabled = true;
3501 ReplyAllStripMenuItem.Enabled = true;
3502 DMStripMenuItem.Enabled = true;
3503 ShowUserTimelineContextMenuItem.Enabled = true;
3504 MoveToFavToolStripMenuItem.Enabled = true;
3505 TabMenuItem.Enabled = true;
3506 IDRuleMenuItem.Enabled = true;
3507 ReadedStripMenuItem.Enabled = true;
3508 UnreadStripMenuItem.Enabled = true;
3510 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3511 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
3513 FavAddToolStripMenuItem.Enabled = false;
3514 FavRemoveToolStripMenuItem.Enabled = false;
3515 StatusOpenMenuItem.Enabled = false;
3516 FavorareMenuItem.Enabled = false;
3517 ShowRelatedStatusesMenuItem.Enabled = false;
3519 ReTweetStripMenuItem.Enabled = false;
3520 ReTweetOriginalStripMenuItem.Enabled = false;
3521 QuoteStripMenuItem.Enabled = false;
3522 FavoriteRetweetContextMenu.Enabled = false;
3523 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3524 if (this.ExistCurrentPost && _curPost.IsDm)
3525 DeleteStripMenuItem.Enabled = true;
3527 DeleteStripMenuItem.Enabled = false;
3531 FavAddToolStripMenuItem.Enabled = true;
3532 FavRemoveToolStripMenuItem.Enabled = true;
3533 StatusOpenMenuItem.Enabled = true;
3534 FavorareMenuItem.Enabled = true;
3535 ShowRelatedStatusesMenuItem.Enabled = true; //PublicSearchの時問題出るかも
3539 ReTweetOriginalStripMenuItem.Enabled = false;
3540 FavoriteRetweetContextMenu.Enabled = false;
3541 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3543 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3547 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3549 DeleteStripMenuItem.Enabled = true;
3553 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3555 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3559 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3561 DeleteStripMenuItem.Enabled = false;
3562 if (_curPost.IsProtect)
3564 ReTweetOriginalStripMenuItem.Enabled = false;
3565 ReTweetStripMenuItem.Enabled = false;
3566 QuoteStripMenuItem.Enabled = false;
3567 FavoriteRetweetContextMenu.Enabled = false;
3568 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3572 ReTweetOriginalStripMenuItem.Enabled = true;
3573 ReTweetStripMenuItem.Enabled = true;
3574 QuoteStripMenuItem.Enabled = true;
3575 FavoriteRetweetContextMenu.Enabled = true;
3576 FavoriteRetweetUnofficialContextMenu.Enabled = true;
3580 //if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
3582 // RefreshMoreStripMenuItem.Enabled = true;
3586 // RefreshMoreStripMenuItem.Enabled = false;
3588 if (!this.ExistCurrentPost
3589 || _curPost.InReplyToStatusId == null)
3591 RepliedStatusOpenMenuItem.Enabled = false;
3595 RepliedStatusOpenMenuItem.Enabled = true;
3597 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
3599 MoveToRTHomeMenuItem.Enabled = false;
3603 MoveToRTHomeMenuItem.Enabled = true;
3607 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3609 MakeReplyOrDirectStatus(false, true);
3612 private void DMStripMenuItem_Click(object sender, EventArgs e)
3614 MakeReplyOrDirectStatus(false, false);
3617 private void doStatusDelete()
3619 if (_curTab == null || _curList == null) return;
3620 if (_statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
3622 bool myPost = false;
3623 foreach (int idx in _curList.SelectedIndices)
3625 if (GetCurTabPost(idx).IsMe ||
3626 GetCurTabPost(idx).RetweetedBy.ToLower() == tw.Username.ToLower())
3632 if (!myPost) return;
3636 if (_curList.SelectedIndices.Count == 0)
3640 string tmp = string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine);
3642 if (MessageBox.Show(tmp, Properties.Resources.DeleteStripMenuItem_ClickText2,
3643 MessageBoxButtons.OKCancel,
3644 MessageBoxIcon.Question) == DialogResult.Cancel) return;
3647 if (_curList.FocusedItem != null)
3648 fidx = _curList.FocusedItem.Index;
3649 else if (_curList.TopItem != null)
3650 fidx = _curList.TopItem.Index;
3656 this.Cursor = Cursors.WaitCursor;
3659 foreach (long Id in _statuses.GetId(_curTab.Text, _curList.SelectedIndices))
3662 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
3664 rtn = tw.RemoveDirectMessage(Id, _statuses[Id]);
3668 if (_statuses[Id].IsMe || _statuses[Id].RetweetedBy.ToLower() == tw.Username.ToLower())
3669 rtn = tw.RemoveStatus(Id);
3680 _statuses.RemovePost(Id);
3685 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; //失敗
3687 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; //成功
3689 this.PurgeListViewItemCache();
3692 foreach (TabPage tb in ListTab.TabPages)
3694 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
3695 if (_curTab.Equals(tb))
3699 _curList.SelectedIndices.Clear();
3701 while (_curList.SelectedIndices.Count > 0);
3703 if (_statuses.Tabs[tb.Text].AllCount > 0)
3705 if (_statuses.Tabs[tb.Text].AllCount - 1 > fidx && fidx > -1)
3706 _curList.SelectedIndices.Add(fidx);
3708 _curList.SelectedIndices.Add(_statuses.Tabs[tb.Text].AllCount - 1);
3710 if (_curList.SelectedIndices.Count > 0)
3712 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3713 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3717 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3719 if (SettingDialog.TabIconDisp)
3721 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3725 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3729 this.Cursor = Cursors.Default;
3733 private void DeleteStripMenuItem_Click(object sender, EventArgs e)
3738 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3740 using (ControlTransaction.Update(this._curList))
3742 if (SettingDialog.UnreadManage)
3744 foreach (int idx in _curList.SelectedIndices)
3746 _statuses.SetReadAllTab(true, _curTab.Text, idx);
3749 foreach (int idx in _curList.SelectedIndices)
3751 ChangeCacheStyleRead(true, idx);
3755 foreach (TabPage tb in ListTab.TabPages)
3757 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3759 if (SettingDialog.TabIconDisp)
3761 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3765 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3768 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3770 using (ControlTransaction.Update(this._curList))
3772 if (SettingDialog.UnreadManage)
3774 foreach (int idx in _curList.SelectedIndices)
3776 _statuses.SetReadAllTab(false, _curTab.Text, idx);
3779 foreach (int idx in _curList.SelectedIndices)
3781 ChangeCacheStyleRead(false, idx);
3785 foreach (TabPage tb in ListTab.TabPages)
3787 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
3789 if (SettingDialog.TabIconDisp)
3791 if (tb.ImageIndex == -1) tb.ImageIndex = 0; //タブアイコン
3795 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3798 private void RefreshStripMenuItem_Click(object sender, EventArgs e)
3803 private void DoRefresh()
3805 if (_curTab != null)
3807 switch (_statuses.Tabs[_curTab.Text].TabType)
3809 case MyCommon.TabUsageType.Mentions:
3810 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
3812 case MyCommon.TabUsageType.DirectMessage:
3813 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
3815 case MyCommon.TabUsageType.Favorites:
3816 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, 0, "");
3818 //case MyCommon.TabUsageType.Profile:
3820 case MyCommon.TabUsageType.PublicSearch:
3822 TabClass tb = _statuses.Tabs[_curTab.Text];
3823 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3824 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, _curTab.Text);
3826 case MyCommon.TabUsageType.UserTimeline:
3827 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, _curTab.Text);
3829 case MyCommon.TabUsageType.Lists:
3831 TabClass tab = _statuses.Tabs[_curTab.Text];
3832 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3833 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, _curTab.Text);
3836 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3842 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 0, "");
3846 private void DoRefreshMore()
3849 if (_curTab != null)
3851 switch (_statuses.Tabs[_curTab.Text].TabType)
3853 case MyCommon.TabUsageType.Mentions:
3854 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, 0, "");
3856 case MyCommon.TabUsageType.DirectMessage:
3857 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, 0, "");
3859 case MyCommon.TabUsageType.Favorites:
3860 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, 0, "");
3862 case MyCommon.TabUsageType.Profile:
3865 case MyCommon.TabUsageType.PublicSearch:
3867 TabClass tb = _statuses.Tabs[_curTab.Text];
3868 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3869 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, -1, 0, _curTab.Text);
3871 case MyCommon.TabUsageType.UserTimeline:
3872 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, 0, _curTab.Text);
3874 case MyCommon.TabUsageType.Lists:
3876 TabClass tab = _statuses.Tabs[_curTab.Text];
3877 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3878 GetTimeline(MyCommon.WORKERTYPE.List, -1, 0, _curTab.Text);
3881 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, 0, "");
3887 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, 0, "");
3891 private void SettingStripMenuItem_Click(object sender, EventArgs e)
3893 DialogResult result;
3894 string uid = tw.Username.ToLower();
3895 var oldIconSz = SettingDialog.IconSz;
3899 result = SettingDialog.ShowDialog(this);
3906 if (result == DialogResult.OK)
3910 tw.TinyUrlResolve = SettingDialog.TinyUrlResolve;
3911 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
3912 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
3913 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
3914 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
3915 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
3916 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3918 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
3919 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
3920 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
3921 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
3923 ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
3927 if (SettingDialog.TabIconDisp)
3929 ListTab.DrawItem -= ListTab_DrawItem;
3930 ListTab.DrawMode = TabDrawMode.Normal;
3931 ListTab.ImageList = this.TabImage;
3935 ListTab.DrawItem -= ListTab_DrawItem;
3936 ListTab.DrawItem += ListTab_DrawItem;
3937 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3938 ListTab.ImageList = null;
3941 catch (Exception ex)
3943 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3944 ex.Data["IsTerminatePermission"] = false;
3950 if (!SettingDialog.UnreadManage)
3952 ReadedStripMenuItem.Enabled = false;
3953 UnreadStripMenuItem.Enabled = false;
3954 if (SettingDialog.TabIconDisp)
3956 foreach (TabPage myTab in ListTab.TabPages)
3958 myTab.ImageIndex = -1;
3964 ReadedStripMenuItem.Enabled = true;
3965 UnreadStripMenuItem.Enabled = true;
3968 catch (Exception ex)
3970 ex.Data["Instance"] = "ListTab(UnreadManage)";
3971 ex.Data["IsTerminatePermission"] = false;
3978 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
3980 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3981 imgazyobizinet.Enabled = this.SettingDialog.EnableImgAzyobuziNet;
3982 imgazyobizinet.DisabledInDM = this.SettingDialog.ImgAzyobuziNetDisabledInDM;
3984 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
3985 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
3986 _fntUnread = SettingDialog.FontUnread;
3987 _clUnread = SettingDialog.ColorUnread;
3988 _fntReaded = SettingDialog.FontReaded;
3989 _clReaded = SettingDialog.ColorReaded;
3990 _clFav = SettingDialog.ColorFav;
3991 _clOWL = SettingDialog.ColorOWL;
3992 _clRetweet = SettingDialog.ColorRetweet;
3993 _fntDetail = SettingDialog.FontDetail;
3994 _clDetail = SettingDialog.ColorDetail;
3995 _clDetailLink = SettingDialog.ColorDetailLink;
3996 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
3997 _clSelf = SettingDialog.ColorSelf;
3998 _clAtSelf = SettingDialog.ColorAtSelf;
3999 _clTarget = SettingDialog.ColorTarget;
4000 _clAtTarget = SettingDialog.ColorAtTarget;
4001 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
4002 _clAtTo = SettingDialog.ColorAtTo;
4003 _clListBackcolor = SettingDialog.ColorListBackcolor;
4004 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
4005 _clInputFont = SettingDialog.ColorInputFont;
4006 _fntInputFont = SettingDialog.FontInputFont;
4007 _brsBackColorMine.Dispose();
4008 _brsBackColorAt.Dispose();
4009 _brsBackColorYou.Dispose();
4010 _brsBackColorAtYou.Dispose();
4011 _brsBackColorAtFromTarget.Dispose();
4012 _brsBackColorAtTo.Dispose();
4013 _brsBackColorNone.Dispose();
4014 _brsBackColorMine = new SolidBrush(_clSelf);
4015 _brsBackColorAt = new SolidBrush(_clAtSelf);
4016 _brsBackColorYou = new SolidBrush(_clTarget);
4017 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
4018 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
4019 _brsBackColorAtTo = new SolidBrush(_clAtTo);
4020 _brsBackColorNone = new SolidBrush(_clListBackcolor);
4024 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
4025 StatusText.Font = _fntInputFont;
4026 StatusText.ForeColor = _clInputFont;
4028 catch (Exception ex)
4030 MessageBox.Show(ex.Message);
4035 InitDetailHtmlFormat();
4037 catch (Exception ex)
4039 ex.Data["Instance"] = "Font";
4040 ex.Data["IsTerminatePermission"] = false;
4046 _statuses.SetUnreadManage(SettingDialog.UnreadManage);
4048 catch (Exception ex)
4050 ex.Data["Instance"] = "_statuses";
4051 ex.Data["IsTerminatePermission"] = false;
4057 foreach (TabPage tb in ListTab.TabPages)
4059 if (SettingDialog.TabIconDisp)
4061 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
4068 catch (Exception ex)
4070 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
4071 ex.Data["IsTerminatePermission"] = false;
4077 var oldIconCol = _iconCol;
4079 if (SettingDialog.IconSz != oldIconSz)
4080 ApplyListViewIconSize(SettingDialog.IconSz);
4082 foreach (TabPage tp in ListTab.TabPages)
4084 DetailsListView lst = (DetailsListView)tp.Tag;
4086 using (ControlTransaction.Update(lst))
4088 lst.GridLines = SettingDialog.ShowGrid;
4089 lst.Font = _fntReaded;
4090 lst.BackColor = _clListBackcolor;
4092 if (_iconCol != oldIconCol)
4097 catch (Exception ex)
4099 ex.Data["Instance"] = "ListView(IconSize)";
4100 ex.Data["IsTerminatePermission"] = false;
4104 SetMainWindowTitle();
4105 SetNotifyIconText();
4107 this.PurgeListViewItemCache();
4108 if (_curList != null) _curList.Refresh();
4111 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4112 if (SettingDialog.HotkeyEnabled)
4114 ///グローバルホットキーの登録。設定で変更可能にするかも
4115 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4116 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
4117 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
4118 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
4119 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
4121 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
4124 if (uid != tw.Username) this.doGetFollowersMenu();
4126 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
4129 StatusText_TextChanged(null, null);
4137 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4139 this.TopMost = SettingDialog.AlwaysTop;
4140 SaveConfigsAll(false);
4146 private void SetTabAlignment()
4148 var newAlignment = SettingDialog.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
4149 if (ListTab.Alignment == newAlignment) return;
4152 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
4153 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
4154 SaveSelectedStatus(selId, focusedId);
4156 ListTab.Alignment = newAlignment;
4159 foreach (TabPage tab in ListTab.TabPages)
4161 DetailsListView lst = (DetailsListView)tab.Tag;
4162 TabClass tabInfo = _statuses.Tabs[tab.Text];
4163 using (ControlTransaction.Update(lst))
4165 this.SelectListItem(lst,
4166 tabInfo.IndexOf(selId[tab.Text]),
4167 tabInfo.IndexOf(focusedId[tab.Text]));
4172 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
4178 case MyCommon.IconSizes.IconNone:
4181 case MyCommon.IconSizes.Icon16:
4184 case MyCommon.IconSizes.Icon24:
4187 case MyCommon.IconSizes.Icon48:
4190 case MyCommon.IconSizes.Icon48_2:
4198 // ディスプレイの DPI 設定を考慮したサイズを設定する
4199 _listViewImageList.ImageSize = new Size(
4201 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4205 _listViewImageList.ImageSize = new Size(1, 1);
4209 private void ResetColumns(DetailsListView list)
4211 using (ControlTransaction.Update(list))
4212 using (ControlTransaction.Layout(list, false))
4215 list.ColumnClick -= MyList_ColumnClick;
4216 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4217 list.ColumnReordered -= MyList_ColumnReordered;
4218 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4220 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4221 list.Columns.Clear();
4222 cols.ForEach(col => col.Dispose());
4225 InitColumns(list, true);
4227 list.ColumnClick += MyList_ColumnClick;
4228 list.DrawColumnHeader += MyList_DrawColumnHeader;
4229 list.ColumnReordered += MyList_ColumnReordered;
4230 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4234 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4236 if (e.Url.AbsoluteUri != "about:blank")
4239 OpenUriAsync(e.Url.OriginalString);
4243 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4245 if (e.Url.Scheme == "data")
4247 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4249 else if (e.Url.AbsoluteUri != "about:blank")
4253 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4254 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4257 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4258 int i = urlStr.IndexOf('#');
4259 if (i == -1) return;
4261 string hash = urlStr.Substring(i);
4262 HashSupl.AddItem(hash);
4263 HashMgr.AddHashToHistory(hash.Trim(), false);
4264 AddNewTabForSearch(hash);
4269 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4270 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4272 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4273 if (SettingDialog.OpenUserTimeline)
4275 if (MyCommon.IsKeyDown(Keys.Control))
4276 OpenUriAsync(e.Url.OriginalString);
4278 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4282 if (MyCommon.IsKeyDown(Keys.Control))
4283 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4285 OpenUriAsync(e.Url.OriginalString);
4290 OpenUriAsync(e.Url.OriginalString);
4296 public void AddNewTabForSearch(string searchWord)
4298 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4299 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4301 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4303 foreach (TabPage tp in ListTab.TabPages)
4305 if (tb.TabName == tp.Text)
4307 ListTab.SelectedTab = tp;
4314 string tabName = searchWord;
4315 for (int i = 0; i <= 100; i++)
4317 if (_statuses.ContainsTab(tabName))
4323 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4324 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4326 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4328 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4329 cmb.Items.Add(searchWord);
4330 cmb.Text = searchWord;
4333 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4336 private void ShowUserTimeline()
4338 if (!this.ExistCurrentPost) return;
4339 AddNewTabForUserTimeline(_curPost.ScreenName);
4342 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4344 if (e.KeyCode == Keys.Escape)
4346 TabPage relTp = ListTab.SelectedTab;
4347 RemoveSpecifiedTab(relTp.Text, false);
4349 e.SuppressKeyPress = true;
4353 public void AddNewTabForUserTimeline(string user)
4355 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4356 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4358 if (tb.User == user)
4360 foreach (TabPage tp in ListTab.TabPages)
4362 if (tb.TabName == tp.Text)
4364 ListTab.SelectedTab = tp;
4371 string tabName = "user:" + user;
4372 while (_statuses.ContainsTab(tabName))
4377 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4378 _statuses.Tabs[tabName].User = user;
4379 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4381 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4385 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, tabName);
4388 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4391 foreach (TabPage tb in ListTab.TabPages)
4393 if (tb.Text == tabName) return false;
4397 if (tabName == Properties.Resources.AddNewTabText1) return false;
4402 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4403 tabType == MyCommon.TabUsageType.Favorites ||
4404 tabType == MyCommon.TabUsageType.Home ||
4405 tabType == MyCommon.TabUsageType.Mentions ||
4406 tabType == MyCommon.TabUsageType.Related)
4408 if (_statuses.GetTabByType(tabType) != null) return false;
4412 TabPage _tabPage = new TabPage();
4413 DetailsListView _listCustom = new DetailsListView();
4415 int cnt = ListTab.TabPages.Count;
4417 ///ToDo:Create and set controls follow tabtypes
4419 using (ControlTransaction.Update(_listCustom))
4420 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4421 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4422 using (ControlTransaction.Layout(this.SplitContainer1, false))
4423 using (ControlTransaction.Layout(this.ListTab, false))
4424 using (ControlTransaction.Layout(this))
4425 using (ControlTransaction.Layout(_tabPage, false))
4429 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4431 label = new Label();
4432 label.Dock = DockStyle.Top;
4433 label.Name = "labelUser";
4434 if (tabType == MyCommon.TabUsageType.Lists)
4436 label.Text = listInfo.ToString();
4440 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4442 label.TextAlign = ContentAlignment.MiddleLeft;
4443 using (ComboBox tmpComboBox = new ComboBox())
4445 label.Height = tmpComboBox.Height;
4447 _tabPage.Controls.Add(label);
4452 if (tabType == MyCommon.TabUsageType.PublicSearch)
4456 Label lbl = new Label();
4457 ComboBox cmb = new ComboBox();
4458 Button btn = new Button();
4459 ComboBox cmbLang = new ComboBox();
4461 pnl.SuspendLayout();
4463 pnl.Controls.Add(cmb);
4464 pnl.Controls.Add(cmbLang);
4465 pnl.Controls.Add(btn);
4466 pnl.Controls.Add(lbl);
4467 pnl.Name = "panelSearch";
4468 pnl.Dock = DockStyle.Top;
4469 pnl.Height = cmb.Height;
4470 pnl.Enter += SearchControls_Enter;
4471 pnl.Leave += SearchControls_Leave;
4474 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4475 cmb.Dock = DockStyle.Fill;
4476 cmb.Name = "comboSearch";
4477 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4478 cmb.ImeMode = ImeMode.NoControl;
4479 cmb.TabStop = false;
4480 cmb.AutoCompleteMode = AutoCompleteMode.None;
4481 cmb.KeyDown += SearchComboBox_KeyDown;
4483 if (_statuses.ContainsTab(tabName))
4485 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4486 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4490 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4491 cmbLang.Dock = DockStyle.Right;
4493 cmbLang.Name = "comboLang";
4494 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4495 cmbLang.TabStop = false;
4496 cmbLang.Items.Add("");
4497 cmbLang.Items.Add("ja");
4498 cmbLang.Items.Add("en");
4499 cmbLang.Items.Add("ar");
4500 cmbLang.Items.Add("da");
4501 cmbLang.Items.Add("nl");
4502 cmbLang.Items.Add("fa");
4503 cmbLang.Items.Add("fi");
4504 cmbLang.Items.Add("fr");
4505 cmbLang.Items.Add("de");
4506 cmbLang.Items.Add("hu");
4507 cmbLang.Items.Add("is");
4508 cmbLang.Items.Add("it");
4509 cmbLang.Items.Add("no");
4510 cmbLang.Items.Add("pl");
4511 cmbLang.Items.Add("pt");
4512 cmbLang.Items.Add("ru");
4513 cmbLang.Items.Add("es");
4514 cmbLang.Items.Add("sv");
4515 cmbLang.Items.Add("th");
4516 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4518 lbl.Text = "Search(C-S-f)";
4519 lbl.Name = "label1";
4520 lbl.Dock = DockStyle.Left;
4522 lbl.Height = cmb.Height;
4523 lbl.TextAlign = ContentAlignment.MiddleLeft;
4525 btn.Text = "Search";
4526 btn.Name = "buttonSearch";
4527 btn.UseVisualStyleBackColor = true;
4528 btn.Dock = DockStyle.Right;
4529 btn.TabStop = false;
4530 btn.Click += SearchButton_Click;
4533 this.ListTab.Controls.Add(_tabPage);
4534 _tabPage.Controls.Add(_listCustom);
4536 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4537 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4539 _tabPage.Location = new Point(4, 4);
4540 _tabPage.Name = "CTab" + cnt.ToString();
4541 _tabPage.Size = new Size(380, 260);
4542 _tabPage.TabIndex = 2 + cnt;
4543 _tabPage.Text = tabName;
4544 _tabPage.UseVisualStyleBackColor = true;
4546 _listCustom.AllowColumnReorder = true;
4547 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4548 _listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4549 _listCustom.Dock = DockStyle.Fill;
4550 _listCustom.FullRowSelect = true;
4551 _listCustom.HideSelection = false;
4552 _listCustom.Location = new Point(0, 0);
4553 _listCustom.Margin = new Padding(0);
4554 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4555 _listCustom.ShowItemToolTips = true;
4556 _listCustom.Size = new Size(380, 260);
4557 _listCustom.UseCompatibleStateImageBehavior = false;
4558 _listCustom.View = View.Details;
4559 _listCustom.OwnerDraw = true;
4560 _listCustom.VirtualMode = true;
4561 _listCustom.Font = _fntReaded;
4562 _listCustom.BackColor = _clListBackcolor;
4564 _listCustom.GridLines = SettingDialog.ShowGrid;
4565 _listCustom.AllowDrop = true;
4567 _listCustom.SmallImageList = _listViewImageList;
4569 InitColumns(_listCustom, startup);
4571 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4572 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4573 _listCustom.ColumnClick += MyList_ColumnClick;
4574 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4575 _listCustom.DragDrop += TweenMain_DragDrop;
4576 _listCustom.DragEnter += TweenMain_DragEnter;
4577 _listCustom.DragOver += TweenMain_DragOver;
4578 _listCustom.DrawItem += MyList_DrawItem;
4579 _listCustom.MouseClick += MyList_MouseClick;
4580 _listCustom.ColumnReordered += MyList_ColumnReordered;
4581 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4582 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4583 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4584 _listCustom.DrawSubItem += MyList_DrawSubItem;
4585 _listCustom.HScrolled += MyList_HScrolled;
4587 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4590 _tabPage.Tag = _listCustom;
4594 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4596 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4600 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4601 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4602 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4608 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4609 if (_tabPage == null) return false;
4611 SetListProperty(); //他のタブに列幅等を反映
4613 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4616 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4617 _tabPage.Tag = null;
4619 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4620 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4621 using (ControlTransaction.Layout(this.SplitContainer1, false))
4622 using (ControlTransaction.Layout(this.ListTab, false))
4623 using (ControlTransaction.Layout(this))
4624 using (ControlTransaction.Layout(_tabPage, false))
4626 if (this.ListTab.SelectedTab == _tabPage)
4628 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4629 this._beforeSelectedTab = null;
4631 this.ListTab.Controls.Remove(_tabPage);
4634 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4636 using (Control label = _tabPage.Controls["labelUser"])
4638 _tabPage.Controls.Remove(label);
4641 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4643 using (Control pnl = _tabPage.Controls["panelSearch"])
4645 pnl.Enter -= SearchControls_Enter;
4646 pnl.Leave -= SearchControls_Leave;
4647 _tabPage.Controls.Remove(pnl);
4649 foreach (Control ctrl in pnl.Controls)
4651 if (ctrl.Name == "buttonSearch")
4653 ctrl.Click -= SearchButton_Click;
4655 else if (ctrl.Name == "comboSearch")
4657 ctrl.KeyDown -= SearchComboBox_KeyDown;
4659 pnl.Controls.Remove(ctrl);
4665 _tabPage.Controls.Remove(_listCustom);
4667 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4668 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4669 _listCustom.ColumnClick -= MyList_ColumnClick;
4670 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4671 _listCustom.DragDrop -= TweenMain_DragDrop;
4672 _listCustom.DragEnter -= TweenMain_DragEnter;
4673 _listCustom.DragOver -= TweenMain_DragOver;
4674 _listCustom.DrawItem -= MyList_DrawItem;
4675 _listCustom.MouseClick -= MyList_MouseClick;
4676 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4677 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4678 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4679 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4680 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4681 _listCustom.HScrolled -= MyList_HScrolled;
4683 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4684 _listCustom.Columns.Clear();
4685 cols.ForEach(col => col.Dispose());
4688 _listCustom.ContextMenuStrip = null;
4689 _listCustom.ColumnHeaderContextMenuStrip = null;
4690 _listCustom.Font = null;
4692 _listCustom.SmallImageList = null;
4693 _listCustom.ListViewItemSorter = null;
4696 if (_curTab.Equals(_tabPage))
4703 this.PurgeListViewItemCache();
4707 _listCustom.Dispose();
4708 _statuses.RemoveTab(TabName);
4710 foreach (TabPage tp in ListTab.TabPages)
4712 DetailsListView lst = (DetailsListView)tp.Tag;
4713 var count = _statuses.Tabs[tp.Text].AllCount;
4714 if (lst.VirtualListSize != count)
4716 lst.VirtualListSize = count;
4723 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4725 this.PurgeListViewItemCache();
4726 _beforeSelectedTab = e.TabPage;
4729 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4733 if (!SettingDialog.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4736 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4737 if (!dragEnableRectangle.Contains(e.Location))
4739 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4740 tn = ListTab.SelectedTab.Text;
4743 if (string.IsNullOrEmpty(tn)) return;
4745 foreach (TabPage tb in ListTab.TabPages)
4749 ListTab.DoDragDrop(tb, DragDropEffects.All);
4759 Point cpos = new Point(e.X, e.Y);
4760 for (int i = 0; i < ListTab.TabPages.Count; i++)
4762 Rectangle rect = ListTab.GetTabRect(i);
4763 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4764 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4766 _rclickTabName = ListTab.TabPages[i].Text;
4772 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4774 //_curList.Refresh();
4776 SetMainWindowTitle();
4777 SetStatusLabelUrl();
4778 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4779 TabMenuControl(ListTab.SelectedTab.Text);
4780 this.PushSelectPostChain();
4783 private void SetListProperty()
4785 //削除などで見つからない場合は処理せず
4786 if (_curList == null) return;
4787 if (!_isColumnChanged) return;
4789 int[] dispOrder = new int[_curList.Columns.Count];
4790 for (int i = 0; i < _curList.Columns.Count; i++)
4792 for (int j = 0; j < _curList.Columns.Count; j++)
4794 if (_curList.Columns[j].DisplayIndex == i)
4803 foreach (TabPage tb in ListTab.TabPages)
4805 if (!tb.Equals(_curTab))
4807 if (tb.Tag != null && tb.Controls.Count > 0)
4809 DetailsListView lst = (DetailsListView)tb.Tag;
4810 for (int i = 0; i < lst.Columns.Count; i++)
4812 lst.Columns[dispOrder[i]].DisplayIndex = i;
4813 lst.Columns[i].Width = _curList.Columns[i].Width;
4819 _isColumnChanged = false;
4822 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4826 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4827 || PostBrowser.StatusText.StartsWith("data"))
4829 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4831 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4833 SetStatusLabelUrl();
4841 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4843 if (e.KeyChar == '@')
4845 if (!SettingDialog.UseAtIdSupplement) return;
4847 int cnt = AtIdSupl.ItemCount;
4848 ShowSuplDialog(StatusText, AtIdSupl);
4849 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4852 else if (e.KeyChar == '#')
4854 if (!SettingDialog.UseHashSupplement) return;
4855 ShowSuplDialog(StatusText, HashSupl);
4860 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4862 ShowSuplDialog(owner, dialog, 0, "");
4865 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4867 ShowSuplDialog(owner, dialog, offset, "");
4870 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4872 dialog.StartsWith = startswith;
4879 dialog.ShowDialog();
4881 this.TopMost = SettingDialog.AlwaysTop;
4882 int selStart = owner.SelectionStart;
4885 if (dialog.DialogResult == DialogResult.OK)
4887 if (!string.IsNullOrEmpty(dialog.inputText))
4891 fHalf = owner.Text.Substring(0, selStart - offset);
4893 if (selStart < owner.Text.Length)
4895 eHalf = owner.Text.Substring(selStart);
4897 owner.Text = fHalf + dialog.inputText + eHalf;
4898 owner.SelectionStart = selStart + dialog.inputText.Length;
4905 fHalf = owner.Text.Substring(0, selStart);
4907 if (selStart < owner.Text.Length)
4909 eHalf = owner.Text.Substring(selStart);
4911 owner.Text = fHalf + eHalf;
4914 owner.SelectionStart = selStart;
4920 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4923 if (!e.Alt && !e.Control && !e.Shift)
4925 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4927 bool isSpace = false;
4928 foreach (char c in StatusText.Text.ToCharArray())
4930 if (c == ' ' || c == ' ')
4943 StatusText.Text = "";
4944 JumpUnreadMenuItem_Click(null, null);
4948 this.StatusText_TextChanged(null, null);
4951 private void StatusText_TextChanged(object sender, EventArgs e)
4954 int pLen = GetRestStatusCount(true, false);
4955 lblLen.Text = pLen.ToString();
4958 StatusText.ForeColor = Color.Red;
4962 StatusText.ForeColor = _clInputFont;
4964 if (string.IsNullOrEmpty(StatusText.Text))
4966 _reply_to_id = null;
4967 _reply_to_name = null;
4971 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
4974 var statusText = this.StatusText.Text;
4975 statusText = statusText.Replace("\r\n", "\n");
4977 int pLen = 140 - statusText.Length;
4978 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
4979 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && SettingDialog.PostShiftEnter) ||
4980 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !SettingDialog.PostShiftEnter) ||
4981 (!isAuto && isAddFooter))
4983 if (SettingDialog.UseRecommendStatus)
4984 pLen -= SettingDialog.RecommendStatusText.Length;
4985 else if (SettingDialog.Status.Length > 0)
4986 pLen -= SettingDialog.Status.Length + 1;
4988 if (!string.IsNullOrEmpty(HashMgr.UseHash))
4990 pLen -= HashMgr.UseHash.Length + 1;
4992 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
4994 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4996 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
4998 string before = m.Result("${before}");
4999 string url = m.Result("${url}");
5000 string protocol = m.Result("${protocol}");
5001 string domain = m.Result("${domain}");
5002 string path = m.Result("${path}");
5003 if (protocol.Length == 0)
5005 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
5010 bool last_url_invalid_match = false;
5011 string lasturl = null;
5012 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
5014 lasturl = mm.ToString();
5015 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
5016 if (!last_url_invalid_match)
5018 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5022 if (path.Length != 0)
5024 if (last_url_invalid_match)
5026 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5028 pLen += path.Length;
5033 int shortUrlLength = protocol == "https://"
5034 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
5035 : SettingDialog.TwitterConfiguration.ShortUrlLength;
5037 pLen += url.Length - shortUrlLength;
5040 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
5042 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5045 if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
5047 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
5052 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
5054 this.itemCacheLock.EnterUpgradeableReadLock();
5057 if (_curList.Equals(sender))
5059 if (_itemCache != null &&
5060 e.StartIndex >= _itemCacheIndex &&
5061 e.EndIndex < _itemCacheIndex + _itemCache.Length)
5063 //If the newly requested cache is a subset of the old cache,
5064 //no need to rebuild everything, so do nothing.
5068 //Now we need to rebuild the cache.
5069 CreateCache(e.StartIndex, e.EndIndex);
5072 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
5075 private async void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
5077 ListViewItem item = null;
5078 PostClass cacheItemPost = null;
5080 if (_curList.Equals(sender))
5081 this.TryGetListViewItemCache(e.ItemIndex, out item, out cacheItemPost);
5085 //A cache miss, so create a new ListViewItem and pass it back.
5086 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
5089 item = this.CreateItem(tb, _statuses[tb.Text, e.ItemIndex], e.ItemIndex);
5094 string[] sitem = {"", "", "", "", "", "", "", ""};
5095 item = new ImageListViewItem(sitem);
5099 // e.Item に値をセットする前に await しないこと
5102 await ((ImageListViewItem)item).GetImageAsync();
5105 private void CreateCache(int StartIndex, int EndIndex)
5107 this.itemCacheLock.EnterWriteLock();
5110 var tabInfo = _statuses.Tabs[_curTab.Text];
5112 //キャッシュ要求(要求範囲±30を作成)
5114 if (StartIndex < 0) StartIndex = 0;
5116 if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
5117 _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
5118 _itemCacheIndex = StartIndex;
5120 _itemCache = new ListViewItem[0] {};
5121 Array.Resize(ref _itemCache, _postCache.Length);
5123 for (int i = 0; i < _postCache.Length; i++)
5125 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5130 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5132 _itemCacheIndex = -1;
5135 finally { this.itemCacheLock.ExitWriteLock(); }
5139 /// DetailsListView のための ListViewItem のキャッシュを消去する
5141 private void PurgeListViewItemCache()
5143 this.itemCacheLock.EnterWriteLock();
5146 this._itemCache = null;
5147 this._itemCacheIndex = -1;
5148 this._postCache = null;
5150 finally { this.itemCacheLock.ExitWriteLock(); }
5153 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5155 this.itemCacheLock.EnterReadLock();
5158 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5160 item = this._itemCache[index - _itemCacheIndex];
5161 post = this._postCache[index - _itemCacheIndex];
5165 finally { this.itemCacheLock.ExitReadLock(); }
5172 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5174 StringBuilder mk = new StringBuilder();
5175 //if (Post.IsDeleted) mk.Append("×");
5176 //if (Post.IsMark) mk.Append("♪");
5177 //if (Post.IsProtect) mk.Append("Ю");
5178 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5179 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5180 ImageListViewItem itm;
5181 if (Post.RetweetedId == null)
5183 string[] sitem= {"",
5185 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5186 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5191 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5195 string[] sitem = {"",
5197 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5198 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5199 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5203 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5205 itm.StateIndex = Post.StateIndex;
5207 bool read = Post.IsRead;
5208 //未読管理していなかったら既読として扱う
5209 if (!_statuses.Tabs[Tab.Text].UnreadManage || !SettingDialog.UnreadManage) read = true;
5210 ChangeItemStyleRead(read, itm, Post, null);
5211 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5216 /// 全てのタブの振り分けルールを反映し直します
5218 private void ApplyPostFilters()
5222 this.Cursor = Cursors.WaitCursor;
5224 this.PurgeListViewItemCache();
5225 this._curPost = null;
5226 this._curItemIndex = -1;
5227 this._statuses.FilterAll();
5229 foreach (TabPage tabPage in this.ListTab.TabPages)
5231 var tab = this._statuses.Tabs[tabPage.Text];
5233 var listview = (DetailsListView)tabPage.Tag;
5234 listview.VirtualListSize = tab.AllCount;
5236 if (this.SettingDialog.TabIconDisp)
5238 if (tab.UnreadCount > 0)
5239 tabPage.ImageIndex = 0;
5241 tabPage.ImageIndex = -1;
5245 if (!this.SettingDialog.TabIconDisp)
5246 this.ListTab.Refresh();
5250 this.Cursor = Cursors.Default;
5254 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5256 e.DrawDefault = true;
5259 private void MyList_HScrolled(object sender, EventArgs e)
5261 DetailsListView listView = (DetailsListView)sender;
5265 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5267 if (e.State == 0) return;
5268 e.DrawDefault = false;
5270 SolidBrush brs2 = null;
5271 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5273 if (e.Item.BackColor == _clSelf)
5274 brs2 = _brsBackColorMine;
5275 else if (e.Item.BackColor == _clAtSelf)
5276 brs2 = _brsBackColorAt;
5277 else if (e.Item.BackColor == _clTarget)
5278 brs2 = _brsBackColorYou;
5279 else if (e.Item.BackColor == _clAtTarget)
5280 brs2 = _brsBackColorAtYou;
5281 else if (e.Item.BackColor == _clAtFromTarget)
5282 brs2 = _brsBackColorAtFromTarget;
5283 else if (e.Item.BackColor == _clAtTo)
5284 brs2 = _brsBackColorAtTo;
5286 brs2 = _brsBackColorNone;
5291 if (((Control)sender).Focused)
5292 brs2 = _brsHighLight;
5294 brs2 = _brsDeactiveSelection;
5296 e.Graphics.FillRectangle(brs2, e.Bounds);
5297 e.DrawFocusRectangle();
5298 this.DrawListViewItemIcon(e);
5301 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5303 if (e.ItemState == 0) return;
5305 if (e.ColumnIndex > 0)
5308 RectangleF rct = e.Bounds;
5309 rct.Width = e.Header.Width;
5310 int fontHeight = e.Item.Font.Height;
5313 rct.Y += fontHeight;
5314 rct.Height -= fontHeight;
5318 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out heightDiff));
5320 //if (heightDiff > fontHeight * 0.7)
5322 // rct.Height += fontHeight;
5323 // drawLineCount += 1;
5326 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5327 if (!_iconCol && drawLineCount <= 1)
5329 //rct.Inflate(0, heightDiff / -2);
5330 //rct.Height += fontHeight / 2;
5332 else if (heightDiff < fontHeight * 0.7)
5334 //最終行が70%以上欠けていたら、最終行は表示しない
5335 //rct.Height = (float)((fontHeight * drawLineCount) + (fontHeight / 2));
5336 rct.Height = (fontHeight * drawLineCount) - 1;
5343 //if (!_iconCol && drawLineCount > 1)
5345 // rct.Y += fontHeight * 0.2;
5346 // if (heightDiff >= fontHeight * 0.8) rct.Height -= fontHeight * 0.2;
5351 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5352 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5357 Rectangle rctB = e.Bounds;
5358 rctB.Width = e.Header.Width;
5359 rctB.Height = fontHeight;
5361 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5363 TextRenderer.DrawText(e.Graphics,
5364 e.Item.SubItems[2].Text,
5366 Rectangle.Round(rct),
5368 TextFormatFlags.WordBreak |
5369 TextFormatFlags.EndEllipsis |
5370 TextFormatFlags.GlyphOverhangPadding |
5371 TextFormatFlags.NoPrefix);
5372 TextRenderer.DrawText(e.Graphics,
5373 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 + "]",
5377 TextFormatFlags.SingleLine |
5378 TextFormatFlags.EndEllipsis |
5379 TextFormatFlags.GlyphOverhangPadding |
5380 TextFormatFlags.NoPrefix);
5383 else if (drawLineCount == 1)
5385 TextRenderer.DrawText(e.Graphics,
5388 Rectangle.Round(rct),
5390 TextFormatFlags.SingleLine |
5391 TextFormatFlags.EndEllipsis |
5392 TextFormatFlags.GlyphOverhangPadding |
5393 TextFormatFlags.NoPrefix |
5394 TextFormatFlags.VerticalCenter);
5398 TextRenderer.DrawText(e.Graphics,
5401 Rectangle.Round(rct),
5403 TextFormatFlags.WordBreak |
5404 TextFormatFlags.EndEllipsis |
5405 TextFormatFlags.GlyphOverhangPadding |
5406 TextFormatFlags.NoPrefix);
5408 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5413 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5415 if (_iconSz == 0) return;
5417 ImageListViewItem item = (ImageListViewItem)e.Item;
5419 //e.Bounds.Leftが常に0を指すから自前で計算
5420 Rectangle itemRect = item.Bounds;
5421 var col0 = e.Item.ListView.Columns[0];
5422 itemRect.Width = col0.Width;
5424 if (col0.DisplayIndex > 0)
5426 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5428 if (clm.DisplayIndex < col0.DisplayIndex)
5429 itemRect.X += clm.Width;
5433 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5434 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5435 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5438 var img = item.Image;
5441 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5442 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5444 if (iconRect.Width > 0)
5446 e.Graphics.FillRectangle(Brushes.White, iconRect);
5447 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5450 e.Graphics.DrawImage(img.Image, iconRect);
5452 catch (ArgumentException)
5454 item.RefreshImageAsync();
5460 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5461 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5464 if (item.StateIndex > -1)
5466 Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5467 if (stateRect.Width > 0)
5469 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5470 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5471 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5476 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5478 base.ScaleControl(factor, specified);
5480 const int baseDpi = 96;
5482 // デザイン時の DPI (96dpi) との比を更新する
5483 this.currentScaleFactor = new SizeF(
5484 this.CurrentAutoScaleDimensions.Width / baseDpi,
5485 this.CurrentAutoScaleDimensions.Height / baseDpi);
5488 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5490 // ImageListViewItem item = (ImageListViewItem)e.Item;
5491 // if (item.StateImageIndex > -1)
5493 // ////e.Bounds.Leftが常に0を指すから自前で計算
5494 // //Rectangle itemRect = item.Bounds;
5495 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5497 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5499 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5501 // // itemRect.X += clm.Width;
5505 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5506 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5508 // if (rct.Width > 0)
5510 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5511 // //e.Graphics.FillRectangle(Brushes.White, rct);
5512 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5513 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5518 private void DoTabSearch(string _word,
5528 if (_curList.VirtualListSize == 0)
5530 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5533 if (_curList.SelectedIndices.Count > 0)
5535 cidx = _curList.SelectedIndices[0];
5537 toIdx = _curList.VirtualListSize;
5541 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5542 if (_curList.SelectedIndices.Count > 0)
5543 cidx = _curList.SelectedIndices[0];
5547 case SEARCHTYPE.NextSearch: //次を検索
5548 if (_curList.SelectedIndices.Count > 0)
5550 cidx = _curList.SelectedIndices[0] + 1;
5551 if (cidx > toIdx) cidx = toIdx;
5558 case SEARCHTYPE.PrevSearch: //前を検索
5559 if (_curList.SelectedIndices.Count > 0)
5561 cidx = _curList.SelectedIndices[0] - 1;
5562 if (cidx < 0) cidx = 0;
5573 RegexOptions regOpt = RegexOptions.None;
5574 StringComparison fndOpt = StringComparison.Ordinal;
5577 regOpt = RegexOptions.IgnoreCase;
5578 fndOpt = StringComparison.OrdinalIgnoreCase;
5589 _search = new Regex(_word, regOpt);
5590 for (int idx = cidx; idx != toIdx; idx += stp)
5595 post = _statuses[_curTab.Text, idx];
5601 if (_search.IsMatch(post.Nickname)
5602 || _search.IsMatch(post.TextFromApi)
5603 || _search.IsMatch(post.ScreenName))
5605 SelectListItem(_curList, idx);
5606 _curList.EnsureVisible(idx);
5611 catch (ArgumentException)
5613 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5620 for (int idx = cidx; idx != toIdx; idx += stp)
5625 post = _statuses[_curTab.Text, idx];
5631 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5632 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5633 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5635 SelectListItem(_curList, idx);
5636 _curList.EnsureVisible(idx);
5646 case SEARCHTYPE.DialogSearch:
5647 case SEARCHTYPE.NextSearch:
5651 case SEARCHTYPE.PrevSearch:
5653 cidx = _curList.VirtualListSize - 1;
5660 catch (ArgumentOutOfRangeException)
5663 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5666 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5669 this.ShowSearchDialog();
5672 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5674 var previousSearch = this.SearchDialog.ResultOptions;
5675 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5677 this.SearchDialog.Reset();
5678 this.ShowSearchDialog();
5684 previousSearch.Query,
5685 previousSearch.CaseSensitive,
5686 previousSearch.UseRegex,
5687 SEARCHTYPE.NextSearch);
5690 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5692 var previousSearch = this.SearchDialog.ResultOptions;
5693 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5695 this.SearchDialog.Reset();
5696 this.ShowSearchDialog();
5702 previousSearch.Query,
5703 previousSearch.CaseSensitive,
5704 previousSearch.UseRegex,
5705 SEARCHTYPE.PrevSearch);
5709 /// 検索ダイアログを表示し、検索を実行します
5711 private void ShowSearchDialog()
5713 // Recentタブの検索時以外では「新規タブに表示」ボタンを無効化する
5714 if (this._statuses.Tabs[this._curTab.Text].TabType == MyCommon.TabUsageType.Home)
5715 this.SearchDialog.DisableNewTabButton = false;
5717 this.SearchDialog.DisableNewTabButton = true;
5719 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5721 this.TopMost = this.SettingDialog.AlwaysTop;
5724 this.TopMost = this.SettingDialog.AlwaysTop;
5726 var searchOptions = this.SearchDialog.ResultOptions;
5727 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5729 if (searchOptions.NewTab)
5731 var tabName = searchOptions.Query;
5735 tabName = this._statuses.MakeTabName(tabName);
5737 catch (TabException ex)
5739 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5742 this.AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined);
5743 this._statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
5745 var filter = new PostFilterRule
5747 FilterBody = new[] { searchOptions.Query },
5748 UseRegex = searchOptions.UseRegex,
5749 CaseSensitive = searchOptions.CaseSensitive,
5751 this._statuses.Tabs[tabName].AddFilter(filter);
5753 var tabPage = this.ListTab.TabPages.Cast<TabPage>()
5754 .First(x => x.Text == tabName);
5756 this.ListTab.SelectedTab = tabPage;
5757 this.ListTabSelect(tabPage);
5759 this.ApplyPostFilters();
5760 this.SaveConfigsTabs();
5765 searchOptions.Query,
5766 searchOptions.CaseSensitive,
5767 searchOptions.UseRegex,
5768 SEARCHTYPE.DialogSearch);
5771 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5773 this.AddNewTabForSearch(searchOptions.Query);
5777 private void AboutMenuItem_Click(object sender, EventArgs e)
5779 using (TweenAboutBox about = new TweenAboutBox())
5781 about.ShowDialog(this);
5783 this.TopMost = SettingDialog.AlwaysTop;
5786 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5788 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5790 DetailsListView lst = null;
5792 if (ImageSelector.Enabled)
5796 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5799 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5802 ListTab.SelectedIndex = i;
5803 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5804 //_curTab = ListTab.TabPages[i];
5809 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5810 if (idx == -1 && bgnIdx > 0)
5812 for (int i = 0; i < bgnIdx; i++)
5814 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5817 ListTab.SelectedIndex = i;
5818 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5819 //_curTab = ListTab.TabPages[i];
5825 //全部調べたが未読見つからず→先頭タブの最新発言へ
5828 ListTab.SelectedIndex = 0;
5829 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5830 //_curTab = ListTab.TabPages[0];
5831 if (_statuses.SortOrder == SortOrder.Ascending)
5832 idx = lst.VirtualListSize - 1;
5837 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5839 SelectListItem(lst, idx);
5840 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5842 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5843 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5849 lst.EnsureVisible(idx);
5854 lst.EnsureVisible(idx);
5860 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5862 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5864 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5865 OpenUriAsync(MyCommon.GetStatusUrl(post));
5869 private void FavorareMenuItem_Click(object sender, EventArgs e)
5871 if (_curList.SelectedIndices.Count > 0)
5873 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5874 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5878 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5880 await this.CheckNewVersion(false);
5883 private void RunTweenUp()
5885 ProcessStartInfo pinfo = new ProcessStartInfo();
5886 pinfo.UseShellExecute = true;
5887 pinfo.WorkingDirectory = MyCommon.settingPath;
5888 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5889 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5892 Process.Start(pinfo);
5896 MessageBox.Show("Failed to execute TweenUp3.exe.");
5900 public class VersionInfo
5902 public Version Version { get; set; }
5903 public Uri DownloadUri { get; set; }
5904 public string ReleaseNote { get; set; }
5908 /// OpenTween の最新バージョンの情報を取得します
5910 public async Task<VersionInfo> GetVersionInfoAsync()
5912 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5913 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5915 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5916 .ConfigureAwait(false);
5918 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5919 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5921 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5922 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5924 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5926 return new VersionInfo
5928 Version = Version.Parse(msgHeader[0]),
5929 DownloadUri = new Uri(msgHeader[1]),
5930 ReleaseNote = msgBody,
5934 private async Task CheckNewVersion(bool startup = false)
5936 if (ApplicationSettings.VersionInfoUrl == null)
5937 return; // 更新チェック無効化
5941 var versionInfo = await this.GetVersionInfoAsync();
5943 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5948 var msgtext = string.Format(Properties.Resources.CheckNewVersionText7,
5949 MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version));
5950 msgtext = MyCommon.ReplaceAppName(msgtext);
5952 MessageBox.Show(msgtext,
5953 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5954 MessageBoxButtons.OK, MessageBoxIcon.Information);
5959 using (var dialog = new UpdateDialog())
5961 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5962 MyCommon.GetReadableVersion(versionInfo.Version));
5963 dialog.DetailsText = versionInfo.ReleaseNote;
5965 if (dialog.ShowDialog(this) == DialogResult.Yes)
5967 await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString);
5973 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5976 MessageBox.Show(Properties.Resources.CheckNewVersionText10,
5977 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5978 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5983 private void Colorize()
5987 //件数関連の場合、タイトル即時書き換え
5988 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
5989 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5990 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5991 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5993 SetMainWindowTitle();
5995 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
5996 foreach (TabPage tb in ListTab.TabPages)
5998 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
6000 if (SettingDialog.TabIconDisp)
6002 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
6006 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
6009 public string createDetailHtml(string orgdata)
6011 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
6014 private async void DisplayItemImage_Downloaded(object sender, EventArgs e)
6016 if (sender.Equals(displayItem))
6018 this.ClearUserPicture();
6020 var img = displayItem.Image;
6024 img = await img.CloneAsync();
6026 UserPicture.Image = img;
6030 UserPicture.ShowErrorImage();
6035 private void DispSelectedPost()
6037 DispSelectedPost(false);
6040 private PostClass displayPost = new PostClass();
6043 /// サムネイルの表示処理を表すタスク
6045 private Task thumbnailTask = null;
6048 /// サムネイル表示に使用する CancellationToken の生成元
6050 private CancellationTokenSource thumbnailTokenSource = null;
6052 private void DispSelectedPost(bool forceupdate)
6054 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
6057 var oldDisplayPost = this.displayPost;
6058 this.displayPost = this._curPost;
6060 if (!forceupdate && this._curPost.Equals(oldDisplayPost))
6063 if (displayItem != null)
6065 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
6068 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
6069 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
6071 using (ControlTransaction.Update(this.TableLayoutPanel1))
6073 var sourceText = "";
6074 string sourceUrl = null;
6077 var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
6080 var src = mc.Groups["sourceurl"].Value;
6081 if (Regex.IsMatch(src, "^https?://"))
6084 sourceUrl = "https://twitter.com/" + src;
6087 if (_curPost.Source != null)
6088 sourceText = _curPost.Source;
6090 SourceLinkLabel.Text = sourceText;
6091 SourceLinkLabel.Tag = sourceUrl;
6092 SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
6098 nameText = "DM FROM <- ";
6100 nameText = "DM TO -> ";
6106 nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
6107 if (_curPost.RetweetedId != null)
6108 nameText += " (RT:" + _curPost.RetweetedBy + ")";
6110 NameLabel.Text = nameText;
6111 NameLabel.Tag = _curPost.ScreenName;
6113 var nameForeColor = SystemColors.ControlText;
6114 if (_curPost.IsOwl && (this.SettingDialog.OneWayLove || _curPost.IsDm))
6115 nameForeColor = this._clOWL;
6116 if (_curPost.RetweetedId != null)
6117 nameForeColor = this._clRetweet;
6119 nameForeColor = this._clFav;
6120 NameLabel.ForeColor = nameForeColor;
6122 this.ClearUserPicture();
6124 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6126 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6129 UserPicture.Image = image != null ? image.Clone() : null;
6133 UserPicture.ShowErrorImage();
6137 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6139 if (DumpPostClassToolStripMenuItem.Checked)
6141 StringBuilder sb = new StringBuilder(512);
6143 sb.Append("-----Start PostClass Dump<br>");
6144 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6145 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6146 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6147 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6148 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6149 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6150 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6151 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6152 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6153 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6154 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6155 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6156 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6157 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6158 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6160 foreach (string nm in _curPost.ReplyToList)
6162 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6165 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6166 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6167 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6168 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6169 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6170 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6171 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6172 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6173 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6174 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6175 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6176 sb.Append("-----End PostClass Dump<br>");
6178 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6182 // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
6183 // (同一ツイートの RT は文面が同じであるため同様に更新しない)
6184 if (_curPost.StatusId != oldDisplayPost.StatusId)
6186 this.PostBrowser.DocumentText =
6187 this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6189 this.PostBrowser.Document.Window.ScrollTo(0, 0);
6191 this.SplitContainer3.Panel2Collapsed = true;
6193 if (this.IsPreviewEnable)
6195 if (this.thumbnailTokenSource != null)
6197 var oldTokenSource = this.thumbnailTokenSource;
6199 var cancelTask = Task.Run(() => oldTokenSource.Cancel());
6201 Task.WhenAll(this.thumbnailTask, cancelTask)
6202 .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
6205 this.thumbnailTokenSource = new CancellationTokenSource();
6207 var token = this.thumbnailTokenSource.Token;
6208 this.thumbnailTask = this.tweetThumbnail1.ShowThumbnailAsync(_curPost, token);
6215 private void MatomeMenuItem_Click(object sender, EventArgs e)
6217 OpenApplicationWebsite();
6220 private void OpenApplicationWebsite()
6222 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6225 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6227 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6230 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6232 if (ListTab.SelectedTab != null)
6234 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6236 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6237 if (pnl.Controls["comboSearch"].Focused ||
6238 pnl.Controls["comboLang"].Focused ||
6239 pnl.Controls["buttonSearch"].Focused) return;
6241 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6242 if (State == ModifierState.NotFlags) return;
6243 if (State != ModifierState.None) _anchorFlag = false;
6244 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6247 e.SuppressKeyPress = true;
6252 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6254 ModifierState state = ModifierState.None;
6255 if (sControl) state = state | ModifierState.Ctrl;
6256 if (sShift) state = state | ModifierState.Shift;
6257 if (sAlt) state = state | ModifierState.Alt;
6262 private enum ModifierState
6274 //PostBrowser = 102,
6278 private enum FocusedControl : int
6286 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6288 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6289 if (Focused == FocusedControl.ListTab)
6291 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6292 Modifier == ModifierState.Ctrl ||
6293 Modifier == ModifierState.None ||
6294 Modifier == ModifierState.Shift)
6296 if (KeyCode == Keys.J)
6298 SendKeys.Send("{DOWN}");
6301 else if (KeyCode == Keys.K)
6303 SendKeys.Send("{UP}");
6307 if (Modifier == ModifierState.Shift ||
6308 Modifier == ModifierState.None)
6310 if (KeyCode == Keys.F)
6312 SendKeys.Send("{PGDN}");
6315 else if (KeyCode == Keys.B)
6317 SendKeys.Send("{PGUP}");
6326 case ModifierState.None:
6331 OpenApplicationWebsite();
6334 MenuItemSearchNext_Click(null, null);
6340 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 0, "");
6343 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 0, "");
6346 if (Focused != FocusedControl.StatusText)
6352 case Keys.ProcessKey:
6353 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6354 JumpUnreadMenuItem_Click(null, null);
6357 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6358 ShowRelatedStatusesMenuItem_Click(null, null);
6362 if (Focused == FocusedControl.ListTab)
6375 case Keys.OemPeriod:
6379 if (this.StatusText.Enabled) this.StatusText.Focus();
6382 MakeReplyOrDirectStatus();
6389 _anchorFlag = false;
6409 // ] in_reply_to参照元へ戻る
6410 GoInReplyToPostTree();
6413 // [ in_reply_toへジャンプ
6414 GoBackInReplyToPostTree();
6417 if (ListTab.SelectedTab != null)
6419 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6420 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6422 TabPage relTp = ListTab.SelectedTab;
6423 RemoveSpecifiedTab(relTp.Text, false);
6431 else if (Focused == FocusedControl.PostBrowser)
6438 //スクロールを発生させるため、true を返す
6443 case ModifierState.Ctrl:
6448 MakeReplyOrDirectStatus(false, true);
6454 MakeReplyOrDirectStatus(false, false);
6457 FavoriteChange(true);
6460 doRepliedStatusOpen();
6466 ReadedStripMenuItem_Click(null, null);
6469 HashManageMenuItem_Click(null, null);
6472 UrlConvertAutoToolStripMenuItem_Click(null, null);
6475 if (Focused != FocusedControl.PostBrowser)
6477 MultiLineMenuItem_Click(null, null);
6482 MenuItemSubSearch_Click(null, null);
6489 MoveToHomeToolStripMenuItem_Click(null, null);
6493 MoveToFavToolStripMenuItem_Click(null, null);
6497 StatusOpenMenuItem_Click(null, null);
6501 OpenURLMenuItem_Click(null, null);
6505 if (Focused == FocusedControl.ListTab)
6512 return false; //スルーする
6530 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6531 int tabNo = KeyCode - Keys.D1;
6532 if (ListTab.TabPages.Count < tabNo)
6534 ListTab.SelectedIndex = tabNo;
6535 ListTabSelect(ListTab.TabPages[tabNo]);
6538 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6539 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6543 else if (Focused == FocusedControl.StatusText)
6549 StatusText.SelectAll();
6553 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6555 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6557 if (KeyCode == Keys.Up)
6560 if (_hisIdx < 0) _hisIdx = 0;
6565 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6567 StatusText.Text = _history[_hisIdx].status;
6568 _reply_to_id = _history[_hisIdx].inReplyToId;
6569 _reply_to_name = _history[_hisIdx].inReplyToName;
6570 StatusText.SelectionStart = StatusText.Text.Length;
6574 if (ListTab.SelectedIndex == 0)
6576 ListTab.SelectedIndex = ListTab.TabCount - 1;
6580 ListTab.SelectedIndex -= 1;
6586 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6588 ListTab.SelectedIndex = 0;
6592 ListTab.SelectedIndex += 1;
6600 //フォーカスPostBrowserもしくは関係なし
6604 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6608 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6609 if (!string.IsNullOrEmpty(_selText))
6613 Clipboard.SetDataObject(_selText, false, 5, 100);
6615 catch (Exception ex)
6617 MessageBox.Show(ex.Message);
6622 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6623 MultiLineMenuItem_Click(null, null);
6628 case ModifierState.Shift:
6633 MenuItemSearchPrev_Click(null, null);
6639 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, 0, "");
6642 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, 0, "");
6646 if (Focused != FocusedControl.StatusText)
6648 if (KeyCode == Keys.R)
6655 if (Focused == FocusedControl.ListTab)
6675 GoBackInReplyToPostTree(true, false);
6678 GoBackInReplyToPostTree(true, true);
6682 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6687 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6691 this.GoBackSelectPostChain();
6696 case ModifierState.Alt:
6700 doReTweetOfficial(true);
6703 if (_curPost != null)
6705 doShowUserStatus(_curPost.ScreenName, false);
6710 ScrollDownPostBrowser(false);
6713 ScrollDownPostBrowser(true);
6716 PageDownPostBrowser(false);
6719 PageDownPostBrowser(true);
6722 if (Focused == FocusedControl.ListTab)
6724 // 別タブの同じ書き込みへ(ALT+←/→)
6725 if (KeyCode == Keys.Right)
6727 GoSamePostToAnotherTab(false);
6730 else if (KeyCode == Keys.Left)
6732 GoSamePostToAnotherTab(true);
6737 case ModifierState.Ctrl | ModifierState.Shift:
6741 MakeReplyOrDirectStatus(false, true, true);
6747 if (ListTab.SelectedTab != null)
6749 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6751 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6757 FavoriteChange(false);
6760 UnreadStripMenuItem_Click(null, null);
6763 HashToggleMenuItem_Click(null, null);
6766 ImageSelectMenuItem_Click(null, null);
6772 FavorareMenuItem_Click(null, null);
6775 if (Focused == FocusedControl.StatusText)
6781 if (_curList != null && _curList.VirtualListSize != 0 &&
6782 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6784 idx = _curList.SelectedIndices[0] - 1;
6785 SelectListItem(_curList, idx);
6786 _curList.EnsureVisible(idx);
6791 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6792 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6794 idx = _curList.SelectedIndices[0] + 1;
6795 SelectListItem(_curList, idx);
6796 _curList.EnsureVisible(idx);
6801 if (StatusText.SelectionStart > 0)
6803 int endidx = StatusText.SelectionStart - 1;
6804 string startstr = "";
6805 bool pressed = false;
6806 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6808 char c = StatusText.Text[i];
6809 if (Char.IsLetterOrDigit(c) || c == '_')
6816 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6817 int cnt = AtIdSupl.ItemCount;
6818 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6819 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6824 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6825 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6837 else if (Focused == FocusedControl.ListTab)
6839 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6851 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6852 int colNo = KeyCode - Keys.D1;
6853 if (lst.Columns.Count < colNo) return false;
6854 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6855 if (col == null) return false;
6856 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6859 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6860 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6865 case ModifierState.Ctrl | ModifierState.Alt:
6866 if (KeyCode == Keys.S)
6868 FavoritesRetweetOriginal();
6871 else if (KeyCode == Keys.R)
6873 FavoritesRetweetUnofficial();
6876 else if (KeyCode == Keys.H)
6878 OpenUserAppointUrl();
6882 case ModifierState.Alt | ModifierState.Shift:
6883 if (Focused == FocusedControl.PostBrowser)
6885 if (KeyCode == Keys.R)
6886 doReTweetUnofficial();
6887 else if (KeyCode == Keys.C)
6894 if (!this.ExistCurrentPost) return false;
6895 doTranslation(_curPost.TextFromApi);
6898 doReTweetUnofficial();
6904 this.tweetThumbnail1.ScrollUp();
6907 this.tweetThumbnail1.ScrollDown();
6910 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6912 if (!this.SplitContainer3.Panel2Collapsed)
6914 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6924 private void ScrollDownPostBrowser(bool forward)
6926 var doc = PostBrowser.Document;
6927 if (doc == null) return;
6929 var tags = doc.GetElementsByTagName("html");
6933 tags[0].ScrollTop += SettingDialog.FontDetail.Height;
6935 tags[0].ScrollTop -= SettingDialog.FontDetail.Height;
6939 private void PageDownPostBrowser(bool forward)
6941 var doc = PostBrowser.Document;
6942 if (doc == null) return;
6944 var tags = doc.GetElementsByTagName("html");
6948 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6950 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6954 private void GoNextTab(bool forward)
6956 int idx = ListTab.SelectedIndex;
6960 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6965 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6967 ListTab.SelectedIndex = idx;
6968 ListTabSelect(ListTab.TabPages[idx]);
6971 private void CopyStot()
6974 StringBuilder sb = new StringBuilder();
6975 bool IsProtected = false;
6977 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6978 foreach (int idx in _curList.SelectedIndices)
6980 PostClass post = _statuses[_curTab.Text, idx];
6986 if (post.IsDeleted) continue;
6989 if (post.RetweetedId != null)
6990 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6992 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6996 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7001 MessageBox.Show(Properties.Resources.CopyStotText1);
7005 clstr = sb.ToString();
7008 Clipboard.SetDataObject(clstr, false, 5, 100);
7010 catch (Exception ex)
7012 MessageBox.Show(ex.Message);
7017 private void CopyIdUri()
7020 StringBuilder sb = new StringBuilder();
7021 if (this._curTab == null) return;
7022 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
7023 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
7024 foreach (int idx in _curList.SelectedIndices)
7026 var post = _statuses[_curTab.Text, idx];
7027 sb.Append(MyCommon.GetStatusUrl(post));
7028 sb.Append(Environment.NewLine);
7032 clstr = sb.ToString();
7035 Clipboard.SetDataObject(clstr, false, 5, 100);
7037 catch (Exception ex)
7039 MessageBox.Show(ex.Message);
7044 private void GoFav(bool forward)
7046 if (_curList.VirtualListSize == 0) return;
7053 if (_curList.SelectedIndices.Count == 0)
7059 fIdx = _curList.SelectedIndices[0] + 1;
7060 if (fIdx > _curList.VirtualListSize - 1) return;
7062 toIdx = _curList.VirtualListSize;
7067 if (_curList.SelectedIndices.Count == 0)
7069 fIdx = _curList.VirtualListSize - 1;
7073 fIdx = _curList.SelectedIndices[0] - 1;
7074 if (fIdx < 0) return;
7080 for (int idx = fIdx; idx != toIdx; idx += stp)
7082 if (_statuses[_curTab.Text, idx].IsFav)
7084 SelectListItem(_curList, idx);
7085 _curList.EnsureVisible(idx);
7091 private void GoSamePostToAnotherTab(bool left)
7093 if (_curList.VirtualListSize == 0) return;
7099 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7100 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7102 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7107 if (ListTab.SelectedIndex == 0)
7113 fIdx = ListTab.SelectedIndex - 1;
7121 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7127 fIdx = ListTab.SelectedIndex + 1;
7129 toIdx = ListTab.TabCount;
7134 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7136 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7137 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7139 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7141 ListTab.SelectedIndex = tabidx;
7142 ListTabSelect(ListTab.TabPages[tabidx]);
7143 SelectListItem(_curList, idx);
7144 _curList.EnsureVisible(idx);
7153 private void GoPost(bool forward)
7155 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7162 fIdx = _curList.SelectedIndices[0] + 1;
7163 if (fIdx > _curList.VirtualListSize - 1) return;
7164 toIdx = _curList.VirtualListSize;
7169 fIdx = _curList.SelectedIndices[0] - 1;
7170 if (fIdx < 0) return;
7176 if (_curPost.RetweetedId == null)
7178 name = _curPost.ScreenName;
7182 name = _curPost.RetweetedBy;
7184 for (int idx = fIdx; idx != toIdx; idx += stp)
7186 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7188 if (_statuses[_curTab.Text, idx].ScreenName == name)
7190 SelectListItem(_curList, idx);
7191 _curList.EnsureVisible(idx);
7197 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7199 SelectListItem(_curList, idx);
7200 _curList.EnsureVisible(idx);
7207 private void GoRelPost(bool forward)
7209 if (_curList.SelectedIndices.Count == 0) return;
7216 fIdx = _curList.SelectedIndices[0] + 1;
7217 if (fIdx > _curList.VirtualListSize - 1) return;
7218 toIdx = _curList.VirtualListSize;
7223 fIdx = _curList.SelectedIndices[0] - 1;
7224 if (fIdx < 0) return;
7231 if (_curPost == null) return;
7232 _anchorPost = _curPost;
7237 if (_anchorPost == null) return;
7240 for (int idx = fIdx; idx != toIdx; idx += stp)
7242 PostClass post = _statuses[_curTab.Text, idx];
7243 if (post.ScreenName == _anchorPost.ScreenName ||
7244 post.RetweetedBy == _anchorPost.ScreenName ||
7245 post.ScreenName == _anchorPost.RetweetedBy ||
7246 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7247 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7248 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7249 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7250 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7252 SelectListItem(_curList, idx);
7253 _curList.EnsureVisible(idx);
7259 private void GoAnchor()
7261 if (_anchorPost == null) return;
7262 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7263 if (idx == -1) return;
7265 SelectListItem(_curList, idx);
7266 _curList.EnsureVisible(idx);
7269 private void GoTopEnd(bool GoTop)
7276 _item = _curList.GetItemAt(0, 25);
7284 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7286 idx = _curList.VirtualListSize - 1;
7290 SelectListItem(_curList, idx);
7293 private void GoMiddle()
7300 _item = _curList.GetItemAt(0, 0);
7310 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7313 idx2 = _curList.VirtualListSize - 1;
7319 idx3 = (idx1 + idx2) / 2;
7321 SelectListItem(_curList, idx3);
7324 private void GoLast()
7326 if (_curList.VirtualListSize == 0) return;
7328 if (_statuses.SortOrder == SortOrder.Ascending)
7330 SelectListItem(_curList, _curList.VirtualListSize - 1);
7331 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7335 SelectListItem(_curList, 0);
7336 _curList.EnsureVisible(0);
7340 private void MoveTop()
7342 if (_curList.SelectedIndices.Count == 0) return;
7343 int idx = _curList.SelectedIndices[0];
7344 if (_statuses.SortOrder == SortOrder.Ascending)
7346 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7350 _curList.EnsureVisible(0);
7352 _curList.EnsureVisible(idx);
7355 private void GoInReplyToPostTree()
7357 if (_curPost == null) return;
7359 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7361 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7363 PostClass post = null;
7364 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7365 if (string.IsNullOrEmpty(r) && post != null)
7367 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7368 _curPost.InReplyToUser = post.InReplyToUser;
7369 _curPost.IsReply = post.IsReply;
7370 this.PurgeListViewItemCache();
7371 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7375 this.StatusLabel.Text = r;
7379 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7381 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7383 replyChains = new Stack<ReplyChain>();
7385 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7388 string inReplyToTabName;
7389 long inReplyToId = _curPost.InReplyToStatusId.Value;
7390 string inReplyToUser = _curPost.InReplyToUser;
7391 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7393 var inReplyToPosts = from tab in _statuses.Tabs.Values
7394 orderby tab != curTabClass
7395 from post in tab.Posts.Values
7396 where post.StatusId == inReplyToId
7397 let index = tab.IndexOf(post.StatusId)
7399 select new {Tab = tab, Index = index};
7403 var inReplyPost = inReplyToPosts.First();
7404 inReplyToTabName = inReplyPost.Tab.TabName;
7405 inReplyToIndex = inReplyPost.Index;
7407 catch (InvalidOperationException)
7409 PostClass post = null;
7410 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7411 if (string.IsNullOrEmpty(r) && post != null)
7414 _statuses.AddPost(post);
7415 _statuses.DistributePosts();
7416 //_statuses.SubmitUpdate(null, null, null, false);
7417 this.RefreshTimeline(false);
7420 var inReplyPost = inReplyToPosts.First();
7421 inReplyToTabName = inReplyPost.Tab.TabName;
7422 inReplyToIndex = inReplyPost.Index;
7424 catch (InvalidOperationException)
7426 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7432 this.StatusLabel.Text = r;
7433 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7438 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7439 DetailsListView listView = (DetailsListView)tabPage.Tag;
7441 if (_curTab != tabPage)
7443 this.ListTab.SelectTab(tabPage);
7446 this.SelectListItem(listView, inReplyToIndex);
7447 listView.EnsureVisible(inReplyToIndex);
7450 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7452 if (_curPost == null) return;
7454 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7455 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7459 if (_curPost.InReplyToStatusId != null)
7461 var posts = from t in _statuses.Tabs
7462 from p in t.Value.Posts
7463 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7464 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7466 orderby isForward ? indexOf : indexOf * -1
7467 orderby t.Value != curTabClass
7468 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7471 var postList = posts.ToList();
7472 for (int i = postList.Count - 1; i >= 0; i--)
7475 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7477 postList.RemoveAt(index);
7480 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7481 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7482 if (post == null) post = postList.First();
7483 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7484 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7485 SelectListItem(listView, post.Index);
7486 listView.EnsureVisible(post.Index);
7488 catch (InvalidOperationException)
7496 if (replyChains == null || replyChains.Count < 1)
7498 var posts = from t in _statuses.Tabs
7499 from p in t.Value.Posts
7500 where p.Value.InReplyToStatusId == _curPost.StatusId
7501 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7504 orderby t.Value != curTabClass
7505 select new {Tab = t.Value, Index = indexOf};
7508 var post = posts.First();
7509 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7510 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7511 SelectListItem(listView, post.Index);
7512 listView.EnsureVisible(post.Index);
7514 catch (InvalidOperationException)
7521 ReplyChain chainHead = replyChains.Pop();
7522 if (chainHead.InReplyToId == _curPost.StatusId)
7524 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7533 ListTab.SelectTab(chainHead.OriginalTab);
7539 SelectListItem(_curList, idx);
7540 _curList.EnsureVisible(idx);
7546 this.GoBackInReplyToPostTree(parallel);
7552 private void GoBackSelectPostChain()
7554 if (this.selectPostChains.Count > 1)
7563 this.selectPostChains.Pop();
7564 var tabPostPair = this.selectPostChains.Peek();
7566 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) continue; //該当タブが存在しないので無視
7568 if (tabPostPair.Item2 != null)
7570 idx = this._statuses.Tabs[tabPostPair.Item1.Text].IndexOf(tabPostPair.Item2.StatusId);
7571 if (idx == -1) continue; //該当ポストが存在しないので無視
7574 tp = tabPostPair.Item1;
7576 this.selectPostChains.Pop();
7578 catch (InvalidOperationException)
7584 while (this.selectPostChains.Count > 1);
7589 //履歴が残り1つであればクリアしておく
7590 if (this.selectPostChains.Count == 1)
7591 this.selectPostChains.Clear();
7595 DetailsListView lst = (DetailsListView)tp.Tag;
7596 this.ListTab.SelectedTab = tp;
7599 SelectListItem(lst, idx);
7600 lst.EnsureVisible(idx);
7606 private void PushSelectPostChain()
7608 int count = this.selectPostChains.Count;
7611 var p = this.selectPostChains.Peek();
7612 if (p.Item1 == this._curTab)
7614 if (p.Item2 == this._curPost) return; //最新の履歴と同一
7615 if (p.Item2 == null) this.selectPostChains.Pop(); //置き換えるため削除
7618 if (count >= 2500) TrimPostChain();
7619 this.selectPostChains.Push(Tuple.Create(this._curTab, this._curPost));
7622 private void TrimPostChain()
7624 if (this.selectPostChains.Count <= 2000) return;
7625 var p = new Stack<Tuple<TabPage, PostClass>>(2000);
7626 for (int i = 0; i < 2000; i++)
7628 p.Push(this.selectPostChains.Pop());
7630 this.selectPostChains.Clear();
7631 for (int i = 0; i < 2000; i++)
7633 this.selectPostChains.Push(p.Pop());
7637 private bool GoStatus(long statusId)
7639 if (statusId == 0) return false;
7640 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7642 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7644 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7645 ListTab.SelectedIndex = tabidx;
7646 ListTabSelect(ListTab.TabPages[tabidx]);
7647 SelectListItem(_curList, idx);
7648 _curList.EnsureVisible(idx);
7655 private bool GoDirectMessage(long statusId)
7657 if (statusId == 0) return false;
7658 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7660 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7662 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7663 ListTab.SelectedIndex = tabidx;
7664 ListTabSelect(ListTab.TabPages[tabidx]);
7665 SelectListItem(_curList, idx);
7666 _curList.EnsureVisible(idx);
7673 private void MyList_MouseClick(object sender, MouseEventArgs e)
7675 _anchorFlag = false;
7678 private void StatusText_Enter(object sender, EventArgs e)
7680 // フォーカスの戻り先を StatusText に設定
7681 this.Tag = StatusText;
7682 StatusText.BackColor = _clInputBackcolor;
7685 public Color InputBackColor
7687 get { return _clInputBackcolor; }
7688 set { _clInputBackcolor = value; }
7691 private void StatusText_Leave(object sender, EventArgs e)
7693 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7694 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7695 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7698 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7700 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7701 if (State == ModifierState.NotFlags) return;
7702 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7705 e.SuppressKeyPress = true;
7708 this.StatusText_TextChanged(null, null);
7711 private void SaveConfigsAll(bool ifModified)
7715 SaveConfigsCommon();
7722 if (_modifySettingCommon) SaveConfigsCommon();
7723 if (_modifySettingLocal) SaveConfigsLocal();
7724 if (_modifySettingAtId) SaveConfigsAtId();
7728 private void SaveConfigsAtId()
7730 if (_ignoreConfigSave || !SettingDialog.UseAtIdSupplement && AtIdSupl == null) return;
7732 _modifySettingAtId = false;
7733 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7737 private void SaveConfigsCommon()
7739 if (_ignoreConfigSave) return;
7741 _modifySettingCommon = false;
7744 _cfgCommon.UserName = tw.Username;
7745 _cfgCommon.UserId = tw.UserId;
7746 _cfgCommon.Password = tw.Password;
7747 _cfgCommon.Token = tw.AccessToken;
7748 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7749 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7750 _cfgCommon.UserstreamStartup = SettingDialog.UserstreamStartup;
7751 _cfgCommon.UserstreamPeriod = SettingDialog.UserstreamPeriodInt;
7752 _cfgCommon.TimelinePeriod = SettingDialog.TimelinePeriodInt;
7753 _cfgCommon.ReplyPeriod = SettingDialog.ReplyPeriodInt;
7754 _cfgCommon.DMPeriod = SettingDialog.DMPeriodInt;
7755 _cfgCommon.PubSearchPeriod = SettingDialog.PubSearchPeriodInt;
7756 _cfgCommon.ListsPeriod = SettingDialog.ListsPeriodInt;
7757 _cfgCommon.UserTimelinePeriod = SettingDialog.UserTimelinePeriodInt;
7758 _cfgCommon.Read = SettingDialog.Readed;
7759 _cfgCommon.IconSize = SettingDialog.IconSz;
7760 _cfgCommon.UnreadManage = SettingDialog.UnreadManage;
7761 _cfgCommon.PlaySound = SettingDialog.PlaySound;
7762 _cfgCommon.OneWayLove = SettingDialog.OneWayLove;
7764 _cfgCommon.NameBalloon = SettingDialog.NameBalloon;
7765 _cfgCommon.PostCtrlEnter = SettingDialog.PostCtrlEnter;
7766 _cfgCommon.PostShiftEnter = SettingDialog.PostShiftEnter;
7767 _cfgCommon.CountApi = SettingDialog.CountApi;
7768 _cfgCommon.CountApiReply = SettingDialog.CountApiReply;
7769 _cfgCommon.PostAndGet = SettingDialog.PostAndGet;
7770 _cfgCommon.DispUsername = SettingDialog.DispUsername;
7771 _cfgCommon.MinimizeToTray = SettingDialog.MinimizeToTray;
7772 _cfgCommon.CloseToExit = SettingDialog.CloseToExit;
7773 _cfgCommon.DispLatestPost = SettingDialog.DispLatestPost;
7774 _cfgCommon.SortOrderLock = SettingDialog.SortOrderLock;
7775 _cfgCommon.ViewTabBottom = SettingDialog.ViewTabBottom;
7776 _cfgCommon.TinyUrlResolve = SettingDialog.TinyUrlResolve;
7777 _cfgCommon.StartupVersion = SettingDialog.StartupVersion;
7778 _cfgCommon.StartupFollowers = SettingDialog.StartupFollowers;
7779 _cfgCommon.RestrictFavCheck = SettingDialog.RestrictFavCheck;
7780 _cfgCommon.AlwaysTop = SettingDialog.AlwaysTop;
7781 _cfgCommon.UrlConvertAuto = SettingDialog.UrlConvertAuto;
7782 _cfgCommon.UseUnreadStyle = SettingDialog.UseUnreadStyle;
7783 _cfgCommon.DateTimeFormat = SettingDialog.DateTimeFormat;
7784 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7785 _cfgCommon.RetweetNoConfirm = SettingDialog.RetweetNoConfirm;
7786 _cfgCommon.LimitBalloon = SettingDialog.LimitBalloon;
7787 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7788 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7789 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7790 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7791 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7792 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7793 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7794 _cfgCommon.AutoShortUrlFirst = SettingDialog.AutoShortUrlFirst;
7795 _cfgCommon.TabIconDisp = SettingDialog.TabIconDisp;
7796 _cfgCommon.ReplyIconState = SettingDialog.ReplyIconState;
7797 _cfgCommon.ReadOwnPost = SettingDialog.ReadOwnPost;
7798 _cfgCommon.GetFav = SettingDialog.GetFav;
7799 _cfgCommon.IsMonospace = SettingDialog.IsMonospace;
7800 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7801 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7803 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7805 _cfgCommon.ReadOldPosts = SettingDialog.ReadOldPosts;
7806 _cfgCommon.BilyUser = SettingDialog.BitlyUser;
7807 _cfgCommon.BitlyPwd = SettingDialog.BitlyPwd;
7808 _cfgCommon.ShowGrid = SettingDialog.ShowGrid;
7809 _cfgCommon.UseAtIdSupplement = SettingDialog.UseAtIdSupplement;
7810 _cfgCommon.UseHashSupplement = SettingDialog.UseHashSupplement;
7811 _cfgCommon.PreviewEnable = SettingDialog.PreviewEnable;
7812 _cfgCommon.StatusAreaAtBottom = SettingDialog.StatusAreaAtBottom;
7813 _cfgCommon.Language = SettingDialog.Language;
7815 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7816 switch (_statuses.SortMode)
7818 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7819 _cfgCommon.SortColumn = 1;
7821 case IdComparerClass.ComparerMode.Data: //本文
7822 _cfgCommon.SortColumn = 2;
7824 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7825 _cfgCommon.SortColumn = 3;
7827 case IdComparerClass.ComparerMode.Name: //名前
7828 _cfgCommon.SortColumn = 4;
7830 case IdComparerClass.ComparerMode.Source: //Source
7831 _cfgCommon.SortColumn = 7;
7835 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7836 _cfgCommon.HashTags = HashMgr.HashHistories;
7837 if (HashMgr.IsPermanent)
7839 _cfgCommon.HashSelected = HashMgr.UseHash;
7843 _cfgCommon.HashSelected = "";
7845 _cfgCommon.HashIsHead = HashMgr.IsHead;
7846 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7847 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7848 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7849 _cfgCommon.HotkeyEnabled = SettingDialog.HotkeyEnabled;
7850 _cfgCommon.HotkeyModifier = SettingDialog.HotkeyMod;
7851 _cfgCommon.HotkeyKey = SettingDialog.HotkeyKey;
7852 _cfgCommon.HotkeyValue = SettingDialog.HotkeyValue;
7853 _cfgCommon.BlinkNewMentions = SettingDialog.BlinkNewMentions;
7854 if (ToolStripFocusLockMenuItem != null &&
7855 ToolStripFocusLockMenuItem.IsDisposed == false)
7857 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7859 _cfgCommon.UseAdditionalCount = SettingDialog.UseAdditionalCount;
7860 _cfgCommon.MoreCountApi = SettingDialog.MoreCountApi;
7861 _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi;
7862 _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi;
7863 _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi;
7864 _cfgCommon.UserTimelineCountApi = SettingDialog.UserTimelineCountApi;
7865 _cfgCommon.TrackWord = tw.TrackWord;
7866 _cfgCommon.AllAtReply = tw.AllAtReply;
7867 _cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
7868 _cfgCommon.ListCountApi = SettingDialog.ListCountApi;
7869 _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
7870 _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
7871 _cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
7872 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7873 _cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
7874 _cfgCommon.EnableImgAzyobuziNet = SettingDialog.EnableImgAzyobuziNet;
7875 _cfgCommon.ImgAzyobuziNetDisabledInDM = SettingDialog.ImgAzyobuziNetDisabledInDM;
7876 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7877 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7878 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7879 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7880 _cfgCommon.IsListsIncludeRts = SettingDialog.IsListStatusesIncludeRts;
7881 _cfgCommon.TabMouseLock = SettingDialog.TabMouseLock;
7882 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7883 _cfgCommon.IsUseNotifyGrowl = SettingDialog.IsNotifyUseGrowl;
7889 private void SaveConfigsLocal()
7891 if (_ignoreConfigSave) return;
7894 _modifySettingLocal = false;
7895 _cfgLocal.FormSize = _mySize;
7896 _cfgLocal.FormLocation = _myLoc;
7897 _cfgLocal.SplitterDistance = _mySpDis;
7898 _cfgLocal.PreviewDistance = _mySpDis3;
7899 _cfgLocal.StatusMultiline = StatusText.Multiline;
7900 _cfgLocal.StatusTextHeight = _mySpDis2;
7901 _cfgLocal.StatusText = SettingDialog.Status;
7903 _cfgLocal.FontUnread = _fntUnread;
7904 _cfgLocal.ColorUnread = _clUnread;
7905 _cfgLocal.FontRead = _fntReaded;
7906 _cfgLocal.ColorRead = _clReaded;
7907 _cfgLocal.FontDetail = _fntDetail;
7908 _cfgLocal.ColorDetail = _clDetail;
7909 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7910 _cfgLocal.ColorDetailLink = _clDetailLink;
7911 _cfgLocal.ColorFav = _clFav;
7912 _cfgLocal.ColorOWL = _clOWL;
7913 _cfgLocal.ColorRetweet = _clRetweet;
7914 _cfgLocal.ColorSelf = _clSelf;
7915 _cfgLocal.ColorAtSelf = _clAtSelf;
7916 _cfgLocal.ColorTarget = _clTarget;
7917 _cfgLocal.ColorAtTarget = _clAtTarget;
7918 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7919 _cfgLocal.ColorAtTo = _clAtTo;
7920 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7921 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7922 _cfgLocal.ColorInputFont = _clInputFont;
7923 _cfgLocal.FontInputFont = _fntInputFont;
7925 _cfgLocal.BrowserPath = SettingDialog.BrowserPath;
7926 _cfgLocal.UseRecommendStatus = SettingDialog.UseRecommendStatus;
7927 _cfgLocal.ProxyType = SettingDialog.SelectedProxyType;
7928 _cfgLocal.ProxyAddress = SettingDialog.ProxyAddress;
7929 _cfgLocal.ProxyPort = SettingDialog.ProxyPort;
7930 _cfgLocal.ProxyUser = SettingDialog.ProxyUser;
7931 _cfgLocal.ProxyPassword = SettingDialog.ProxyPassword;
7932 if (_ignoreConfigSave) return;
7937 private void SaveConfigsTabs()
7939 SettingTabs tabSetting = new SettingTabs();
7940 for (int i = 0; i < ListTab.TabPages.Count; i++)
7942 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7947 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7950 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7951 if (ret != DialogResult.OK)
7954 var match = Twitter.StatusUrlRegex.Match(inputText);
7957 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7958 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7962 var statusId = long.Parse(match.Groups["StatusId"].Value);
7964 var post = this._statuses[statusId];
7969 post = await Task.Run(() =>
7971 PostClass newPost = null;
7973 var err = this.tw.GetStatusApi(false, statusId, ref newPost);
7974 if (!string.IsNullOrEmpty(err))
7975 throw new WebApiException(err);
7980 catch (WebApiException ex)
7982 var message = ex.Message;
7983 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7984 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7991 this.OpenRelatedTab(post);
7993 catch (TabException ex)
7995 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7999 private void SaveLogMenuItem_Click(object sender, EventArgs e)
8001 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
8002 Properties.Resources.SaveLogMenuItem_ClickText2,
8003 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
8004 if (rslt == DialogResult.Cancel) return;
8006 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
8007 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
8008 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
8009 SaveFileDialog1.FilterIndex = 0;
8010 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
8011 SaveFileDialog1.RestoreDirectory = true;
8013 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
8015 if (!SaveFileDialog1.ValidateNames) return;
8016 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
8018 if (rslt == DialogResult.Yes)
8021 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
8023 PostClass post = _statuses[_curTab.Text, idx];
8024 string protect = "";
8025 if (post.IsProtect) protect = "Protect";
8026 sw.WriteLine(post.Nickname + "\t" +
8027 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8028 post.CreatedAt.ToString() + "\t" +
8029 post.ScreenName + "\t" +
8030 post.StatusId.ToString() + "\t" +
8031 post.ImageUrl + "\t" +
8032 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8038 foreach (int idx in _curList.SelectedIndices)
8040 PostClass post = _statuses[_curTab.Text, idx];
8041 string protect = "";
8042 if (post.IsProtect) protect = "Protect";
8043 sw.WriteLine(post.Nickname + "\t" +
8044 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8045 post.CreatedAt.ToString() + "\t" +
8046 post.ScreenName + "\t" +
8047 post.StatusId.ToString() + "\t" +
8048 post.ImageUrl + "\t" +
8049 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8055 this.TopMost = SettingDialog.AlwaysTop;
8058 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
8060 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
8061 if (State == ModifierState.NotFlags) return;
8062 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
8065 e.IsInputKey = true;
8068 public bool TabRename(ref string tabName)
8071 string newTabText = null;
8072 using (InputTabName inputName = new InputTabName())
8074 inputName.TabName = tabName;
8075 inputName.ShowDialog();
8076 if (inputName.DialogResult == DialogResult.Cancel) return false;
8077 newTabText = inputName.TabName;
8079 this.TopMost = SettingDialog.AlwaysTop;
8080 if (!string.IsNullOrEmpty(newTabText))
8083 for (int i = 0; i < ListTab.TabCount; i++)
8085 if (ListTab.TabPages[i].Text == newTabText)
8087 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
8088 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8092 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
8093 for (int i = 0; i < ListTab.TabCount; i++)
8095 if (ListTab.TabPages[i].Text == tabName)
8097 ListTab.TabPages[i].Text = newTabText;
8100 _statuses.RenameTab(tabName, newTabText);
8102 for (int i = 0; i < ListTab.TabCount; i++)
8104 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
8106 if (ListTab.TabPages[i].Text == tabName)
8108 ListTab.TabPages[i].Text = newTabText;
8112 SaveConfigsCommon();
8114 _rclickTabName = newTabText;
8115 tabName = newTabText;
8124 private void ListTab_MouseClick(object sender, MouseEventArgs e)
8126 if (e.Button == MouseButtons.Middle)
8128 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
8130 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8132 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
8133 this.SaveConfigsTabs();
8140 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
8142 string tn = ListTab.SelectedTab.Text;
8146 private void ListTab_MouseDown(object sender, MouseEventArgs e)
8148 if (SettingDialog.TabMouseLock) return;
8149 Point cpos = new Point(e.X, e.Y);
8150 if (e.Button == MouseButtons.Left)
8152 for (int i = 0; i < ListTab.TabPages.Count; i++)
8154 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8157 _tabMouseDownPoint = e.Location;
8168 private void ListTab_DragEnter(object sender, DragEventArgs e)
8170 if (e.Data.GetDataPresent(typeof(TabPage)))
8171 e.Effect = DragDropEffects.Move;
8173 e.Effect = DragDropEffects.None;
8176 private void ListTab_DragDrop(object sender, DragEventArgs e)
8178 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8183 Point cpos = new Point(e.X, e.Y);
8184 Point spos = ListTab.PointToClient(cpos);
8186 for (i = 0; i < ListTab.TabPages.Count; i++)
8188 Rectangle rect = ListTab.GetTabRect(i);
8189 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8190 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8192 tn = ListTab.TabPages[i].Text;
8193 if (spos.X <= (rect.Left + rect.Right) / 2)
8202 //タブのないところにドロップ->最後尾へ移動
8203 if (string.IsNullOrEmpty(tn))
8205 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8207 i = ListTab.TabPages.Count - 1;
8210 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8211 if (tp.Text == tn) return;
8213 ReOrderTab(tp.Text, tn, bef);
8216 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8219 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8221 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8224 using (ControlTransaction.Layout(this.ListTab))
8227 for (int j = 0; j < ListTab.TabPages.Count; j++)
8229 if (ListTab.TabPages[j].Text == targetTabText)
8231 mTp = ListTab.TabPages[j];
8232 ListTab.TabPages.Remove(mTp);
8233 if (j < baseIndex) baseIndex -= 1;
8237 if (isBeforeBaseTab)
8238 ListTab.TabPages.Insert(baseIndex, mTp);
8240 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8246 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8248 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8249 //isReply:true=@,false=DM
8250 if (!StatusText.Enabled) return;
8251 if (_curList == null) return;
8252 if (_curTab == null) return;
8253 if (!this.ExistCurrentPost) return;
8255 // 複数あてリプライはReplyではなく通常ポスト
8256 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8257 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8258 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8260 if (_curList.SelectedIndices.Count > 0)
8263 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8266 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8269 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8270 StatusText.SelectionStart = StatusText.Text.Length;
8272 _reply_to_id = null;
8273 _reply_to_name = null;
8276 if (string.IsNullOrEmpty(StatusText.Text))
8280 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8281 StatusText.Text = "@" + _curPost.ScreenName + " ";
8282 if (_curPost.RetweetedId != null)
8284 _reply_to_id = _curPost.RetweetedId.Value;
8288 _reply_to_id = _curPost.StatusId;
8290 _reply_to_name = _curPost.ScreenName;
8298 //1件選んでEnter or DoubleClick
8299 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8301 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8304 if (_curPost.RetweetedId != null)
8306 _reply_to_id = _curPost.RetweetedId.Value;
8310 _reply_to_id = _curPost.StatusId;
8312 _reply_to_name = _curPost.ScreenName;
8316 if (!StatusText.Text.StartsWith("@"))
8319 if (StatusText.Text.StartsWith(". "))
8322 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8323 _reply_to_id = null;
8324 _reply_to_name = null;
8329 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8330 if (_curPost.RetweetedId != null)
8332 _reply_to_id = _curPost.RetweetedId.Value;
8336 _reply_to_id = _curPost.StatusId;
8338 _reply_to_name = _curPost.ScreenName;
8345 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8346 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8347 _reply_to_id = null;
8348 _reply_to_name = null;
8353 //1件選んでCtrl-Rの場合(返信先操作せず)
8354 int sidx = StatusText.SelectionStart;
8355 string id = "@" + _curPost.ScreenName + " ";
8358 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8363 StatusText.Text = StatusText.Text.Insert(sidx, id);
8365 //if (StatusText.Text.StartsWith("@"))
8368 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8369 // sidx += 5 + _curPost.ScreenName.Length;
8374 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8375 // sidx += 3 + _curPost.ScreenName.Length;
8377 StatusText.SelectionStart = sidx;
8380 //_reply_to_name = null;
8388 if (!isAuto && !isReply) return;
8390 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8394 //Enter or DoubleClick
8396 string sTxt = StatusText.Text;
8397 if (!sTxt.StartsWith(". "))
8400 _reply_to_id = null;
8401 _reply_to_name = null;
8403 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8405 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8406 if (!sTxt.Contains("@" + post.ScreenName + " "))
8408 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8409 //sTxt = "@" + post.ScreenName + " " + sTxt;
8412 StatusText.Text = sTxt;
8417 if (_curList.SelectedIndices.Count > 1)
8422 int sidx = StatusText.SelectionStart;
8423 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8425 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8426 if (!ids.Contains("@" + post.ScreenName + " ") &&
8427 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8429 ids += "@" + post.ScreenName + " ";
8433 foreach (string nm in post.ReplyToList)
8435 if (!ids.Contains("@" + nm + " ") &&
8436 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8438 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8440 ids += "@" + m.Result("${id}") + " ";
8442 ids += "@" + nm + " ";
8447 if (ids.Length == 0) return;
8448 if (!StatusText.Text.StartsWith(". "))
8450 StatusText.Text = ". " + StatusText.Text;
8452 _reply_to_id = null;
8453 _reply_to_name = null;
8457 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8462 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8464 //if (StatusText.Text.StartsWith("@"))
8466 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8467 // sidx += 2 + ids.Length;
8471 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8472 // sidx += 1 + ids.Length;
8474 StatusText.SelectionStart = sidx;
8480 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8483 int sidx = StatusText.SelectionStart;
8484 PostClass post = _curPost;
8485 if (!ids.Contains("@" + post.ScreenName + " ") &&
8486 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8488 ids += "@" + post.ScreenName + " ";
8490 foreach (string nm in post.ReplyToList)
8492 if (!ids.Contains("@" + nm + " ") &&
8493 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8495 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8497 ids += "@" + m.Result("${id}") + " ";
8499 ids += "@" + nm + " ";
8502 if (!string.IsNullOrEmpty(post.RetweetedBy))
8504 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8505 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8507 ids += "@" + post.RetweetedBy + " ";
8510 if (ids.Length == 0) return;
8511 if (string.IsNullOrEmpty(StatusText.Text))
8514 StatusText.Text = ids;
8515 StatusText.SelectionStart = ids.Length;
8517 if (post.RetweetedId != null)
8519 _reply_to_id = post.RetweetedId.Value;
8523 _reply_to_id = post.StatusId;
8525 _reply_to_name = post.ScreenName;
8531 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8536 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8538 StatusText.SelectionStart = sidx;
8544 StatusText.SelectionStart = StatusText.Text.Length;
8549 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8554 private static int iconCnt = 0;
8555 private static int blinkCnt = 0;
8556 private static bool blink = false;
8557 private static bool idle = false;
8559 private void RefreshTasktrayIcon(bool forceRefresh)
8561 if (_colorize) Colorize();
8562 if (!TimerRefreshIcon.Enabled) return;
8563 //Static usCheckCnt As int = 0
8565 //Static iconDlListTopItem As ListViewItem = null
8567 if (forceRefresh) idle = false;
8569 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8570 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8572 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8574 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8580 //if (usCheckCnt > 300) //1min
8583 // if (!this.IsReceivedUserStream)
8585 // TraceOut("ReconnectUserStream");
8586 // tw.ReconnectUserStream();
8591 foreach (BackgroundWorker bw in this._bw)
8593 if (bw != null && bw.IsBusy)
8608 SaveConfigsAll(true);
8613 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8615 _myStatusError = false;
8619 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8620 if (SettingDialog.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8622 if (blinkCnt > 0) return;
8624 if (blink || SettingDialog.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8626 NotifyIcon1.Icon = ReplyIcon;
8630 NotifyIcon1.Icon = ReplyIconBlink;
8638 //優先度:エラー→オフライン→アイドル
8642 NotifyIcon1.Icon = NIconAtRed;
8645 if (_myStatusOnline)
8647 NotifyIcon1.Icon = NIconAt;
8651 NotifyIcon1.Icon = NIconAtSmoke;
8655 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8658 this.RefreshTasktrayIcon(false);
8661 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8663 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8664 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8666 if (ListTab != null && ListTab.SelectedTab != null)
8667 _rclickTabName = ListTab.SelectedTab.Text;
8672 if (_statuses == null) return;
8673 if (_statuses.Tabs == null) return;
8675 TabClass tb = _statuses.Tabs[_rclickTabName];
8676 if (tb == null) return;
8678 NotifyDispMenuItem.Checked = tb.Notify;
8679 this.NotifyTbMenuItem.Checked = tb.Notify;
8681 soundfileListup = true;
8682 SoundFileComboBox.Items.Clear();
8683 this.SoundFileTbComboBox.Items.Clear();
8684 SoundFileComboBox.Items.Add("");
8685 this.SoundFileTbComboBox.Items.Add("");
8686 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8687 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8689 oDir = oDir.GetDirectories("Sounds")[0];
8691 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8693 SoundFileComboBox.Items.Add(oFile.Name);
8694 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8696 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8697 if (idx == -1) idx = 0;
8698 SoundFileComboBox.SelectedIndex = idx;
8699 this.SoundFileTbComboBox.SelectedIndex = idx;
8700 soundfileListup = false;
8701 UreadManageMenuItem.Checked = tb.UnreadManage;
8702 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8704 TabMenuControl(_rclickTabName);
8707 private void TabMenuControl(string tabName)
8709 this.FilterEditMenuItem.Enabled = true;
8710 this.EditRuleTbMenuItem.Enabled = true;
8712 if (_statuses.IsDefaultTab(tabName))
8714 this.ProtectTabMenuItem.Enabled = false;
8715 this.ProtectTbMenuItem.Enabled = false;
8719 this.ProtectTabMenuItem.Enabled = true;
8720 this.ProtectTbMenuItem.Enabled = true;
8723 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8725 this.ProtectTabMenuItem.Checked = true;
8726 this.ProtectTbMenuItem.Checked = true;
8727 this.DeleteTabMenuItem.Enabled = false;
8728 this.DeleteTbMenuItem.Enabled = false;
8732 this.ProtectTabMenuItem.Checked = false;
8733 this.ProtectTbMenuItem.Checked = false;
8734 this.DeleteTabMenuItem.Enabled = true;
8735 this.DeleteTbMenuItem.Enabled = true;
8739 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8741 var checkState = ((ToolStripMenuItem)sender).Checked;
8744 this.ProtectTbMenuItem.Checked = checkState;
8745 this.ProtectTabMenuItem.Checked = checkState;
8748 this.DeleteTabMenuItem.Enabled = !checkState;
8749 this.DeleteTbMenuItem.Enabled = !checkState;
8751 if (string.IsNullOrEmpty(_rclickTabName)) return;
8752 _statuses.Tabs[_rclickTabName].Protected = checkState;
8757 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8759 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8760 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8762 if (string.IsNullOrEmpty(_rclickTabName)) return;
8763 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8768 public void ChangeTabUnreadManage(string tabName, bool isManage)
8771 for (idx = 0; idx < ListTab.TabCount; idx++)
8773 if (ListTab.TabPages[idx].Text == tabName) break;
8776 _statuses.SetTabUnreadManage(tabName, isManage);
8777 if (SettingDialog.TabIconDisp)
8779 if (_statuses.Tabs[tabName].UnreadCount > 0)
8780 ListTab.TabPages[idx].ImageIndex = 0;
8782 ListTab.TabPages[idx].ImageIndex = -1;
8785 if (_curTab.Text == tabName)
8787 this.PurgeListViewItemCache();
8791 SetMainWindowTitle();
8792 SetStatusLabelUrl();
8793 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8796 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8798 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8799 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8801 if (string.IsNullOrEmpty(_rclickTabName)) return;
8803 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8808 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8810 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8812 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8817 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8819 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8821 RemoveSpecifiedTab(_rclickTabName, true);
8825 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8827 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8828 fltDialog.SetCurrent(_rclickTabName);
8829 fltDialog.ShowDialog(this);
8830 this.TopMost = SettingDialog.AlwaysTop;
8832 this.ApplyPostFilters();
8836 private void AddTabMenuItem_Click(object sender, EventArgs e)
8838 string tabName = null;
8839 MyCommon.TabUsageType tabUsage;
8840 using (InputTabName inputName = new InputTabName())
8842 inputName.TabName = _statuses.GetUniqueTabName();
8843 inputName.IsShowUsage = true;
8844 inputName.ShowDialog();
8845 if (inputName.DialogResult == DialogResult.Cancel) return;
8846 tabName = inputName.TabName;
8847 tabUsage = inputName.Usage;
8849 this.TopMost = SettingDialog.AlwaysTop;
8850 if (!string.IsNullOrEmpty(tabName))
8853 ListElement list = null;
8854 if (tabUsage == MyCommon.TabUsageType.Lists)
8856 using (ListAvailable listAvail = new ListAvailable())
8858 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8859 if (listAvail.SelectedList == null) return;
8860 list = listAvail.SelectedList;
8863 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8865 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8866 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8872 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8874 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8875 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8876 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8878 if (tabUsage == MyCommon.TabUsageType.Lists)
8880 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8881 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8882 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, tabName);
8888 private void TabMenuItem_Click(object sender, EventArgs e)
8891 foreach (int idx in _curList.SelectedIndices)
8895 if (!SelectTab(out tabName)) return;
8897 fltDialog.SetCurrent(tabName);
8898 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8900 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8904 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8906 fltDialog.ShowDialog(this);
8907 this.TopMost = SettingDialog.AlwaysTop;
8910 this.ApplyPostFilters();
8912 if (this.ListTab.SelectedTab != null &&
8913 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8915 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8919 protected override bool ProcessDialogKey(Keys keyData)
8921 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8922 if ((keyData & Keys.KeyCode) == Keys.Enter)
8924 if (StatusText.Focused)
8926 bool _NewLine = false;
8929 if (SettingDialog.PostCtrlEnter) //Ctrl+Enter投稿時
8931 if (StatusText.Multiline)
8933 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8935 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8939 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8943 else if (SettingDialog.PostShiftEnter) //SHift+Enter投稿時
8945 if (StatusText.Multiline)
8947 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8949 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8953 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8959 if (StatusText.Multiline)
8961 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8963 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8964 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8968 if (((keyData & Keys.Shift) == Keys.Shift) ||
8969 (((keyData & Keys.Control) != Keys.Control) &&
8970 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8976 int pos1 = StatusText.SelectionStart;
8977 if (StatusText.SelectionLength > 0)
8979 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8981 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8982 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8987 PostButton_Click(null, null);
8991 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8992 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8993 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8995 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
9000 return base.ProcessDialogKey(keyData);
9003 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
9005 MakeReplyOrDirectStatus(false, true, true);
9008 private void IDRuleMenuItem_Click(object sender, EventArgs e)
9013 if (_curList.SelectedIndices.Count == 0) return;
9016 if (!SelectTab(out tabName)) return;
9020 MoveOrCopy(ref mv, ref mk);
9022 List<string> ids = new List<string>();
9023 foreach (int idx in _curList.SelectedIndices)
9025 PostClass post = _statuses[_curTab.Text, idx];
9026 if (!ids.Contains(post.ScreenName))
9028 PostFilterRule fc = new PostFilterRule();
9029 ids.Add(post.ScreenName);
9030 if (post.RetweetedId == null)
9032 fc.FilterName = post.ScreenName;
9036 fc.FilterName = post.RetweetedBy;
9038 fc.UseNameField = true;
9039 fc.MoveMatches = mv;
9040 fc.MarkMatches = mk;
9041 fc.UseRegex = false;
9042 fc.FilterByUrl = false;
9043 _statuses.Tabs[tabName].AddFilter(fc);
9048 List<string> atids = new List<string>();
9049 foreach (string id in ids)
9051 atids.Add("@" + id);
9053 int cnt = AtIdSupl.ItemCount;
9054 AtIdSupl.AddRangeItem(atids.ToArray());
9055 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
9058 this.ApplyPostFilters();
9062 private bool SelectTab(out string tabName)
9069 using (var dialog = new TabsDialog(_statuses))
9071 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
9073 var selectedTab = dialog.SelectedTab;
9074 tabName = selectedTab == null ? null : selectedTab.TabName;
9077 ListTab.SelectedTab.Focus();
9079 if (tabName == null)
9081 using (InputTabName inputName = new InputTabName())
9083 inputName.TabName = _statuses.GetUniqueTabName();
9084 inputName.ShowDialog();
9085 if (inputName.DialogResult == DialogResult.Cancel) return false;
9086 tabName = inputName.TabName;
9088 this.TopMost = SettingDialog.AlwaysTop;
9089 if (!string.IsNullOrEmpty(tabName))
9091 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
9093 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
9094 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
9112 private void MoveOrCopy(ref bool move, ref bool mark)
9116 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
9117 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9125 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
9126 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9132 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
9137 private void CopyURLMenuItem_Click(object sender, EventArgs e)
9142 private void SelectAllMenuItem_Click(object sender, EventArgs e)
9144 if (StatusText.Focused)
9147 StatusText.SelectAll();
9151 // ListView上でのCtrl+A
9152 for (int i = 0; i < _curList.VirtualListSize; i++)
9154 _curList.SelectedIndices.Add(i);
9159 private void MoveMiddle()
9165 if (_curList.SelectedIndices.Count == 0) return;
9167 int idx = _curList.SelectedIndices[0];
9169 _item = _curList.GetItemAt(0, 25);
9175 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9177 idx2 = _curList.VirtualListSize - 1;
9181 idx -= Math.Abs(idx1 - idx2) / 2;
9182 if (idx < 0) idx = 0;
9184 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9185 _curList.EnsureVisible(idx);
9188 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9190 if (PostBrowser.Document.Links.Count > 0)
9192 UrlDialog.ClearUrl();
9194 string openUrlStr = "";
9196 if (PostBrowser.Document.Links.Count == 1)
9201 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9203 catch (ArgumentException)
9212 if (string.IsNullOrEmpty(urlStr)) return;
9213 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9217 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9220 string linkText = "";
9224 urlStr = linkElm.GetAttribute("title");
9225 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9226 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9227 linkText = linkElm.InnerText;
9228 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9230 linkText = "@" + linkText;
9233 catch (ArgumentException)
9242 if (string.IsNullOrEmpty(urlStr)) continue;
9243 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9247 if (UrlDialog.ShowDialog() == DialogResult.OK)
9249 openUrlStr = UrlDialog.SelectedUrl;
9256 this.TopMost = SettingDialog.AlwaysTop;
9258 if (string.IsNullOrEmpty(openUrlStr)) return;
9260 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9261 openUrlStr.StartsWith("https://twitter.com/search?q="))
9264 string urlStr = Uri.UnescapeDataString(openUrlStr);
9265 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9266 HashSupl.AddItem(hash);
9267 HashMgr.AddHashToHistory(hash.Trim(), false);
9268 AddNewTabForSearch(hash);
9273 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9274 if (SettingDialog.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9275 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9277 OpenUriAsync(openUrlStr);
9283 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9285 if (string.IsNullOrEmpty(_rclickTabName)) return;
9286 ClearTab(_rclickTabName, true);
9289 private void ClearTab(string tabName, bool showWarning)
9293 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9294 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9300 _statuses.ClearTabIds(tabName);
9301 if (ListTab.SelectedTab.Text == tabName)
9304 _anchorFlag = false;
9305 this.PurgeListViewItemCache();
9309 foreach (TabPage tb in ListTab.TabPages)
9311 if (tb.Text == tabName)
9314 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9318 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9320 SetMainWindowTitle();
9321 SetStatusLabelUrl();
9324 private static long followers = 0;
9326 private void SetMainWindowTitle()
9329 StringBuilder ttl = new StringBuilder(256);
9332 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
9333 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9334 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9335 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9337 foreach (var tab in _statuses.Tabs.Values)
9339 ur += tab.UnreadCount;
9344 if (SettingDialog.DispUsername) ttl.Append(tw.Username).Append(" - ");
9345 ttl.Append(Application.ProductName);
9347 switch (SettingDialog.DispLatestPost)
9349 case MyCommon.DispTitleEnum.Ver:
9350 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9352 case MyCommon.DispTitleEnum.Post:
9353 if (_history != null && _history.Count > 1)
9354 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9356 case MyCommon.DispTitleEnum.UnreadRepCount:
9357 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9359 case MyCommon.DispTitleEnum.UnreadAllCount:
9360 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9362 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9363 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9365 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9366 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9368 case MyCommon.DispTitleEnum.OwnStatus:
9369 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9370 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9376 this.Text = ttl.ToString();
9378 catch (AccessViolationException)
9380 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9384 private string GetStatusLabelText()
9387 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9388 if (_statuses == null) return "";
9389 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9390 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9391 if (tbRep == null || tbDm == null) return "";
9392 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9397 StringBuilder slbl = new StringBuilder(256);
9400 foreach (var tab in _statuses.Tabs.Values)
9402 ur += tab.UnreadCount;
9404 if (_curTab != null && tab.TabName.Equals(_curTab.Text))
9406 tur = tab.UnreadCount;
9417 UnreadAtCounter = urat;
9419 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9420 if (SettingDialog.TimelinePeriodInt == 0)
9422 slbl.Append(Properties.Resources.SetStatusLabelText2);
9426 slbl.Append(SettingDialog.TimelinePeriodInt.ToString() + Properties.Resources.SetStatusLabelText3);
9428 return slbl.ToString();
9431 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9435 if (this.InvokeRequired && !this.IsDisposed)
9437 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9441 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9442 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9444 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9448 catch (ObjectDisposedException)
9452 catch (InvalidOperationException)
9458 private void SetStatusLabelUrl()
9460 StatusLabelUrl.Text = GetStatusLabelText();
9463 public void SetStatusLabel(string text)
9465 StatusLabel.Text = text;
9468 private static StringBuilder ur = new StringBuilder(64);
9470 private void SetNotifyIconText()
9472 // タスクトレイアイコンのツールチップテキスト書き換え
9474 ur.Remove(0, ur.Length);
9475 if (SettingDialog.DispUsername)
9477 ur.Append(tw.Username);
9480 ur.Append(Application.ProductName);
9482 ur.Append("(Debug Build)");
9484 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9487 ur.Append(UnreadCounter);
9489 ur.Append(UnreadAtCounter);
9492 NotifyIcon1.Text = ur.ToString();
9495 internal void CheckReplyTo(string StatusText)
9499 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9501 foreach (Match hm in m)
9503 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9505 hstr += "#" + hm.Result("$3") + " ";
9506 HashSupl.AddItem("#" + hm.Result("$3"));
9509 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9511 hstr += HashMgr.UseHash;
9513 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9515 // 本当にリプライ先指定すべきかどうかの判定
9516 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9518 if (SettingDialog.UseAtIdSupplement)
9520 int bCnt = AtIdSupl.ItemCount;
9521 foreach (Match mid in m)
9523 AtIdSupl.AddItem(mid.Result("${id}"));
9525 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9528 // リプライ先ステータスIDの指定がない場合は指定しない
9529 if (_reply_to_id == null) return;
9531 // リプライ先ユーザー名がない場合も指定しない
9532 if (string.IsNullOrEmpty(_reply_to_name))
9534 _reply_to_id = null;
9539 // 次の条件を満たす場合に in_reply_to_status_id 指定
9540 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9541 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9542 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9546 if (StatusText.StartsWith("@"))
9548 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9552 foreach (Match mid in m)
9554 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9559 _reply_to_id = null;
9560 _reply_to_name = null;
9564 private void TweenMain_Resize(object sender, EventArgs e)
9566 if (!_initialLayout && SettingDialog.MinimizeToTray && WindowState == FormWindowState.Minimized)
9568 this.Visible = false;
9570 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9572 this.ClientSize = _cfgLocal.FormSize;
9573 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9574 this.DesktopLocation = _cfgLocal.FormLocation;
9575 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9576 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9577 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9579 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9582 StatusText.Multiline = _cfgLocal.StatusMultiline;
9583 if (StatusText.Multiline)
9585 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9586 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9588 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9590 StatusText.Height = _cfgLocal.StatusTextHeight;
9594 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9596 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9599 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9601 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9603 _initialLayout = false;
9605 if (this.WindowState != FormWindowState.Minimized)
9607 _formWindowState = this.WindowState;
9611 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9613 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9614 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9615 if (PlaySoundMenuItem.Checked)
9617 SettingDialog.PlaySound = true;
9621 SettingDialog.PlaySound = false;
9623 _modifySettingCommon = true;
9626 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9628 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9630 _mySpDis = SplitContainer1.SplitterDistance;
9631 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9632 _modifySettingLocal = true;
9636 private void doRepliedStatusOpen()
9638 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9640 if (MyCommon.IsKeyDown(Keys.Shift))
9642 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9645 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9647 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9648 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9652 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9654 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9655 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9656 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9659 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9664 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9666 doRepliedStatusOpen();
9670 /// UserPicture.Image に設定されている画像を破棄します。
9672 private void ClearUserPicture()
9674 if (this.UserPicture.Image != null)
9676 var oldImage = this.UserPicture.Image;
9677 this.UserPicture.Image = null;
9682 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9684 //発言詳細のアイコン右クリック時のメニュー制御
9685 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9687 string name = _curPost.ImageUrl;
9688 if (name != null && name.Length > 0)
9690 int idx = name.LastIndexOf('/');
9693 name = Path.GetFileName(name.Substring(idx));
9694 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9696 name = name.Replace("_normal", "");
9697 this.IconNameToolStripMenuItem.Text = name;
9698 this.IconNameToolStripMenuItem.Enabled = true;
9702 this.IconNameToolStripMenuItem.Enabled = false;
9703 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9708 this.IconNameToolStripMenuItem.Enabled = false;
9709 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9712 this.ReloadIconToolStripMenuItem.Enabled = true;
9714 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9716 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9720 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9725 this.IconNameToolStripMenuItem.Enabled = false;
9726 this.ReloadIconToolStripMenuItem.Enabled = false;
9727 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9728 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9733 this.IconNameToolStripMenuItem.Enabled = false;
9734 this.ReloadIconToolStripMenuItem.Enabled = false;
9735 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9736 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9738 if (NameLabel.Tag != null)
9740 string id = (string)NameLabel.Tag;
9741 if (id == tw.Username)
9743 FollowToolStripMenuItem.Enabled = false;
9744 UnFollowToolStripMenuItem.Enabled = false;
9745 ShowFriendShipToolStripMenuItem.Enabled = false;
9746 ShowUserStatusToolStripMenuItem.Enabled = true;
9747 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9748 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9749 ListManageUserContextToolStripMenuItem3.Enabled = true;
9753 FollowToolStripMenuItem.Enabled = true;
9754 UnFollowToolStripMenuItem.Enabled = true;
9755 ShowFriendShipToolStripMenuItem.Enabled = true;
9756 ShowUserStatusToolStripMenuItem.Enabled = true;
9757 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9758 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9759 ListManageUserContextToolStripMenuItem3.Enabled = true;
9764 FollowToolStripMenuItem.Enabled = false;
9765 UnFollowToolStripMenuItem.Enabled = false;
9766 ShowFriendShipToolStripMenuItem.Enabled = false;
9767 ShowUserStatusToolStripMenuItem.Enabled = false;
9768 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9769 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9770 ListManageUserContextToolStripMenuItem3.Enabled = false;
9774 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9776 if (_curPost == null) return;
9777 string name = _curPost.ImageUrl;
9778 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9781 private async void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9783 if (this._curPost == null) return;
9785 await this.UserPicture.SetImageFromTask(async () =>
9787 var imageUrl = this._curPost.ImageUrl;
9789 var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
9790 .ConfigureAwait(false);
9792 return await image.CloneAsync()
9793 .ConfigureAwait(false);
9797 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9799 if (_curPost == null) return;
9800 string name = _curPost.ImageUrl;
9801 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9803 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9805 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9811 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9813 if (_curPost == null) return;
9814 string name = _curPost.ImageUrl;
9816 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9818 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9822 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9824 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9826 using (Graphics g = Graphics.FromImage(bmp2))
9828 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9829 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9831 bmp2.Save(this.SaveFileDialog1.FileName);
9837 //処理中にキャッシュアウトする可能性あり
9842 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9844 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9845 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9846 _modifySettingLocal = true;
9849 private void StatusText_MultilineChanged(object sender, EventArgs e)
9851 if (this.StatusText.Multiline)
9852 this.StatusText.ScrollBars = ScrollBars.Vertical;
9854 this.StatusText.ScrollBars = ScrollBars.None;
9856 _modifySettingLocal = true;
9859 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9862 StatusText.Multiline = MultiLineMenuItem.Checked;
9863 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9864 if (MultiLineMenuItem.Checked)
9866 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9867 SplitContainer2.SplitterDistance = 0;
9869 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9873 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9875 _modifySettingLocal = true;
9878 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
9880 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9881 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9883 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9884 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9885 //Appendix A. Collected ABNF for URI
9886 //http://www.ietf.org/rfc/rfc3986.txt
9890 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9892 if (StatusText.SelectionLength > 0)
9894 string tmp = StatusText.SelectedText;
9895 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9896 if (tmp.StartsWith("http"))
9898 // 文字列が選択されている場合はその文字列について処理
9900 //nico.ms使用、nicovideoにマッチしたら変換
9901 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9903 result = nicoms.Shorten(tmp);
9905 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9907 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9910 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9911 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9912 result = resultUri.ToString();
9914 catch (WebApiException e)
9916 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9919 catch (UriFormatException e)
9921 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9930 if (!string.IsNullOrEmpty(result))
9932 urlUndo undotmp = new urlUndo();
9934 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9935 StatusText.SelectedText = result;
9938 undotmp.Before = tmp;
9939 undotmp.After = result;
9941 if (urlUndoBuffer == null)
9943 urlUndoBuffer = new List<urlUndo>();
9944 UrlUndoToolStripMenuItem.Enabled = true;
9947 urlUndoBuffer.Add(undotmp);
9953 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9954 @"(?<url>(?<protocol>https?://)" +
9955 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9956 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9957 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9958 // 正規表現にマッチしたURL文字列をtinyurl化
9959 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9961 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9962 string tmp = mt.Result("${url}");
9963 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9964 urlUndo undotmp = new urlUndo();
9967 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9969 //nico.ms使用、nicovideoにマッチしたら変換
9970 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9972 result = nicoms.Shorten(tmp);
9974 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9976 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9979 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9980 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9981 result = resultUri.ToString();
9983 catch (HttpRequestException e)
9985 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
9986 // のように長いので「:」が含まれていればそれ以降のみを抽出する
9987 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
9989 this.StatusLabel.Text = Converter_Type + ":" + message;
9992 catch (WebApiException e)
9994 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9997 catch (UriFormatException e)
9999 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
10008 if (!string.IsNullOrEmpty(result))
10010 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
10011 StatusText.SelectedText = result;
10013 undotmp.Before = mt.Result("${url}");
10014 undotmp.After = result;
10016 if (urlUndoBuffer == null)
10018 urlUndoBuffer = new List<urlUndo>();
10019 UrlUndoToolStripMenuItem.Enabled = true;
10022 urlUndoBuffer.Add(undotmp);
10030 private void doUrlUndo()
10032 if (urlUndoBuffer != null)
10034 string tmp = StatusText.Text;
10035 foreach (urlUndo data in urlUndoBuffer)
10037 tmp = tmp.Replace(data.After, data.Before);
10039 StatusText.Text = tmp;
10040 urlUndoBuffer = null;
10041 UrlUndoToolStripMenuItem.Enabled = false;
10042 StatusText.SelectionStart = 0;
10043 StatusText.SelectionLength = 0;
10047 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
10049 await UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
10052 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
10054 await UrlConvertAsync(MyCommon.UrlConverter.Isgd);
10057 private async void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
10059 await UrlConvertAsync(MyCommon.UrlConverter.Twurl);
10062 private async void UxnuMenuItem_Click(object sender, EventArgs e)
10064 await UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
10067 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
10069 if (!await UrlConvertAsync(SettingDialog.AutoShortUrlFirst))
10071 MyCommon.UrlConverter svc = SettingDialog.AutoShortUrlFirst;
10072 Random rnd = new Random();
10073 // 前回使用した短縮URLサービス以外を選択する
10076 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
10078 while (svc == SettingDialog.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
10079 await UrlConvertAsync(svc);
10083 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
10088 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
10090 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10091 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
10092 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
10093 _modifySettingCommon = true;
10096 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
10098 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10099 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
10100 _cfgCommon.ListLock = ListLockMenuItem.Checked;
10101 _modifySettingCommon = true;
10104 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
10106 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
10107 MenuStrip1.Tag = new Object();
10108 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
10111 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
10113 if (this.Tag != null) // 設定された戻り先へ遷移
10115 if (this.Tag == this.ListTab.SelectedTab)
10116 ((Control)this.ListTab.SelectedTab.Tag).Select();
10118 ((Control)this.Tag).Select();
10120 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
10122 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
10124 this.Tag = ListTab.SelectedTab.Tag;
10125 ((Control)this.Tag).Select();
10128 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
10129 MenuStrip1.Tag = null;
10132 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
10134 DetailsListView lst = (DetailsListView)sender;
10135 if (_cfgLocal == null) return;
10139 _cfgLocal.Width1 = lst.Columns[0].Width;
10140 _cfgLocal.Width3 = lst.Columns[1].Width;
10144 int[] darr = new int[lst.Columns.Count];
10145 for (int i = 0; i < lst.Columns.Count; i++)
10147 darr[lst.Columns[i].DisplayIndex] = i;
10149 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
10151 for (int i = 0; i < lst.Columns.Count; i++)
10156 _cfgLocal.DisplayIndex1 = i;
10159 _cfgLocal.DisplayIndex2 = i;
10162 _cfgLocal.DisplayIndex3 = i;
10165 _cfgLocal.DisplayIndex4 = i;
10168 _cfgLocal.DisplayIndex5 = i;
10171 _cfgLocal.DisplayIndex6 = i;
10174 _cfgLocal.DisplayIndex7 = i;
10177 _cfgLocal.DisplayIndex8 = i;
10181 _cfgLocal.Width1 = lst.Columns[0].Width;
10182 _cfgLocal.Width2 = lst.Columns[1].Width;
10183 _cfgLocal.Width3 = lst.Columns[2].Width;
10184 _cfgLocal.Width4 = lst.Columns[3].Width;
10185 _cfgLocal.Width5 = lst.Columns[4].Width;
10186 _cfgLocal.Width6 = lst.Columns[5].Width;
10187 _cfgLocal.Width7 = lst.Columns[6].Width;
10188 _cfgLocal.Width8 = lst.Columns[7].Width;
10190 _modifySettingLocal = true;
10191 _isColumnChanged = true;
10194 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10196 DetailsListView lst = (DetailsListView)sender;
10197 if (_cfgLocal == null) return;
10200 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10202 _cfgLocal.Width1 = lst.Columns[0].Width;
10203 _modifySettingLocal = true;
10204 _isColumnChanged = true;
10206 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10208 _cfgLocal.Width3 = lst.Columns[1].Width;
10209 _modifySettingLocal = true;
10210 _isColumnChanged = true;
10215 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10217 _cfgLocal.Width1 = lst.Columns[0].Width;
10218 _modifySettingLocal = true;
10219 _isColumnChanged = true;
10221 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10223 _cfgLocal.Width2 = lst.Columns[1].Width;
10224 _modifySettingLocal = true;
10225 _isColumnChanged = true;
10227 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10229 _cfgLocal.Width3 = lst.Columns[2].Width;
10230 _modifySettingLocal = true;
10231 _isColumnChanged = true;
10233 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10235 _cfgLocal.Width4 = lst.Columns[3].Width;
10236 _modifySettingLocal = true;
10237 _isColumnChanged = true;
10239 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10241 _cfgLocal.Width5 = lst.Columns[4].Width;
10242 _modifySettingLocal = true;
10243 _isColumnChanged = true;
10245 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10247 _cfgLocal.Width6 = lst.Columns[5].Width;
10248 _modifySettingLocal = true;
10249 _isColumnChanged = true;
10251 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10253 _cfgLocal.Width7 = lst.Columns[6].Width;
10254 _modifySettingLocal = true;
10255 _isColumnChanged = true;
10257 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10259 _cfgLocal.Width8 = lst.Columns[7].Width;
10260 _modifySettingLocal = true;
10261 _isColumnChanged = true;
10264 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10267 // SaveConfigsLocal();
10271 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10273 //発言詳細で「選択文字列をコピー」を行う
10274 //WebBrowserコンポーネントのインスタンスを渡す
10275 Type typ = ComponentInstance.ActiveXInstance.GetType();
10276 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10277 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10278 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10281 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10284 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10287 Clipboard.SetDataObject(_selText, false, 5, 100);
10289 catch (Exception ex)
10291 MessageBox.Show(ex.Message);
10295 private void doSearchToolStrip(string url)
10297 //発言詳細で「選択文字列で検索」(選択文字列取得)
10298 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10300 if (_selText != null)
10302 if (url == Properties.Resources.SearchItem4Url)
10305 AddNewTabForSearch(_selText);
10309 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10314 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10317 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10320 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10322 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10325 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10327 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10330 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10332 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10335 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10339 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10340 foreach (Match m in mc)
10342 if (m.Groups["url"].Value == this._postBrowserStatusText)
10344 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10350 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10352 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10354 catch (Exception ex)
10356 MessageBox.Show(ex.Message);
10360 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10362 // URLコピーの項目の表示/非表示
10363 if (PostBrowser.StatusText.StartsWith("http"))
10365 this._postBrowserStatusText = PostBrowser.StatusText;
10366 string name = GetUserId();
10367 UrlCopyContextMenuItem.Enabled = true;
10370 FollowContextMenuItem.Enabled = true;
10371 RemoveContextMenuItem.Enabled = true;
10372 FriendshipContextMenuItem.Enabled = true;
10373 ShowUserStatusContextMenuItem.Enabled = true;
10374 SearchPostsDetailToolStripMenuItem.Enabled = true;
10375 IdFilterAddMenuItem.Enabled = true;
10376 ListManageUserContextToolStripMenuItem.Enabled = true;
10377 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10381 FollowContextMenuItem.Enabled = false;
10382 RemoveContextMenuItem.Enabled = false;
10383 FriendshipContextMenuItem.Enabled = false;
10384 ShowUserStatusContextMenuItem.Enabled = false;
10385 SearchPostsDetailToolStripMenuItem.Enabled = false;
10386 IdFilterAddMenuItem.Enabled = false;
10387 ListManageUserContextToolStripMenuItem.Enabled = false;
10388 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10391 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10392 UseHashtagMenuItem.Enabled = true;
10394 UseHashtagMenuItem.Enabled = false;
10398 this._postBrowserStatusText = "";
10399 UrlCopyContextMenuItem.Enabled = false;
10400 FollowContextMenuItem.Enabled = false;
10401 RemoveContextMenuItem.Enabled = false;
10402 FriendshipContextMenuItem.Enabled = false;
10403 ShowUserStatusContextMenuItem.Enabled = false;
10404 SearchPostsDetailToolStripMenuItem.Enabled = false;
10405 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10406 UseHashtagMenuItem.Enabled = false;
10407 IdFilterAddMenuItem.Enabled = false;
10408 ListManageUserContextToolStripMenuItem.Enabled = false;
10410 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10411 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10412 if (_selText == null)
10414 SelectionSearchContextMenuItem.Enabled = false;
10415 SelectionCopyContextMenuItem.Enabled = false;
10416 SelectionTranslationToolStripMenuItem.Enabled = false;
10420 SelectionSearchContextMenuItem.Enabled = true;
10421 SelectionCopyContextMenuItem.Enabled = true;
10422 SelectionTranslationToolStripMenuItem.Enabled = true;
10424 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10425 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10426 bool fAllFlag = false;
10427 foreach (Match mu in ma)
10429 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10435 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10437 if (_curPost == null)
10438 TranslationToolStripMenuItem.Enabled = false;
10440 TranslationToolStripMenuItem.Enabled = true;
10445 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10447 //発言詳細の選択文字列で現在のタブを検索
10448 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10450 if (_selText != null)
10452 var searchOptions = new SearchWordDialog.SearchOptions(
10453 SearchWordDialog.SearchType.Timeline,
10456 caseSensitive: false,
10459 this.SearchDialog.ResultOptions = searchOptions;
10462 searchOptions.Query,
10463 searchOptions.CaseSensitive,
10464 searchOptions.UseRegex,
10465 SEARCHTYPE.NextSearch);
10469 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10471 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10472 _modifySettingLocal = true;
10475 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10477 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10479 SelectMedia_DragDrop(e);
10481 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10483 var url = GetUrlFromDataObject(e.Data);
10486 if (url.Item2 == null)
10487 appendText = url.Item1;
10489 appendText = url.Item2 + " " + url.Item1;
10491 if (this.StatusText.TextLength == 0)
10492 this.StatusText.Text = appendText;
10494 this.StatusText.Text += " " + appendText;
10496 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10498 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10499 if (data != null) StatusText.Text += data;
10504 /// IDataObject から URL とタイトルの対を取得します
10507 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10509 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10510 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10511 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10513 if (data.GetDataPresent("text/x-moz-url"))
10515 // Firefox, Google Chrome で利用可能
10516 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10518 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10520 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10521 if (lines.Length < 2)
10522 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10524 return new Tuple<string, string>(lines[0], lines[1]);
10527 else if (data.GetDataPresent("IESiteModeToUrl"))
10529 // Internet Exproler 用
10530 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10532 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10534 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10535 if (lines.Length < 2)
10536 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10538 return new Tuple<string, string>(lines[0], lines[1]);
10541 else if (data.GetDataPresent("UniformResourceLocatorW"))
10545 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10547 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10548 return new Tuple<string, string>(url, null);
10552 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10555 private void TweenMain_DragEnter(object sender, DragEventArgs e)
10557 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10559 SelectMedia_DragEnter(e);
10563 private void TweenMain_DragOver(object sender, DragEventArgs e)
10565 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10567 SelectMedia_DragOver(e);
10569 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10571 e.Effect = DragDropEffects.Copy;
10573 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10575 e.Effect = DragDropEffects.Copy;
10579 e.Effect = DragDropEffects.None;
10583 public bool IsNetworkAvailable()
10586 nw = MyCommon.IsNetworkAvailable();
10587 _myStatusOnline = nw;
10591 public Task OpenUriAsync(string UriString)
10593 return Task.Run(() =>
10595 string myPath = UriString;
10599 var configBrowserPath = SettingDialog.BrowserPath;
10600 if (!string.IsNullOrEmpty(configBrowserPath))
10602 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10604 int sep = configBrowserPath.IndexOf("\"", 2);
10605 string browserPath = configBrowserPath.Substring(1, sep - 1);
10607 if (sep < configBrowserPath.Length - 1)
10609 arg = configBrowserPath.Substring(sep + 1);
10611 myPath = arg + " " + myPath;
10612 System.Diagnostics.Process.Start(browserPath, myPath);
10616 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10621 System.Diagnostics.Process.Start(myPath);
10626 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10631 private void ListTabSelect(TabPage _tab)
10635 this.PurgeListViewItemCache();
10638 _curList = (DetailsListView)_tab.Tag;
10639 if (_curList.SelectedIndices.Count > 0)
10641 _curItemIndex = _curList.SelectedIndices[0];
10642 _curPost = GetCurTabPost(_curItemIndex);
10646 _curItemIndex = -1;
10650 _anchorPost = null;
10651 _anchorFlag = false;
10655 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10659 for (int i = 0; i < _curList.Columns.Count; i++)
10661 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10666 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10668 ListTabSelect(e.TabPage);
10671 private void SelectListItem(DetailsListView LView, int Index)
10674 Rectangle bnd = new Rectangle();
10676 var item = LView.FocusedItem;
10685 LView.SelectedIndices.Clear();
10687 while (LView.SelectedIndices.Count > 0);
10688 item = LView.Items[Index];
10689 item.Selected = true;
10690 item.Focused = true;
10692 if (flg) LView.Invalidate(bnd);
10695 private void SelectListItem(DetailsListView LView , int[] Index, int[] FocusedIndex)
10698 Rectangle bnd = new Rectangle();
10700 var item = LView.FocusedItem;
10708 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10712 LView.SelectedIndices.Clear();
10714 while (LView.SelectedIndices.Count > 0);
10715 foreach (int idx in Index)
10717 if (idx > -1 && LView.VirtualListSize > idx)
10719 LView.SelectedIndices.Add(idx);
10720 if (fIdx == -1) fIdx = idx;
10724 if (FocusedIndex[1] > -1 && LView.VirtualListSize > FocusedIndex[1])
10726 LView.SelectionMark = FocusedIndex[1];
10728 if (FocusedIndex[0] > -1 && LView.VirtualListSize > FocusedIndex[0])
10730 LView.Items[FocusedIndex[0]].Focused = true;
10732 else if (fIdx > -1)
10734 LView.Items[fIdx].Focused = true;
10737 if (flg) LView.Invalidate(bnd);
10740 private void RunAsync(GetWorkerArg args)
10742 BackgroundWorker bw = null;
10743 if (args.type != MyCommon.WORKERTYPE.Follower)
10745 for (int i = 0; i < _bw.Length; i++)
10747 if (_bw[i] != null && !_bw[i].IsBusy)
10755 for (int i = 0; i < _bw.Length; i++)
10757 if (_bw[i] == null)
10759 _bw[i] = new BackgroundWorker();
10761 bw.WorkerReportsProgress = true;
10762 bw.WorkerSupportsCancellation = true;
10763 bw.DoWork += GetTimelineWorker_DoWork;
10764 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10765 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10773 if (_bwFollower == null)
10775 _bwFollower = new BackgroundWorker();
10777 bw.WorkerReportsProgress = true;
10778 bw.WorkerSupportsCancellation = true;
10779 bw.DoWork += GetTimelineWorker_DoWork;
10780 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10781 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10785 if (_bwFollower.IsBusy == false)
10789 if (bw == null) return;
10791 bw.RunWorkerAsync(args);
10794 private void StartUserStream()
10796 tw.NewPostFromStream += tw_NewPostFromStream;
10797 tw.UserStreamStarted += tw_UserStreamStarted;
10798 tw.UserStreamStopped += tw_UserStreamStopped;
10799 tw.PostDeleted += tw_PostDeleted;
10800 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10802 MenuItemUserStream.Text = "&UserStream ■";
10803 MenuItemUserStream.Enabled = true;
10804 StopToolStripMenuItem.Text = "&Start";
10805 StopToolStripMenuItem.Enabled = true;
10806 if (SettingDialog.UserstreamStartup) tw.StartUserStream();
10809 private async void TweenMain_Shown(object sender, EventArgs e)
10813 PostBrowser.Url = new Uri("about:blank");
10814 PostBrowser.DocumentText = ""; //発言詳細部初期化
10820 NotifyIcon1.Visible = true;
10822 if (this.IsNetworkAvailable())
10824 this.RefreshMuteUserIdsAsync();
10825 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, 0, "");
10826 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
10827 if (SettingDialog.StartupFollowers)
10829 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, 0, "");
10831 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
10833 _waitTimeline = true;
10834 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, 1, "");
10836 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, 1, "");
10838 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, 1, "");
10839 if (SettingDialog.GetFav)
10842 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, 1, "");
10844 _waitPubSearch = true;
10845 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, ""); //tabname="":全タブ
10846 _waitUserTimeline = true;
10847 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, 0, ""); //tabname="":全タブ
10849 GetTimeline(MyCommon.WORKERTYPE.List, 1, 0, ""); //tabname="":全タブ
10852 while (this.IsInitialRead())
10854 await Task.Delay(5000);
10857 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10859 if (MyCommon._endingFlag)
10863 if (MyCommon._endingFlag) return;
10865 if (ApplicationSettings.VersionInfoUrl != null)
10867 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10868 if (SettingDialog.StartupVersion)
10869 await this.CheckNewVersion(true);
10873 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10874 this.VerUpMenuItem.Enabled = false;
10875 this.VerUpMenuItem.Available = false;
10876 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10880 if (!tw.GetFollowersSuccess && SettingDialog.StartupFollowers)
10881 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, 0, "");
10884 if (!tw.GetNoRetweetSuccess)
10885 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, 0, "");
10888 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10889 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, 0, "");
10891 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10892 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10894 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10895 SettingStripMenuItem_Click(null, null);
10902 TimerTimeline.Enabled = true;
10905 private bool IsInitialRead()
10907 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10910 private void doGetFollowersMenu()
10912 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, 0, "");
10913 DispSelectedPost(true);
10916 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10918 doGetFollowersMenu();
10921 private void doReTweetUnofficial()
10924 if (this.ExistCurrentPost)
10926 if (_curPost.IsDm ||
10927 !StatusText.Enabled) return;
10929 if (_curPost.IsProtect)
10931 MessageBox.Show("Protected.");
10934 string rtdata = _curPost.Text;
10935 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10937 this._reply_to_id = null;
10938 this._reply_to_name = null;
10940 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10942 StatusText.SelectionStart = 0;
10943 StatusText.Focus();
10947 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10949 doReTweetUnofficial();
10952 private void doReTweetOfficial(bool isConfirm)
10955 if (this.ExistCurrentPost)
10957 if (_curPost.IsProtect)
10959 MessageBox.Show("Protected.");
10960 _DoFavRetweetFlags = false;
10963 if (_curList.SelectedIndices.Count > 15)
10965 MessageBox.Show(Properties.Resources.RetweetLimitText);
10966 _DoFavRetweetFlags = false;
10969 else if (_curList.SelectedIndices.Count > 1)
10971 string QuestionText = Properties.Resources.RetweetQuestion2;
10972 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10973 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10975 case DialogResult.Cancel:
10976 case DialogResult.No:
10977 _DoFavRetweetFlags = false;
10983 if (_curPost.IsDm || _curPost.IsMe)
10985 _DoFavRetweetFlags = false;
10988 if (!SettingDialog.RetweetNoConfirm)
10990 string Questiontext = Properties.Resources.RetweetQuestion1;
10991 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
10992 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
10994 _DoFavRetweetFlags = false;
10999 GetWorkerArg args = new GetWorkerArg();
11000 args.ids = new List<long>();
11001 args.sIds = new List<long>();
11002 args.tName = _curTab.Text;
11003 args.type = MyCommon.WORKERTYPE.Retweet;
11004 foreach (int idx in _curList.SelectedIndices)
11006 PostClass post = GetCurTabPost(idx);
11007 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
11013 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
11015 doReTweetOfficial(true);
11018 private void FavoritesRetweetOriginal()
11020 if (!this.ExistCurrentPost) return;
11021 _DoFavRetweetFlags = true;
11022 doReTweetOfficial(true);
11023 if (_DoFavRetweetFlags)
11025 _DoFavRetweetFlags = false;
11026 FavoriteChange(true, false);
11030 private void FavoritesRetweetUnofficial()
11032 if (this.ExistCurrentPost && !_curPost.IsDm)
11034 _DoFavRetweetFlags = true;
11035 FavoriteChange(true);
11036 if (!_curPost.IsProtect && _DoFavRetweetFlags)
11038 _DoFavRetweetFlags = false;
11039 doReTweetUnofficial();
11045 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
11047 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
11048 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
11049 /// <returns>復元されたツイート本文</returns>
11050 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
11052 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
11055 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
11057 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11059 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11063 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
11065 statusHtml = statusHtml.Replace("<br>", " ");
11067 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
11068 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
11069 statusHtml = statusHtml.Replace(" ", " ");
11071 return WebUtility.HtmlDecode(statusHtml);
11074 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
11076 if (_curPost != null)
11077 DispSelectedPost(true);
11080 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
11082 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
11083 DebugModeToolStripMenuItem.Visible = true;
11085 DebugModeToolStripMenuItem.Visible = false;
11088 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
11090 SettingDialog.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
11093 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
11095 ToolStripMenuItemUrlAutoShorten.Checked = SettingDialog.UrlConvertAuto;
11098 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
11100 if (TraceOutToolStripMenuItem.Checked)
11101 MyCommon.TraceFlag = true;
11103 MyCommon.TraceFlag = false;
11106 private void TweenMain_Deactivate(object sender, EventArgs e)
11108 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
11109 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
11112 private void TabRenameMenuItem_Click(object sender, EventArgs e)
11114 if (string.IsNullOrEmpty(_rclickTabName)) return;
11115 TabRename(ref _rclickTabName);
11118 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
11120 await UrlConvertAsync(MyCommon.UrlConverter.Bitly);
11123 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
11125 await UrlConvertAsync(MyCommon.UrlConverter.Jmp);
11129 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
11131 e.Result = tw.GetInfoApi();
11134 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
11136 StringBuilder tmp = new StringBuilder();
11138 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
11142 var result = (TwitterApiStatus)dlg.Result;
11144 if (result == null)
11146 var accessLevel = result.AccessLevel;
11147 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
11148 var mediaLimit = result.MediaUploadLimit;
11150 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
11151 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
11152 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
11153 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
11156 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
11157 SetStatusLabelUrl();
11160 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
11161 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
11162 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
11166 tmp.Append(Properties.Resources.ApiInfo5);
11170 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11173 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11176 if (_curPost != null) id = _curPost.ScreenName;
11180 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11182 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11183 e.Result = arg.tw.PostFollowCommand(arg.id);
11186 private void FollowCommand(string id)
11188 using (InputTabName inputName = new InputTabName())
11190 inputName.FormTitle = "Follow";
11191 inputName.FormDescription = Properties.Resources.FRMessage1;
11192 inputName.TabName = id;
11193 if (inputName.ShowDialog() == DialogResult.OK &&
11194 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11196 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11198 arg.id = inputName.TabName.Trim();
11199 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11200 FollowCommand_DoWork,
11204 _info.ShowDialog();
11205 string ret = (string)_info.Result;
11206 if (!string.IsNullOrEmpty(ret))
11207 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11209 MessageBox.Show(Properties.Resources.FRMessage3);
11215 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11218 if (_curPost != null) id = _curPost.ScreenName;
11219 RemoveCommand(id, false);
11222 private class FollowRemoveCommandArgs
11228 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11230 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11231 e.Result = arg.tw.PostRemoveCommand(arg.id);
11234 private void RemoveCommand(string id, bool skipInput)
11236 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11241 using (InputTabName inputName = new InputTabName())
11243 inputName.FormTitle = "Unfollow";
11244 inputName.FormDescription = Properties.Resources.FRMessage1;
11245 inputName.TabName = id;
11246 if (inputName.ShowDialog() == DialogResult.OK &&
11247 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11250 arg.id = inputName.TabName.Trim();
11259 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11260 RemoveCommand_DoWork,
11264 _info.ShowDialog();
11265 string ret = (string)_info.Result;
11266 if (!string.IsNullOrEmpty(ret))
11267 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11269 MessageBox.Show(Properties.Resources.FRMessage3);
11273 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11276 if (_curPost != null)
11277 id = _curPost.ScreenName;
11279 ShowFriendship(id);
11282 private class ShowFriendshipArgs
11285 public class FriendshipInfo
11287 public string id = "";
11288 public bool isFollowing = false;
11289 public bool isFollowed = false;
11290 public bool isError = false;
11291 public FriendshipInfo(string id)
11296 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11299 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11301 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11302 string result = "";
11303 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11305 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11306 if (!string.IsNullOrEmpty(rt))
11308 if (string.IsNullOrEmpty(result)) result = rt;
11309 fInfo.isError = true;
11315 private void ShowFriendship(string id)
11317 ShowFriendshipArgs args = new ShowFriendshipArgs();
11319 using (InputTabName inputName = new InputTabName())
11321 inputName.FormTitle = "Show Friendships";
11322 inputName.FormDescription = Properties.Resources.FRMessage1;
11323 inputName.TabName = id;
11324 if (inputName.ShowDialog() == DialogResult.OK &&
11325 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11328 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11329 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11330 ShowFriendship_DoWork,
11334 _info.ShowDialog();
11335 ret = (string)_info.Result;
11337 string result = "";
11338 if (string.IsNullOrEmpty(ret))
11340 if (args.ids[0].isFollowing)
11342 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11346 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11348 if (args.ids[0].isFollowed)
11350 result += Properties.Resources.GetFriendshipInfo3;
11354 result += Properties.Resources.GetFriendshipInfo4;
11356 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11362 MessageBox.Show(result);
11367 private void ShowFriendship(string[] ids)
11369 foreach (string id in ids)
11372 ShowFriendshipArgs args = new ShowFriendshipArgs();
11374 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11375 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11376 ShowFriendship_DoWork,
11380 _info.ShowDialog();
11381 ret = (string)_info.Result;
11383 string result = "";
11384 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11386 if (string.IsNullOrEmpty(ret))
11389 if (fInfo.isFollowing)
11391 ff += Properties.Resources.GetFriendshipInfo1;
11395 ff += Properties.Resources.GetFriendshipInfo2;
11398 ff += System.Environment.NewLine + " ";
11399 if (fInfo.isFollowed)
11401 ff += Properties.Resources.GetFriendshipInfo3;
11405 ff += Properties.Resources.GetFriendshipInfo4;
11407 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11408 if (fInfo.isFollowing)
11410 if (MessageBox.Show(
11411 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11412 MessageBoxButtons.YesNo,
11413 MessageBoxIcon.Question,
11414 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11416 RemoveCommand(fInfo.id, true);
11421 MessageBox.Show(result);
11426 MessageBox.Show(ret);
11431 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11433 doShowUserStatus(tw.Username, false);
11434 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11436 // doShowUserStatus(tw.Username, false);
11440 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11445 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11446 // URLから切り出した文字列を渡す
11448 public bool IsTwitterId(string name)
11450 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11451 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11453 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11456 private string GetUserId()
11458 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11459 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11460 return m.Result("${ScreenName}");
11465 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11467 string name = GetUserId();
11468 if (name != null) FollowCommand(name);
11471 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11473 string name = GetUserId();
11474 if (name != null) RemoveCommand(name, false);
11477 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11479 string name = GetUserId();
11480 if (name != null) ShowFriendship(name);
11483 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11485 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11486 List<string> ids = new List<string>();
11487 foreach (Match mu in ma)
11489 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11491 ids.Add(mu.Result("${ScreenName}"));
11494 ShowFriendship(ids.ToArray());
11497 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11499 string name = GetUserId();
11500 if (name != null) ShowUserStatus(name);
11503 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11505 string name = GetUserId();
11506 if (name != null) AddNewTabForUserTimeline(name);
11509 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11511 string name = GetUserId();
11512 if (name != null) AddNewTabForSearch("@" + name);
11515 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11517 _modifySettingCommon = true;
11520 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11522 _modifySettingCommon = true;
11525 private void doQuote()
11529 if (this.ExistCurrentPost)
11531 if (_curPost.IsDm ||
11532 !StatusText.Enabled) return;
11534 if (_curPost.IsProtect)
11536 MessageBox.Show("Protected.");
11539 string rtdata = _curPost.Text;
11540 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11542 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11543 if (_curPost.RetweetedId == null)
11545 _reply_to_id = _curPost.StatusId;
11549 _reply_to_id = _curPost.RetweetedId.Value;
11551 _reply_to_name = _curPost.ScreenName;
11553 StatusText.SelectionStart = 0;
11554 StatusText.Focus();
11558 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11563 private void SearchButton_Click(object sender, EventArgs e)
11566 Control pnl = ((Control)sender).Parent;
11567 if (pnl == null) return;
11568 string tbName = pnl.Parent.Text;
11569 TabClass tb = _statuses.Tabs[tbName];
11570 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11571 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11572 cmb.Text = cmb.Text.Trim();
11573 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11574 bool Quote = false;
11575 StringBuilder buf = new StringBuilder();
11576 char[] c = cmb.Text.ToCharArray();
11577 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11579 if (cnt > cmb.Text.Length - 4)
11581 buf.Append(cmb.Text.Substring(cnt));
11590 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11592 buf.Append(" OR ");
11597 buf.Append(c[cnt]);
11599 cmb.Text = buf.ToString();
11601 tb.SearchWords = cmb.Text;
11602 tb.SearchLang = cmbLang.Text;
11603 if (string.IsNullOrEmpty(cmb.Text))
11605 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11609 if (tb.IsQueryChanged())
11611 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11612 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11613 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11614 cmb.Text = tb.SearchWords;
11616 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11617 this.PurgeListViewItemCache();
11618 lst.VirtualListSize = 0;
11619 _statuses.ClearTabIds(tbName);
11620 SaveConfigsTabs(); //検索条件の保存
11623 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, 0, tbName);
11624 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11627 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11633 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11635 if (_statuses.RemovedTab.Count == 0)
11637 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11642 TabClass tb = _statuses.RemovedTab.Pop();
11643 if (tb.TabType == MyCommon.TabUsageType.Related)
11645 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11646 if (relatedTab != null)
11648 // 関連発言なら既存のタブを置き換える
11649 tb.TabName = relatedTab.TabName;
11650 this.ClearTab(tb.TabName, false);
11651 _statuses.Tabs[tb.TabName] = tb;
11652 for (int i = 0; i < ListTab.TabPages.Count; i++)
11654 if (tb.TabName == ListTab.TabPages[i].Text)
11656 ListTab.SelectedIndex = i;
11657 ListTabSelect(ListTab.TabPages[i]);
11664 const string TabName = "Related Tweets";
11665 string renamed = TabName;
11666 for (int i = 2; i <= 100; i++)
11668 if (!_statuses.ContainsTab(renamed)) break;
11669 renamed = TabName + i.ToString();
11671 tb.TabName = renamed;
11672 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11673 _statuses.Tabs.Add(renamed, tb); // 後に
11674 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11675 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11680 string renamed = tb.TabName;
11681 for (int i = 1; i < int.MaxValue; i++)
11683 if (!_statuses.ContainsTab(renamed)) break;
11684 renamed = tb.TabName + "(" + i.ToString() + ")";
11686 tb.TabName = renamed;
11687 _statuses.Tabs.Add(renamed, tb); // 先に
11688 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11689 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11690 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11696 private void doMoveToRTHome()
11698 if (_curList.SelectedIndices.Count > 0)
11700 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11701 if (post.RetweetedId != null)
11703 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11708 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11713 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11715 string name = GetUserId();
11721 if (_curList.SelectedIndices.Count == 0) return;
11724 if (!SelectTab(out tabName)) return;
11728 MoveOrCopy(ref mv, ref mk);
11730 PostFilterRule fc = new PostFilterRule();
11731 fc.FilterName = name;
11732 fc.UseNameField = true;
11733 fc.MoveMatches = mv;
11734 fc.MarkMatches = mk;
11735 fc.UseRegex = false;
11736 fc.FilterByUrl = false;
11737 _statuses.Tabs[tabName].AddFilter(fc);
11739 this.ApplyPostFilters();
11744 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11748 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11750 if (menuItem.Owner == this.ContextMenuPostBrowser)
11752 user = GetUserId();
11753 if (user == null) return;
11755 else if (this._curPost != null)
11757 user = this._curPost.ScreenName;
11764 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11766 string res = this.tw.GetListsApi();
11768 if (!string.IsNullOrEmpty(res))
11770 MessageBox.Show("Failed to get lists. (" + res + ")");
11775 using (MyLists listSelectForm = new MyLists(user, this.tw))
11777 listSelectForm.ShowDialog(this);
11781 private void SearchControls_Enter(object sender, EventArgs e)
11783 Control pnl = (Control)sender;
11784 foreach (Control ctl in pnl.Controls)
11786 ctl.TabStop = true;
11790 private void SearchControls_Leave(object sender, EventArgs e)
11792 Control pnl = (Control)sender;
11793 foreach (Control ctl in pnl.Controls)
11795 ctl.TabStop = false;
11799 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11801 if (ListTab.SelectedTab != null)
11803 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11804 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11808 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11810 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11813 HashMgr.SetPermanentHash("#" + Uri.UnescapeDataString(m.Result("${hash}")));
11814 HashStripSplitButton.Text = HashMgr.UseHash;
11815 HashToggleMenuItem.Checked = true;
11816 HashToggleToolStripMenuItem.Checked = true;
11818 _modifySettingCommon = true;
11822 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11824 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11827 private void HashManageMenuItem_Click(object sender, EventArgs e)
11829 DialogResult rslt = DialogResult.Cancel;
11832 rslt = HashMgr.ShowDialog();
11838 this.TopMost = SettingDialog.AlwaysTop;
11839 if (rslt == DialogResult.Cancel) return;
11840 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11842 HashStripSplitButton.Text = HashMgr.UseHash;
11843 HashToggleMenuItem.Checked = true;
11844 HashToggleToolStripMenuItem.Checked = true;
11848 HashStripSplitButton.Text = "#[-]";
11849 HashToggleMenuItem.Checked = false;
11850 HashToggleToolStripMenuItem.Checked = false;
11852 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11854 // int sidx = StatusText.SelectionStart;
11855 // string hash = HashMgr.UseHash + " ";
11858 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11859 // hash = " " + hash;
11861 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11862 // sidx += hash.Length;
11863 // StatusText.SelectionStart = sidx;
11864 // StatusText.Focus();
11866 _modifySettingCommon = true;
11867 this.StatusText_TextChanged(null, null);
11870 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11872 HashMgr.ToggleHash();
11873 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11875 HashStripSplitButton.Text = HashMgr.UseHash;
11876 HashToggleMenuItem.Checked = true;
11877 HashToggleToolStripMenuItem.Checked = true;
11881 HashStripSplitButton.Text = "#[-]";
11882 HashToggleMenuItem.Checked = false;
11883 HashToggleToolStripMenuItem.Checked = false;
11885 _modifySettingCommon = true;
11886 this.StatusText_TextChanged(null, null);
11889 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11891 HashToggleMenuItem_Click(null, null);
11894 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11896 if (ListTab.SelectedTab == null) return;
11897 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11898 if (!this.ExistCurrentPost)
11900 this.ReplyOpMenuItem.Enabled = false;
11901 this.ReplyAllOpMenuItem.Enabled = false;
11902 this.DmOpMenuItem.Enabled = false;
11903 this.ShowProfMenuItem.Enabled = false;
11904 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11905 this.ListManageMenuItem.Enabled = false;
11906 this.OpenFavOpMenuItem.Enabled = false;
11907 this.CreateTabRuleOpMenuItem.Enabled = false;
11908 this.CreateIdRuleOpMenuItem.Enabled = false;
11909 this.ReadOpMenuItem.Enabled = false;
11910 this.UnreadOpMenuItem.Enabled = false;
11914 this.ReplyOpMenuItem.Enabled = true;
11915 this.ReplyAllOpMenuItem.Enabled = true;
11916 this.DmOpMenuItem.Enabled = true;
11917 this.ShowProfMenuItem.Enabled = true;
11918 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11919 this.ListManageMenuItem.Enabled = true;
11920 this.OpenFavOpMenuItem.Enabled = true;
11921 this.CreateTabRuleOpMenuItem.Enabled = true;
11922 this.CreateIdRuleOpMenuItem.Enabled = true;
11923 this.ReadOpMenuItem.Enabled = true;
11924 this.UnreadOpMenuItem.Enabled = true;
11927 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11929 this.FavOpMenuItem.Enabled = false;
11930 this.UnFavOpMenuItem.Enabled = false;
11931 this.OpenStatusOpMenuItem.Enabled = false;
11932 this.OpenFavotterOpMenuItem.Enabled = false;
11933 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11934 this.RtOpMenuItem.Enabled = false;
11935 this.RtUnOpMenuItem.Enabled = false;
11936 this.QtOpMenuItem.Enabled = false;
11937 this.FavoriteRetweetMenuItem.Enabled = false;
11938 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11939 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11943 this.FavOpMenuItem.Enabled = true;
11944 this.UnFavOpMenuItem.Enabled = true;
11945 this.OpenStatusOpMenuItem.Enabled = true;
11946 this.OpenFavotterOpMenuItem.Enabled = true;
11947 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11951 this.RtOpMenuItem.Enabled = false;
11952 this.FavoriteRetweetMenuItem.Enabled = false;
11953 this.DelOpMenuItem.Enabled = true;
11957 this.DelOpMenuItem.Enabled = false;
11958 if (_curPost.IsProtect)
11960 this.RtOpMenuItem.Enabled = false;
11961 this.RtUnOpMenuItem.Enabled = false;
11962 this.QtOpMenuItem.Enabled = false;
11963 this.FavoriteRetweetMenuItem.Enabled = false;
11964 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11968 this.RtOpMenuItem.Enabled = true;
11969 this.RtUnOpMenuItem.Enabled = true;
11970 this.QtOpMenuItem.Enabled = true;
11971 this.FavoriteRetweetMenuItem.Enabled = true;
11972 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
11977 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
11979 this.RefreshPrevOpMenuItem.Enabled = true;
11983 this.RefreshPrevOpMenuItem.Enabled = false;
11985 if (!this.ExistCurrentPost
11986 || _curPost.InReplyToStatusId == null)
11988 OpenRepSourceOpMenuItem.Enabled = false;
11992 OpenRepSourceOpMenuItem.Enabled = true;
11994 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
11996 OpenRterHomeMenuItem.Enabled = false;
12000 OpenRterHomeMenuItem.Enabled = true;
12004 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
12006 ContextMenuTabProperty_Opening(sender, null);
12009 public Twitter TwitterInstance
12014 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
12016 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
12018 _mySpDis3 = SplitContainer3.SplitterDistance;
12019 _modifySettingLocal = true;
12023 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
12025 if (_statuses.RemovedTab.Count == 0)
12027 UndoRemoveTabMenuItem.Enabled = false;
12031 UndoRemoveTabMenuItem.Enabled = true;
12033 if (ListTab.SelectedTab != null)
12035 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
12036 PublicSearchQueryMenuItem.Enabled = true;
12038 PublicSearchQueryMenuItem.Enabled = false;
12042 PublicSearchQueryMenuItem.Enabled = false;
12044 if (!this.ExistCurrentPost)
12046 this.CopySTOTMenuItem.Enabled = false;
12047 this.CopyURLMenuItem.Enabled = false;
12048 this.CopyUserIdStripMenuItem.Enabled = false;
12052 this.CopySTOTMenuItem.Enabled = true;
12053 this.CopyURLMenuItem.Enabled = true;
12054 this.CopyUserIdStripMenuItem.Enabled = true;
12055 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
12056 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
12060 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
12062 SetNotifyIconText();
12065 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12068 if (_curPost != null)
12070 id = _curPost.ScreenName;
12072 ShowUserStatus(id);
12075 private class GetUserInfoArgs
12079 public TwitterUser user;
12082 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
12084 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
12085 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
12088 private void doShowUserStatus(string id, bool ShowInputDialog)
12090 TwitterUser user = null;
12091 GetUserInfoArgs args = new GetUserInfoArgs();
12092 if (ShowInputDialog)
12094 using (InputTabName inputName = new InputTabName())
12096 inputName.FormTitle = "Show UserStatus";
12097 inputName.FormDescription = Properties.Resources.FRMessage1;
12098 inputName.TabName = id;
12099 if (inputName.ShowDialog() == DialogResult.OK &&
12100 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12102 id = inputName.TabName.Trim();
12106 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12107 GetUserInfo_DoWork,
12111 _info.ShowDialog();
12112 string ret = (string)_info.Result;
12113 if (string.IsNullOrEmpty(ret))
12114 doShowUserStatus(args.user);
12116 MessageBox.Show(ret);
12126 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12127 GetUserInfo_DoWork,
12131 _info.ShowDialog();
12132 string ret = (string)_info.Result;
12133 if (string.IsNullOrEmpty(ret))
12135 doShowUserStatus(args.user);
12139 MessageBox.Show(ret);
12145 private async void doShowUserStatus(TwitterUser user)
12147 using (var userDialog = new UserInfoDialog(this, this.tw))
12149 var showUserTask = userDialog.ShowUserAsync(user);
12150 userDialog.ShowDialog(this);
12153 this.BringToFront();
12155 // ユーザー情報の表示が完了するまで userDialog を破棄しない
12156 await showUserTask;
12160 private void ShowUserStatus(string id, bool ShowInputDialog)
12162 doShowUserStatus(id, ShowInputDialog);
12165 private void ShowUserStatus(string id)
12167 doShowUserStatus(id, true);
12170 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12172 if (NameLabel.Tag != null)
12174 string id = (string)NameLabel.Tag;
12175 if (id != tw.Username)
12182 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12184 if (NameLabel.Tag != null)
12186 string id = (string)NameLabel.Tag;
12187 if (id != tw.Username)
12189 RemoveCommand(id, false);
12194 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12196 if (NameLabel.Tag != null)
12198 string id = (string)NameLabel.Tag;
12199 if (id != tw.Username)
12201 ShowFriendship(id);
12206 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12208 if (NameLabel.Tag != null)
12210 string id = (string)NameLabel.Tag;
12211 ShowUserStatus(id, false);
12215 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12217 if (NameLabel.Tag != null)
12219 string id = (string)NameLabel.Tag;
12220 AddNewTabForUserTimeline(id);
12224 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12226 if (NameLabel.Tag != null)
12228 string id = (string)NameLabel.Tag;
12229 AddNewTabForSearch("@" + id);
12233 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12235 if (_curPost != null)
12237 ShowUserStatus(_curPost.ScreenName, false);
12241 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12246 if (_curPost.RetweetedId != null)
12248 statusid = _curPost.RetweetedId.Value;
12252 statusid = _curPost.StatusId;
12254 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12256 e.Result = counter;
12259 private void RtCountMenuItem_Click(object sender, EventArgs e)
12261 if (this.ExistCurrentPost)
12263 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12264 GetRetweet_DoWork))
12266 int retweet_count = 0;
12269 _info.ShowDialog();
12270 retweet_count = (int)_info.Result;
12271 if (retweet_count < 0)
12273 MessageBox.Show(Properties.Resources.RtCountText2);
12277 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12283 private HookGlobalHotkey _hookGlobalHotkey;
12286 _hookGlobalHotkey = new HookGlobalHotkey(this);
12288 // この呼び出しは、Windows フォーム デザイナで必要です。
12289 InitializeComponent();
12291 // InitializeComponent() 呼び出しの後で初期化を追加します。
12293 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12294 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12295 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12296 this.gh.NotifyClicked += GrowlHelper_Callback;
12298 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12299 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
12301 this._apiGauge = new ToolStripAPIGauge();
12302 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12303 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12305 this.ImageSelector.Visible = false;
12306 this.ImageSelector.Enabled = false;
12307 this.ImageSelector.FilePickDialog = OpenFileDialog1;
12309 this.ReplaceAppName();
12312 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12314 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12317 this.Visible = false;
12319 else if (Form.ActiveForm == null)
12321 this.Visible = true;
12322 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12324 this.BringToFront();
12325 this.StatusText.Focus();
12329 private void UserPicture_MouseEnter(object sender, EventArgs e)
12331 this.UserPicture.Cursor = Cursors.Hand;
12334 private void UserPicture_MouseLeave(object sender, EventArgs e)
12336 this.UserPicture.Cursor = Cursors.Default;
12339 private void UserPicture_DoubleClick(object sender, EventArgs e)
12341 if (NameLabel.Tag != null)
12343 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12347 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12349 this.MultiLineMenuItem.PerformClick();
12352 public PostClass CurPost
12354 get { return _curPost; }
12357 public bool IsPreviewEnable
12359 get { return SettingDialog.PreviewEnable; }
12363 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12365 if (ImageSelector.Visible)
12366 ImageSelector.EndSelection();
12368 ImageSelector.BeginSelection();
12371 private void SelectMedia_DragEnter(DragEventArgs e)
12373 if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]))
12375 e.Effect = DragDropEffects.Copy;
12378 e.Effect = DragDropEffects.None;
12381 private void SelectMedia_DragOver(DragEventArgs e)
12386 private void SelectMedia_DragDrop(DragEventArgs e)
12389 this.BringToFront();
12390 ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
12391 StatusText.Focus();
12394 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
12396 TimelinePanel.Visible = false;
12397 TimelinePanel.Enabled = false;
12400 private void ImageSelector_EndSelecting(object sender, EventArgs e)
12402 TimelinePanel.Visible = true;
12403 TimelinePanel.Enabled = true;
12404 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12407 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
12409 this.AllowDrop = false;
12412 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
12414 this.AllowDrop = true;
12417 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
12419 if (ImageSelector.Visible)
12421 _modifySettingCommon = true;
12422 SaveConfigsAll(true);
12424 if (ImageSelector.ServiceName.Equals("Twitter"))
12425 this.StatusText_TextChanged(null, null);
12429 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
12431 this.StatusText_TextChanged(null, null);
12435 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12437 using (ListManage form = new ListManage(tw))
12439 form.ShowDialog(this);
12443 public bool ModifySettingCommon
12445 set { _modifySettingCommon = value; }
12448 public bool ModifySettingLocal
12450 set { _modifySettingLocal = value; }
12453 public bool ModifySettingAtId
12455 set { _modifySettingAtId = value; }
12458 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12460 string link = (string)SourceLinkLabel.Tag;
12461 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12463 OpenUriAsync(link);
12467 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12469 string link = (string)SourceLinkLabel.Tag;
12470 if (!string.IsNullOrEmpty(link))
12472 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12476 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12478 SetStatusLabelUrl();
12481 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12483 if (this.ExistCurrentPost && !_curPost.IsDm)
12484 RtCountMenuItem.Enabled = true;
12486 RtCountMenuItem.Enabled = false;
12488 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12489 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12491 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12494 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12499 private void CopyUserId()
12501 if (_curPost == null) return;
12502 string clstr = _curPost.ScreenName;
12505 Clipboard.SetDataObject(clstr, false, 5, 100);
12507 catch (Exception ex)
12509 MessageBox.Show(ex.Message);
12513 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12515 if (this.ExistCurrentPost && !_curPost.IsDm)
12519 this.OpenRelatedTab(this._curPost);
12521 catch (TabException ex)
12523 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12529 /// 指定されたツイートに対する関連発言タブを開きます
12531 /// <param name="post">表示する対象となるツイート</param>
12532 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12533 private void OpenRelatedTab(PostClass post)
12535 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12538 if (tabRelated == null)
12540 tabName = this._statuses.MakeTabName("Related Tweets");
12542 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12543 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12545 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12546 tabRelated.UnreadManage = false;
12547 tabRelated.Notify = false;
12551 tabName = tabRelated.TabName;
12554 tabRelated.RelationTargetPost = post;
12555 this.ClearTab(tabName, false);
12557 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12559 var tabPage = this.ListTab.TabPages[i];
12560 if (tabName == tabPage.Text)
12562 this.ListTab.SelectedIndex = i;
12563 this.ListTabSelect(tabPage);
12568 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, 1, tabName);
12571 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12573 StringBuilder buf = new StringBuilder();
12574 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12575 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12576 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12577 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12578 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12581 private void tw_UserIdChanged()
12583 this._modifySettingCommon = true;
12586 #region "Userstream"
12587 private bool _isActiveUserstream = false;
12589 private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
12593 if (InvokeRequired && !IsDisposed)
12595 Invoke((Action) (() =>
12597 _statuses.RemovePostReserve(e.StatusId);
12598 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
12600 this.PurgeListViewItemCache();
12601 ((DetailsListView)_curTab.Tag).Update();
12602 if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
12608 catch (ObjectDisposedException)
12612 catch (InvalidOperationException)
12618 private void tw_NewPostFromStream(object sender, EventArgs e)
12620 if (SettingDialog.ReadOldPosts)
12622 _statuses.SetRead(); //新着時未読クリア
12625 int rsltAddCount = _statuses.DistributePosts();
12628 DateTime tm = DateTime.Now;
12629 if (_tlTimestamps.ContainsKey(tm))
12631 _tlTimestamps[tm] += rsltAddCount;
12635 _tlTimestamps.Add(tm, rsltAddCount);
12637 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12638 List<DateTime> keys = new List<DateTime>();
12640 foreach (DateTime key in _tlTimestamps.Keys)
12642 if (key.CompareTo(oneHour) < 0)
12645 _tlCount += _tlTimestamps[key];
12647 foreach (DateTime key in keys)
12649 _tlTimestamps.Remove(key);
12653 //Static DateTime before = Now;
12654 //if (before.Subtract(Now).Seconds > -5) return;
12658 if (SettingDialog.UserstreamPeriodInt > 0) return;
12662 if (InvokeRequired && !IsDisposed)
12664 Invoke(new Action<bool>(RefreshTimeline), true);
12668 catch (ObjectDisposedException)
12672 catch (InvalidOperationException)
12678 private void tw_UserStreamStarted(object sender, EventArgs e)
12680 this._isActiveUserstream = true;
12683 if (InvokeRequired && !IsDisposed)
12685 Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
12689 catch (ObjectDisposedException)
12693 catch (InvalidOperationException)
12698 MenuItemUserStream.Text = "&UserStream ▶";
12699 MenuItemUserStream.Enabled = true;
12700 StopToolStripMenuItem.Text = "&Stop";
12701 StopToolStripMenuItem.Enabled = true;
12703 StatusLabel.Text = "UserStream Started.";
12706 private void tw_UserStreamStopped(object sender, EventArgs e)
12708 this._isActiveUserstream = false;
12711 if (InvokeRequired && !IsDisposed)
12713 Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
12717 catch (ObjectDisposedException)
12721 catch (InvalidOperationException)
12726 MenuItemUserStream.Text = "&UserStream ■";
12727 MenuItemUserStream.Enabled = true;
12728 StopToolStripMenuItem.Text = "&Start";
12729 StopToolStripMenuItem.Enabled = true;
12731 StatusLabel.Text = "UserStream Stopped.";
12734 private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
12738 if (InvokeRequired && !IsDisposed)
12740 Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
12744 catch (ObjectDisposedException)
12748 catch (InvalidOperationException)
12752 var ev = e.EventData;
12753 StatusLabel.Text = "Event: " + ev.Event;
12754 //if (ev.Event == "favorite")
12756 // NotifyFavorite(ev);
12759 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12761 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12763 this.PurgeListViewItemCache();
12764 ((DetailsListView)_curTab.Tag).Update();
12766 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12768 RemovePostFromFavTab(new long[] {ev.Id});
12773 private void NotifyEvent(Twitter.FormattedEvent ev)
12776 if (BalloonRequired(ev))
12778 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12779 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12780 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12781 StringBuilder title = new StringBuilder();
12782 if (SettingDialog.DispUsername)
12784 title.Append(tw.Username);
12785 title.Append(" - ");
12791 title.Append(Application.ProductName);
12792 title.Append(" [");
12793 title.Append(ev.Event.ToUpper());
12794 title.Append("] by ");
12795 if (!string.IsNullOrEmpty(ev.Username))
12797 title.Append(ev.Username.ToString());
12801 //title.Append("");
12804 if (!string.IsNullOrEmpty(ev.Target))
12806 //NotifyIcon1.BalloonTipText = ev.Target;
12811 //NotifyIcon1.BalloonTipText = " ";
12814 //NotifyIcon1.ShowBalloonTip(500);
12815 if (SettingDialog.IsNotifyUseGrowl)
12817 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
12818 ev.Id.ToString(), title.ToString(), text);
12822 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12823 NotifyIcon1.BalloonTipTitle = title.ToString();
12824 NotifyIcon1.BalloonTipText = text;
12825 NotifyIcon1.ShowBalloonTip(500);
12830 string snd = SettingDialog.EventSoundFile;
12831 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(snd))
12833 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
12837 string dir = Application.StartupPath;
12838 if (Directory.Exists(Path.Combine(dir, "Sounds")))
12840 dir = Path.Combine(dir, "Sounds");
12842 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
12854 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
12856 MenuItemUserStream.Enabled = false;
12857 if (StopRefreshAllMenuItem.Checked)
12859 StopRefreshAllMenuItem.Checked = false;
12862 if (this._isActiveUserstream)
12864 tw.StopUserStream();
12868 tw.StartUserStream();
12872 private static string inputTrack = "";
12874 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
12876 if (TrackToolStripMenuItem.Checked)
12878 using (InputTabName inputForm = new InputTabName())
12880 inputForm.TabName = inputTrack;
12881 inputForm.FormTitle = "Input track word";
12882 inputForm.FormDescription = "Track word";
12883 if (inputForm.ShowDialog() != DialogResult.OK)
12885 TrackToolStripMenuItem.Checked = false;
12888 inputTrack = inputForm.TabName.Trim();
12890 if (!inputTrack.Equals(tw.TrackWord))
12892 tw.TrackWord = inputTrack;
12893 this._modifySettingCommon = true;
12894 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
12895 tw.ReconnectUserStream();
12901 tw.ReconnectUserStream();
12903 this._modifySettingCommon = true;
12906 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
12908 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
12909 this._modifySettingCommon = true;
12910 tw.ReconnectUserStream();
12913 private void EventViewerMenuItem_Click(object sender, EventArgs e)
12915 if (evtDialog == null || evtDialog.IsDisposed)
12918 evtDialog = new EventViewerDialog();
12919 evtDialog.Owner = this;
12921 Point pos = evtDialog.Location;
12922 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
12923 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
12924 evtDialog.Location = pos;
12926 evtDialog.EventSource = tw.StoredEvent;
12927 if (!evtDialog.Visible)
12929 evtDialog.Show(this);
12933 evtDialog.Activate();
12935 this.TopMost = this.SettingDialog.AlwaysTop;
12939 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
12941 MyCommon._endingFlag = true;
12945 Application.Restart();
12949 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
12953 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
12955 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
12958 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
12960 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
12963 private async Task doTranslation(string str)
12965 if (string.IsNullOrEmpty(str))
12968 var bing = new Bing();
12971 var translatedText = await bing.TranslateAsync(str,
12973 langTo: this.SettingDialog.TranslateLanguage);
12975 this.PostBrowser.DocumentText = translatedText;
12977 catch (HttpRequestException e)
12979 this.StatusLabel.Text = "Err:" + e.Message;
12983 private async void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
12985 if (!this.ExistCurrentPost)
12988 await this.doTranslation(this._curPost.TextFromApi);
12991 private async void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
12993 var text = this.WebBrowser_GetSelectionText(ref this.PostBrowser);
12994 await this.doTranslation(text);
12997 private bool ExistCurrentPost
13001 if (_curPost == null) return false;
13002 if (_curPost.IsDeleted) return false;
13007 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13009 ShowUserTimeline();
13012 public bool FavEventChangeUnread
13014 get { return SettingDialog.FavEventUnread; }
13017 private string GetUserIdFromCurPostOrInput(string caption)
13020 if (_curPost != null)
13022 id = _curPost.ScreenName;
13024 using (InputTabName inputName = new InputTabName())
13026 inputName.FormTitle = caption;
13027 inputName.FormDescription = Properties.Resources.FRMessage1;
13028 inputName.TabName = id;
13029 if (inputName.ShowDialog() == DialogResult.OK &&
13030 !string.IsNullOrEmpty(inputName.TabName.Trim()))
13032 id = inputName.TabName.Trim();
13042 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13044 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
13045 if (!string.IsNullOrEmpty(id))
13047 AddNewTabForUserTimeline(id);
13051 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
13053 string id = GetUserIdFromCurPostOrInput("Show Favstar");
13054 if (!string.IsNullOrEmpty(id))
13056 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
13060 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
13062 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
13065 private void TimelineRefreshEnableChange(bool isEnable)
13069 tw.StartUserStream();
13073 tw.StopUserStream();
13075 TimerTimeline.Enabled = isEnable;
13078 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
13080 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
13083 private void OpenUserAppointUrl()
13085 if (SettingDialog.UserAppointUrl != null)
13087 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
13089 if (_curPost != null)
13091 string xUrl = SettingDialog.UserAppointUrl;
13092 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
13093 if (_curPost.RetweetedId != null)
13095 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
13099 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
13101 OpenUriAsync(xUrl);
13106 OpenUriAsync(SettingDialog.UserAppointUrl);
13111 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
13113 OpenUserAppointUrl();
13116 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
13118 string selText = SourceLinkLabel.Text;
13121 Clipboard.SetDataObject(selText, false, 5, 100);
13123 catch (Exception ex)
13125 MessageBox.Show(ex.Message);
13129 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
13131 string selText = (string)SourceLinkLabel.Tag;
13134 Clipboard.SetDataObject(selText, false, 5, 100);
13136 catch (Exception ex)
13138 MessageBox.Show(ex.Message);
13142 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
13144 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
13146 SourceCopyMenuItem.Enabled = false;
13147 SourceUrlCopyMenuItem.Enabled = false;
13151 SourceCopyMenuItem.Enabled = true;
13152 SourceUrlCopyMenuItem.Enabled = true;
13156 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
13158 if (Form.ActiveForm == null)
13160 this.BeginInvoke((Action) (() =>
13162 this.Visible = true;
13163 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
13165 this.BringToFront();
13166 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
13168 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
13172 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13178 private void ReplaceAppName()
13180 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13181 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13184 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13186 this.SplitContainer3.Panel2Collapsed = false;
13188 // PreviewDistance が起動のたびに広がっていく問題の回避策
13189 // FixedPanel が Panel2 に設定された状態で Panel2 を開くと、初回だけ SplitterDistance が再計算されておかしくなるため、
13190 // None で開いた後に設定するようにする
13191 if (this.SplitContainer3.FixedPanel == FixedPanel.None)
13192 this.SplitContainer3.FixedPanel = FixedPanel.Panel2;
13195 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13197 this.OpenThumbnailPicture(e.Thumbnail);
13200 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13202 this.OpenUriAsync(e.ImageUrl);
13205 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13207 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13210 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13212 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13215 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13217 if (e.KeyCode == Keys.Space)
13219 this.JumpUnreadMenuItem_Click(null, null);
13221 e.SuppressKeyPress = true;
13225 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
13227 this.IconSizeNoneToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.IconNone;
13228 this.IconSize16ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon16;
13229 this.IconSize24ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon24;
13230 this.IconSize48ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48;
13231 this.IconSize48_2ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48_2;
13233 this.LockListSortOrderToolStripMenuItem.Checked = SettingDialog.SortOrderLock;
13236 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
13238 ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
13241 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
13243 ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
13246 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
13248 ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
13251 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
13253 ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
13256 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
13258 ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
13261 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
13263 if (SettingDialog.IconSz == iconSize) return;
13265 var oldIconCol = _iconCol;
13267 SettingDialog.IconSz = iconSize;
13268 ApplyListViewIconSize(iconSize);
13270 if (_iconCol != oldIconCol)
13272 foreach (TabPage tp in ListTab.TabPages)
13274 ResetColumns((DetailsListView)tp.Tag);
13278 if (_curList != null) _curList.Refresh();
13280 _modifySettingCommon = true;
13283 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
13285 var state = this.LockListSortOrderToolStripMenuItem.Checked;
13286 if (SettingDialog.SortOrderLock == state) return;
13288 SettingDialog.SortOrderLock = state;
13290 _modifySettingCommon = true;