1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
29 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
32 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Diagnostics;
40 using System.Net.Http;
41 using System.Reflection;
43 using System.Text.RegularExpressions;
44 using System.Threading;
45 using System.Threading.Tasks;
46 using System.Windows.Forms;
48 using OpenTween.Connection;
49 using OpenTween.OpenTweenCustomControl;
50 using OpenTween.Thumbnail;
54 public partial class TweenMain : OTBaseForm
57 private Size _mySize; //画面サイズ
58 private Point _myLoc; //画面位置
59 private int _mySpDis; //区切り位置
60 private int _mySpDis2; //発言欄区切り位置
61 private int _mySpDis3; //プレビュー区切り位置
62 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
63 private bool _iconCol; //1列表示の時true(48サイズのとき)
66 private bool _initial; //true:起動時処理中
67 private bool _initialLayout = true;
68 private bool _ignoreConfigSave; //true:起動時処理中
69 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
70 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
71 private Point _tabMouseDownPoint;
72 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
73 private readonly object _syncObject = new object(); //ロック用
74 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
75 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
76 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
77 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
78 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
79 private const string detailHtmlFormatMono6 = ");\"><pre>";
80 private const string detailHtmlFormatMono7 = "</pre></body></html>";
81 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
82 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
83 private const string detailHtmlFormat7 = "</span></p></body></html>";
84 private string detailHtmlFormatHeader;
85 private string detailHtmlFormatFooter;
86 private bool _myStatusError = false;
87 private bool _myStatusOnline = false;
88 private bool soundfileListup = false;
89 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
92 //private SettingToConfig _cfg; //旧
93 private SettingLocal _cfgLocal;
94 private SettingCommon _cfgCommon;
95 private bool _modifySettingLocal = false;
96 private bool _modifySettingCommon = false;
97 private bool _modifySettingAtId = false;
100 private Twitter tw = new Twitter();
103 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
106 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
107 private SearchWordDialog SearchDialog = new SearchWordDialog(); //検索画面インスタンス
108 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
109 private OpenURL UrlDialog = new OpenURL();
110 public AtIdSupplement AtIdSupl; //@id補助
111 public AtIdSupplement HashSupl; //Hashtag補助
112 public HashtagManage HashMgr;
113 private EventViewerDialog evtDialog;
116 private Font _fntUnread; //未読用フォント
117 private Color _clUnread; //未読用文字色
118 private Font _fntReaded; //既読用フォント
119 private Color _clReaded; //既読用文字色
120 private Color _clFav; //Fav用文字色
121 private Color _clOWL; //片思い用文字色
122 private Color _clRetweet; //Retweet用文字色
123 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
124 private Font _fntDetail; //発言詳細部用フォント
125 private Color _clDetail; //発言詳細部用色
126 private Color _clDetailLink; //発言詳細部用リンク文字色
127 private Color _clDetailBackcolor; //発言詳細部用背景色
128 private Color _clSelf; //自分の発言用背景色
129 private Color _clAtSelf; //自分宛返信用背景色
130 private Color _clTarget; //選択発言者の他の発言用背景色
131 private Color _clAtTarget; //選択発言中の返信先用背景色
132 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
133 private Color _clAtTo; //選択発言の唯一@先
134 private Color _clListBackcolor; //リスト部通常発言背景色
135 private Color _clInputBackcolor; //入力欄背景色
136 private Color _clInputFont; //入力欄文字色
137 private Font _fntInputFont; //入力欄フォント
138 private ImageCache IconCache; //アイコン画像リスト
139 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
140 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
141 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
142 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
143 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
144 private Icon MainIcon; //Main.ico 画面左上のアイコン
145 private Icon ReplyIcon; //5g
146 private Icon ReplyIconBlink; //6g
148 private ImageList _listViewImageList = new ImageList(); //ListViewItemの高さ変更用
150 private PostClass _anchorPost;
151 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
153 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
154 private int _hisIdx; //発言履歴カレントインデックス
156 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
157 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
158 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
161 private List<DateTime> _postTimestamps = new List<DateTime>();
162 private List<DateTime> _favTimestamps = new List<DateTime>();
163 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
164 private int _tlCount;
167 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
168 private SolidBrush _brsBackColorMine;
169 private SolidBrush _brsBackColorAt;
170 private SolidBrush _brsBackColorYou;
171 private SolidBrush _brsBackColorAtYou;
172 private SolidBrush _brsBackColorAtFromTarget;
173 private SolidBrush _brsBackColorAtTo;
174 private SolidBrush _brsBackColorNone;
175 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
176 private StringFormat sfTab = new StringFormat();
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////
179 private ToolStripAPIGauge _apiGauge;
180 private TabInformations _statuses;
182 // ListViewItem のキャッシュ関連
183 private int _itemCacheIndex;
184 private ListViewItem[] _itemCache;
185 private PostClass[] _postCache;
186 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
188 private TabPage _curTab;
189 private int _curItemIndex;
190 private DetailsListView _curList;
191 private PostClass _curPost;
192 private bool _isColumnChanged = false;
193 private bool _waitTimeline = false;
194 private bool _waitReply = false;
195 private bool _waitDm = false;
196 private bool _waitFav = false;
197 private bool _waitPubSearch = false;
198 private bool _waitUserTimeline = false;
199 private bool _waitLists = false;
200 private BackgroundWorker[] _bw = new BackgroundWorker[20];
201 private BackgroundWorker _bwFollower;
203 private int UnreadCounter = -1;
204 private int UnreadAtCounter = -1;
206 private string[] ColumnOrgText = new string[9];
207 private string[] ColumnText = new string[9];
209 private bool _DoFavRetweetFlags = false;
210 private bool osResumed = false;
212 //////////////////////////////////////////////////////////////////////////////////////////////////////////
213 private string _postBrowserStatusText = "";
215 private bool _colorize = false;
217 private System.Timers.Timer TimerTimeline = new System.Timers.Timer();
219 private ImageListViewItem displayItem;
222 /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
224 protected SizeF currentScaleFactor = new SizeF();
227 private struct urlUndo
229 public string Before;
233 private List<urlUndo> urlUndoBuffer = null;
235 private struct ReplyChain
237 public long OriginalId;
238 public long InReplyToId;
239 public TabPage OriginalTab;
241 public ReplyChain(long originalId, long inReplyToId, TabPage originalTab)
243 this.OriginalId = originalId;
244 this.InReplyToId = inReplyToId;
245 this.OriginalTab = originalTab;
249 private Stack<ReplyChain> replyChains; //[, ]でのリプライ移動の履歴
250 private Stack<Tuple<TabPage, PostClass>> selectPostChains = new Stack<Tuple<TabPage, PostClass>>(); //ポスト選択履歴
252 //Backgroundworkerの処理結果通知用引数構造体
253 private class GetWorkerResult
255 public string retMsg = ""; //処理結果詳細メッセージ。エラー時に値がセットされる
256 public MyCommon.WORKERTYPE type; //処理種別
257 public string tName = ""; //Fav追加・削除時のタブ名
258 public List<long> sIds = null; //Fav追加・削除成功分のID
259 public bool newDM = false;
261 public PostingStatus status;
264 //Backgroundworkerへ処理内容を通知するための引数用構造体
265 private class GetWorkerArg
267 public int page; //処理対象ページ番号
268 public MyCommon.WORKERTYPE type; //処理種別
269 public PostingStatus status = new PostingStatus(); //発言POST時の発言内容
270 public List<long> ids; //Fav追加・削除時のItemIndex
271 public List<long> sIds; //Fav追加・削除成功分のItemIndex
272 public string tName = ""; //Fav追加・削除時のタブ名
276 private enum SEARCHTYPE
283 private class PostingStatus
285 public string status = "";
286 public long? inReplyToId = null;
287 public string inReplyToName = null;
288 public string imageService = ""; //画像投稿サービス名
289 public string[] imagePath = null;
290 public PostingStatus()
293 public PostingStatus(string status, long? replyToId, string replyToName)
295 this.status = status;
296 this.inReplyToId = replyToId;
297 this.inReplyToName = replyToName;
301 private void TweenMain_Activated(object sender, EventArgs e)
303 //画面がアクティブになったら、発言欄の背景色戻す
304 if (StatusText.Focused)
306 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
310 private bool disposed = false;
313 /// 使用中のリソースをすべてクリーンアップします。
315 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
316 protected override void Dispose(bool disposing)
318 base.Dispose(disposing);
325 if (this.components != null)
326 this.components.Dispose();
329 SettingDialog.Dispose();
330 SearchDialog.Dispose();
333 if (NIconAt != null) NIconAt.Dispose();
334 if (NIconAtRed != null) NIconAtRed.Dispose();
335 if (NIconAtSmoke != null) NIconAtSmoke.Dispose();
336 if (NIconRefresh[0] != null) NIconRefresh[0].Dispose();
337 if (NIconRefresh[1] != null) NIconRefresh[1].Dispose();
338 if (NIconRefresh[2] != null) NIconRefresh[2].Dispose();
339 if (NIconRefresh[3] != null) NIconRefresh[3].Dispose();
340 if (TabIcon != null) TabIcon.Dispose();
341 if (MainIcon != null) MainIcon.Dispose();
342 if (ReplyIcon != null) ReplyIcon.Dispose();
343 if (ReplyIconBlink != null) ReplyIconBlink.Dispose();
344 _listViewImageList.Dispose();
345 _brsHighLight.Dispose();
346 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
347 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
348 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
349 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
350 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
351 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
352 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
353 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
356 foreach (BackgroundWorker bw in _bw)
361 if (_bwFollower != null)
363 _bwFollower.Dispose();
365 this._apiGauge.Dispose();
366 if (IconCache != null)
368 this.IconCache.CancelAsync();
369 this.IconCache.Dispose();
373 // 終了時にRemoveHandlerしておかないとメモリリークする
374 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
375 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
377 this.disposed = true;
380 private void LoadIcon(ref Icon IconInstance, string FileName)
382 string dir = Application.StartupPath;
383 if (File.Exists(Path.Combine(dir, FileName)))
387 IconInstance = new Icon(Path.Combine(dir, FileName));
395 private void LoadIcons()
399 string dir = Application.StartupPath;
401 NIconAt = Properties.Resources.At;
402 NIconAtRed = Properties.Resources.AtRed;
403 NIconAtSmoke = Properties.Resources.AtSmoke;
404 NIconRefresh[0] = Properties.Resources.Refresh;
405 NIconRefresh[1] = Properties.Resources.Refresh2;
406 NIconRefresh[2] = Properties.Resources.Refresh3;
407 NIconRefresh[3] = Properties.Resources.Refresh4;
408 TabIcon = Properties.Resources.TabIcon;
409 MainIcon = Properties.Resources.MIcon;
410 ReplyIcon = Properties.Resources.Reply;
411 ReplyIconBlink = Properties.Resources.ReplyBlink;
413 if (!Directory.Exists(Path.Combine(dir, "Icons")))
416 LoadIcon(ref NIconAt, "Icons\\At.ico");
419 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
422 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
425 //アニメーション対応により4種類読み込み
426 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
427 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
428 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
429 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
432 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
435 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
438 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
441 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
444 private void InitColumns(ListView list, bool startup)
446 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
447 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
448 ColumnHeader _colHd3 = new ColumnHeader(); //本文
449 ColumnHeader _colHd4 = new ColumnHeader(); //日付
450 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
451 ColumnHeader _colHd6 = new ColumnHeader(); //未読
452 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
453 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
457 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
461 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
465 _colHd1.Text = ColumnText[0];
467 _colHd2.Text = ColumnText[1];
469 _colHd3.Text = ColumnText[2];
471 _colHd4.Text = ColumnText[3];
473 _colHd5.Text = ColumnText[4];
475 _colHd6.Text = ColumnText[5];
477 _colHd7.Text = ColumnText[6];
479 _colHd8.Text = ColumnText[7];
482 int[] dispOrder = new int[8];
485 for (int i = 0; i < _curList.Columns.Count; i++)
487 for (int j = 0; j < _curList.Columns.Count; j++)
489 if (_curList.Columns[j].DisplayIndex == i)
496 for (int i = 0; i < _curList.Columns.Count; i++)
498 list.Columns[i].Width = _curList.Columns[i].Width;
499 list.Columns[dispOrder[i]].DisplayIndex = i;
506 list.Columns[0].Width = _cfgLocal.Width1;
507 list.Columns[1].Width = _cfgLocal.Width3;
508 list.Columns[0].DisplayIndex = 0;
509 list.Columns[1].DisplayIndex = 1;
513 for (int i = 0; i <= 7; i++)
515 if (_cfgLocal.DisplayIndex1 == i)
517 else if (_cfgLocal.DisplayIndex2 == i)
519 else if (_cfgLocal.DisplayIndex3 == i)
521 else if (_cfgLocal.DisplayIndex4 == i)
523 else if (_cfgLocal.DisplayIndex5 == i)
525 else if (_cfgLocal.DisplayIndex6 == i)
527 else if (_cfgLocal.DisplayIndex7 == i)
529 else if (_cfgLocal.DisplayIndex8 == i)
532 list.Columns[0].Width = _cfgLocal.Width1;
533 list.Columns[1].Width = _cfgLocal.Width2;
534 list.Columns[2].Width = _cfgLocal.Width3;
535 list.Columns[3].Width = _cfgLocal.Width4;
536 list.Columns[4].Width = _cfgLocal.Width5;
537 list.Columns[5].Width = _cfgLocal.Width6;
538 list.Columns[6].Width = _cfgLocal.Width7;
539 list.Columns[7].Width = _cfgLocal.Width8;
540 for (int i = 0; i <= 7; i++)
542 list.Columns[dispOrder[i]].DisplayIndex = i;
548 private void InitColumnText()
551 ColumnText[1] = Properties.Resources.AddNewTabText2;
552 ColumnText[2] = Properties.Resources.AddNewTabText3;
553 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
554 ColumnText[4] = Properties.Resources.AddNewTabText5;
557 ColumnText[7] = "Source";
559 ColumnOrgText[0] = "";
560 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
561 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
562 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
563 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
564 ColumnOrgText[5] = "";
565 ColumnOrgText[6] = "";
566 ColumnOrgText[7] = "Source";
569 switch (_statuses.SortMode)
571 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
574 case IdComparerClass.ComparerMode.Data: //本文
577 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
580 case IdComparerClass.ComparerMode.Name: //名前
583 case IdComparerClass.ComparerMode.Source: //Source
590 if (_statuses.SortOrder == SortOrder.Descending)
592 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
593 ColumnText[2] = ColumnOrgText[2] + "▾";
597 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
598 ColumnText[2] = ColumnOrgText[2] + "▴";
603 if (_statuses.SortOrder == SortOrder.Descending)
605 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
606 ColumnText[c] = ColumnOrgText[c] + "▾";
610 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
611 ColumnText[c] = ColumnOrgText[c] + "▴";
616 private void InitializeTraceFrag()
619 TraceOutToolStripMenuItem.Checked = true;
620 MyCommon.TraceFlag = true;
622 if (!MyCommon.FileVersion.EndsWith("0"))
624 TraceOutToolStripMenuItem.Checked = true;
625 MyCommon.TraceFlag = true;
629 private void TweenMain_Load(object sender, EventArgs e)
631 _ignoreConfigSave = true;
632 this.Visible = false;
634 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
636 new InternetSecurityManager(PostBrowser);
637 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
639 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
640 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
642 if (MyApplication.StartupOptions.ContainsKey("d"))
643 MyCommon.TraceFlag = true;
645 Regex.CacheSize = 100;
647 InitializeTraceFrag();
648 LoadIcons(); // アイコン読み込み
651 _statuses = TabInformations.GetInstance();
654 this.Icon = MainIcon; //メインフォーム(TweenMain)
655 NotifyIcon1.Icon = NIconAt; //タスクトレイ
656 TabImage.Images.Add(TabIcon); //タブ見出し
658 SettingDialog.Owner = this;;
659 SearchDialog.Owner = this;
660 fltDialog.Owner = this;
661 UrlDialog.Owner = this;
663 _history.Add(new PostingStatus());
666 _reply_to_name = null;
668 //<<<<<<<<<設定関連>>>>>>>>>
675 ThumbnailGenerator.InitializeGenerator();
677 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
678 imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
679 imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
681 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
682 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
683 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
686 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
687 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
690 _fntUnread = _cfgLocal.FontUnread;
691 _clUnread = _cfgLocal.ColorUnread;
692 _fntReaded = _cfgLocal.FontRead;
693 _clReaded = _cfgLocal.ColorRead;
694 _clFav = _cfgLocal.ColorFav;
695 _clOWL = _cfgLocal.ColorOWL;
696 _clRetweet = _cfgLocal.ColorRetweet;
697 _fntDetail = _cfgLocal.FontDetail;
698 _clDetail = _cfgLocal.ColorDetail;
699 _clDetailLink = _cfgLocal.ColorDetailLink;
700 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
701 _clSelf = _cfgLocal.ColorSelf;
702 _clAtSelf = _cfgLocal.ColorAtSelf;
703 _clTarget = _cfgLocal.ColorTarget;
704 _clAtTarget = _cfgLocal.ColorAtTarget;
705 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
706 _clAtTo = _cfgLocal.ColorAtTo;
707 _clListBackcolor = _cfgLocal.ColorListBackcolor;
708 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
709 _clInputFont = _cfgLocal.ColorInputFont;
710 _fntInputFont = _cfgLocal.FontInputFont;
712 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
713 if (fontUIGlobal != null)
715 OTBaseForm.GlobalFont = fontUIGlobal;
716 this.Font = fontUIGlobal;
719 // StringFormatオブジェクトへの事前設定
720 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
721 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
722 //sf.FormatFlags = StringFormatFlags.LineLimit; //
723 sfTab.Alignment = StringAlignment.Center;
724 sfTab.LineAlignment = StringAlignment.Center;
727 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
728 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
731 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
732 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
734 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
736 SettingDialog.TimelinePeriodInt = _cfgCommon.TimelinePeriod;
737 SettingDialog.ReplyPeriodInt = _cfgCommon.ReplyPeriod;
738 SettingDialog.DMPeriodInt = _cfgCommon.DMPeriod;
739 SettingDialog.PubSearchPeriodInt = _cfgCommon.PubSearchPeriod;
740 SettingDialog.UserTimelinePeriodInt = _cfgCommon.UserTimelinePeriod;
741 SettingDialog.ListsPeriodInt = _cfgCommon.ListsPeriod;
743 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
745 if (SettingDialog.TimelinePeriodInt < 15 && SettingDialog.TimelinePeriodInt > 0) SettingDialog.TimelinePeriodInt = 15;
746 if (SettingDialog.ReplyPeriodInt < 15 && SettingDialog.ReplyPeriodInt > 0) SettingDialog.ReplyPeriodInt = 15;
747 if (SettingDialog.DMPeriodInt < 15 && SettingDialog.DMPeriodInt > 0) SettingDialog.DMPeriodInt = 15;
748 if (SettingDialog.PubSearchPeriodInt < 30 && SettingDialog.PubSearchPeriodInt > 0) SettingDialog.PubSearchPeriodInt = 30;
749 if (SettingDialog.UserTimelinePeriodInt < 15 && SettingDialog.UserTimelinePeriodInt > 0) SettingDialog.UserTimelinePeriodInt = 15;
750 if (SettingDialog.ListsPeriodInt < 15 && SettingDialog.ListsPeriodInt > 0) SettingDialog.ListsPeriodInt = 15;
753 //起動時読み込み分を既読にするか。trueなら既読として処理
754 SettingDialog.Readed = _cfgCommon.Read;
755 //新着取得時のリストスクロールをするか。trueならスクロールしない
756 ListLockMenuItem.Checked = _cfgCommon.ListLock;
757 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
758 SettingDialog.IconSz = _cfgCommon.IconSize;
760 SettingDialog.Status = _cfgLocal.StatusText;
762 SettingDialog.UnreadManage = _cfgCommon.UnreadManage;
764 SettingDialog.PlaySound = _cfgCommon.PlaySound;
765 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
766 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
767 //片思い表示。trueなら片思い表示する
768 SettingDialog.OneWayLove = _cfgCommon.OneWayLove;
770 SettingDialog.FontUnread = _fntUnread;
771 SettingDialog.ColorUnread = _clUnread;
772 SettingDialog.FontReaded = _fntReaded;
773 SettingDialog.ColorReaded = _clReaded;
774 SettingDialog.ColorFav = _clFav;
775 SettingDialog.ColorOWL = _clOWL;
776 SettingDialog.ColorRetweet = _clRetweet;
777 SettingDialog.FontDetail = _fntDetail;
778 SettingDialog.ColorDetail = _clDetail;
779 SettingDialog.ColorDetailLink = _clDetailLink;
780 SettingDialog.ColorDetailBackcolor = _clDetailBackcolor;
781 SettingDialog.ColorSelf = _clSelf;
782 SettingDialog.ColorAtSelf = _clAtSelf;
783 SettingDialog.ColorTarget = _clTarget;
784 SettingDialog.ColorAtTarget = _clAtTarget;
785 SettingDialog.ColorAtFromTarget = _clAtFromTarget;
786 SettingDialog.ColorAtTo = _clAtTo;
787 SettingDialog.ColorListBackcolor = _clListBackcolor;
788 SettingDialog.ColorInputBackcolor = _clInputBackcolor;
789 SettingDialog.ColorInputFont = _clInputFont;
790 SettingDialog.FontInputFont = _fntInputFont;
792 SettingDialog.NameBalloon = _cfgCommon.NameBalloon;
793 SettingDialog.PostCtrlEnter = _cfgCommon.PostCtrlEnter;
794 SettingDialog.PostShiftEnter = _cfgCommon.PostShiftEnter;
796 SettingDialog.CountApi = _cfgCommon.CountApi;
797 SettingDialog.CountApiReply = _cfgCommon.CountApiReply;
798 if (SettingDialog.CountApi < 20 || SettingDialog.CountApi > 200) SettingDialog.CountApi = 60;
799 if (SettingDialog.CountApiReply < 20 || SettingDialog.CountApiReply > 200) SettingDialog.CountApiReply = 40;
801 SettingDialog.BrowserPath = _cfgLocal.BrowserPath;
802 SettingDialog.PostAndGet = _cfgCommon.PostAndGet;
803 SettingDialog.UseRecommendStatus = _cfgLocal.UseRecommendStatus;
804 SettingDialog.DispUsername = _cfgCommon.DispUsername;
805 SettingDialog.CloseToExit = _cfgCommon.CloseToExit;
806 SettingDialog.MinimizeToTray = _cfgCommon.MinimizeToTray;
807 SettingDialog.DispLatestPost = _cfgCommon.DispLatestPost;
808 SettingDialog.SortOrderLock = _cfgCommon.SortOrderLock;
809 SettingDialog.ViewTabBottom = _cfgCommon.ViewTabBottom;
810 SettingDialog.TinyUrlResolve = _cfgCommon.TinyUrlResolve;
812 SettingDialog.SelectedProxyType = _cfgLocal.ProxyType;
813 SettingDialog.ProxyAddress = _cfgLocal.ProxyAddress;
814 SettingDialog.ProxyPort = _cfgLocal.ProxyPort;
815 SettingDialog.ProxyUser = _cfgLocal.ProxyUser;
816 SettingDialog.ProxyPassword = _cfgLocal.ProxyPassword;
818 SettingDialog.StartupVersion = _cfgCommon.StartupVersion;
819 SettingDialog.StartupFollowers = _cfgCommon.StartupFollowers;
820 SettingDialog.RestrictFavCheck = _cfgCommon.RestrictFavCheck;
821 SettingDialog.AlwaysTop = _cfgCommon.AlwaysTop;
822 SettingDialog.UrlConvertAuto = false;
823 //SettingDialog.UrlConvertAuto = _cfgCommon.UrlConvertAuto;
825 SettingDialog.UseUnreadStyle = _cfgCommon.UseUnreadStyle;
826 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
827 SettingDialog.RetweetNoConfirm = _cfgCommon.RetweetNoConfirm;
828 SettingDialog.PlaySound = _cfgCommon.PlaySound;
829 SettingDialog.DateTimeFormat = _cfgCommon.DateTimeFormat;
830 SettingDialog.LimitBalloon = _cfgCommon.LimitBalloon;
831 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
832 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
833 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
834 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
835 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
836 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
837 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
839 //廃止サービスが選択されていた場合bit.lyへ読み替え
840 if (_cfgCommon.AutoShortUrlFirst < 0)
841 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
843 SettingDialog.AutoShortUrlFirst = _cfgCommon.AutoShortUrlFirst;
844 SettingDialog.TabIconDisp = _cfgCommon.TabIconDisp;
845 SettingDialog.ReplyIconState = _cfgCommon.ReplyIconState;
846 SettingDialog.ReadOwnPost = _cfgCommon.ReadOwnPost;
847 SettingDialog.GetFav = _cfgCommon.GetFav;
848 SettingDialog.ReadOldPosts = _cfgCommon.ReadOldPosts;
849 SettingDialog.BitlyUser = _cfgCommon.BilyUser;
850 SettingDialog.BitlyPwd = _cfgCommon.BitlyPwd;
851 SettingDialog.ShowGrid = _cfgCommon.ShowGrid;
852 SettingDialog.Language = _cfgCommon.Language;
853 SettingDialog.UseAtIdSupplement = _cfgCommon.UseAtIdSupplement;
854 SettingDialog.UseHashSupplement = _cfgCommon.UseHashSupplement;
855 SettingDialog.PreviewEnable = _cfgCommon.PreviewEnable;
856 SettingDialog.StatusAreaAtBottom = _cfgCommon.StatusAreaAtBottom;
857 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
859 SettingDialog.IsMonospace = _cfgCommon.IsMonospace;
861 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
862 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
864 //Regex statregex = new Regex("^0*");
865 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
870 if (DateTime.Now.ToString(SettingDialog.DateTimeFormat).Length == 0)
872 // このブロックは絶対に実行されないはず
873 // 変換が成功した場合にLengthが0にならない
874 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
877 catch (FormatException)
879 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
880 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
883 SettingDialog.Nicoms = _cfgCommon.Nicoms;
884 SettingDialog.HotkeyEnabled = _cfgCommon.HotkeyEnabled;
885 SettingDialog.HotkeyMod = _cfgCommon.HotkeyModifier;
886 SettingDialog.HotkeyKey = _cfgCommon.HotkeyKey;
887 SettingDialog.HotkeyValue = _cfgCommon.HotkeyValue;
889 SettingDialog.BlinkNewMentions = _cfgCommon.BlinkNewMentions;
891 SettingDialog.UseAdditionalCount = _cfgCommon.UseAdditionalCount;
892 SettingDialog.MoreCountApi = _cfgCommon.MoreCountApi;
893 SettingDialog.FirstCountApi = _cfgCommon.FirstCountApi;
894 SettingDialog.SearchCountApi = _cfgCommon.SearchCountApi;
895 SettingDialog.FavoritesCountApi = _cfgCommon.FavoritesCountApi;
896 SettingDialog.UserTimelineCountApi = _cfgCommon.UserTimelineCountApi;
897 SettingDialog.ListCountApi = _cfgCommon.ListCountApi;
899 SettingDialog.UserstreamStartup = _cfgCommon.UserstreamStartup;
900 SettingDialog.UserstreamPeriodInt = _cfgCommon.UserstreamPeriod;
901 SettingDialog.OpenUserTimeline = _cfgCommon.OpenUserTimeline;
902 SettingDialog.ListDoubleClickAction = _cfgCommon.ListDoubleClickAction;
903 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
904 SettingDialog.HideDuplicatedRetweets = _cfgCommon.HideDuplicatedRetweets;
906 SettingDialog.EnableImgAzyobuziNet = _cfgCommon.EnableImgAzyobuziNet;
907 SettingDialog.ImgAzyobuziNetDisabledInDM = _cfgCommon.ImgAzyobuziNetDisabledInDM;
908 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
909 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
910 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
911 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
912 SettingDialog.IsListStatusesIncludeRts = _cfgCommon.IsListsIncludeRts;
913 SettingDialog.TabMouseLock = _cfgCommon.TabMouseLock;
914 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
915 SettingDialog.IsNotifyUseGrowl = _cfgCommon.IsUseNotifyGrowl;
918 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
919 HashMgr = new HashtagManage(HashSupl,
920 _cfgCommon.HashTags.ToArray(),
921 _cfgCommon.HashSelected,
922 _cfgCommon.HashIsPermanent,
923 _cfgCommon.HashIsHead,
924 _cfgCommon.HashIsNotAddToAtReply);
925 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
929 Networking.Initialize();
932 this.IconCache = new ImageCache();
934 bool saveRequired = false;
935 bool firstRun = false;
937 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
938 if (string.IsNullOrEmpty(tw.Username))
942 SettingDialog.ShowInTaskbar = true;
944 //設定せずにキャンセルされた場合はプログラム終了
945 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
947 Application.Exit(); //強制終了
950 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
951 if (string.IsNullOrEmpty(tw.Username))
953 Application.Exit(); //強制終了
956 SettingDialog.ShowInTaskbar = false;
960 _fntUnread = SettingDialog.FontUnread;
961 _clUnread = SettingDialog.ColorUnread;
962 _fntReaded = SettingDialog.FontReaded;
963 _clReaded = SettingDialog.ColorReaded;
964 _clFav = SettingDialog.ColorFav;
965 _clOWL = SettingDialog.ColorOWL;
966 _clRetweet = SettingDialog.ColorRetweet;
967 _fntDetail = SettingDialog.FontDetail;
968 _clDetail = SettingDialog.ColorDetail;
969 _clDetailLink = SettingDialog.ColorDetailLink;
970 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
971 _clSelf = SettingDialog.ColorSelf;
972 _clAtSelf = SettingDialog.ColorAtSelf;
973 _clTarget = SettingDialog.ColorTarget;
974 _clAtTarget = SettingDialog.ColorAtTarget;
975 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
976 _clAtTo = SettingDialog.ColorAtTo;
977 _clListBackcolor = SettingDialog.ColorListBackcolor;
978 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
979 _clInputFont = SettingDialog.ColorInputFont;
980 _fntInputFont = SettingDialog.FontInputFont;
982 //他の設定項目は、随時設定画面で保持している値を読み出して使用
985 _brsBackColorMine = new SolidBrush(_clSelf);
986 _brsBackColorAt = new SolidBrush(_clAtSelf);
987 _brsBackColorYou = new SolidBrush(_clTarget);
988 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
989 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
990 _brsBackColorAtTo = new SolidBrush(_clAtTo);
991 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
992 _brsBackColorNone = new SolidBrush(_clListBackcolor);
994 InitDetailHtmlFormat();
996 if (SettingDialog.HotkeyEnabled)
999 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
1000 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
1001 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
1002 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
1003 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
1005 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
1009 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
1010 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
1011 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
1012 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
1014 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
1015 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
1016 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
1017 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
1018 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
1019 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
1020 tw.TrackWord = _cfgCommon.TrackWord;
1021 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
1022 tw.AllAtReply = _cfgCommon.AllAtReply;
1023 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
1026 ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
1029 this.ClientSize = _cfgLocal.FormSize;
1030 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1031 _myLoc = _cfgLocal.FormLocation;
1033 if (this.WindowState != FormWindowState.Minimized)
1035 this.DesktopLocation = _cfgLocal.FormLocation;
1036 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
1037 bool outOfScreen = true;
1038 if (Screen.AllScreens.Length == 1) //ハングするとの報告
1040 foreach (Screen scr in Screen.AllScreens)
1042 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1044 outOfScreen = false;
1050 this.DesktopLocation = new Point(0, 0);
1051 _myLoc = this.DesktopLocation;
1055 this.TopMost = SettingDialog.AlwaysTop;
1056 _mySpDis = _cfgLocal.SplitterDistance;
1057 _mySpDis2 = _cfgLocal.StatusTextHeight;
1058 _mySpDis3 = _cfgLocal.PreviewDistance;
1059 if (_mySpDis3 == -1)
1061 _mySpDis3 = _mySize.Width - 150;
1062 if (_mySpDis3 < 1) _mySpDis3 = 50;
1063 _cfgLocal.PreviewDistance = _mySpDis3;
1065 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
1066 //this.Tween_ClientSizeChanged(this, null);
1067 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
1068 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
1070 StatusText.Font = _fntInputFont;
1071 StatusText.ForeColor = _clInputFont;
1073 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
1074 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
1076 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
1077 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
1079 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1080 if (SettingDialog.UnreadManage == false)
1082 ReadedStripMenuItem.Enabled = false;
1083 UnreadStripMenuItem.Enabled = false;
1086 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
1089 TimerTimeline.AutoReset = true;
1090 TimerTimeline.SynchronizingObject = this;
1092 TimerTimeline.Interval = 1000;
1093 TimerTimeline.Enabled = true;
1096 TimerRefreshIcon.Interval = 200;
1097 TimerRefreshIcon.Enabled = true;
1100 StatusLabel.Text = "";
1101 StatusLabel.AutoToolTip = false;
1102 StatusLabel.ToolTipText = "";
1104 lblLen.Text = GetRestStatusCount(true, false).ToString();
1106 ////////////////////////////////////////////////////////////////////////////////
1107 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1108 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1109 switch (_cfgCommon.SortColumn)
1111 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1115 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1118 mode = IdComparerClass.ComparerMode.Nickname;
1121 mode = IdComparerClass.ComparerMode.Data;
1124 mode = IdComparerClass.ComparerMode.Id;
1127 mode = IdComparerClass.ComparerMode.Name;
1130 mode = IdComparerClass.ComparerMode.Source;
1133 _statuses.SortMode = mode;
1134 ////////////////////////////////////////////////////////////////////////////////
1136 ApplyListViewIconSize(SettingDialog.IconSz);
1138 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1139 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1140 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1141 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1142 SourceLinkLabel.Text = ""; //Source部分初期化
1144 //<<<<<<<<タブ関連>>>>>>>
1145 //デフォルトタブの存在チェック、ない場合には追加
1146 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1149 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1151 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1155 tab.TabType = MyCommon.TabUsageType.Home;
1158 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1161 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1163 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1167 tab.TabType = MyCommon.TabUsageType.Mentions;
1170 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1173 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1175 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1179 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1182 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1185 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1187 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1191 tab.TabType = MyCommon.TabUsageType.Favorites;
1194 foreach (var tab in _statuses.Tabs.Values)
1196 if (tab.TabType == MyCommon.TabUsageType.Undefined)
1198 tab.TabType = MyCommon.TabUsageType.UserDefined;
1200 if (!AddNewTab(tab.TabName, true, tab.TabType, tab.ListInfo))
1201 throw new TabException(Properties.Resources.TweenMain_LoadText1);
1204 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1205 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1206 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1207 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1209 if (SettingDialog.MinimizeToTray == false || this.WindowState != FormWindowState.Minimized)
1211 this.Visible = true;
1213 _curTab = ListTab.SelectedTab;
1215 _curList = (DetailsListView)_curTab.Tag;
1216 SetMainWindowTitle();
1217 SetNotifyIconText();
1219 if (SettingDialog.TabIconDisp)
1221 ListTab.DrawMode = TabDrawMode.Normal;
1225 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1226 ListTab.DrawItem += ListTab_DrawItem;
1227 ListTab.ImageList = null;
1230 _ignoreConfigSave = false;
1231 this.TweenMain_Resize(null, null);
1232 if (saveRequired) SaveConfigsAll(false);
1236 tw.VerifyCredentials();
1237 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1239 if (ua.Username.ToLower() == tw.Username.ToLower())
1241 ua.UserId = tw.UserId;
1246 foreach (UserAccount ua in SettingDialog.UserAccounts)
1248 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1250 ua.UserId = tw.UserId;
1257 // 初回起動時だけ右下のメニューを目立たせる
1258 HashStripSplitButton.ShowDropDown();
1265 private void InitDetailHtmlFormat()
1267 if (SettingDialog.IsMonospace)
1269 detailHtmlFormatHeader = detailHtmlFormatMono1;
1270 detailHtmlFormatFooter = detailHtmlFormatMono7;
1274 detailHtmlFormatHeader = detailHtmlFormat1;
1275 detailHtmlFormatFooter = detailHtmlFormat7;
1277 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();
1278 if (SettingDialog.IsMonospace)
1280 detailHtmlFormatHeader += detailHtmlFormatMono6;
1284 detailHtmlFormatHeader += detailHtmlFormat6;
1288 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1293 txt = ListTab.TabPages[e.Index].Text;
1300 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1301 if (e.State == DrawItemState.Selected)
1303 e.DrawFocusRectangle();
1308 if (_statuses.Tabs[txt].UnreadCount > 0)
1311 fore = System.Drawing.SystemBrushes.ControlText;
1315 fore = System.Drawing.SystemBrushes.ControlText;
1317 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1320 private void LoadConfig()
1322 _cfgCommon = SettingCommon.Load();
1323 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1325 _cfgCommon.UserAccounts = new List<UserAccount>();
1326 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1328 UserAccount account = new UserAccount();
1329 account.Username = _cfgCommon.UserName;
1330 account.UserId = _cfgCommon.UserId;
1331 account.Token = _cfgCommon.Token;
1332 account.TokenSecret = _cfgCommon.TokenSecret;
1334 _cfgCommon.UserAccounts.Add(account);
1337 _cfgLocal = SettingLocal.Load();
1338 List<TabClass> tabs = SettingTabs.Load().Tabs;
1339 foreach (TabClass tb in tabs)
1343 _statuses.Tabs.Add(tb.TabName, tb);
1347 tb.TabName = _statuses.GetUniqueTabName();
1348 _statuses.Tabs.Add(tb.TabName, tb);
1351 if (_statuses.Tabs.Count == 0)
1353 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1354 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1355 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1356 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1360 private void TimerInterval_Changed(object sender, AppendSettingDialog.IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1362 if (!TimerTimeline.Enabled) return;
1366 private AppendSettingDialog.IntervalChangedEventArgs ResetTimers = new AppendSettingDialog.IntervalChangedEventArgs();
1368 private static int homeCounter = 0;
1369 private static int mentionCounter = 0;
1370 private static int dmCounter = 0;
1371 private static int pubSearchCounter = 0;
1372 private static int userTimelineCounter = 0;
1373 private static int listsCounter = 0;
1374 private static int usCounter = 0;
1375 private static int ResumeWait = 0;
1376 private static int refreshFollowers = 0;
1378 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1380 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1381 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1382 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1383 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1384 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1385 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1386 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1387 Interlocked.Increment(ref refreshFollowers);
1390 if (ResetTimers.Timeline || homeCounter <= 0 && SettingDialog.TimelinePeriodInt > 0)
1392 Interlocked.Exchange(ref homeCounter, SettingDialog.TimelinePeriodInt);
1393 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1394 ResetTimers.Timeline = false;
1396 if (ResetTimers.Reply || mentionCounter <= 0 && SettingDialog.ReplyPeriodInt > 0)
1398 Interlocked.Exchange(ref mentionCounter, SettingDialog.ReplyPeriodInt);
1399 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1400 ResetTimers.Reply = false;
1402 if (ResetTimers.DirectMessage || dmCounter <= 0 && SettingDialog.DMPeriodInt > 0)
1404 Interlocked.Exchange(ref dmCounter, SettingDialog.DMPeriodInt);
1405 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1406 ResetTimers.DirectMessage = false;
1408 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && SettingDialog.PubSearchPeriodInt > 0)
1410 Interlocked.Exchange(ref pubSearchCounter, SettingDialog.PubSearchPeriodInt);
1411 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1412 ResetTimers.PublicSearch = false;
1414 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && SettingDialog.UserTimelinePeriodInt > 0)
1416 Interlocked.Exchange(ref userTimelineCounter, SettingDialog.UserTimelinePeriodInt);
1417 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1418 ResetTimers.UserTimeline = false;
1420 if (ResetTimers.Lists || listsCounter <= 0 && SettingDialog.ListsPeriodInt > 0)
1422 Interlocked.Exchange(ref listsCounter, SettingDialog.ListsPeriodInt);
1423 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1424 ResetTimers.Lists = false;
1426 if (ResetTimers.UserStream || usCounter <= 0 && SettingDialog.UserstreamPeriodInt > 0)
1428 Interlocked.Exchange(ref usCounter, SettingDialog.UserstreamPeriodInt);
1429 if (this._isActiveUserstream) RefreshTimeline(true);
1430 ResetTimers.UserStream = false;
1432 if (refreshFollowers > 6 * 3600)
1434 Interlocked.Exchange(ref refreshFollowers, 0);
1435 doGetFollowersMenu();
1436 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
1437 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1441 Interlocked.Increment(ref ResumeWait);
1442 if (ResumeWait > 30)
1445 Interlocked.Exchange(ref ResumeWait, 0);
1446 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1447 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1448 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1449 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1450 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1451 GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1452 doGetFollowersMenu();
1453 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1458 private void RefreshTimeline(bool isUserStream)
1460 if (isUserStream) this.RefreshTasktrayIcon(true);
1462 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1463 long topId = GetScrollPos(ref smode);
1464 int befCnt = _curList.VirtualListSize;
1467 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1468 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
1469 SaveSelectedStatus(selId, focusedId);
1472 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1475 PostClass[] notifyPosts = null;
1476 string soundFile = "";
1478 bool isMention = false;
1479 bool isDelete = false;
1480 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1482 if (MyCommon._endingFlag) return;
1487 foreach (TabPage tab in ListTab.TabPages)
1489 DetailsListView lst = (DetailsListView)tab.Tag;
1490 TabClass tabInfo = _statuses.Tabs[tab.Text];
1491 using (ControlTransaction.Update(lst))
1493 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1495 if (lst.Equals(_curList))
1497 this.PurgeListViewItemCache();
1501 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1507 this.SelectListItem(lst,
1508 tabInfo.IndexOf(selId[tab.Text]),
1509 tabInfo.IndexOf(focusedId[tab.Text]));
1512 if (tabInfo.UnreadCount > 0)
1513 if (SettingDialog.TabIconDisp)
1514 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1516 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
1520 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1529 if (befCnt != _curList.VirtualListSize)
1535 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1539 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1546 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1548 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1549 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1555 catch (Exception ex)
1557 ex.Data["Msg"] = "Ref2";
1563 NotifyNewPosts(notifyPosts,
1566 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1568 SetMainWindowTitle();
1569 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1571 HashSupl.AddRangeItem(tw.GetHashList());
1575 private long GetScrollPos(ref int smode)
1578 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1580 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1582 if (_statuses.SortOrder == SortOrder.Ascending)
1585 if (ListLockMenuItem.Checked)
1590 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1595 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1597 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1598 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1599 if (_item.Index == _curList.VirtualListSize - 1)
1606 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1614 if (ListLockMenuItem.Checked)
1617 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1622 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1625 _item = _curList.GetItemAt(0, 10); //一番上
1626 if (_item == null) _item = _curList.Items[0];
1627 if (_item.Index == 0)
1633 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1642 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1653 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long[]> focusedId)
1655 if (MyCommon._endingFlag) return;
1656 foreach (TabPage tab in ListTab.TabPages)
1658 var lst = (DetailsListView)tab.Tag;
1659 var tabInfo = _statuses.Tabs[tab.Text];
1660 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1662 selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
1666 selId.Add(tab.Text, new long[1] {-2});
1669 var fIds = new long[2]; // 0 = focus, 1 = selection mark
1670 var item = lst.FocusedItem;
1671 fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
1672 var mIdx = lst.SelectionMark;
1673 fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
1674 focusedId.Add(tab.Text, fIds);
1679 private bool BalloonRequired()
1681 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1682 ev.Eventtype = MyCommon.EVENTTYPE.None;
1684 return BalloonRequired(ev);
1687 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1689 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1692 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1694 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1697 private bool BalloonRequired(Twitter.FormattedEvent ev)
1700 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1701 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1705 SettingDialog.LimitBalloon &&
1707 this.WindowState == FormWindowState.Minimized ||
1709 Form.ActiveForm == null
1712 !SettingDialog.LimitBalloon
1715 !NativeMethods.IsScreenSaverRunning())
1725 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1727 if (notifyPosts != null &&
1728 notifyPosts.Length > 0 &&
1729 this.SettingDialog.ReadOwnPost &&
1730 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1736 if (BalloonRequired())
1738 if (notifyPosts != null && notifyPosts.Length > 0)
1740 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1741 if (SettingDialog.IsNotifyUseGrowl)
1743 StringBuilder sb = new StringBuilder();
1747 foreach (PostClass post in notifyPosts)
1749 if (!(notifyPosts.Length > 3))
1755 if (post.IsReply && !post.IsExcludeReply) reply = true;
1756 if (post.IsDm) dm = true;
1757 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1758 switch (SettingDialog.NameBalloon)
1760 case MyCommon.NameBalloonEnum.UserID:
1761 sb.Append(post.ScreenName).Append(" : ");
1763 case MyCommon.NameBalloonEnum.NickName:
1764 sb.Append(post.Nickname).Append(" : ");
1767 sb.Append(post.TextFromApi);
1768 if (notifyPosts.Length > 3)
1770 if (notifyPosts.Last() != post) continue;
1773 StringBuilder title = new StringBuilder();
1774 GrowlHelper.NotifyType nt;
1775 if (SettingDialog.DispUsername)
1777 title.Append(tw.Username);
1778 title.Append(" - ");
1786 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1787 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1788 title.Append(Application.ProductName);
1789 title.Append(" [DM] ");
1790 title.Append(Properties.Resources.RefreshDirectMessageText1);
1792 title.Append(addCount);
1793 title.Append(Properties.Resources.RefreshDirectMessageText2);
1794 nt = GrowlHelper.NotifyType.DirectMessage;
1798 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1799 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1800 title.Append(Application.ProductName);
1801 title.Append(" [Reply!] ");
1802 title.Append(Properties.Resources.RefreshTimelineText1);
1804 title.Append(addCount);
1805 title.Append(Properties.Resources.RefreshTimelineText2);
1806 nt = GrowlHelper.NotifyType.Reply;
1810 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1811 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1812 title.Append(Application.ProductName);
1814 title.Append(Properties.Resources.RefreshTimelineText1);
1816 title.Append(addCount);
1817 title.Append(Properties.Resources.RefreshTimelineText2);
1818 nt = GrowlHelper.NotifyType.Notify;
1820 string bText = sb.ToString();
1821 if (string.IsNullOrEmpty(bText)) return;
1823 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1824 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1829 StringBuilder sb = new StringBuilder();
1832 foreach (PostClass post in notifyPosts)
1834 if (post.IsReply && !post.IsExcludeReply) reply = true;
1835 if (post.IsDm) dm = true;
1836 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1837 switch (SettingDialog.NameBalloon)
1839 case MyCommon.NameBalloonEnum.UserID:
1840 sb.Append(post.ScreenName).Append(" : ");
1842 case MyCommon.NameBalloonEnum.NickName:
1843 sb.Append(post.Nickname).Append(" : ");
1846 sb.Append(post.TextFromApi);
1849 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1850 StringBuilder title = new StringBuilder();
1852 if (SettingDialog.DispUsername)
1854 title.Append(tw.Username);
1855 title.Append(" - ");
1863 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1864 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1865 ntIcon = ToolTipIcon.Warning;
1866 title.Append(Application.ProductName);
1867 title.Append(" [DM] ");
1868 title.Append(Properties.Resources.RefreshDirectMessageText1);
1870 title.Append(addCount);
1871 title.Append(Properties.Resources.RefreshDirectMessageText2);
1875 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1876 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1877 ntIcon = ToolTipIcon.Warning;
1878 title.Append(Application.ProductName);
1879 title.Append(" [Reply!] ");
1880 title.Append(Properties.Resources.RefreshTimelineText1);
1882 title.Append(addCount);
1883 title.Append(Properties.Resources.RefreshTimelineText2);
1887 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1888 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1889 ntIcon = ToolTipIcon.Info;
1890 title.Append(Application.ProductName);
1892 title.Append(Properties.Resources.RefreshTimelineText1);
1894 title.Append(addCount);
1895 title.Append(Properties.Resources.RefreshTimelineText2);
1897 string bText = sb.ToString();
1898 if (string.IsNullOrEmpty(bText)) return;
1899 //NotifyIcon1.BalloonTipText = sb.ToString();
1900 //NotifyIcon1.ShowBalloonTip(500);
1901 NotifyIcon1.BalloonTipTitle = title.ToString();
1902 NotifyIcon1.BalloonTipText = bText;
1903 NotifyIcon1.BalloonTipIcon = ntIcon;
1904 NotifyIcon1.ShowBalloonTip(500);
1910 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(soundFile))
1914 string dir = Application.StartupPath;
1915 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1917 dir = Path.Combine(dir, "Sounds");
1919 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1929 //mentions新着時に画面ブリンク
1930 if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1932 NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
1936 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1938 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1940 _curItemIndex = _curList.SelectedIndices[0];
1941 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1945 _curPost = GetCurTabPost(_curItemIndex);
1947 catch (ArgumentException)
1952 this.PushSelectPostChain();
1954 if (SettingDialog.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
1956 ChangeCacheStyleRead(true, _curItemIndex); //既読へ(フォント、文字色)
1962 private void ChangeCacheStyleRead(bool Read, int Index)
1964 var tabInfo = _statuses.Tabs[_curTab.Text];
1965 //Read:true=既読 false=未読
1966 //未読管理していなかったら既読として扱う
1967 if (!tabInfo.UnreadManage ||
1968 !SettingDialog.UnreadManage) Read = true;
1971 ListViewItem itm = null;
1972 PostClass post = null;
1974 this.TryGetListViewItemCache(Index, out itm, out post);
1976 if (itm == null || post == null)
1978 itm = ((DetailsListView)_curTab.Tag).Items[Index];
1979 post = tabInfo[Index];
1982 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
1985 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
1992 Item.SubItems[5].Text = "";
1997 Item.SubItems[5].Text = "★";
2003 else if (Post.RetweetedId != null)
2005 else if (Post.IsOwl && (Post.IsDm || SettingDialog.OneWayLove))
2007 else if (Read || !SettingDialog.UseUnreadStyle)
2012 if (DList == null || Item.Index == -1)
2014 Item.ForeColor = cl;
2015 if (SettingDialog.UseUnreadStyle)
2021 if (SettingDialog.UseUnreadStyle)
2022 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
2024 DList.ChangeItemForeColor(Item.Index, cl);
2025 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
2029 private void ColorizeList()
2031 //Index:更新対象のListviewItem.Index。Colorを返す。
2032 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2035 _post = _anchorPost;
2039 if (_post == null) return;
2041 var itemColors = new Color[] { };
2044 this.itemCacheLock.EnterReadLock();
2047 if (this._itemCache == null) return;
2050 from i in Enumerable.Range(0, this._itemCache.Length)
2051 select this.JudgeColor(_post, this._postCache[i]);
2053 itemColors = query.ToArray();
2054 itemIndex = _itemCacheIndex;
2056 finally { this.itemCacheLock.ExitReadLock(); }
2058 if (itemIndex < 0) return;
2060 foreach (var backColor in itemColors)
2062 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
2063 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
2064 _curList.ChangeItemBackColor(itemIndex++, backColor);
2068 private void ColorizeList(ListViewItem Item, int Index)
2070 //Index:更新対象のListviewItem.Index。Colorを返す。
2071 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2074 _post = _anchorPost;
2078 PostClass tPost = GetCurTabPost(Index);
2080 if (_post == null) return;
2082 if (Item.Index == -1)
2083 Item.BackColor = JudgeColor(_post, tPost);
2085 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
2088 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
2091 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
2094 else if (TargetPost.IsMe)
2097 else if (TargetPost.IsReply)
2100 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2102 cl = _clAtFromTarget;
2103 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2106 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2111 cl = _clListBackcolor;
2116 private async void PostButton_Click(object sender, EventArgs e)
2118 if (StatusText.Text.Trim().Length == 0)
2120 if (!ImageSelector.Enabled)
2127 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2129 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2131 MessageBoxButtons.YesNoCancel,
2132 MessageBoxIcon.Question);
2135 case DialogResult.Yes:
2136 doReTweetOfficial(false);
2137 StatusText.Text = "";
2139 case DialogResult.Cancel:
2144 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2146 if (SettingDialog.Nicoms)
2148 StatusText.SelectionStart = StatusText.Text.Length;
2149 await UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2151 //if (SettingDialog.UrlConvertAuto)
2153 // StatusText.SelectionStart = StatusText.Text.Length;
2154 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2156 //else if (SettingDialog.Nicoms)
2158 // StatusText.SelectionStart = StatusText.Text.Length;
2159 // UrlConvert(UrlConverter.Nicoms);
2161 StatusText.SelectionStart = StatusText.Text.Length;
2162 GetWorkerArg args = new GetWorkerArg();
2164 args.type = MyCommon.WORKERTYPE.PostMessage;
2165 CheckReplyTo(StatusText.Text);
2168 int adjustCount = 0;
2169 string tmpStatus = StatusText.Text.Trim();
2170 if (ToolStripMenuItemApiCommandEvasion.Checked)
2173 if (Regex.IsMatch(tmpStatus,
2174 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2175 RegexOptions.IgnoreCase)
2176 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2179 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2182 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2185 bool isCutOff = false;
2186 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2187 if (StatusText.Multiline && !SettingDialog.PostCtrlEnter)
2189 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2190 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2192 if (SettingDialog.PostShiftEnter)
2194 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2196 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2198 isRemoveFooter = true;
2200 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2202 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2205 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2206 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2208 isRemoveFooter = true;
2219 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2227 if (HashMgr.IsNotAddToAtReply)
2229 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2232 header = HashMgr.UseHash + " ";
2234 footer = " " + HashMgr.UseHash;
2239 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2242 header = HashMgr.UseHash + " ";
2244 footer = " " + HashMgr.UseHash;
2247 if (!isRemoveFooter)
2249 if (SettingDialog.UseRecommendStatus)
2251 footer += SettingDialog.RecommendStatusText;
2253 // テキストボックスに入力されている文字列を使用する
2254 footer += " " + SettingDialog.Status.Trim();
2257 args.status.status = header + StatusText.Text + footer;
2259 if (ToolStripMenuItemApiCommandEvasion.Checked)
2262 if (Regex.IsMatch(args.status.status,
2263 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2264 RegexOptions.IgnoreCase)
2265 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2268 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2271 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2272 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2275 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2277 // 文中の全角スペースを半角スペース1個にする
2278 args.status.status = args.status.status.Replace(" ", " ");
2281 if (isCutOff && args.status.status.Length > 140)
2283 args.status.status = args.status.status.Substring(0, 140);
2284 string AtId = @"(@|@)[a-z0-9_/]+$";
2285 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2286 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2287 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2288 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2291 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2292 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2294 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2297 args.status.inReplyToId = _reply_to_id;
2298 args.status.inReplyToName = _reply_to_name;
2299 if (ImageSelector.Visible)
2302 if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
2308 _reply_to_id = null;
2309 _reply_to_name = null;
2310 StatusText.Text = "";
2311 _history.Add(new PostingStatus());
2312 _hisIdx = _history.Count - 1;
2313 if (!ToolStripFocusLockMenuItem.Checked)
2314 ((Control)ListTab.SelectedTab.Tag).Focus();
2315 urlUndoBuffer = null;
2316 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2319 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2321 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2322 await this.OpenUriAsync(tmp);
2326 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2328 MyCommon._endingFlag = true;
2332 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2334 if (!SettingDialog.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2336 //_endingFlag=false:フォームの×ボタン
2338 this.Visible = false;
2342 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2343 _ignoreConfigSave = true;
2344 MyCommon._endingFlag = true;
2345 TimerTimeline.Enabled = false;
2346 TimerRefreshIcon.Enabled = false;
2350 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2352 this.Visible = true;
2353 if (this.WindowState == FormWindowState.Minimized)
2355 this.WindowState = FormWindowState.Normal;
2358 this.BringToFront();
2361 private static int errorCount = 0;
2363 private static bool CheckAccountValid()
2365 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2371 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2380 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2382 BackgroundWorker bw = (BackgroundWorker)sender;
2383 if (bw.CancellationPending || MyCommon._endingFlag)
2389 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2391 MyApplication.InitCulture();
2394 GetWorkerResult rslt = new GetWorkerResult();
2396 bool read = !SettingDialog.UnreadManage;
2397 if (_initial && SettingDialog.UnreadManage) read = SettingDialog.Readed;
2399 GetWorkerArg args = (GetWorkerArg)e.Argument;
2401 if (!CheckAccountValid())
2403 rslt.retMsg = "Auth error. Check your account";
2404 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2405 rslt.tName = args.tName;
2410 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2414 case MyCommon.WORKERTYPE.Timeline:
2415 case MyCommon.WORKERTYPE.Reply:
2416 bw.ReportProgress(50, MakeStatusMessage(args, false));
2417 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2419 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && SettingDialog.ReadOldPosts)
2420 _statuses.SetRead();
2422 rslt.addCount = _statuses.DistributePosts();
2424 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2425 bw.ReportProgress(50, MakeStatusMessage(args, false));
2426 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2427 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2428 rslt.addCount = _statuses.DistributePosts();
2431 case MyCommon.WORKERTYPE.FavAdd:
2435 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2437 for (int i = 0; i <= args.ids.Count - 1; i++)
2439 var post = tab.Posts[args.ids[i]];
2442 bw.ReportProgress(50, MakeStatusMessage(args, false));
2445 if (post.RetweetedId == null)
2446 ret = tw.PostFavAdd(post.StatusId);
2448 ret = tw.PostFavAdd(post.RetweetedId.Value);
2450 if (ret.Length == 0)
2452 args.sIds.Add(post.StatusId);
2453 post.IsFav = true; //リスト再描画必要
2454 _favTimestamps.Add(DateTime.Now);
2455 if (string.IsNullOrEmpty(post.RelTabName))
2457 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2458 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2462 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2463 if (_statuses.ContainsKey(post.StatusId))
2465 PostClass postTl = _statuses[post.StatusId];
2466 postTl.IsFav = true;
2467 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2470 //検索,リスト,UserTimeline,Relatedの各タブに反映
2471 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2473 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2479 rslt.sIds = args.sIds;
2483 case MyCommon.WORKERTYPE.FavRemove:
2487 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2489 for (int i = 0; i <= args.ids.Count - 1; i++)
2491 var post = tab.Posts[args.ids[i]];
2494 bw.ReportProgress(50, MakeStatusMessage(args, false));
2497 if (post.RetweetedId == null)
2498 ret = tw.PostFavRemove(post.StatusId);
2500 ret = tw.PostFavRemove(post.RetweetedId.Value);
2502 if (ret.Length == 0)
2504 args.sIds.Add(post.StatusId);
2505 post.IsFav = false; //リスト再描画必要
2506 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2507 //検索,リスト,UserTimeline,Relatedの各タブに反映
2508 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2510 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2516 rslt.sIds = args.sIds;
2520 case MyCommon.WORKERTYPE.PostMessage:
2521 bw.ReportProgress(200);
2522 if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
2524 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2528 var service = ImageSelector.GetService(args.status.imageService);
2531 service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
2534 catch (AggregateException ex)
2536 ret = ex.InnerException.Message;
2539 bw.ReportProgress(300);
2540 rslt.status = args.status;
2542 case MyCommon.WORKERTYPE.Retweet:
2543 bw.ReportProgress(200);
2544 for (int i = 0; i <= args.ids.Count - 1; i++)
2546 ret = tw.PostRetweet(args.ids[i], read);
2548 bw.ReportProgress(300);
2550 case MyCommon.WORKERTYPE.Follower:
2551 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2554 tw.RefreshFollowerIds();
2556 catch (WebApiException ex) { ret = ex.Message; }
2558 case MyCommon.WORKERTYPE.NoRetweetIds:
2561 tw.RefreshNoRetweetIds();
2563 catch (WebApiException ex) { ret = ex.Message; }
2565 case MyCommon.WORKERTYPE.Configuration:
2568 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2570 catch (WebApiException ex) { ret = ex.Message; }
2572 case MyCommon.WORKERTYPE.Favorites:
2573 bw.ReportProgress(50, MakeStatusMessage(args, false));
2574 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2575 rslt.addCount = _statuses.DistributePosts();
2577 case MyCommon.WORKERTYPE.PublicSearch:
2578 bw.ReportProgress(50, MakeStatusMessage(args, false));
2579 if (string.IsNullOrEmpty(args.tName))
2581 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2583 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2584 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2589 TabClass tb = _statuses.GetTabByName(args.tName);
2592 //ret = tw.GetPhoenixSearch(read, tb, false);
2593 ret = tw.GetSearch(read, tb, false);
2594 if (string.IsNullOrEmpty(ret) && args.page == -1)
2596 //ret = tw.GetPhoenixSearch(read, tb, true)
2597 ret = tw.GetSearch(read, tb, true);
2602 rslt.addCount = _statuses.DistributePosts();
2604 case MyCommon.WORKERTYPE.UserTimeline:
2605 bw.ReportProgress(50, MakeStatusMessage(args, false));
2607 if (SettingDialog.UseAdditionalCount) count = SettingDialog.UserTimelineCountApi;
2608 if (string.IsNullOrEmpty(args.tName))
2610 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2612 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2617 TabClass tb = _statuses.GetTabByName(args.tName);
2620 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2624 rslt.addCount = _statuses.DistributePosts();
2626 case MyCommon.WORKERTYPE.List:
2627 bw.ReportProgress(50, MakeStatusMessage(args, false));
2628 if (string.IsNullOrEmpty(args.tName))
2631 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2633 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2639 TabClass tb = _statuses.GetTabByName(args.tName);
2642 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2646 rslt.addCount = _statuses.DistributePosts();
2649 case MyCommon.WORKERTYPE.Related:
2651 bw.ReportProgress(50, MakeStatusMessage(args, false));
2652 TabClass tab = _statuses.GetTabByName(args.tName);
2653 ret = tw.GetRelatedResult(read, tab);
2654 rslt.addCount = _statuses.DistributePosts();
2658 case MyCommon.WORKERTYPE.BlockIds:
2659 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2662 tw.RefreshBlockIds();
2664 catch (WebApiException ex) { ret = ex.Message; }
2668 if (bw.CancellationPending)
2675 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2677 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2678 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2680 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2682 _favTimestamps.RemoveAt(i);
2686 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2690 DateTime tm = DateTime.Now;
2691 if (_tlTimestamps.ContainsKey(tm))
2692 _tlTimestamps[tm] += rslt.addCount;
2694 _tlTimestamps.Add(tm, rslt.addCount);
2696 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2697 List<DateTime> keys = new List<DateTime>();
2699 foreach (DateTime key in _tlTimestamps.Keys)
2701 if (key.CompareTo(oneHour) < 0)
2707 _tlCount += _tlTimestamps[key];
2710 foreach (DateTime key in keys)
2712 _tlTimestamps.Remove(key);
2719 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2722 rslt.type = args.type;
2723 rslt.tName = args.tName;
2728 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2734 switch (AsyncArg.type)
2736 case MyCommon.WORKERTYPE.Timeline:
2737 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2739 case MyCommon.WORKERTYPE.Reply:
2740 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2742 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2743 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2745 case MyCommon.WORKERTYPE.FavAdd:
2746 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2747 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2749 case MyCommon.WORKERTYPE.FavRemove:
2750 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2751 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2753 case MyCommon.WORKERTYPE.Favorites:
2754 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2756 case MyCommon.WORKERTYPE.PublicSearch:
2757 smsg = "Search refreshing...";
2759 case MyCommon.WORKERTYPE.List:
2760 smsg = "List refreshing...";
2762 case MyCommon.WORKERTYPE.Related:
2763 smsg = "Related refreshing...";
2765 case MyCommon.WORKERTYPE.UserTimeline:
2766 smsg = "UserTimeline refreshing...";
2773 switch (AsyncArg.type)
2775 case MyCommon.WORKERTYPE.Timeline:
2776 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2778 case MyCommon.WORKERTYPE.Reply:
2779 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2781 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2782 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2784 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2785 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2787 case MyCommon.WORKERTYPE.FavAdd:
2790 case MyCommon.WORKERTYPE.FavRemove:
2793 case MyCommon.WORKERTYPE.Favorites:
2794 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2796 case MyCommon.WORKERTYPE.Follower:
2797 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2799 case MyCommon.WORKERTYPE.NoRetweetIds:
2800 smsg = "NoRetweetIds refreshed";
2802 case MyCommon.WORKERTYPE.Configuration:
2805 case MyCommon.WORKERTYPE.PublicSearch:
2806 smsg = "Search refreshed";
2808 case MyCommon.WORKERTYPE.List:
2809 smsg = "List refreshed";
2811 case MyCommon.WORKERTYPE.Related:
2812 smsg = "Related refreshed";
2814 case MyCommon.WORKERTYPE.UserTimeline:
2815 smsg = "UserTimeline refreshed";
2817 case MyCommon.WORKERTYPE.BlockIds:
2818 smsg = Properties.Resources.UpdateBlockUserText3;
2825 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2827 if (MyCommon._endingFlag) return;
2828 if (e.ProgressPercentage > 100)
2831 if (e.ProgressPercentage == 200) //開始
2832 StatusLabel.Text = "Posting...";
2833 if (e.ProgressPercentage == 300) //終了
2834 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2838 string smsg = (string)e.UserState;
2839 if (smsg.Length > 0) StatusLabel.Text = smsg;
2843 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2845 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2847 if (e.Error != null)
2849 _myStatusError = true;
2850 _waitTimeline = false;
2854 _waitPubSearch = false;
2855 _waitUserTimeline = false;
2857 throw new Exception("BackgroundWorker Exception", e.Error);
2860 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2863 if (rslt.retMsg.Length > 0)
2865 _myStatusError = true;
2866 StatusLabel.Text = rslt.retMsg;
2869 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2871 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2873 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2877 //bool busy = false;
2878 //foreach (BackgroundWorker bw in _bw)
2880 // if (bw != null && bw.IsBusy)
2886 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2887 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2888 rslt.type == MyCommon.WORKERTYPE.Reply ||
2889 rslt.type == MyCommon.WORKERTYPE.List ||
2890 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2891 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2892 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2893 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2894 rslt.type == MyCommon.WORKERTYPE.Follower ||
2895 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2896 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2897 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2898 rslt.type == MyCommon.WORKERTYPE.Related ||
2899 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2900 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2901 rslt.type == MyCommon.WORKERTYPE.Configuration)
2903 RefreshTimeline(false); //リスト反映
2908 case MyCommon.WORKERTYPE.Timeline:
2909 _waitTimeline = false;
2912 // //API使用時の取得調整は別途考える(カウント調整?)
2915 case MyCommon.WORKERTYPE.Reply:
2917 if (rslt.newDM && !_initial)
2919 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
2922 case MyCommon.WORKERTYPE.Favorites:
2925 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2928 case MyCommon.WORKERTYPE.FavAdd:
2929 case MyCommon.WORKERTYPE.FavRemove:
2930 if (_curList != null && _curTab != null)
2932 using (ControlTransaction.Update(this._curList))
2934 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
2940 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
2942 if (_curTab.Text.Equals(rslt.tName))
2944 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
2947 PostClass post = null;
2948 TabClass tb = _statuses.Tabs[rslt.tName];
2951 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
2953 post = tb.Posts[rslt.sIds[i]];
2957 post = _statuses[rslt.sIds[i]];
2959 ChangeCacheStyleRead(post.IsRead, idx);
2961 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
2969 case MyCommon.WORKERTYPE.PostMessage:
2970 if (string.IsNullOrEmpty(rslt.retMsg) ||
2971 rslt.retMsg.StartsWith("OK:") ||
2972 rslt.retMsg == "Warn:Status is a duplicate.")
2974 _postTimestamps.Add(DateTime.Now);
2975 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2976 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2978 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2980 _postTimestamps.RemoveAt(i);
2984 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
2986 HashMgr.ClearHashtag();
2987 this.HashStripSplitButton.Text = "#[-]";
2988 this.HashToggleMenuItem.Checked = false;
2989 this.HashToggleToolStripMenuItem.Checked = false;
2991 SetMainWindowTitle();
2999 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
3000 Properties.Resources.StatusUpdateFailed1,
3001 Properties.Resources.StatusUpdateFailed2),
3002 "Failed to update status",
3003 MessageBoxButtons.RetryCancel,
3004 MessageBoxIcon.Question);
3008 retry = DialogResult.Abort;
3010 if (retry == DialogResult.Retry)
3012 GetWorkerArg args = new GetWorkerArg();
3014 args.type = MyCommon.WORKERTYPE.PostMessage;
3015 args.status = rslt.status;
3020 if (ToolStripFocusLockMenuItem.Checked)
3022 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
3023 StatusText_Enter(StatusText, new EventArgs());
3027 if (rslt.retMsg.Length == 0 && SettingDialog.PostAndGet)
3029 if (_isActiveUserstream)
3031 RefreshTimeline(true);
3035 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3039 case MyCommon.WORKERTYPE.Retweet:
3040 if (rslt.retMsg.Length == 0)
3042 _postTimestamps.Add(DateTime.Now);
3043 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3044 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3046 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3048 _postTimestamps.RemoveAt(i);
3051 if (!_isActiveUserstream && SettingDialog.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3054 case MyCommon.WORKERTYPE.Follower:
3055 //_waitFollower = false;
3056 this.PurgeListViewItemCache();
3057 if (_curList != null) _curList.Refresh();
3059 case MyCommon.WORKERTYPE.NoRetweetIds:
3061 case MyCommon.WORKERTYPE.Configuration:
3062 //_waitFollower = false
3063 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
3065 foreach (var service in this.ImageSelector.GetServices())
3067 service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
3070 this.PurgeListViewItemCache();
3071 if (_curList != null) _curList.Refresh();
3073 case MyCommon.WORKERTYPE.PublicSearch:
3074 _waitPubSearch = false;
3076 case MyCommon.WORKERTYPE.UserTimeline:
3077 _waitUserTimeline = false;
3079 case MyCommon.WORKERTYPE.List:
3082 case MyCommon.WORKERTYPE.Related:
3083 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
3084 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
3086 foreach (TabPage tp in ListTab.TabPages)
3088 if (tp.Text == tab.TabName)
3090 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
3091 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3100 private async Task RefreshMuteUserIdsAsync()
3102 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
3106 await tw.RefreshMuteUserIdsAsync();
3108 catch (WebApiException ex)
3110 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
3114 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
3117 private void RemovePostFromFavTab(Int64[] ids)
3119 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3121 if (_curTab.Text.Equals(favTabName))
3123 if (_curList.FocusedItem != null)
3124 fidx = _curList.FocusedItem.Index;
3125 else if (_curList.TopItem != null)
3126 fidx = _curList.TopItem.Index;
3131 foreach (long i in ids)
3135 _statuses.RemoveFavPost(i);
3142 if (_curTab != null && _curTab.Text.Equals(favTabName))
3144 this.PurgeListViewItemCache();
3146 //_curItemIndex = -1;
3148 foreach (TabPage tp in ListTab.TabPages)
3150 if (tp.Text == favTabName)
3152 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3156 if (_curTab.Text.Equals(favTabName))
3160 _curList.SelectedIndices.Clear();
3162 while (_curList.SelectedIndices.Count > 0);
3164 if (_statuses.Tabs[favTabName].AllCount > 0)
3166 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3168 _curList.SelectedIndices.Add(fidx);
3172 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3174 if (_curList.SelectedIndices.Count > 0)
3176 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3177 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3183 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3185 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, string tabName)
3187 if (!this.IsNetworkAvailable()) return;
3190 GetWorkerArg args = new GetWorkerArg();
3191 args.page = fromPage;
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, "");
3812 case MyCommon.TabUsageType.DirectMessage:
3813 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
3815 case MyCommon.TabUsageType.Favorites:
3816 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
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, _curTab.Text);
3826 case MyCommon.TabUsageType.UserTimeline:
3827 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, _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, _curTab.Text);
3836 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3842 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
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, "");
3856 case MyCommon.TabUsageType.DirectMessage:
3857 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
3859 case MyCommon.TabUsageType.Favorites:
3860 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, "");
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, _curTab.Text);
3871 case MyCommon.TabUsageType.UserTimeline:
3872 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, _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, _curTab.Text);
3881 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3887 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
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.RestrictFavCheck = SettingDialog.RestrictFavCheck;
3911 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
3912 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
3913 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
3914 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
3915 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3917 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
3918 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
3919 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
3920 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
3922 ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
3926 if (SettingDialog.TabIconDisp)
3928 ListTab.DrawItem -= ListTab_DrawItem;
3929 ListTab.DrawMode = TabDrawMode.Normal;
3930 ListTab.ImageList = this.TabImage;
3934 ListTab.DrawItem -= ListTab_DrawItem;
3935 ListTab.DrawItem += ListTab_DrawItem;
3936 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3937 ListTab.ImageList = null;
3940 catch (Exception ex)
3942 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3943 ex.Data["IsTerminatePermission"] = false;
3949 if (!SettingDialog.UnreadManage)
3951 ReadedStripMenuItem.Enabled = false;
3952 UnreadStripMenuItem.Enabled = false;
3953 if (SettingDialog.TabIconDisp)
3955 foreach (TabPage myTab in ListTab.TabPages)
3957 myTab.ImageIndex = -1;
3963 ReadedStripMenuItem.Enabled = true;
3964 UnreadStripMenuItem.Enabled = true;
3967 catch (Exception ex)
3969 ex.Data["Instance"] = "ListTab(UnreadManage)";
3970 ex.Data["IsTerminatePermission"] = false;
3977 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
3979 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3980 imgazyobizinet.Enabled = this.SettingDialog.EnableImgAzyobuziNet;
3981 imgazyobizinet.DisabledInDM = this.SettingDialog.ImgAzyobuziNetDisabledInDM;
3983 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
3984 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
3985 _fntUnread = SettingDialog.FontUnread;
3986 _clUnread = SettingDialog.ColorUnread;
3987 _fntReaded = SettingDialog.FontReaded;
3988 _clReaded = SettingDialog.ColorReaded;
3989 _clFav = SettingDialog.ColorFav;
3990 _clOWL = SettingDialog.ColorOWL;
3991 _clRetweet = SettingDialog.ColorRetweet;
3992 _fntDetail = SettingDialog.FontDetail;
3993 _clDetail = SettingDialog.ColorDetail;
3994 _clDetailLink = SettingDialog.ColorDetailLink;
3995 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
3996 _clSelf = SettingDialog.ColorSelf;
3997 _clAtSelf = SettingDialog.ColorAtSelf;
3998 _clTarget = SettingDialog.ColorTarget;
3999 _clAtTarget = SettingDialog.ColorAtTarget;
4000 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
4001 _clAtTo = SettingDialog.ColorAtTo;
4002 _clListBackcolor = SettingDialog.ColorListBackcolor;
4003 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
4004 _clInputFont = SettingDialog.ColorInputFont;
4005 _fntInputFont = SettingDialog.FontInputFont;
4006 _brsBackColorMine.Dispose();
4007 _brsBackColorAt.Dispose();
4008 _brsBackColorYou.Dispose();
4009 _brsBackColorAtYou.Dispose();
4010 _brsBackColorAtFromTarget.Dispose();
4011 _brsBackColorAtTo.Dispose();
4012 _brsBackColorNone.Dispose();
4013 _brsBackColorMine = new SolidBrush(_clSelf);
4014 _brsBackColorAt = new SolidBrush(_clAtSelf);
4015 _brsBackColorYou = new SolidBrush(_clTarget);
4016 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
4017 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
4018 _brsBackColorAtTo = new SolidBrush(_clAtTo);
4019 _brsBackColorNone = new SolidBrush(_clListBackcolor);
4023 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
4024 StatusText.Font = _fntInputFont;
4025 StatusText.ForeColor = _clInputFont;
4027 catch (Exception ex)
4029 MessageBox.Show(ex.Message);
4034 InitDetailHtmlFormat();
4036 catch (Exception ex)
4038 ex.Data["Instance"] = "Font";
4039 ex.Data["IsTerminatePermission"] = false;
4045 _statuses.SetUnreadManage(SettingDialog.UnreadManage);
4047 catch (Exception ex)
4049 ex.Data["Instance"] = "_statuses";
4050 ex.Data["IsTerminatePermission"] = false;
4056 foreach (TabPage tb in ListTab.TabPages)
4058 if (SettingDialog.TabIconDisp)
4060 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
4067 catch (Exception ex)
4069 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
4070 ex.Data["IsTerminatePermission"] = false;
4076 var oldIconCol = _iconCol;
4078 if (SettingDialog.IconSz != oldIconSz)
4079 ApplyListViewIconSize(SettingDialog.IconSz);
4081 foreach (TabPage tp in ListTab.TabPages)
4083 DetailsListView lst = (DetailsListView)tp.Tag;
4085 using (ControlTransaction.Update(lst))
4087 lst.GridLines = SettingDialog.ShowGrid;
4088 lst.Font = _fntReaded;
4089 lst.BackColor = _clListBackcolor;
4091 if (_iconCol != oldIconCol)
4096 catch (Exception ex)
4098 ex.Data["Instance"] = "ListView(IconSize)";
4099 ex.Data["IsTerminatePermission"] = false;
4103 SetMainWindowTitle();
4104 SetNotifyIconText();
4106 this.PurgeListViewItemCache();
4107 if (_curList != null) _curList.Refresh();
4110 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4111 if (SettingDialog.HotkeyEnabled)
4113 ///グローバルホットキーの登録。設定で変更可能にするかも
4114 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4115 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
4116 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
4117 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
4118 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
4120 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
4123 if (uid != tw.Username) this.doGetFollowersMenu();
4125 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
4128 StatusText_TextChanged(null, null);
4136 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4138 this.TopMost = SettingDialog.AlwaysTop;
4139 SaveConfigsAll(false);
4145 private void SetTabAlignment()
4147 var newAlignment = SettingDialog.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
4148 if (ListTab.Alignment == newAlignment) return;
4151 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
4152 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
4153 SaveSelectedStatus(selId, focusedId);
4155 ListTab.Alignment = newAlignment;
4158 foreach (TabPage tab in ListTab.TabPages)
4160 DetailsListView lst = (DetailsListView)tab.Tag;
4161 TabClass tabInfo = _statuses.Tabs[tab.Text];
4162 using (ControlTransaction.Update(lst))
4164 this.SelectListItem(lst,
4165 tabInfo.IndexOf(selId[tab.Text]),
4166 tabInfo.IndexOf(focusedId[tab.Text]));
4171 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
4177 case MyCommon.IconSizes.IconNone:
4180 case MyCommon.IconSizes.Icon16:
4183 case MyCommon.IconSizes.Icon24:
4186 case MyCommon.IconSizes.Icon48:
4189 case MyCommon.IconSizes.Icon48_2:
4197 // ディスプレイの DPI 設定を考慮したサイズを設定する
4198 _listViewImageList.ImageSize = new Size(
4200 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4204 _listViewImageList.ImageSize = new Size(1, 1);
4208 private void ResetColumns(DetailsListView list)
4210 using (ControlTransaction.Update(list))
4211 using (ControlTransaction.Layout(list, false))
4214 list.ColumnClick -= MyList_ColumnClick;
4215 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4216 list.ColumnReordered -= MyList_ColumnReordered;
4217 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4219 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4220 list.Columns.Clear();
4221 cols.ForEach(col => col.Dispose());
4224 InitColumns(list, true);
4226 list.ColumnClick += MyList_ColumnClick;
4227 list.DrawColumnHeader += MyList_DrawColumnHeader;
4228 list.ColumnReordered += MyList_ColumnReordered;
4229 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4233 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4235 if (e.Url.AbsoluteUri != "about:blank")
4238 OpenUriAsync(e.Url.OriginalString);
4242 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4244 if (e.Url.Scheme == "data")
4246 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4248 else if (e.Url.AbsoluteUri != "about:blank")
4252 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4253 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4256 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4257 int i = urlStr.IndexOf('#');
4258 if (i == -1) return;
4260 string hash = urlStr.Substring(i);
4261 HashSupl.AddItem(hash);
4262 HashMgr.AddHashToHistory(hash.Trim(), false);
4263 AddNewTabForSearch(hash);
4268 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4269 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4271 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4272 if (SettingDialog.OpenUserTimeline)
4274 if (MyCommon.IsKeyDown(Keys.Control))
4275 OpenUriAsync(e.Url.OriginalString);
4277 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4281 if (MyCommon.IsKeyDown(Keys.Control))
4282 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4284 OpenUriAsync(e.Url.OriginalString);
4289 OpenUriAsync(e.Url.OriginalString);
4295 public void AddNewTabForSearch(string searchWord)
4297 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4298 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4300 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4302 foreach (TabPage tp in ListTab.TabPages)
4304 if (tb.TabName == tp.Text)
4306 ListTab.SelectedTab = tp;
4313 string tabName = searchWord;
4314 for (int i = 0; i <= 100; i++)
4316 if (_statuses.ContainsTab(tabName))
4322 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4323 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4325 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4327 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4328 cmb.Items.Add(searchWord);
4329 cmb.Text = searchWord;
4332 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4335 private void ShowUserTimeline()
4337 if (!this.ExistCurrentPost) return;
4338 AddNewTabForUserTimeline(_curPost.ScreenName);
4341 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4343 if (e.KeyCode == Keys.Escape)
4345 TabPage relTp = ListTab.SelectedTab;
4346 RemoveSpecifiedTab(relTp.Text, false);
4348 e.SuppressKeyPress = true;
4352 public void AddNewTabForUserTimeline(string user)
4354 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4355 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4357 if (tb.User == user)
4359 foreach (TabPage tp in ListTab.TabPages)
4361 if (tb.TabName == tp.Text)
4363 ListTab.SelectedTab = tp;
4370 string tabName = "user:" + user;
4371 while (_statuses.ContainsTab(tabName))
4376 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4377 _statuses.Tabs[tabName].User = user;
4378 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4380 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4384 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, tabName);
4387 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4390 foreach (TabPage tb in ListTab.TabPages)
4392 if (tb.Text == tabName) return false;
4396 if (tabName == Properties.Resources.AddNewTabText1) return false;
4401 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4402 tabType == MyCommon.TabUsageType.Favorites ||
4403 tabType == MyCommon.TabUsageType.Home ||
4404 tabType == MyCommon.TabUsageType.Mentions ||
4405 tabType == MyCommon.TabUsageType.Related)
4407 if (_statuses.GetTabByType(tabType) != null) return false;
4411 TabPage _tabPage = new TabPage();
4412 DetailsListView _listCustom = new DetailsListView();
4414 int cnt = ListTab.TabPages.Count;
4416 ///ToDo:Create and set controls follow tabtypes
4418 using (ControlTransaction.Update(_listCustom))
4419 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4420 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4421 using (ControlTransaction.Layout(this.SplitContainer1, false))
4422 using (ControlTransaction.Layout(this.ListTab, false))
4423 using (ControlTransaction.Layout(this))
4424 using (ControlTransaction.Layout(_tabPage, false))
4428 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4430 label = new Label();
4431 label.Dock = DockStyle.Top;
4432 label.Name = "labelUser";
4433 if (tabType == MyCommon.TabUsageType.Lists)
4435 label.Text = listInfo.ToString();
4439 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4441 label.TextAlign = ContentAlignment.MiddleLeft;
4442 using (ComboBox tmpComboBox = new ComboBox())
4444 label.Height = tmpComboBox.Height;
4446 _tabPage.Controls.Add(label);
4451 if (tabType == MyCommon.TabUsageType.PublicSearch)
4455 Label lbl = new Label();
4456 ComboBox cmb = new ComboBox();
4457 Button btn = new Button();
4458 ComboBox cmbLang = new ComboBox();
4460 pnl.SuspendLayout();
4462 pnl.Controls.Add(cmb);
4463 pnl.Controls.Add(cmbLang);
4464 pnl.Controls.Add(btn);
4465 pnl.Controls.Add(lbl);
4466 pnl.Name = "panelSearch";
4467 pnl.Dock = DockStyle.Top;
4468 pnl.Height = cmb.Height;
4469 pnl.Enter += SearchControls_Enter;
4470 pnl.Leave += SearchControls_Leave;
4473 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4474 cmb.Dock = DockStyle.Fill;
4475 cmb.Name = "comboSearch";
4476 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4477 cmb.ImeMode = ImeMode.NoControl;
4478 cmb.TabStop = false;
4479 cmb.AutoCompleteMode = AutoCompleteMode.None;
4480 cmb.KeyDown += SearchComboBox_KeyDown;
4482 if (_statuses.ContainsTab(tabName))
4484 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4485 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4489 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4490 cmbLang.Dock = DockStyle.Right;
4492 cmbLang.Name = "comboLang";
4493 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4494 cmbLang.TabStop = false;
4495 cmbLang.Items.Add("");
4496 cmbLang.Items.Add("ja");
4497 cmbLang.Items.Add("en");
4498 cmbLang.Items.Add("ar");
4499 cmbLang.Items.Add("da");
4500 cmbLang.Items.Add("nl");
4501 cmbLang.Items.Add("fa");
4502 cmbLang.Items.Add("fi");
4503 cmbLang.Items.Add("fr");
4504 cmbLang.Items.Add("de");
4505 cmbLang.Items.Add("hu");
4506 cmbLang.Items.Add("is");
4507 cmbLang.Items.Add("it");
4508 cmbLang.Items.Add("no");
4509 cmbLang.Items.Add("pl");
4510 cmbLang.Items.Add("pt");
4511 cmbLang.Items.Add("ru");
4512 cmbLang.Items.Add("es");
4513 cmbLang.Items.Add("sv");
4514 cmbLang.Items.Add("th");
4515 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4517 lbl.Text = "Search(C-S-f)";
4518 lbl.Name = "label1";
4519 lbl.Dock = DockStyle.Left;
4521 lbl.Height = cmb.Height;
4522 lbl.TextAlign = ContentAlignment.MiddleLeft;
4524 btn.Text = "Search";
4525 btn.Name = "buttonSearch";
4526 btn.UseVisualStyleBackColor = true;
4527 btn.Dock = DockStyle.Right;
4528 btn.TabStop = false;
4529 btn.Click += SearchButton_Click;
4532 this.ListTab.Controls.Add(_tabPage);
4533 _tabPage.Controls.Add(_listCustom);
4535 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4536 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4538 _tabPage.Location = new Point(4, 4);
4539 _tabPage.Name = "CTab" + cnt.ToString();
4540 _tabPage.Size = new Size(380, 260);
4541 _tabPage.TabIndex = 2 + cnt;
4542 _tabPage.Text = tabName;
4543 _tabPage.UseVisualStyleBackColor = true;
4545 _listCustom.AllowColumnReorder = true;
4546 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4547 _listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4548 _listCustom.Dock = DockStyle.Fill;
4549 _listCustom.FullRowSelect = true;
4550 _listCustom.HideSelection = false;
4551 _listCustom.Location = new Point(0, 0);
4552 _listCustom.Margin = new Padding(0);
4553 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4554 _listCustom.ShowItemToolTips = true;
4555 _listCustom.Size = new Size(380, 260);
4556 _listCustom.UseCompatibleStateImageBehavior = false;
4557 _listCustom.View = View.Details;
4558 _listCustom.OwnerDraw = true;
4559 _listCustom.VirtualMode = true;
4560 _listCustom.Font = _fntReaded;
4561 _listCustom.BackColor = _clListBackcolor;
4563 _listCustom.GridLines = SettingDialog.ShowGrid;
4564 _listCustom.AllowDrop = true;
4566 _listCustom.SmallImageList = _listViewImageList;
4568 InitColumns(_listCustom, startup);
4570 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4571 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4572 _listCustom.ColumnClick += MyList_ColumnClick;
4573 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4574 _listCustom.DragDrop += TweenMain_DragDrop;
4575 _listCustom.DragEnter += TweenMain_DragEnter;
4576 _listCustom.DragOver += TweenMain_DragOver;
4577 _listCustom.DrawItem += MyList_DrawItem;
4578 _listCustom.MouseClick += MyList_MouseClick;
4579 _listCustom.ColumnReordered += MyList_ColumnReordered;
4580 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4581 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4582 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4583 _listCustom.DrawSubItem += MyList_DrawSubItem;
4584 _listCustom.HScrolled += MyList_HScrolled;
4586 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4589 _tabPage.Tag = _listCustom;
4593 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4595 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4599 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4600 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4601 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4607 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4608 if (_tabPage == null) return false;
4610 SetListProperty(); //他のタブに列幅等を反映
4612 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4615 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4616 _tabPage.Tag = null;
4618 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4619 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4620 using (ControlTransaction.Layout(this.SplitContainer1, false))
4621 using (ControlTransaction.Layout(this.ListTab, false))
4622 using (ControlTransaction.Layout(this))
4623 using (ControlTransaction.Layout(_tabPage, false))
4625 if (this.ListTab.SelectedTab == _tabPage)
4627 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4628 this._beforeSelectedTab = null;
4630 this.ListTab.Controls.Remove(_tabPage);
4633 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4635 using (Control label = _tabPage.Controls["labelUser"])
4637 _tabPage.Controls.Remove(label);
4640 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4642 using (Control pnl = _tabPage.Controls["panelSearch"])
4644 pnl.Enter -= SearchControls_Enter;
4645 pnl.Leave -= SearchControls_Leave;
4646 _tabPage.Controls.Remove(pnl);
4648 foreach (Control ctrl in pnl.Controls)
4650 if (ctrl.Name == "buttonSearch")
4652 ctrl.Click -= SearchButton_Click;
4654 else if (ctrl.Name == "comboSearch")
4656 ctrl.KeyDown -= SearchComboBox_KeyDown;
4658 pnl.Controls.Remove(ctrl);
4664 _tabPage.Controls.Remove(_listCustom);
4666 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4667 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4668 _listCustom.ColumnClick -= MyList_ColumnClick;
4669 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4670 _listCustom.DragDrop -= TweenMain_DragDrop;
4671 _listCustom.DragEnter -= TweenMain_DragEnter;
4672 _listCustom.DragOver -= TweenMain_DragOver;
4673 _listCustom.DrawItem -= MyList_DrawItem;
4674 _listCustom.MouseClick -= MyList_MouseClick;
4675 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4676 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4677 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4678 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4679 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4680 _listCustom.HScrolled -= MyList_HScrolled;
4682 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4683 _listCustom.Columns.Clear();
4684 cols.ForEach(col => col.Dispose());
4687 _listCustom.ContextMenuStrip = null;
4688 _listCustom.ColumnHeaderContextMenuStrip = null;
4689 _listCustom.Font = null;
4691 _listCustom.SmallImageList = null;
4692 _listCustom.ListViewItemSorter = null;
4695 if (_curTab.Equals(_tabPage))
4702 this.PurgeListViewItemCache();
4706 _listCustom.Dispose();
4707 _statuses.RemoveTab(TabName);
4709 foreach (TabPage tp in ListTab.TabPages)
4711 DetailsListView lst = (DetailsListView)tp.Tag;
4712 var count = _statuses.Tabs[tp.Text].AllCount;
4713 if (lst.VirtualListSize != count)
4715 lst.VirtualListSize = count;
4722 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4724 this.PurgeListViewItemCache();
4725 _beforeSelectedTab = e.TabPage;
4728 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4732 if (!SettingDialog.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4735 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4736 if (!dragEnableRectangle.Contains(e.Location))
4738 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4739 tn = ListTab.SelectedTab.Text;
4742 if (string.IsNullOrEmpty(tn)) return;
4744 foreach (TabPage tb in ListTab.TabPages)
4748 ListTab.DoDragDrop(tb, DragDropEffects.All);
4758 Point cpos = new Point(e.X, e.Y);
4759 for (int i = 0; i < ListTab.TabPages.Count; i++)
4761 Rectangle rect = ListTab.GetTabRect(i);
4762 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4763 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4765 _rclickTabName = ListTab.TabPages[i].Text;
4771 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4773 //_curList.Refresh();
4775 SetMainWindowTitle();
4776 SetStatusLabelUrl();
4777 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4778 TabMenuControl(ListTab.SelectedTab.Text);
4779 this.PushSelectPostChain();
4782 private void SetListProperty()
4784 //削除などで見つからない場合は処理せず
4785 if (_curList == null) return;
4786 if (!_isColumnChanged) return;
4788 int[] dispOrder = new int[_curList.Columns.Count];
4789 for (int i = 0; i < _curList.Columns.Count; i++)
4791 for (int j = 0; j < _curList.Columns.Count; j++)
4793 if (_curList.Columns[j].DisplayIndex == i)
4802 foreach (TabPage tb in ListTab.TabPages)
4804 if (!tb.Equals(_curTab))
4806 if (tb.Tag != null && tb.Controls.Count > 0)
4808 DetailsListView lst = (DetailsListView)tb.Tag;
4809 for (int i = 0; i < lst.Columns.Count; i++)
4811 lst.Columns[dispOrder[i]].DisplayIndex = i;
4812 lst.Columns[i].Width = _curList.Columns[i].Width;
4818 _isColumnChanged = false;
4821 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4825 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4826 || PostBrowser.StatusText.StartsWith("data"))
4828 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4830 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4832 SetStatusLabelUrl();
4840 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4842 if (e.KeyChar == '@')
4844 if (!SettingDialog.UseAtIdSupplement) return;
4846 int cnt = AtIdSupl.ItemCount;
4847 ShowSuplDialog(StatusText, AtIdSupl);
4848 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4851 else if (e.KeyChar == '#')
4853 if (!SettingDialog.UseHashSupplement) return;
4854 ShowSuplDialog(StatusText, HashSupl);
4859 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4861 ShowSuplDialog(owner, dialog, 0, "");
4864 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4866 ShowSuplDialog(owner, dialog, offset, "");
4869 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4871 dialog.StartsWith = startswith;
4878 dialog.ShowDialog();
4880 this.TopMost = SettingDialog.AlwaysTop;
4881 int selStart = owner.SelectionStart;
4884 if (dialog.DialogResult == DialogResult.OK)
4886 if (!string.IsNullOrEmpty(dialog.inputText))
4890 fHalf = owner.Text.Substring(0, selStart - offset);
4892 if (selStart < owner.Text.Length)
4894 eHalf = owner.Text.Substring(selStart);
4896 owner.Text = fHalf + dialog.inputText + eHalf;
4897 owner.SelectionStart = selStart + dialog.inputText.Length;
4904 fHalf = owner.Text.Substring(0, selStart);
4906 if (selStart < owner.Text.Length)
4908 eHalf = owner.Text.Substring(selStart);
4910 owner.Text = fHalf + eHalf;
4913 owner.SelectionStart = selStart;
4919 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4922 if (!e.Alt && !e.Control && !e.Shift)
4924 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4926 bool isSpace = false;
4927 foreach (char c in StatusText.Text.ToCharArray())
4929 if (c == ' ' || c == ' ')
4942 StatusText.Text = "";
4943 JumpUnreadMenuItem_Click(null, null);
4947 this.StatusText_TextChanged(null, null);
4950 private void StatusText_TextChanged(object sender, EventArgs e)
4953 int pLen = GetRestStatusCount(true, false);
4954 lblLen.Text = pLen.ToString();
4957 StatusText.ForeColor = Color.Red;
4961 StatusText.ForeColor = _clInputFont;
4963 if (string.IsNullOrEmpty(StatusText.Text))
4965 _reply_to_id = null;
4966 _reply_to_name = null;
4970 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
4973 var statusText = this.StatusText.Text;
4974 statusText = statusText.Replace("\r\n", "\n");
4976 int pLen = 140 - statusText.Length;
4977 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
4978 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && SettingDialog.PostShiftEnter) ||
4979 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !SettingDialog.PostShiftEnter) ||
4980 (!isAuto && isAddFooter))
4982 if (SettingDialog.UseRecommendStatus)
4983 pLen -= SettingDialog.RecommendStatusText.Length;
4984 else if (SettingDialog.Status.Length > 0)
4985 pLen -= SettingDialog.Status.Length + 1;
4987 if (!string.IsNullOrEmpty(HashMgr.UseHash))
4989 pLen -= HashMgr.UseHash.Length + 1;
4991 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
4993 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
4995 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
4997 string before = m.Result("${before}");
4998 string url = m.Result("${url}");
4999 string protocol = m.Result("${protocol}");
5000 string domain = m.Result("${domain}");
5001 string path = m.Result("${path}");
5002 if (protocol.Length == 0)
5004 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
5009 bool last_url_invalid_match = false;
5010 string lasturl = null;
5011 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
5013 lasturl = mm.ToString();
5014 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
5015 if (!last_url_invalid_match)
5017 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5021 if (path.Length != 0)
5023 if (last_url_invalid_match)
5025 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5027 pLen += path.Length;
5032 int shortUrlLength = protocol == "https://"
5033 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
5034 : SettingDialog.TwitterConfiguration.ShortUrlLength;
5036 pLen += url.Length - shortUrlLength;
5039 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
5041 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5044 if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
5046 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
5051 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
5053 this.itemCacheLock.EnterUpgradeableReadLock();
5056 if (_curList.Equals(sender))
5058 if (_itemCache != null &&
5059 e.StartIndex >= _itemCacheIndex &&
5060 e.EndIndex < _itemCacheIndex + _itemCache.Length)
5062 //If the newly requested cache is a subset of the old cache,
5063 //no need to rebuild everything, so do nothing.
5067 //Now we need to rebuild the cache.
5068 CreateCache(e.StartIndex, e.EndIndex);
5071 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
5074 private async void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
5076 ListViewItem item = null;
5077 PostClass cacheItemPost = null;
5079 if (_curList.Equals(sender))
5080 this.TryGetListViewItemCache(e.ItemIndex, out item, out cacheItemPost);
5084 //A cache miss, so create a new ListViewItem and pass it back.
5085 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
5088 item = this.CreateItem(tb, _statuses[tb.Text, e.ItemIndex], e.ItemIndex);
5093 string[] sitem = {"", "", "", "", "", "", "", ""};
5094 item = new ImageListViewItem(sitem);
5098 // e.Item に値をセットする前に await しないこと
5101 await ((ImageListViewItem)item).GetImageAsync();
5104 private void CreateCache(int StartIndex, int EndIndex)
5106 this.itemCacheLock.EnterWriteLock();
5109 var tabInfo = _statuses.Tabs[_curTab.Text];
5111 //キャッシュ要求(要求範囲±30を作成)
5113 if (StartIndex < 0) StartIndex = 0;
5115 if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
5116 _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
5117 _itemCacheIndex = StartIndex;
5119 _itemCache = new ListViewItem[0] {};
5120 Array.Resize(ref _itemCache, _postCache.Length);
5122 for (int i = 0; i < _postCache.Length; i++)
5124 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5129 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5131 _itemCacheIndex = -1;
5134 finally { this.itemCacheLock.ExitWriteLock(); }
5138 /// DetailsListView のための ListViewItem のキャッシュを消去する
5140 private void PurgeListViewItemCache()
5142 this.itemCacheLock.EnterWriteLock();
5145 this._itemCache = null;
5146 this._itemCacheIndex = -1;
5147 this._postCache = null;
5149 finally { this.itemCacheLock.ExitWriteLock(); }
5152 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5154 this.itemCacheLock.EnterReadLock();
5157 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5159 item = this._itemCache[index - _itemCacheIndex];
5160 post = this._postCache[index - _itemCacheIndex];
5164 finally { this.itemCacheLock.ExitReadLock(); }
5171 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5173 StringBuilder mk = new StringBuilder();
5174 //if (Post.IsDeleted) mk.Append("×");
5175 //if (Post.IsMark) mk.Append("♪");
5176 //if (Post.IsProtect) mk.Append("Ю");
5177 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5178 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5179 ImageListViewItem itm;
5180 if (Post.RetweetedId == null)
5182 string[] sitem= {"",
5184 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5185 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5190 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5194 string[] sitem = {"",
5196 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5197 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5198 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5202 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5204 itm.StateIndex = Post.StateIndex;
5206 bool read = Post.IsRead;
5207 //未読管理していなかったら既読として扱う
5208 if (!_statuses.Tabs[Tab.Text].UnreadManage || !SettingDialog.UnreadManage) read = true;
5209 ChangeItemStyleRead(read, itm, Post, null);
5210 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5215 /// 全てのタブの振り分けルールを反映し直します
5217 private void ApplyPostFilters()
5221 this.Cursor = Cursors.WaitCursor;
5223 this.PurgeListViewItemCache();
5224 this._curPost = null;
5225 this._curItemIndex = -1;
5226 this._statuses.FilterAll();
5228 foreach (TabPage tabPage in this.ListTab.TabPages)
5230 var tab = this._statuses.Tabs[tabPage.Text];
5232 var listview = (DetailsListView)tabPage.Tag;
5233 listview.VirtualListSize = tab.AllCount;
5235 if (this.SettingDialog.TabIconDisp)
5237 if (tab.UnreadCount > 0)
5238 tabPage.ImageIndex = 0;
5240 tabPage.ImageIndex = -1;
5244 if (!this.SettingDialog.TabIconDisp)
5245 this.ListTab.Refresh();
5249 this.Cursor = Cursors.Default;
5253 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5255 e.DrawDefault = true;
5258 private void MyList_HScrolled(object sender, EventArgs e)
5260 DetailsListView listView = (DetailsListView)sender;
5264 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5266 if (e.State == 0) return;
5267 e.DrawDefault = false;
5269 SolidBrush brs2 = null;
5270 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5272 if (e.Item.BackColor == _clSelf)
5273 brs2 = _brsBackColorMine;
5274 else if (e.Item.BackColor == _clAtSelf)
5275 brs2 = _brsBackColorAt;
5276 else if (e.Item.BackColor == _clTarget)
5277 brs2 = _brsBackColorYou;
5278 else if (e.Item.BackColor == _clAtTarget)
5279 brs2 = _brsBackColorAtYou;
5280 else if (e.Item.BackColor == _clAtFromTarget)
5281 brs2 = _brsBackColorAtFromTarget;
5282 else if (e.Item.BackColor == _clAtTo)
5283 brs2 = _brsBackColorAtTo;
5285 brs2 = _brsBackColorNone;
5290 if (((Control)sender).Focused)
5291 brs2 = _brsHighLight;
5293 brs2 = _brsDeactiveSelection;
5295 e.Graphics.FillRectangle(brs2, e.Bounds);
5296 e.DrawFocusRectangle();
5297 this.DrawListViewItemIcon(e);
5300 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5302 if (e.ItemState == 0) return;
5304 if (e.ColumnIndex > 0)
5307 RectangleF rct = e.Bounds;
5308 rct.Width = e.Header.Width;
5309 int fontHeight = e.Item.Font.Height;
5312 rct.Y += fontHeight;
5313 rct.Height -= fontHeight;
5317 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out heightDiff));
5319 //if (heightDiff > fontHeight * 0.7)
5321 // rct.Height += fontHeight;
5322 // drawLineCount += 1;
5325 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5326 if (!_iconCol && drawLineCount <= 1)
5328 //rct.Inflate(0, heightDiff / -2);
5329 //rct.Height += fontHeight / 2;
5331 else if (heightDiff < fontHeight * 0.7)
5333 //最終行が70%以上欠けていたら、最終行は表示しない
5334 //rct.Height = (float)((fontHeight * drawLineCount) + (fontHeight / 2));
5335 rct.Height = (fontHeight * drawLineCount) - 1;
5342 //if (!_iconCol && drawLineCount > 1)
5344 // rct.Y += fontHeight * 0.2;
5345 // if (heightDiff >= fontHeight * 0.8) rct.Height -= fontHeight * 0.2;
5350 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5351 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5356 Rectangle rctB = e.Bounds;
5357 rctB.Width = e.Header.Width;
5358 rctB.Height = fontHeight;
5360 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5362 TextRenderer.DrawText(e.Graphics,
5363 e.Item.SubItems[2].Text,
5365 Rectangle.Round(rct),
5367 TextFormatFlags.WordBreak |
5368 TextFormatFlags.EndEllipsis |
5369 TextFormatFlags.GlyphOverhangPadding |
5370 TextFormatFlags.NoPrefix);
5371 TextRenderer.DrawText(e.Graphics,
5372 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 + "]",
5376 TextFormatFlags.SingleLine |
5377 TextFormatFlags.EndEllipsis |
5378 TextFormatFlags.GlyphOverhangPadding |
5379 TextFormatFlags.NoPrefix);
5382 else if (drawLineCount == 1)
5384 TextRenderer.DrawText(e.Graphics,
5387 Rectangle.Round(rct),
5389 TextFormatFlags.SingleLine |
5390 TextFormatFlags.EndEllipsis |
5391 TextFormatFlags.GlyphOverhangPadding |
5392 TextFormatFlags.NoPrefix |
5393 TextFormatFlags.VerticalCenter);
5397 TextRenderer.DrawText(e.Graphics,
5400 Rectangle.Round(rct),
5402 TextFormatFlags.WordBreak |
5403 TextFormatFlags.EndEllipsis |
5404 TextFormatFlags.GlyphOverhangPadding |
5405 TextFormatFlags.NoPrefix);
5407 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5412 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5414 if (_iconSz == 0) return;
5416 ImageListViewItem item = (ImageListViewItem)e.Item;
5418 //e.Bounds.Leftが常に0を指すから自前で計算
5419 Rectangle itemRect = item.Bounds;
5420 var col0 = e.Item.ListView.Columns[0];
5421 itemRect.Width = col0.Width;
5423 if (col0.DisplayIndex > 0)
5425 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5427 if (clm.DisplayIndex < col0.DisplayIndex)
5428 itemRect.X += clm.Width;
5432 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5433 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5434 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5437 var img = item.Image;
5440 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5441 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5443 if (iconRect.Width > 0)
5445 e.Graphics.FillRectangle(Brushes.White, iconRect);
5446 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5449 e.Graphics.DrawImage(img.Image, iconRect);
5451 catch (ArgumentException)
5453 item.RefreshImageAsync();
5459 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5460 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5463 if (item.StateIndex > -1)
5465 Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5466 if (stateRect.Width > 0)
5468 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5469 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5470 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5475 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5477 base.ScaleControl(factor, specified);
5479 const int baseDpi = 96;
5481 // デザイン時の DPI (96dpi) との比を更新する
5482 this.currentScaleFactor = new SizeF(
5483 this.CurrentAutoScaleDimensions.Width / baseDpi,
5484 this.CurrentAutoScaleDimensions.Height / baseDpi);
5487 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5489 // ImageListViewItem item = (ImageListViewItem)e.Item;
5490 // if (item.StateImageIndex > -1)
5492 // ////e.Bounds.Leftが常に0を指すから自前で計算
5493 // //Rectangle itemRect = item.Bounds;
5494 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5496 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5498 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5500 // // itemRect.X += clm.Width;
5504 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5505 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5507 // if (rct.Width > 0)
5509 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5510 // //e.Graphics.FillRectangle(Brushes.White, rct);
5511 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5512 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5517 private void DoTabSearch(string _word,
5527 if (_curList.VirtualListSize == 0)
5529 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5532 if (_curList.SelectedIndices.Count > 0)
5534 cidx = _curList.SelectedIndices[0];
5536 toIdx = _curList.VirtualListSize;
5540 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5541 if (_curList.SelectedIndices.Count > 0)
5542 cidx = _curList.SelectedIndices[0];
5546 case SEARCHTYPE.NextSearch: //次を検索
5547 if (_curList.SelectedIndices.Count > 0)
5549 cidx = _curList.SelectedIndices[0] + 1;
5550 if (cidx > toIdx) cidx = toIdx;
5557 case SEARCHTYPE.PrevSearch: //前を検索
5558 if (_curList.SelectedIndices.Count > 0)
5560 cidx = _curList.SelectedIndices[0] - 1;
5561 if (cidx < 0) cidx = 0;
5572 RegexOptions regOpt = RegexOptions.None;
5573 StringComparison fndOpt = StringComparison.Ordinal;
5576 regOpt = RegexOptions.IgnoreCase;
5577 fndOpt = StringComparison.OrdinalIgnoreCase;
5588 _search = new Regex(_word, regOpt);
5589 for (int idx = cidx; idx != toIdx; idx += stp)
5594 post = _statuses[_curTab.Text, idx];
5600 if (_search.IsMatch(post.Nickname)
5601 || _search.IsMatch(post.TextFromApi)
5602 || _search.IsMatch(post.ScreenName))
5604 SelectListItem(_curList, idx);
5605 _curList.EnsureVisible(idx);
5610 catch (ArgumentException)
5612 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5619 for (int idx = cidx; idx != toIdx; idx += stp)
5624 post = _statuses[_curTab.Text, idx];
5630 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5631 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5632 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5634 SelectListItem(_curList, idx);
5635 _curList.EnsureVisible(idx);
5645 case SEARCHTYPE.DialogSearch:
5646 case SEARCHTYPE.NextSearch:
5650 case SEARCHTYPE.PrevSearch:
5652 cidx = _curList.VirtualListSize - 1;
5659 catch (ArgumentOutOfRangeException)
5662 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5665 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5668 this.ShowSearchDialog();
5671 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5673 var previousSearch = this.SearchDialog.ResultOptions;
5674 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5676 this.SearchDialog.Reset();
5677 this.ShowSearchDialog();
5683 previousSearch.Query,
5684 previousSearch.CaseSensitive,
5685 previousSearch.UseRegex,
5686 SEARCHTYPE.NextSearch);
5689 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5691 var previousSearch = this.SearchDialog.ResultOptions;
5692 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5694 this.SearchDialog.Reset();
5695 this.ShowSearchDialog();
5701 previousSearch.Query,
5702 previousSearch.CaseSensitive,
5703 previousSearch.UseRegex,
5704 SEARCHTYPE.PrevSearch);
5708 /// 検索ダイアログを表示し、検索を実行します
5710 private void ShowSearchDialog()
5712 // Recentタブの検索時以外では「新規タブに表示」ボタンを無効化する
5713 if (this._statuses.Tabs[this._curTab.Text].TabType == MyCommon.TabUsageType.Home)
5714 this.SearchDialog.DisableNewTabButton = false;
5716 this.SearchDialog.DisableNewTabButton = true;
5718 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5720 this.TopMost = this.SettingDialog.AlwaysTop;
5723 this.TopMost = this.SettingDialog.AlwaysTop;
5725 var searchOptions = this.SearchDialog.ResultOptions;
5726 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5728 if (searchOptions.NewTab)
5730 var tabName = searchOptions.Query;
5734 tabName = this._statuses.MakeTabName(tabName);
5736 catch (TabException ex)
5738 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5741 this.AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined);
5742 this._statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
5744 var filter = new PostFilterRule
5746 FilterBody = new[] { searchOptions.Query },
5747 UseRegex = searchOptions.UseRegex,
5748 CaseSensitive = searchOptions.CaseSensitive,
5750 this._statuses.Tabs[tabName].AddFilter(filter);
5752 var tabPage = this.ListTab.TabPages.Cast<TabPage>()
5753 .First(x => x.Text == tabName);
5755 this.ListTab.SelectedTab = tabPage;
5756 this.ListTabSelect(tabPage);
5758 this.ApplyPostFilters();
5759 this.SaveConfigsTabs();
5764 searchOptions.Query,
5765 searchOptions.CaseSensitive,
5766 searchOptions.UseRegex,
5767 SEARCHTYPE.DialogSearch);
5770 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5772 this.AddNewTabForSearch(searchOptions.Query);
5776 private void AboutMenuItem_Click(object sender, EventArgs e)
5778 using (TweenAboutBox about = new TweenAboutBox())
5780 about.ShowDialog(this);
5782 this.TopMost = SettingDialog.AlwaysTop;
5785 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5787 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5789 DetailsListView lst = null;
5791 if (ImageSelector.Enabled)
5795 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5798 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5801 ListTab.SelectedIndex = i;
5802 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5803 //_curTab = ListTab.TabPages[i];
5808 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5809 if (idx == -1 && bgnIdx > 0)
5811 for (int i = 0; i < bgnIdx; i++)
5813 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5816 ListTab.SelectedIndex = i;
5817 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5818 //_curTab = ListTab.TabPages[i];
5824 //全部調べたが未読見つからず→先頭タブの最新発言へ
5827 ListTab.SelectedIndex = 0;
5828 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5829 //_curTab = ListTab.TabPages[0];
5830 if (_statuses.SortOrder == SortOrder.Ascending)
5831 idx = lst.VirtualListSize - 1;
5836 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5838 SelectListItem(lst, idx);
5839 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5841 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5842 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5848 lst.EnsureVisible(idx);
5853 lst.EnsureVisible(idx);
5859 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5861 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5863 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5864 OpenUriAsync(MyCommon.GetStatusUrl(post));
5868 private void FavorareMenuItem_Click(object sender, EventArgs e)
5870 if (_curList.SelectedIndices.Count > 0)
5872 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5873 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5877 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5879 await this.CheckNewVersion(false);
5882 private void RunTweenUp()
5884 ProcessStartInfo pinfo = new ProcessStartInfo();
5885 pinfo.UseShellExecute = true;
5886 pinfo.WorkingDirectory = MyCommon.settingPath;
5887 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5888 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5891 Process.Start(pinfo);
5895 MessageBox.Show("Failed to execute TweenUp3.exe.");
5899 public class VersionInfo
5901 public Version Version { get; set; }
5902 public Uri DownloadUri { get; set; }
5903 public string ReleaseNote { get; set; }
5907 /// OpenTween の最新バージョンの情報を取得します
5909 public async Task<VersionInfo> GetVersionInfoAsync()
5911 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5912 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5914 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5915 .ConfigureAwait(false);
5917 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5918 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5920 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5921 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5923 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5925 return new VersionInfo
5927 Version = Version.Parse(msgHeader[0]),
5928 DownloadUri = new Uri(msgHeader[1]),
5929 ReleaseNote = msgBody,
5933 private async Task CheckNewVersion(bool startup = false)
5935 if (ApplicationSettings.VersionInfoUrl == null)
5936 return; // 更新チェック無効化
5940 var versionInfo = await this.GetVersionInfoAsync();
5942 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5947 var msgtext = string.Format(Properties.Resources.CheckNewVersionText7,
5948 MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version));
5949 msgtext = MyCommon.ReplaceAppName(msgtext);
5951 MessageBox.Show(msgtext,
5952 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5953 MessageBoxButtons.OK, MessageBoxIcon.Information);
5958 using (var dialog = new UpdateDialog())
5960 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5961 MyCommon.GetReadableVersion(versionInfo.Version));
5962 dialog.DetailsText = versionInfo.ReleaseNote;
5964 if (dialog.ShowDialog(this) == DialogResult.Yes)
5966 await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString);
5972 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5975 MessageBox.Show(Properties.Resources.CheckNewVersionText10,
5976 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5977 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5982 private void Colorize()
5986 //件数関連の場合、タイトル即時書き換え
5987 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
5988 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5989 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5990 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5992 SetMainWindowTitle();
5994 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
5995 foreach (TabPage tb in ListTab.TabPages)
5997 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
5999 if (SettingDialog.TabIconDisp)
6001 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
6005 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
6008 public string createDetailHtml(string orgdata)
6010 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
6013 private async void DisplayItemImage_Downloaded(object sender, EventArgs e)
6015 if (sender.Equals(displayItem))
6017 this.ClearUserPicture();
6019 var img = displayItem.Image;
6023 img = await img.CloneAsync();
6025 UserPicture.Image = img;
6029 UserPicture.ShowErrorImage();
6034 private void DispSelectedPost()
6036 DispSelectedPost(false);
6039 private PostClass displayPost = new PostClass();
6042 /// サムネイルの表示処理を表すタスク
6044 private Task thumbnailTask = null;
6047 /// サムネイル表示に使用する CancellationToken の生成元
6049 private CancellationTokenSource thumbnailTokenSource = null;
6051 private void DispSelectedPost(bool forceupdate)
6053 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
6056 var oldDisplayPost = this.displayPost;
6057 this.displayPost = this._curPost;
6059 if (!forceupdate && this._curPost.Equals(oldDisplayPost))
6062 if (displayItem != null)
6064 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
6067 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
6068 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
6070 using (ControlTransaction.Update(this.TableLayoutPanel1))
6072 var sourceText = "";
6073 string sourceUrl = null;
6076 var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
6079 var src = mc.Groups["sourceurl"].Value;
6080 if (Regex.IsMatch(src, "^https?://"))
6083 sourceUrl = "https://twitter.com/" + src;
6086 if (_curPost.Source != null)
6087 sourceText = _curPost.Source;
6089 SourceLinkLabel.Text = sourceText;
6090 SourceLinkLabel.Tag = sourceUrl;
6091 SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
6097 nameText = "DM FROM <- ";
6099 nameText = "DM TO -> ";
6105 nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
6106 if (_curPost.RetweetedId != null)
6107 nameText += " (RT:" + _curPost.RetweetedBy + ")";
6109 NameLabel.Text = nameText;
6110 NameLabel.Tag = _curPost.ScreenName;
6112 var nameForeColor = SystemColors.ControlText;
6113 if (_curPost.IsOwl && (this.SettingDialog.OneWayLove || _curPost.IsDm))
6114 nameForeColor = this._clOWL;
6115 if (_curPost.RetweetedId != null)
6116 nameForeColor = this._clRetweet;
6118 nameForeColor = this._clFav;
6119 NameLabel.ForeColor = nameForeColor;
6121 this.ClearUserPicture();
6123 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6125 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6128 UserPicture.Image = image != null ? image.Clone() : null;
6132 UserPicture.ShowErrorImage();
6136 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6138 if (DumpPostClassToolStripMenuItem.Checked)
6140 StringBuilder sb = new StringBuilder(512);
6142 sb.Append("-----Start PostClass Dump<br>");
6143 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6144 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6145 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6146 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6147 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6148 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6149 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6150 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6151 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6152 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6153 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6154 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6155 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6156 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6157 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6159 foreach (string nm in _curPost.ReplyToList)
6161 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6164 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6165 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6166 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6167 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6168 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6169 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6170 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6171 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6172 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6173 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6174 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6175 sb.Append("-----End PostClass Dump<br>");
6177 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6181 // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
6182 // (同一ツイートの RT は文面が同じであるため同様に更新しない)
6183 if (_curPost.StatusId != oldDisplayPost.StatusId)
6185 this.PostBrowser.DocumentText =
6186 this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6188 this.PostBrowser.Document.Window.ScrollTo(0, 0);
6190 this.SplitContainer3.Panel2Collapsed = true;
6192 if (this.IsPreviewEnable)
6194 if (this.thumbnailTokenSource != null)
6196 var oldTokenSource = this.thumbnailTokenSource;
6198 var cancelTask = Task.Run(() => oldTokenSource.Cancel());
6200 Task.WhenAll(this.thumbnailTask, cancelTask)
6201 .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
6204 this.thumbnailTokenSource = new CancellationTokenSource();
6206 var token = this.thumbnailTokenSource.Token;
6207 this.thumbnailTask = this.tweetThumbnail1.ShowThumbnailAsync(_curPost, token);
6214 private void MatomeMenuItem_Click(object sender, EventArgs e)
6216 OpenApplicationWebsite();
6219 private void OpenApplicationWebsite()
6221 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6224 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6226 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6229 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6231 if (ListTab.SelectedTab != null)
6233 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6235 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6236 if (pnl.Controls["comboSearch"].Focused ||
6237 pnl.Controls["comboLang"].Focused ||
6238 pnl.Controls["buttonSearch"].Focused) return;
6240 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6241 if (State == ModifierState.NotFlags) return;
6242 if (State != ModifierState.None) _anchorFlag = false;
6243 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6246 e.SuppressKeyPress = true;
6251 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6253 ModifierState state = ModifierState.None;
6254 if (sControl) state = state | ModifierState.Ctrl;
6255 if (sShift) state = state | ModifierState.Shift;
6256 if (sAlt) state = state | ModifierState.Alt;
6261 private enum ModifierState
6273 //PostBrowser = 102,
6277 private enum FocusedControl : int
6285 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6287 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6288 if (Focused == FocusedControl.ListTab)
6290 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6291 Modifier == ModifierState.Ctrl ||
6292 Modifier == ModifierState.None ||
6293 Modifier == ModifierState.Shift)
6295 if (KeyCode == Keys.J)
6297 SendKeys.Send("{DOWN}");
6300 else if (KeyCode == Keys.K)
6302 SendKeys.Send("{UP}");
6306 if (Modifier == ModifierState.Shift ||
6307 Modifier == ModifierState.None)
6309 if (KeyCode == Keys.F)
6311 SendKeys.Send("{PGDN}");
6314 else if (KeyCode == Keys.B)
6316 SendKeys.Send("{PGUP}");
6325 case ModifierState.None:
6330 OpenApplicationWebsite();
6333 MenuItemSearchNext_Click(null, null);
6339 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
6342 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
6345 if (Focused != FocusedControl.StatusText)
6351 case Keys.ProcessKey:
6352 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6353 JumpUnreadMenuItem_Click(null, null);
6356 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6357 ShowRelatedStatusesMenuItem_Click(null, null);
6361 if (Focused == FocusedControl.ListTab)
6374 case Keys.OemPeriod:
6378 if (this.StatusText.Enabled) this.StatusText.Focus();
6381 MakeReplyOrDirectStatus();
6388 _anchorFlag = false;
6408 // ] in_reply_to参照元へ戻る
6409 GoInReplyToPostTree();
6412 // [ in_reply_toへジャンプ
6413 GoBackInReplyToPostTree();
6416 if (ListTab.SelectedTab != null)
6418 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6419 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6421 TabPage relTp = ListTab.SelectedTab;
6422 RemoveSpecifiedTab(relTp.Text, false);
6430 else if (Focused == FocusedControl.PostBrowser)
6437 //スクロールを発生させるため、true を返す
6442 case ModifierState.Ctrl:
6447 MakeReplyOrDirectStatus(false, true);
6453 MakeReplyOrDirectStatus(false, false);
6456 FavoriteChange(true);
6459 doRepliedStatusOpen();
6465 ReadedStripMenuItem_Click(null, null);
6468 HashManageMenuItem_Click(null, null);
6471 UrlConvertAutoToolStripMenuItem_Click(null, null);
6474 if (Focused != FocusedControl.PostBrowser)
6476 MultiLineMenuItem_Click(null, null);
6481 MenuItemSubSearch_Click(null, null);
6488 MoveToHomeToolStripMenuItem_Click(null, null);
6492 MoveToFavToolStripMenuItem_Click(null, null);
6496 StatusOpenMenuItem_Click(null, null);
6500 OpenURLMenuItem_Click(null, null);
6504 if (Focused == FocusedControl.ListTab)
6511 return false; //スルーする
6529 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6530 int tabNo = KeyCode - Keys.D1;
6531 if (ListTab.TabPages.Count < tabNo)
6533 ListTab.SelectedIndex = tabNo;
6534 ListTabSelect(ListTab.TabPages[tabNo]);
6537 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6538 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6542 else if (Focused == FocusedControl.StatusText)
6548 StatusText.SelectAll();
6552 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6554 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6556 if (KeyCode == Keys.Up)
6559 if (_hisIdx < 0) _hisIdx = 0;
6564 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6566 StatusText.Text = _history[_hisIdx].status;
6567 _reply_to_id = _history[_hisIdx].inReplyToId;
6568 _reply_to_name = _history[_hisIdx].inReplyToName;
6569 StatusText.SelectionStart = StatusText.Text.Length;
6573 if (ListTab.SelectedIndex == 0)
6575 ListTab.SelectedIndex = ListTab.TabCount - 1;
6579 ListTab.SelectedIndex -= 1;
6585 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6587 ListTab.SelectedIndex = 0;
6591 ListTab.SelectedIndex += 1;
6599 //フォーカスPostBrowserもしくは関係なし
6603 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6607 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6608 if (!string.IsNullOrEmpty(_selText))
6612 Clipboard.SetDataObject(_selText, false, 5, 100);
6614 catch (Exception ex)
6616 MessageBox.Show(ex.Message);
6621 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6622 MultiLineMenuItem_Click(null, null);
6627 case ModifierState.Shift:
6632 MenuItemSearchPrev_Click(null, null);
6638 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
6641 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
6645 if (Focused != FocusedControl.StatusText)
6647 if (KeyCode == Keys.R)
6654 if (Focused == FocusedControl.ListTab)
6674 GoBackInReplyToPostTree(true, false);
6677 GoBackInReplyToPostTree(true, true);
6681 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6686 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6690 this.GoBackSelectPostChain();
6695 case ModifierState.Alt:
6699 doReTweetOfficial(true);
6702 if (_curPost != null)
6704 doShowUserStatus(_curPost.ScreenName, false);
6709 ScrollDownPostBrowser(false);
6712 ScrollDownPostBrowser(true);
6715 PageDownPostBrowser(false);
6718 PageDownPostBrowser(true);
6721 if (Focused == FocusedControl.ListTab)
6723 // 別タブの同じ書き込みへ(ALT+←/→)
6724 if (KeyCode == Keys.Right)
6726 GoSamePostToAnotherTab(false);
6729 else if (KeyCode == Keys.Left)
6731 GoSamePostToAnotherTab(true);
6736 case ModifierState.Ctrl | ModifierState.Shift:
6740 MakeReplyOrDirectStatus(false, true, true);
6746 if (ListTab.SelectedTab != null)
6748 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6750 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6756 FavoriteChange(false);
6759 UnreadStripMenuItem_Click(null, null);
6762 HashToggleMenuItem_Click(null, null);
6765 ImageSelectMenuItem_Click(null, null);
6771 FavorareMenuItem_Click(null, null);
6774 if (Focused == FocusedControl.StatusText)
6780 if (_curList != null && _curList.VirtualListSize != 0 &&
6781 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6783 idx = _curList.SelectedIndices[0] - 1;
6784 SelectListItem(_curList, idx);
6785 _curList.EnsureVisible(idx);
6790 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6791 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6793 idx = _curList.SelectedIndices[0] + 1;
6794 SelectListItem(_curList, idx);
6795 _curList.EnsureVisible(idx);
6800 if (StatusText.SelectionStart > 0)
6802 int endidx = StatusText.SelectionStart - 1;
6803 string startstr = "";
6804 bool pressed = false;
6805 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6807 char c = StatusText.Text[i];
6808 if (Char.IsLetterOrDigit(c) || c == '_')
6815 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6816 int cnt = AtIdSupl.ItemCount;
6817 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6818 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6823 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6824 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6836 else if (Focused == FocusedControl.ListTab)
6838 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6850 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6851 int colNo = KeyCode - Keys.D1;
6852 if (lst.Columns.Count < colNo) return false;
6853 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6854 if (col == null) return false;
6855 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6858 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6859 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6864 case ModifierState.Ctrl | ModifierState.Alt:
6865 if (KeyCode == Keys.S)
6867 FavoritesRetweetOriginal();
6870 else if (KeyCode == Keys.R)
6872 FavoritesRetweetUnofficial();
6875 else if (KeyCode == Keys.H)
6877 OpenUserAppointUrl();
6881 case ModifierState.Alt | ModifierState.Shift:
6882 if (Focused == FocusedControl.PostBrowser)
6884 if (KeyCode == Keys.R)
6885 doReTweetUnofficial();
6886 else if (KeyCode == Keys.C)
6893 if (!this.ExistCurrentPost) return false;
6894 doTranslation(_curPost.TextFromApi);
6897 doReTweetUnofficial();
6903 this.tweetThumbnail1.ScrollUp();
6906 this.tweetThumbnail1.ScrollDown();
6909 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6911 if (!this.SplitContainer3.Panel2Collapsed)
6913 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6923 private void ScrollDownPostBrowser(bool forward)
6925 var doc = PostBrowser.Document;
6926 if (doc == null) return;
6928 var tags = doc.GetElementsByTagName("html");
6932 tags[0].ScrollTop += SettingDialog.FontDetail.Height;
6934 tags[0].ScrollTop -= SettingDialog.FontDetail.Height;
6938 private void PageDownPostBrowser(bool forward)
6940 var doc = PostBrowser.Document;
6941 if (doc == null) return;
6943 var tags = doc.GetElementsByTagName("html");
6947 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6949 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6953 private void GoNextTab(bool forward)
6955 int idx = ListTab.SelectedIndex;
6959 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6964 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6966 ListTab.SelectedIndex = idx;
6967 ListTabSelect(ListTab.TabPages[idx]);
6970 private void CopyStot()
6973 StringBuilder sb = new StringBuilder();
6974 bool IsProtected = false;
6976 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6977 foreach (int idx in _curList.SelectedIndices)
6979 PostClass post = _statuses[_curTab.Text, idx];
6985 if (post.IsDeleted) continue;
6988 if (post.RetweetedId != null)
6989 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6991 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6995 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7000 MessageBox.Show(Properties.Resources.CopyStotText1);
7004 clstr = sb.ToString();
7007 Clipboard.SetDataObject(clstr, false, 5, 100);
7009 catch (Exception ex)
7011 MessageBox.Show(ex.Message);
7016 private void CopyIdUri()
7019 StringBuilder sb = new StringBuilder();
7020 if (this._curTab == null) return;
7021 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
7022 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
7023 foreach (int idx in _curList.SelectedIndices)
7025 var post = _statuses[_curTab.Text, idx];
7026 sb.Append(MyCommon.GetStatusUrl(post));
7027 sb.Append(Environment.NewLine);
7031 clstr = sb.ToString();
7034 Clipboard.SetDataObject(clstr, false, 5, 100);
7036 catch (Exception ex)
7038 MessageBox.Show(ex.Message);
7043 private void GoFav(bool forward)
7045 if (_curList.VirtualListSize == 0) return;
7052 if (_curList.SelectedIndices.Count == 0)
7058 fIdx = _curList.SelectedIndices[0] + 1;
7059 if (fIdx > _curList.VirtualListSize - 1) return;
7061 toIdx = _curList.VirtualListSize;
7066 if (_curList.SelectedIndices.Count == 0)
7068 fIdx = _curList.VirtualListSize - 1;
7072 fIdx = _curList.SelectedIndices[0] - 1;
7073 if (fIdx < 0) return;
7079 for (int idx = fIdx; idx != toIdx; idx += stp)
7081 if (_statuses[_curTab.Text, idx].IsFav)
7083 SelectListItem(_curList, idx);
7084 _curList.EnsureVisible(idx);
7090 private void GoSamePostToAnotherTab(bool left)
7092 if (_curList.VirtualListSize == 0) return;
7098 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7099 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7101 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7106 if (ListTab.SelectedIndex == 0)
7112 fIdx = ListTab.SelectedIndex - 1;
7120 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7126 fIdx = ListTab.SelectedIndex + 1;
7128 toIdx = ListTab.TabCount;
7133 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7135 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7136 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7138 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7140 ListTab.SelectedIndex = tabidx;
7141 ListTabSelect(ListTab.TabPages[tabidx]);
7142 SelectListItem(_curList, idx);
7143 _curList.EnsureVisible(idx);
7152 private void GoPost(bool forward)
7154 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7161 fIdx = _curList.SelectedIndices[0] + 1;
7162 if (fIdx > _curList.VirtualListSize - 1) return;
7163 toIdx = _curList.VirtualListSize;
7168 fIdx = _curList.SelectedIndices[0] - 1;
7169 if (fIdx < 0) return;
7175 if (_curPost.RetweetedId == null)
7177 name = _curPost.ScreenName;
7181 name = _curPost.RetweetedBy;
7183 for (int idx = fIdx; idx != toIdx; idx += stp)
7185 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7187 if (_statuses[_curTab.Text, idx].ScreenName == name)
7189 SelectListItem(_curList, idx);
7190 _curList.EnsureVisible(idx);
7196 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7198 SelectListItem(_curList, idx);
7199 _curList.EnsureVisible(idx);
7206 private void GoRelPost(bool forward)
7208 if (_curList.SelectedIndices.Count == 0) return;
7215 fIdx = _curList.SelectedIndices[0] + 1;
7216 if (fIdx > _curList.VirtualListSize - 1) return;
7217 toIdx = _curList.VirtualListSize;
7222 fIdx = _curList.SelectedIndices[0] - 1;
7223 if (fIdx < 0) return;
7230 if (_curPost == null) return;
7231 _anchorPost = _curPost;
7236 if (_anchorPost == null) return;
7239 for (int idx = fIdx; idx != toIdx; idx += stp)
7241 PostClass post = _statuses[_curTab.Text, idx];
7242 if (post.ScreenName == _anchorPost.ScreenName ||
7243 post.RetweetedBy == _anchorPost.ScreenName ||
7244 post.ScreenName == _anchorPost.RetweetedBy ||
7245 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7246 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7247 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7248 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7249 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7251 SelectListItem(_curList, idx);
7252 _curList.EnsureVisible(idx);
7258 private void GoAnchor()
7260 if (_anchorPost == null) return;
7261 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7262 if (idx == -1) return;
7264 SelectListItem(_curList, idx);
7265 _curList.EnsureVisible(idx);
7268 private void GoTopEnd(bool GoTop)
7275 _item = _curList.GetItemAt(0, 25);
7283 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7285 idx = _curList.VirtualListSize - 1;
7289 SelectListItem(_curList, idx);
7292 private void GoMiddle()
7299 _item = _curList.GetItemAt(0, 0);
7309 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7312 idx2 = _curList.VirtualListSize - 1;
7318 idx3 = (idx1 + idx2) / 2;
7320 SelectListItem(_curList, idx3);
7323 private void GoLast()
7325 if (_curList.VirtualListSize == 0) return;
7327 if (_statuses.SortOrder == SortOrder.Ascending)
7329 SelectListItem(_curList, _curList.VirtualListSize - 1);
7330 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7334 SelectListItem(_curList, 0);
7335 _curList.EnsureVisible(0);
7339 private void MoveTop()
7341 if (_curList.SelectedIndices.Count == 0) return;
7342 int idx = _curList.SelectedIndices[0];
7343 if (_statuses.SortOrder == SortOrder.Ascending)
7345 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7349 _curList.EnsureVisible(0);
7351 _curList.EnsureVisible(idx);
7354 private void GoInReplyToPostTree()
7356 if (_curPost == null) return;
7358 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7360 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7362 PostClass post = null;
7363 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7364 if (string.IsNullOrEmpty(r) && post != null)
7366 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7367 _curPost.InReplyToUser = post.InReplyToUser;
7368 _curPost.IsReply = post.IsReply;
7369 this.PurgeListViewItemCache();
7370 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7374 this.StatusLabel.Text = r;
7378 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7380 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7382 replyChains = new Stack<ReplyChain>();
7384 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7387 string inReplyToTabName;
7388 long inReplyToId = _curPost.InReplyToStatusId.Value;
7389 string inReplyToUser = _curPost.InReplyToUser;
7390 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7392 var inReplyToPosts = from tab in _statuses.Tabs.Values
7393 orderby tab != curTabClass
7394 from post in tab.Posts.Values
7395 where post.StatusId == inReplyToId
7396 let index = tab.IndexOf(post.StatusId)
7398 select new {Tab = tab, Index = index};
7402 var inReplyPost = inReplyToPosts.First();
7403 inReplyToTabName = inReplyPost.Tab.TabName;
7404 inReplyToIndex = inReplyPost.Index;
7406 catch (InvalidOperationException)
7408 PostClass post = null;
7409 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7410 if (string.IsNullOrEmpty(r) && post != null)
7413 _statuses.AddPost(post);
7414 _statuses.DistributePosts();
7415 //_statuses.SubmitUpdate(null, null, null, false);
7416 this.RefreshTimeline(false);
7419 var inReplyPost = inReplyToPosts.First();
7420 inReplyToTabName = inReplyPost.Tab.TabName;
7421 inReplyToIndex = inReplyPost.Index;
7423 catch (InvalidOperationException)
7425 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7431 this.StatusLabel.Text = r;
7432 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7437 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7438 DetailsListView listView = (DetailsListView)tabPage.Tag;
7440 if (_curTab != tabPage)
7442 this.ListTab.SelectTab(tabPage);
7445 this.SelectListItem(listView, inReplyToIndex);
7446 listView.EnsureVisible(inReplyToIndex);
7449 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7451 if (_curPost == null) return;
7453 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7454 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7458 if (_curPost.InReplyToStatusId != null)
7460 var posts = from t in _statuses.Tabs
7461 from p in t.Value.Posts
7462 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7463 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7465 orderby isForward ? indexOf : indexOf * -1
7466 orderby t.Value != curTabClass
7467 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7470 var postList = posts.ToList();
7471 for (int i = postList.Count - 1; i >= 0; i--)
7474 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7476 postList.RemoveAt(index);
7479 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7480 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7481 if (post == null) post = postList.First();
7482 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7483 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7484 SelectListItem(listView, post.Index);
7485 listView.EnsureVisible(post.Index);
7487 catch (InvalidOperationException)
7495 if (replyChains == null || replyChains.Count < 1)
7497 var posts = from t in _statuses.Tabs
7498 from p in t.Value.Posts
7499 where p.Value.InReplyToStatusId == _curPost.StatusId
7500 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7503 orderby t.Value != curTabClass
7504 select new {Tab = t.Value, Index = indexOf};
7507 var post = posts.First();
7508 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7509 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7510 SelectListItem(listView, post.Index);
7511 listView.EnsureVisible(post.Index);
7513 catch (InvalidOperationException)
7520 ReplyChain chainHead = replyChains.Pop();
7521 if (chainHead.InReplyToId == _curPost.StatusId)
7523 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7532 ListTab.SelectTab(chainHead.OriginalTab);
7538 SelectListItem(_curList, idx);
7539 _curList.EnsureVisible(idx);
7545 this.GoBackInReplyToPostTree(parallel);
7551 private void GoBackSelectPostChain()
7553 if (this.selectPostChains.Count > 1)
7562 this.selectPostChains.Pop();
7563 var tabPostPair = this.selectPostChains.Peek();
7565 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) continue; //該当タブが存在しないので無視
7567 if (tabPostPair.Item2 != null)
7569 idx = this._statuses.Tabs[tabPostPair.Item1.Text].IndexOf(tabPostPair.Item2.StatusId);
7570 if (idx == -1) continue; //該当ポストが存在しないので無視
7573 tp = tabPostPair.Item1;
7575 this.selectPostChains.Pop();
7577 catch (InvalidOperationException)
7583 while (this.selectPostChains.Count > 1);
7588 //履歴が残り1つであればクリアしておく
7589 if (this.selectPostChains.Count == 1)
7590 this.selectPostChains.Clear();
7594 DetailsListView lst = (DetailsListView)tp.Tag;
7595 this.ListTab.SelectedTab = tp;
7598 SelectListItem(lst, idx);
7599 lst.EnsureVisible(idx);
7605 private void PushSelectPostChain()
7607 int count = this.selectPostChains.Count;
7610 var p = this.selectPostChains.Peek();
7611 if (p.Item1 == this._curTab)
7613 if (p.Item2 == this._curPost) return; //最新の履歴と同一
7614 if (p.Item2 == null) this.selectPostChains.Pop(); //置き換えるため削除
7617 if (count >= 2500) TrimPostChain();
7618 this.selectPostChains.Push(Tuple.Create(this._curTab, this._curPost));
7621 private void TrimPostChain()
7623 if (this.selectPostChains.Count <= 2000) return;
7624 var p = new Stack<Tuple<TabPage, PostClass>>(2000);
7625 for (int i = 0; i < 2000; i++)
7627 p.Push(this.selectPostChains.Pop());
7629 this.selectPostChains.Clear();
7630 for (int i = 0; i < 2000; i++)
7632 this.selectPostChains.Push(p.Pop());
7636 private bool GoStatus(long statusId)
7638 if (statusId == 0) return false;
7639 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7641 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7643 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7644 ListTab.SelectedIndex = tabidx;
7645 ListTabSelect(ListTab.TabPages[tabidx]);
7646 SelectListItem(_curList, idx);
7647 _curList.EnsureVisible(idx);
7654 private bool GoDirectMessage(long statusId)
7656 if (statusId == 0) return false;
7657 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7659 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7661 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7662 ListTab.SelectedIndex = tabidx;
7663 ListTabSelect(ListTab.TabPages[tabidx]);
7664 SelectListItem(_curList, idx);
7665 _curList.EnsureVisible(idx);
7672 private void MyList_MouseClick(object sender, MouseEventArgs e)
7674 _anchorFlag = false;
7677 private void StatusText_Enter(object sender, EventArgs e)
7679 // フォーカスの戻り先を StatusText に設定
7680 this.Tag = StatusText;
7681 StatusText.BackColor = _clInputBackcolor;
7684 public Color InputBackColor
7686 get { return _clInputBackcolor; }
7687 set { _clInputBackcolor = value; }
7690 private void StatusText_Leave(object sender, EventArgs e)
7692 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7693 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7694 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7697 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7699 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7700 if (State == ModifierState.NotFlags) return;
7701 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7704 e.SuppressKeyPress = true;
7707 this.StatusText_TextChanged(null, null);
7710 private void SaveConfigsAll(bool ifModified)
7714 SaveConfigsCommon();
7721 if (_modifySettingCommon) SaveConfigsCommon();
7722 if (_modifySettingLocal) SaveConfigsLocal();
7723 if (_modifySettingAtId) SaveConfigsAtId();
7727 private void SaveConfigsAtId()
7729 if (_ignoreConfigSave || !SettingDialog.UseAtIdSupplement && AtIdSupl == null) return;
7731 _modifySettingAtId = false;
7732 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7736 private void SaveConfigsCommon()
7738 if (_ignoreConfigSave) return;
7740 _modifySettingCommon = false;
7743 _cfgCommon.UserName = tw.Username;
7744 _cfgCommon.UserId = tw.UserId;
7745 _cfgCommon.Password = tw.Password;
7746 _cfgCommon.Token = tw.AccessToken;
7747 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7748 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7749 _cfgCommon.UserstreamStartup = SettingDialog.UserstreamStartup;
7750 _cfgCommon.UserstreamPeriod = SettingDialog.UserstreamPeriodInt;
7751 _cfgCommon.TimelinePeriod = SettingDialog.TimelinePeriodInt;
7752 _cfgCommon.ReplyPeriod = SettingDialog.ReplyPeriodInt;
7753 _cfgCommon.DMPeriod = SettingDialog.DMPeriodInt;
7754 _cfgCommon.PubSearchPeriod = SettingDialog.PubSearchPeriodInt;
7755 _cfgCommon.ListsPeriod = SettingDialog.ListsPeriodInt;
7756 _cfgCommon.UserTimelinePeriod = SettingDialog.UserTimelinePeriodInt;
7757 _cfgCommon.Read = SettingDialog.Readed;
7758 _cfgCommon.IconSize = SettingDialog.IconSz;
7759 _cfgCommon.UnreadManage = SettingDialog.UnreadManage;
7760 _cfgCommon.PlaySound = SettingDialog.PlaySound;
7761 _cfgCommon.OneWayLove = SettingDialog.OneWayLove;
7763 _cfgCommon.NameBalloon = SettingDialog.NameBalloon;
7764 _cfgCommon.PostCtrlEnter = SettingDialog.PostCtrlEnter;
7765 _cfgCommon.PostShiftEnter = SettingDialog.PostShiftEnter;
7766 _cfgCommon.CountApi = SettingDialog.CountApi;
7767 _cfgCommon.CountApiReply = SettingDialog.CountApiReply;
7768 _cfgCommon.PostAndGet = SettingDialog.PostAndGet;
7769 _cfgCommon.DispUsername = SettingDialog.DispUsername;
7770 _cfgCommon.MinimizeToTray = SettingDialog.MinimizeToTray;
7771 _cfgCommon.CloseToExit = SettingDialog.CloseToExit;
7772 _cfgCommon.DispLatestPost = SettingDialog.DispLatestPost;
7773 _cfgCommon.SortOrderLock = SettingDialog.SortOrderLock;
7774 _cfgCommon.ViewTabBottom = SettingDialog.ViewTabBottom;
7775 _cfgCommon.TinyUrlResolve = SettingDialog.TinyUrlResolve;
7776 _cfgCommon.StartupVersion = SettingDialog.StartupVersion;
7777 _cfgCommon.StartupFollowers = SettingDialog.StartupFollowers;
7778 _cfgCommon.RestrictFavCheck = SettingDialog.RestrictFavCheck;
7779 _cfgCommon.AlwaysTop = SettingDialog.AlwaysTop;
7780 _cfgCommon.UrlConvertAuto = SettingDialog.UrlConvertAuto;
7781 _cfgCommon.UseUnreadStyle = SettingDialog.UseUnreadStyle;
7782 _cfgCommon.DateTimeFormat = SettingDialog.DateTimeFormat;
7783 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7784 _cfgCommon.RetweetNoConfirm = SettingDialog.RetweetNoConfirm;
7785 _cfgCommon.LimitBalloon = SettingDialog.LimitBalloon;
7786 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7787 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7788 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7789 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7790 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7791 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7792 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7793 _cfgCommon.AutoShortUrlFirst = SettingDialog.AutoShortUrlFirst;
7794 _cfgCommon.TabIconDisp = SettingDialog.TabIconDisp;
7795 _cfgCommon.ReplyIconState = SettingDialog.ReplyIconState;
7796 _cfgCommon.ReadOwnPost = SettingDialog.ReadOwnPost;
7797 _cfgCommon.GetFav = SettingDialog.GetFav;
7798 _cfgCommon.IsMonospace = SettingDialog.IsMonospace;
7799 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7800 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7802 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7804 _cfgCommon.ReadOldPosts = SettingDialog.ReadOldPosts;
7805 _cfgCommon.BilyUser = SettingDialog.BitlyUser;
7806 _cfgCommon.BitlyPwd = SettingDialog.BitlyPwd;
7807 _cfgCommon.ShowGrid = SettingDialog.ShowGrid;
7808 _cfgCommon.UseAtIdSupplement = SettingDialog.UseAtIdSupplement;
7809 _cfgCommon.UseHashSupplement = SettingDialog.UseHashSupplement;
7810 _cfgCommon.PreviewEnable = SettingDialog.PreviewEnable;
7811 _cfgCommon.StatusAreaAtBottom = SettingDialog.StatusAreaAtBottom;
7812 _cfgCommon.Language = SettingDialog.Language;
7814 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7815 switch (_statuses.SortMode)
7817 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7818 _cfgCommon.SortColumn = 1;
7820 case IdComparerClass.ComparerMode.Data: //本文
7821 _cfgCommon.SortColumn = 2;
7823 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7824 _cfgCommon.SortColumn = 3;
7826 case IdComparerClass.ComparerMode.Name: //名前
7827 _cfgCommon.SortColumn = 4;
7829 case IdComparerClass.ComparerMode.Source: //Source
7830 _cfgCommon.SortColumn = 7;
7834 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7835 _cfgCommon.HashTags = HashMgr.HashHistories;
7836 if (HashMgr.IsPermanent)
7838 _cfgCommon.HashSelected = HashMgr.UseHash;
7842 _cfgCommon.HashSelected = "";
7844 _cfgCommon.HashIsHead = HashMgr.IsHead;
7845 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7846 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7847 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7848 _cfgCommon.HotkeyEnabled = SettingDialog.HotkeyEnabled;
7849 _cfgCommon.HotkeyModifier = SettingDialog.HotkeyMod;
7850 _cfgCommon.HotkeyKey = SettingDialog.HotkeyKey;
7851 _cfgCommon.HotkeyValue = SettingDialog.HotkeyValue;
7852 _cfgCommon.BlinkNewMentions = SettingDialog.BlinkNewMentions;
7853 if (ToolStripFocusLockMenuItem != null &&
7854 ToolStripFocusLockMenuItem.IsDisposed == false)
7856 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7858 _cfgCommon.UseAdditionalCount = SettingDialog.UseAdditionalCount;
7859 _cfgCommon.MoreCountApi = SettingDialog.MoreCountApi;
7860 _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi;
7861 _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi;
7862 _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi;
7863 _cfgCommon.UserTimelineCountApi = SettingDialog.UserTimelineCountApi;
7864 _cfgCommon.TrackWord = tw.TrackWord;
7865 _cfgCommon.AllAtReply = tw.AllAtReply;
7866 _cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
7867 _cfgCommon.ListCountApi = SettingDialog.ListCountApi;
7868 _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
7869 _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
7870 _cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
7871 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7872 _cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
7873 _cfgCommon.EnableImgAzyobuziNet = SettingDialog.EnableImgAzyobuziNet;
7874 _cfgCommon.ImgAzyobuziNetDisabledInDM = SettingDialog.ImgAzyobuziNetDisabledInDM;
7875 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7876 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7877 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7878 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7879 _cfgCommon.IsListsIncludeRts = SettingDialog.IsListStatusesIncludeRts;
7880 _cfgCommon.TabMouseLock = SettingDialog.TabMouseLock;
7881 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7882 _cfgCommon.IsUseNotifyGrowl = SettingDialog.IsNotifyUseGrowl;
7888 private void SaveConfigsLocal()
7890 if (_ignoreConfigSave) return;
7893 _modifySettingLocal = false;
7894 _cfgLocal.FormSize = _mySize;
7895 _cfgLocal.FormLocation = _myLoc;
7896 _cfgLocal.SplitterDistance = _mySpDis;
7897 _cfgLocal.PreviewDistance = _mySpDis3;
7898 _cfgLocal.StatusMultiline = StatusText.Multiline;
7899 _cfgLocal.StatusTextHeight = _mySpDis2;
7900 _cfgLocal.StatusText = SettingDialog.Status;
7902 _cfgLocal.FontUnread = _fntUnread;
7903 _cfgLocal.ColorUnread = _clUnread;
7904 _cfgLocal.FontRead = _fntReaded;
7905 _cfgLocal.ColorRead = _clReaded;
7906 _cfgLocal.FontDetail = _fntDetail;
7907 _cfgLocal.ColorDetail = _clDetail;
7908 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7909 _cfgLocal.ColorDetailLink = _clDetailLink;
7910 _cfgLocal.ColorFav = _clFav;
7911 _cfgLocal.ColorOWL = _clOWL;
7912 _cfgLocal.ColorRetweet = _clRetweet;
7913 _cfgLocal.ColorSelf = _clSelf;
7914 _cfgLocal.ColorAtSelf = _clAtSelf;
7915 _cfgLocal.ColorTarget = _clTarget;
7916 _cfgLocal.ColorAtTarget = _clAtTarget;
7917 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7918 _cfgLocal.ColorAtTo = _clAtTo;
7919 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7920 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7921 _cfgLocal.ColorInputFont = _clInputFont;
7922 _cfgLocal.FontInputFont = _fntInputFont;
7924 _cfgLocal.BrowserPath = SettingDialog.BrowserPath;
7925 _cfgLocal.UseRecommendStatus = SettingDialog.UseRecommendStatus;
7926 _cfgLocal.ProxyType = SettingDialog.SelectedProxyType;
7927 _cfgLocal.ProxyAddress = SettingDialog.ProxyAddress;
7928 _cfgLocal.ProxyPort = SettingDialog.ProxyPort;
7929 _cfgLocal.ProxyUser = SettingDialog.ProxyUser;
7930 _cfgLocal.ProxyPassword = SettingDialog.ProxyPassword;
7931 if (_ignoreConfigSave) return;
7936 private void SaveConfigsTabs()
7938 SettingTabs tabSetting = new SettingTabs();
7939 for (int i = 0; i < ListTab.TabPages.Count; i++)
7941 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7946 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7949 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7950 if (ret != DialogResult.OK)
7953 var match = Twitter.StatusUrlRegex.Match(inputText);
7956 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7957 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7961 var statusId = long.Parse(match.Groups["StatusId"].Value);
7963 var post = this._statuses[statusId];
7968 post = await Task.Run(() =>
7970 PostClass newPost = null;
7972 var err = this.tw.GetStatusApi(false, statusId, ref newPost);
7973 if (!string.IsNullOrEmpty(err))
7974 throw new WebApiException(err);
7979 catch (WebApiException ex)
7981 var message = ex.Message;
7982 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7983 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7990 this.OpenRelatedTab(post);
7992 catch (TabException ex)
7994 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7998 private void SaveLogMenuItem_Click(object sender, EventArgs e)
8000 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
8001 Properties.Resources.SaveLogMenuItem_ClickText2,
8002 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
8003 if (rslt == DialogResult.Cancel) return;
8005 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
8006 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
8007 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
8008 SaveFileDialog1.FilterIndex = 0;
8009 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
8010 SaveFileDialog1.RestoreDirectory = true;
8012 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
8014 if (!SaveFileDialog1.ValidateNames) return;
8015 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
8017 if (rslt == DialogResult.Yes)
8020 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
8022 PostClass post = _statuses[_curTab.Text, idx];
8023 string protect = "";
8024 if (post.IsProtect) protect = "Protect";
8025 sw.WriteLine(post.Nickname + "\t" +
8026 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8027 post.CreatedAt.ToString() + "\t" +
8028 post.ScreenName + "\t" +
8029 post.StatusId.ToString() + "\t" +
8030 post.ImageUrl + "\t" +
8031 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8037 foreach (int idx in _curList.SelectedIndices)
8039 PostClass post = _statuses[_curTab.Text, idx];
8040 string protect = "";
8041 if (post.IsProtect) protect = "Protect";
8042 sw.WriteLine(post.Nickname + "\t" +
8043 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8044 post.CreatedAt.ToString() + "\t" +
8045 post.ScreenName + "\t" +
8046 post.StatusId.ToString() + "\t" +
8047 post.ImageUrl + "\t" +
8048 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8054 this.TopMost = SettingDialog.AlwaysTop;
8057 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
8059 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
8060 if (State == ModifierState.NotFlags) return;
8061 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
8064 e.IsInputKey = true;
8067 public bool TabRename(ref string tabName)
8070 string newTabText = null;
8071 using (InputTabName inputName = new InputTabName())
8073 inputName.TabName = tabName;
8074 inputName.ShowDialog();
8075 if (inputName.DialogResult == DialogResult.Cancel) return false;
8076 newTabText = inputName.TabName;
8078 this.TopMost = SettingDialog.AlwaysTop;
8079 if (!string.IsNullOrEmpty(newTabText))
8082 for (int i = 0; i < ListTab.TabCount; i++)
8084 if (ListTab.TabPages[i].Text == newTabText)
8086 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
8087 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8091 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
8092 for (int i = 0; i < ListTab.TabCount; i++)
8094 if (ListTab.TabPages[i].Text == tabName)
8096 ListTab.TabPages[i].Text = newTabText;
8099 _statuses.RenameTab(tabName, newTabText);
8101 for (int i = 0; i < ListTab.TabCount; i++)
8103 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
8105 if (ListTab.TabPages[i].Text == tabName)
8107 ListTab.TabPages[i].Text = newTabText;
8111 SaveConfigsCommon();
8113 _rclickTabName = newTabText;
8114 tabName = newTabText;
8123 private void ListTab_MouseClick(object sender, MouseEventArgs e)
8125 if (e.Button == MouseButtons.Middle)
8127 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
8129 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8131 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
8132 this.SaveConfigsTabs();
8139 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
8141 string tn = ListTab.SelectedTab.Text;
8145 private void ListTab_MouseDown(object sender, MouseEventArgs e)
8147 if (SettingDialog.TabMouseLock) return;
8148 Point cpos = new Point(e.X, e.Y);
8149 if (e.Button == MouseButtons.Left)
8151 for (int i = 0; i < ListTab.TabPages.Count; i++)
8153 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8156 _tabMouseDownPoint = e.Location;
8167 private void ListTab_DragEnter(object sender, DragEventArgs e)
8169 if (e.Data.GetDataPresent(typeof(TabPage)))
8170 e.Effect = DragDropEffects.Move;
8172 e.Effect = DragDropEffects.None;
8175 private void ListTab_DragDrop(object sender, DragEventArgs e)
8177 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8182 Point cpos = new Point(e.X, e.Y);
8183 Point spos = ListTab.PointToClient(cpos);
8185 for (i = 0; i < ListTab.TabPages.Count; i++)
8187 Rectangle rect = ListTab.GetTabRect(i);
8188 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8189 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8191 tn = ListTab.TabPages[i].Text;
8192 if (spos.X <= (rect.Left + rect.Right) / 2)
8201 //タブのないところにドロップ->最後尾へ移動
8202 if (string.IsNullOrEmpty(tn))
8204 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8206 i = ListTab.TabPages.Count - 1;
8209 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8210 if (tp.Text == tn) return;
8212 ReOrderTab(tp.Text, tn, bef);
8215 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8218 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8220 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8223 using (ControlTransaction.Layout(this.ListTab))
8226 for (int j = 0; j < ListTab.TabPages.Count; j++)
8228 if (ListTab.TabPages[j].Text == targetTabText)
8230 mTp = ListTab.TabPages[j];
8231 ListTab.TabPages.Remove(mTp);
8232 if (j < baseIndex) baseIndex -= 1;
8236 if (isBeforeBaseTab)
8237 ListTab.TabPages.Insert(baseIndex, mTp);
8239 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8245 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8247 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8248 //isReply:true=@,false=DM
8249 if (!StatusText.Enabled) return;
8250 if (_curList == null) return;
8251 if (_curTab == null) return;
8252 if (!this.ExistCurrentPost) return;
8254 // 複数あてリプライはReplyではなく通常ポスト
8255 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8256 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8257 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8259 if (_curList.SelectedIndices.Count > 0)
8262 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8265 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8268 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8269 StatusText.SelectionStart = StatusText.Text.Length;
8271 _reply_to_id = null;
8272 _reply_to_name = null;
8275 if (string.IsNullOrEmpty(StatusText.Text))
8279 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8280 StatusText.Text = "@" + _curPost.ScreenName + " ";
8281 if (_curPost.RetweetedId != null)
8283 _reply_to_id = _curPost.RetweetedId.Value;
8287 _reply_to_id = _curPost.StatusId;
8289 _reply_to_name = _curPost.ScreenName;
8297 //1件選んでEnter or DoubleClick
8298 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8300 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8303 if (_curPost.RetweetedId != null)
8305 _reply_to_id = _curPost.RetweetedId.Value;
8309 _reply_to_id = _curPost.StatusId;
8311 _reply_to_name = _curPost.ScreenName;
8315 if (!StatusText.Text.StartsWith("@"))
8318 if (StatusText.Text.StartsWith(". "))
8321 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8322 _reply_to_id = null;
8323 _reply_to_name = null;
8328 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8329 if (_curPost.RetweetedId != null)
8331 _reply_to_id = _curPost.RetweetedId.Value;
8335 _reply_to_id = _curPost.StatusId;
8337 _reply_to_name = _curPost.ScreenName;
8344 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8345 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8346 _reply_to_id = null;
8347 _reply_to_name = null;
8352 //1件選んでCtrl-Rの場合(返信先操作せず)
8353 int sidx = StatusText.SelectionStart;
8354 string id = "@" + _curPost.ScreenName + " ";
8357 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8362 StatusText.Text = StatusText.Text.Insert(sidx, id);
8364 //if (StatusText.Text.StartsWith("@"))
8367 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8368 // sidx += 5 + _curPost.ScreenName.Length;
8373 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8374 // sidx += 3 + _curPost.ScreenName.Length;
8376 StatusText.SelectionStart = sidx;
8379 //_reply_to_name = null;
8387 if (!isAuto && !isReply) return;
8389 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8393 //Enter or DoubleClick
8395 string sTxt = StatusText.Text;
8396 if (!sTxt.StartsWith(". "))
8399 _reply_to_id = null;
8400 _reply_to_name = null;
8402 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8404 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8405 if (!sTxt.Contains("@" + post.ScreenName + " "))
8407 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8408 //sTxt = "@" + post.ScreenName + " " + sTxt;
8411 StatusText.Text = sTxt;
8416 if (_curList.SelectedIndices.Count > 1)
8421 int sidx = StatusText.SelectionStart;
8422 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8424 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8425 if (!ids.Contains("@" + post.ScreenName + " ") &&
8426 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8428 ids += "@" + post.ScreenName + " ";
8432 foreach (string nm in post.ReplyToList)
8434 if (!ids.Contains("@" + nm + " ") &&
8435 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8437 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8439 ids += "@" + m.Result("${id}") + " ";
8441 ids += "@" + nm + " ";
8446 if (ids.Length == 0) return;
8447 if (!StatusText.Text.StartsWith(". "))
8449 StatusText.Text = ". " + StatusText.Text;
8451 _reply_to_id = null;
8452 _reply_to_name = null;
8456 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8461 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8463 //if (StatusText.Text.StartsWith("@"))
8465 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8466 // sidx += 2 + ids.Length;
8470 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8471 // sidx += 1 + ids.Length;
8473 StatusText.SelectionStart = sidx;
8479 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8482 int sidx = StatusText.SelectionStart;
8483 PostClass post = _curPost;
8484 if (!ids.Contains("@" + post.ScreenName + " ") &&
8485 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8487 ids += "@" + post.ScreenName + " ";
8489 foreach (string nm in post.ReplyToList)
8491 if (!ids.Contains("@" + nm + " ") &&
8492 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8494 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8496 ids += "@" + m.Result("${id}") + " ";
8498 ids += "@" + nm + " ";
8501 if (!string.IsNullOrEmpty(post.RetweetedBy))
8503 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8504 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8506 ids += "@" + post.RetweetedBy + " ";
8509 if (ids.Length == 0) return;
8510 if (string.IsNullOrEmpty(StatusText.Text))
8513 StatusText.Text = ids;
8514 StatusText.SelectionStart = ids.Length;
8516 if (post.RetweetedId != null)
8518 _reply_to_id = post.RetweetedId.Value;
8522 _reply_to_id = post.StatusId;
8524 _reply_to_name = post.ScreenName;
8530 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8535 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8537 StatusText.SelectionStart = sidx;
8543 StatusText.SelectionStart = StatusText.Text.Length;
8548 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8553 private static int iconCnt = 0;
8554 private static int blinkCnt = 0;
8555 private static bool blink = false;
8556 private static bool idle = false;
8558 private void RefreshTasktrayIcon(bool forceRefresh)
8560 if (_colorize) Colorize();
8561 if (!TimerRefreshIcon.Enabled) return;
8562 //Static usCheckCnt As int = 0
8564 //Static iconDlListTopItem As ListViewItem = null
8566 if (forceRefresh) idle = false;
8568 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8569 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8571 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8573 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8579 //if (usCheckCnt > 300) //1min
8582 // if (!this.IsReceivedUserStream)
8584 // TraceOut("ReconnectUserStream");
8585 // tw.ReconnectUserStream();
8590 foreach (BackgroundWorker bw in this._bw)
8592 if (bw != null && bw.IsBusy)
8607 SaveConfigsAll(true);
8612 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8614 _myStatusError = false;
8618 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8619 if (SettingDialog.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8621 if (blinkCnt > 0) return;
8623 if (blink || SettingDialog.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8625 NotifyIcon1.Icon = ReplyIcon;
8629 NotifyIcon1.Icon = ReplyIconBlink;
8637 //優先度:エラー→オフライン→アイドル
8641 NotifyIcon1.Icon = NIconAtRed;
8644 if (_myStatusOnline)
8646 NotifyIcon1.Icon = NIconAt;
8650 NotifyIcon1.Icon = NIconAtSmoke;
8654 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8657 this.RefreshTasktrayIcon(false);
8660 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8662 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8663 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8665 if (ListTab != null && ListTab.SelectedTab != null)
8666 _rclickTabName = ListTab.SelectedTab.Text;
8671 if (_statuses == null) return;
8672 if (_statuses.Tabs == null) return;
8674 TabClass tb = _statuses.Tabs[_rclickTabName];
8675 if (tb == null) return;
8677 NotifyDispMenuItem.Checked = tb.Notify;
8678 this.NotifyTbMenuItem.Checked = tb.Notify;
8680 soundfileListup = true;
8681 SoundFileComboBox.Items.Clear();
8682 this.SoundFileTbComboBox.Items.Clear();
8683 SoundFileComboBox.Items.Add("");
8684 this.SoundFileTbComboBox.Items.Add("");
8685 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8686 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8688 oDir = oDir.GetDirectories("Sounds")[0];
8690 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8692 SoundFileComboBox.Items.Add(oFile.Name);
8693 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8695 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8696 if (idx == -1) idx = 0;
8697 SoundFileComboBox.SelectedIndex = idx;
8698 this.SoundFileTbComboBox.SelectedIndex = idx;
8699 soundfileListup = false;
8700 UreadManageMenuItem.Checked = tb.UnreadManage;
8701 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8703 TabMenuControl(_rclickTabName);
8706 private void TabMenuControl(string tabName)
8708 this.FilterEditMenuItem.Enabled = true;
8709 this.EditRuleTbMenuItem.Enabled = true;
8711 if (_statuses.IsDefaultTab(tabName))
8713 this.ProtectTabMenuItem.Enabled = false;
8714 this.ProtectTbMenuItem.Enabled = false;
8718 this.ProtectTabMenuItem.Enabled = true;
8719 this.ProtectTbMenuItem.Enabled = true;
8722 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8724 this.ProtectTabMenuItem.Checked = true;
8725 this.ProtectTbMenuItem.Checked = true;
8726 this.DeleteTabMenuItem.Enabled = false;
8727 this.DeleteTbMenuItem.Enabled = false;
8731 this.ProtectTabMenuItem.Checked = false;
8732 this.ProtectTbMenuItem.Checked = false;
8733 this.DeleteTabMenuItem.Enabled = true;
8734 this.DeleteTbMenuItem.Enabled = true;
8738 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8740 var checkState = ((ToolStripMenuItem)sender).Checked;
8743 this.ProtectTbMenuItem.Checked = checkState;
8744 this.ProtectTabMenuItem.Checked = checkState;
8747 this.DeleteTabMenuItem.Enabled = !checkState;
8748 this.DeleteTbMenuItem.Enabled = !checkState;
8750 if (string.IsNullOrEmpty(_rclickTabName)) return;
8751 _statuses.Tabs[_rclickTabName].Protected = checkState;
8756 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8758 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8759 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8761 if (string.IsNullOrEmpty(_rclickTabName)) return;
8762 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8767 public void ChangeTabUnreadManage(string tabName, bool isManage)
8770 for (idx = 0; idx < ListTab.TabCount; idx++)
8772 if (ListTab.TabPages[idx].Text == tabName) break;
8775 _statuses.SetTabUnreadManage(tabName, isManage);
8776 if (SettingDialog.TabIconDisp)
8778 if (_statuses.Tabs[tabName].UnreadCount > 0)
8779 ListTab.TabPages[idx].ImageIndex = 0;
8781 ListTab.TabPages[idx].ImageIndex = -1;
8784 if (_curTab.Text == tabName)
8786 this.PurgeListViewItemCache();
8790 SetMainWindowTitle();
8791 SetStatusLabelUrl();
8792 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8795 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8797 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8798 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8800 if (string.IsNullOrEmpty(_rclickTabName)) return;
8802 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8807 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8809 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8811 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8816 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8818 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8820 RemoveSpecifiedTab(_rclickTabName, true);
8824 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8826 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8827 fltDialog.SetCurrent(_rclickTabName);
8828 fltDialog.ShowDialog(this);
8829 this.TopMost = SettingDialog.AlwaysTop;
8831 this.ApplyPostFilters();
8835 private void AddTabMenuItem_Click(object sender, EventArgs e)
8837 string tabName = null;
8838 MyCommon.TabUsageType tabUsage;
8839 using (InputTabName inputName = new InputTabName())
8841 inputName.TabName = _statuses.GetUniqueTabName();
8842 inputName.IsShowUsage = true;
8843 inputName.ShowDialog();
8844 if (inputName.DialogResult == DialogResult.Cancel) return;
8845 tabName = inputName.TabName;
8846 tabUsage = inputName.Usage;
8848 this.TopMost = SettingDialog.AlwaysTop;
8849 if (!string.IsNullOrEmpty(tabName))
8852 ListElement list = null;
8853 if (tabUsage == MyCommon.TabUsageType.Lists)
8855 using (ListAvailable listAvail = new ListAvailable())
8857 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8858 if (listAvail.SelectedList == null) return;
8859 list = listAvail.SelectedList;
8862 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8864 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8865 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8871 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8873 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8874 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8875 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8877 if (tabUsage == MyCommon.TabUsageType.Lists)
8879 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8880 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8881 GetTimeline(MyCommon.WORKERTYPE.List, 1, tabName);
8887 private void TabMenuItem_Click(object sender, EventArgs e)
8890 foreach (int idx in _curList.SelectedIndices)
8894 if (!SelectTab(out tabName)) return;
8896 fltDialog.SetCurrent(tabName);
8897 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8899 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8903 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8905 fltDialog.ShowDialog(this);
8906 this.TopMost = SettingDialog.AlwaysTop;
8909 this.ApplyPostFilters();
8911 if (this.ListTab.SelectedTab != null &&
8912 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8914 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8918 protected override bool ProcessDialogKey(Keys keyData)
8920 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8921 if ((keyData & Keys.KeyCode) == Keys.Enter)
8923 if (StatusText.Focused)
8925 bool _NewLine = false;
8928 if (SettingDialog.PostCtrlEnter) //Ctrl+Enter投稿時
8930 if (StatusText.Multiline)
8932 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8934 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8938 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8942 else if (SettingDialog.PostShiftEnter) //SHift+Enter投稿時
8944 if (StatusText.Multiline)
8946 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8948 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8952 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8958 if (StatusText.Multiline)
8960 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8962 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8963 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8967 if (((keyData & Keys.Shift) == Keys.Shift) ||
8968 (((keyData & Keys.Control) != Keys.Control) &&
8969 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8975 int pos1 = StatusText.SelectionStart;
8976 if (StatusText.SelectionLength > 0)
8978 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8980 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8981 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8986 PostButton_Click(null, null);
8990 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8991 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8992 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8994 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
8999 return base.ProcessDialogKey(keyData);
9002 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
9004 MakeReplyOrDirectStatus(false, true, true);
9007 private void IDRuleMenuItem_Click(object sender, EventArgs e)
9012 if (_curList.SelectedIndices.Count == 0) return;
9015 if (!SelectTab(out tabName)) return;
9019 MoveOrCopy(ref mv, ref mk);
9021 List<string> ids = new List<string>();
9022 foreach (int idx in _curList.SelectedIndices)
9024 PostClass post = _statuses[_curTab.Text, idx];
9025 if (!ids.Contains(post.ScreenName))
9027 PostFilterRule fc = new PostFilterRule();
9028 ids.Add(post.ScreenName);
9029 if (post.RetweetedId == null)
9031 fc.FilterName = post.ScreenName;
9035 fc.FilterName = post.RetweetedBy;
9037 fc.UseNameField = true;
9038 fc.MoveMatches = mv;
9039 fc.MarkMatches = mk;
9040 fc.UseRegex = false;
9041 fc.FilterByUrl = false;
9042 _statuses.Tabs[tabName].AddFilter(fc);
9047 List<string> atids = new List<string>();
9048 foreach (string id in ids)
9050 atids.Add("@" + id);
9052 int cnt = AtIdSupl.ItemCount;
9053 AtIdSupl.AddRangeItem(atids.ToArray());
9054 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
9057 this.ApplyPostFilters();
9061 private bool SelectTab(out string tabName)
9068 using (var dialog = new TabsDialog(_statuses))
9070 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
9072 var selectedTab = dialog.SelectedTab;
9073 tabName = selectedTab == null ? null : selectedTab.TabName;
9076 ListTab.SelectedTab.Focus();
9078 if (tabName == null)
9080 using (InputTabName inputName = new InputTabName())
9082 inputName.TabName = _statuses.GetUniqueTabName();
9083 inputName.ShowDialog();
9084 if (inputName.DialogResult == DialogResult.Cancel) return false;
9085 tabName = inputName.TabName;
9087 this.TopMost = SettingDialog.AlwaysTop;
9088 if (!string.IsNullOrEmpty(tabName))
9090 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
9092 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
9093 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
9111 private void MoveOrCopy(ref bool move, ref bool mark)
9115 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
9116 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9124 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
9125 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9131 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
9136 private void CopyURLMenuItem_Click(object sender, EventArgs e)
9141 private void SelectAllMenuItem_Click(object sender, EventArgs e)
9143 if (StatusText.Focused)
9146 StatusText.SelectAll();
9150 // ListView上でのCtrl+A
9151 for (int i = 0; i < _curList.VirtualListSize; i++)
9153 _curList.SelectedIndices.Add(i);
9158 private void MoveMiddle()
9164 if (_curList.SelectedIndices.Count == 0) return;
9166 int idx = _curList.SelectedIndices[0];
9168 _item = _curList.GetItemAt(0, 25);
9174 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9176 idx2 = _curList.VirtualListSize - 1;
9180 idx -= Math.Abs(idx1 - idx2) / 2;
9181 if (idx < 0) idx = 0;
9183 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9184 _curList.EnsureVisible(idx);
9187 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9189 if (PostBrowser.Document.Links.Count > 0)
9191 UrlDialog.ClearUrl();
9193 string openUrlStr = "";
9195 if (PostBrowser.Document.Links.Count == 1)
9200 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9202 catch (ArgumentException)
9211 if (string.IsNullOrEmpty(urlStr)) return;
9212 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9216 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9219 string linkText = "";
9223 urlStr = linkElm.GetAttribute("title");
9224 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9225 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9226 linkText = linkElm.InnerText;
9227 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9229 linkText = "@" + linkText;
9232 catch (ArgumentException)
9241 if (string.IsNullOrEmpty(urlStr)) continue;
9242 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9246 if (UrlDialog.ShowDialog() == DialogResult.OK)
9248 openUrlStr = UrlDialog.SelectedUrl;
9255 this.TopMost = SettingDialog.AlwaysTop;
9257 if (string.IsNullOrEmpty(openUrlStr)) return;
9259 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9260 openUrlStr.StartsWith("https://twitter.com/search?q="))
9263 string urlStr = Uri.UnescapeDataString(openUrlStr);
9264 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9265 HashSupl.AddItem(hash);
9266 HashMgr.AddHashToHistory(hash.Trim(), false);
9267 AddNewTabForSearch(hash);
9272 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9273 if (SettingDialog.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9274 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9276 OpenUriAsync(openUrlStr);
9282 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9284 if (string.IsNullOrEmpty(_rclickTabName)) return;
9285 ClearTab(_rclickTabName, true);
9288 private void ClearTab(string tabName, bool showWarning)
9292 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9293 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9299 _statuses.ClearTabIds(tabName);
9300 if (ListTab.SelectedTab.Text == tabName)
9303 _anchorFlag = false;
9304 this.PurgeListViewItemCache();
9308 foreach (TabPage tb in ListTab.TabPages)
9310 if (tb.Text == tabName)
9313 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9317 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9319 SetMainWindowTitle();
9320 SetStatusLabelUrl();
9323 private static long followers = 0;
9325 private void SetMainWindowTitle()
9328 StringBuilder ttl = new StringBuilder(256);
9331 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
9332 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9333 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9334 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9336 foreach (var tab in _statuses.Tabs.Values)
9338 ur += tab.UnreadCount;
9343 if (SettingDialog.DispUsername) ttl.Append(tw.Username).Append(" - ");
9344 ttl.Append(Application.ProductName);
9346 switch (SettingDialog.DispLatestPost)
9348 case MyCommon.DispTitleEnum.Ver:
9349 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9351 case MyCommon.DispTitleEnum.Post:
9352 if (_history != null && _history.Count > 1)
9353 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9355 case MyCommon.DispTitleEnum.UnreadRepCount:
9356 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9358 case MyCommon.DispTitleEnum.UnreadAllCount:
9359 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9361 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9362 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9364 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9365 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9367 case MyCommon.DispTitleEnum.OwnStatus:
9368 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9369 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9375 this.Text = ttl.ToString();
9377 catch (AccessViolationException)
9379 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9383 private string GetStatusLabelText()
9386 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9387 if (_statuses == null) return "";
9388 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9389 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9390 if (tbRep == null || tbDm == null) return "";
9391 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9396 StringBuilder slbl = new StringBuilder(256);
9399 foreach (var tab in _statuses.Tabs.Values)
9401 ur += tab.UnreadCount;
9403 if (_curTab != null && tab.TabName.Equals(_curTab.Text))
9405 tur = tab.UnreadCount;
9416 UnreadAtCounter = urat;
9418 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9419 if (SettingDialog.TimelinePeriodInt == 0)
9421 slbl.Append(Properties.Resources.SetStatusLabelText2);
9425 slbl.Append(SettingDialog.TimelinePeriodInt.ToString() + Properties.Resources.SetStatusLabelText3);
9427 return slbl.ToString();
9430 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9434 if (this.InvokeRequired && !this.IsDisposed)
9436 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9440 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9441 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9443 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9447 catch (ObjectDisposedException)
9451 catch (InvalidOperationException)
9457 private void SetStatusLabelUrl()
9459 StatusLabelUrl.Text = GetStatusLabelText();
9462 public void SetStatusLabel(string text)
9464 StatusLabel.Text = text;
9467 private static StringBuilder ur = new StringBuilder(64);
9469 private void SetNotifyIconText()
9471 // タスクトレイアイコンのツールチップテキスト書き換え
9473 ur.Remove(0, ur.Length);
9474 if (SettingDialog.DispUsername)
9476 ur.Append(tw.Username);
9479 ur.Append(Application.ProductName);
9481 ur.Append("(Debug Build)");
9483 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9486 ur.Append(UnreadCounter);
9488 ur.Append(UnreadAtCounter);
9491 NotifyIcon1.Text = ur.ToString();
9494 internal void CheckReplyTo(string StatusText)
9498 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9500 foreach (Match hm in m)
9502 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9504 hstr += "#" + hm.Result("$3") + " ";
9505 HashSupl.AddItem("#" + hm.Result("$3"));
9508 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9510 hstr += HashMgr.UseHash;
9512 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9514 // 本当にリプライ先指定すべきかどうかの判定
9515 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9517 if (SettingDialog.UseAtIdSupplement)
9519 int bCnt = AtIdSupl.ItemCount;
9520 foreach (Match mid in m)
9522 AtIdSupl.AddItem(mid.Result("${id}"));
9524 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9527 // リプライ先ステータスIDの指定がない場合は指定しない
9528 if (_reply_to_id == null) return;
9530 // リプライ先ユーザー名がない場合も指定しない
9531 if (string.IsNullOrEmpty(_reply_to_name))
9533 _reply_to_id = null;
9538 // 次の条件を満たす場合に in_reply_to_status_id 指定
9539 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9540 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9541 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9545 if (StatusText.StartsWith("@"))
9547 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9551 foreach (Match mid in m)
9553 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9558 _reply_to_id = null;
9559 _reply_to_name = null;
9563 private void TweenMain_Resize(object sender, EventArgs e)
9565 if (!_initialLayout && SettingDialog.MinimizeToTray && WindowState == FormWindowState.Minimized)
9567 this.Visible = false;
9569 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9571 this.ClientSize = _cfgLocal.FormSize;
9572 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9573 this.DesktopLocation = _cfgLocal.FormLocation;
9574 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9575 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9576 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9578 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9581 StatusText.Multiline = _cfgLocal.StatusMultiline;
9582 if (StatusText.Multiline)
9584 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9585 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9587 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9589 StatusText.Height = _cfgLocal.StatusTextHeight;
9593 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9595 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9598 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9600 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9602 _initialLayout = false;
9604 if (this.WindowState != FormWindowState.Minimized)
9606 _formWindowState = this.WindowState;
9610 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9612 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9613 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9614 if (PlaySoundMenuItem.Checked)
9616 SettingDialog.PlaySound = true;
9620 SettingDialog.PlaySound = false;
9622 _modifySettingCommon = true;
9625 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9627 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9629 _mySpDis = SplitContainer1.SplitterDistance;
9630 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9631 _modifySettingLocal = true;
9635 private void doRepliedStatusOpen()
9637 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9639 if (MyCommon.IsKeyDown(Keys.Shift))
9641 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9644 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9646 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9647 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9651 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9653 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9654 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9655 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9658 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9663 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9665 doRepliedStatusOpen();
9669 /// UserPicture.Image に設定されている画像を破棄します。
9671 private void ClearUserPicture()
9673 if (this.UserPicture.Image != null)
9675 var oldImage = this.UserPicture.Image;
9676 this.UserPicture.Image = null;
9681 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9683 //発言詳細のアイコン右クリック時のメニュー制御
9684 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9686 string name = _curPost.ImageUrl;
9687 if (name != null && name.Length > 0)
9689 int idx = name.LastIndexOf('/');
9692 name = Path.GetFileName(name.Substring(idx));
9693 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9695 name = name.Replace("_normal", "");
9696 this.IconNameToolStripMenuItem.Text = name;
9697 this.IconNameToolStripMenuItem.Enabled = true;
9701 this.IconNameToolStripMenuItem.Enabled = false;
9702 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9707 this.IconNameToolStripMenuItem.Enabled = false;
9708 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9711 this.ReloadIconToolStripMenuItem.Enabled = true;
9713 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9715 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9719 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9724 this.IconNameToolStripMenuItem.Enabled = false;
9725 this.ReloadIconToolStripMenuItem.Enabled = false;
9726 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9727 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9732 this.IconNameToolStripMenuItem.Enabled = false;
9733 this.ReloadIconToolStripMenuItem.Enabled = false;
9734 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9735 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9737 if (NameLabel.Tag != null)
9739 string id = (string)NameLabel.Tag;
9740 if (id == tw.Username)
9742 FollowToolStripMenuItem.Enabled = false;
9743 UnFollowToolStripMenuItem.Enabled = false;
9744 ShowFriendShipToolStripMenuItem.Enabled = false;
9745 ShowUserStatusToolStripMenuItem.Enabled = true;
9746 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9747 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9748 ListManageUserContextToolStripMenuItem3.Enabled = true;
9752 FollowToolStripMenuItem.Enabled = true;
9753 UnFollowToolStripMenuItem.Enabled = true;
9754 ShowFriendShipToolStripMenuItem.Enabled = true;
9755 ShowUserStatusToolStripMenuItem.Enabled = true;
9756 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9757 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9758 ListManageUserContextToolStripMenuItem3.Enabled = true;
9763 FollowToolStripMenuItem.Enabled = false;
9764 UnFollowToolStripMenuItem.Enabled = false;
9765 ShowFriendShipToolStripMenuItem.Enabled = false;
9766 ShowUserStatusToolStripMenuItem.Enabled = false;
9767 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9768 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9769 ListManageUserContextToolStripMenuItem3.Enabled = false;
9773 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9775 if (_curPost == null) return;
9776 string name = _curPost.ImageUrl;
9777 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9780 private async void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9782 if (this._curPost == null) return;
9784 await this.UserPicture.SetImageFromTask(async () =>
9786 var imageUrl = this._curPost.ImageUrl;
9788 var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
9789 .ConfigureAwait(false);
9791 return await image.CloneAsync()
9792 .ConfigureAwait(false);
9796 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9798 if (_curPost == null) return;
9799 string name = _curPost.ImageUrl;
9800 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9802 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9804 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9810 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9812 if (_curPost == null) return;
9813 string name = _curPost.ImageUrl;
9815 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9817 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9821 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9823 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9825 using (Graphics g = Graphics.FromImage(bmp2))
9827 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9828 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9830 bmp2.Save(this.SaveFileDialog1.FileName);
9836 //処理中にキャッシュアウトする可能性あり
9841 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9843 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9844 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9845 _modifySettingLocal = true;
9848 private void StatusText_MultilineChanged(object sender, EventArgs e)
9850 if (this.StatusText.Multiline)
9851 this.StatusText.ScrollBars = ScrollBars.Vertical;
9853 this.StatusText.ScrollBars = ScrollBars.None;
9855 _modifySettingLocal = true;
9858 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9861 StatusText.Multiline = MultiLineMenuItem.Checked;
9862 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9863 if (MultiLineMenuItem.Checked)
9865 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9866 SplitContainer2.SplitterDistance = 0;
9868 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9872 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9874 _modifySettingLocal = true;
9877 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
9879 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9880 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9882 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9883 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9884 //Appendix A. Collected ABNF for URI
9885 //http://www.ietf.org/rfc/rfc3986.txt
9889 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9891 if (StatusText.SelectionLength > 0)
9893 string tmp = StatusText.SelectedText;
9894 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9895 if (tmp.StartsWith("http"))
9897 // 文字列が選択されている場合はその文字列について処理
9899 //nico.ms使用、nicovideoにマッチしたら変換
9900 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9902 result = nicoms.Shorten(tmp);
9904 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9906 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9909 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9910 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9911 result = resultUri.ToString();
9913 catch (WebApiException e)
9915 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9918 catch (UriFormatException e)
9920 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9929 if (!string.IsNullOrEmpty(result))
9931 urlUndo undotmp = new urlUndo();
9933 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9934 StatusText.SelectedText = result;
9937 undotmp.Before = tmp;
9938 undotmp.After = result;
9940 if (urlUndoBuffer == null)
9942 urlUndoBuffer = new List<urlUndo>();
9943 UrlUndoToolStripMenuItem.Enabled = true;
9946 urlUndoBuffer.Add(undotmp);
9952 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9953 @"(?<url>(?<protocol>https?://)" +
9954 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9955 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9956 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9957 // 正規表現にマッチしたURL文字列をtinyurl化
9958 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9960 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9961 string tmp = mt.Result("${url}");
9962 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9963 urlUndo undotmp = new urlUndo();
9966 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9968 //nico.ms使用、nicovideoにマッチしたら変換
9969 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9971 result = nicoms.Shorten(tmp);
9973 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9975 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9978 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9979 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9980 result = resultUri.ToString();
9982 catch (HttpRequestException e)
9984 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
9985 // のように長いので「:」が含まれていればそれ以降のみを抽出する
9986 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
9988 this.StatusLabel.Text = Converter_Type + ":" + message;
9991 catch (WebApiException e)
9993 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9996 catch (UriFormatException e)
9998 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
10007 if (!string.IsNullOrEmpty(result))
10009 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
10010 StatusText.SelectedText = result;
10012 undotmp.Before = mt.Result("${url}");
10013 undotmp.After = result;
10015 if (urlUndoBuffer == null)
10017 urlUndoBuffer = new List<urlUndo>();
10018 UrlUndoToolStripMenuItem.Enabled = true;
10021 urlUndoBuffer.Add(undotmp);
10029 private void doUrlUndo()
10031 if (urlUndoBuffer != null)
10033 string tmp = StatusText.Text;
10034 foreach (urlUndo data in urlUndoBuffer)
10036 tmp = tmp.Replace(data.After, data.Before);
10038 StatusText.Text = tmp;
10039 urlUndoBuffer = null;
10040 UrlUndoToolStripMenuItem.Enabled = false;
10041 StatusText.SelectionStart = 0;
10042 StatusText.SelectionLength = 0;
10046 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
10048 await UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
10051 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
10053 await UrlConvertAsync(MyCommon.UrlConverter.Isgd);
10056 private async void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
10058 await UrlConvertAsync(MyCommon.UrlConverter.Twurl);
10061 private async void UxnuMenuItem_Click(object sender, EventArgs e)
10063 await UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
10066 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
10068 if (!await UrlConvertAsync(SettingDialog.AutoShortUrlFirst))
10070 MyCommon.UrlConverter svc = SettingDialog.AutoShortUrlFirst;
10071 Random rnd = new Random();
10072 // 前回使用した短縮URLサービス以外を選択する
10075 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
10077 while (svc == SettingDialog.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
10078 await UrlConvertAsync(svc);
10082 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
10087 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
10089 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10090 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
10091 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
10092 _modifySettingCommon = true;
10095 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
10097 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10098 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
10099 _cfgCommon.ListLock = ListLockMenuItem.Checked;
10100 _modifySettingCommon = true;
10103 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
10105 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
10106 MenuStrip1.Tag = new Object();
10107 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
10110 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
10112 if (this.Tag != null) // 設定された戻り先へ遷移
10114 if (this.Tag == this.ListTab.SelectedTab)
10115 ((Control)this.ListTab.SelectedTab.Tag).Select();
10117 ((Control)this.Tag).Select();
10119 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
10121 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
10123 this.Tag = ListTab.SelectedTab.Tag;
10124 ((Control)this.Tag).Select();
10127 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
10128 MenuStrip1.Tag = null;
10131 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
10133 DetailsListView lst = (DetailsListView)sender;
10134 if (_cfgLocal == null) return;
10138 _cfgLocal.Width1 = lst.Columns[0].Width;
10139 _cfgLocal.Width3 = lst.Columns[1].Width;
10143 int[] darr = new int[lst.Columns.Count];
10144 for (int i = 0; i < lst.Columns.Count; i++)
10146 darr[lst.Columns[i].DisplayIndex] = i;
10148 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
10150 for (int i = 0; i < lst.Columns.Count; i++)
10155 _cfgLocal.DisplayIndex1 = i;
10158 _cfgLocal.DisplayIndex2 = i;
10161 _cfgLocal.DisplayIndex3 = i;
10164 _cfgLocal.DisplayIndex4 = i;
10167 _cfgLocal.DisplayIndex5 = i;
10170 _cfgLocal.DisplayIndex6 = i;
10173 _cfgLocal.DisplayIndex7 = i;
10176 _cfgLocal.DisplayIndex8 = i;
10180 _cfgLocal.Width1 = lst.Columns[0].Width;
10181 _cfgLocal.Width2 = lst.Columns[1].Width;
10182 _cfgLocal.Width3 = lst.Columns[2].Width;
10183 _cfgLocal.Width4 = lst.Columns[3].Width;
10184 _cfgLocal.Width5 = lst.Columns[4].Width;
10185 _cfgLocal.Width6 = lst.Columns[5].Width;
10186 _cfgLocal.Width7 = lst.Columns[6].Width;
10187 _cfgLocal.Width8 = lst.Columns[7].Width;
10189 _modifySettingLocal = true;
10190 _isColumnChanged = true;
10193 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10195 DetailsListView lst = (DetailsListView)sender;
10196 if (_cfgLocal == null) return;
10199 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10201 _cfgLocal.Width1 = lst.Columns[0].Width;
10202 _modifySettingLocal = true;
10203 _isColumnChanged = true;
10205 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10207 _cfgLocal.Width3 = lst.Columns[1].Width;
10208 _modifySettingLocal = true;
10209 _isColumnChanged = true;
10214 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10216 _cfgLocal.Width1 = lst.Columns[0].Width;
10217 _modifySettingLocal = true;
10218 _isColumnChanged = true;
10220 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10222 _cfgLocal.Width2 = lst.Columns[1].Width;
10223 _modifySettingLocal = true;
10224 _isColumnChanged = true;
10226 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10228 _cfgLocal.Width3 = lst.Columns[2].Width;
10229 _modifySettingLocal = true;
10230 _isColumnChanged = true;
10232 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10234 _cfgLocal.Width4 = lst.Columns[3].Width;
10235 _modifySettingLocal = true;
10236 _isColumnChanged = true;
10238 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10240 _cfgLocal.Width5 = lst.Columns[4].Width;
10241 _modifySettingLocal = true;
10242 _isColumnChanged = true;
10244 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10246 _cfgLocal.Width6 = lst.Columns[5].Width;
10247 _modifySettingLocal = true;
10248 _isColumnChanged = true;
10250 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10252 _cfgLocal.Width7 = lst.Columns[6].Width;
10253 _modifySettingLocal = true;
10254 _isColumnChanged = true;
10256 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10258 _cfgLocal.Width8 = lst.Columns[7].Width;
10259 _modifySettingLocal = true;
10260 _isColumnChanged = true;
10263 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10266 // SaveConfigsLocal();
10270 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10272 //発言詳細で「選択文字列をコピー」を行う
10273 //WebBrowserコンポーネントのインスタンスを渡す
10274 Type typ = ComponentInstance.ActiveXInstance.GetType();
10275 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10276 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10277 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10280 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10283 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10286 Clipboard.SetDataObject(_selText, false, 5, 100);
10288 catch (Exception ex)
10290 MessageBox.Show(ex.Message);
10294 private void doSearchToolStrip(string url)
10296 //発言詳細で「選択文字列で検索」(選択文字列取得)
10297 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10299 if (_selText != null)
10301 if (url == Properties.Resources.SearchItem4Url)
10304 AddNewTabForSearch(_selText);
10308 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10313 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10316 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10319 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10321 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10324 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10326 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10329 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10331 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10334 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10338 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10339 foreach (Match m in mc)
10341 if (m.Groups["url"].Value == this._postBrowserStatusText)
10343 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10349 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10351 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10353 catch (Exception ex)
10355 MessageBox.Show(ex.Message);
10359 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10361 // URLコピーの項目の表示/非表示
10362 if (PostBrowser.StatusText.StartsWith("http"))
10364 this._postBrowserStatusText = PostBrowser.StatusText;
10365 string name = GetUserId();
10366 UrlCopyContextMenuItem.Enabled = true;
10369 FollowContextMenuItem.Enabled = true;
10370 RemoveContextMenuItem.Enabled = true;
10371 FriendshipContextMenuItem.Enabled = true;
10372 ShowUserStatusContextMenuItem.Enabled = true;
10373 SearchPostsDetailToolStripMenuItem.Enabled = true;
10374 IdFilterAddMenuItem.Enabled = true;
10375 ListManageUserContextToolStripMenuItem.Enabled = true;
10376 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10380 FollowContextMenuItem.Enabled = false;
10381 RemoveContextMenuItem.Enabled = false;
10382 FriendshipContextMenuItem.Enabled = false;
10383 ShowUserStatusContextMenuItem.Enabled = false;
10384 SearchPostsDetailToolStripMenuItem.Enabled = false;
10385 IdFilterAddMenuItem.Enabled = false;
10386 ListManageUserContextToolStripMenuItem.Enabled = false;
10387 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10390 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10391 UseHashtagMenuItem.Enabled = true;
10393 UseHashtagMenuItem.Enabled = false;
10397 this._postBrowserStatusText = "";
10398 UrlCopyContextMenuItem.Enabled = false;
10399 FollowContextMenuItem.Enabled = false;
10400 RemoveContextMenuItem.Enabled = false;
10401 FriendshipContextMenuItem.Enabled = false;
10402 ShowUserStatusContextMenuItem.Enabled = false;
10403 SearchPostsDetailToolStripMenuItem.Enabled = false;
10404 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10405 UseHashtagMenuItem.Enabled = false;
10406 IdFilterAddMenuItem.Enabled = false;
10407 ListManageUserContextToolStripMenuItem.Enabled = false;
10409 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10410 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10411 if (_selText == null)
10413 SelectionSearchContextMenuItem.Enabled = false;
10414 SelectionCopyContextMenuItem.Enabled = false;
10415 SelectionTranslationToolStripMenuItem.Enabled = false;
10419 SelectionSearchContextMenuItem.Enabled = true;
10420 SelectionCopyContextMenuItem.Enabled = true;
10421 SelectionTranslationToolStripMenuItem.Enabled = true;
10423 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10424 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10425 bool fAllFlag = false;
10426 foreach (Match mu in ma)
10428 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10434 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10436 if (_curPost == null)
10437 TranslationToolStripMenuItem.Enabled = false;
10439 TranslationToolStripMenuItem.Enabled = true;
10444 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10446 //発言詳細の選択文字列で現在のタブを検索
10447 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10449 if (_selText != null)
10451 var searchOptions = new SearchWordDialog.SearchOptions(
10452 SearchWordDialog.SearchType.Timeline,
10455 caseSensitive: false,
10458 this.SearchDialog.ResultOptions = searchOptions;
10461 searchOptions.Query,
10462 searchOptions.CaseSensitive,
10463 searchOptions.UseRegex,
10464 SEARCHTYPE.NextSearch);
10468 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10470 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10471 _modifySettingLocal = true;
10474 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10476 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10478 SelectMedia_DragDrop(e);
10480 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10482 var url = GetUrlFromDataObject(e.Data);
10485 if (url.Item2 == null)
10486 appendText = url.Item1;
10488 appendText = url.Item2 + " " + url.Item1;
10490 if (this.StatusText.TextLength == 0)
10491 this.StatusText.Text = appendText;
10493 this.StatusText.Text += " " + appendText;
10495 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10497 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10498 if (data != null) StatusText.Text += data;
10503 /// IDataObject から URL とタイトルの対を取得します
10506 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10508 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10509 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10510 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10512 if (data.GetDataPresent("text/x-moz-url"))
10514 // Firefox, Google Chrome で利用可能
10515 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10517 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10519 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10520 if (lines.Length < 2)
10521 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10523 return new Tuple<string, string>(lines[0], lines[1]);
10526 else if (data.GetDataPresent("IESiteModeToUrl"))
10528 // Internet Exproler 用
10529 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10531 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10533 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10534 if (lines.Length < 2)
10535 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10537 return new Tuple<string, string>(lines[0], lines[1]);
10540 else if (data.GetDataPresent("UniformResourceLocatorW"))
10544 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10546 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10547 return new Tuple<string, string>(url, null);
10551 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10554 private void TweenMain_DragEnter(object sender, DragEventArgs e)
10556 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10558 SelectMedia_DragEnter(e);
10562 private void TweenMain_DragOver(object sender, DragEventArgs e)
10564 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10566 SelectMedia_DragOver(e);
10568 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10570 e.Effect = DragDropEffects.Copy;
10572 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10574 e.Effect = DragDropEffects.Copy;
10578 e.Effect = DragDropEffects.None;
10582 public bool IsNetworkAvailable()
10585 nw = MyCommon.IsNetworkAvailable();
10586 _myStatusOnline = nw;
10590 public Task OpenUriAsync(string UriString)
10592 return Task.Run(() =>
10594 string myPath = UriString;
10598 var configBrowserPath = SettingDialog.BrowserPath;
10599 if (!string.IsNullOrEmpty(configBrowserPath))
10601 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10603 int sep = configBrowserPath.IndexOf("\"", 2);
10604 string browserPath = configBrowserPath.Substring(1, sep - 1);
10606 if (sep < configBrowserPath.Length - 1)
10608 arg = configBrowserPath.Substring(sep + 1);
10610 myPath = arg + " " + myPath;
10611 System.Diagnostics.Process.Start(browserPath, myPath);
10615 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10620 System.Diagnostics.Process.Start(myPath);
10625 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10630 private void ListTabSelect(TabPage _tab)
10634 this.PurgeListViewItemCache();
10637 _curList = (DetailsListView)_tab.Tag;
10638 if (_curList.SelectedIndices.Count > 0)
10640 _curItemIndex = _curList.SelectedIndices[0];
10641 _curPost = GetCurTabPost(_curItemIndex);
10645 _curItemIndex = -1;
10649 _anchorPost = null;
10650 _anchorFlag = false;
10654 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10658 for (int i = 0; i < _curList.Columns.Count; i++)
10660 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10665 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10667 ListTabSelect(e.TabPage);
10670 private void SelectListItem(DetailsListView LView, int Index)
10673 Rectangle bnd = new Rectangle();
10675 var item = LView.FocusedItem;
10684 LView.SelectedIndices.Clear();
10686 while (LView.SelectedIndices.Count > 0);
10687 item = LView.Items[Index];
10688 item.Selected = true;
10689 item.Focused = true;
10691 if (flg) LView.Invalidate(bnd);
10694 private void SelectListItem(DetailsListView LView , int[] Index, int[] FocusedIndex)
10697 Rectangle bnd = new Rectangle();
10699 var item = LView.FocusedItem;
10707 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10711 LView.SelectedIndices.Clear();
10713 while (LView.SelectedIndices.Count > 0);
10714 foreach (int idx in Index)
10716 if (idx > -1 && LView.VirtualListSize > idx)
10718 LView.SelectedIndices.Add(idx);
10719 if (fIdx == -1) fIdx = idx;
10723 if (FocusedIndex[1] > -1 && LView.VirtualListSize > FocusedIndex[1])
10725 LView.SelectionMark = FocusedIndex[1];
10727 if (FocusedIndex[0] > -1 && LView.VirtualListSize > FocusedIndex[0])
10729 LView.Items[FocusedIndex[0]].Focused = true;
10731 else if (fIdx > -1)
10733 LView.Items[fIdx].Focused = true;
10736 if (flg) LView.Invalidate(bnd);
10739 private void RunAsync(GetWorkerArg args)
10741 BackgroundWorker bw = null;
10742 if (args.type != MyCommon.WORKERTYPE.Follower)
10744 for (int i = 0; i < _bw.Length; i++)
10746 if (_bw[i] != null && !_bw[i].IsBusy)
10754 for (int i = 0; i < _bw.Length; i++)
10756 if (_bw[i] == null)
10758 _bw[i] = new BackgroundWorker();
10760 bw.WorkerReportsProgress = true;
10761 bw.WorkerSupportsCancellation = true;
10762 bw.DoWork += GetTimelineWorker_DoWork;
10763 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10764 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10772 if (_bwFollower == null)
10774 _bwFollower = new BackgroundWorker();
10776 bw.WorkerReportsProgress = true;
10777 bw.WorkerSupportsCancellation = true;
10778 bw.DoWork += GetTimelineWorker_DoWork;
10779 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10780 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10784 if (_bwFollower.IsBusy == false)
10788 if (bw == null) return;
10790 bw.RunWorkerAsync(args);
10793 private void StartUserStream()
10795 tw.NewPostFromStream += tw_NewPostFromStream;
10796 tw.UserStreamStarted += tw_UserStreamStarted;
10797 tw.UserStreamStopped += tw_UserStreamStopped;
10798 tw.PostDeleted += tw_PostDeleted;
10799 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10801 MenuItemUserStream.Text = "&UserStream ■";
10802 MenuItemUserStream.Enabled = true;
10803 StopToolStripMenuItem.Text = "&Start";
10804 StopToolStripMenuItem.Enabled = true;
10805 if (SettingDialog.UserstreamStartup) tw.StartUserStream();
10808 private async void TweenMain_Shown(object sender, EventArgs e)
10812 PostBrowser.Url = new Uri("about:blank");
10813 PostBrowser.DocumentText = ""; //発言詳細部初期化
10819 NotifyIcon1.Visible = true;
10821 if (this.IsNetworkAvailable())
10823 this.RefreshMuteUserIdsAsync();
10824 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, "");
10825 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10826 if (SettingDialog.StartupFollowers)
10828 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10830 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10832 _waitTimeline = true;
10833 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
10835 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
10837 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
10838 if (SettingDialog.GetFav)
10841 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
10843 _waitPubSearch = true;
10844 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, ""); //tabname="":全タブ
10845 _waitUserTimeline = true;
10846 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, ""); //tabname="":全タブ
10848 GetTimeline(MyCommon.WORKERTYPE.List, 1, ""); //tabname="":全タブ
10851 while (this.IsInitialRead())
10853 await Task.Delay(5000);
10856 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10858 if (MyCommon._endingFlag)
10862 if (MyCommon._endingFlag) return;
10864 if (ApplicationSettings.VersionInfoUrl != null)
10866 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10867 if (SettingDialog.StartupVersion)
10868 await this.CheckNewVersion(true);
10872 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10873 this.VerUpMenuItem.Enabled = false;
10874 this.VerUpMenuItem.Available = false;
10875 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10879 if (!tw.GetFollowersSuccess && SettingDialog.StartupFollowers)
10880 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10883 if (!tw.GetNoRetweetSuccess)
10884 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10887 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10888 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10890 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10891 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10893 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10894 SettingStripMenuItem_Click(null, null);
10901 TimerTimeline.Enabled = true;
10904 private bool IsInitialRead()
10906 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10909 private void doGetFollowersMenu()
10911 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, "");
10912 DispSelectedPost(true);
10915 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10917 doGetFollowersMenu();
10920 private void doReTweetUnofficial()
10923 if (this.ExistCurrentPost)
10925 if (_curPost.IsDm ||
10926 !StatusText.Enabled) return;
10928 if (_curPost.IsProtect)
10930 MessageBox.Show("Protected.");
10933 string rtdata = _curPost.Text;
10934 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10936 this._reply_to_id = null;
10937 this._reply_to_name = null;
10939 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10941 StatusText.SelectionStart = 0;
10942 StatusText.Focus();
10946 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10948 doReTweetUnofficial();
10951 private void doReTweetOfficial(bool isConfirm)
10954 if (this.ExistCurrentPost)
10956 if (_curPost.IsProtect)
10958 MessageBox.Show("Protected.");
10959 _DoFavRetweetFlags = false;
10962 if (_curList.SelectedIndices.Count > 15)
10964 MessageBox.Show(Properties.Resources.RetweetLimitText);
10965 _DoFavRetweetFlags = false;
10968 else if (_curList.SelectedIndices.Count > 1)
10970 string QuestionText = Properties.Resources.RetweetQuestion2;
10971 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10972 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10974 case DialogResult.Cancel:
10975 case DialogResult.No:
10976 _DoFavRetweetFlags = false;
10982 if (_curPost.IsDm || _curPost.IsMe)
10984 _DoFavRetweetFlags = false;
10987 if (!SettingDialog.RetweetNoConfirm)
10989 string Questiontext = Properties.Resources.RetweetQuestion1;
10990 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
10991 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
10993 _DoFavRetweetFlags = false;
10998 GetWorkerArg args = new GetWorkerArg();
10999 args.ids = new List<long>();
11000 args.sIds = new List<long>();
11001 args.tName = _curTab.Text;
11002 args.type = MyCommon.WORKERTYPE.Retweet;
11003 foreach (int idx in _curList.SelectedIndices)
11005 PostClass post = GetCurTabPost(idx);
11006 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
11012 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
11014 doReTweetOfficial(true);
11017 private void FavoritesRetweetOriginal()
11019 if (!this.ExistCurrentPost) return;
11020 _DoFavRetweetFlags = true;
11021 doReTweetOfficial(true);
11022 if (_DoFavRetweetFlags)
11024 _DoFavRetweetFlags = false;
11025 FavoriteChange(true, false);
11029 private void FavoritesRetweetUnofficial()
11031 if (this.ExistCurrentPost && !_curPost.IsDm)
11033 _DoFavRetweetFlags = true;
11034 FavoriteChange(true);
11035 if (!_curPost.IsProtect && _DoFavRetweetFlags)
11037 _DoFavRetweetFlags = false;
11038 doReTweetUnofficial();
11044 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
11046 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
11047 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
11048 /// <returns>復元されたツイート本文</returns>
11049 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
11051 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
11054 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
11056 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11058 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11062 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
11064 statusHtml = statusHtml.Replace("<br>", " ");
11066 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
11067 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
11068 statusHtml = statusHtml.Replace(" ", " ");
11070 return WebUtility.HtmlDecode(statusHtml);
11073 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
11075 if (_curPost != null)
11076 DispSelectedPost(true);
11079 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
11081 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
11082 DebugModeToolStripMenuItem.Visible = true;
11084 DebugModeToolStripMenuItem.Visible = false;
11087 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
11089 SettingDialog.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
11092 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
11094 ToolStripMenuItemUrlAutoShorten.Checked = SettingDialog.UrlConvertAuto;
11097 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
11099 if (TraceOutToolStripMenuItem.Checked)
11100 MyCommon.TraceFlag = true;
11102 MyCommon.TraceFlag = false;
11105 private void TweenMain_Deactivate(object sender, EventArgs e)
11107 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
11108 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
11111 private void TabRenameMenuItem_Click(object sender, EventArgs e)
11113 if (string.IsNullOrEmpty(_rclickTabName)) return;
11114 TabRename(ref _rclickTabName);
11117 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
11119 await UrlConvertAsync(MyCommon.UrlConverter.Bitly);
11122 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
11124 await UrlConvertAsync(MyCommon.UrlConverter.Jmp);
11128 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
11130 e.Result = tw.GetInfoApi();
11133 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
11135 StringBuilder tmp = new StringBuilder();
11137 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
11141 var result = (TwitterApiStatus)dlg.Result;
11143 if (result == null)
11145 var accessLevel = result.AccessLevel;
11146 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
11147 var mediaLimit = result.MediaUploadLimit;
11149 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
11150 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
11151 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
11152 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
11155 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
11156 SetStatusLabelUrl();
11159 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
11160 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
11161 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
11165 tmp.Append(Properties.Resources.ApiInfo5);
11169 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11172 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11175 if (_curPost != null) id = _curPost.ScreenName;
11179 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11181 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11182 e.Result = arg.tw.PostFollowCommand(arg.id);
11185 private void FollowCommand(string id)
11187 using (InputTabName inputName = new InputTabName())
11189 inputName.FormTitle = "Follow";
11190 inputName.FormDescription = Properties.Resources.FRMessage1;
11191 inputName.TabName = id;
11192 if (inputName.ShowDialog() == DialogResult.OK &&
11193 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11195 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11197 arg.id = inputName.TabName.Trim();
11198 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11199 FollowCommand_DoWork,
11203 _info.ShowDialog();
11204 string ret = (string)_info.Result;
11205 if (!string.IsNullOrEmpty(ret))
11206 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11208 MessageBox.Show(Properties.Resources.FRMessage3);
11214 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11217 if (_curPost != null) id = _curPost.ScreenName;
11218 RemoveCommand(id, false);
11221 private class FollowRemoveCommandArgs
11227 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11229 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11230 e.Result = arg.tw.PostRemoveCommand(arg.id);
11233 private void RemoveCommand(string id, bool skipInput)
11235 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11240 using (InputTabName inputName = new InputTabName())
11242 inputName.FormTitle = "Unfollow";
11243 inputName.FormDescription = Properties.Resources.FRMessage1;
11244 inputName.TabName = id;
11245 if (inputName.ShowDialog() == DialogResult.OK &&
11246 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11249 arg.id = inputName.TabName.Trim();
11258 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11259 RemoveCommand_DoWork,
11263 _info.ShowDialog();
11264 string ret = (string)_info.Result;
11265 if (!string.IsNullOrEmpty(ret))
11266 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11268 MessageBox.Show(Properties.Resources.FRMessage3);
11272 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11275 if (_curPost != null)
11276 id = _curPost.ScreenName;
11278 ShowFriendship(id);
11281 private class ShowFriendshipArgs
11284 public class FriendshipInfo
11286 public string id = "";
11287 public bool isFollowing = false;
11288 public bool isFollowed = false;
11289 public FriendshipInfo(string id)
11294 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11297 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11299 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11300 string result = "";
11301 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11303 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11304 if (!string.IsNullOrEmpty(rt))
11306 if (string.IsNullOrEmpty(result)) result = rt;
11312 private void ShowFriendship(string id)
11314 ShowFriendshipArgs args = new ShowFriendshipArgs();
11316 using (InputTabName inputName = new InputTabName())
11318 inputName.FormTitle = "Show Friendships";
11319 inputName.FormDescription = Properties.Resources.FRMessage1;
11320 inputName.TabName = id;
11321 if (inputName.ShowDialog() == DialogResult.OK &&
11322 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11325 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11326 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11327 ShowFriendship_DoWork,
11331 _info.ShowDialog();
11332 ret = (string)_info.Result;
11334 string result = "";
11335 if (string.IsNullOrEmpty(ret))
11337 if (args.ids[0].isFollowing)
11339 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11343 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11345 if (args.ids[0].isFollowed)
11347 result += Properties.Resources.GetFriendshipInfo3;
11351 result += Properties.Resources.GetFriendshipInfo4;
11353 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11359 MessageBox.Show(result);
11364 private void ShowFriendship(string[] ids)
11366 foreach (string id in ids)
11369 ShowFriendshipArgs args = new ShowFriendshipArgs();
11371 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11372 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11373 ShowFriendship_DoWork,
11377 _info.ShowDialog();
11378 ret = (string)_info.Result;
11380 string result = "";
11381 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11383 if (string.IsNullOrEmpty(ret))
11386 if (fInfo.isFollowing)
11388 ff += Properties.Resources.GetFriendshipInfo1;
11392 ff += Properties.Resources.GetFriendshipInfo2;
11395 ff += System.Environment.NewLine + " ";
11396 if (fInfo.isFollowed)
11398 ff += Properties.Resources.GetFriendshipInfo3;
11402 ff += Properties.Resources.GetFriendshipInfo4;
11404 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11405 if (fInfo.isFollowing)
11407 if (MessageBox.Show(
11408 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11409 MessageBoxButtons.YesNo,
11410 MessageBoxIcon.Question,
11411 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11413 RemoveCommand(fInfo.id, true);
11418 MessageBox.Show(result);
11423 MessageBox.Show(ret);
11428 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11430 doShowUserStatus(tw.Username, false);
11431 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11433 // doShowUserStatus(tw.Username, false);
11437 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11442 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11443 // URLから切り出した文字列を渡す
11445 public bool IsTwitterId(string name)
11447 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11448 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11450 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11453 private string GetUserId()
11455 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11456 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11457 return m.Result("${ScreenName}");
11462 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11464 string name = GetUserId();
11465 if (name != null) FollowCommand(name);
11468 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11470 string name = GetUserId();
11471 if (name != null) RemoveCommand(name, false);
11474 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11476 string name = GetUserId();
11477 if (name != null) ShowFriendship(name);
11480 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11482 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11483 List<string> ids = new List<string>();
11484 foreach (Match mu in ma)
11486 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11488 ids.Add(mu.Result("${ScreenName}"));
11491 ShowFriendship(ids.ToArray());
11494 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11496 string name = GetUserId();
11497 if (name != null) ShowUserStatus(name);
11500 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11502 string name = GetUserId();
11503 if (name != null) AddNewTabForUserTimeline(name);
11506 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11508 string name = GetUserId();
11509 if (name != null) AddNewTabForSearch("@" + name);
11512 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11514 _modifySettingCommon = true;
11517 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11519 _modifySettingCommon = true;
11522 private void doQuote()
11526 if (this.ExistCurrentPost)
11528 if (_curPost.IsDm ||
11529 !StatusText.Enabled) return;
11531 if (_curPost.IsProtect)
11533 MessageBox.Show("Protected.");
11536 string rtdata = _curPost.Text;
11537 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11539 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11540 if (_curPost.RetweetedId == null)
11542 _reply_to_id = _curPost.StatusId;
11546 _reply_to_id = _curPost.RetweetedId.Value;
11548 _reply_to_name = _curPost.ScreenName;
11550 StatusText.SelectionStart = 0;
11551 StatusText.Focus();
11555 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11560 private void SearchButton_Click(object sender, EventArgs e)
11563 Control pnl = ((Control)sender).Parent;
11564 if (pnl == null) return;
11565 string tbName = pnl.Parent.Text;
11566 TabClass tb = _statuses.Tabs[tbName];
11567 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11568 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11569 cmb.Text = cmb.Text.Trim();
11570 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11571 bool Quote = false;
11572 StringBuilder buf = new StringBuilder();
11573 char[] c = cmb.Text.ToCharArray();
11574 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11576 if (cnt > cmb.Text.Length - 4)
11578 buf.Append(cmb.Text.Substring(cnt));
11587 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11589 buf.Append(" OR ");
11594 buf.Append(c[cnt]);
11596 cmb.Text = buf.ToString();
11598 tb.SearchWords = cmb.Text;
11599 tb.SearchLang = cmbLang.Text;
11600 if (string.IsNullOrEmpty(cmb.Text))
11602 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11606 if (tb.IsQueryChanged())
11608 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11609 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11610 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11611 cmb.Text = tb.SearchWords;
11613 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11614 this.PurgeListViewItemCache();
11615 lst.VirtualListSize = 0;
11616 _statuses.ClearTabIds(tbName);
11617 SaveConfigsTabs(); //検索条件の保存
11620 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, tbName);
11621 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11624 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11630 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11632 if (_statuses.RemovedTab.Count == 0)
11634 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11639 TabClass tb = _statuses.RemovedTab.Pop();
11640 if (tb.TabType == MyCommon.TabUsageType.Related)
11642 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11643 if (relatedTab != null)
11645 // 関連発言なら既存のタブを置き換える
11646 tb.TabName = relatedTab.TabName;
11647 this.ClearTab(tb.TabName, false);
11648 _statuses.Tabs[tb.TabName] = tb;
11649 for (int i = 0; i < ListTab.TabPages.Count; i++)
11651 if (tb.TabName == ListTab.TabPages[i].Text)
11653 ListTab.SelectedIndex = i;
11654 ListTabSelect(ListTab.TabPages[i]);
11661 const string TabName = "Related Tweets";
11662 string renamed = TabName;
11663 for (int i = 2; i <= 100; i++)
11665 if (!_statuses.ContainsTab(renamed)) break;
11666 renamed = TabName + i.ToString();
11668 tb.TabName = renamed;
11669 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11670 _statuses.Tabs.Add(renamed, tb); // 後に
11671 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11672 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11677 string renamed = tb.TabName;
11678 for (int i = 1; i < int.MaxValue; i++)
11680 if (!_statuses.ContainsTab(renamed)) break;
11681 renamed = tb.TabName + "(" + i.ToString() + ")";
11683 tb.TabName = renamed;
11684 _statuses.Tabs.Add(renamed, tb); // 先に
11685 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11686 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11687 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11693 private void doMoveToRTHome()
11695 if (_curList.SelectedIndices.Count > 0)
11697 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11698 if (post.RetweetedId != null)
11700 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11705 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11710 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11712 string name = GetUserId();
11718 if (_curList.SelectedIndices.Count == 0) return;
11721 if (!SelectTab(out tabName)) return;
11725 MoveOrCopy(ref mv, ref mk);
11727 PostFilterRule fc = new PostFilterRule();
11728 fc.FilterName = name;
11729 fc.UseNameField = true;
11730 fc.MoveMatches = mv;
11731 fc.MarkMatches = mk;
11732 fc.UseRegex = false;
11733 fc.FilterByUrl = false;
11734 _statuses.Tabs[tabName].AddFilter(fc);
11736 this.ApplyPostFilters();
11741 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11745 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11747 if (menuItem.Owner == this.ContextMenuPostBrowser)
11749 user = GetUserId();
11750 if (user == null) return;
11752 else if (this._curPost != null)
11754 user = this._curPost.ScreenName;
11761 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11763 string res = this.tw.GetListsApi();
11765 if (!string.IsNullOrEmpty(res))
11767 MessageBox.Show("Failed to get lists. (" + res + ")");
11772 using (MyLists listSelectForm = new MyLists(user, this.tw))
11774 listSelectForm.ShowDialog(this);
11778 private void SearchControls_Enter(object sender, EventArgs e)
11780 Control pnl = (Control)sender;
11781 foreach (Control ctl in pnl.Controls)
11783 ctl.TabStop = true;
11787 private void SearchControls_Leave(object sender, EventArgs e)
11789 Control pnl = (Control)sender;
11790 foreach (Control ctl in pnl.Controls)
11792 ctl.TabStop = false;
11796 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11798 if (ListTab.SelectedTab != null)
11800 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11801 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11805 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11807 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11810 HashMgr.SetPermanentHash("#" + Uri.UnescapeDataString(m.Result("${hash}")));
11811 HashStripSplitButton.Text = HashMgr.UseHash;
11812 HashToggleMenuItem.Checked = true;
11813 HashToggleToolStripMenuItem.Checked = true;
11815 _modifySettingCommon = true;
11819 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11821 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11824 private void HashManageMenuItem_Click(object sender, EventArgs e)
11826 DialogResult rslt = DialogResult.Cancel;
11829 rslt = HashMgr.ShowDialog();
11835 this.TopMost = SettingDialog.AlwaysTop;
11836 if (rslt == DialogResult.Cancel) return;
11837 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11839 HashStripSplitButton.Text = HashMgr.UseHash;
11840 HashToggleMenuItem.Checked = true;
11841 HashToggleToolStripMenuItem.Checked = true;
11845 HashStripSplitButton.Text = "#[-]";
11846 HashToggleMenuItem.Checked = false;
11847 HashToggleToolStripMenuItem.Checked = false;
11849 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11851 // int sidx = StatusText.SelectionStart;
11852 // string hash = HashMgr.UseHash + " ";
11855 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11856 // hash = " " + hash;
11858 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11859 // sidx += hash.Length;
11860 // StatusText.SelectionStart = sidx;
11861 // StatusText.Focus();
11863 _modifySettingCommon = true;
11864 this.StatusText_TextChanged(null, null);
11867 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11869 HashMgr.ToggleHash();
11870 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11872 HashStripSplitButton.Text = HashMgr.UseHash;
11873 HashToggleMenuItem.Checked = true;
11874 HashToggleToolStripMenuItem.Checked = true;
11878 HashStripSplitButton.Text = "#[-]";
11879 HashToggleMenuItem.Checked = false;
11880 HashToggleToolStripMenuItem.Checked = false;
11882 _modifySettingCommon = true;
11883 this.StatusText_TextChanged(null, null);
11886 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11888 HashToggleMenuItem_Click(null, null);
11891 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11893 if (ListTab.SelectedTab == null) return;
11894 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11895 if (!this.ExistCurrentPost)
11897 this.ReplyOpMenuItem.Enabled = false;
11898 this.ReplyAllOpMenuItem.Enabled = false;
11899 this.DmOpMenuItem.Enabled = false;
11900 this.ShowProfMenuItem.Enabled = false;
11901 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11902 this.ListManageMenuItem.Enabled = false;
11903 this.OpenFavOpMenuItem.Enabled = false;
11904 this.CreateTabRuleOpMenuItem.Enabled = false;
11905 this.CreateIdRuleOpMenuItem.Enabled = false;
11906 this.ReadOpMenuItem.Enabled = false;
11907 this.UnreadOpMenuItem.Enabled = false;
11911 this.ReplyOpMenuItem.Enabled = true;
11912 this.ReplyAllOpMenuItem.Enabled = true;
11913 this.DmOpMenuItem.Enabled = true;
11914 this.ShowProfMenuItem.Enabled = true;
11915 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11916 this.ListManageMenuItem.Enabled = true;
11917 this.OpenFavOpMenuItem.Enabled = true;
11918 this.CreateTabRuleOpMenuItem.Enabled = true;
11919 this.CreateIdRuleOpMenuItem.Enabled = true;
11920 this.ReadOpMenuItem.Enabled = true;
11921 this.UnreadOpMenuItem.Enabled = true;
11924 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11926 this.FavOpMenuItem.Enabled = false;
11927 this.UnFavOpMenuItem.Enabled = false;
11928 this.OpenStatusOpMenuItem.Enabled = false;
11929 this.OpenFavotterOpMenuItem.Enabled = false;
11930 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11931 this.RtOpMenuItem.Enabled = false;
11932 this.RtUnOpMenuItem.Enabled = false;
11933 this.QtOpMenuItem.Enabled = false;
11934 this.FavoriteRetweetMenuItem.Enabled = false;
11935 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11936 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11940 this.FavOpMenuItem.Enabled = true;
11941 this.UnFavOpMenuItem.Enabled = true;
11942 this.OpenStatusOpMenuItem.Enabled = true;
11943 this.OpenFavotterOpMenuItem.Enabled = true;
11944 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11948 this.RtOpMenuItem.Enabled = false;
11949 this.FavoriteRetweetMenuItem.Enabled = false;
11950 this.DelOpMenuItem.Enabled = true;
11954 this.DelOpMenuItem.Enabled = false;
11955 if (_curPost.IsProtect)
11957 this.RtOpMenuItem.Enabled = false;
11958 this.RtUnOpMenuItem.Enabled = false;
11959 this.QtOpMenuItem.Enabled = false;
11960 this.FavoriteRetweetMenuItem.Enabled = false;
11961 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11965 this.RtOpMenuItem.Enabled = true;
11966 this.RtUnOpMenuItem.Enabled = true;
11967 this.QtOpMenuItem.Enabled = true;
11968 this.FavoriteRetweetMenuItem.Enabled = true;
11969 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
11974 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
11976 this.RefreshPrevOpMenuItem.Enabled = true;
11980 this.RefreshPrevOpMenuItem.Enabled = false;
11982 if (!this.ExistCurrentPost
11983 || _curPost.InReplyToStatusId == null)
11985 OpenRepSourceOpMenuItem.Enabled = false;
11989 OpenRepSourceOpMenuItem.Enabled = true;
11991 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
11993 OpenRterHomeMenuItem.Enabled = false;
11997 OpenRterHomeMenuItem.Enabled = true;
12001 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
12003 ContextMenuTabProperty_Opening(sender, null);
12006 public Twitter TwitterInstance
12011 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
12013 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
12015 _mySpDis3 = SplitContainer3.SplitterDistance;
12016 _modifySettingLocal = true;
12020 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
12022 if (_statuses.RemovedTab.Count == 0)
12024 UndoRemoveTabMenuItem.Enabled = false;
12028 UndoRemoveTabMenuItem.Enabled = true;
12030 if (ListTab.SelectedTab != null)
12032 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
12033 PublicSearchQueryMenuItem.Enabled = true;
12035 PublicSearchQueryMenuItem.Enabled = false;
12039 PublicSearchQueryMenuItem.Enabled = false;
12041 if (!this.ExistCurrentPost)
12043 this.CopySTOTMenuItem.Enabled = false;
12044 this.CopyURLMenuItem.Enabled = false;
12045 this.CopyUserIdStripMenuItem.Enabled = false;
12049 this.CopySTOTMenuItem.Enabled = true;
12050 this.CopyURLMenuItem.Enabled = true;
12051 this.CopyUserIdStripMenuItem.Enabled = true;
12052 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
12053 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
12057 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
12059 SetNotifyIconText();
12062 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12065 if (_curPost != null)
12067 id = _curPost.ScreenName;
12069 ShowUserStatus(id);
12072 private class GetUserInfoArgs
12076 public TwitterUser user;
12079 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
12081 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
12082 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
12085 private void doShowUserStatus(string id, bool ShowInputDialog)
12087 TwitterUser user = null;
12088 GetUserInfoArgs args = new GetUserInfoArgs();
12089 if (ShowInputDialog)
12091 using (InputTabName inputName = new InputTabName())
12093 inputName.FormTitle = "Show UserStatus";
12094 inputName.FormDescription = Properties.Resources.FRMessage1;
12095 inputName.TabName = id;
12096 if (inputName.ShowDialog() == DialogResult.OK &&
12097 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12099 id = inputName.TabName.Trim();
12103 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12104 GetUserInfo_DoWork,
12108 _info.ShowDialog();
12109 string ret = (string)_info.Result;
12110 if (string.IsNullOrEmpty(ret))
12111 doShowUserStatus(args.user);
12113 MessageBox.Show(ret);
12123 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12124 GetUserInfo_DoWork,
12128 _info.ShowDialog();
12129 string ret = (string)_info.Result;
12130 if (string.IsNullOrEmpty(ret))
12132 doShowUserStatus(args.user);
12136 MessageBox.Show(ret);
12142 private async void doShowUserStatus(TwitterUser user)
12144 using (var userDialog = new UserInfoDialog(this, this.tw))
12146 var showUserTask = userDialog.ShowUserAsync(user);
12147 userDialog.ShowDialog(this);
12150 this.BringToFront();
12152 // ユーザー情報の表示が完了するまで userDialog を破棄しない
12153 await showUserTask;
12157 private void ShowUserStatus(string id, bool ShowInputDialog)
12159 doShowUserStatus(id, ShowInputDialog);
12162 private void ShowUserStatus(string id)
12164 doShowUserStatus(id, true);
12167 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12169 if (NameLabel.Tag != null)
12171 string id = (string)NameLabel.Tag;
12172 if (id != tw.Username)
12179 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12181 if (NameLabel.Tag != null)
12183 string id = (string)NameLabel.Tag;
12184 if (id != tw.Username)
12186 RemoveCommand(id, false);
12191 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12193 if (NameLabel.Tag != null)
12195 string id = (string)NameLabel.Tag;
12196 if (id != tw.Username)
12198 ShowFriendship(id);
12203 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12205 if (NameLabel.Tag != null)
12207 string id = (string)NameLabel.Tag;
12208 ShowUserStatus(id, false);
12212 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12214 if (NameLabel.Tag != null)
12216 string id = (string)NameLabel.Tag;
12217 AddNewTabForUserTimeline(id);
12221 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12223 if (NameLabel.Tag != null)
12225 string id = (string)NameLabel.Tag;
12226 AddNewTabForSearch("@" + id);
12230 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12232 if (_curPost != null)
12234 ShowUserStatus(_curPost.ScreenName, false);
12238 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12243 if (_curPost.RetweetedId != null)
12245 statusid = _curPost.RetweetedId.Value;
12249 statusid = _curPost.StatusId;
12251 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12253 e.Result = counter;
12256 private void RtCountMenuItem_Click(object sender, EventArgs e)
12258 if (this.ExistCurrentPost)
12260 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12261 GetRetweet_DoWork))
12263 int retweet_count = 0;
12266 _info.ShowDialog();
12267 retweet_count = (int)_info.Result;
12268 if (retweet_count < 0)
12270 MessageBox.Show(Properties.Resources.RtCountText2);
12274 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12280 private HookGlobalHotkey _hookGlobalHotkey;
12283 _hookGlobalHotkey = new HookGlobalHotkey(this);
12285 // この呼び出しは、Windows フォーム デザイナで必要です。
12286 InitializeComponent();
12288 // InitializeComponent() 呼び出しの後で初期化を追加します。
12290 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12291 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12292 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12293 this.gh.NotifyClicked += GrowlHelper_Callback;
12295 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12296 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
12298 this._apiGauge = new ToolStripAPIGauge();
12299 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12300 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12302 this.ImageSelector.Visible = false;
12303 this.ImageSelector.Enabled = false;
12304 this.ImageSelector.FilePickDialog = OpenFileDialog1;
12306 this.ReplaceAppName();
12309 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12311 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12314 this.Visible = false;
12316 else if (Form.ActiveForm == null)
12318 this.Visible = true;
12319 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12321 this.BringToFront();
12322 this.StatusText.Focus();
12326 private void UserPicture_MouseEnter(object sender, EventArgs e)
12328 this.UserPicture.Cursor = Cursors.Hand;
12331 private void UserPicture_MouseLeave(object sender, EventArgs e)
12333 this.UserPicture.Cursor = Cursors.Default;
12336 private void UserPicture_DoubleClick(object sender, EventArgs e)
12338 if (NameLabel.Tag != null)
12340 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12344 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12346 this.MultiLineMenuItem.PerformClick();
12349 public PostClass CurPost
12351 get { return _curPost; }
12354 public bool IsPreviewEnable
12356 get { return SettingDialog.PreviewEnable; }
12360 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12362 if (ImageSelector.Visible)
12363 ImageSelector.EndSelection();
12365 ImageSelector.BeginSelection();
12368 private void SelectMedia_DragEnter(DragEventArgs e)
12370 if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]))
12372 e.Effect = DragDropEffects.Copy;
12375 e.Effect = DragDropEffects.None;
12378 private void SelectMedia_DragOver(DragEventArgs e)
12383 private void SelectMedia_DragDrop(DragEventArgs e)
12386 this.BringToFront();
12387 ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
12388 StatusText.Focus();
12391 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
12393 TimelinePanel.Visible = false;
12394 TimelinePanel.Enabled = false;
12397 private void ImageSelector_EndSelecting(object sender, EventArgs e)
12399 TimelinePanel.Visible = true;
12400 TimelinePanel.Enabled = true;
12401 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12404 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
12406 this.AllowDrop = false;
12409 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
12411 this.AllowDrop = true;
12414 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
12416 if (ImageSelector.Visible)
12418 _modifySettingCommon = true;
12419 SaveConfigsAll(true);
12421 if (ImageSelector.ServiceName.Equals("Twitter"))
12422 this.StatusText_TextChanged(null, null);
12426 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
12428 this.StatusText_TextChanged(null, null);
12432 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12434 using (ListManage form = new ListManage(tw))
12436 form.ShowDialog(this);
12440 public bool ModifySettingCommon
12442 set { _modifySettingCommon = value; }
12445 public bool ModifySettingLocal
12447 set { _modifySettingLocal = value; }
12450 public bool ModifySettingAtId
12452 set { _modifySettingAtId = value; }
12455 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12457 string link = (string)SourceLinkLabel.Tag;
12458 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12460 OpenUriAsync(link);
12464 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12466 string link = (string)SourceLinkLabel.Tag;
12467 if (!string.IsNullOrEmpty(link))
12469 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12473 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12475 SetStatusLabelUrl();
12478 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12480 if (this.ExistCurrentPost && !_curPost.IsDm)
12481 RtCountMenuItem.Enabled = true;
12483 RtCountMenuItem.Enabled = false;
12485 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12486 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12488 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12491 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12496 private void CopyUserId()
12498 if (_curPost == null) return;
12499 string clstr = _curPost.ScreenName;
12502 Clipboard.SetDataObject(clstr, false, 5, 100);
12504 catch (Exception ex)
12506 MessageBox.Show(ex.Message);
12510 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12512 if (this.ExistCurrentPost && !_curPost.IsDm)
12516 this.OpenRelatedTab(this._curPost);
12518 catch (TabException ex)
12520 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12526 /// 指定されたツイートに対する関連発言タブを開きます
12528 /// <param name="post">表示する対象となるツイート</param>
12529 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12530 private void OpenRelatedTab(PostClass post)
12532 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12535 if (tabRelated == null)
12537 tabName = this._statuses.MakeTabName("Related Tweets");
12539 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12540 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12542 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12543 tabRelated.UnreadManage = false;
12544 tabRelated.Notify = false;
12548 tabName = tabRelated.TabName;
12551 tabRelated.RelationTargetPost = post;
12552 this.ClearTab(tabName, false);
12554 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12556 var tabPage = this.ListTab.TabPages[i];
12557 if (tabName == tabPage.Text)
12559 this.ListTab.SelectedIndex = i;
12560 this.ListTabSelect(tabPage);
12565 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, tabName);
12568 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12570 StringBuilder buf = new StringBuilder();
12571 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12572 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12573 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12574 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12575 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12578 private void tw_UserIdChanged()
12580 this._modifySettingCommon = true;
12583 #region "Userstream"
12584 private bool _isActiveUserstream = false;
12586 private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
12590 if (InvokeRequired && !IsDisposed)
12592 Invoke((Action) (() =>
12594 _statuses.RemovePostReserve(e.StatusId);
12595 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
12597 this.PurgeListViewItemCache();
12598 ((DetailsListView)_curTab.Tag).Update();
12599 if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
12605 catch (ObjectDisposedException)
12609 catch (InvalidOperationException)
12615 private void tw_NewPostFromStream(object sender, EventArgs e)
12617 if (SettingDialog.ReadOldPosts)
12619 _statuses.SetRead(); //新着時未読クリア
12622 int rsltAddCount = _statuses.DistributePosts();
12625 DateTime tm = DateTime.Now;
12626 if (_tlTimestamps.ContainsKey(tm))
12628 _tlTimestamps[tm] += rsltAddCount;
12632 _tlTimestamps.Add(tm, rsltAddCount);
12634 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12635 List<DateTime> keys = new List<DateTime>();
12637 foreach (DateTime key in _tlTimestamps.Keys)
12639 if (key.CompareTo(oneHour) < 0)
12642 _tlCount += _tlTimestamps[key];
12644 foreach (DateTime key in keys)
12646 _tlTimestamps.Remove(key);
12650 //Static DateTime before = Now;
12651 //if (before.Subtract(Now).Seconds > -5) return;
12655 if (SettingDialog.UserstreamPeriodInt > 0) return;
12659 if (InvokeRequired && !IsDisposed)
12661 Invoke(new Action<bool>(RefreshTimeline), true);
12665 catch (ObjectDisposedException)
12669 catch (InvalidOperationException)
12675 private void tw_UserStreamStarted(object sender, EventArgs e)
12677 this._isActiveUserstream = true;
12680 if (InvokeRequired && !IsDisposed)
12682 Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
12686 catch (ObjectDisposedException)
12690 catch (InvalidOperationException)
12695 MenuItemUserStream.Text = "&UserStream ▶";
12696 MenuItemUserStream.Enabled = true;
12697 StopToolStripMenuItem.Text = "&Stop";
12698 StopToolStripMenuItem.Enabled = true;
12700 StatusLabel.Text = "UserStream Started.";
12703 private void tw_UserStreamStopped(object sender, EventArgs e)
12705 this._isActiveUserstream = false;
12708 if (InvokeRequired && !IsDisposed)
12710 Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
12714 catch (ObjectDisposedException)
12718 catch (InvalidOperationException)
12723 MenuItemUserStream.Text = "&UserStream ■";
12724 MenuItemUserStream.Enabled = true;
12725 StopToolStripMenuItem.Text = "&Start";
12726 StopToolStripMenuItem.Enabled = true;
12728 StatusLabel.Text = "UserStream Stopped.";
12731 private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
12735 if (InvokeRequired && !IsDisposed)
12737 Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
12741 catch (ObjectDisposedException)
12745 catch (InvalidOperationException)
12749 var ev = e.EventData;
12750 StatusLabel.Text = "Event: " + ev.Event;
12751 //if (ev.Event == "favorite")
12753 // NotifyFavorite(ev);
12756 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12758 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12760 this.PurgeListViewItemCache();
12761 ((DetailsListView)_curTab.Tag).Update();
12763 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12765 RemovePostFromFavTab(new long[] {ev.Id});
12770 private void NotifyEvent(Twitter.FormattedEvent ev)
12773 if (BalloonRequired(ev))
12775 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12776 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12777 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12778 StringBuilder title = new StringBuilder();
12779 if (SettingDialog.DispUsername)
12781 title.Append(tw.Username);
12782 title.Append(" - ");
12788 title.Append(Application.ProductName);
12789 title.Append(" [");
12790 title.Append(ev.Event.ToUpper());
12791 title.Append("] by ");
12792 if (!string.IsNullOrEmpty(ev.Username))
12794 title.Append(ev.Username.ToString());
12798 //title.Append("");
12801 if (!string.IsNullOrEmpty(ev.Target))
12803 //NotifyIcon1.BalloonTipText = ev.Target;
12808 //NotifyIcon1.BalloonTipText = " ";
12811 //NotifyIcon1.ShowBalloonTip(500);
12812 if (SettingDialog.IsNotifyUseGrowl)
12814 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
12815 ev.Id.ToString(), title.ToString(), text);
12819 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12820 NotifyIcon1.BalloonTipTitle = title.ToString();
12821 NotifyIcon1.BalloonTipText = text;
12822 NotifyIcon1.ShowBalloonTip(500);
12827 string snd = SettingDialog.EventSoundFile;
12828 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(snd))
12830 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
12834 string dir = Application.StartupPath;
12835 if (Directory.Exists(Path.Combine(dir, "Sounds")))
12837 dir = Path.Combine(dir, "Sounds");
12839 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
12851 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
12853 MenuItemUserStream.Enabled = false;
12854 if (StopRefreshAllMenuItem.Checked)
12856 StopRefreshAllMenuItem.Checked = false;
12859 if (this._isActiveUserstream)
12861 tw.StopUserStream();
12865 tw.StartUserStream();
12869 private static string inputTrack = "";
12871 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
12873 if (TrackToolStripMenuItem.Checked)
12875 using (InputTabName inputForm = new InputTabName())
12877 inputForm.TabName = inputTrack;
12878 inputForm.FormTitle = "Input track word";
12879 inputForm.FormDescription = "Track word";
12880 if (inputForm.ShowDialog() != DialogResult.OK)
12882 TrackToolStripMenuItem.Checked = false;
12885 inputTrack = inputForm.TabName.Trim();
12887 if (!inputTrack.Equals(tw.TrackWord))
12889 tw.TrackWord = inputTrack;
12890 this._modifySettingCommon = true;
12891 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
12892 tw.ReconnectUserStream();
12898 tw.ReconnectUserStream();
12900 this._modifySettingCommon = true;
12903 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
12905 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
12906 this._modifySettingCommon = true;
12907 tw.ReconnectUserStream();
12910 private void EventViewerMenuItem_Click(object sender, EventArgs e)
12912 if (evtDialog == null || evtDialog.IsDisposed)
12915 evtDialog = new EventViewerDialog();
12916 evtDialog.Owner = this;
12918 Point pos = evtDialog.Location;
12919 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
12920 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
12921 evtDialog.Location = pos;
12923 evtDialog.EventSource = tw.StoredEvent;
12924 if (!evtDialog.Visible)
12926 evtDialog.Show(this);
12930 evtDialog.Activate();
12932 this.TopMost = this.SettingDialog.AlwaysTop;
12936 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
12938 MyCommon._endingFlag = true;
12942 Application.Restart();
12946 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
12950 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
12952 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
12955 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
12957 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
12960 private async Task doTranslation(string str)
12962 if (string.IsNullOrEmpty(str))
12965 var bing = new Bing();
12968 var translatedText = await bing.TranslateAsync(str,
12970 langTo: this.SettingDialog.TranslateLanguage);
12972 this.PostBrowser.DocumentText = translatedText;
12974 catch (HttpRequestException e)
12976 this.StatusLabel.Text = "Err:" + e.Message;
12980 private async void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
12982 if (!this.ExistCurrentPost)
12985 await this.doTranslation(this._curPost.TextFromApi);
12988 private async void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
12990 var text = this.WebBrowser_GetSelectionText(ref this.PostBrowser);
12991 await this.doTranslation(text);
12994 private bool ExistCurrentPost
12998 if (_curPost == null) return false;
12999 if (_curPost.IsDeleted) return false;
13004 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13006 ShowUserTimeline();
13009 public bool FavEventChangeUnread
13011 get { return SettingDialog.FavEventUnread; }
13014 private string GetUserIdFromCurPostOrInput(string caption)
13017 if (_curPost != null)
13019 id = _curPost.ScreenName;
13021 using (InputTabName inputName = new InputTabName())
13023 inputName.FormTitle = caption;
13024 inputName.FormDescription = Properties.Resources.FRMessage1;
13025 inputName.TabName = id;
13026 if (inputName.ShowDialog() == DialogResult.OK &&
13027 !string.IsNullOrEmpty(inputName.TabName.Trim()))
13029 id = inputName.TabName.Trim();
13039 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13041 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
13042 if (!string.IsNullOrEmpty(id))
13044 AddNewTabForUserTimeline(id);
13048 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
13050 string id = GetUserIdFromCurPostOrInput("Show Favstar");
13051 if (!string.IsNullOrEmpty(id))
13053 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
13057 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
13059 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
13062 private void TimelineRefreshEnableChange(bool isEnable)
13066 tw.StartUserStream();
13070 tw.StopUserStream();
13072 TimerTimeline.Enabled = isEnable;
13075 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
13077 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
13080 private void OpenUserAppointUrl()
13082 if (SettingDialog.UserAppointUrl != null)
13084 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
13086 if (_curPost != null)
13088 string xUrl = SettingDialog.UserAppointUrl;
13089 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
13090 if (_curPost.RetweetedId != null)
13092 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
13096 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
13098 OpenUriAsync(xUrl);
13103 OpenUriAsync(SettingDialog.UserAppointUrl);
13108 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
13110 OpenUserAppointUrl();
13113 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
13115 string selText = SourceLinkLabel.Text;
13118 Clipboard.SetDataObject(selText, false, 5, 100);
13120 catch (Exception ex)
13122 MessageBox.Show(ex.Message);
13126 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
13128 string selText = (string)SourceLinkLabel.Tag;
13131 Clipboard.SetDataObject(selText, false, 5, 100);
13133 catch (Exception ex)
13135 MessageBox.Show(ex.Message);
13139 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
13141 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
13143 SourceCopyMenuItem.Enabled = false;
13144 SourceUrlCopyMenuItem.Enabled = false;
13148 SourceCopyMenuItem.Enabled = true;
13149 SourceUrlCopyMenuItem.Enabled = true;
13153 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
13155 if (Form.ActiveForm == null)
13157 this.BeginInvoke((Action) (() =>
13159 this.Visible = true;
13160 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
13162 this.BringToFront();
13163 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
13165 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
13169 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13175 private void ReplaceAppName()
13177 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13178 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13181 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13183 this.SplitContainer3.Panel2Collapsed = false;
13185 // PreviewDistance が起動のたびに広がっていく問題の回避策
13186 // FixedPanel が Panel2 に設定された状態で Panel2 を開くと、初回だけ SplitterDistance が再計算されておかしくなるため、
13187 // None で開いた後に設定するようにする
13188 if (this.SplitContainer3.FixedPanel == FixedPanel.None)
13189 this.SplitContainer3.FixedPanel = FixedPanel.Panel2;
13192 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13194 this.OpenThumbnailPicture(e.Thumbnail);
13197 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13199 this.OpenUriAsync(e.ImageUrl);
13202 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13204 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13207 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13209 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13212 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13214 if (e.KeyCode == Keys.Space)
13216 this.JumpUnreadMenuItem_Click(null, null);
13218 e.SuppressKeyPress = true;
13222 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
13224 this.IconSizeNoneToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.IconNone;
13225 this.IconSize16ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon16;
13226 this.IconSize24ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon24;
13227 this.IconSize48ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48;
13228 this.IconSize48_2ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48_2;
13230 this.LockListSortOrderToolStripMenuItem.Checked = SettingDialog.SortOrderLock;
13233 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
13235 ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
13238 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
13240 ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
13243 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
13245 ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
13248 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
13250 ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
13253 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
13255 ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
13258 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
13260 if (SettingDialog.IconSz == iconSize) return;
13262 var oldIconCol = _iconCol;
13264 SettingDialog.IconSz = iconSize;
13265 ApplyListViewIconSize(iconSize);
13267 if (_iconCol != oldIconCol)
13269 foreach (TabPage tp in ListTab.TabPages)
13271 ResetColumns((DetailsListView)tp.Tag);
13275 if (_curList != null) _curList.Refresh();
13277 _modifySettingCommon = true;
13280 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
13282 var state = this.LockListSortOrderToolStripMenuItem.Checked;
13283 if (SettingDialog.SortOrderLock == state) return;
13285 SettingDialog.SortOrderLock = state;
13287 _modifySettingCommon = true;