1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
29 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
32 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Diagnostics;
40 using System.Net.Http;
41 using System.Reflection;
43 using System.Text.RegularExpressions;
44 using System.Threading;
45 using System.Threading.Tasks;
46 using System.Windows.Forms;
48 using OpenTween.Connection;
49 using OpenTween.OpenTweenCustomControl;
50 using OpenTween.Thumbnail;
54 public partial class TweenMain : OTBaseForm
57 private Size _mySize; //画面サイズ
58 private Point _myLoc; //画面位置
59 private int _mySpDis; //区切り位置
60 private int _mySpDis2; //発言欄区切り位置
61 private int _mySpDis3; //プレビュー区切り位置
62 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
63 private bool _iconCol; //1列表示の時true(48サイズのとき)
66 private bool _initial; //true:起動時処理中
67 private bool _initialLayout = true;
68 private bool _ignoreConfigSave; //true:起動時処理中
69 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
70 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
71 private Point _tabMouseDownPoint;
72 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
73 private readonly object _syncObject = new object(); //ロック用
74 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
75 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
76 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
77 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
78 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
79 private const string detailHtmlFormatMono6 = ");\"><pre>";
80 private const string detailHtmlFormatMono7 = "</pre></body></html>";
81 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
82 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
83 private const string detailHtmlFormat7 = "</span></p></body></html>";
84 private string detailHtmlFormatHeader;
85 private string detailHtmlFormatFooter;
86 private bool _myStatusError = false;
87 private bool _myStatusOnline = false;
88 private bool soundfileListup = false;
89 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
92 //private SettingToConfig _cfg; //旧
93 private SettingLocal _cfgLocal;
94 private SettingCommon _cfgCommon;
95 private bool _modifySettingLocal = false;
96 private bool _modifySettingCommon = false;
97 private bool _modifySettingAtId = false;
100 private Twitter tw = new Twitter();
103 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
106 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
107 private SearchWordDialog SearchDialog = new SearchWordDialog(); //検索画面インスタンス
108 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
109 private OpenURL UrlDialog = new OpenURL();
110 public AtIdSupplement AtIdSupl; //@id補助
111 public AtIdSupplement HashSupl; //Hashtag補助
112 public HashtagManage HashMgr;
113 private EventViewerDialog evtDialog;
116 private Font _fntUnread; //未読用フォント
117 private Color _clUnread; //未読用文字色
118 private Font _fntReaded; //既読用フォント
119 private Color _clReaded; //既読用文字色
120 private Color _clFav; //Fav用文字色
121 private Color _clOWL; //片思い用文字色
122 private Color _clRetweet; //Retweet用文字色
123 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
124 private Font _fntDetail; //発言詳細部用フォント
125 private Color _clDetail; //発言詳細部用色
126 private Color _clDetailLink; //発言詳細部用リンク文字色
127 private Color _clDetailBackcolor; //発言詳細部用背景色
128 private Color _clSelf; //自分の発言用背景色
129 private Color _clAtSelf; //自分宛返信用背景色
130 private Color _clTarget; //選択発言者の他の発言用背景色
131 private Color _clAtTarget; //選択発言中の返信先用背景色
132 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
133 private Color _clAtTo; //選択発言の唯一@先
134 private Color _clListBackcolor; //リスト部通常発言背景色
135 private Color _clInputBackcolor; //入力欄背景色
136 private Color _clInputFont; //入力欄文字色
137 private Font _fntInputFont; //入力欄フォント
138 private ImageCache IconCache; //アイコン画像リスト
139 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
140 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
141 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
142 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
143 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
144 private Icon MainIcon; //Main.ico 画面左上のアイコン
145 private Icon ReplyIcon; //5g
146 private Icon ReplyIconBlink; //6g
148 private ImageList _listViewImageList = new ImageList(); //ListViewItemの高さ変更用
150 private PostClass _anchorPost;
151 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
153 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
154 private int _hisIdx; //発言履歴カレントインデックス
156 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
157 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
158 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
161 private List<DateTime> _postTimestamps = new List<DateTime>();
162 private List<DateTime> _favTimestamps = new List<DateTime>();
163 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
164 private int _tlCount;
167 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
168 private SolidBrush _brsBackColorMine;
169 private SolidBrush _brsBackColorAt;
170 private SolidBrush _brsBackColorYou;
171 private SolidBrush _brsBackColorAtYou;
172 private SolidBrush _brsBackColorAtFromTarget;
173 private SolidBrush _brsBackColorAtTo;
174 private SolidBrush _brsBackColorNone;
175 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
176 private StringFormat sfTab = new StringFormat();
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////
179 private ToolStripAPIGauge _apiGauge;
180 private TabInformations _statuses;
182 // ListViewItem のキャッシュ関連
183 private int _itemCacheIndex;
184 private ListViewItem[] _itemCache;
185 private PostClass[] _postCache;
186 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
188 private TabPage _curTab;
189 private int _curItemIndex;
190 private DetailsListView _curList;
191 private PostClass _curPost;
192 private bool _isColumnChanged = false;
193 private bool _waitTimeline = false;
194 private bool _waitReply = false;
195 private bool _waitDm = false;
196 private bool _waitFav = false;
197 private bool _waitPubSearch = false;
198 private bool _waitUserTimeline = false;
199 private bool _waitLists = false;
200 private BackgroundWorker[] _bw = new BackgroundWorker[20];
201 private BackgroundWorker _bwFollower;
203 private int UnreadCounter = -1;
204 private int UnreadAtCounter = -1;
206 private string[] ColumnOrgText = new string[9];
207 private string[] ColumnText = new string[9];
209 private bool _DoFavRetweetFlags = false;
210 private bool osResumed = false;
212 //////////////////////////////////////////////////////////////////////////////////////////////////////////
213 private string _postBrowserStatusText = "";
215 private bool _colorize = false;
217 private System.Timers.Timer TimerTimeline = new System.Timers.Timer();
219 private ImageListViewItem displayItem;
222 /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
224 protected SizeF currentScaleFactor = new SizeF();
227 private struct urlUndo
229 public string Before;
233 private List<urlUndo> urlUndoBuffer = null;
235 private struct ReplyChain
237 public long OriginalId;
238 public long InReplyToId;
239 public TabPage OriginalTab;
241 public ReplyChain(long originalId, long inReplyToId, TabPage originalTab)
243 this.OriginalId = originalId;
244 this.InReplyToId = inReplyToId;
245 this.OriginalTab = originalTab;
249 private Stack<ReplyChain> replyChains; //[, ]でのリプライ移動の履歴
250 private Stack<Tuple<TabPage, PostClass>> selectPostChains = new Stack<Tuple<TabPage, PostClass>>(); //ポスト選択履歴
252 //Backgroundworkerの処理結果通知用引数構造体
253 private class GetWorkerResult
255 public string retMsg = ""; //処理結果詳細メッセージ。エラー時に値がセットされる
256 public MyCommon.WORKERTYPE type; //処理種別
257 public string tName = ""; //Fav追加・削除時のタブ名
258 public List<long> sIds = null; //Fav追加・削除成功分のID
259 public bool newDM = false;
261 public PostingStatus status;
264 //Backgroundworkerへ処理内容を通知するための引数用構造体
265 private class GetWorkerArg
267 public int page; //処理対象ページ番号
268 public MyCommon.WORKERTYPE type; //処理種別
269 public PostingStatus status = new PostingStatus(); //発言POST時の発言内容
270 public List<long> ids; //Fav追加・削除時のItemIndex
271 public List<long> sIds; //Fav追加・削除成功分のItemIndex
272 public string tName = ""; //Fav追加・削除時のタブ名
276 private enum SEARCHTYPE
283 private class PostingStatus
285 public string status = "";
286 public long? inReplyToId = null;
287 public string inReplyToName = null;
288 public string imageService = ""; //画像投稿サービス名
289 public string[] imagePath = null;
290 public PostingStatus()
293 public PostingStatus(string status, long? replyToId, string replyToName)
295 this.status = status;
296 this.inReplyToId = replyToId;
297 this.inReplyToName = replyToName;
301 private void TweenMain_Activated(object sender, EventArgs e)
303 //画面がアクティブになったら、発言欄の背景色戻す
304 if (StatusText.Focused)
306 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
310 private bool disposed = false;
313 /// 使用中のリソースをすべてクリーンアップします。
315 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
316 protected override void Dispose(bool disposing)
318 base.Dispose(disposing);
325 if (this.components != null)
326 this.components.Dispose();
329 SettingDialog.Dispose();
330 SearchDialog.Dispose();
333 if (NIconAt != null) NIconAt.Dispose();
334 if (NIconAtRed != null) NIconAtRed.Dispose();
335 if (NIconAtSmoke != null) NIconAtSmoke.Dispose();
336 if (NIconRefresh[0] != null) NIconRefresh[0].Dispose();
337 if (NIconRefresh[1] != null) NIconRefresh[1].Dispose();
338 if (NIconRefresh[2] != null) NIconRefresh[2].Dispose();
339 if (NIconRefresh[3] != null) NIconRefresh[3].Dispose();
340 if (TabIcon != null) TabIcon.Dispose();
341 if (MainIcon != null) MainIcon.Dispose();
342 if (ReplyIcon != null) ReplyIcon.Dispose();
343 if (ReplyIconBlink != null) ReplyIconBlink.Dispose();
344 _listViewImageList.Dispose();
345 _brsHighLight.Dispose();
346 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
347 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
348 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
349 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
350 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
351 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
352 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
353 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
356 foreach (BackgroundWorker bw in _bw)
361 if (_bwFollower != null)
363 _bwFollower.Dispose();
365 this._apiGauge.Dispose();
366 if (IconCache != null)
368 this.IconCache.CancelAsync();
369 this.IconCache.Dispose();
372 this.thumbnailTokenSource.Dispose();
373 this.itemCacheLock.Dispose();
375 this._hookGlobalHotkey.Dispose();
378 // 終了時にRemoveHandlerしておかないとメモリリークする
379 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
380 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
382 this.disposed = true;
385 private void LoadIcon(ref Icon IconInstance, string FileName)
387 string dir = Application.StartupPath;
388 if (File.Exists(Path.Combine(dir, FileName)))
392 IconInstance = new Icon(Path.Combine(dir, FileName));
400 private void LoadIcons()
404 string dir = Application.StartupPath;
406 NIconAt = Properties.Resources.At;
407 NIconAtRed = Properties.Resources.AtRed;
408 NIconAtSmoke = Properties.Resources.AtSmoke;
409 NIconRefresh[0] = Properties.Resources.Refresh;
410 NIconRefresh[1] = Properties.Resources.Refresh2;
411 NIconRefresh[2] = Properties.Resources.Refresh3;
412 NIconRefresh[3] = Properties.Resources.Refresh4;
413 TabIcon = Properties.Resources.TabIcon;
414 MainIcon = Properties.Resources.MIcon;
415 ReplyIcon = Properties.Resources.Reply;
416 ReplyIconBlink = Properties.Resources.ReplyBlink;
418 if (!Directory.Exists(Path.Combine(dir, "Icons")))
421 LoadIcon(ref NIconAt, "Icons\\At.ico");
424 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
427 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
430 //アニメーション対応により4種類読み込み
431 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
432 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
433 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
434 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
437 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
440 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
443 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
446 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
449 private void InitColumns(ListView list, bool startup)
451 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
452 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
453 ColumnHeader _colHd3 = new ColumnHeader(); //本文
454 ColumnHeader _colHd4 = new ColumnHeader(); //日付
455 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
456 ColumnHeader _colHd6 = new ColumnHeader(); //未読
457 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
458 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
462 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
466 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
470 _colHd1.Text = ColumnText[0];
472 _colHd2.Text = ColumnText[1];
474 _colHd3.Text = ColumnText[2];
476 _colHd4.Text = ColumnText[3];
478 _colHd5.Text = ColumnText[4];
480 _colHd6.Text = ColumnText[5];
482 _colHd7.Text = ColumnText[6];
484 _colHd8.Text = ColumnText[7];
487 int[] dispOrder = new int[8];
490 for (int i = 0; i < _curList.Columns.Count; i++)
492 for (int j = 0; j < _curList.Columns.Count; j++)
494 if (_curList.Columns[j].DisplayIndex == i)
501 for (int i = 0; i < _curList.Columns.Count; i++)
503 list.Columns[i].Width = _curList.Columns[i].Width;
504 list.Columns[dispOrder[i]].DisplayIndex = i;
511 list.Columns[0].Width = _cfgLocal.Width1;
512 list.Columns[1].Width = _cfgLocal.Width3;
513 list.Columns[0].DisplayIndex = 0;
514 list.Columns[1].DisplayIndex = 1;
518 for (int i = 0; i <= 7; i++)
520 if (_cfgLocal.DisplayIndex1 == i)
522 else if (_cfgLocal.DisplayIndex2 == i)
524 else if (_cfgLocal.DisplayIndex3 == i)
526 else if (_cfgLocal.DisplayIndex4 == i)
528 else if (_cfgLocal.DisplayIndex5 == i)
530 else if (_cfgLocal.DisplayIndex6 == i)
532 else if (_cfgLocal.DisplayIndex7 == i)
534 else if (_cfgLocal.DisplayIndex8 == i)
537 list.Columns[0].Width = _cfgLocal.Width1;
538 list.Columns[1].Width = _cfgLocal.Width2;
539 list.Columns[2].Width = _cfgLocal.Width3;
540 list.Columns[3].Width = _cfgLocal.Width4;
541 list.Columns[4].Width = _cfgLocal.Width5;
542 list.Columns[5].Width = _cfgLocal.Width6;
543 list.Columns[6].Width = _cfgLocal.Width7;
544 list.Columns[7].Width = _cfgLocal.Width8;
545 for (int i = 0; i <= 7; i++)
547 list.Columns[dispOrder[i]].DisplayIndex = i;
553 private void InitColumnText()
556 ColumnText[1] = Properties.Resources.AddNewTabText2;
557 ColumnText[2] = Properties.Resources.AddNewTabText3;
558 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
559 ColumnText[4] = Properties.Resources.AddNewTabText5;
562 ColumnText[7] = "Source";
564 ColumnOrgText[0] = "";
565 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
566 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
567 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
568 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
569 ColumnOrgText[5] = "";
570 ColumnOrgText[6] = "";
571 ColumnOrgText[7] = "Source";
574 switch (_statuses.SortMode)
576 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
579 case IdComparerClass.ComparerMode.Data: //本文
582 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
585 case IdComparerClass.ComparerMode.Name: //名前
588 case IdComparerClass.ComparerMode.Source: //Source
595 if (_statuses.SortOrder == SortOrder.Descending)
597 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
598 ColumnText[2] = ColumnOrgText[2] + "▾";
602 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
603 ColumnText[2] = ColumnOrgText[2] + "▴";
608 if (_statuses.SortOrder == SortOrder.Descending)
610 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
611 ColumnText[c] = ColumnOrgText[c] + "▾";
615 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
616 ColumnText[c] = ColumnOrgText[c] + "▴";
621 private void InitializeTraceFrag()
624 TraceOutToolStripMenuItem.Checked = true;
625 MyCommon.TraceFlag = true;
627 if (!MyCommon.FileVersion.EndsWith("0"))
629 TraceOutToolStripMenuItem.Checked = true;
630 MyCommon.TraceFlag = true;
634 private void TweenMain_Load(object sender, EventArgs e)
636 _ignoreConfigSave = true;
637 this.Visible = false;
639 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
641 new InternetSecurityManager(PostBrowser);
642 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
644 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
645 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
647 if (MyApplication.StartupOptions.ContainsKey("d"))
648 MyCommon.TraceFlag = true;
650 Regex.CacheSize = 100;
652 InitializeTraceFrag();
653 LoadIcons(); // アイコン読み込み
656 _statuses = TabInformations.GetInstance();
659 this.Icon = MainIcon; //メインフォーム(TweenMain)
660 NotifyIcon1.Icon = NIconAt; //タスクトレイ
661 TabImage.Images.Add(TabIcon); //タブ見出し
663 SettingDialog.Owner = this;;
664 SearchDialog.Owner = this;
665 fltDialog.Owner = this;
666 UrlDialog.Owner = this;
668 _history.Add(new PostingStatus());
671 _reply_to_name = null;
673 //<<<<<<<<<設定関連>>>>>>>>>
680 ThumbnailGenerator.InitializeGenerator();
682 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
683 imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
684 imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
686 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
687 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
688 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
691 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
692 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
695 _fntUnread = _cfgLocal.FontUnread;
696 _clUnread = _cfgLocal.ColorUnread;
697 _fntReaded = _cfgLocal.FontRead;
698 _clReaded = _cfgLocal.ColorRead;
699 _clFav = _cfgLocal.ColorFav;
700 _clOWL = _cfgLocal.ColorOWL;
701 _clRetweet = _cfgLocal.ColorRetweet;
702 _fntDetail = _cfgLocal.FontDetail;
703 _clDetail = _cfgLocal.ColorDetail;
704 _clDetailLink = _cfgLocal.ColorDetailLink;
705 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
706 _clSelf = _cfgLocal.ColorSelf;
707 _clAtSelf = _cfgLocal.ColorAtSelf;
708 _clTarget = _cfgLocal.ColorTarget;
709 _clAtTarget = _cfgLocal.ColorAtTarget;
710 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
711 _clAtTo = _cfgLocal.ColorAtTo;
712 _clListBackcolor = _cfgLocal.ColorListBackcolor;
713 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
714 _clInputFont = _cfgLocal.ColorInputFont;
715 _fntInputFont = _cfgLocal.FontInputFont;
717 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
718 if (fontUIGlobal != null)
720 OTBaseForm.GlobalFont = fontUIGlobal;
721 this.Font = fontUIGlobal;
724 // StringFormatオブジェクトへの事前設定
725 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
726 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
727 //sf.FormatFlags = StringFormatFlags.LineLimit; //
728 sfTab.Alignment = StringAlignment.Center;
729 sfTab.LineAlignment = StringAlignment.Center;
732 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
733 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
736 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
737 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
739 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
741 SettingDialog.TimelinePeriodInt = _cfgCommon.TimelinePeriod;
742 SettingDialog.ReplyPeriodInt = _cfgCommon.ReplyPeriod;
743 SettingDialog.DMPeriodInt = _cfgCommon.DMPeriod;
744 SettingDialog.PubSearchPeriodInt = _cfgCommon.PubSearchPeriod;
745 SettingDialog.UserTimelinePeriodInt = _cfgCommon.UserTimelinePeriod;
746 SettingDialog.ListsPeriodInt = _cfgCommon.ListsPeriod;
748 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
750 if (SettingDialog.TimelinePeriodInt < 15 && SettingDialog.TimelinePeriodInt > 0) SettingDialog.TimelinePeriodInt = 15;
751 if (SettingDialog.ReplyPeriodInt < 15 && SettingDialog.ReplyPeriodInt > 0) SettingDialog.ReplyPeriodInt = 15;
752 if (SettingDialog.DMPeriodInt < 15 && SettingDialog.DMPeriodInt > 0) SettingDialog.DMPeriodInt = 15;
753 if (SettingDialog.PubSearchPeriodInt < 30 && SettingDialog.PubSearchPeriodInt > 0) SettingDialog.PubSearchPeriodInt = 30;
754 if (SettingDialog.UserTimelinePeriodInt < 15 && SettingDialog.UserTimelinePeriodInt > 0) SettingDialog.UserTimelinePeriodInt = 15;
755 if (SettingDialog.ListsPeriodInt < 15 && SettingDialog.ListsPeriodInt > 0) SettingDialog.ListsPeriodInt = 15;
758 //起動時読み込み分を既読にするか。trueなら既読として処理
759 SettingDialog.Readed = _cfgCommon.Read;
760 //新着取得時のリストスクロールをするか。trueならスクロールしない
761 ListLockMenuItem.Checked = _cfgCommon.ListLock;
762 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
763 SettingDialog.IconSz = _cfgCommon.IconSize;
765 SettingDialog.Status = _cfgLocal.StatusText;
767 SettingDialog.UnreadManage = _cfgCommon.UnreadManage;
769 SettingDialog.PlaySound = _cfgCommon.PlaySound;
770 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
771 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
772 //片思い表示。trueなら片思い表示する
773 SettingDialog.OneWayLove = _cfgCommon.OneWayLove;
775 SettingDialog.FontUnread = _fntUnread;
776 SettingDialog.ColorUnread = _clUnread;
777 SettingDialog.FontReaded = _fntReaded;
778 SettingDialog.ColorReaded = _clReaded;
779 SettingDialog.ColorFav = _clFav;
780 SettingDialog.ColorOWL = _clOWL;
781 SettingDialog.ColorRetweet = _clRetweet;
782 SettingDialog.FontDetail = _fntDetail;
783 SettingDialog.ColorDetail = _clDetail;
784 SettingDialog.ColorDetailLink = _clDetailLink;
785 SettingDialog.ColorDetailBackcolor = _clDetailBackcolor;
786 SettingDialog.ColorSelf = _clSelf;
787 SettingDialog.ColorAtSelf = _clAtSelf;
788 SettingDialog.ColorTarget = _clTarget;
789 SettingDialog.ColorAtTarget = _clAtTarget;
790 SettingDialog.ColorAtFromTarget = _clAtFromTarget;
791 SettingDialog.ColorAtTo = _clAtTo;
792 SettingDialog.ColorListBackcolor = _clListBackcolor;
793 SettingDialog.ColorInputBackcolor = _clInputBackcolor;
794 SettingDialog.ColorInputFont = _clInputFont;
795 SettingDialog.FontInputFont = _fntInputFont;
797 SettingDialog.NameBalloon = _cfgCommon.NameBalloon;
798 SettingDialog.PostCtrlEnter = _cfgCommon.PostCtrlEnter;
799 SettingDialog.PostShiftEnter = _cfgCommon.PostShiftEnter;
801 SettingDialog.CountApi = _cfgCommon.CountApi;
802 SettingDialog.CountApiReply = _cfgCommon.CountApiReply;
803 if (SettingDialog.CountApi < 20 || SettingDialog.CountApi > 200) SettingDialog.CountApi = 60;
804 if (SettingDialog.CountApiReply < 20 || SettingDialog.CountApiReply > 200) SettingDialog.CountApiReply = 40;
806 SettingDialog.BrowserPath = _cfgLocal.BrowserPath;
807 SettingDialog.PostAndGet = _cfgCommon.PostAndGet;
808 SettingDialog.UseRecommendStatus = _cfgLocal.UseRecommendStatus;
809 SettingDialog.DispUsername = _cfgCommon.DispUsername;
810 SettingDialog.CloseToExit = _cfgCommon.CloseToExit;
811 SettingDialog.MinimizeToTray = _cfgCommon.MinimizeToTray;
812 SettingDialog.DispLatestPost = _cfgCommon.DispLatestPost;
813 SettingDialog.SortOrderLock = _cfgCommon.SortOrderLock;
814 SettingDialog.ViewTabBottom = _cfgCommon.ViewTabBottom;
815 SettingDialog.TinyUrlResolve = _cfgCommon.TinyUrlResolve;
817 SettingDialog.SelectedProxyType = _cfgLocal.ProxyType;
818 SettingDialog.ProxyAddress = _cfgLocal.ProxyAddress;
819 SettingDialog.ProxyPort = _cfgLocal.ProxyPort;
820 SettingDialog.ProxyUser = _cfgLocal.ProxyUser;
821 SettingDialog.ProxyPassword = _cfgLocal.ProxyPassword;
823 SettingDialog.StartupVersion = _cfgCommon.StartupVersion;
824 SettingDialog.StartupFollowers = _cfgCommon.StartupFollowers;
825 SettingDialog.RestrictFavCheck = _cfgCommon.RestrictFavCheck;
826 SettingDialog.AlwaysTop = _cfgCommon.AlwaysTop;
827 SettingDialog.UrlConvertAuto = false;
828 //SettingDialog.UrlConvertAuto = _cfgCommon.UrlConvertAuto;
830 SettingDialog.UseUnreadStyle = _cfgCommon.UseUnreadStyle;
831 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
832 SettingDialog.RetweetNoConfirm = _cfgCommon.RetweetNoConfirm;
833 SettingDialog.PlaySound = _cfgCommon.PlaySound;
834 SettingDialog.DateTimeFormat = _cfgCommon.DateTimeFormat;
835 SettingDialog.LimitBalloon = _cfgCommon.LimitBalloon;
836 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
837 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
838 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
839 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
840 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
841 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
842 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
844 //廃止サービスが選択されていた場合bit.lyへ読み替え
845 if (_cfgCommon.AutoShortUrlFirst < 0)
846 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
848 SettingDialog.AutoShortUrlFirst = _cfgCommon.AutoShortUrlFirst;
849 SettingDialog.TabIconDisp = _cfgCommon.TabIconDisp;
850 SettingDialog.ReplyIconState = _cfgCommon.ReplyIconState;
851 SettingDialog.ReadOwnPost = _cfgCommon.ReadOwnPost;
852 SettingDialog.GetFav = _cfgCommon.GetFav;
853 SettingDialog.ReadOldPosts = _cfgCommon.ReadOldPosts;
854 SettingDialog.BitlyUser = _cfgCommon.BilyUser;
855 SettingDialog.BitlyPwd = _cfgCommon.BitlyPwd;
856 SettingDialog.ShowGrid = _cfgCommon.ShowGrid;
857 SettingDialog.Language = _cfgCommon.Language;
858 SettingDialog.UseAtIdSupplement = _cfgCommon.UseAtIdSupplement;
859 SettingDialog.UseHashSupplement = _cfgCommon.UseHashSupplement;
860 SettingDialog.PreviewEnable = _cfgCommon.PreviewEnable;
861 SettingDialog.StatusAreaAtBottom = _cfgCommon.StatusAreaAtBottom;
862 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
864 SettingDialog.IsMonospace = _cfgCommon.IsMonospace;
866 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
867 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
869 //Regex statregex = new Regex("^0*");
870 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
875 if (DateTime.Now.ToString(SettingDialog.DateTimeFormat).Length == 0)
877 // このブロックは絶対に実行されないはず
878 // 変換が成功した場合にLengthが0にならない
879 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
882 catch (FormatException)
884 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
885 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
888 SettingDialog.Nicoms = _cfgCommon.Nicoms;
889 SettingDialog.HotkeyEnabled = _cfgCommon.HotkeyEnabled;
890 SettingDialog.HotkeyMod = _cfgCommon.HotkeyModifier;
891 SettingDialog.HotkeyKey = _cfgCommon.HotkeyKey;
892 SettingDialog.HotkeyValue = _cfgCommon.HotkeyValue;
894 SettingDialog.BlinkNewMentions = _cfgCommon.BlinkNewMentions;
896 SettingDialog.UseAdditionalCount = _cfgCommon.UseAdditionalCount;
897 SettingDialog.MoreCountApi = _cfgCommon.MoreCountApi;
898 SettingDialog.FirstCountApi = _cfgCommon.FirstCountApi;
899 SettingDialog.SearchCountApi = _cfgCommon.SearchCountApi;
900 SettingDialog.FavoritesCountApi = _cfgCommon.FavoritesCountApi;
901 SettingDialog.UserTimelineCountApi = _cfgCommon.UserTimelineCountApi;
902 SettingDialog.ListCountApi = _cfgCommon.ListCountApi;
904 SettingDialog.UserstreamStartup = _cfgCommon.UserstreamStartup;
905 SettingDialog.UserstreamPeriodInt = _cfgCommon.UserstreamPeriod;
906 SettingDialog.OpenUserTimeline = _cfgCommon.OpenUserTimeline;
907 SettingDialog.ListDoubleClickAction = _cfgCommon.ListDoubleClickAction;
908 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
909 SettingDialog.HideDuplicatedRetweets = _cfgCommon.HideDuplicatedRetweets;
911 SettingDialog.EnableImgAzyobuziNet = _cfgCommon.EnableImgAzyobuziNet;
912 SettingDialog.ImgAzyobuziNetDisabledInDM = _cfgCommon.ImgAzyobuziNetDisabledInDM;
913 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
914 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
915 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
916 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
917 SettingDialog.IsListStatusesIncludeRts = _cfgCommon.IsListsIncludeRts;
918 SettingDialog.TabMouseLock = _cfgCommon.TabMouseLock;
919 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
920 SettingDialog.IsNotifyUseGrowl = _cfgCommon.IsUseNotifyGrowl;
923 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
924 HashMgr = new HashtagManage(HashSupl,
925 _cfgCommon.HashTags.ToArray(),
926 _cfgCommon.HashSelected,
927 _cfgCommon.HashIsPermanent,
928 _cfgCommon.HashIsHead,
929 _cfgCommon.HashIsNotAddToAtReply);
930 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
934 Networking.Initialize();
937 this.IconCache = new ImageCache();
939 bool saveRequired = false;
940 bool firstRun = false;
942 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
943 if (string.IsNullOrEmpty(tw.Username))
947 SettingDialog.ShowInTaskbar = true;
949 //設定せずにキャンセルされた場合はプログラム終了
950 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
952 Application.Exit(); //強制終了
955 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
956 if (string.IsNullOrEmpty(tw.Username))
958 Application.Exit(); //強制終了
961 SettingDialog.ShowInTaskbar = false;
965 _fntUnread = SettingDialog.FontUnread;
966 _clUnread = SettingDialog.ColorUnread;
967 _fntReaded = SettingDialog.FontReaded;
968 _clReaded = SettingDialog.ColorReaded;
969 _clFav = SettingDialog.ColorFav;
970 _clOWL = SettingDialog.ColorOWL;
971 _clRetweet = SettingDialog.ColorRetweet;
972 _fntDetail = SettingDialog.FontDetail;
973 _clDetail = SettingDialog.ColorDetail;
974 _clDetailLink = SettingDialog.ColorDetailLink;
975 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
976 _clSelf = SettingDialog.ColorSelf;
977 _clAtSelf = SettingDialog.ColorAtSelf;
978 _clTarget = SettingDialog.ColorTarget;
979 _clAtTarget = SettingDialog.ColorAtTarget;
980 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
981 _clAtTo = SettingDialog.ColorAtTo;
982 _clListBackcolor = SettingDialog.ColorListBackcolor;
983 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
984 _clInputFont = SettingDialog.ColorInputFont;
985 _fntInputFont = SettingDialog.FontInputFont;
987 //他の設定項目は、随時設定画面で保持している値を読み出して使用
990 _brsBackColorMine = new SolidBrush(_clSelf);
991 _brsBackColorAt = new SolidBrush(_clAtSelf);
992 _brsBackColorYou = new SolidBrush(_clTarget);
993 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
994 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
995 _brsBackColorAtTo = new SolidBrush(_clAtTo);
996 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
997 _brsBackColorNone = new SolidBrush(_clListBackcolor);
999 InitDetailHtmlFormat();
1001 if (SettingDialog.HotkeyEnabled)
1004 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
1005 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
1006 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
1007 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
1008 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
1010 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
1014 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
1015 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
1016 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
1017 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
1019 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
1020 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
1021 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
1022 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
1023 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
1024 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
1025 tw.TrackWord = _cfgCommon.TrackWord;
1026 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
1027 tw.AllAtReply = _cfgCommon.AllAtReply;
1028 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
1031 ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
1034 this.ClientSize = _cfgLocal.FormSize;
1035 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1036 _myLoc = _cfgLocal.FormLocation;
1038 if (this.WindowState != FormWindowState.Minimized)
1040 this.DesktopLocation = _cfgLocal.FormLocation;
1041 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
1042 bool outOfScreen = true;
1043 if (Screen.AllScreens.Length == 1) //ハングするとの報告
1045 foreach (Screen scr in Screen.AllScreens)
1047 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1049 outOfScreen = false;
1055 this.DesktopLocation = new Point(0, 0);
1056 _myLoc = this.DesktopLocation;
1060 this.TopMost = SettingDialog.AlwaysTop;
1061 _mySpDis = _cfgLocal.SplitterDistance;
1062 _mySpDis2 = _cfgLocal.StatusTextHeight;
1063 _mySpDis3 = _cfgLocal.PreviewDistance;
1064 if (_mySpDis3 == -1)
1066 _mySpDis3 = _mySize.Width - 150;
1067 if (_mySpDis3 < 1) _mySpDis3 = 50;
1068 _cfgLocal.PreviewDistance = _mySpDis3;
1070 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
1071 //this.Tween_ClientSizeChanged(this, null);
1072 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
1073 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
1075 StatusText.Font = _fntInputFont;
1076 StatusText.ForeColor = _clInputFont;
1078 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
1079 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
1081 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
1082 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
1084 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1085 if (SettingDialog.UnreadManage == false)
1087 ReadedStripMenuItem.Enabled = false;
1088 UnreadStripMenuItem.Enabled = false;
1091 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
1094 TimerTimeline.AutoReset = true;
1095 TimerTimeline.SynchronizingObject = this;
1097 TimerTimeline.Interval = 1000;
1098 TimerTimeline.Enabled = true;
1101 TimerRefreshIcon.Interval = 200;
1102 TimerRefreshIcon.Enabled = true;
1105 StatusLabel.Text = "";
1106 StatusLabel.AutoToolTip = false;
1107 StatusLabel.ToolTipText = "";
1109 lblLen.Text = GetRestStatusCount(true, false).ToString();
1111 ////////////////////////////////////////////////////////////////////////////////
1112 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1113 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1114 switch (_cfgCommon.SortColumn)
1116 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1120 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1123 mode = IdComparerClass.ComparerMode.Nickname;
1126 mode = IdComparerClass.ComparerMode.Data;
1129 mode = IdComparerClass.ComparerMode.Id;
1132 mode = IdComparerClass.ComparerMode.Name;
1135 mode = IdComparerClass.ComparerMode.Source;
1138 _statuses.SortMode = mode;
1139 ////////////////////////////////////////////////////////////////////////////////
1141 ApplyListViewIconSize(SettingDialog.IconSz);
1143 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1144 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1145 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1146 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1147 SourceLinkLabel.Text = ""; //Source部分初期化
1149 //<<<<<<<<タブ関連>>>>>>>
1150 //デフォルトタブの存在チェック、ない場合には追加
1151 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1154 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1156 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1160 tab.TabType = MyCommon.TabUsageType.Home;
1163 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1166 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1168 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1172 tab.TabType = MyCommon.TabUsageType.Mentions;
1175 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1178 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1180 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1184 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1187 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1190 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1192 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1196 tab.TabType = MyCommon.TabUsageType.Favorites;
1199 foreach (var tab in _statuses.Tabs.Values)
1201 if (tab.TabType == MyCommon.TabUsageType.Undefined)
1203 tab.TabType = MyCommon.TabUsageType.UserDefined;
1205 if (!AddNewTab(tab.TabName, true, tab.TabType, tab.ListInfo))
1206 throw new TabException(Properties.Resources.TweenMain_LoadText1);
1209 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1210 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1211 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1212 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1214 if (SettingDialog.MinimizeToTray == false || this.WindowState != FormWindowState.Minimized)
1216 this.Visible = true;
1218 _curTab = ListTab.SelectedTab;
1220 _curList = (DetailsListView)_curTab.Tag;
1221 SetMainWindowTitle();
1222 SetNotifyIconText();
1224 if (SettingDialog.TabIconDisp)
1226 ListTab.DrawMode = TabDrawMode.Normal;
1230 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1231 ListTab.DrawItem += ListTab_DrawItem;
1232 ListTab.ImageList = null;
1235 _ignoreConfigSave = false;
1236 this.TweenMain_Resize(null, null);
1237 if (saveRequired) SaveConfigsAll(false);
1241 tw.VerifyCredentials();
1242 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1244 if (ua.Username.ToLower() == tw.Username.ToLower())
1246 ua.UserId = tw.UserId;
1251 foreach (UserAccount ua in SettingDialog.UserAccounts)
1253 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1255 ua.UserId = tw.UserId;
1262 // 初回起動時だけ右下のメニューを目立たせる
1263 HashStripSplitButton.ShowDropDown();
1270 private void InitDetailHtmlFormat()
1272 if (SettingDialog.IsMonospace)
1274 detailHtmlFormatHeader = detailHtmlFormatMono1;
1275 detailHtmlFormatFooter = detailHtmlFormatMono7;
1279 detailHtmlFormatHeader = detailHtmlFormat1;
1280 detailHtmlFormatFooter = detailHtmlFormat7;
1282 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();
1283 if (SettingDialog.IsMonospace)
1285 detailHtmlFormatHeader += detailHtmlFormatMono6;
1289 detailHtmlFormatHeader += detailHtmlFormat6;
1293 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1298 txt = ListTab.TabPages[e.Index].Text;
1305 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1306 if (e.State == DrawItemState.Selected)
1308 e.DrawFocusRectangle();
1313 if (_statuses.Tabs[txt].UnreadCount > 0)
1316 fore = System.Drawing.SystemBrushes.ControlText;
1320 fore = System.Drawing.SystemBrushes.ControlText;
1322 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1325 private void LoadConfig()
1327 _cfgCommon = SettingCommon.Load();
1328 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1330 _cfgCommon.UserAccounts = new List<UserAccount>();
1331 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1333 UserAccount account = new UserAccount();
1334 account.Username = _cfgCommon.UserName;
1335 account.UserId = _cfgCommon.UserId;
1336 account.Token = _cfgCommon.Token;
1337 account.TokenSecret = _cfgCommon.TokenSecret;
1339 _cfgCommon.UserAccounts.Add(account);
1342 _cfgLocal = SettingLocal.Load();
1343 List<TabClass> tabs = SettingTabs.Load().Tabs;
1344 foreach (TabClass tb in tabs)
1348 _statuses.Tabs.Add(tb.TabName, tb);
1352 tb.TabName = _statuses.GetUniqueTabName();
1353 _statuses.Tabs.Add(tb.TabName, tb);
1356 if (_statuses.Tabs.Count == 0)
1358 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1359 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1360 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1361 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1365 private void TimerInterval_Changed(object sender, AppendSettingDialog.IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1367 if (!TimerTimeline.Enabled) return;
1371 private AppendSettingDialog.IntervalChangedEventArgs ResetTimers = new AppendSettingDialog.IntervalChangedEventArgs();
1373 private static int homeCounter = 0;
1374 private static int mentionCounter = 0;
1375 private static int dmCounter = 0;
1376 private static int pubSearchCounter = 0;
1377 private static int userTimelineCounter = 0;
1378 private static int listsCounter = 0;
1379 private static int usCounter = 0;
1380 private static int ResumeWait = 0;
1381 private static int refreshFollowers = 0;
1383 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1385 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1386 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1387 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1388 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1389 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1390 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1391 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1392 Interlocked.Increment(ref refreshFollowers);
1395 if (ResetTimers.Timeline || homeCounter <= 0 && SettingDialog.TimelinePeriodInt > 0)
1397 Interlocked.Exchange(ref homeCounter, SettingDialog.TimelinePeriodInt);
1398 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1399 ResetTimers.Timeline = false;
1401 if (ResetTimers.Reply || mentionCounter <= 0 && SettingDialog.ReplyPeriodInt > 0)
1403 Interlocked.Exchange(ref mentionCounter, SettingDialog.ReplyPeriodInt);
1404 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1405 ResetTimers.Reply = false;
1407 if (ResetTimers.DirectMessage || dmCounter <= 0 && SettingDialog.DMPeriodInt > 0)
1409 Interlocked.Exchange(ref dmCounter, SettingDialog.DMPeriodInt);
1410 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1411 ResetTimers.DirectMessage = false;
1413 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && SettingDialog.PubSearchPeriodInt > 0)
1415 Interlocked.Exchange(ref pubSearchCounter, SettingDialog.PubSearchPeriodInt);
1416 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1417 ResetTimers.PublicSearch = false;
1419 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && SettingDialog.UserTimelinePeriodInt > 0)
1421 Interlocked.Exchange(ref userTimelineCounter, SettingDialog.UserTimelinePeriodInt);
1422 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1423 ResetTimers.UserTimeline = false;
1425 if (ResetTimers.Lists || listsCounter <= 0 && SettingDialog.ListsPeriodInt > 0)
1427 Interlocked.Exchange(ref listsCounter, SettingDialog.ListsPeriodInt);
1428 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1429 ResetTimers.Lists = false;
1431 if (ResetTimers.UserStream || usCounter <= 0 && SettingDialog.UserstreamPeriodInt > 0)
1433 Interlocked.Exchange(ref usCounter, SettingDialog.UserstreamPeriodInt);
1434 if (this._isActiveUserstream) RefreshTimeline(true);
1435 ResetTimers.UserStream = false;
1437 if (refreshFollowers > 6 * 3600)
1439 Interlocked.Exchange(ref refreshFollowers, 0);
1440 doGetFollowersMenu();
1441 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
1442 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1446 Interlocked.Increment(ref ResumeWait);
1447 if (ResumeWait > 30)
1450 Interlocked.Exchange(ref ResumeWait, 0);
1451 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1452 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1453 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1454 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1455 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1456 GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1457 doGetFollowersMenu();
1458 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1463 private void RefreshTimeline(bool isUserStream)
1465 if (isUserStream) this.RefreshTasktrayIcon(true);
1467 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1468 long topId = GetScrollPos(ref smode);
1469 int befCnt = _curList.VirtualListSize;
1472 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1473 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
1474 SaveSelectedStatus(selId, focusedId);
1477 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1480 PostClass[] notifyPosts = null;
1481 string soundFile = "";
1483 bool isMention = false;
1484 bool isDelete = false;
1485 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1487 if (MyCommon._endingFlag) return;
1492 foreach (TabPage tab in ListTab.TabPages)
1494 DetailsListView lst = (DetailsListView)tab.Tag;
1495 TabClass tabInfo = _statuses.Tabs[tab.Text];
1496 using (ControlTransaction.Update(lst))
1498 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1500 if (lst.Equals(_curList))
1502 this.PurgeListViewItemCache();
1506 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1512 this.SelectListItem(lst,
1513 tabInfo.IndexOf(selId[tab.Text]),
1514 tabInfo.IndexOf(focusedId[tab.Text]));
1517 if (tabInfo.UnreadCount > 0)
1518 if (SettingDialog.TabIconDisp)
1519 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1521 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
1525 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1534 if (befCnt != _curList.VirtualListSize)
1540 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1544 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1551 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1553 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1554 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1560 catch (Exception ex)
1562 ex.Data["Msg"] = "Ref2";
1568 NotifyNewPosts(notifyPosts,
1571 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1573 SetMainWindowTitle();
1574 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1576 HashSupl.AddRangeItem(tw.GetHashList());
1580 private long GetScrollPos(ref int smode)
1583 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1585 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1587 if (_statuses.SortOrder == SortOrder.Ascending)
1590 if (ListLockMenuItem.Checked)
1595 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1600 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1602 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1603 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1604 if (_item.Index == _curList.VirtualListSize - 1)
1611 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1619 if (ListLockMenuItem.Checked)
1622 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1627 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1630 _item = _curList.GetItemAt(0, 10); //一番上
1631 if (_item == null) _item = _curList.Items[0];
1632 if (_item.Index == 0)
1638 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1647 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1658 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long[]> focusedId)
1660 if (MyCommon._endingFlag) return;
1661 foreach (TabPage tab in ListTab.TabPages)
1663 var lst = (DetailsListView)tab.Tag;
1664 var tabInfo = _statuses.Tabs[tab.Text];
1665 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1667 selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
1671 selId.Add(tab.Text, new long[1] {-2});
1674 var fIds = new long[2]; // 0 = focus, 1 = selection mark
1675 var item = lst.FocusedItem;
1676 fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
1677 var mIdx = lst.SelectionMark;
1678 fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
1679 focusedId.Add(tab.Text, fIds);
1684 private bool BalloonRequired()
1686 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1687 ev.Eventtype = MyCommon.EVENTTYPE.None;
1689 return BalloonRequired(ev);
1692 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1694 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1697 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1699 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1702 private bool BalloonRequired(Twitter.FormattedEvent ev)
1705 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1706 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1710 SettingDialog.LimitBalloon &&
1712 this.WindowState == FormWindowState.Minimized ||
1714 Form.ActiveForm == null
1717 !SettingDialog.LimitBalloon
1720 !NativeMethods.IsScreenSaverRunning())
1730 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1732 if (notifyPosts != null &&
1733 notifyPosts.Length > 0 &&
1734 this.SettingDialog.ReadOwnPost &&
1735 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1741 if (BalloonRequired())
1743 if (notifyPosts != null && notifyPosts.Length > 0)
1745 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1746 if (SettingDialog.IsNotifyUseGrowl)
1748 StringBuilder sb = new StringBuilder();
1752 foreach (PostClass post in notifyPosts)
1754 if (!(notifyPosts.Length > 3))
1760 if (post.IsReply && !post.IsExcludeReply) reply = true;
1761 if (post.IsDm) dm = true;
1762 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1763 switch (SettingDialog.NameBalloon)
1765 case MyCommon.NameBalloonEnum.UserID:
1766 sb.Append(post.ScreenName).Append(" : ");
1768 case MyCommon.NameBalloonEnum.NickName:
1769 sb.Append(post.Nickname).Append(" : ");
1772 sb.Append(post.TextFromApi);
1773 if (notifyPosts.Length > 3)
1775 if (notifyPosts.Last() != post) continue;
1778 StringBuilder title = new StringBuilder();
1779 GrowlHelper.NotifyType nt;
1780 if (SettingDialog.DispUsername)
1782 title.Append(tw.Username);
1783 title.Append(" - ");
1791 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1792 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1793 title.Append(Application.ProductName);
1794 title.Append(" [DM] ");
1795 title.Append(Properties.Resources.RefreshDirectMessageText1);
1797 title.Append(addCount);
1798 title.Append(Properties.Resources.RefreshDirectMessageText2);
1799 nt = GrowlHelper.NotifyType.DirectMessage;
1803 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1804 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1805 title.Append(Application.ProductName);
1806 title.Append(" [Reply!] ");
1807 title.Append(Properties.Resources.RefreshTimelineText1);
1809 title.Append(addCount);
1810 title.Append(Properties.Resources.RefreshTimelineText2);
1811 nt = GrowlHelper.NotifyType.Reply;
1815 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1816 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1817 title.Append(Application.ProductName);
1819 title.Append(Properties.Resources.RefreshTimelineText1);
1821 title.Append(addCount);
1822 title.Append(Properties.Resources.RefreshTimelineText2);
1823 nt = GrowlHelper.NotifyType.Notify;
1825 string bText = sb.ToString();
1826 if (string.IsNullOrEmpty(bText)) return;
1828 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1829 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1834 StringBuilder sb = new StringBuilder();
1837 foreach (PostClass post in notifyPosts)
1839 if (post.IsReply && !post.IsExcludeReply) reply = true;
1840 if (post.IsDm) dm = true;
1841 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1842 switch (SettingDialog.NameBalloon)
1844 case MyCommon.NameBalloonEnum.UserID:
1845 sb.Append(post.ScreenName).Append(" : ");
1847 case MyCommon.NameBalloonEnum.NickName:
1848 sb.Append(post.Nickname).Append(" : ");
1851 sb.Append(post.TextFromApi);
1854 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1855 StringBuilder title = new StringBuilder();
1857 if (SettingDialog.DispUsername)
1859 title.Append(tw.Username);
1860 title.Append(" - ");
1868 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1869 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1870 ntIcon = ToolTipIcon.Warning;
1871 title.Append(Application.ProductName);
1872 title.Append(" [DM] ");
1873 title.Append(Properties.Resources.RefreshDirectMessageText1);
1875 title.Append(addCount);
1876 title.Append(Properties.Resources.RefreshDirectMessageText2);
1880 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1881 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1882 ntIcon = ToolTipIcon.Warning;
1883 title.Append(Application.ProductName);
1884 title.Append(" [Reply!] ");
1885 title.Append(Properties.Resources.RefreshTimelineText1);
1887 title.Append(addCount);
1888 title.Append(Properties.Resources.RefreshTimelineText2);
1892 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1893 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1894 ntIcon = ToolTipIcon.Info;
1895 title.Append(Application.ProductName);
1897 title.Append(Properties.Resources.RefreshTimelineText1);
1899 title.Append(addCount);
1900 title.Append(Properties.Resources.RefreshTimelineText2);
1902 string bText = sb.ToString();
1903 if (string.IsNullOrEmpty(bText)) return;
1904 //NotifyIcon1.BalloonTipText = sb.ToString();
1905 //NotifyIcon1.ShowBalloonTip(500);
1906 NotifyIcon1.BalloonTipTitle = title.ToString();
1907 NotifyIcon1.BalloonTipText = bText;
1908 NotifyIcon1.BalloonTipIcon = ntIcon;
1909 NotifyIcon1.ShowBalloonTip(500);
1915 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(soundFile))
1919 string dir = Application.StartupPath;
1920 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1922 dir = Path.Combine(dir, "Sounds");
1924 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1934 //mentions新着時に画面ブリンク
1935 if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1937 NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
1941 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1943 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1945 _curItemIndex = _curList.SelectedIndices[0];
1946 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1950 _curPost = GetCurTabPost(_curItemIndex);
1952 catch (ArgumentException)
1957 this.PushSelectPostChain();
1959 if (SettingDialog.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
1961 ChangeCacheStyleRead(true, _curItemIndex); //既読へ(フォント、文字色)
1967 private void ChangeCacheStyleRead(bool Read, int Index)
1969 var tabInfo = _statuses.Tabs[_curTab.Text];
1970 //Read:true=既読 false=未読
1971 //未読管理していなかったら既読として扱う
1972 if (!tabInfo.UnreadManage ||
1973 !SettingDialog.UnreadManage) Read = true;
1976 ListViewItem itm = null;
1977 PostClass post = null;
1979 this.TryGetListViewItemCache(Index, out itm, out post);
1981 if (itm == null || post == null)
1983 itm = ((DetailsListView)_curTab.Tag).Items[Index];
1984 post = tabInfo[Index];
1987 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
1990 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
1997 Item.SubItems[5].Text = "";
2002 Item.SubItems[5].Text = "★";
2008 else if (Post.RetweetedId != null)
2010 else if (Post.IsOwl && (Post.IsDm || SettingDialog.OneWayLove))
2012 else if (Read || !SettingDialog.UseUnreadStyle)
2017 if (DList == null || Item.Index == -1)
2019 Item.ForeColor = cl;
2020 if (SettingDialog.UseUnreadStyle)
2026 if (SettingDialog.UseUnreadStyle)
2027 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
2029 DList.ChangeItemForeColor(Item.Index, cl);
2030 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
2034 private void ColorizeList()
2036 //Index:更新対象のListviewItem.Index。Colorを返す。
2037 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2040 _post = _anchorPost;
2044 if (_post == null) return;
2046 var itemColors = new Color[] { };
2049 this.itemCacheLock.EnterReadLock();
2052 if (this._itemCache == null) return;
2055 from i in Enumerable.Range(0, this._itemCache.Length)
2056 select this.JudgeColor(_post, this._postCache[i]);
2058 itemColors = query.ToArray();
2059 itemIndex = _itemCacheIndex;
2061 finally { this.itemCacheLock.ExitReadLock(); }
2063 if (itemIndex < 0) return;
2065 foreach (var backColor in itemColors)
2067 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
2068 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
2069 _curList.ChangeItemBackColor(itemIndex++, backColor);
2073 private void ColorizeList(ListViewItem Item, int Index)
2075 //Index:更新対象のListviewItem.Index。Colorを返す。
2076 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2079 _post = _anchorPost;
2083 PostClass tPost = GetCurTabPost(Index);
2085 if (_post == null) return;
2087 if (Item.Index == -1)
2088 Item.BackColor = JudgeColor(_post, tPost);
2090 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
2093 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
2096 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
2099 else if (TargetPost.IsMe)
2102 else if (TargetPost.IsReply)
2105 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2107 cl = _clAtFromTarget;
2108 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2111 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2116 cl = _clListBackcolor;
2121 private async void PostButton_Click(object sender, EventArgs e)
2123 if (StatusText.Text.Trim().Length == 0)
2125 if (!ImageSelector.Enabled)
2132 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2134 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2136 MessageBoxButtons.YesNoCancel,
2137 MessageBoxIcon.Question);
2140 case DialogResult.Yes:
2141 doReTweetOfficial(false);
2142 StatusText.Text = "";
2144 case DialogResult.Cancel:
2149 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2151 if (SettingDialog.Nicoms)
2153 StatusText.SelectionStart = StatusText.Text.Length;
2154 await UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2156 //if (SettingDialog.UrlConvertAuto)
2158 // StatusText.SelectionStart = StatusText.Text.Length;
2159 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2161 //else if (SettingDialog.Nicoms)
2163 // StatusText.SelectionStart = StatusText.Text.Length;
2164 // UrlConvert(UrlConverter.Nicoms);
2166 StatusText.SelectionStart = StatusText.Text.Length;
2167 GetWorkerArg args = new GetWorkerArg();
2169 args.type = MyCommon.WORKERTYPE.PostMessage;
2170 CheckReplyTo(StatusText.Text);
2173 int adjustCount = 0;
2174 string tmpStatus = StatusText.Text.Trim();
2175 if (ToolStripMenuItemApiCommandEvasion.Checked)
2178 if (Regex.IsMatch(tmpStatus,
2179 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2180 RegexOptions.IgnoreCase)
2181 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2184 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2187 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2190 bool isCutOff = false;
2191 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2192 if (StatusText.Multiline && !SettingDialog.PostCtrlEnter)
2194 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2195 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2197 if (SettingDialog.PostShiftEnter)
2199 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2201 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2203 isRemoveFooter = true;
2205 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2207 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2210 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2211 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2213 isRemoveFooter = true;
2224 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2232 if (HashMgr.IsNotAddToAtReply)
2234 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2237 header = HashMgr.UseHash + " ";
2239 footer = " " + HashMgr.UseHash;
2244 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2247 header = HashMgr.UseHash + " ";
2249 footer = " " + HashMgr.UseHash;
2252 if (!isRemoveFooter)
2254 if (SettingDialog.UseRecommendStatus)
2256 footer += SettingDialog.RecommendStatusText;
2258 // テキストボックスに入力されている文字列を使用する
2259 footer += " " + SettingDialog.Status.Trim();
2262 args.status.status = header + StatusText.Text + footer;
2264 if (ToolStripMenuItemApiCommandEvasion.Checked)
2267 if (Regex.IsMatch(args.status.status,
2268 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2269 RegexOptions.IgnoreCase)
2270 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2273 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2276 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2277 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2280 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2282 // 文中の全角スペースを半角スペース1個にする
2283 args.status.status = args.status.status.Replace(" ", " ");
2286 if (isCutOff && args.status.status.Length > 140)
2288 args.status.status = args.status.status.Substring(0, 140);
2289 string AtId = @"(@|@)[a-z0-9_/]+$";
2290 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2291 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2292 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2293 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2296 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2297 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2299 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2302 args.status.inReplyToId = _reply_to_id;
2303 args.status.inReplyToName = _reply_to_name;
2304 if (ImageSelector.Visible)
2307 if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
2313 _reply_to_id = null;
2314 _reply_to_name = null;
2315 StatusText.Text = "";
2316 _history.Add(new PostingStatus());
2317 _hisIdx = _history.Count - 1;
2318 if (!ToolStripFocusLockMenuItem.Checked)
2319 ((Control)ListTab.SelectedTab.Tag).Focus();
2320 urlUndoBuffer = null;
2321 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2324 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2326 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2327 await this.OpenUriAsync(tmp);
2331 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2333 MyCommon._endingFlag = true;
2337 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2339 if (!SettingDialog.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2341 //_endingFlag=false:フォームの×ボタン
2343 this.Visible = false;
2347 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2348 _ignoreConfigSave = true;
2349 MyCommon._endingFlag = true;
2350 TimerTimeline.Enabled = false;
2351 TimerRefreshIcon.Enabled = false;
2355 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2357 this.Visible = true;
2358 if (this.WindowState == FormWindowState.Minimized)
2360 this.WindowState = FormWindowState.Normal;
2363 this.BringToFront();
2366 private static int errorCount = 0;
2368 private static bool CheckAccountValid()
2370 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2376 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2385 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2387 BackgroundWorker bw = (BackgroundWorker)sender;
2388 if (bw.CancellationPending || MyCommon._endingFlag)
2394 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2396 MyApplication.InitCulture();
2399 GetWorkerResult rslt = new GetWorkerResult();
2401 bool read = !SettingDialog.UnreadManage;
2402 if (_initial && SettingDialog.UnreadManage) read = SettingDialog.Readed;
2404 GetWorkerArg args = (GetWorkerArg)e.Argument;
2406 if (!CheckAccountValid())
2408 rslt.retMsg = "Auth error. Check your account";
2409 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2410 rslt.tName = args.tName;
2415 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2419 case MyCommon.WORKERTYPE.Timeline:
2420 case MyCommon.WORKERTYPE.Reply:
2421 bw.ReportProgress(50, MakeStatusMessage(args, false));
2422 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2424 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && SettingDialog.ReadOldPosts)
2425 _statuses.SetRead();
2427 rslt.addCount = _statuses.DistributePosts();
2429 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2430 bw.ReportProgress(50, MakeStatusMessage(args, false));
2431 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2432 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2433 rslt.addCount = _statuses.DistributePosts();
2436 case MyCommon.WORKERTYPE.FavAdd:
2440 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2442 for (int i = 0; i <= args.ids.Count - 1; i++)
2444 var post = tab.Posts[args.ids[i]];
2447 bw.ReportProgress(50, MakeStatusMessage(args, false));
2450 if (post.RetweetedId == null)
2451 ret = tw.PostFavAdd(post.StatusId);
2453 ret = tw.PostFavAdd(post.RetweetedId.Value);
2455 if (ret.Length == 0)
2457 args.sIds.Add(post.StatusId);
2458 post.IsFav = true; //リスト再描画必要
2459 _favTimestamps.Add(DateTime.Now);
2460 if (string.IsNullOrEmpty(post.RelTabName))
2462 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2463 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2467 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2468 if (_statuses.ContainsKey(post.StatusId))
2470 PostClass postTl = _statuses[post.StatusId];
2471 postTl.IsFav = true;
2472 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2475 //検索,リスト,UserTimeline,Relatedの各タブに反映
2476 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2478 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2484 rslt.sIds = args.sIds;
2488 case MyCommon.WORKERTYPE.FavRemove:
2492 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2494 for (int i = 0; i <= args.ids.Count - 1; i++)
2496 var post = tab.Posts[args.ids[i]];
2499 bw.ReportProgress(50, MakeStatusMessage(args, false));
2502 if (post.RetweetedId == null)
2503 ret = tw.PostFavRemove(post.StatusId);
2505 ret = tw.PostFavRemove(post.RetweetedId.Value);
2507 if (ret.Length == 0)
2509 args.sIds.Add(post.StatusId);
2510 post.IsFav = false; //リスト再描画必要
2511 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2512 //検索,リスト,UserTimeline,Relatedの各タブに反映
2513 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2515 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2521 rslt.sIds = args.sIds;
2525 case MyCommon.WORKERTYPE.PostMessage:
2526 bw.ReportProgress(200);
2527 if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
2529 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2533 var service = ImageSelector.GetService(args.status.imageService);
2536 service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
2539 catch (AggregateException ex)
2541 ret = ex.InnerException.Message;
2544 bw.ReportProgress(300);
2545 rslt.status = args.status;
2547 case MyCommon.WORKERTYPE.Retweet:
2548 bw.ReportProgress(200);
2549 for (int i = 0; i <= args.ids.Count - 1; i++)
2551 ret = tw.PostRetweet(args.ids[i], read);
2553 bw.ReportProgress(300);
2555 case MyCommon.WORKERTYPE.Follower:
2556 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2559 tw.RefreshFollowerIds();
2561 catch (WebApiException ex) { ret = ex.Message; }
2563 case MyCommon.WORKERTYPE.NoRetweetIds:
2566 tw.RefreshNoRetweetIds();
2568 catch (WebApiException ex) { ret = ex.Message; }
2570 case MyCommon.WORKERTYPE.Configuration:
2573 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2575 catch (WebApiException ex) { ret = ex.Message; }
2577 case MyCommon.WORKERTYPE.Favorites:
2578 bw.ReportProgress(50, MakeStatusMessage(args, false));
2579 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2580 rslt.addCount = _statuses.DistributePosts();
2582 case MyCommon.WORKERTYPE.PublicSearch:
2583 bw.ReportProgress(50, MakeStatusMessage(args, false));
2584 if (string.IsNullOrEmpty(args.tName))
2586 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2588 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2589 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2594 TabClass tb = _statuses.GetTabByName(args.tName);
2597 //ret = tw.GetPhoenixSearch(read, tb, false);
2598 ret = tw.GetSearch(read, tb, false);
2599 if (string.IsNullOrEmpty(ret) && args.page == -1)
2601 //ret = tw.GetPhoenixSearch(read, tb, true)
2602 ret = tw.GetSearch(read, tb, true);
2607 rslt.addCount = _statuses.DistributePosts();
2609 case MyCommon.WORKERTYPE.UserTimeline:
2610 bw.ReportProgress(50, MakeStatusMessage(args, false));
2612 if (SettingDialog.UseAdditionalCount) count = SettingDialog.UserTimelineCountApi;
2613 if (string.IsNullOrEmpty(args.tName))
2615 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2617 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2622 TabClass tb = _statuses.GetTabByName(args.tName);
2625 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2629 rslt.addCount = _statuses.DistributePosts();
2631 case MyCommon.WORKERTYPE.List:
2632 bw.ReportProgress(50, MakeStatusMessage(args, false));
2633 if (string.IsNullOrEmpty(args.tName))
2636 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2638 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2644 TabClass tb = _statuses.GetTabByName(args.tName);
2647 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2651 rslt.addCount = _statuses.DistributePosts();
2654 case MyCommon.WORKERTYPE.Related:
2656 bw.ReportProgress(50, MakeStatusMessage(args, false));
2657 TabClass tab = _statuses.GetTabByName(args.tName);
2658 ret = tw.GetRelatedResult(read, tab);
2659 rslt.addCount = _statuses.DistributePosts();
2663 case MyCommon.WORKERTYPE.BlockIds:
2664 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2667 tw.RefreshBlockIds();
2669 catch (WebApiException ex) { ret = ex.Message; }
2673 if (bw.CancellationPending)
2680 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2682 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2683 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2685 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2687 _favTimestamps.RemoveAt(i);
2691 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2695 DateTime tm = DateTime.Now;
2696 if (_tlTimestamps.ContainsKey(tm))
2697 _tlTimestamps[tm] += rslt.addCount;
2699 _tlTimestamps.Add(tm, rslt.addCount);
2701 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2702 List<DateTime> keys = new List<DateTime>();
2704 foreach (DateTime key in _tlTimestamps.Keys)
2706 if (key.CompareTo(oneHour) < 0)
2712 _tlCount += _tlTimestamps[key];
2715 foreach (DateTime key in keys)
2717 _tlTimestamps.Remove(key);
2724 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2727 rslt.type = args.type;
2728 rslt.tName = args.tName;
2733 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2739 switch (AsyncArg.type)
2741 case MyCommon.WORKERTYPE.Timeline:
2742 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2744 case MyCommon.WORKERTYPE.Reply:
2745 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2747 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2748 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2750 case MyCommon.WORKERTYPE.FavAdd:
2751 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2752 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2754 case MyCommon.WORKERTYPE.FavRemove:
2755 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2756 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2758 case MyCommon.WORKERTYPE.Favorites:
2759 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2761 case MyCommon.WORKERTYPE.PublicSearch:
2762 smsg = "Search refreshing...";
2764 case MyCommon.WORKERTYPE.List:
2765 smsg = "List refreshing...";
2767 case MyCommon.WORKERTYPE.Related:
2768 smsg = "Related refreshing...";
2770 case MyCommon.WORKERTYPE.UserTimeline:
2771 smsg = "UserTimeline refreshing...";
2778 switch (AsyncArg.type)
2780 case MyCommon.WORKERTYPE.Timeline:
2781 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2783 case MyCommon.WORKERTYPE.Reply:
2784 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2786 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2787 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2789 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2790 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2792 case MyCommon.WORKERTYPE.FavAdd:
2795 case MyCommon.WORKERTYPE.FavRemove:
2798 case MyCommon.WORKERTYPE.Favorites:
2799 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2801 case MyCommon.WORKERTYPE.Follower:
2802 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2804 case MyCommon.WORKERTYPE.NoRetweetIds:
2805 smsg = "NoRetweetIds refreshed";
2807 case MyCommon.WORKERTYPE.Configuration:
2810 case MyCommon.WORKERTYPE.PublicSearch:
2811 smsg = "Search refreshed";
2813 case MyCommon.WORKERTYPE.List:
2814 smsg = "List refreshed";
2816 case MyCommon.WORKERTYPE.Related:
2817 smsg = "Related refreshed";
2819 case MyCommon.WORKERTYPE.UserTimeline:
2820 smsg = "UserTimeline refreshed";
2822 case MyCommon.WORKERTYPE.BlockIds:
2823 smsg = Properties.Resources.UpdateBlockUserText3;
2830 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2832 if (MyCommon._endingFlag) return;
2833 if (e.ProgressPercentage > 100)
2836 if (e.ProgressPercentage == 200) //開始
2837 StatusLabel.Text = "Posting...";
2838 if (e.ProgressPercentage == 300) //終了
2839 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2843 string smsg = (string)e.UserState;
2844 if (smsg.Length > 0) StatusLabel.Text = smsg;
2848 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2850 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2852 if (e.Error != null)
2854 _myStatusError = true;
2855 _waitTimeline = false;
2859 _waitPubSearch = false;
2860 _waitUserTimeline = false;
2862 throw new Exception("BackgroundWorker Exception", e.Error);
2865 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2868 if (rslt.retMsg.Length > 0)
2870 _myStatusError = true;
2871 StatusLabel.Text = rslt.retMsg;
2874 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2876 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2878 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2882 //bool busy = false;
2883 //foreach (BackgroundWorker bw in _bw)
2885 // if (bw != null && bw.IsBusy)
2891 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2892 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2893 rslt.type == MyCommon.WORKERTYPE.Reply ||
2894 rslt.type == MyCommon.WORKERTYPE.List ||
2895 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2896 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2897 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2898 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2899 rslt.type == MyCommon.WORKERTYPE.Follower ||
2900 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2901 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2902 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2903 rslt.type == MyCommon.WORKERTYPE.Related ||
2904 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2905 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2906 rslt.type == MyCommon.WORKERTYPE.Configuration)
2908 RefreshTimeline(false); //リスト反映
2913 case MyCommon.WORKERTYPE.Timeline:
2914 _waitTimeline = false;
2917 // //API使用時の取得調整は別途考える(カウント調整?)
2920 case MyCommon.WORKERTYPE.Reply:
2922 if (rslt.newDM && !_initial)
2924 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
2927 case MyCommon.WORKERTYPE.Favorites:
2930 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2933 case MyCommon.WORKERTYPE.FavAdd:
2934 case MyCommon.WORKERTYPE.FavRemove:
2935 if (_curList != null && _curTab != null)
2937 using (ControlTransaction.Update(this._curList))
2939 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
2945 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
2947 if (_curTab.Text.Equals(rslt.tName))
2949 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
2952 PostClass post = null;
2953 TabClass tb = _statuses.Tabs[rslt.tName];
2956 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
2958 post = tb.Posts[rslt.sIds[i]];
2962 post = _statuses[rslt.sIds[i]];
2964 ChangeCacheStyleRead(post.IsRead, idx);
2966 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
2974 case MyCommon.WORKERTYPE.PostMessage:
2975 if (string.IsNullOrEmpty(rslt.retMsg) ||
2976 rslt.retMsg.StartsWith("OK:") ||
2977 rslt.retMsg == "Warn:Status is a duplicate.")
2979 _postTimestamps.Add(DateTime.Now);
2980 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2981 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2983 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2985 _postTimestamps.RemoveAt(i);
2989 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
2991 HashMgr.ClearHashtag();
2992 this.HashStripSplitButton.Text = "#[-]";
2993 this.HashToggleMenuItem.Checked = false;
2994 this.HashToggleToolStripMenuItem.Checked = false;
2996 SetMainWindowTitle();
3004 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
3005 Properties.Resources.StatusUpdateFailed1,
3006 Properties.Resources.StatusUpdateFailed2),
3007 "Failed to update status",
3008 MessageBoxButtons.RetryCancel,
3009 MessageBoxIcon.Question);
3013 retry = DialogResult.Abort;
3015 if (retry == DialogResult.Retry)
3017 GetWorkerArg args = new GetWorkerArg();
3019 args.type = MyCommon.WORKERTYPE.PostMessage;
3020 args.status = rslt.status;
3025 if (ToolStripFocusLockMenuItem.Checked)
3027 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
3028 StatusText_Enter(StatusText, new EventArgs());
3032 if (rslt.retMsg.Length == 0 && SettingDialog.PostAndGet)
3034 if (_isActiveUserstream)
3036 RefreshTimeline(true);
3040 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3044 case MyCommon.WORKERTYPE.Retweet:
3045 if (rslt.retMsg.Length == 0)
3047 _postTimestamps.Add(DateTime.Now);
3048 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3049 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3051 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3053 _postTimestamps.RemoveAt(i);
3056 if (!_isActiveUserstream && SettingDialog.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3059 case MyCommon.WORKERTYPE.Follower:
3060 //_waitFollower = false;
3061 this.PurgeListViewItemCache();
3062 if (_curList != null) _curList.Refresh();
3064 case MyCommon.WORKERTYPE.NoRetweetIds:
3066 case MyCommon.WORKERTYPE.Configuration:
3067 //_waitFollower = false
3068 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
3070 foreach (var service in this.ImageSelector.GetServices())
3072 service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
3075 this.PurgeListViewItemCache();
3076 if (_curList != null) _curList.Refresh();
3078 case MyCommon.WORKERTYPE.PublicSearch:
3079 _waitPubSearch = false;
3081 case MyCommon.WORKERTYPE.UserTimeline:
3082 _waitUserTimeline = false;
3084 case MyCommon.WORKERTYPE.List:
3087 case MyCommon.WORKERTYPE.Related:
3088 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
3089 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
3091 foreach (TabPage tp in ListTab.TabPages)
3093 if (tp.Text == tab.TabName)
3095 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
3096 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3105 private async Task RefreshMuteUserIdsAsync()
3107 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
3111 await tw.RefreshMuteUserIdsAsync();
3113 catch (WebApiException ex)
3115 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
3119 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
3122 private void RemovePostFromFavTab(Int64[] ids)
3124 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3126 if (_curTab.Text.Equals(favTabName))
3128 if (_curList.FocusedItem != null)
3129 fidx = _curList.FocusedItem.Index;
3130 else if (_curList.TopItem != null)
3131 fidx = _curList.TopItem.Index;
3136 foreach (long i in ids)
3140 _statuses.RemoveFavPost(i);
3147 if (_curTab != null && _curTab.Text.Equals(favTabName))
3149 this.PurgeListViewItemCache();
3151 //_curItemIndex = -1;
3153 foreach (TabPage tp in ListTab.TabPages)
3155 if (tp.Text == favTabName)
3157 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3161 if (_curTab.Text.Equals(favTabName))
3165 _curList.SelectedIndices.Clear();
3167 while (_curList.SelectedIndices.Count > 0);
3169 if (_statuses.Tabs[favTabName].AllCount > 0)
3171 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3173 _curList.SelectedIndices.Add(fidx);
3177 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3179 if (_curList.SelectedIndices.Count > 0)
3181 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3182 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3188 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3190 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, string tabName)
3192 if (!this.IsNetworkAvailable()) return;
3195 GetWorkerArg args = new GetWorkerArg();
3196 args.page = fromPage;
3198 args.tName = tabName;
3200 if (!lastTime.ContainsKey(WkType)) lastTime.Add(WkType, new DateTime());
3201 double period = DateTime.Now.Subtract(lastTime[WkType]).TotalSeconds;
3202 if (period > 1 || period < -1)
3204 lastTime[WkType] = DateTime.Now;
3208 //Timeline取得モードの場合はReplyも同時に取得
3209 //if (!SettingDialog.UseAPI &&
3211 // WkType == MyCommon.WORKERTYPE.Timeline &&
3212 // SettingDialog.CheckReply)
3214 // //TimerReply.Enabled = false;
3215 // _mentionCounter = SettingDialog.ReplyPeriodInt;
3216 // GetWorkerArg _args = new GetWorkerArg();
3217 // _args.page = fromPage;
3218 // _args.endPage = toPage;
3219 // _args.type = MyCommon.WORKERTYPE.Reply;
3224 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
3226 if (e.Button == MouseButtons.Left)
3228 this.Visible = true;
3229 if (this.WindowState == FormWindowState.Minimized)
3231 this.WindowState = _formWindowState;
3234 this.BringToFront();
3238 private void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
3240 switch (SettingDialog.ListDoubleClickAction)
3243 MakeReplyOrDirectStatus();
3246 FavoriteChange(true);
3249 if (_curPost != null)
3250 ShowUserStatus(_curPost.ScreenName, false);
3256 ShowRelatedStatusesMenuItem_Click(null, null);
3259 MoveToHomeToolStripMenuItem_Click(null, null);
3262 StatusOpenMenuItem_Click(null, null);
3270 private void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
3272 FavoriteChange(true);
3275 private void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
3277 FavoriteChange(false);
3281 private void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
3283 FavoritesRetweetOriginal();
3286 private void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
3288 FavoritesRetweetUnofficial();
3291 private void FavoriteChange(bool FavAdd , bool multiFavoriteChangeDialogEnable = true)
3293 //trueでFavAdd,falseでFavRemove
3294 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || _curList.SelectedIndices.Count == 0
3295 || !this.ExistCurrentPost) return;
3298 if (_curList.SelectedIndices.Count > 250 && FavAdd)
3300 MessageBox.Show(Properties.Resources.FavoriteLimitCountText);
3301 _DoFavRetweetFlags = false;
3304 else if (multiFavoriteChangeDialogEnable && _curList.SelectedIndices.Count > 1)
3308 string QuestionText = Properties.Resources.FavAddToolStripMenuItem_ClickText1;
3309 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText3;
3310 if (MessageBox.Show(QuestionText, Properties.Resources.FavAddToolStripMenuItem_ClickText2,
3311 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3313 _DoFavRetweetFlags = false;
3319 if (MessageBox.Show(Properties.Resources.FavRemoveToolStripMenuItem_ClickText1, Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
3320 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3327 GetWorkerArg args = new GetWorkerArg();
3328 args.ids = new List<long>();
3329 args.sIds = new List<long>();
3330 args.tName = _curTab.Text;
3333 args.type = MyCommon.WORKERTYPE.FavAdd;
3337 args.type = MyCommon.WORKERTYPE.FavRemove;
3339 foreach (int idx in _curList.SelectedIndices)
3341 PostClass post = GetCurTabPost(idx);
3344 if (!post.IsFav) args.ids.Add(post.StatusId);
3348 if (post.IsFav) args.ids.Add(post.StatusId);
3351 if (args.ids.Count == 0)
3354 StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
3356 StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
3364 private PostClass GetCurTabPost(int Index)
3366 this.itemCacheLock.EnterReadLock();
3369 if (_postCache != null && Index >= _itemCacheIndex && Index < _itemCacheIndex + _postCache.Length)
3370 return _postCache[Index - _itemCacheIndex];
3372 finally { this.itemCacheLock.ExitReadLock(); }
3374 return _statuses[_curTab.Text, Index];
3378 private void MoveToHomeToolStripMenuItem_Click(object sender, EventArgs e)
3380 if (_curList.SelectedIndices.Count > 0)
3381 OpenUriAsync(MyCommon.TwitterUrl + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName);
3382 else if (_curList.SelectedIndices.Count == 0)
3383 OpenUriAsync(MyCommon.TwitterUrl);
3386 private void MoveToFavToolStripMenuItem_Click(object sender, EventArgs e)
3388 if (_curList.SelectedIndices.Count > 0)
3389 OpenUriAsync(MyCommon.TwitterUrl + "#!/" + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName + "/favorites");
3392 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3394 if ((!_initialLayout) && this.Visible)
3396 if (this.WindowState == FormWindowState.Normal)
3398 _mySize = this.ClientSize;
3399 _mySpDis = this.SplitContainer1.SplitterDistance;
3400 _mySpDis3 = this.SplitContainer3.SplitterDistance;
3401 if (StatusText.Multiline) _mySpDis2 = this.StatusText.Height;
3402 _modifySettingLocal = true;
3407 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3409 if (SettingDialog.SortOrderLock) return;
3410 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
3413 mode = IdComparerClass.ComparerMode.Id;
3421 case 6: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
3425 mode = IdComparerClass.ComparerMode.Nickname;
3428 mode = IdComparerClass.ComparerMode.Data;
3431 mode = IdComparerClass.ComparerMode.Id;
3434 mode = IdComparerClass.ComparerMode.Name;
3437 mode = IdComparerClass.ComparerMode.Source;
3441 _statuses.ToggleSortOrder(mode);
3444 DetailsListView list = (DetailsListView)sender;
3447 list.Columns[0].Text = ColumnOrgText[0];
3448 list.Columns[1].Text = ColumnText[2];
3452 for (int i = 0; i <= 7; i++)
3454 list.Columns[i].Text = ColumnOrgText[i];
3456 list.Columns[e.Column].Text = ColumnText[e.Column];
3459 this.PurgeListViewItemCache();
3461 if (_statuses.Tabs[_curTab.Text].AllCount > 0 && _curPost != null)
3463 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_curPost.StatusId);
3466 SelectListItem(_curList, idx);
3467 _curList.EnsureVisible(idx);
3471 _modifySettingCommon = true;
3474 private void TweenMain_LocationChanged(object sender, EventArgs e)
3476 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
3478 _myLoc = this.DesktopLocation;
3479 _modifySettingLocal = true;
3483 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3485 if (ListTab.SelectedTab == null) return;
3486 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
3487 if (!this.ExistCurrentPost)
3489 ReplyStripMenuItem.Enabled = false;
3490 ReplyAllStripMenuItem.Enabled = false;
3491 DMStripMenuItem.Enabled = false;
3492 ShowProfileMenuItem.Enabled = false;
3493 ShowUserTimelineContextMenuItem.Enabled = false;
3494 ListManageUserContextToolStripMenuItem2.Enabled = false;
3495 MoveToFavToolStripMenuItem.Enabled = false;
3496 TabMenuItem.Enabled = false;
3497 IDRuleMenuItem.Enabled = false;
3498 ReadedStripMenuItem.Enabled = false;
3499 UnreadStripMenuItem.Enabled = false;
3503 ShowProfileMenuItem.Enabled = true;
3504 ListManageUserContextToolStripMenuItem2.Enabled = true;
3505 ReplyStripMenuItem.Enabled = true;
3506 ReplyAllStripMenuItem.Enabled = true;
3507 DMStripMenuItem.Enabled = true;
3508 ShowUserTimelineContextMenuItem.Enabled = true;
3509 MoveToFavToolStripMenuItem.Enabled = true;
3510 TabMenuItem.Enabled = true;
3511 IDRuleMenuItem.Enabled = true;
3512 ReadedStripMenuItem.Enabled = true;
3513 UnreadStripMenuItem.Enabled = true;
3515 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3516 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
3518 FavAddToolStripMenuItem.Enabled = false;
3519 FavRemoveToolStripMenuItem.Enabled = false;
3520 StatusOpenMenuItem.Enabled = false;
3521 FavorareMenuItem.Enabled = false;
3522 ShowRelatedStatusesMenuItem.Enabled = false;
3524 ReTweetStripMenuItem.Enabled = false;
3525 ReTweetOriginalStripMenuItem.Enabled = false;
3526 QuoteStripMenuItem.Enabled = false;
3527 FavoriteRetweetContextMenu.Enabled = false;
3528 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3529 if (this.ExistCurrentPost && _curPost.IsDm)
3530 DeleteStripMenuItem.Enabled = true;
3532 DeleteStripMenuItem.Enabled = false;
3536 FavAddToolStripMenuItem.Enabled = true;
3537 FavRemoveToolStripMenuItem.Enabled = true;
3538 StatusOpenMenuItem.Enabled = true;
3539 FavorareMenuItem.Enabled = true;
3540 ShowRelatedStatusesMenuItem.Enabled = true; //PublicSearchの時問題出るかも
3544 ReTweetOriginalStripMenuItem.Enabled = false;
3545 FavoriteRetweetContextMenu.Enabled = false;
3546 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3548 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3552 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3554 DeleteStripMenuItem.Enabled = true;
3558 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3560 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3564 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3566 DeleteStripMenuItem.Enabled = false;
3567 if (_curPost.IsProtect)
3569 ReTweetOriginalStripMenuItem.Enabled = false;
3570 ReTweetStripMenuItem.Enabled = false;
3571 QuoteStripMenuItem.Enabled = false;
3572 FavoriteRetweetContextMenu.Enabled = false;
3573 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3577 ReTweetOriginalStripMenuItem.Enabled = true;
3578 ReTweetStripMenuItem.Enabled = true;
3579 QuoteStripMenuItem.Enabled = true;
3580 FavoriteRetweetContextMenu.Enabled = true;
3581 FavoriteRetweetUnofficialContextMenu.Enabled = true;
3585 //if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
3587 // RefreshMoreStripMenuItem.Enabled = true;
3591 // RefreshMoreStripMenuItem.Enabled = false;
3593 if (!this.ExistCurrentPost
3594 || _curPost.InReplyToStatusId == null)
3596 RepliedStatusOpenMenuItem.Enabled = false;
3600 RepliedStatusOpenMenuItem.Enabled = true;
3602 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
3604 MoveToRTHomeMenuItem.Enabled = false;
3608 MoveToRTHomeMenuItem.Enabled = true;
3612 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3614 MakeReplyOrDirectStatus(false, true);
3617 private void DMStripMenuItem_Click(object sender, EventArgs e)
3619 MakeReplyOrDirectStatus(false, false);
3622 private void doStatusDelete()
3624 if (_curTab == null || _curList == null) return;
3625 if (_statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
3627 bool myPost = false;
3628 foreach (int idx in _curList.SelectedIndices)
3630 if (GetCurTabPost(idx).IsMe ||
3631 GetCurTabPost(idx).RetweetedBy.ToLower() == tw.Username.ToLower())
3637 if (!myPost) return;
3641 if (_curList.SelectedIndices.Count == 0)
3645 string tmp = string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine);
3647 if (MessageBox.Show(tmp, Properties.Resources.DeleteStripMenuItem_ClickText2,
3648 MessageBoxButtons.OKCancel,
3649 MessageBoxIcon.Question) == DialogResult.Cancel) return;
3652 if (_curList.FocusedItem != null)
3653 fidx = _curList.FocusedItem.Index;
3654 else if (_curList.TopItem != null)
3655 fidx = _curList.TopItem.Index;
3661 this.Cursor = Cursors.WaitCursor;
3664 foreach (long Id in _statuses.GetId(_curTab.Text, _curList.SelectedIndices))
3667 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
3669 rtn = tw.RemoveDirectMessage(Id, _statuses[Id]);
3673 if (_statuses[Id].IsMe || _statuses[Id].RetweetedBy.ToLower() == tw.Username.ToLower())
3674 rtn = tw.RemoveStatus(Id);
3685 _statuses.RemovePost(Id);
3690 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; //失敗
3692 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; //成功
3694 this.PurgeListViewItemCache();
3697 foreach (TabPage tb in ListTab.TabPages)
3699 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
3700 if (_curTab.Equals(tb))
3704 _curList.SelectedIndices.Clear();
3706 while (_curList.SelectedIndices.Count > 0);
3708 if (_statuses.Tabs[tb.Text].AllCount > 0)
3710 if (_statuses.Tabs[tb.Text].AllCount - 1 > fidx && fidx > -1)
3711 _curList.SelectedIndices.Add(fidx);
3713 _curList.SelectedIndices.Add(_statuses.Tabs[tb.Text].AllCount - 1);
3715 if (_curList.SelectedIndices.Count > 0)
3717 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3718 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3722 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3724 if (SettingDialog.TabIconDisp)
3726 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3730 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3734 this.Cursor = Cursors.Default;
3738 private void DeleteStripMenuItem_Click(object sender, EventArgs e)
3743 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3745 using (ControlTransaction.Update(this._curList))
3747 if (SettingDialog.UnreadManage)
3749 foreach (int idx in _curList.SelectedIndices)
3751 _statuses.SetReadAllTab(true, _curTab.Text, idx);
3754 foreach (int idx in _curList.SelectedIndices)
3756 ChangeCacheStyleRead(true, idx);
3760 foreach (TabPage tb in ListTab.TabPages)
3762 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3764 if (SettingDialog.TabIconDisp)
3766 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3770 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3773 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3775 using (ControlTransaction.Update(this._curList))
3777 if (SettingDialog.UnreadManage)
3779 foreach (int idx in _curList.SelectedIndices)
3781 _statuses.SetReadAllTab(false, _curTab.Text, idx);
3784 foreach (int idx in _curList.SelectedIndices)
3786 ChangeCacheStyleRead(false, idx);
3790 foreach (TabPage tb in ListTab.TabPages)
3792 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
3794 if (SettingDialog.TabIconDisp)
3796 if (tb.ImageIndex == -1) tb.ImageIndex = 0; //タブアイコン
3800 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3803 private void RefreshStripMenuItem_Click(object sender, EventArgs e)
3808 private void DoRefresh()
3810 if (_curTab != null)
3812 switch (_statuses.Tabs[_curTab.Text].TabType)
3814 case MyCommon.TabUsageType.Mentions:
3815 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
3817 case MyCommon.TabUsageType.DirectMessage:
3818 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
3820 case MyCommon.TabUsageType.Favorites:
3821 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
3823 //case MyCommon.TabUsageType.Profile:
3825 case MyCommon.TabUsageType.PublicSearch:
3827 TabClass tb = _statuses.Tabs[_curTab.Text];
3828 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3829 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, _curTab.Text);
3831 case MyCommon.TabUsageType.UserTimeline:
3832 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, _curTab.Text);
3834 case MyCommon.TabUsageType.Lists:
3836 TabClass tab = _statuses.Tabs[_curTab.Text];
3837 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3838 GetTimeline(MyCommon.WORKERTYPE.List, 1, _curTab.Text);
3841 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3847 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3851 private void DoRefreshMore()
3854 if (_curTab != null)
3856 switch (_statuses.Tabs[_curTab.Text].TabType)
3858 case MyCommon.TabUsageType.Mentions:
3859 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
3861 case MyCommon.TabUsageType.DirectMessage:
3862 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
3864 case MyCommon.TabUsageType.Favorites:
3865 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, "");
3867 case MyCommon.TabUsageType.Profile:
3870 case MyCommon.TabUsageType.PublicSearch:
3872 TabClass tb = _statuses.Tabs[_curTab.Text];
3873 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3874 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, -1, _curTab.Text);
3876 case MyCommon.TabUsageType.UserTimeline:
3877 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, _curTab.Text);
3879 case MyCommon.TabUsageType.Lists:
3881 TabClass tab = _statuses.Tabs[_curTab.Text];
3882 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3883 GetTimeline(MyCommon.WORKERTYPE.List, -1, _curTab.Text);
3886 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3892 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3896 private void SettingStripMenuItem_Click(object sender, EventArgs e)
3898 DialogResult result;
3899 string uid = tw.Username.ToLower();
3900 var oldIconSz = SettingDialog.IconSz;
3904 result = SettingDialog.ShowDialog(this);
3911 if (result == DialogResult.OK)
3915 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
3916 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
3917 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
3918 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
3919 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
3920 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3922 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
3923 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
3924 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
3925 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
3927 ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
3931 if (SettingDialog.TabIconDisp)
3933 ListTab.DrawItem -= ListTab_DrawItem;
3934 ListTab.DrawMode = TabDrawMode.Normal;
3935 ListTab.ImageList = this.TabImage;
3939 ListTab.DrawItem -= ListTab_DrawItem;
3940 ListTab.DrawItem += ListTab_DrawItem;
3941 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3942 ListTab.ImageList = null;
3945 catch (Exception ex)
3947 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3948 ex.Data["IsTerminatePermission"] = false;
3954 if (!SettingDialog.UnreadManage)
3956 ReadedStripMenuItem.Enabled = false;
3957 UnreadStripMenuItem.Enabled = false;
3958 if (SettingDialog.TabIconDisp)
3960 foreach (TabPage myTab in ListTab.TabPages)
3962 myTab.ImageIndex = -1;
3968 ReadedStripMenuItem.Enabled = true;
3969 UnreadStripMenuItem.Enabled = true;
3972 catch (Exception ex)
3974 ex.Data["Instance"] = "ListTab(UnreadManage)";
3975 ex.Data["IsTerminatePermission"] = false;
3982 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
3984 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3985 imgazyobizinet.Enabled = this.SettingDialog.EnableImgAzyobuziNet;
3986 imgazyobizinet.DisabledInDM = this.SettingDialog.ImgAzyobuziNetDisabledInDM;
3988 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
3989 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
3990 _fntUnread = SettingDialog.FontUnread;
3991 _clUnread = SettingDialog.ColorUnread;
3992 _fntReaded = SettingDialog.FontReaded;
3993 _clReaded = SettingDialog.ColorReaded;
3994 _clFav = SettingDialog.ColorFav;
3995 _clOWL = SettingDialog.ColorOWL;
3996 _clRetweet = SettingDialog.ColorRetweet;
3997 _fntDetail = SettingDialog.FontDetail;
3998 _clDetail = SettingDialog.ColorDetail;
3999 _clDetailLink = SettingDialog.ColorDetailLink;
4000 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
4001 _clSelf = SettingDialog.ColorSelf;
4002 _clAtSelf = SettingDialog.ColorAtSelf;
4003 _clTarget = SettingDialog.ColorTarget;
4004 _clAtTarget = SettingDialog.ColorAtTarget;
4005 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
4006 _clAtTo = SettingDialog.ColorAtTo;
4007 _clListBackcolor = SettingDialog.ColorListBackcolor;
4008 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
4009 _clInputFont = SettingDialog.ColorInputFont;
4010 _fntInputFont = SettingDialog.FontInputFont;
4011 _brsBackColorMine.Dispose();
4012 _brsBackColorAt.Dispose();
4013 _brsBackColorYou.Dispose();
4014 _brsBackColorAtYou.Dispose();
4015 _brsBackColorAtFromTarget.Dispose();
4016 _brsBackColorAtTo.Dispose();
4017 _brsBackColorNone.Dispose();
4018 _brsBackColorMine = new SolidBrush(_clSelf);
4019 _brsBackColorAt = new SolidBrush(_clAtSelf);
4020 _brsBackColorYou = new SolidBrush(_clTarget);
4021 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
4022 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
4023 _brsBackColorAtTo = new SolidBrush(_clAtTo);
4024 _brsBackColorNone = new SolidBrush(_clListBackcolor);
4028 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
4029 StatusText.Font = _fntInputFont;
4030 StatusText.ForeColor = _clInputFont;
4032 catch (Exception ex)
4034 MessageBox.Show(ex.Message);
4039 InitDetailHtmlFormat();
4041 catch (Exception ex)
4043 ex.Data["Instance"] = "Font";
4044 ex.Data["IsTerminatePermission"] = false;
4050 _statuses.SetUnreadManage(SettingDialog.UnreadManage);
4052 catch (Exception ex)
4054 ex.Data["Instance"] = "_statuses";
4055 ex.Data["IsTerminatePermission"] = false;
4061 foreach (TabPage tb in ListTab.TabPages)
4063 if (SettingDialog.TabIconDisp)
4065 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
4072 catch (Exception ex)
4074 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
4075 ex.Data["IsTerminatePermission"] = false;
4081 var oldIconCol = _iconCol;
4083 if (SettingDialog.IconSz != oldIconSz)
4084 ApplyListViewIconSize(SettingDialog.IconSz);
4086 foreach (TabPage tp in ListTab.TabPages)
4088 DetailsListView lst = (DetailsListView)tp.Tag;
4090 using (ControlTransaction.Update(lst))
4092 lst.GridLines = SettingDialog.ShowGrid;
4093 lst.Font = _fntReaded;
4094 lst.BackColor = _clListBackcolor;
4096 if (_iconCol != oldIconCol)
4101 catch (Exception ex)
4103 ex.Data["Instance"] = "ListView(IconSize)";
4104 ex.Data["IsTerminatePermission"] = false;
4108 SetMainWindowTitle();
4109 SetNotifyIconText();
4111 this.PurgeListViewItemCache();
4112 if (_curList != null) _curList.Refresh();
4115 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4116 if (SettingDialog.HotkeyEnabled)
4118 ///グローバルホットキーの登録。設定で変更可能にするかも
4119 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4120 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
4121 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
4122 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
4123 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
4125 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
4128 if (uid != tw.Username) this.doGetFollowersMenu();
4130 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
4133 StatusText_TextChanged(null, null);
4141 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4143 this.TopMost = SettingDialog.AlwaysTop;
4144 SaveConfigsAll(false);
4150 private void SetTabAlignment()
4152 var newAlignment = SettingDialog.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
4153 if (ListTab.Alignment == newAlignment) return;
4156 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
4157 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
4158 SaveSelectedStatus(selId, focusedId);
4160 ListTab.Alignment = newAlignment;
4163 foreach (TabPage tab in ListTab.TabPages)
4165 DetailsListView lst = (DetailsListView)tab.Tag;
4166 TabClass tabInfo = _statuses.Tabs[tab.Text];
4167 using (ControlTransaction.Update(lst))
4169 this.SelectListItem(lst,
4170 tabInfo.IndexOf(selId[tab.Text]),
4171 tabInfo.IndexOf(focusedId[tab.Text]));
4176 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
4182 case MyCommon.IconSizes.IconNone:
4185 case MyCommon.IconSizes.Icon16:
4188 case MyCommon.IconSizes.Icon24:
4191 case MyCommon.IconSizes.Icon48:
4194 case MyCommon.IconSizes.Icon48_2:
4202 // ディスプレイの DPI 設定を考慮したサイズを設定する
4203 _listViewImageList.ImageSize = new Size(
4205 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4209 _listViewImageList.ImageSize = new Size(1, 1);
4213 private void ResetColumns(DetailsListView list)
4215 using (ControlTransaction.Update(list))
4216 using (ControlTransaction.Layout(list, false))
4219 list.ColumnClick -= MyList_ColumnClick;
4220 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4221 list.ColumnReordered -= MyList_ColumnReordered;
4222 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4224 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4225 list.Columns.Clear();
4226 cols.ForEach(col => col.Dispose());
4229 InitColumns(list, true);
4231 list.ColumnClick += MyList_ColumnClick;
4232 list.DrawColumnHeader += MyList_DrawColumnHeader;
4233 list.ColumnReordered += MyList_ColumnReordered;
4234 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4238 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4240 if (e.Url.AbsoluteUri != "about:blank")
4243 OpenUriAsync(e.Url.OriginalString);
4247 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4249 if (e.Url.Scheme == "data")
4251 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4253 else if (e.Url.AbsoluteUri != "about:blank")
4257 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4258 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4261 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4262 int i = urlStr.IndexOf('#');
4263 if (i == -1) return;
4265 string hash = urlStr.Substring(i);
4266 HashSupl.AddItem(hash);
4267 HashMgr.AddHashToHistory(hash.Trim(), false);
4268 AddNewTabForSearch(hash);
4273 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4274 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4276 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4277 if (SettingDialog.OpenUserTimeline)
4279 if (MyCommon.IsKeyDown(Keys.Control))
4280 OpenUriAsync(e.Url.OriginalString);
4282 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4286 if (MyCommon.IsKeyDown(Keys.Control))
4287 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4289 OpenUriAsync(e.Url.OriginalString);
4294 OpenUriAsync(e.Url.OriginalString);
4300 public void AddNewTabForSearch(string searchWord)
4302 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4303 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4305 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4307 foreach (TabPage tp in ListTab.TabPages)
4309 if (tb.TabName == tp.Text)
4311 ListTab.SelectedTab = tp;
4318 string tabName = searchWord;
4319 for (int i = 0; i <= 100; i++)
4321 if (_statuses.ContainsTab(tabName))
4327 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4328 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4330 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4332 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4333 cmb.Items.Add(searchWord);
4334 cmb.Text = searchWord;
4337 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4340 private void ShowUserTimeline()
4342 if (!this.ExistCurrentPost) return;
4343 AddNewTabForUserTimeline(_curPost.ScreenName);
4346 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4348 if (e.KeyCode == Keys.Escape)
4350 TabPage relTp = ListTab.SelectedTab;
4351 RemoveSpecifiedTab(relTp.Text, false);
4353 e.SuppressKeyPress = true;
4357 public void AddNewTabForUserTimeline(string user)
4359 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4360 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4362 if (tb.User == user)
4364 foreach (TabPage tp in ListTab.TabPages)
4366 if (tb.TabName == tp.Text)
4368 ListTab.SelectedTab = tp;
4375 string tabName = "user:" + user;
4376 while (_statuses.ContainsTab(tabName))
4381 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4382 _statuses.Tabs[tabName].User = user;
4383 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4385 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4389 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, tabName);
4392 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4395 foreach (TabPage tb in ListTab.TabPages)
4397 if (tb.Text == tabName) return false;
4401 if (tabName == Properties.Resources.AddNewTabText1) return false;
4406 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4407 tabType == MyCommon.TabUsageType.Favorites ||
4408 tabType == MyCommon.TabUsageType.Home ||
4409 tabType == MyCommon.TabUsageType.Mentions ||
4410 tabType == MyCommon.TabUsageType.Related)
4412 if (_statuses.GetTabByType(tabType) != null) return false;
4416 TabPage _tabPage = new TabPage();
4417 DetailsListView _listCustom = new DetailsListView();
4419 int cnt = ListTab.TabPages.Count;
4421 ///ToDo:Create and set controls follow tabtypes
4423 using (ControlTransaction.Update(_listCustom))
4424 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4425 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4426 using (ControlTransaction.Layout(this.SplitContainer1, false))
4427 using (ControlTransaction.Layout(this.ListTab, false))
4428 using (ControlTransaction.Layout(this))
4429 using (ControlTransaction.Layout(_tabPage, false))
4433 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4435 label = new Label();
4436 label.Dock = DockStyle.Top;
4437 label.Name = "labelUser";
4438 if (tabType == MyCommon.TabUsageType.Lists)
4440 label.Text = listInfo.ToString();
4444 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4446 label.TextAlign = ContentAlignment.MiddleLeft;
4447 using (ComboBox tmpComboBox = new ComboBox())
4449 label.Height = tmpComboBox.Height;
4451 _tabPage.Controls.Add(label);
4456 if (tabType == MyCommon.TabUsageType.PublicSearch)
4460 Label lbl = new Label();
4461 ComboBox cmb = new ComboBox();
4462 Button btn = new Button();
4463 ComboBox cmbLang = new ComboBox();
4465 pnl.SuspendLayout();
4467 pnl.Controls.Add(cmb);
4468 pnl.Controls.Add(cmbLang);
4469 pnl.Controls.Add(btn);
4470 pnl.Controls.Add(lbl);
4471 pnl.Name = "panelSearch";
4472 pnl.Dock = DockStyle.Top;
4473 pnl.Height = cmb.Height;
4474 pnl.Enter += SearchControls_Enter;
4475 pnl.Leave += SearchControls_Leave;
4478 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4479 cmb.Dock = DockStyle.Fill;
4480 cmb.Name = "comboSearch";
4481 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4482 cmb.ImeMode = ImeMode.NoControl;
4483 cmb.TabStop = false;
4484 cmb.AutoCompleteMode = AutoCompleteMode.None;
4485 cmb.KeyDown += SearchComboBox_KeyDown;
4487 if (_statuses.ContainsTab(tabName))
4489 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4490 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4494 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4495 cmbLang.Dock = DockStyle.Right;
4497 cmbLang.Name = "comboLang";
4498 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4499 cmbLang.TabStop = false;
4500 cmbLang.Items.Add("");
4501 cmbLang.Items.Add("ja");
4502 cmbLang.Items.Add("en");
4503 cmbLang.Items.Add("ar");
4504 cmbLang.Items.Add("da");
4505 cmbLang.Items.Add("nl");
4506 cmbLang.Items.Add("fa");
4507 cmbLang.Items.Add("fi");
4508 cmbLang.Items.Add("fr");
4509 cmbLang.Items.Add("de");
4510 cmbLang.Items.Add("hu");
4511 cmbLang.Items.Add("is");
4512 cmbLang.Items.Add("it");
4513 cmbLang.Items.Add("no");
4514 cmbLang.Items.Add("pl");
4515 cmbLang.Items.Add("pt");
4516 cmbLang.Items.Add("ru");
4517 cmbLang.Items.Add("es");
4518 cmbLang.Items.Add("sv");
4519 cmbLang.Items.Add("th");
4520 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4522 lbl.Text = "Search(C-S-f)";
4523 lbl.Name = "label1";
4524 lbl.Dock = DockStyle.Left;
4526 lbl.Height = cmb.Height;
4527 lbl.TextAlign = ContentAlignment.MiddleLeft;
4529 btn.Text = "Search";
4530 btn.Name = "buttonSearch";
4531 btn.UseVisualStyleBackColor = true;
4532 btn.Dock = DockStyle.Right;
4533 btn.TabStop = false;
4534 btn.Click += SearchButton_Click;
4537 this.ListTab.Controls.Add(_tabPage);
4538 _tabPage.Controls.Add(_listCustom);
4540 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4541 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4543 _tabPage.Location = new Point(4, 4);
4544 _tabPage.Name = "CTab" + cnt.ToString();
4545 _tabPage.Size = new Size(380, 260);
4546 _tabPage.TabIndex = 2 + cnt;
4547 _tabPage.Text = tabName;
4548 _tabPage.UseVisualStyleBackColor = true;
4550 _listCustom.AllowColumnReorder = true;
4551 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4552 _listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4553 _listCustom.Dock = DockStyle.Fill;
4554 _listCustom.FullRowSelect = true;
4555 _listCustom.HideSelection = false;
4556 _listCustom.Location = new Point(0, 0);
4557 _listCustom.Margin = new Padding(0);
4558 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4559 _listCustom.ShowItemToolTips = true;
4560 _listCustom.Size = new Size(380, 260);
4561 _listCustom.UseCompatibleStateImageBehavior = false;
4562 _listCustom.View = View.Details;
4563 _listCustom.OwnerDraw = true;
4564 _listCustom.VirtualMode = true;
4565 _listCustom.Font = _fntReaded;
4566 _listCustom.BackColor = _clListBackcolor;
4568 _listCustom.GridLines = SettingDialog.ShowGrid;
4569 _listCustom.AllowDrop = true;
4571 _listCustom.SmallImageList = _listViewImageList;
4573 InitColumns(_listCustom, startup);
4575 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4576 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4577 _listCustom.ColumnClick += MyList_ColumnClick;
4578 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4579 _listCustom.DragDrop += TweenMain_DragDrop;
4580 _listCustom.DragEnter += TweenMain_DragEnter;
4581 _listCustom.DragOver += TweenMain_DragOver;
4582 _listCustom.DrawItem += MyList_DrawItem;
4583 _listCustom.MouseClick += MyList_MouseClick;
4584 _listCustom.ColumnReordered += MyList_ColumnReordered;
4585 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4586 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4587 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4588 _listCustom.DrawSubItem += MyList_DrawSubItem;
4589 _listCustom.HScrolled += MyList_HScrolled;
4591 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4594 _tabPage.Tag = _listCustom;
4598 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4600 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4604 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4605 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4606 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4612 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4613 if (_tabPage == null) return false;
4615 SetListProperty(); //他のタブに列幅等を反映
4617 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4620 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4621 _tabPage.Tag = null;
4623 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4624 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4625 using (ControlTransaction.Layout(this.SplitContainer1, false))
4626 using (ControlTransaction.Layout(this.ListTab, false))
4627 using (ControlTransaction.Layout(this))
4628 using (ControlTransaction.Layout(_tabPage, false))
4630 if (this.ListTab.SelectedTab == _tabPage)
4632 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4633 this._beforeSelectedTab = null;
4635 this.ListTab.Controls.Remove(_tabPage);
4638 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4640 using (Control label = _tabPage.Controls["labelUser"])
4642 _tabPage.Controls.Remove(label);
4645 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4647 using (Control pnl = _tabPage.Controls["panelSearch"])
4649 pnl.Enter -= SearchControls_Enter;
4650 pnl.Leave -= SearchControls_Leave;
4651 _tabPage.Controls.Remove(pnl);
4653 foreach (Control ctrl in pnl.Controls)
4655 if (ctrl.Name == "buttonSearch")
4657 ctrl.Click -= SearchButton_Click;
4659 else if (ctrl.Name == "comboSearch")
4661 ctrl.KeyDown -= SearchComboBox_KeyDown;
4663 pnl.Controls.Remove(ctrl);
4669 _tabPage.Controls.Remove(_listCustom);
4671 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4672 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4673 _listCustom.ColumnClick -= MyList_ColumnClick;
4674 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4675 _listCustom.DragDrop -= TweenMain_DragDrop;
4676 _listCustom.DragEnter -= TweenMain_DragEnter;
4677 _listCustom.DragOver -= TweenMain_DragOver;
4678 _listCustom.DrawItem -= MyList_DrawItem;
4679 _listCustom.MouseClick -= MyList_MouseClick;
4680 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4681 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4682 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4683 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4684 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4685 _listCustom.HScrolled -= MyList_HScrolled;
4687 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4688 _listCustom.Columns.Clear();
4689 cols.ForEach(col => col.Dispose());
4692 _listCustom.ContextMenuStrip = null;
4693 _listCustom.ColumnHeaderContextMenuStrip = null;
4694 _listCustom.Font = null;
4696 _listCustom.SmallImageList = null;
4697 _listCustom.ListViewItemSorter = null;
4700 if (_curTab.Equals(_tabPage))
4707 this.PurgeListViewItemCache();
4711 _listCustom.Dispose();
4712 _statuses.RemoveTab(TabName);
4714 foreach (TabPage tp in ListTab.TabPages)
4716 DetailsListView lst = (DetailsListView)tp.Tag;
4717 var count = _statuses.Tabs[tp.Text].AllCount;
4718 if (lst.VirtualListSize != count)
4720 lst.VirtualListSize = count;
4727 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4729 this.PurgeListViewItemCache();
4730 _beforeSelectedTab = e.TabPage;
4733 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4737 if (!SettingDialog.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4740 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4741 if (!dragEnableRectangle.Contains(e.Location))
4743 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4744 tn = ListTab.SelectedTab.Text;
4747 if (string.IsNullOrEmpty(tn)) return;
4749 foreach (TabPage tb in ListTab.TabPages)
4753 ListTab.DoDragDrop(tb, DragDropEffects.All);
4763 Point cpos = new Point(e.X, e.Y);
4764 for (int i = 0; i < ListTab.TabPages.Count; i++)
4766 Rectangle rect = ListTab.GetTabRect(i);
4767 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4768 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4770 _rclickTabName = ListTab.TabPages[i].Text;
4776 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4778 //_curList.Refresh();
4780 SetMainWindowTitle();
4781 SetStatusLabelUrl();
4782 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4783 TabMenuControl(ListTab.SelectedTab.Text);
4784 this.PushSelectPostChain();
4787 private void SetListProperty()
4789 //削除などで見つからない場合は処理せず
4790 if (_curList == null) return;
4791 if (!_isColumnChanged) return;
4793 int[] dispOrder = new int[_curList.Columns.Count];
4794 for (int i = 0; i < _curList.Columns.Count; i++)
4796 for (int j = 0; j < _curList.Columns.Count; j++)
4798 if (_curList.Columns[j].DisplayIndex == i)
4807 foreach (TabPage tb in ListTab.TabPages)
4809 if (!tb.Equals(_curTab))
4811 if (tb.Tag != null && tb.Controls.Count > 0)
4813 DetailsListView lst = (DetailsListView)tb.Tag;
4814 for (int i = 0; i < lst.Columns.Count; i++)
4816 lst.Columns[dispOrder[i]].DisplayIndex = i;
4817 lst.Columns[i].Width = _curList.Columns[i].Width;
4823 _isColumnChanged = false;
4826 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4830 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4831 || PostBrowser.StatusText.StartsWith("data"))
4833 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4835 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4837 SetStatusLabelUrl();
4845 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4847 if (e.KeyChar == '@')
4849 if (!SettingDialog.UseAtIdSupplement) return;
4851 int cnt = AtIdSupl.ItemCount;
4852 ShowSuplDialog(StatusText, AtIdSupl);
4853 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4856 else if (e.KeyChar == '#')
4858 if (!SettingDialog.UseHashSupplement) return;
4859 ShowSuplDialog(StatusText, HashSupl);
4864 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4866 ShowSuplDialog(owner, dialog, 0, "");
4869 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4871 ShowSuplDialog(owner, dialog, offset, "");
4874 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4876 dialog.StartsWith = startswith;
4883 dialog.ShowDialog();
4885 this.TopMost = SettingDialog.AlwaysTop;
4886 int selStart = owner.SelectionStart;
4889 if (dialog.DialogResult == DialogResult.OK)
4891 if (!string.IsNullOrEmpty(dialog.inputText))
4895 fHalf = owner.Text.Substring(0, selStart - offset);
4897 if (selStart < owner.Text.Length)
4899 eHalf = owner.Text.Substring(selStart);
4901 owner.Text = fHalf + dialog.inputText + eHalf;
4902 owner.SelectionStart = selStart + dialog.inputText.Length;
4909 fHalf = owner.Text.Substring(0, selStart);
4911 if (selStart < owner.Text.Length)
4913 eHalf = owner.Text.Substring(selStart);
4915 owner.Text = fHalf + eHalf;
4918 owner.SelectionStart = selStart;
4924 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4927 if (!e.Alt && !e.Control && !e.Shift)
4929 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4931 bool isSpace = false;
4932 foreach (char c in StatusText.Text.ToCharArray())
4934 if (c == ' ' || c == ' ')
4947 StatusText.Text = "";
4948 JumpUnreadMenuItem_Click(null, null);
4952 this.StatusText_TextChanged(null, null);
4955 private void StatusText_TextChanged(object sender, EventArgs e)
4958 int pLen = GetRestStatusCount(true, false);
4959 lblLen.Text = pLen.ToString();
4962 StatusText.ForeColor = Color.Red;
4966 StatusText.ForeColor = _clInputFont;
4968 if (string.IsNullOrEmpty(StatusText.Text))
4970 _reply_to_id = null;
4971 _reply_to_name = null;
4975 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
4978 var statusText = this.StatusText.Text;
4979 statusText = statusText.Replace("\r\n", "\n");
4981 int pLen = 140 - statusText.Length;
4982 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
4983 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && SettingDialog.PostShiftEnter) ||
4984 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !SettingDialog.PostShiftEnter) ||
4985 (!isAuto && isAddFooter))
4987 if (SettingDialog.UseRecommendStatus)
4988 pLen -= SettingDialog.RecommendStatusText.Length;
4989 else if (SettingDialog.Status.Length > 0)
4990 pLen -= SettingDialog.Status.Length + 1;
4992 if (!string.IsNullOrEmpty(HashMgr.UseHash))
4994 pLen -= HashMgr.UseHash.Length + 1;
4996 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
4998 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5000 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
5002 string before = m.Result("${before}");
5003 string url = m.Result("${url}");
5004 string protocol = m.Result("${protocol}");
5005 string domain = m.Result("${domain}");
5006 string path = m.Result("${path}");
5007 if (protocol.Length == 0)
5009 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
5014 bool last_url_invalid_match = false;
5015 string lasturl = null;
5016 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
5018 lasturl = mm.ToString();
5019 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
5020 if (!last_url_invalid_match)
5022 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5026 if (path.Length != 0)
5028 if (last_url_invalid_match)
5030 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5032 pLen += path.Length;
5037 int shortUrlLength = protocol == "https://"
5038 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
5039 : SettingDialog.TwitterConfiguration.ShortUrlLength;
5041 pLen += url.Length - shortUrlLength;
5044 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
5046 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5049 if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
5051 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
5056 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
5058 this.itemCacheLock.EnterUpgradeableReadLock();
5061 if (_curList.Equals(sender))
5063 if (_itemCache != null &&
5064 e.StartIndex >= _itemCacheIndex &&
5065 e.EndIndex < _itemCacheIndex + _itemCache.Length)
5067 //If the newly requested cache is a subset of the old cache,
5068 //no need to rebuild everything, so do nothing.
5072 //Now we need to rebuild the cache.
5073 CreateCache(e.StartIndex, e.EndIndex);
5076 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
5079 private async void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
5081 ListViewItem item = null;
5082 PostClass cacheItemPost = null;
5084 if (_curList.Equals(sender))
5085 this.TryGetListViewItemCache(e.ItemIndex, out item, out cacheItemPost);
5089 //A cache miss, so create a new ListViewItem and pass it back.
5090 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
5093 item = this.CreateItem(tb, _statuses[tb.Text, e.ItemIndex], e.ItemIndex);
5098 string[] sitem = {"", "", "", "", "", "", "", ""};
5099 item = new ImageListViewItem(sitem);
5103 // e.Item に値をセットする前に await しないこと
5106 await ((ImageListViewItem)item).GetImageAsync();
5109 private void CreateCache(int StartIndex, int EndIndex)
5111 this.itemCacheLock.EnterWriteLock();
5114 var tabInfo = _statuses.Tabs[_curTab.Text];
5116 //キャッシュ要求(要求範囲±30を作成)
5118 if (StartIndex < 0) StartIndex = 0;
5120 if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
5121 _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
5122 _itemCacheIndex = StartIndex;
5124 _itemCache = new ListViewItem[0] {};
5125 Array.Resize(ref _itemCache, _postCache.Length);
5127 for (int i = 0; i < _postCache.Length; i++)
5129 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5134 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5136 _itemCacheIndex = -1;
5139 finally { this.itemCacheLock.ExitWriteLock(); }
5143 /// DetailsListView のための ListViewItem のキャッシュを消去する
5145 private void PurgeListViewItemCache()
5147 this.itemCacheLock.EnterWriteLock();
5150 this._itemCache = null;
5151 this._itemCacheIndex = -1;
5152 this._postCache = null;
5154 finally { this.itemCacheLock.ExitWriteLock(); }
5157 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5159 this.itemCacheLock.EnterReadLock();
5162 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5164 item = this._itemCache[index - _itemCacheIndex];
5165 post = this._postCache[index - _itemCacheIndex];
5169 finally { this.itemCacheLock.ExitReadLock(); }
5176 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5178 StringBuilder mk = new StringBuilder();
5179 //if (Post.IsDeleted) mk.Append("×");
5180 //if (Post.IsMark) mk.Append("♪");
5181 //if (Post.IsProtect) mk.Append("Ю");
5182 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5183 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5184 ImageListViewItem itm;
5185 if (Post.RetweetedId == null)
5187 string[] sitem= {"",
5189 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5190 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5195 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5199 string[] sitem = {"",
5201 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5202 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5203 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5207 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5209 itm.StateIndex = Post.StateIndex;
5211 bool read = Post.IsRead;
5212 //未読管理していなかったら既読として扱う
5213 if (!_statuses.Tabs[Tab.Text].UnreadManage || !SettingDialog.UnreadManage) read = true;
5214 ChangeItemStyleRead(read, itm, Post, null);
5215 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5220 /// 全てのタブの振り分けルールを反映し直します
5222 private void ApplyPostFilters()
5226 this.Cursor = Cursors.WaitCursor;
5228 this.PurgeListViewItemCache();
5229 this._curPost = null;
5230 this._curItemIndex = -1;
5231 this._statuses.FilterAll();
5233 foreach (TabPage tabPage in this.ListTab.TabPages)
5235 var tab = this._statuses.Tabs[tabPage.Text];
5237 var listview = (DetailsListView)tabPage.Tag;
5238 listview.VirtualListSize = tab.AllCount;
5240 if (this.SettingDialog.TabIconDisp)
5242 if (tab.UnreadCount > 0)
5243 tabPage.ImageIndex = 0;
5245 tabPage.ImageIndex = -1;
5249 if (!this.SettingDialog.TabIconDisp)
5250 this.ListTab.Refresh();
5254 this.Cursor = Cursors.Default;
5258 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5260 e.DrawDefault = true;
5263 private void MyList_HScrolled(object sender, EventArgs e)
5265 DetailsListView listView = (DetailsListView)sender;
5269 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5271 if (e.State == 0) return;
5272 e.DrawDefault = false;
5274 SolidBrush brs2 = null;
5275 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5277 if (e.Item.BackColor == _clSelf)
5278 brs2 = _brsBackColorMine;
5279 else if (e.Item.BackColor == _clAtSelf)
5280 brs2 = _brsBackColorAt;
5281 else if (e.Item.BackColor == _clTarget)
5282 brs2 = _brsBackColorYou;
5283 else if (e.Item.BackColor == _clAtTarget)
5284 brs2 = _brsBackColorAtYou;
5285 else if (e.Item.BackColor == _clAtFromTarget)
5286 brs2 = _brsBackColorAtFromTarget;
5287 else if (e.Item.BackColor == _clAtTo)
5288 brs2 = _brsBackColorAtTo;
5290 brs2 = _brsBackColorNone;
5295 if (((Control)sender).Focused)
5296 brs2 = _brsHighLight;
5298 brs2 = _brsDeactiveSelection;
5300 e.Graphics.FillRectangle(brs2, e.Bounds);
5301 e.DrawFocusRectangle();
5302 this.DrawListViewItemIcon(e);
5305 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5307 if (e.ItemState == 0) return;
5309 if (e.ColumnIndex > 0)
5312 RectangleF rct = e.Bounds;
5313 rct.Width = e.Header.Width;
5314 int fontHeight = e.Item.Font.Height;
5317 rct.Y += fontHeight;
5318 rct.Height -= fontHeight;
5322 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out heightDiff));
5324 //if (heightDiff > fontHeight * 0.7)
5326 // rct.Height += fontHeight;
5327 // drawLineCount += 1;
5330 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5331 if (!_iconCol && drawLineCount <= 1)
5333 //rct.Inflate(0, heightDiff / -2);
5334 //rct.Height += fontHeight / 2;
5336 else if (heightDiff < fontHeight * 0.7)
5338 //最終行が70%以上欠けていたら、最終行は表示しない
5339 //rct.Height = (float)((fontHeight * drawLineCount) + (fontHeight / 2));
5340 rct.Height = (fontHeight * drawLineCount) - 1;
5347 //if (!_iconCol && drawLineCount > 1)
5349 // rct.Y += fontHeight * 0.2;
5350 // if (heightDiff >= fontHeight * 0.8) rct.Height -= fontHeight * 0.2;
5355 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5356 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5361 Rectangle rctB = e.Bounds;
5362 rctB.Width = e.Header.Width;
5363 rctB.Height = fontHeight;
5365 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5367 TextRenderer.DrawText(e.Graphics,
5368 e.Item.SubItems[2].Text,
5370 Rectangle.Round(rct),
5372 TextFormatFlags.WordBreak |
5373 TextFormatFlags.EndEllipsis |
5374 TextFormatFlags.GlyphOverhangPadding |
5375 TextFormatFlags.NoPrefix);
5376 TextRenderer.DrawText(e.Graphics,
5377 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 + "]",
5381 TextFormatFlags.SingleLine |
5382 TextFormatFlags.EndEllipsis |
5383 TextFormatFlags.GlyphOverhangPadding |
5384 TextFormatFlags.NoPrefix);
5387 else if (drawLineCount == 1)
5389 TextRenderer.DrawText(e.Graphics,
5392 Rectangle.Round(rct),
5394 TextFormatFlags.SingleLine |
5395 TextFormatFlags.EndEllipsis |
5396 TextFormatFlags.GlyphOverhangPadding |
5397 TextFormatFlags.NoPrefix |
5398 TextFormatFlags.VerticalCenter);
5402 TextRenderer.DrawText(e.Graphics,
5405 Rectangle.Round(rct),
5407 TextFormatFlags.WordBreak |
5408 TextFormatFlags.EndEllipsis |
5409 TextFormatFlags.GlyphOverhangPadding |
5410 TextFormatFlags.NoPrefix);
5412 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5417 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5419 if (_iconSz == 0) return;
5421 ImageListViewItem item = (ImageListViewItem)e.Item;
5423 //e.Bounds.Leftが常に0を指すから自前で計算
5424 Rectangle itemRect = item.Bounds;
5425 var col0 = e.Item.ListView.Columns[0];
5426 itemRect.Width = col0.Width;
5428 if (col0.DisplayIndex > 0)
5430 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5432 if (clm.DisplayIndex < col0.DisplayIndex)
5433 itemRect.X += clm.Width;
5437 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5438 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5439 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5442 var img = item.Image;
5445 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5446 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5448 if (iconRect.Width > 0)
5450 e.Graphics.FillRectangle(Brushes.White, iconRect);
5451 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5454 e.Graphics.DrawImage(img.Image, iconRect);
5456 catch (ArgumentException)
5458 item.RefreshImageAsync();
5464 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5465 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5468 if (item.StateIndex > -1)
5470 Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5471 if (stateRect.Width > 0)
5473 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5474 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5475 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5480 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5482 base.ScaleControl(factor, specified);
5484 const int baseDpi = 96;
5486 // デザイン時の DPI (96dpi) との比を更新する
5487 this.currentScaleFactor = new SizeF(
5488 this.CurrentAutoScaleDimensions.Width / baseDpi,
5489 this.CurrentAutoScaleDimensions.Height / baseDpi);
5492 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5494 // ImageListViewItem item = (ImageListViewItem)e.Item;
5495 // if (item.StateImageIndex > -1)
5497 // ////e.Bounds.Leftが常に0を指すから自前で計算
5498 // //Rectangle itemRect = item.Bounds;
5499 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5501 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5503 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5505 // // itemRect.X += clm.Width;
5509 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5510 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5512 // if (rct.Width > 0)
5514 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5515 // //e.Graphics.FillRectangle(Brushes.White, rct);
5516 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5517 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5522 private void DoTabSearch(string _word,
5532 if (_curList.VirtualListSize == 0)
5534 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5537 if (_curList.SelectedIndices.Count > 0)
5539 cidx = _curList.SelectedIndices[0];
5541 toIdx = _curList.VirtualListSize;
5545 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5546 if (_curList.SelectedIndices.Count > 0)
5547 cidx = _curList.SelectedIndices[0];
5551 case SEARCHTYPE.NextSearch: //次を検索
5552 if (_curList.SelectedIndices.Count > 0)
5554 cidx = _curList.SelectedIndices[0] + 1;
5555 if (cidx > toIdx) cidx = toIdx;
5562 case SEARCHTYPE.PrevSearch: //前を検索
5563 if (_curList.SelectedIndices.Count > 0)
5565 cidx = _curList.SelectedIndices[0] - 1;
5566 if (cidx < 0) cidx = 0;
5577 RegexOptions regOpt = RegexOptions.None;
5578 StringComparison fndOpt = StringComparison.Ordinal;
5581 regOpt = RegexOptions.IgnoreCase;
5582 fndOpt = StringComparison.OrdinalIgnoreCase;
5593 _search = new Regex(_word, regOpt);
5594 for (int idx = cidx; idx != toIdx; idx += stp)
5599 post = _statuses[_curTab.Text, idx];
5605 if (_search.IsMatch(post.Nickname)
5606 || _search.IsMatch(post.TextFromApi)
5607 || _search.IsMatch(post.ScreenName))
5609 SelectListItem(_curList, idx);
5610 _curList.EnsureVisible(idx);
5615 catch (ArgumentException)
5617 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5624 for (int idx = cidx; idx != toIdx; idx += stp)
5629 post = _statuses[_curTab.Text, idx];
5635 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5636 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5637 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5639 SelectListItem(_curList, idx);
5640 _curList.EnsureVisible(idx);
5650 case SEARCHTYPE.DialogSearch:
5651 case SEARCHTYPE.NextSearch:
5655 case SEARCHTYPE.PrevSearch:
5657 cidx = _curList.VirtualListSize - 1;
5664 catch (ArgumentOutOfRangeException)
5667 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5670 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5673 this.ShowSearchDialog();
5676 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5678 var previousSearch = this.SearchDialog.ResultOptions;
5679 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5681 this.SearchDialog.Reset();
5682 this.ShowSearchDialog();
5688 previousSearch.Query,
5689 previousSearch.CaseSensitive,
5690 previousSearch.UseRegex,
5691 SEARCHTYPE.NextSearch);
5694 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5696 var previousSearch = this.SearchDialog.ResultOptions;
5697 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5699 this.SearchDialog.Reset();
5700 this.ShowSearchDialog();
5706 previousSearch.Query,
5707 previousSearch.CaseSensitive,
5708 previousSearch.UseRegex,
5709 SEARCHTYPE.PrevSearch);
5713 /// 検索ダイアログを表示し、検索を実行します
5715 private void ShowSearchDialog()
5717 // Recentタブの検索時以外では「新規タブに表示」ボタンを無効化する
5718 if (this._statuses.Tabs[this._curTab.Text].TabType == MyCommon.TabUsageType.Home)
5719 this.SearchDialog.DisableNewTabButton = false;
5721 this.SearchDialog.DisableNewTabButton = true;
5723 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5725 this.TopMost = this.SettingDialog.AlwaysTop;
5728 this.TopMost = this.SettingDialog.AlwaysTop;
5730 var searchOptions = this.SearchDialog.ResultOptions;
5731 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5733 if (searchOptions.NewTab)
5735 var tabName = searchOptions.Query;
5739 tabName = this._statuses.MakeTabName(tabName);
5741 catch (TabException ex)
5743 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5746 this.AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined);
5747 this._statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
5749 var filter = new PostFilterRule
5751 FilterBody = new[] { searchOptions.Query },
5752 UseRegex = searchOptions.UseRegex,
5753 CaseSensitive = searchOptions.CaseSensitive,
5755 this._statuses.Tabs[tabName].AddFilter(filter);
5757 var tabPage = this.ListTab.TabPages.Cast<TabPage>()
5758 .First(x => x.Text == tabName);
5760 this.ListTab.SelectedTab = tabPage;
5761 this.ListTabSelect(tabPage);
5763 this.ApplyPostFilters();
5764 this.SaveConfigsTabs();
5769 searchOptions.Query,
5770 searchOptions.CaseSensitive,
5771 searchOptions.UseRegex,
5772 SEARCHTYPE.DialogSearch);
5775 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5777 this.AddNewTabForSearch(searchOptions.Query);
5781 private void AboutMenuItem_Click(object sender, EventArgs e)
5783 using (TweenAboutBox about = new TweenAboutBox())
5785 about.ShowDialog(this);
5787 this.TopMost = SettingDialog.AlwaysTop;
5790 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5792 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5794 DetailsListView lst = null;
5796 if (ImageSelector.Enabled)
5800 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5803 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5806 ListTab.SelectedIndex = i;
5807 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5808 //_curTab = ListTab.TabPages[i];
5813 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5814 if (idx == -1 && bgnIdx > 0)
5816 for (int i = 0; i < bgnIdx; i++)
5818 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5821 ListTab.SelectedIndex = i;
5822 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5823 //_curTab = ListTab.TabPages[i];
5829 //全部調べたが未読見つからず→先頭タブの最新発言へ
5832 ListTab.SelectedIndex = 0;
5833 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5834 //_curTab = ListTab.TabPages[0];
5835 if (_statuses.SortOrder == SortOrder.Ascending)
5836 idx = lst.VirtualListSize - 1;
5841 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5843 SelectListItem(lst, idx);
5844 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5846 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5847 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5853 lst.EnsureVisible(idx);
5858 lst.EnsureVisible(idx);
5864 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5866 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5868 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5869 OpenUriAsync(MyCommon.GetStatusUrl(post));
5873 private void FavorareMenuItem_Click(object sender, EventArgs e)
5875 if (_curList.SelectedIndices.Count > 0)
5877 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5878 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5882 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5884 await this.CheckNewVersion(false);
5887 private void RunTweenUp()
5889 ProcessStartInfo pinfo = new ProcessStartInfo();
5890 pinfo.UseShellExecute = true;
5891 pinfo.WorkingDirectory = MyCommon.settingPath;
5892 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5893 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5896 Process.Start(pinfo);
5900 MessageBox.Show("Failed to execute TweenUp3.exe.");
5904 public class VersionInfo
5906 public Version Version { get; set; }
5907 public Uri DownloadUri { get; set; }
5908 public string ReleaseNote { get; set; }
5912 /// OpenTween の最新バージョンの情報を取得します
5914 public async Task<VersionInfo> GetVersionInfoAsync()
5916 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5917 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5919 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5920 .ConfigureAwait(false);
5922 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5923 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5925 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5926 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5928 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5930 return new VersionInfo
5932 Version = Version.Parse(msgHeader[0]),
5933 DownloadUri = new Uri(msgHeader[1]),
5934 ReleaseNote = msgBody,
5938 private async Task CheckNewVersion(bool startup = false)
5940 if (ApplicationSettings.VersionInfoUrl == null)
5941 return; // 更新チェック無効化
5945 var versionInfo = await this.GetVersionInfoAsync();
5947 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5952 var msgtext = string.Format(Properties.Resources.CheckNewVersionText7,
5953 MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version));
5954 msgtext = MyCommon.ReplaceAppName(msgtext);
5956 MessageBox.Show(msgtext,
5957 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5958 MessageBoxButtons.OK, MessageBoxIcon.Information);
5963 using (var dialog = new UpdateDialog())
5965 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5966 MyCommon.GetReadableVersion(versionInfo.Version));
5967 dialog.DetailsText = versionInfo.ReleaseNote;
5969 if (dialog.ShowDialog(this) == DialogResult.Yes)
5971 await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString);
5977 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5980 MessageBox.Show(Properties.Resources.CheckNewVersionText10,
5981 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5982 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5987 private void Colorize()
5991 //件数関連の場合、タイトル即時書き換え
5992 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
5993 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5994 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5995 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5997 SetMainWindowTitle();
5999 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
6000 foreach (TabPage tb in ListTab.TabPages)
6002 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
6004 if (SettingDialog.TabIconDisp)
6006 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
6010 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
6013 public string createDetailHtml(string orgdata)
6015 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
6018 private async void DisplayItemImage_Downloaded(object sender, EventArgs e)
6020 if (sender.Equals(displayItem))
6022 this.ClearUserPicture();
6024 var img = displayItem.Image;
6028 img = await img.CloneAsync();
6030 UserPicture.Image = img;
6034 UserPicture.ShowErrorImage();
6039 private void DispSelectedPost()
6041 DispSelectedPost(false);
6044 private PostClass displayPost = new PostClass();
6047 /// サムネイルの表示処理を表すタスク
6049 private Task thumbnailTask = null;
6052 /// サムネイル表示に使用する CancellationToken の生成元
6054 private CancellationTokenSource thumbnailTokenSource = null;
6056 private void DispSelectedPost(bool forceupdate)
6058 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
6061 var oldDisplayPost = this.displayPost;
6062 this.displayPost = this._curPost;
6064 if (!forceupdate && this._curPost.Equals(oldDisplayPost))
6067 if (displayItem != null)
6069 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
6072 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
6073 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
6075 using (ControlTransaction.Update(this.TableLayoutPanel1))
6077 var sourceText = "";
6078 string sourceUrl = null;
6081 var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
6084 var src = mc.Groups["sourceurl"].Value;
6085 if (Regex.IsMatch(src, "^https?://"))
6088 sourceUrl = "https://twitter.com/" + src;
6091 if (_curPost.Source != null)
6092 sourceText = _curPost.Source;
6094 SourceLinkLabel.Text = sourceText;
6095 SourceLinkLabel.Tag = sourceUrl;
6096 SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
6102 nameText = "DM FROM <- ";
6104 nameText = "DM TO -> ";
6110 nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
6111 if (_curPost.RetweetedId != null)
6112 nameText += " (RT:" + _curPost.RetweetedBy + ")";
6114 NameLabel.Text = nameText;
6115 NameLabel.Tag = _curPost.ScreenName;
6117 var nameForeColor = SystemColors.ControlText;
6118 if (_curPost.IsOwl && (this.SettingDialog.OneWayLove || _curPost.IsDm))
6119 nameForeColor = this._clOWL;
6120 if (_curPost.RetweetedId != null)
6121 nameForeColor = this._clRetweet;
6123 nameForeColor = this._clFav;
6124 NameLabel.ForeColor = nameForeColor;
6126 this.ClearUserPicture();
6128 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6130 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6133 UserPicture.Image = image != null ? image.Clone() : null;
6137 UserPicture.ShowErrorImage();
6141 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6143 if (DumpPostClassToolStripMenuItem.Checked)
6145 StringBuilder sb = new StringBuilder(512);
6147 sb.Append("-----Start PostClass Dump<br>");
6148 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6149 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6150 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6151 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6152 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6153 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6154 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6155 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6156 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6157 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6158 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6159 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6160 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6161 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6162 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6164 foreach (string nm in _curPost.ReplyToList)
6166 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6169 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6170 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6171 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6172 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6173 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6174 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6175 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6176 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6177 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6178 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6179 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6180 sb.Append("-----End PostClass Dump<br>");
6182 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6186 // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
6187 // (同一ツイートの RT は文面が同じであるため同様に更新しない)
6188 if (_curPost.StatusId != oldDisplayPost.StatusId)
6190 this.PostBrowser.DocumentText =
6191 this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6193 this.PostBrowser.Document.Window.ScrollTo(0, 0);
6195 this.SplitContainer3.Panel2Collapsed = true;
6197 if (this.IsPreviewEnable)
6199 if (this.thumbnailTokenSource != null)
6201 var oldTokenSource = this.thumbnailTokenSource;
6203 var cancelTask = Task.Run(() => oldTokenSource.Cancel());
6205 Task.WhenAll(this.thumbnailTask, cancelTask)
6206 .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
6209 this.thumbnailTokenSource = new CancellationTokenSource();
6211 var token = this.thumbnailTokenSource.Token;
6212 this.thumbnailTask = this.tweetThumbnail1.ShowThumbnailAsync(_curPost, token);
6219 private void MatomeMenuItem_Click(object sender, EventArgs e)
6221 OpenApplicationWebsite();
6224 private void OpenApplicationWebsite()
6226 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6229 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6231 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6234 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6236 if (ListTab.SelectedTab != null)
6238 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6240 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6241 if (pnl.Controls["comboSearch"].Focused ||
6242 pnl.Controls["comboLang"].Focused ||
6243 pnl.Controls["buttonSearch"].Focused) return;
6245 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6246 if (State == ModifierState.NotFlags) return;
6247 if (State != ModifierState.None) _anchorFlag = false;
6248 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6251 e.SuppressKeyPress = true;
6256 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6258 ModifierState state = ModifierState.None;
6259 if (sControl) state = state | ModifierState.Ctrl;
6260 if (sShift) state = state | ModifierState.Shift;
6261 if (sAlt) state = state | ModifierState.Alt;
6266 private enum ModifierState
6278 //PostBrowser = 102,
6282 private enum FocusedControl : int
6290 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6292 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6293 if (Focused == FocusedControl.ListTab)
6295 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6296 Modifier == ModifierState.Ctrl ||
6297 Modifier == ModifierState.None ||
6298 Modifier == ModifierState.Shift)
6300 if (KeyCode == Keys.J)
6302 SendKeys.Send("{DOWN}");
6305 else if (KeyCode == Keys.K)
6307 SendKeys.Send("{UP}");
6311 if (Modifier == ModifierState.Shift ||
6312 Modifier == ModifierState.None)
6314 if (KeyCode == Keys.F)
6316 SendKeys.Send("{PGDN}");
6319 else if (KeyCode == Keys.B)
6321 SendKeys.Send("{PGUP}");
6330 case ModifierState.None:
6335 OpenApplicationWebsite();
6338 MenuItemSearchNext_Click(null, null);
6344 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
6347 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
6350 if (Focused != FocusedControl.StatusText)
6356 case Keys.ProcessKey:
6357 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6358 JumpUnreadMenuItem_Click(null, null);
6361 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6362 ShowRelatedStatusesMenuItem_Click(null, null);
6366 if (Focused == FocusedControl.ListTab)
6379 case Keys.OemPeriod:
6383 if (this.StatusText.Enabled) this.StatusText.Focus();
6386 MakeReplyOrDirectStatus();
6393 _anchorFlag = false;
6413 // ] in_reply_to参照元へ戻る
6414 GoInReplyToPostTree();
6417 // [ in_reply_toへジャンプ
6418 GoBackInReplyToPostTree();
6421 if (ListTab.SelectedTab != null)
6423 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6424 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6426 TabPage relTp = ListTab.SelectedTab;
6427 RemoveSpecifiedTab(relTp.Text, false);
6435 else if (Focused == FocusedControl.PostBrowser)
6442 //スクロールを発生させるため、true を返す
6447 case ModifierState.Ctrl:
6452 MakeReplyOrDirectStatus(false, true);
6458 MakeReplyOrDirectStatus(false, false);
6461 FavoriteChange(true);
6464 doRepliedStatusOpen();
6470 ReadedStripMenuItem_Click(null, null);
6473 HashManageMenuItem_Click(null, null);
6476 UrlConvertAutoToolStripMenuItem_Click(null, null);
6479 if (Focused != FocusedControl.PostBrowser)
6481 MultiLineMenuItem_Click(null, null);
6486 MenuItemSubSearch_Click(null, null);
6493 MoveToHomeToolStripMenuItem_Click(null, null);
6497 MoveToFavToolStripMenuItem_Click(null, null);
6501 StatusOpenMenuItem_Click(null, null);
6505 OpenURLMenuItem_Click(null, null);
6509 if (Focused == FocusedControl.ListTab)
6516 return false; //スルーする
6534 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6535 int tabNo = KeyCode - Keys.D1;
6536 if (ListTab.TabPages.Count < tabNo)
6538 ListTab.SelectedIndex = tabNo;
6539 ListTabSelect(ListTab.TabPages[tabNo]);
6542 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6543 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6547 else if (Focused == FocusedControl.StatusText)
6553 StatusText.SelectAll();
6557 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6559 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6561 if (KeyCode == Keys.Up)
6564 if (_hisIdx < 0) _hisIdx = 0;
6569 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6571 StatusText.Text = _history[_hisIdx].status;
6572 _reply_to_id = _history[_hisIdx].inReplyToId;
6573 _reply_to_name = _history[_hisIdx].inReplyToName;
6574 StatusText.SelectionStart = StatusText.Text.Length;
6578 if (ListTab.SelectedIndex == 0)
6580 ListTab.SelectedIndex = ListTab.TabCount - 1;
6584 ListTab.SelectedIndex -= 1;
6590 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6592 ListTab.SelectedIndex = 0;
6596 ListTab.SelectedIndex += 1;
6604 //フォーカスPostBrowserもしくは関係なし
6608 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6612 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6613 if (!string.IsNullOrEmpty(_selText))
6617 Clipboard.SetDataObject(_selText, false, 5, 100);
6619 catch (Exception ex)
6621 MessageBox.Show(ex.Message);
6626 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6627 MultiLineMenuItem_Click(null, null);
6632 case ModifierState.Shift:
6637 MenuItemSearchPrev_Click(null, null);
6643 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
6646 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
6650 if (Focused != FocusedControl.StatusText)
6652 if (KeyCode == Keys.R)
6659 if (Focused == FocusedControl.ListTab)
6679 GoBackInReplyToPostTree(true, false);
6682 GoBackInReplyToPostTree(true, true);
6686 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6691 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6695 this.GoBackSelectPostChain();
6700 case ModifierState.Alt:
6704 doReTweetOfficial(true);
6707 if (_curPost != null)
6709 doShowUserStatus(_curPost.ScreenName, false);
6714 ScrollDownPostBrowser(false);
6717 ScrollDownPostBrowser(true);
6720 PageDownPostBrowser(false);
6723 PageDownPostBrowser(true);
6726 if (Focused == FocusedControl.ListTab)
6728 // 別タブの同じ書き込みへ(ALT+←/→)
6729 if (KeyCode == Keys.Right)
6731 GoSamePostToAnotherTab(false);
6734 else if (KeyCode == Keys.Left)
6736 GoSamePostToAnotherTab(true);
6741 case ModifierState.Ctrl | ModifierState.Shift:
6745 MakeReplyOrDirectStatus(false, true, true);
6751 if (ListTab.SelectedTab != null)
6753 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6755 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6761 FavoriteChange(false);
6764 UnreadStripMenuItem_Click(null, null);
6767 HashToggleMenuItem_Click(null, null);
6770 ImageSelectMenuItem_Click(null, null);
6776 FavorareMenuItem_Click(null, null);
6779 if (Focused == FocusedControl.StatusText)
6785 if (_curList != null && _curList.VirtualListSize != 0 &&
6786 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6788 idx = _curList.SelectedIndices[0] - 1;
6789 SelectListItem(_curList, idx);
6790 _curList.EnsureVisible(idx);
6795 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6796 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6798 idx = _curList.SelectedIndices[0] + 1;
6799 SelectListItem(_curList, idx);
6800 _curList.EnsureVisible(idx);
6805 if (StatusText.SelectionStart > 0)
6807 int endidx = StatusText.SelectionStart - 1;
6808 string startstr = "";
6809 bool pressed = false;
6810 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6812 char c = StatusText.Text[i];
6813 if (Char.IsLetterOrDigit(c) || c == '_')
6820 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6821 int cnt = AtIdSupl.ItemCount;
6822 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6823 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6828 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6829 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6841 else if (Focused == FocusedControl.ListTab)
6843 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6855 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6856 int colNo = KeyCode - Keys.D1;
6857 if (lst.Columns.Count < colNo) return false;
6858 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6859 if (col == null) return false;
6860 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6863 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6864 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6869 case ModifierState.Ctrl | ModifierState.Alt:
6870 if (KeyCode == Keys.S)
6872 FavoritesRetweetOriginal();
6875 else if (KeyCode == Keys.R)
6877 FavoritesRetweetUnofficial();
6880 else if (KeyCode == Keys.H)
6882 OpenUserAppointUrl();
6886 case ModifierState.Alt | ModifierState.Shift:
6887 if (Focused == FocusedControl.PostBrowser)
6889 if (KeyCode == Keys.R)
6890 doReTweetUnofficial();
6891 else if (KeyCode == Keys.C)
6898 if (!this.ExistCurrentPost) return false;
6899 doTranslation(_curPost.TextFromApi);
6902 doReTweetUnofficial();
6908 this.tweetThumbnail1.ScrollUp();
6911 this.tweetThumbnail1.ScrollDown();
6914 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6916 if (!this.SplitContainer3.Panel2Collapsed)
6918 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6928 private void ScrollDownPostBrowser(bool forward)
6930 var doc = PostBrowser.Document;
6931 if (doc == null) return;
6933 var tags = doc.GetElementsByTagName("html");
6937 tags[0].ScrollTop += SettingDialog.FontDetail.Height;
6939 tags[0].ScrollTop -= SettingDialog.FontDetail.Height;
6943 private void PageDownPostBrowser(bool forward)
6945 var doc = PostBrowser.Document;
6946 if (doc == null) return;
6948 var tags = doc.GetElementsByTagName("html");
6952 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6954 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6958 private void GoNextTab(bool forward)
6960 int idx = ListTab.SelectedIndex;
6964 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6969 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6971 ListTab.SelectedIndex = idx;
6972 ListTabSelect(ListTab.TabPages[idx]);
6975 private void CopyStot()
6978 StringBuilder sb = new StringBuilder();
6979 bool IsProtected = false;
6981 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6982 foreach (int idx in _curList.SelectedIndices)
6984 PostClass post = _statuses[_curTab.Text, idx];
6990 if (post.IsDeleted) continue;
6993 if (post.RetweetedId != null)
6994 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6996 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7000 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7005 MessageBox.Show(Properties.Resources.CopyStotText1);
7009 clstr = sb.ToString();
7012 Clipboard.SetDataObject(clstr, false, 5, 100);
7014 catch (Exception ex)
7016 MessageBox.Show(ex.Message);
7021 private void CopyIdUri()
7024 StringBuilder sb = new StringBuilder();
7025 if (this._curTab == null) return;
7026 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
7027 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
7028 foreach (int idx in _curList.SelectedIndices)
7030 var post = _statuses[_curTab.Text, idx];
7031 sb.Append(MyCommon.GetStatusUrl(post));
7032 sb.Append(Environment.NewLine);
7036 clstr = sb.ToString();
7039 Clipboard.SetDataObject(clstr, false, 5, 100);
7041 catch (Exception ex)
7043 MessageBox.Show(ex.Message);
7048 private void GoFav(bool forward)
7050 if (_curList.VirtualListSize == 0) return;
7057 if (_curList.SelectedIndices.Count == 0)
7063 fIdx = _curList.SelectedIndices[0] + 1;
7064 if (fIdx > _curList.VirtualListSize - 1) return;
7066 toIdx = _curList.VirtualListSize;
7071 if (_curList.SelectedIndices.Count == 0)
7073 fIdx = _curList.VirtualListSize - 1;
7077 fIdx = _curList.SelectedIndices[0] - 1;
7078 if (fIdx < 0) return;
7084 for (int idx = fIdx; idx != toIdx; idx += stp)
7086 if (_statuses[_curTab.Text, idx].IsFav)
7088 SelectListItem(_curList, idx);
7089 _curList.EnsureVisible(idx);
7095 private void GoSamePostToAnotherTab(bool left)
7097 if (_curList.VirtualListSize == 0) return;
7103 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7104 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7106 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7111 if (ListTab.SelectedIndex == 0)
7117 fIdx = ListTab.SelectedIndex - 1;
7125 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7131 fIdx = ListTab.SelectedIndex + 1;
7133 toIdx = ListTab.TabCount;
7138 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7140 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7141 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7143 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7145 ListTab.SelectedIndex = tabidx;
7146 ListTabSelect(ListTab.TabPages[tabidx]);
7147 SelectListItem(_curList, idx);
7148 _curList.EnsureVisible(idx);
7157 private void GoPost(bool forward)
7159 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7166 fIdx = _curList.SelectedIndices[0] + 1;
7167 if (fIdx > _curList.VirtualListSize - 1) return;
7168 toIdx = _curList.VirtualListSize;
7173 fIdx = _curList.SelectedIndices[0] - 1;
7174 if (fIdx < 0) return;
7180 if (_curPost.RetweetedId == null)
7182 name = _curPost.ScreenName;
7186 name = _curPost.RetweetedBy;
7188 for (int idx = fIdx; idx != toIdx; idx += stp)
7190 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7192 if (_statuses[_curTab.Text, idx].ScreenName == name)
7194 SelectListItem(_curList, idx);
7195 _curList.EnsureVisible(idx);
7201 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7203 SelectListItem(_curList, idx);
7204 _curList.EnsureVisible(idx);
7211 private void GoRelPost(bool forward)
7213 if (_curList.SelectedIndices.Count == 0) return;
7220 fIdx = _curList.SelectedIndices[0] + 1;
7221 if (fIdx > _curList.VirtualListSize - 1) return;
7222 toIdx = _curList.VirtualListSize;
7227 fIdx = _curList.SelectedIndices[0] - 1;
7228 if (fIdx < 0) return;
7235 if (_curPost == null) return;
7236 _anchorPost = _curPost;
7241 if (_anchorPost == null) return;
7244 for (int idx = fIdx; idx != toIdx; idx += stp)
7246 PostClass post = _statuses[_curTab.Text, idx];
7247 if (post.ScreenName == _anchorPost.ScreenName ||
7248 post.RetweetedBy == _anchorPost.ScreenName ||
7249 post.ScreenName == _anchorPost.RetweetedBy ||
7250 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7251 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7252 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7253 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7254 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7256 SelectListItem(_curList, idx);
7257 _curList.EnsureVisible(idx);
7263 private void GoAnchor()
7265 if (_anchorPost == null) return;
7266 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7267 if (idx == -1) return;
7269 SelectListItem(_curList, idx);
7270 _curList.EnsureVisible(idx);
7273 private void GoTopEnd(bool GoTop)
7280 _item = _curList.GetItemAt(0, 25);
7288 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7290 idx = _curList.VirtualListSize - 1;
7294 SelectListItem(_curList, idx);
7297 private void GoMiddle()
7304 _item = _curList.GetItemAt(0, 0);
7314 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7317 idx2 = _curList.VirtualListSize - 1;
7323 idx3 = (idx1 + idx2) / 2;
7325 SelectListItem(_curList, idx3);
7328 private void GoLast()
7330 if (_curList.VirtualListSize == 0) return;
7332 if (_statuses.SortOrder == SortOrder.Ascending)
7334 SelectListItem(_curList, _curList.VirtualListSize - 1);
7335 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7339 SelectListItem(_curList, 0);
7340 _curList.EnsureVisible(0);
7344 private void MoveTop()
7346 if (_curList.SelectedIndices.Count == 0) return;
7347 int idx = _curList.SelectedIndices[0];
7348 if (_statuses.SortOrder == SortOrder.Ascending)
7350 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7354 _curList.EnsureVisible(0);
7356 _curList.EnsureVisible(idx);
7359 private void GoInReplyToPostTree()
7361 if (_curPost == null) return;
7363 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7365 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7367 PostClass post = null;
7368 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7369 if (string.IsNullOrEmpty(r) && post != null)
7371 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7372 _curPost.InReplyToUser = post.InReplyToUser;
7373 _curPost.IsReply = post.IsReply;
7374 this.PurgeListViewItemCache();
7375 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7379 this.StatusLabel.Text = r;
7383 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7385 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7387 replyChains = new Stack<ReplyChain>();
7389 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7392 string inReplyToTabName;
7393 long inReplyToId = _curPost.InReplyToStatusId.Value;
7394 string inReplyToUser = _curPost.InReplyToUser;
7395 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7397 var inReplyToPosts = from tab in _statuses.Tabs.Values
7398 orderby tab != curTabClass
7399 from post in tab.Posts.Values
7400 where post.StatusId == inReplyToId
7401 let index = tab.IndexOf(post.StatusId)
7403 select new {Tab = tab, Index = index};
7407 var inReplyPost = inReplyToPosts.First();
7408 inReplyToTabName = inReplyPost.Tab.TabName;
7409 inReplyToIndex = inReplyPost.Index;
7411 catch (InvalidOperationException)
7413 PostClass post = null;
7414 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7415 if (string.IsNullOrEmpty(r) && post != null)
7418 _statuses.AddPost(post);
7419 _statuses.DistributePosts();
7420 //_statuses.SubmitUpdate(null, null, null, false);
7421 this.RefreshTimeline(false);
7424 var inReplyPost = inReplyToPosts.First();
7425 inReplyToTabName = inReplyPost.Tab.TabName;
7426 inReplyToIndex = inReplyPost.Index;
7428 catch (InvalidOperationException)
7430 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7436 this.StatusLabel.Text = r;
7437 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7442 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7443 DetailsListView listView = (DetailsListView)tabPage.Tag;
7445 if (_curTab != tabPage)
7447 this.ListTab.SelectTab(tabPage);
7450 this.SelectListItem(listView, inReplyToIndex);
7451 listView.EnsureVisible(inReplyToIndex);
7454 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7456 if (_curPost == null) return;
7458 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7459 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7463 if (_curPost.InReplyToStatusId != null)
7465 var posts = from t in _statuses.Tabs
7466 from p in t.Value.Posts
7467 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7468 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7470 orderby isForward ? indexOf : indexOf * -1
7471 orderby t.Value != curTabClass
7472 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7475 var postList = posts.ToList();
7476 for (int i = postList.Count - 1; i >= 0; i--)
7479 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7481 postList.RemoveAt(index);
7484 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7485 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7486 if (post == null) post = postList.First();
7487 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7488 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7489 SelectListItem(listView, post.Index);
7490 listView.EnsureVisible(post.Index);
7492 catch (InvalidOperationException)
7500 if (replyChains == null || replyChains.Count < 1)
7502 var posts = from t in _statuses.Tabs
7503 from p in t.Value.Posts
7504 where p.Value.InReplyToStatusId == _curPost.StatusId
7505 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7508 orderby t.Value != curTabClass
7509 select new {Tab = t.Value, Index = indexOf};
7512 var post = posts.First();
7513 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7514 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7515 SelectListItem(listView, post.Index);
7516 listView.EnsureVisible(post.Index);
7518 catch (InvalidOperationException)
7525 ReplyChain chainHead = replyChains.Pop();
7526 if (chainHead.InReplyToId == _curPost.StatusId)
7528 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7537 ListTab.SelectTab(chainHead.OriginalTab);
7543 SelectListItem(_curList, idx);
7544 _curList.EnsureVisible(idx);
7550 this.GoBackInReplyToPostTree(parallel);
7556 private void GoBackSelectPostChain()
7558 if (this.selectPostChains.Count > 1)
7567 this.selectPostChains.Pop();
7568 var tabPostPair = this.selectPostChains.Peek();
7570 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) continue; //該当タブが存在しないので無視
7572 if (tabPostPair.Item2 != null)
7574 idx = this._statuses.Tabs[tabPostPair.Item1.Text].IndexOf(tabPostPair.Item2.StatusId);
7575 if (idx == -1) continue; //該当ポストが存在しないので無視
7578 tp = tabPostPair.Item1;
7580 this.selectPostChains.Pop();
7582 catch (InvalidOperationException)
7588 while (this.selectPostChains.Count > 1);
7593 //履歴が残り1つであればクリアしておく
7594 if (this.selectPostChains.Count == 1)
7595 this.selectPostChains.Clear();
7599 DetailsListView lst = (DetailsListView)tp.Tag;
7600 this.ListTab.SelectedTab = tp;
7603 SelectListItem(lst, idx);
7604 lst.EnsureVisible(idx);
7610 private void PushSelectPostChain()
7612 int count = this.selectPostChains.Count;
7615 var p = this.selectPostChains.Peek();
7616 if (p.Item1 == this._curTab)
7618 if (p.Item2 == this._curPost) return; //最新の履歴と同一
7619 if (p.Item2 == null) this.selectPostChains.Pop(); //置き換えるため削除
7622 if (count >= 2500) TrimPostChain();
7623 this.selectPostChains.Push(Tuple.Create(this._curTab, this._curPost));
7626 private void TrimPostChain()
7628 if (this.selectPostChains.Count <= 2000) return;
7629 var p = new Stack<Tuple<TabPage, PostClass>>(2000);
7630 for (int i = 0; i < 2000; i++)
7632 p.Push(this.selectPostChains.Pop());
7634 this.selectPostChains.Clear();
7635 for (int i = 0; i < 2000; i++)
7637 this.selectPostChains.Push(p.Pop());
7641 private bool GoStatus(long statusId)
7643 if (statusId == 0) return false;
7644 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7646 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7648 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7649 ListTab.SelectedIndex = tabidx;
7650 ListTabSelect(ListTab.TabPages[tabidx]);
7651 SelectListItem(_curList, idx);
7652 _curList.EnsureVisible(idx);
7659 private bool GoDirectMessage(long statusId)
7661 if (statusId == 0) return false;
7662 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7664 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7666 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7667 ListTab.SelectedIndex = tabidx;
7668 ListTabSelect(ListTab.TabPages[tabidx]);
7669 SelectListItem(_curList, idx);
7670 _curList.EnsureVisible(idx);
7677 private void MyList_MouseClick(object sender, MouseEventArgs e)
7679 _anchorFlag = false;
7682 private void StatusText_Enter(object sender, EventArgs e)
7684 // フォーカスの戻り先を StatusText に設定
7685 this.Tag = StatusText;
7686 StatusText.BackColor = _clInputBackcolor;
7689 public Color InputBackColor
7691 get { return _clInputBackcolor; }
7692 set { _clInputBackcolor = value; }
7695 private void StatusText_Leave(object sender, EventArgs e)
7697 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7698 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7699 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7702 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7704 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7705 if (State == ModifierState.NotFlags) return;
7706 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7709 e.SuppressKeyPress = true;
7712 this.StatusText_TextChanged(null, null);
7715 private void SaveConfigsAll(bool ifModified)
7719 SaveConfigsCommon();
7726 if (_modifySettingCommon) SaveConfigsCommon();
7727 if (_modifySettingLocal) SaveConfigsLocal();
7728 if (_modifySettingAtId) SaveConfigsAtId();
7732 private void SaveConfigsAtId()
7734 if (_ignoreConfigSave || !SettingDialog.UseAtIdSupplement && AtIdSupl == null) return;
7736 _modifySettingAtId = false;
7737 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7741 private void SaveConfigsCommon()
7743 if (_ignoreConfigSave) return;
7745 _modifySettingCommon = false;
7748 _cfgCommon.UserName = tw.Username;
7749 _cfgCommon.UserId = tw.UserId;
7750 _cfgCommon.Password = tw.Password;
7751 _cfgCommon.Token = tw.AccessToken;
7752 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7753 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7754 _cfgCommon.UserstreamStartup = SettingDialog.UserstreamStartup;
7755 _cfgCommon.UserstreamPeriod = SettingDialog.UserstreamPeriodInt;
7756 _cfgCommon.TimelinePeriod = SettingDialog.TimelinePeriodInt;
7757 _cfgCommon.ReplyPeriod = SettingDialog.ReplyPeriodInt;
7758 _cfgCommon.DMPeriod = SettingDialog.DMPeriodInt;
7759 _cfgCommon.PubSearchPeriod = SettingDialog.PubSearchPeriodInt;
7760 _cfgCommon.ListsPeriod = SettingDialog.ListsPeriodInt;
7761 _cfgCommon.UserTimelinePeriod = SettingDialog.UserTimelinePeriodInt;
7762 _cfgCommon.Read = SettingDialog.Readed;
7763 _cfgCommon.IconSize = SettingDialog.IconSz;
7764 _cfgCommon.UnreadManage = SettingDialog.UnreadManage;
7765 _cfgCommon.PlaySound = SettingDialog.PlaySound;
7766 _cfgCommon.OneWayLove = SettingDialog.OneWayLove;
7768 _cfgCommon.NameBalloon = SettingDialog.NameBalloon;
7769 _cfgCommon.PostCtrlEnter = SettingDialog.PostCtrlEnter;
7770 _cfgCommon.PostShiftEnter = SettingDialog.PostShiftEnter;
7771 _cfgCommon.CountApi = SettingDialog.CountApi;
7772 _cfgCommon.CountApiReply = SettingDialog.CountApiReply;
7773 _cfgCommon.PostAndGet = SettingDialog.PostAndGet;
7774 _cfgCommon.DispUsername = SettingDialog.DispUsername;
7775 _cfgCommon.MinimizeToTray = SettingDialog.MinimizeToTray;
7776 _cfgCommon.CloseToExit = SettingDialog.CloseToExit;
7777 _cfgCommon.DispLatestPost = SettingDialog.DispLatestPost;
7778 _cfgCommon.SortOrderLock = SettingDialog.SortOrderLock;
7779 _cfgCommon.ViewTabBottom = SettingDialog.ViewTabBottom;
7780 _cfgCommon.TinyUrlResolve = SettingDialog.TinyUrlResolve;
7781 _cfgCommon.StartupVersion = SettingDialog.StartupVersion;
7782 _cfgCommon.StartupFollowers = SettingDialog.StartupFollowers;
7783 _cfgCommon.RestrictFavCheck = SettingDialog.RestrictFavCheck;
7784 _cfgCommon.AlwaysTop = SettingDialog.AlwaysTop;
7785 _cfgCommon.UrlConvertAuto = SettingDialog.UrlConvertAuto;
7786 _cfgCommon.UseUnreadStyle = SettingDialog.UseUnreadStyle;
7787 _cfgCommon.DateTimeFormat = SettingDialog.DateTimeFormat;
7788 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7789 _cfgCommon.RetweetNoConfirm = SettingDialog.RetweetNoConfirm;
7790 _cfgCommon.LimitBalloon = SettingDialog.LimitBalloon;
7791 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7792 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7793 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7794 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7795 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7796 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7797 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7798 _cfgCommon.AutoShortUrlFirst = SettingDialog.AutoShortUrlFirst;
7799 _cfgCommon.TabIconDisp = SettingDialog.TabIconDisp;
7800 _cfgCommon.ReplyIconState = SettingDialog.ReplyIconState;
7801 _cfgCommon.ReadOwnPost = SettingDialog.ReadOwnPost;
7802 _cfgCommon.GetFav = SettingDialog.GetFav;
7803 _cfgCommon.IsMonospace = SettingDialog.IsMonospace;
7804 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7805 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7807 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7809 _cfgCommon.ReadOldPosts = SettingDialog.ReadOldPosts;
7810 _cfgCommon.BilyUser = SettingDialog.BitlyUser;
7811 _cfgCommon.BitlyPwd = SettingDialog.BitlyPwd;
7812 _cfgCommon.ShowGrid = SettingDialog.ShowGrid;
7813 _cfgCommon.UseAtIdSupplement = SettingDialog.UseAtIdSupplement;
7814 _cfgCommon.UseHashSupplement = SettingDialog.UseHashSupplement;
7815 _cfgCommon.PreviewEnable = SettingDialog.PreviewEnable;
7816 _cfgCommon.StatusAreaAtBottom = SettingDialog.StatusAreaAtBottom;
7817 _cfgCommon.Language = SettingDialog.Language;
7819 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7820 switch (_statuses.SortMode)
7822 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7823 _cfgCommon.SortColumn = 1;
7825 case IdComparerClass.ComparerMode.Data: //本文
7826 _cfgCommon.SortColumn = 2;
7828 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7829 _cfgCommon.SortColumn = 3;
7831 case IdComparerClass.ComparerMode.Name: //名前
7832 _cfgCommon.SortColumn = 4;
7834 case IdComparerClass.ComparerMode.Source: //Source
7835 _cfgCommon.SortColumn = 7;
7839 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7840 _cfgCommon.HashTags = HashMgr.HashHistories;
7841 if (HashMgr.IsPermanent)
7843 _cfgCommon.HashSelected = HashMgr.UseHash;
7847 _cfgCommon.HashSelected = "";
7849 _cfgCommon.HashIsHead = HashMgr.IsHead;
7850 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7851 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7852 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7853 _cfgCommon.HotkeyEnabled = SettingDialog.HotkeyEnabled;
7854 _cfgCommon.HotkeyModifier = SettingDialog.HotkeyMod;
7855 _cfgCommon.HotkeyKey = SettingDialog.HotkeyKey;
7856 _cfgCommon.HotkeyValue = SettingDialog.HotkeyValue;
7857 _cfgCommon.BlinkNewMentions = SettingDialog.BlinkNewMentions;
7858 if (ToolStripFocusLockMenuItem != null &&
7859 ToolStripFocusLockMenuItem.IsDisposed == false)
7861 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7863 _cfgCommon.UseAdditionalCount = SettingDialog.UseAdditionalCount;
7864 _cfgCommon.MoreCountApi = SettingDialog.MoreCountApi;
7865 _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi;
7866 _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi;
7867 _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi;
7868 _cfgCommon.UserTimelineCountApi = SettingDialog.UserTimelineCountApi;
7869 _cfgCommon.TrackWord = tw.TrackWord;
7870 _cfgCommon.AllAtReply = tw.AllAtReply;
7871 _cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
7872 _cfgCommon.ListCountApi = SettingDialog.ListCountApi;
7873 _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
7874 _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
7875 _cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
7876 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7877 _cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
7878 _cfgCommon.EnableImgAzyobuziNet = SettingDialog.EnableImgAzyobuziNet;
7879 _cfgCommon.ImgAzyobuziNetDisabledInDM = SettingDialog.ImgAzyobuziNetDisabledInDM;
7880 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7881 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7882 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7883 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7884 _cfgCommon.IsListsIncludeRts = SettingDialog.IsListStatusesIncludeRts;
7885 _cfgCommon.TabMouseLock = SettingDialog.TabMouseLock;
7886 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7887 _cfgCommon.IsUseNotifyGrowl = SettingDialog.IsNotifyUseGrowl;
7893 private void SaveConfigsLocal()
7895 if (_ignoreConfigSave) return;
7898 _modifySettingLocal = false;
7899 _cfgLocal.FormSize = _mySize;
7900 _cfgLocal.FormLocation = _myLoc;
7901 _cfgLocal.SplitterDistance = _mySpDis;
7902 _cfgLocal.PreviewDistance = _mySpDis3;
7903 _cfgLocal.StatusMultiline = StatusText.Multiline;
7904 _cfgLocal.StatusTextHeight = _mySpDis2;
7905 _cfgLocal.StatusText = SettingDialog.Status;
7907 _cfgLocal.FontUnread = _fntUnread;
7908 _cfgLocal.ColorUnread = _clUnread;
7909 _cfgLocal.FontRead = _fntReaded;
7910 _cfgLocal.ColorRead = _clReaded;
7911 _cfgLocal.FontDetail = _fntDetail;
7912 _cfgLocal.ColorDetail = _clDetail;
7913 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7914 _cfgLocal.ColorDetailLink = _clDetailLink;
7915 _cfgLocal.ColorFav = _clFav;
7916 _cfgLocal.ColorOWL = _clOWL;
7917 _cfgLocal.ColorRetweet = _clRetweet;
7918 _cfgLocal.ColorSelf = _clSelf;
7919 _cfgLocal.ColorAtSelf = _clAtSelf;
7920 _cfgLocal.ColorTarget = _clTarget;
7921 _cfgLocal.ColorAtTarget = _clAtTarget;
7922 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7923 _cfgLocal.ColorAtTo = _clAtTo;
7924 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7925 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7926 _cfgLocal.ColorInputFont = _clInputFont;
7927 _cfgLocal.FontInputFont = _fntInputFont;
7929 _cfgLocal.BrowserPath = SettingDialog.BrowserPath;
7930 _cfgLocal.UseRecommendStatus = SettingDialog.UseRecommendStatus;
7931 _cfgLocal.ProxyType = SettingDialog.SelectedProxyType;
7932 _cfgLocal.ProxyAddress = SettingDialog.ProxyAddress;
7933 _cfgLocal.ProxyPort = SettingDialog.ProxyPort;
7934 _cfgLocal.ProxyUser = SettingDialog.ProxyUser;
7935 _cfgLocal.ProxyPassword = SettingDialog.ProxyPassword;
7936 if (_ignoreConfigSave) return;
7941 private void SaveConfigsTabs()
7943 SettingTabs tabSetting = new SettingTabs();
7944 for (int i = 0; i < ListTab.TabPages.Count; i++)
7946 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7951 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7954 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7955 if (ret != DialogResult.OK)
7958 var match = Twitter.StatusUrlRegex.Match(inputText);
7961 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7962 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7966 var statusId = long.Parse(match.Groups["StatusId"].Value);
7968 var post = this._statuses[statusId];
7973 post = await Task.Run(() =>
7975 PostClass newPost = null;
7977 var err = this.tw.GetStatusApi(false, statusId, ref newPost);
7978 if (!string.IsNullOrEmpty(err))
7979 throw new WebApiException(err);
7984 catch (WebApiException ex)
7986 var message = ex.Message;
7987 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7988 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7995 this.OpenRelatedTab(post);
7997 catch (TabException ex)
7999 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
8003 private void SaveLogMenuItem_Click(object sender, EventArgs e)
8005 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
8006 Properties.Resources.SaveLogMenuItem_ClickText2,
8007 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
8008 if (rslt == DialogResult.Cancel) return;
8010 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
8011 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
8012 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
8013 SaveFileDialog1.FilterIndex = 0;
8014 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
8015 SaveFileDialog1.RestoreDirectory = true;
8017 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
8019 if (!SaveFileDialog1.ValidateNames) return;
8020 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
8022 if (rslt == DialogResult.Yes)
8025 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
8027 PostClass post = _statuses[_curTab.Text, idx];
8028 string protect = "";
8029 if (post.IsProtect) protect = "Protect";
8030 sw.WriteLine(post.Nickname + "\t" +
8031 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8032 post.CreatedAt.ToString() + "\t" +
8033 post.ScreenName + "\t" +
8034 post.StatusId.ToString() + "\t" +
8035 post.ImageUrl + "\t" +
8036 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8042 foreach (int idx in _curList.SelectedIndices)
8044 PostClass post = _statuses[_curTab.Text, idx];
8045 string protect = "";
8046 if (post.IsProtect) protect = "Protect";
8047 sw.WriteLine(post.Nickname + "\t" +
8048 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8049 post.CreatedAt.ToString() + "\t" +
8050 post.ScreenName + "\t" +
8051 post.StatusId.ToString() + "\t" +
8052 post.ImageUrl + "\t" +
8053 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8059 this.TopMost = SettingDialog.AlwaysTop;
8062 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
8064 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
8065 if (State == ModifierState.NotFlags) return;
8066 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
8069 e.IsInputKey = true;
8072 public bool TabRename(ref string tabName)
8075 string newTabText = null;
8076 using (InputTabName inputName = new InputTabName())
8078 inputName.TabName = tabName;
8079 inputName.ShowDialog();
8080 if (inputName.DialogResult == DialogResult.Cancel) return false;
8081 newTabText = inputName.TabName;
8083 this.TopMost = SettingDialog.AlwaysTop;
8084 if (!string.IsNullOrEmpty(newTabText))
8087 for (int i = 0; i < ListTab.TabCount; i++)
8089 if (ListTab.TabPages[i].Text == newTabText)
8091 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
8092 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8096 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
8097 for (int i = 0; i < ListTab.TabCount; i++)
8099 if (ListTab.TabPages[i].Text == tabName)
8101 ListTab.TabPages[i].Text = newTabText;
8104 _statuses.RenameTab(tabName, newTabText);
8106 for (int i = 0; i < ListTab.TabCount; i++)
8108 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
8110 if (ListTab.TabPages[i].Text == tabName)
8112 ListTab.TabPages[i].Text = newTabText;
8116 SaveConfigsCommon();
8118 _rclickTabName = newTabText;
8119 tabName = newTabText;
8128 private void ListTab_MouseClick(object sender, MouseEventArgs e)
8130 if (e.Button == MouseButtons.Middle)
8132 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
8134 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8136 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
8137 this.SaveConfigsTabs();
8144 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
8146 string tn = ListTab.SelectedTab.Text;
8150 private void ListTab_MouseDown(object sender, MouseEventArgs e)
8152 if (SettingDialog.TabMouseLock) return;
8153 Point cpos = new Point(e.X, e.Y);
8154 if (e.Button == MouseButtons.Left)
8156 for (int i = 0; i < ListTab.TabPages.Count; i++)
8158 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8161 _tabMouseDownPoint = e.Location;
8172 private void ListTab_DragEnter(object sender, DragEventArgs e)
8174 if (e.Data.GetDataPresent(typeof(TabPage)))
8175 e.Effect = DragDropEffects.Move;
8177 e.Effect = DragDropEffects.None;
8180 private void ListTab_DragDrop(object sender, DragEventArgs e)
8182 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8187 Point cpos = new Point(e.X, e.Y);
8188 Point spos = ListTab.PointToClient(cpos);
8190 for (i = 0; i < ListTab.TabPages.Count; i++)
8192 Rectangle rect = ListTab.GetTabRect(i);
8193 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8194 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8196 tn = ListTab.TabPages[i].Text;
8197 if (spos.X <= (rect.Left + rect.Right) / 2)
8206 //タブのないところにドロップ->最後尾へ移動
8207 if (string.IsNullOrEmpty(tn))
8209 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8211 i = ListTab.TabPages.Count - 1;
8214 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8215 if (tp.Text == tn) return;
8217 ReOrderTab(tp.Text, tn, bef);
8220 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8223 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8225 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8228 using (ControlTransaction.Layout(this.ListTab))
8231 for (int j = 0; j < ListTab.TabPages.Count; j++)
8233 if (ListTab.TabPages[j].Text == targetTabText)
8235 mTp = ListTab.TabPages[j];
8236 ListTab.TabPages.Remove(mTp);
8237 if (j < baseIndex) baseIndex -= 1;
8241 if (isBeforeBaseTab)
8242 ListTab.TabPages.Insert(baseIndex, mTp);
8244 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8250 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8252 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8253 //isReply:true=@,false=DM
8254 if (!StatusText.Enabled) return;
8255 if (_curList == null) return;
8256 if (_curTab == null) return;
8257 if (!this.ExistCurrentPost) return;
8259 // 複数あてリプライはReplyではなく通常ポスト
8260 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8261 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8262 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8264 if (_curList.SelectedIndices.Count > 0)
8267 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8270 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8273 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8274 StatusText.SelectionStart = StatusText.Text.Length;
8276 _reply_to_id = null;
8277 _reply_to_name = null;
8280 if (string.IsNullOrEmpty(StatusText.Text))
8284 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8285 StatusText.Text = "@" + _curPost.ScreenName + " ";
8286 if (_curPost.RetweetedId != null)
8288 _reply_to_id = _curPost.RetweetedId.Value;
8292 _reply_to_id = _curPost.StatusId;
8294 _reply_to_name = _curPost.ScreenName;
8302 //1件選んでEnter or DoubleClick
8303 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8305 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8308 if (_curPost.RetweetedId != null)
8310 _reply_to_id = _curPost.RetweetedId.Value;
8314 _reply_to_id = _curPost.StatusId;
8316 _reply_to_name = _curPost.ScreenName;
8320 if (!StatusText.Text.StartsWith("@"))
8323 if (StatusText.Text.StartsWith(". "))
8326 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8327 _reply_to_id = null;
8328 _reply_to_name = null;
8333 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8334 if (_curPost.RetweetedId != null)
8336 _reply_to_id = _curPost.RetweetedId.Value;
8340 _reply_to_id = _curPost.StatusId;
8342 _reply_to_name = _curPost.ScreenName;
8349 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8350 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8351 _reply_to_id = null;
8352 _reply_to_name = null;
8357 //1件選んでCtrl-Rの場合(返信先操作せず)
8358 int sidx = StatusText.SelectionStart;
8359 string id = "@" + _curPost.ScreenName + " ";
8362 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8367 StatusText.Text = StatusText.Text.Insert(sidx, id);
8369 //if (StatusText.Text.StartsWith("@"))
8372 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8373 // sidx += 5 + _curPost.ScreenName.Length;
8378 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8379 // sidx += 3 + _curPost.ScreenName.Length;
8381 StatusText.SelectionStart = sidx;
8384 //_reply_to_name = null;
8392 if (!isAuto && !isReply) return;
8394 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8398 //Enter or DoubleClick
8400 string sTxt = StatusText.Text;
8401 if (!sTxt.StartsWith(". "))
8404 _reply_to_id = null;
8405 _reply_to_name = null;
8407 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8409 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8410 if (!sTxt.Contains("@" + post.ScreenName + " "))
8412 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8413 //sTxt = "@" + post.ScreenName + " " + sTxt;
8416 StatusText.Text = sTxt;
8421 if (_curList.SelectedIndices.Count > 1)
8426 int sidx = StatusText.SelectionStart;
8427 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8429 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8430 if (!ids.Contains("@" + post.ScreenName + " ") &&
8431 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8433 ids += "@" + post.ScreenName + " ";
8437 foreach (string nm in post.ReplyToList)
8439 if (!ids.Contains("@" + nm + " ") &&
8440 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8442 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8444 ids += "@" + m.Result("${id}") + " ";
8446 ids += "@" + nm + " ";
8451 if (ids.Length == 0) return;
8452 if (!StatusText.Text.StartsWith(". "))
8454 StatusText.Text = ". " + StatusText.Text;
8456 _reply_to_id = null;
8457 _reply_to_name = null;
8461 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8466 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8468 //if (StatusText.Text.StartsWith("@"))
8470 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8471 // sidx += 2 + ids.Length;
8475 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8476 // sidx += 1 + ids.Length;
8478 StatusText.SelectionStart = sidx;
8484 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8487 int sidx = StatusText.SelectionStart;
8488 PostClass post = _curPost;
8489 if (!ids.Contains("@" + post.ScreenName + " ") &&
8490 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8492 ids += "@" + post.ScreenName + " ";
8494 foreach (string nm in post.ReplyToList)
8496 if (!ids.Contains("@" + nm + " ") &&
8497 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8499 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8501 ids += "@" + m.Result("${id}") + " ";
8503 ids += "@" + nm + " ";
8506 if (!string.IsNullOrEmpty(post.RetweetedBy))
8508 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8509 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8511 ids += "@" + post.RetweetedBy + " ";
8514 if (ids.Length == 0) return;
8515 if (string.IsNullOrEmpty(StatusText.Text))
8518 StatusText.Text = ids;
8519 StatusText.SelectionStart = ids.Length;
8521 if (post.RetweetedId != null)
8523 _reply_to_id = post.RetweetedId.Value;
8527 _reply_to_id = post.StatusId;
8529 _reply_to_name = post.ScreenName;
8535 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8540 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8542 StatusText.SelectionStart = sidx;
8548 StatusText.SelectionStart = StatusText.Text.Length;
8553 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8558 private static int iconCnt = 0;
8559 private static int blinkCnt = 0;
8560 private static bool blink = false;
8561 private static bool idle = false;
8563 private void RefreshTasktrayIcon(bool forceRefresh)
8565 if (_colorize) Colorize();
8566 if (!TimerRefreshIcon.Enabled) return;
8567 //Static usCheckCnt As int = 0
8569 //Static iconDlListTopItem As ListViewItem = null
8571 if (forceRefresh) idle = false;
8573 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8574 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8576 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8578 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8584 //if (usCheckCnt > 300) //1min
8587 // if (!this.IsReceivedUserStream)
8589 // TraceOut("ReconnectUserStream");
8590 // tw.ReconnectUserStream();
8595 foreach (BackgroundWorker bw in this._bw)
8597 if (bw != null && bw.IsBusy)
8612 SaveConfigsAll(true);
8617 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8619 _myStatusError = false;
8623 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8624 if (SettingDialog.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8626 if (blinkCnt > 0) return;
8628 if (blink || SettingDialog.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8630 NotifyIcon1.Icon = ReplyIcon;
8634 NotifyIcon1.Icon = ReplyIconBlink;
8642 //優先度:エラー→オフライン→アイドル
8646 NotifyIcon1.Icon = NIconAtRed;
8649 if (_myStatusOnline)
8651 NotifyIcon1.Icon = NIconAt;
8655 NotifyIcon1.Icon = NIconAtSmoke;
8659 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8662 this.RefreshTasktrayIcon(false);
8665 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8667 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8668 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8670 if (ListTab != null && ListTab.SelectedTab != null)
8671 _rclickTabName = ListTab.SelectedTab.Text;
8676 if (_statuses == null) return;
8677 if (_statuses.Tabs == null) return;
8679 TabClass tb = _statuses.Tabs[_rclickTabName];
8680 if (tb == null) return;
8682 NotifyDispMenuItem.Checked = tb.Notify;
8683 this.NotifyTbMenuItem.Checked = tb.Notify;
8685 soundfileListup = true;
8686 SoundFileComboBox.Items.Clear();
8687 this.SoundFileTbComboBox.Items.Clear();
8688 SoundFileComboBox.Items.Add("");
8689 this.SoundFileTbComboBox.Items.Add("");
8690 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8691 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8693 oDir = oDir.GetDirectories("Sounds")[0];
8695 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8697 SoundFileComboBox.Items.Add(oFile.Name);
8698 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8700 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8701 if (idx == -1) idx = 0;
8702 SoundFileComboBox.SelectedIndex = idx;
8703 this.SoundFileTbComboBox.SelectedIndex = idx;
8704 soundfileListup = false;
8705 UreadManageMenuItem.Checked = tb.UnreadManage;
8706 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8708 TabMenuControl(_rclickTabName);
8711 private void TabMenuControl(string tabName)
8713 this.FilterEditMenuItem.Enabled = true;
8714 this.EditRuleTbMenuItem.Enabled = true;
8716 if (_statuses.IsDefaultTab(tabName))
8718 this.ProtectTabMenuItem.Enabled = false;
8719 this.ProtectTbMenuItem.Enabled = false;
8723 this.ProtectTabMenuItem.Enabled = true;
8724 this.ProtectTbMenuItem.Enabled = true;
8727 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8729 this.ProtectTabMenuItem.Checked = true;
8730 this.ProtectTbMenuItem.Checked = true;
8731 this.DeleteTabMenuItem.Enabled = false;
8732 this.DeleteTbMenuItem.Enabled = false;
8736 this.ProtectTabMenuItem.Checked = false;
8737 this.ProtectTbMenuItem.Checked = false;
8738 this.DeleteTabMenuItem.Enabled = true;
8739 this.DeleteTbMenuItem.Enabled = true;
8743 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8745 var checkState = ((ToolStripMenuItem)sender).Checked;
8748 this.ProtectTbMenuItem.Checked = checkState;
8749 this.ProtectTabMenuItem.Checked = checkState;
8752 this.DeleteTabMenuItem.Enabled = !checkState;
8753 this.DeleteTbMenuItem.Enabled = !checkState;
8755 if (string.IsNullOrEmpty(_rclickTabName)) return;
8756 _statuses.Tabs[_rclickTabName].Protected = checkState;
8761 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8763 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8764 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8766 if (string.IsNullOrEmpty(_rclickTabName)) return;
8767 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8772 public void ChangeTabUnreadManage(string tabName, bool isManage)
8775 for (idx = 0; idx < ListTab.TabCount; idx++)
8777 if (ListTab.TabPages[idx].Text == tabName) break;
8780 _statuses.SetTabUnreadManage(tabName, isManage);
8781 if (SettingDialog.TabIconDisp)
8783 if (_statuses.Tabs[tabName].UnreadCount > 0)
8784 ListTab.TabPages[idx].ImageIndex = 0;
8786 ListTab.TabPages[idx].ImageIndex = -1;
8789 if (_curTab.Text == tabName)
8791 this.PurgeListViewItemCache();
8795 SetMainWindowTitle();
8796 SetStatusLabelUrl();
8797 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8800 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8802 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8803 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8805 if (string.IsNullOrEmpty(_rclickTabName)) return;
8807 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8812 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8814 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8816 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8821 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8823 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8825 RemoveSpecifiedTab(_rclickTabName, true);
8829 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8831 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8832 fltDialog.SetCurrent(_rclickTabName);
8833 fltDialog.ShowDialog(this);
8834 this.TopMost = SettingDialog.AlwaysTop;
8836 this.ApplyPostFilters();
8840 private void AddTabMenuItem_Click(object sender, EventArgs e)
8842 string tabName = null;
8843 MyCommon.TabUsageType tabUsage;
8844 using (InputTabName inputName = new InputTabName())
8846 inputName.TabName = _statuses.GetUniqueTabName();
8847 inputName.IsShowUsage = true;
8848 inputName.ShowDialog();
8849 if (inputName.DialogResult == DialogResult.Cancel) return;
8850 tabName = inputName.TabName;
8851 tabUsage = inputName.Usage;
8853 this.TopMost = SettingDialog.AlwaysTop;
8854 if (!string.IsNullOrEmpty(tabName))
8857 ListElement list = null;
8858 if (tabUsage == MyCommon.TabUsageType.Lists)
8860 using (ListAvailable listAvail = new ListAvailable())
8862 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8863 if (listAvail.SelectedList == null) return;
8864 list = listAvail.SelectedList;
8867 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8869 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8870 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8876 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8878 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8879 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8880 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8882 if (tabUsage == MyCommon.TabUsageType.Lists)
8884 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8885 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8886 GetTimeline(MyCommon.WORKERTYPE.List, 1, tabName);
8892 private void TabMenuItem_Click(object sender, EventArgs e)
8895 foreach (int idx in _curList.SelectedIndices)
8899 if (!SelectTab(out tabName)) return;
8901 fltDialog.SetCurrent(tabName);
8902 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8904 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8908 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8910 fltDialog.ShowDialog(this);
8911 this.TopMost = SettingDialog.AlwaysTop;
8914 this.ApplyPostFilters();
8916 if (this.ListTab.SelectedTab != null &&
8917 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8919 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8923 protected override bool ProcessDialogKey(Keys keyData)
8925 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8926 if ((keyData & Keys.KeyCode) == Keys.Enter)
8928 if (StatusText.Focused)
8930 bool _NewLine = false;
8933 if (SettingDialog.PostCtrlEnter) //Ctrl+Enter投稿時
8935 if (StatusText.Multiline)
8937 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8939 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8943 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8947 else if (SettingDialog.PostShiftEnter) //SHift+Enter投稿時
8949 if (StatusText.Multiline)
8951 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8953 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8957 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8963 if (StatusText.Multiline)
8965 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8967 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8968 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8972 if (((keyData & Keys.Shift) == Keys.Shift) ||
8973 (((keyData & Keys.Control) != Keys.Control) &&
8974 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8980 int pos1 = StatusText.SelectionStart;
8981 if (StatusText.SelectionLength > 0)
8983 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8985 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8986 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8991 PostButton_Click(null, null);
8995 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8996 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8997 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8999 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
9004 return base.ProcessDialogKey(keyData);
9007 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
9009 MakeReplyOrDirectStatus(false, true, true);
9012 private void IDRuleMenuItem_Click(object sender, EventArgs e)
9017 if (_curList.SelectedIndices.Count == 0) return;
9020 if (!SelectTab(out tabName)) return;
9024 MoveOrCopy(ref mv, ref mk);
9026 List<string> ids = new List<string>();
9027 foreach (int idx in _curList.SelectedIndices)
9029 PostClass post = _statuses[_curTab.Text, idx];
9030 if (!ids.Contains(post.ScreenName))
9032 PostFilterRule fc = new PostFilterRule();
9033 ids.Add(post.ScreenName);
9034 if (post.RetweetedId == null)
9036 fc.FilterName = post.ScreenName;
9040 fc.FilterName = post.RetweetedBy;
9042 fc.UseNameField = true;
9043 fc.MoveMatches = mv;
9044 fc.MarkMatches = mk;
9045 fc.UseRegex = false;
9046 fc.FilterByUrl = false;
9047 _statuses.Tabs[tabName].AddFilter(fc);
9052 List<string> atids = new List<string>();
9053 foreach (string id in ids)
9055 atids.Add("@" + id);
9057 int cnt = AtIdSupl.ItemCount;
9058 AtIdSupl.AddRangeItem(atids.ToArray());
9059 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
9062 this.ApplyPostFilters();
9066 private bool SelectTab(out string tabName)
9073 using (var dialog = new TabsDialog(_statuses))
9075 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
9077 var selectedTab = dialog.SelectedTab;
9078 tabName = selectedTab == null ? null : selectedTab.TabName;
9081 ListTab.SelectedTab.Focus();
9083 if (tabName == null)
9085 using (InputTabName inputName = new InputTabName())
9087 inputName.TabName = _statuses.GetUniqueTabName();
9088 inputName.ShowDialog();
9089 if (inputName.DialogResult == DialogResult.Cancel) return false;
9090 tabName = inputName.TabName;
9092 this.TopMost = SettingDialog.AlwaysTop;
9093 if (!string.IsNullOrEmpty(tabName))
9095 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
9097 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
9098 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
9116 private void MoveOrCopy(ref bool move, ref bool mark)
9120 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
9121 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9129 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
9130 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9136 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
9141 private void CopyURLMenuItem_Click(object sender, EventArgs e)
9146 private void SelectAllMenuItem_Click(object sender, EventArgs e)
9148 if (StatusText.Focused)
9151 StatusText.SelectAll();
9155 // ListView上でのCtrl+A
9156 for (int i = 0; i < _curList.VirtualListSize; i++)
9158 _curList.SelectedIndices.Add(i);
9163 private void MoveMiddle()
9169 if (_curList.SelectedIndices.Count == 0) return;
9171 int idx = _curList.SelectedIndices[0];
9173 _item = _curList.GetItemAt(0, 25);
9179 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9181 idx2 = _curList.VirtualListSize - 1;
9185 idx -= Math.Abs(idx1 - idx2) / 2;
9186 if (idx < 0) idx = 0;
9188 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9189 _curList.EnsureVisible(idx);
9192 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9194 if (PostBrowser.Document.Links.Count > 0)
9196 UrlDialog.ClearUrl();
9198 string openUrlStr = "";
9200 if (PostBrowser.Document.Links.Count == 1)
9205 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9207 catch (ArgumentException)
9216 if (string.IsNullOrEmpty(urlStr)) return;
9217 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9221 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9224 string linkText = "";
9228 urlStr = linkElm.GetAttribute("title");
9229 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9230 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9231 linkText = linkElm.InnerText;
9232 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9234 linkText = "@" + linkText;
9237 catch (ArgumentException)
9246 if (string.IsNullOrEmpty(urlStr)) continue;
9247 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9251 if (UrlDialog.ShowDialog() == DialogResult.OK)
9253 openUrlStr = UrlDialog.SelectedUrl;
9260 this.TopMost = SettingDialog.AlwaysTop;
9262 if (string.IsNullOrEmpty(openUrlStr)) return;
9264 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9265 openUrlStr.StartsWith("https://twitter.com/search?q="))
9268 string urlStr = Uri.UnescapeDataString(openUrlStr);
9269 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9270 HashSupl.AddItem(hash);
9271 HashMgr.AddHashToHistory(hash.Trim(), false);
9272 AddNewTabForSearch(hash);
9277 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9278 if (SettingDialog.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9279 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9281 OpenUriAsync(openUrlStr);
9287 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9289 if (string.IsNullOrEmpty(_rclickTabName)) return;
9290 ClearTab(_rclickTabName, true);
9293 private void ClearTab(string tabName, bool showWarning)
9297 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9298 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9304 _statuses.ClearTabIds(tabName);
9305 if (ListTab.SelectedTab.Text == tabName)
9308 _anchorFlag = false;
9309 this.PurgeListViewItemCache();
9313 foreach (TabPage tb in ListTab.TabPages)
9315 if (tb.Text == tabName)
9318 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9322 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9324 SetMainWindowTitle();
9325 SetStatusLabelUrl();
9328 private static long followers = 0;
9330 private void SetMainWindowTitle()
9333 StringBuilder ttl = new StringBuilder(256);
9336 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
9337 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9338 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9339 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9341 foreach (var tab in _statuses.Tabs.Values)
9343 ur += tab.UnreadCount;
9348 if (SettingDialog.DispUsername) ttl.Append(tw.Username).Append(" - ");
9349 ttl.Append(Application.ProductName);
9351 switch (SettingDialog.DispLatestPost)
9353 case MyCommon.DispTitleEnum.Ver:
9354 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9356 case MyCommon.DispTitleEnum.Post:
9357 if (_history != null && _history.Count > 1)
9358 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9360 case MyCommon.DispTitleEnum.UnreadRepCount:
9361 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9363 case MyCommon.DispTitleEnum.UnreadAllCount:
9364 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9366 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9367 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9369 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9370 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9372 case MyCommon.DispTitleEnum.OwnStatus:
9373 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9374 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9380 this.Text = ttl.ToString();
9382 catch (AccessViolationException)
9384 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9388 private string GetStatusLabelText()
9391 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9392 if (_statuses == null) return "";
9393 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9394 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9395 if (tbRep == null || tbDm == null) return "";
9396 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9401 StringBuilder slbl = new StringBuilder(256);
9404 foreach (var tab in _statuses.Tabs.Values)
9406 ur += tab.UnreadCount;
9408 if (_curTab != null && tab.TabName.Equals(_curTab.Text))
9410 tur = tab.UnreadCount;
9421 UnreadAtCounter = urat;
9423 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9424 if (SettingDialog.TimelinePeriodInt == 0)
9426 slbl.Append(Properties.Resources.SetStatusLabelText2);
9430 slbl.Append(SettingDialog.TimelinePeriodInt.ToString() + Properties.Resources.SetStatusLabelText3);
9432 return slbl.ToString();
9435 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9439 if (this.InvokeRequired && !this.IsDisposed)
9441 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9445 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9446 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9448 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9452 catch (ObjectDisposedException)
9456 catch (InvalidOperationException)
9462 private void SetStatusLabelUrl()
9464 StatusLabelUrl.Text = GetStatusLabelText();
9467 public void SetStatusLabel(string text)
9469 StatusLabel.Text = text;
9472 private static StringBuilder ur = new StringBuilder(64);
9474 private void SetNotifyIconText()
9476 // タスクトレイアイコンのツールチップテキスト書き換え
9478 ur.Remove(0, ur.Length);
9479 if (SettingDialog.DispUsername)
9481 ur.Append(tw.Username);
9484 ur.Append(Application.ProductName);
9486 ur.Append("(Debug Build)");
9488 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9491 ur.Append(UnreadCounter);
9493 ur.Append(UnreadAtCounter);
9496 NotifyIcon1.Text = ur.ToString();
9499 internal void CheckReplyTo(string StatusText)
9503 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9505 foreach (Match hm in m)
9507 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9509 hstr += "#" + hm.Result("$3") + " ";
9510 HashSupl.AddItem("#" + hm.Result("$3"));
9513 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9515 hstr += HashMgr.UseHash;
9517 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9519 // 本当にリプライ先指定すべきかどうかの判定
9520 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9522 if (SettingDialog.UseAtIdSupplement)
9524 int bCnt = AtIdSupl.ItemCount;
9525 foreach (Match mid in m)
9527 AtIdSupl.AddItem(mid.Result("${id}"));
9529 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9532 // リプライ先ステータスIDの指定がない場合は指定しない
9533 if (_reply_to_id == null) return;
9535 // リプライ先ユーザー名がない場合も指定しない
9536 if (string.IsNullOrEmpty(_reply_to_name))
9538 _reply_to_id = null;
9543 // 次の条件を満たす場合に in_reply_to_status_id 指定
9544 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9545 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9546 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9550 if (StatusText.StartsWith("@"))
9552 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9556 foreach (Match mid in m)
9558 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9563 _reply_to_id = null;
9564 _reply_to_name = null;
9568 private void TweenMain_Resize(object sender, EventArgs e)
9570 if (!_initialLayout && SettingDialog.MinimizeToTray && WindowState == FormWindowState.Minimized)
9572 this.Visible = false;
9574 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9576 this.ClientSize = _cfgLocal.FormSize;
9577 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9578 this.DesktopLocation = _cfgLocal.FormLocation;
9579 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9580 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9581 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9583 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9586 StatusText.Multiline = _cfgLocal.StatusMultiline;
9587 if (StatusText.Multiline)
9589 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9590 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9592 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9594 StatusText.Height = _cfgLocal.StatusTextHeight;
9598 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9600 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9603 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9605 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9607 _initialLayout = false;
9609 if (this.WindowState != FormWindowState.Minimized)
9611 _formWindowState = this.WindowState;
9615 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9617 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9618 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9619 if (PlaySoundMenuItem.Checked)
9621 SettingDialog.PlaySound = true;
9625 SettingDialog.PlaySound = false;
9627 _modifySettingCommon = true;
9630 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9632 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9634 _mySpDis = SplitContainer1.SplitterDistance;
9635 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9636 _modifySettingLocal = true;
9640 private void doRepliedStatusOpen()
9642 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9644 if (MyCommon.IsKeyDown(Keys.Shift))
9646 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9649 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9651 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9652 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9656 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9658 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9659 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9660 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9663 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9668 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9670 doRepliedStatusOpen();
9674 /// UserPicture.Image に設定されている画像を破棄します。
9676 private void ClearUserPicture()
9678 if (this.UserPicture.Image != null)
9680 var oldImage = this.UserPicture.Image;
9681 this.UserPicture.Image = null;
9686 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9688 //発言詳細のアイコン右クリック時のメニュー制御
9689 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9691 string name = _curPost.ImageUrl;
9692 if (name != null && name.Length > 0)
9694 int idx = name.LastIndexOf('/');
9697 name = Path.GetFileName(name.Substring(idx));
9698 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9700 name = name.Replace("_normal", "");
9701 this.IconNameToolStripMenuItem.Text = name;
9702 this.IconNameToolStripMenuItem.Enabled = true;
9706 this.IconNameToolStripMenuItem.Enabled = false;
9707 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9712 this.IconNameToolStripMenuItem.Enabled = false;
9713 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9716 this.ReloadIconToolStripMenuItem.Enabled = true;
9718 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9720 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9724 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9729 this.IconNameToolStripMenuItem.Enabled = false;
9730 this.ReloadIconToolStripMenuItem.Enabled = false;
9731 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9732 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9737 this.IconNameToolStripMenuItem.Enabled = false;
9738 this.ReloadIconToolStripMenuItem.Enabled = false;
9739 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9740 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9742 if (NameLabel.Tag != null)
9744 string id = (string)NameLabel.Tag;
9745 if (id == tw.Username)
9747 FollowToolStripMenuItem.Enabled = false;
9748 UnFollowToolStripMenuItem.Enabled = false;
9749 ShowFriendShipToolStripMenuItem.Enabled = false;
9750 ShowUserStatusToolStripMenuItem.Enabled = true;
9751 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9752 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9753 ListManageUserContextToolStripMenuItem3.Enabled = true;
9757 FollowToolStripMenuItem.Enabled = true;
9758 UnFollowToolStripMenuItem.Enabled = true;
9759 ShowFriendShipToolStripMenuItem.Enabled = true;
9760 ShowUserStatusToolStripMenuItem.Enabled = true;
9761 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9762 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9763 ListManageUserContextToolStripMenuItem3.Enabled = true;
9768 FollowToolStripMenuItem.Enabled = false;
9769 UnFollowToolStripMenuItem.Enabled = false;
9770 ShowFriendShipToolStripMenuItem.Enabled = false;
9771 ShowUserStatusToolStripMenuItem.Enabled = false;
9772 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9773 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9774 ListManageUserContextToolStripMenuItem3.Enabled = false;
9778 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9780 if (_curPost == null) return;
9781 string name = _curPost.ImageUrl;
9782 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9785 private async void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9787 if (this._curPost == null) return;
9789 await this.UserPicture.SetImageFromTask(async () =>
9791 var imageUrl = this._curPost.ImageUrl;
9793 var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
9794 .ConfigureAwait(false);
9796 return await image.CloneAsync()
9797 .ConfigureAwait(false);
9801 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9803 if (_curPost == null) return;
9804 string name = _curPost.ImageUrl;
9805 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9807 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9809 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9815 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9817 if (_curPost == null) return;
9818 string name = _curPost.ImageUrl;
9820 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9822 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9826 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9828 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9830 using (Graphics g = Graphics.FromImage(bmp2))
9832 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9833 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9835 bmp2.Save(this.SaveFileDialog1.FileName);
9841 //処理中にキャッシュアウトする可能性あり
9846 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9848 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9849 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9850 _modifySettingLocal = true;
9853 private void StatusText_MultilineChanged(object sender, EventArgs e)
9855 if (this.StatusText.Multiline)
9856 this.StatusText.ScrollBars = ScrollBars.Vertical;
9858 this.StatusText.ScrollBars = ScrollBars.None;
9860 _modifySettingLocal = true;
9863 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9866 StatusText.Multiline = MultiLineMenuItem.Checked;
9867 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9868 if (MultiLineMenuItem.Checked)
9870 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9871 SplitContainer2.SplitterDistance = 0;
9873 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9877 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9879 _modifySettingLocal = true;
9882 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
9884 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9885 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9887 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9888 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9889 //Appendix A. Collected ABNF for URI
9890 //http://www.ietf.org/rfc/rfc3986.txt
9894 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9896 if (StatusText.SelectionLength > 0)
9898 string tmp = StatusText.SelectedText;
9899 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9900 if (tmp.StartsWith("http"))
9902 // 文字列が選択されている場合はその文字列について処理
9904 //nico.ms使用、nicovideoにマッチしたら変換
9905 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9907 result = nicoms.Shorten(tmp);
9909 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9911 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9914 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9915 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9916 result = resultUri.ToString();
9918 catch (WebApiException e)
9920 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9923 catch (UriFormatException e)
9925 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9934 if (!string.IsNullOrEmpty(result))
9936 urlUndo undotmp = new urlUndo();
9938 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9939 StatusText.SelectedText = result;
9942 undotmp.Before = tmp;
9943 undotmp.After = result;
9945 if (urlUndoBuffer == null)
9947 urlUndoBuffer = new List<urlUndo>();
9948 UrlUndoToolStripMenuItem.Enabled = true;
9951 urlUndoBuffer.Add(undotmp);
9957 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9958 @"(?<url>(?<protocol>https?://)" +
9959 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9960 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9961 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9962 // 正規表現にマッチしたURL文字列をtinyurl化
9963 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9965 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9966 string tmp = mt.Result("${url}");
9967 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9968 urlUndo undotmp = new urlUndo();
9971 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9973 //nico.ms使用、nicovideoにマッチしたら変換
9974 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9976 result = nicoms.Shorten(tmp);
9978 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9980 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9983 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9984 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9985 result = resultUri.ToString();
9987 catch (HttpRequestException e)
9989 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
9990 // のように長いので「:」が含まれていればそれ以降のみを抽出する
9991 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
9993 this.StatusLabel.Text = Converter_Type + ":" + message;
9996 catch (WebApiException e)
9998 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
10001 catch (UriFormatException e)
10003 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
10012 if (!string.IsNullOrEmpty(result))
10014 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
10015 StatusText.SelectedText = result;
10017 undotmp.Before = mt.Result("${url}");
10018 undotmp.After = result;
10020 if (urlUndoBuffer == null)
10022 urlUndoBuffer = new List<urlUndo>();
10023 UrlUndoToolStripMenuItem.Enabled = true;
10026 urlUndoBuffer.Add(undotmp);
10034 private void doUrlUndo()
10036 if (urlUndoBuffer != null)
10038 string tmp = StatusText.Text;
10039 foreach (urlUndo data in urlUndoBuffer)
10041 tmp = tmp.Replace(data.After, data.Before);
10043 StatusText.Text = tmp;
10044 urlUndoBuffer = null;
10045 UrlUndoToolStripMenuItem.Enabled = false;
10046 StatusText.SelectionStart = 0;
10047 StatusText.SelectionLength = 0;
10051 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
10053 await UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
10056 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
10058 await UrlConvertAsync(MyCommon.UrlConverter.Isgd);
10061 private async void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
10063 await UrlConvertAsync(MyCommon.UrlConverter.Twurl);
10066 private async void UxnuMenuItem_Click(object sender, EventArgs e)
10068 await UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
10071 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
10073 if (!await UrlConvertAsync(SettingDialog.AutoShortUrlFirst))
10075 MyCommon.UrlConverter svc = SettingDialog.AutoShortUrlFirst;
10076 Random rnd = new Random();
10077 // 前回使用した短縮URLサービス以外を選択する
10080 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
10082 while (svc == SettingDialog.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
10083 await UrlConvertAsync(svc);
10087 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
10092 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
10094 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10095 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
10096 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
10097 _modifySettingCommon = true;
10100 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
10102 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10103 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
10104 _cfgCommon.ListLock = ListLockMenuItem.Checked;
10105 _modifySettingCommon = true;
10108 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
10110 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
10111 MenuStrip1.Tag = new Object();
10112 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
10115 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
10117 if (this.Tag != null) // 設定された戻り先へ遷移
10119 if (this.Tag == this.ListTab.SelectedTab)
10120 ((Control)this.ListTab.SelectedTab.Tag).Select();
10122 ((Control)this.Tag).Select();
10124 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
10126 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
10128 this.Tag = ListTab.SelectedTab.Tag;
10129 ((Control)this.Tag).Select();
10132 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
10133 MenuStrip1.Tag = null;
10136 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
10138 DetailsListView lst = (DetailsListView)sender;
10139 if (_cfgLocal == null) return;
10143 _cfgLocal.Width1 = lst.Columns[0].Width;
10144 _cfgLocal.Width3 = lst.Columns[1].Width;
10148 int[] darr = new int[lst.Columns.Count];
10149 for (int i = 0; i < lst.Columns.Count; i++)
10151 darr[lst.Columns[i].DisplayIndex] = i;
10153 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
10155 for (int i = 0; i < lst.Columns.Count; i++)
10160 _cfgLocal.DisplayIndex1 = i;
10163 _cfgLocal.DisplayIndex2 = i;
10166 _cfgLocal.DisplayIndex3 = i;
10169 _cfgLocal.DisplayIndex4 = i;
10172 _cfgLocal.DisplayIndex5 = i;
10175 _cfgLocal.DisplayIndex6 = i;
10178 _cfgLocal.DisplayIndex7 = i;
10181 _cfgLocal.DisplayIndex8 = i;
10185 _cfgLocal.Width1 = lst.Columns[0].Width;
10186 _cfgLocal.Width2 = lst.Columns[1].Width;
10187 _cfgLocal.Width3 = lst.Columns[2].Width;
10188 _cfgLocal.Width4 = lst.Columns[3].Width;
10189 _cfgLocal.Width5 = lst.Columns[4].Width;
10190 _cfgLocal.Width6 = lst.Columns[5].Width;
10191 _cfgLocal.Width7 = lst.Columns[6].Width;
10192 _cfgLocal.Width8 = lst.Columns[7].Width;
10194 _modifySettingLocal = true;
10195 _isColumnChanged = true;
10198 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10200 DetailsListView lst = (DetailsListView)sender;
10201 if (_cfgLocal == null) return;
10204 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10206 _cfgLocal.Width1 = lst.Columns[0].Width;
10207 _modifySettingLocal = true;
10208 _isColumnChanged = true;
10210 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10212 _cfgLocal.Width3 = lst.Columns[1].Width;
10213 _modifySettingLocal = true;
10214 _isColumnChanged = true;
10219 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10221 _cfgLocal.Width1 = lst.Columns[0].Width;
10222 _modifySettingLocal = true;
10223 _isColumnChanged = true;
10225 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10227 _cfgLocal.Width2 = lst.Columns[1].Width;
10228 _modifySettingLocal = true;
10229 _isColumnChanged = true;
10231 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10233 _cfgLocal.Width3 = lst.Columns[2].Width;
10234 _modifySettingLocal = true;
10235 _isColumnChanged = true;
10237 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10239 _cfgLocal.Width4 = lst.Columns[3].Width;
10240 _modifySettingLocal = true;
10241 _isColumnChanged = true;
10243 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10245 _cfgLocal.Width5 = lst.Columns[4].Width;
10246 _modifySettingLocal = true;
10247 _isColumnChanged = true;
10249 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10251 _cfgLocal.Width6 = lst.Columns[5].Width;
10252 _modifySettingLocal = true;
10253 _isColumnChanged = true;
10255 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10257 _cfgLocal.Width7 = lst.Columns[6].Width;
10258 _modifySettingLocal = true;
10259 _isColumnChanged = true;
10261 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10263 _cfgLocal.Width8 = lst.Columns[7].Width;
10264 _modifySettingLocal = true;
10265 _isColumnChanged = true;
10268 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10271 // SaveConfigsLocal();
10275 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10277 //発言詳細で「選択文字列をコピー」を行う
10278 //WebBrowserコンポーネントのインスタンスを渡す
10279 Type typ = ComponentInstance.ActiveXInstance.GetType();
10280 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10281 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10282 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10285 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10288 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10291 Clipboard.SetDataObject(_selText, false, 5, 100);
10293 catch (Exception ex)
10295 MessageBox.Show(ex.Message);
10299 private void doSearchToolStrip(string url)
10301 //発言詳細で「選択文字列で検索」(選択文字列取得)
10302 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10304 if (_selText != null)
10306 if (url == Properties.Resources.SearchItem4Url)
10309 AddNewTabForSearch(_selText);
10313 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10318 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10321 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10324 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10326 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10329 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10331 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10334 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10336 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10339 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10343 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10344 foreach (Match m in mc)
10346 if (m.Groups["url"].Value == this._postBrowserStatusText)
10348 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10354 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10356 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10358 catch (Exception ex)
10360 MessageBox.Show(ex.Message);
10364 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10366 // URLコピーの項目の表示/非表示
10367 if (PostBrowser.StatusText.StartsWith("http"))
10369 this._postBrowserStatusText = PostBrowser.StatusText;
10370 string name = GetUserId();
10371 UrlCopyContextMenuItem.Enabled = true;
10374 FollowContextMenuItem.Enabled = true;
10375 RemoveContextMenuItem.Enabled = true;
10376 FriendshipContextMenuItem.Enabled = true;
10377 ShowUserStatusContextMenuItem.Enabled = true;
10378 SearchPostsDetailToolStripMenuItem.Enabled = true;
10379 IdFilterAddMenuItem.Enabled = true;
10380 ListManageUserContextToolStripMenuItem.Enabled = true;
10381 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10385 FollowContextMenuItem.Enabled = false;
10386 RemoveContextMenuItem.Enabled = false;
10387 FriendshipContextMenuItem.Enabled = false;
10388 ShowUserStatusContextMenuItem.Enabled = false;
10389 SearchPostsDetailToolStripMenuItem.Enabled = false;
10390 IdFilterAddMenuItem.Enabled = false;
10391 ListManageUserContextToolStripMenuItem.Enabled = false;
10392 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10395 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10396 UseHashtagMenuItem.Enabled = true;
10398 UseHashtagMenuItem.Enabled = false;
10402 this._postBrowserStatusText = "";
10403 UrlCopyContextMenuItem.Enabled = false;
10404 FollowContextMenuItem.Enabled = false;
10405 RemoveContextMenuItem.Enabled = false;
10406 FriendshipContextMenuItem.Enabled = false;
10407 ShowUserStatusContextMenuItem.Enabled = false;
10408 SearchPostsDetailToolStripMenuItem.Enabled = false;
10409 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10410 UseHashtagMenuItem.Enabled = false;
10411 IdFilterAddMenuItem.Enabled = false;
10412 ListManageUserContextToolStripMenuItem.Enabled = false;
10414 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10415 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10416 if (_selText == null)
10418 SelectionSearchContextMenuItem.Enabled = false;
10419 SelectionCopyContextMenuItem.Enabled = false;
10420 SelectionTranslationToolStripMenuItem.Enabled = false;
10424 SelectionSearchContextMenuItem.Enabled = true;
10425 SelectionCopyContextMenuItem.Enabled = true;
10426 SelectionTranslationToolStripMenuItem.Enabled = true;
10428 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10429 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10430 bool fAllFlag = false;
10431 foreach (Match mu in ma)
10433 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10439 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10441 if (_curPost == null)
10442 TranslationToolStripMenuItem.Enabled = false;
10444 TranslationToolStripMenuItem.Enabled = true;
10449 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10451 //発言詳細の選択文字列で現在のタブを検索
10452 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10454 if (_selText != null)
10456 var searchOptions = new SearchWordDialog.SearchOptions(
10457 SearchWordDialog.SearchType.Timeline,
10460 caseSensitive: false,
10463 this.SearchDialog.ResultOptions = searchOptions;
10466 searchOptions.Query,
10467 searchOptions.CaseSensitive,
10468 searchOptions.UseRegex,
10469 SEARCHTYPE.NextSearch);
10473 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10475 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10476 _modifySettingLocal = true;
10479 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10481 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10483 SelectMedia_DragDrop(e);
10485 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10487 var url = GetUrlFromDataObject(e.Data);
10490 if (url.Item2 == null)
10491 appendText = url.Item1;
10493 appendText = url.Item2 + " " + url.Item1;
10495 if (this.StatusText.TextLength == 0)
10496 this.StatusText.Text = appendText;
10498 this.StatusText.Text += " " + appendText;
10500 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10502 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10503 if (data != null) StatusText.Text += data;
10508 /// IDataObject から URL とタイトルの対を取得します
10511 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10513 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10514 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10515 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10517 if (data.GetDataPresent("text/x-moz-url"))
10519 // Firefox, Google Chrome で利用可能
10520 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10522 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10524 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10525 if (lines.Length < 2)
10526 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10528 return new Tuple<string, string>(lines[0], lines[1]);
10531 else if (data.GetDataPresent("IESiteModeToUrl"))
10533 // Internet Exproler 用
10534 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10536 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10538 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10539 if (lines.Length < 2)
10540 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10542 return new Tuple<string, string>(lines[0], lines[1]);
10545 else if (data.GetDataPresent("UniformResourceLocatorW"))
10549 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10551 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10552 return new Tuple<string, string>(url, null);
10556 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10559 private void TweenMain_DragEnter(object sender, DragEventArgs e)
10561 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10563 SelectMedia_DragEnter(e);
10567 private void TweenMain_DragOver(object sender, DragEventArgs e)
10569 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10571 SelectMedia_DragOver(e);
10573 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10575 e.Effect = DragDropEffects.Copy;
10577 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10579 e.Effect = DragDropEffects.Copy;
10583 e.Effect = DragDropEffects.None;
10587 public bool IsNetworkAvailable()
10590 nw = MyCommon.IsNetworkAvailable();
10591 _myStatusOnline = nw;
10595 public Task OpenUriAsync(string UriString)
10597 return Task.Run(() =>
10599 string myPath = UriString;
10603 var configBrowserPath = SettingDialog.BrowserPath;
10604 if (!string.IsNullOrEmpty(configBrowserPath))
10606 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10608 int sep = configBrowserPath.IndexOf("\"", 2);
10609 string browserPath = configBrowserPath.Substring(1, sep - 1);
10611 if (sep < configBrowserPath.Length - 1)
10613 arg = configBrowserPath.Substring(sep + 1);
10615 myPath = arg + " " + myPath;
10616 System.Diagnostics.Process.Start(browserPath, myPath);
10620 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10625 System.Diagnostics.Process.Start(myPath);
10630 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10635 private void ListTabSelect(TabPage _tab)
10639 this.PurgeListViewItemCache();
10642 _curList = (DetailsListView)_tab.Tag;
10643 if (_curList.SelectedIndices.Count > 0)
10645 _curItemIndex = _curList.SelectedIndices[0];
10646 _curPost = GetCurTabPost(_curItemIndex);
10650 _curItemIndex = -1;
10654 _anchorPost = null;
10655 _anchorFlag = false;
10659 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10663 for (int i = 0; i < _curList.Columns.Count; i++)
10665 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10670 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10672 ListTabSelect(e.TabPage);
10675 private void SelectListItem(DetailsListView LView, int Index)
10678 Rectangle bnd = new Rectangle();
10680 var item = LView.FocusedItem;
10689 LView.SelectedIndices.Clear();
10691 while (LView.SelectedIndices.Count > 0);
10692 item = LView.Items[Index];
10693 item.Selected = true;
10694 item.Focused = true;
10696 if (flg) LView.Invalidate(bnd);
10699 private void SelectListItem(DetailsListView LView , int[] Index, int[] FocusedIndex)
10702 Rectangle bnd = new Rectangle();
10704 var item = LView.FocusedItem;
10712 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10716 LView.SelectedIndices.Clear();
10718 while (LView.SelectedIndices.Count > 0);
10719 foreach (int idx in Index)
10721 if (idx > -1 && LView.VirtualListSize > idx)
10723 LView.SelectedIndices.Add(idx);
10724 if (fIdx == -1) fIdx = idx;
10728 if (FocusedIndex[1] > -1 && LView.VirtualListSize > FocusedIndex[1])
10730 LView.SelectionMark = FocusedIndex[1];
10732 if (FocusedIndex[0] > -1 && LView.VirtualListSize > FocusedIndex[0])
10734 LView.Items[FocusedIndex[0]].Focused = true;
10736 else if (fIdx > -1)
10738 LView.Items[fIdx].Focused = true;
10741 if (flg) LView.Invalidate(bnd);
10744 private void RunAsync(GetWorkerArg args)
10746 BackgroundWorker bw = null;
10747 if (args.type != MyCommon.WORKERTYPE.Follower)
10749 for (int i = 0; i < _bw.Length; i++)
10751 if (_bw[i] != null && !_bw[i].IsBusy)
10759 for (int i = 0; i < _bw.Length; i++)
10761 if (_bw[i] == null)
10763 _bw[i] = new BackgroundWorker();
10765 bw.WorkerReportsProgress = true;
10766 bw.WorkerSupportsCancellation = true;
10767 bw.DoWork += GetTimelineWorker_DoWork;
10768 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10769 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10777 if (_bwFollower == null)
10779 _bwFollower = new BackgroundWorker();
10781 bw.WorkerReportsProgress = true;
10782 bw.WorkerSupportsCancellation = true;
10783 bw.DoWork += GetTimelineWorker_DoWork;
10784 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10785 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10789 if (_bwFollower.IsBusy == false)
10793 if (bw == null) return;
10795 bw.RunWorkerAsync(args);
10798 private void StartUserStream()
10800 tw.NewPostFromStream += tw_NewPostFromStream;
10801 tw.UserStreamStarted += tw_UserStreamStarted;
10802 tw.UserStreamStopped += tw_UserStreamStopped;
10803 tw.PostDeleted += tw_PostDeleted;
10804 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10806 MenuItemUserStream.Text = "&UserStream ■";
10807 MenuItemUserStream.Enabled = true;
10808 StopToolStripMenuItem.Text = "&Start";
10809 StopToolStripMenuItem.Enabled = true;
10810 if (SettingDialog.UserstreamStartup) tw.StartUserStream();
10813 private async void TweenMain_Shown(object sender, EventArgs e)
10817 PostBrowser.Url = new Uri("about:blank");
10818 PostBrowser.DocumentText = ""; //発言詳細部初期化
10824 NotifyIcon1.Visible = true;
10826 if (this.IsNetworkAvailable())
10828 this.RefreshMuteUserIdsAsync();
10829 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, "");
10830 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10831 if (SettingDialog.StartupFollowers)
10833 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10835 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10837 _waitTimeline = true;
10838 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
10840 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
10842 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
10843 if (SettingDialog.GetFav)
10846 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
10848 _waitPubSearch = true;
10849 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, ""); //tabname="":全タブ
10850 _waitUserTimeline = true;
10851 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, ""); //tabname="":全タブ
10853 GetTimeline(MyCommon.WORKERTYPE.List, 1, ""); //tabname="":全タブ
10856 while (this.IsInitialRead())
10858 await Task.Delay(5000);
10861 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10863 if (MyCommon._endingFlag)
10867 if (MyCommon._endingFlag) return;
10869 if (ApplicationSettings.VersionInfoUrl != null)
10871 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10872 if (SettingDialog.StartupVersion)
10873 await this.CheckNewVersion(true);
10877 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10878 this.VerUpMenuItem.Enabled = false;
10879 this.VerUpMenuItem.Available = false;
10880 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10884 if (!tw.GetFollowersSuccess && SettingDialog.StartupFollowers)
10885 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10888 if (!tw.GetNoRetweetSuccess)
10889 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10892 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10893 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10895 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10896 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10898 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10899 SettingStripMenuItem_Click(null, null);
10906 TimerTimeline.Enabled = true;
10909 private bool IsInitialRead()
10911 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10914 private void doGetFollowersMenu()
10916 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, "");
10917 DispSelectedPost(true);
10920 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10922 doGetFollowersMenu();
10925 private void doReTweetUnofficial()
10928 if (this.ExistCurrentPost)
10930 if (_curPost.IsDm ||
10931 !StatusText.Enabled) return;
10933 if (_curPost.IsProtect)
10935 MessageBox.Show("Protected.");
10938 string rtdata = _curPost.Text;
10939 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10941 this._reply_to_id = null;
10942 this._reply_to_name = null;
10944 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10946 StatusText.SelectionStart = 0;
10947 StatusText.Focus();
10951 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10953 doReTweetUnofficial();
10956 private void doReTweetOfficial(bool isConfirm)
10959 if (this.ExistCurrentPost)
10961 if (_curPost.IsProtect)
10963 MessageBox.Show("Protected.");
10964 _DoFavRetweetFlags = false;
10967 if (_curList.SelectedIndices.Count > 15)
10969 MessageBox.Show(Properties.Resources.RetweetLimitText);
10970 _DoFavRetweetFlags = false;
10973 else if (_curList.SelectedIndices.Count > 1)
10975 string QuestionText = Properties.Resources.RetweetQuestion2;
10976 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10977 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10979 case DialogResult.Cancel:
10980 case DialogResult.No:
10981 _DoFavRetweetFlags = false;
10987 if (_curPost.IsDm || _curPost.IsMe)
10989 _DoFavRetweetFlags = false;
10992 if (!SettingDialog.RetweetNoConfirm)
10994 string Questiontext = Properties.Resources.RetweetQuestion1;
10995 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
10996 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
10998 _DoFavRetweetFlags = false;
11003 GetWorkerArg args = new GetWorkerArg();
11004 args.ids = new List<long>();
11005 args.sIds = new List<long>();
11006 args.tName = _curTab.Text;
11007 args.type = MyCommon.WORKERTYPE.Retweet;
11008 foreach (int idx in _curList.SelectedIndices)
11010 PostClass post = GetCurTabPost(idx);
11011 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
11017 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
11019 doReTweetOfficial(true);
11022 private void FavoritesRetweetOriginal()
11024 if (!this.ExistCurrentPost) return;
11025 _DoFavRetweetFlags = true;
11026 doReTweetOfficial(true);
11027 if (_DoFavRetweetFlags)
11029 _DoFavRetweetFlags = false;
11030 FavoriteChange(true, false);
11034 private void FavoritesRetweetUnofficial()
11036 if (this.ExistCurrentPost && !_curPost.IsDm)
11038 _DoFavRetweetFlags = true;
11039 FavoriteChange(true);
11040 if (!_curPost.IsProtect && _DoFavRetweetFlags)
11042 _DoFavRetweetFlags = false;
11043 doReTweetUnofficial();
11049 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
11051 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
11052 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
11053 /// <returns>復元されたツイート本文</returns>
11054 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
11056 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
11059 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
11061 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11063 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11067 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
11069 statusHtml = statusHtml.Replace("<br>", " ");
11071 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
11072 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
11073 statusHtml = statusHtml.Replace(" ", " ");
11075 return WebUtility.HtmlDecode(statusHtml);
11078 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
11080 if (_curPost != null)
11081 DispSelectedPost(true);
11084 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
11086 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
11087 DebugModeToolStripMenuItem.Visible = true;
11089 DebugModeToolStripMenuItem.Visible = false;
11092 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
11094 SettingDialog.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
11097 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
11099 ToolStripMenuItemUrlAutoShorten.Checked = SettingDialog.UrlConvertAuto;
11102 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
11104 if (TraceOutToolStripMenuItem.Checked)
11105 MyCommon.TraceFlag = true;
11107 MyCommon.TraceFlag = false;
11110 private void TweenMain_Deactivate(object sender, EventArgs e)
11112 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
11113 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
11116 private void TabRenameMenuItem_Click(object sender, EventArgs e)
11118 if (string.IsNullOrEmpty(_rclickTabName)) return;
11119 TabRename(ref _rclickTabName);
11122 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
11124 await UrlConvertAsync(MyCommon.UrlConverter.Bitly);
11127 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
11129 await UrlConvertAsync(MyCommon.UrlConverter.Jmp);
11133 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
11135 e.Result = tw.GetInfoApi();
11138 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
11140 StringBuilder tmp = new StringBuilder();
11142 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
11146 var result = (TwitterApiStatus)dlg.Result;
11148 if (result == null)
11150 var accessLevel = result.AccessLevel;
11151 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
11152 var mediaLimit = result.MediaUploadLimit;
11154 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
11155 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
11156 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
11157 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
11160 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
11161 SetStatusLabelUrl();
11164 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
11165 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
11166 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
11170 tmp.Append(Properties.Resources.ApiInfo5);
11174 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11177 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11180 if (_curPost != null) id = _curPost.ScreenName;
11184 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11186 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11187 e.Result = arg.tw.PostFollowCommand(arg.id);
11190 private void FollowCommand(string id)
11192 using (InputTabName inputName = new InputTabName())
11194 inputName.FormTitle = "Follow";
11195 inputName.FormDescription = Properties.Resources.FRMessage1;
11196 inputName.TabName = id;
11197 if (inputName.ShowDialog() == DialogResult.OK &&
11198 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11200 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11202 arg.id = inputName.TabName.Trim();
11203 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11204 FollowCommand_DoWork,
11208 _info.ShowDialog();
11209 string ret = (string)_info.Result;
11210 if (!string.IsNullOrEmpty(ret))
11211 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11213 MessageBox.Show(Properties.Resources.FRMessage3);
11219 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11222 if (_curPost != null) id = _curPost.ScreenName;
11223 RemoveCommand(id, false);
11226 private class FollowRemoveCommandArgs
11232 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11234 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11235 e.Result = arg.tw.PostRemoveCommand(arg.id);
11238 private void RemoveCommand(string id, bool skipInput)
11240 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11245 using (InputTabName inputName = new InputTabName())
11247 inputName.FormTitle = "Unfollow";
11248 inputName.FormDescription = Properties.Resources.FRMessage1;
11249 inputName.TabName = id;
11250 if (inputName.ShowDialog() == DialogResult.OK &&
11251 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11254 arg.id = inputName.TabName.Trim();
11263 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11264 RemoveCommand_DoWork,
11268 _info.ShowDialog();
11269 string ret = (string)_info.Result;
11270 if (!string.IsNullOrEmpty(ret))
11271 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11273 MessageBox.Show(Properties.Resources.FRMessage3);
11277 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11280 if (_curPost != null)
11281 id = _curPost.ScreenName;
11283 ShowFriendship(id);
11286 private class ShowFriendshipArgs
11289 public class FriendshipInfo
11291 public string id = "";
11292 public bool isFollowing = false;
11293 public bool isFollowed = false;
11294 public FriendshipInfo(string id)
11299 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11302 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11304 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11305 string result = "";
11306 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11308 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11309 if (!string.IsNullOrEmpty(rt))
11311 if (string.IsNullOrEmpty(result)) result = rt;
11317 private void ShowFriendship(string id)
11319 ShowFriendshipArgs args = new ShowFriendshipArgs();
11321 using (InputTabName inputName = new InputTabName())
11323 inputName.FormTitle = "Show Friendships";
11324 inputName.FormDescription = Properties.Resources.FRMessage1;
11325 inputName.TabName = id;
11326 if (inputName.ShowDialog() == DialogResult.OK &&
11327 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11330 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11331 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11332 ShowFriendship_DoWork,
11336 _info.ShowDialog();
11337 ret = (string)_info.Result;
11339 string result = "";
11340 if (string.IsNullOrEmpty(ret))
11342 if (args.ids[0].isFollowing)
11344 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11348 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11350 if (args.ids[0].isFollowed)
11352 result += Properties.Resources.GetFriendshipInfo3;
11356 result += Properties.Resources.GetFriendshipInfo4;
11358 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11364 MessageBox.Show(result);
11369 private void ShowFriendship(string[] ids)
11371 foreach (string id in ids)
11374 ShowFriendshipArgs args = new ShowFriendshipArgs();
11376 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11377 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11378 ShowFriendship_DoWork,
11382 _info.ShowDialog();
11383 ret = (string)_info.Result;
11385 string result = "";
11386 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11388 if (string.IsNullOrEmpty(ret))
11391 if (fInfo.isFollowing)
11393 ff += Properties.Resources.GetFriendshipInfo1;
11397 ff += Properties.Resources.GetFriendshipInfo2;
11400 ff += System.Environment.NewLine + " ";
11401 if (fInfo.isFollowed)
11403 ff += Properties.Resources.GetFriendshipInfo3;
11407 ff += Properties.Resources.GetFriendshipInfo4;
11409 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11410 if (fInfo.isFollowing)
11412 if (MessageBox.Show(
11413 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11414 MessageBoxButtons.YesNo,
11415 MessageBoxIcon.Question,
11416 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11418 RemoveCommand(fInfo.id, true);
11423 MessageBox.Show(result);
11428 MessageBox.Show(ret);
11433 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11435 doShowUserStatus(tw.Username, false);
11436 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11438 // doShowUserStatus(tw.Username, false);
11442 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11447 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11448 // URLから切り出した文字列を渡す
11450 public bool IsTwitterId(string name)
11452 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11453 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11455 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11458 private string GetUserId()
11460 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11461 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11462 return m.Result("${ScreenName}");
11467 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11469 string name = GetUserId();
11470 if (name != null) FollowCommand(name);
11473 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11475 string name = GetUserId();
11476 if (name != null) RemoveCommand(name, false);
11479 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11481 string name = GetUserId();
11482 if (name != null) ShowFriendship(name);
11485 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11487 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11488 List<string> ids = new List<string>();
11489 foreach (Match mu in ma)
11491 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11493 ids.Add(mu.Result("${ScreenName}"));
11496 ShowFriendship(ids.ToArray());
11499 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11501 string name = GetUserId();
11502 if (name != null) ShowUserStatus(name);
11505 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11507 string name = GetUserId();
11508 if (name != null) AddNewTabForUserTimeline(name);
11511 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11513 string name = GetUserId();
11514 if (name != null) AddNewTabForSearch("@" + name);
11517 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11519 _modifySettingCommon = true;
11522 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11524 _modifySettingCommon = true;
11527 private void doQuote()
11531 if (this.ExistCurrentPost)
11533 if (_curPost.IsDm ||
11534 !StatusText.Enabled) return;
11536 if (_curPost.IsProtect)
11538 MessageBox.Show("Protected.");
11541 string rtdata = _curPost.Text;
11542 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11544 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11545 if (_curPost.RetweetedId == null)
11547 _reply_to_id = _curPost.StatusId;
11551 _reply_to_id = _curPost.RetweetedId.Value;
11553 _reply_to_name = _curPost.ScreenName;
11555 StatusText.SelectionStart = 0;
11556 StatusText.Focus();
11560 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11565 private void SearchButton_Click(object sender, EventArgs e)
11568 Control pnl = ((Control)sender).Parent;
11569 if (pnl == null) return;
11570 string tbName = pnl.Parent.Text;
11571 TabClass tb = _statuses.Tabs[tbName];
11572 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11573 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11574 cmb.Text = cmb.Text.Trim();
11575 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11576 bool Quote = false;
11577 StringBuilder buf = new StringBuilder();
11578 char[] c = cmb.Text.ToCharArray();
11579 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11581 if (cnt > cmb.Text.Length - 4)
11583 buf.Append(cmb.Text.Substring(cnt));
11592 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11594 buf.Append(" OR ");
11599 buf.Append(c[cnt]);
11601 cmb.Text = buf.ToString();
11603 tb.SearchWords = cmb.Text;
11604 tb.SearchLang = cmbLang.Text;
11605 if (string.IsNullOrEmpty(cmb.Text))
11607 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11611 if (tb.IsQueryChanged())
11613 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11614 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11615 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11616 cmb.Text = tb.SearchWords;
11618 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11619 this.PurgeListViewItemCache();
11620 lst.VirtualListSize = 0;
11621 _statuses.ClearTabIds(tbName);
11622 SaveConfigsTabs(); //検索条件の保存
11625 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, tbName);
11626 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11629 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11635 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11637 if (_statuses.RemovedTab.Count == 0)
11639 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11644 TabClass tb = _statuses.RemovedTab.Pop();
11645 if (tb.TabType == MyCommon.TabUsageType.Related)
11647 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11648 if (relatedTab != null)
11650 // 関連発言なら既存のタブを置き換える
11651 tb.TabName = relatedTab.TabName;
11652 this.ClearTab(tb.TabName, false);
11653 _statuses.Tabs[tb.TabName] = tb;
11654 for (int i = 0; i < ListTab.TabPages.Count; i++)
11656 if (tb.TabName == ListTab.TabPages[i].Text)
11658 ListTab.SelectedIndex = i;
11659 ListTabSelect(ListTab.TabPages[i]);
11666 const string TabName = "Related Tweets";
11667 string renamed = TabName;
11668 for (int i = 2; i <= 100; i++)
11670 if (!_statuses.ContainsTab(renamed)) break;
11671 renamed = TabName + i.ToString();
11673 tb.TabName = renamed;
11674 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11675 _statuses.Tabs.Add(renamed, tb); // 後に
11676 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11677 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11682 string renamed = tb.TabName;
11683 for (int i = 1; i < int.MaxValue; i++)
11685 if (!_statuses.ContainsTab(renamed)) break;
11686 renamed = tb.TabName + "(" + i.ToString() + ")";
11688 tb.TabName = renamed;
11689 _statuses.Tabs.Add(renamed, tb); // 先に
11690 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11691 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11692 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11698 private void doMoveToRTHome()
11700 if (_curList.SelectedIndices.Count > 0)
11702 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11703 if (post.RetweetedId != null)
11705 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11710 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11715 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11717 string name = GetUserId();
11723 if (_curList.SelectedIndices.Count == 0) return;
11726 if (!SelectTab(out tabName)) return;
11730 MoveOrCopy(ref mv, ref mk);
11732 PostFilterRule fc = new PostFilterRule();
11733 fc.FilterName = name;
11734 fc.UseNameField = true;
11735 fc.MoveMatches = mv;
11736 fc.MarkMatches = mk;
11737 fc.UseRegex = false;
11738 fc.FilterByUrl = false;
11739 _statuses.Tabs[tabName].AddFilter(fc);
11741 this.ApplyPostFilters();
11746 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11750 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11752 if (menuItem.Owner == this.ContextMenuPostBrowser)
11754 user = GetUserId();
11755 if (user == null) return;
11757 else if (this._curPost != null)
11759 user = this._curPost.ScreenName;
11766 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11768 string res = this.tw.GetListsApi();
11770 if (!string.IsNullOrEmpty(res))
11772 MessageBox.Show("Failed to get lists. (" + res + ")");
11777 using (MyLists listSelectForm = new MyLists(user, this.tw))
11779 listSelectForm.ShowDialog(this);
11783 private void SearchControls_Enter(object sender, EventArgs e)
11785 Control pnl = (Control)sender;
11786 foreach (Control ctl in pnl.Controls)
11788 ctl.TabStop = true;
11792 private void SearchControls_Leave(object sender, EventArgs e)
11794 Control pnl = (Control)sender;
11795 foreach (Control ctl in pnl.Controls)
11797 ctl.TabStop = false;
11801 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11803 if (ListTab.SelectedTab != null)
11805 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11806 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11810 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11812 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11815 HashMgr.SetPermanentHash("#" + Uri.UnescapeDataString(m.Result("${hash}")));
11816 HashStripSplitButton.Text = HashMgr.UseHash;
11817 HashToggleMenuItem.Checked = true;
11818 HashToggleToolStripMenuItem.Checked = true;
11820 _modifySettingCommon = true;
11824 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11826 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11829 private void HashManageMenuItem_Click(object sender, EventArgs e)
11831 DialogResult rslt = DialogResult.Cancel;
11834 rslt = HashMgr.ShowDialog();
11840 this.TopMost = SettingDialog.AlwaysTop;
11841 if (rslt == DialogResult.Cancel) return;
11842 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11844 HashStripSplitButton.Text = HashMgr.UseHash;
11845 HashToggleMenuItem.Checked = true;
11846 HashToggleToolStripMenuItem.Checked = true;
11850 HashStripSplitButton.Text = "#[-]";
11851 HashToggleMenuItem.Checked = false;
11852 HashToggleToolStripMenuItem.Checked = false;
11854 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11856 // int sidx = StatusText.SelectionStart;
11857 // string hash = HashMgr.UseHash + " ";
11860 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11861 // hash = " " + hash;
11863 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11864 // sidx += hash.Length;
11865 // StatusText.SelectionStart = sidx;
11866 // StatusText.Focus();
11868 _modifySettingCommon = true;
11869 this.StatusText_TextChanged(null, null);
11872 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11874 HashMgr.ToggleHash();
11875 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11877 HashStripSplitButton.Text = HashMgr.UseHash;
11878 HashToggleMenuItem.Checked = true;
11879 HashToggleToolStripMenuItem.Checked = true;
11883 HashStripSplitButton.Text = "#[-]";
11884 HashToggleMenuItem.Checked = false;
11885 HashToggleToolStripMenuItem.Checked = false;
11887 _modifySettingCommon = true;
11888 this.StatusText_TextChanged(null, null);
11891 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11893 HashToggleMenuItem_Click(null, null);
11896 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11898 if (ListTab.SelectedTab == null) return;
11899 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11900 if (!this.ExistCurrentPost)
11902 this.ReplyOpMenuItem.Enabled = false;
11903 this.ReplyAllOpMenuItem.Enabled = false;
11904 this.DmOpMenuItem.Enabled = false;
11905 this.ShowProfMenuItem.Enabled = false;
11906 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11907 this.ListManageMenuItem.Enabled = false;
11908 this.OpenFavOpMenuItem.Enabled = false;
11909 this.CreateTabRuleOpMenuItem.Enabled = false;
11910 this.CreateIdRuleOpMenuItem.Enabled = false;
11911 this.ReadOpMenuItem.Enabled = false;
11912 this.UnreadOpMenuItem.Enabled = false;
11916 this.ReplyOpMenuItem.Enabled = true;
11917 this.ReplyAllOpMenuItem.Enabled = true;
11918 this.DmOpMenuItem.Enabled = true;
11919 this.ShowProfMenuItem.Enabled = true;
11920 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11921 this.ListManageMenuItem.Enabled = true;
11922 this.OpenFavOpMenuItem.Enabled = true;
11923 this.CreateTabRuleOpMenuItem.Enabled = true;
11924 this.CreateIdRuleOpMenuItem.Enabled = true;
11925 this.ReadOpMenuItem.Enabled = true;
11926 this.UnreadOpMenuItem.Enabled = true;
11929 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11931 this.FavOpMenuItem.Enabled = false;
11932 this.UnFavOpMenuItem.Enabled = false;
11933 this.OpenStatusOpMenuItem.Enabled = false;
11934 this.OpenFavotterOpMenuItem.Enabled = false;
11935 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11936 this.RtOpMenuItem.Enabled = false;
11937 this.RtUnOpMenuItem.Enabled = false;
11938 this.QtOpMenuItem.Enabled = false;
11939 this.FavoriteRetweetMenuItem.Enabled = false;
11940 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11941 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11945 this.FavOpMenuItem.Enabled = true;
11946 this.UnFavOpMenuItem.Enabled = true;
11947 this.OpenStatusOpMenuItem.Enabled = true;
11948 this.OpenFavotterOpMenuItem.Enabled = true;
11949 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11953 this.RtOpMenuItem.Enabled = false;
11954 this.FavoriteRetweetMenuItem.Enabled = false;
11955 this.DelOpMenuItem.Enabled = true;
11959 this.DelOpMenuItem.Enabled = false;
11960 if (_curPost.IsProtect)
11962 this.RtOpMenuItem.Enabled = false;
11963 this.RtUnOpMenuItem.Enabled = false;
11964 this.QtOpMenuItem.Enabled = false;
11965 this.FavoriteRetweetMenuItem.Enabled = false;
11966 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11970 this.RtOpMenuItem.Enabled = true;
11971 this.RtUnOpMenuItem.Enabled = true;
11972 this.QtOpMenuItem.Enabled = true;
11973 this.FavoriteRetweetMenuItem.Enabled = true;
11974 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
11979 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
11981 this.RefreshPrevOpMenuItem.Enabled = true;
11985 this.RefreshPrevOpMenuItem.Enabled = false;
11987 if (!this.ExistCurrentPost
11988 || _curPost.InReplyToStatusId == null)
11990 OpenRepSourceOpMenuItem.Enabled = false;
11994 OpenRepSourceOpMenuItem.Enabled = true;
11996 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
11998 OpenRterHomeMenuItem.Enabled = false;
12002 OpenRterHomeMenuItem.Enabled = true;
12006 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
12008 ContextMenuTabProperty_Opening(sender, null);
12011 public Twitter TwitterInstance
12016 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
12018 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
12020 _mySpDis3 = SplitContainer3.SplitterDistance;
12021 _modifySettingLocal = true;
12025 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
12027 if (_statuses.RemovedTab.Count == 0)
12029 UndoRemoveTabMenuItem.Enabled = false;
12033 UndoRemoveTabMenuItem.Enabled = true;
12035 if (ListTab.SelectedTab != null)
12037 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
12038 PublicSearchQueryMenuItem.Enabled = true;
12040 PublicSearchQueryMenuItem.Enabled = false;
12044 PublicSearchQueryMenuItem.Enabled = false;
12046 if (!this.ExistCurrentPost)
12048 this.CopySTOTMenuItem.Enabled = false;
12049 this.CopyURLMenuItem.Enabled = false;
12050 this.CopyUserIdStripMenuItem.Enabled = false;
12054 this.CopySTOTMenuItem.Enabled = true;
12055 this.CopyURLMenuItem.Enabled = true;
12056 this.CopyUserIdStripMenuItem.Enabled = true;
12057 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
12058 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
12062 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
12064 SetNotifyIconText();
12067 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12070 if (_curPost != null)
12072 id = _curPost.ScreenName;
12074 ShowUserStatus(id);
12077 private class GetUserInfoArgs
12081 public TwitterUser user;
12084 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
12086 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
12087 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
12090 private void doShowUserStatus(string id, bool ShowInputDialog)
12092 TwitterUser user = null;
12093 GetUserInfoArgs args = new GetUserInfoArgs();
12094 if (ShowInputDialog)
12096 using (InputTabName inputName = new InputTabName())
12098 inputName.FormTitle = "Show UserStatus";
12099 inputName.FormDescription = Properties.Resources.FRMessage1;
12100 inputName.TabName = id;
12101 if (inputName.ShowDialog() == DialogResult.OK &&
12102 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12104 id = inputName.TabName.Trim();
12108 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12109 GetUserInfo_DoWork,
12113 _info.ShowDialog();
12114 string ret = (string)_info.Result;
12115 if (string.IsNullOrEmpty(ret))
12116 doShowUserStatus(args.user);
12118 MessageBox.Show(ret);
12128 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12129 GetUserInfo_DoWork,
12133 _info.ShowDialog();
12134 string ret = (string)_info.Result;
12135 if (string.IsNullOrEmpty(ret))
12137 doShowUserStatus(args.user);
12141 MessageBox.Show(ret);
12147 private async void doShowUserStatus(TwitterUser user)
12149 using (var userDialog = new UserInfoDialog(this, this.tw))
12151 var showUserTask = userDialog.ShowUserAsync(user);
12152 userDialog.ShowDialog(this);
12155 this.BringToFront();
12157 // ユーザー情報の表示が完了するまで userDialog を破棄しない
12158 await showUserTask;
12162 private void ShowUserStatus(string id, bool ShowInputDialog)
12164 doShowUserStatus(id, ShowInputDialog);
12167 private void ShowUserStatus(string id)
12169 doShowUserStatus(id, true);
12172 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12174 if (NameLabel.Tag != null)
12176 string id = (string)NameLabel.Tag;
12177 if (id != tw.Username)
12184 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12186 if (NameLabel.Tag != null)
12188 string id = (string)NameLabel.Tag;
12189 if (id != tw.Username)
12191 RemoveCommand(id, false);
12196 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12198 if (NameLabel.Tag != null)
12200 string id = (string)NameLabel.Tag;
12201 if (id != tw.Username)
12203 ShowFriendship(id);
12208 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12210 if (NameLabel.Tag != null)
12212 string id = (string)NameLabel.Tag;
12213 ShowUserStatus(id, false);
12217 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12219 if (NameLabel.Tag != null)
12221 string id = (string)NameLabel.Tag;
12222 AddNewTabForUserTimeline(id);
12226 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12228 if (NameLabel.Tag != null)
12230 string id = (string)NameLabel.Tag;
12231 AddNewTabForSearch("@" + id);
12235 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12237 if (_curPost != null)
12239 ShowUserStatus(_curPost.ScreenName, false);
12243 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12248 if (_curPost.RetweetedId != null)
12250 statusid = _curPost.RetweetedId.Value;
12254 statusid = _curPost.StatusId;
12256 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12258 e.Result = counter;
12261 private void RtCountMenuItem_Click(object sender, EventArgs e)
12263 if (this.ExistCurrentPost)
12265 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12266 GetRetweet_DoWork))
12268 int retweet_count = 0;
12271 _info.ShowDialog();
12272 retweet_count = (int)_info.Result;
12273 if (retweet_count < 0)
12275 MessageBox.Show(Properties.Resources.RtCountText2);
12279 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12285 private HookGlobalHotkey _hookGlobalHotkey;
12288 _hookGlobalHotkey = new HookGlobalHotkey(this);
12290 // この呼び出しは、Windows フォーム デザイナで必要です。
12291 InitializeComponent();
12293 // InitializeComponent() 呼び出しの後で初期化を追加します。
12295 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12296 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12297 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12298 this.gh.NotifyClicked += GrowlHelper_Callback;
12300 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12301 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
12303 this._apiGauge = new ToolStripAPIGauge();
12304 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12305 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12307 this.ImageSelector.Visible = false;
12308 this.ImageSelector.Enabled = false;
12309 this.ImageSelector.FilePickDialog = OpenFileDialog1;
12311 this.ReplaceAppName();
12314 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12316 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12319 this.Visible = false;
12321 else if (Form.ActiveForm == null)
12323 this.Visible = true;
12324 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12326 this.BringToFront();
12327 this.StatusText.Focus();
12331 private void UserPicture_MouseEnter(object sender, EventArgs e)
12333 this.UserPicture.Cursor = Cursors.Hand;
12336 private void UserPicture_MouseLeave(object sender, EventArgs e)
12338 this.UserPicture.Cursor = Cursors.Default;
12341 private void UserPicture_DoubleClick(object sender, EventArgs e)
12343 if (NameLabel.Tag != null)
12345 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12349 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12351 this.MultiLineMenuItem.PerformClick();
12354 public PostClass CurPost
12356 get { return _curPost; }
12359 public bool IsPreviewEnable
12361 get { return SettingDialog.PreviewEnable; }
12365 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12367 if (ImageSelector.Visible)
12368 ImageSelector.EndSelection();
12370 ImageSelector.BeginSelection();
12373 private void SelectMedia_DragEnter(DragEventArgs e)
12375 if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0], true))
12377 e.Effect = DragDropEffects.Copy;
12380 e.Effect = DragDropEffects.None;
12383 private void SelectMedia_DragOver(DragEventArgs e)
12388 private void SelectMedia_DragDrop(DragEventArgs e)
12391 this.BringToFront();
12392 ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
12393 StatusText.Focus();
12396 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
12398 TimelinePanel.Visible = false;
12399 TimelinePanel.Enabled = false;
12402 private void ImageSelector_EndSelecting(object sender, EventArgs e)
12404 TimelinePanel.Visible = true;
12405 TimelinePanel.Enabled = true;
12406 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12409 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
12411 this.AllowDrop = false;
12414 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
12416 this.AllowDrop = true;
12419 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
12421 if (ImageSelector.Visible)
12423 _modifySettingCommon = true;
12424 SaveConfigsAll(true);
12426 if (ImageSelector.ServiceName.Equals("Twitter"))
12427 this.StatusText_TextChanged(null, null);
12431 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
12433 this.StatusText_TextChanged(null, null);
12437 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12439 using (ListManage form = new ListManage(tw))
12441 form.ShowDialog(this);
12445 public bool ModifySettingCommon
12447 set { _modifySettingCommon = value; }
12450 public bool ModifySettingLocal
12452 set { _modifySettingLocal = value; }
12455 public bool ModifySettingAtId
12457 set { _modifySettingAtId = value; }
12460 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12462 string link = (string)SourceLinkLabel.Tag;
12463 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12465 OpenUriAsync(link);
12469 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12471 string link = (string)SourceLinkLabel.Tag;
12472 if (!string.IsNullOrEmpty(link))
12474 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12478 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12480 SetStatusLabelUrl();
12483 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12485 if (this.ExistCurrentPost && !_curPost.IsDm)
12486 RtCountMenuItem.Enabled = true;
12488 RtCountMenuItem.Enabled = false;
12490 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12491 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12493 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12496 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12501 private void CopyUserId()
12503 if (_curPost == null) return;
12504 string clstr = _curPost.ScreenName;
12507 Clipboard.SetDataObject(clstr, false, 5, 100);
12509 catch (Exception ex)
12511 MessageBox.Show(ex.Message);
12515 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12517 if (this.ExistCurrentPost && !_curPost.IsDm)
12521 this.OpenRelatedTab(this._curPost);
12523 catch (TabException ex)
12525 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12531 /// 指定されたツイートに対する関連発言タブを開きます
12533 /// <param name="post">表示する対象となるツイート</param>
12534 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12535 private void OpenRelatedTab(PostClass post)
12537 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12540 if (tabRelated == null)
12542 tabName = this._statuses.MakeTabName("Related Tweets");
12544 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12545 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12547 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12548 tabRelated.UnreadManage = false;
12549 tabRelated.Notify = false;
12553 tabName = tabRelated.TabName;
12556 tabRelated.RelationTargetPost = post;
12557 this.ClearTab(tabName, false);
12559 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12561 var tabPage = this.ListTab.TabPages[i];
12562 if (tabName == tabPage.Text)
12564 this.ListTab.SelectedIndex = i;
12565 this.ListTabSelect(tabPage);
12570 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, tabName);
12573 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12575 StringBuilder buf = new StringBuilder();
12576 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12577 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12578 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12579 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12580 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12583 private void tw_UserIdChanged()
12585 this._modifySettingCommon = true;
12588 #region "Userstream"
12589 private bool _isActiveUserstream = false;
12591 private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
12595 if (InvokeRequired && !IsDisposed)
12597 Invoke((Action) (() =>
12599 _statuses.RemovePostReserve(e.StatusId);
12600 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
12602 this.PurgeListViewItemCache();
12603 ((DetailsListView)_curTab.Tag).Update();
12604 if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
12610 catch (ObjectDisposedException)
12614 catch (InvalidOperationException)
12620 private void tw_NewPostFromStream(object sender, EventArgs e)
12622 if (SettingDialog.ReadOldPosts)
12624 _statuses.SetRead(); //新着時未読クリア
12627 int rsltAddCount = _statuses.DistributePosts();
12630 DateTime tm = DateTime.Now;
12631 if (_tlTimestamps.ContainsKey(tm))
12633 _tlTimestamps[tm] += rsltAddCount;
12637 _tlTimestamps.Add(tm, rsltAddCount);
12639 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12640 List<DateTime> keys = new List<DateTime>();
12642 foreach (DateTime key in _tlTimestamps.Keys)
12644 if (key.CompareTo(oneHour) < 0)
12647 _tlCount += _tlTimestamps[key];
12649 foreach (DateTime key in keys)
12651 _tlTimestamps.Remove(key);
12655 //Static DateTime before = Now;
12656 //if (before.Subtract(Now).Seconds > -5) return;
12660 if (SettingDialog.UserstreamPeriodInt > 0) return;
12664 if (InvokeRequired && !IsDisposed)
12666 Invoke(new Action<bool>(RefreshTimeline), true);
12670 catch (ObjectDisposedException)
12674 catch (InvalidOperationException)
12680 private void tw_UserStreamStarted(object sender, EventArgs e)
12682 this._isActiveUserstream = true;
12685 if (InvokeRequired && !IsDisposed)
12687 Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
12691 catch (ObjectDisposedException)
12695 catch (InvalidOperationException)
12700 MenuItemUserStream.Text = "&UserStream ▶";
12701 MenuItemUserStream.Enabled = true;
12702 StopToolStripMenuItem.Text = "&Stop";
12703 StopToolStripMenuItem.Enabled = true;
12705 StatusLabel.Text = "UserStream Started.";
12708 private void tw_UserStreamStopped(object sender, EventArgs e)
12710 this._isActiveUserstream = false;
12713 if (InvokeRequired && !IsDisposed)
12715 Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
12719 catch (ObjectDisposedException)
12723 catch (InvalidOperationException)
12728 MenuItemUserStream.Text = "&UserStream ■";
12729 MenuItemUserStream.Enabled = true;
12730 StopToolStripMenuItem.Text = "&Start";
12731 StopToolStripMenuItem.Enabled = true;
12733 StatusLabel.Text = "UserStream Stopped.";
12736 private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
12740 if (InvokeRequired && !IsDisposed)
12742 Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
12746 catch (ObjectDisposedException)
12750 catch (InvalidOperationException)
12754 var ev = e.EventData;
12755 StatusLabel.Text = "Event: " + ev.Event;
12756 //if (ev.Event == "favorite")
12758 // NotifyFavorite(ev);
12761 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12763 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12765 this.PurgeListViewItemCache();
12766 ((DetailsListView)_curTab.Tag).Update();
12768 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12770 RemovePostFromFavTab(new long[] {ev.Id});
12775 private void NotifyEvent(Twitter.FormattedEvent ev)
12778 if (BalloonRequired(ev))
12780 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12781 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12782 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12783 StringBuilder title = new StringBuilder();
12784 if (SettingDialog.DispUsername)
12786 title.Append(tw.Username);
12787 title.Append(" - ");
12793 title.Append(Application.ProductName);
12794 title.Append(" [");
12795 title.Append(ev.Event.ToUpper());
12796 title.Append("] by ");
12797 if (!string.IsNullOrEmpty(ev.Username))
12799 title.Append(ev.Username.ToString());
12803 //title.Append("");
12806 if (!string.IsNullOrEmpty(ev.Target))
12808 //NotifyIcon1.BalloonTipText = ev.Target;
12813 //NotifyIcon1.BalloonTipText = " ";
12816 //NotifyIcon1.ShowBalloonTip(500);
12817 if (SettingDialog.IsNotifyUseGrowl)
12819 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
12820 ev.Id.ToString(), title.ToString(), text);
12824 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12825 NotifyIcon1.BalloonTipTitle = title.ToString();
12826 NotifyIcon1.BalloonTipText = text;
12827 NotifyIcon1.ShowBalloonTip(500);
12832 string snd = SettingDialog.EventSoundFile;
12833 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(snd))
12835 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
12839 string dir = Application.StartupPath;
12840 if (Directory.Exists(Path.Combine(dir, "Sounds")))
12842 dir = Path.Combine(dir, "Sounds");
12844 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
12856 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
12858 MenuItemUserStream.Enabled = false;
12859 if (StopRefreshAllMenuItem.Checked)
12861 StopRefreshAllMenuItem.Checked = false;
12864 if (this._isActiveUserstream)
12866 tw.StopUserStream();
12870 tw.StartUserStream();
12874 private static string inputTrack = "";
12876 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
12878 if (TrackToolStripMenuItem.Checked)
12880 using (InputTabName inputForm = new InputTabName())
12882 inputForm.TabName = inputTrack;
12883 inputForm.FormTitle = "Input track word";
12884 inputForm.FormDescription = "Track word";
12885 if (inputForm.ShowDialog() != DialogResult.OK)
12887 TrackToolStripMenuItem.Checked = false;
12890 inputTrack = inputForm.TabName.Trim();
12892 if (!inputTrack.Equals(tw.TrackWord))
12894 tw.TrackWord = inputTrack;
12895 this._modifySettingCommon = true;
12896 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
12897 tw.ReconnectUserStream();
12903 tw.ReconnectUserStream();
12905 this._modifySettingCommon = true;
12908 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
12910 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
12911 this._modifySettingCommon = true;
12912 tw.ReconnectUserStream();
12915 private void EventViewerMenuItem_Click(object sender, EventArgs e)
12917 if (evtDialog == null || evtDialog.IsDisposed)
12920 evtDialog = new EventViewerDialog();
12921 evtDialog.Owner = this;
12923 Point pos = evtDialog.Location;
12924 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
12925 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
12926 evtDialog.Location = pos;
12928 evtDialog.EventSource = tw.StoredEvent;
12929 if (!evtDialog.Visible)
12931 evtDialog.Show(this);
12935 evtDialog.Activate();
12937 this.TopMost = this.SettingDialog.AlwaysTop;
12941 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
12943 MyCommon._endingFlag = true;
12947 Application.Restart();
12951 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
12955 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
12957 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
12960 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
12962 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
12965 private async Task doTranslation(string str)
12967 if (string.IsNullOrEmpty(str))
12970 var bing = new Bing();
12973 var translatedText = await bing.TranslateAsync(str,
12975 langTo: this.SettingDialog.TranslateLanguage);
12977 this.PostBrowser.DocumentText = translatedText;
12979 catch (HttpRequestException e)
12981 this.StatusLabel.Text = "Err:" + e.Message;
12985 private async void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
12987 if (!this.ExistCurrentPost)
12990 await this.doTranslation(this._curPost.TextFromApi);
12993 private async void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
12995 var text = this.WebBrowser_GetSelectionText(ref this.PostBrowser);
12996 await this.doTranslation(text);
12999 private bool ExistCurrentPost
13003 if (_curPost == null) return false;
13004 if (_curPost.IsDeleted) return false;
13009 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13011 ShowUserTimeline();
13014 public bool FavEventChangeUnread
13016 get { return SettingDialog.FavEventUnread; }
13019 private string GetUserIdFromCurPostOrInput(string caption)
13022 if (_curPost != null)
13024 id = _curPost.ScreenName;
13026 using (InputTabName inputName = new InputTabName())
13028 inputName.FormTitle = caption;
13029 inputName.FormDescription = Properties.Resources.FRMessage1;
13030 inputName.TabName = id;
13031 if (inputName.ShowDialog() == DialogResult.OK &&
13032 !string.IsNullOrEmpty(inputName.TabName.Trim()))
13034 id = inputName.TabName.Trim();
13044 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13046 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
13047 if (!string.IsNullOrEmpty(id))
13049 AddNewTabForUserTimeline(id);
13053 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
13055 string id = GetUserIdFromCurPostOrInput("Show Favstar");
13056 if (!string.IsNullOrEmpty(id))
13058 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
13062 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
13064 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
13067 private void TimelineRefreshEnableChange(bool isEnable)
13071 tw.StartUserStream();
13075 tw.StopUserStream();
13077 TimerTimeline.Enabled = isEnable;
13080 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
13082 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
13085 private void OpenUserAppointUrl()
13087 if (SettingDialog.UserAppointUrl != null)
13089 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
13091 if (_curPost != null)
13093 string xUrl = SettingDialog.UserAppointUrl;
13094 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
13095 if (_curPost.RetweetedId != null)
13097 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
13101 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
13103 OpenUriAsync(xUrl);
13108 OpenUriAsync(SettingDialog.UserAppointUrl);
13113 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
13115 OpenUserAppointUrl();
13118 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
13120 string selText = SourceLinkLabel.Text;
13123 Clipboard.SetDataObject(selText, false, 5, 100);
13125 catch (Exception ex)
13127 MessageBox.Show(ex.Message);
13131 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
13133 string selText = (string)SourceLinkLabel.Tag;
13136 Clipboard.SetDataObject(selText, false, 5, 100);
13138 catch (Exception ex)
13140 MessageBox.Show(ex.Message);
13144 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
13146 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
13148 SourceCopyMenuItem.Enabled = false;
13149 SourceUrlCopyMenuItem.Enabled = false;
13153 SourceCopyMenuItem.Enabled = true;
13154 SourceUrlCopyMenuItem.Enabled = true;
13158 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
13160 if (Form.ActiveForm == null)
13162 this.BeginInvoke((Action) (() =>
13164 this.Visible = true;
13165 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
13167 this.BringToFront();
13168 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
13170 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
13174 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13180 private void ReplaceAppName()
13182 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13183 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13186 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13188 this.SplitContainer3.Panel2Collapsed = false;
13190 // PreviewDistance が起動のたびに広がっていく問題の回避策
13191 // FixedPanel が Panel2 に設定された状態で Panel2 を開くと、初回だけ SplitterDistance が再計算されておかしくなるため、
13192 // None で開いた後に設定するようにする
13193 if (this.SplitContainer3.FixedPanel == FixedPanel.None)
13194 this.SplitContainer3.FixedPanel = FixedPanel.Panel2;
13197 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13199 this.OpenThumbnailPicture(e.Thumbnail);
13202 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13204 this.OpenUriAsync(e.ImageUrl);
13207 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13209 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13212 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13214 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13217 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13219 if (e.KeyCode == Keys.Space)
13221 this.JumpUnreadMenuItem_Click(null, null);
13223 e.SuppressKeyPress = true;
13227 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
13229 this.IconSizeNoneToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.IconNone;
13230 this.IconSize16ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon16;
13231 this.IconSize24ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon24;
13232 this.IconSize48ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48;
13233 this.IconSize48_2ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48_2;
13235 this.LockListSortOrderToolStripMenuItem.Checked = SettingDialog.SortOrderLock;
13238 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
13240 ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
13243 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
13245 ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
13248 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
13250 ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
13253 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
13255 ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
13258 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
13260 ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
13263 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
13265 if (SettingDialog.IconSz == iconSize) return;
13267 var oldIconCol = _iconCol;
13269 SettingDialog.IconSz = iconSize;
13270 ApplyListViewIconSize(iconSize);
13272 if (_iconCol != oldIconCol)
13274 foreach (TabPage tp in ListTab.TabPages)
13276 ResetColumns((DetailsListView)tp.Tag);
13280 if (_curList != null) _curList.Refresh();
13282 _modifySettingCommon = true;
13285 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
13287 var state = this.LockListSortOrderToolStripMenuItem.Checked;
13288 if (SettingDialog.SortOrderLock == state) return;
13290 SettingDialog.SortOrderLock = state;
13292 _modifySettingCommon = true;