1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
22 // You should have received a copy of the GNU General public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
29 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
32 using System.Collections.Generic;
33 using System.ComponentModel;
34 using System.Diagnostics;
40 using System.Net.Http;
41 using System.Reflection;
43 using System.Text.RegularExpressions;
44 using System.Threading;
45 using System.Threading.Tasks;
46 using System.Windows.Forms;
48 using OpenTween.Connection;
49 using OpenTween.OpenTweenCustomControl;
50 using OpenTween.Thumbnail;
54 public partial class TweenMain : OTBaseForm
57 private Size _mySize; //画面サイズ
58 private Point _myLoc; //画面位置
59 private int _mySpDis; //区切り位置
60 private int _mySpDis2; //発言欄区切り位置
61 private int _mySpDis3; //プレビュー区切り位置
62 private int _iconSz; //アイコンサイズ(現在は16、24、48の3種類。将来直接数字指定可能とする 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様)
63 private bool _iconCol; //1列表示の時true(48サイズのとき)
66 private bool _initial; //true:起動時処理中
67 private bool _initialLayout = true;
68 private bool _ignoreConfigSave; //true:起動時処理中
69 private bool _tabDrag; //タブドラッグ中フラグ(DoDragDropを実行するかの判定用)
70 private TabPage _beforeSelectedTab; //タブが削除されたときに前回選択されていたときのタブを選択する為に保持
71 private Point _tabMouseDownPoint;
72 private string _rclickTabName; //右クリックしたタブの名前(Tabコントロール機能不足対応)
73 private readonly object _syncObject = new object(); //ロック用
74 private const string detailHtmlFormatMono1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- pre {font-family: \"";
75 private const string detailHtmlFormat2 = "\", sans-serif; font-size: ";
76 private const string detailHtmlFormat3 = "pt; margin: 0; word-wrap: break-word; white-space: pre-wrap; color:rgb(";
77 private const string detailHtmlFormat4 = ");} a:link, a:visited, a:active, a:hover {color:rgb(";
78 private const string detailHtmlFormat5 = "); } --></style></head><body style=\"margin:0px; background-color:rgb(";
79 private const string detailHtmlFormatMono6 = ");\"><pre>";
80 private const string detailHtmlFormatMono7 = "</pre></body></html>";
81 private const string detailHtmlFormat1 = "<html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"><style type=\"text/css\"><!-- p {font-family: \"";
82 private const string detailHtmlFormat6 = ");\"><p><span style=\"vertical-align:text-bottom\">";
83 private const string detailHtmlFormat7 = "</span></p></body></html>";
84 private string detailHtmlFormatHeader;
85 private string detailHtmlFormatFooter;
86 private bool _myStatusError = false;
87 private bool _myStatusOnline = false;
88 private bool soundfileListup = false;
89 private FormWindowState _formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
92 //private SettingToConfig _cfg; //旧
93 private SettingLocal _cfgLocal;
94 private SettingCommon _cfgCommon;
95 private bool _modifySettingLocal = false;
96 private bool _modifySettingCommon = false;
97 private bool _modifySettingAtId = false;
100 private Twitter tw = new Twitter();
103 private GrowlHelper gh = new GrowlHelper(Application.ProductName);
106 private AppendSettingDialog SettingDialog = AppendSettingDialog.Instance; //設定画面インスタンス
107 private SearchWordDialog SearchDialog = new SearchWordDialog(); //検索画面インスタンス
108 private FilterDialog fltDialog = new FilterDialog(); //フィルター編集画面
109 private OpenURL UrlDialog = new OpenURL();
110 public AtIdSupplement AtIdSupl; //@id補助
111 public AtIdSupplement HashSupl; //Hashtag補助
112 public HashtagManage HashMgr;
113 private EventViewerDialog evtDialog;
116 private Font _fntUnread; //未読用フォント
117 private Color _clUnread; //未読用文字色
118 private Font _fntReaded; //既読用フォント
119 private Color _clReaded; //既読用文字色
120 private Color _clFav; //Fav用文字色
121 private Color _clOWL; //片思い用文字色
122 private Color _clRetweet; //Retweet用文字色
123 private Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText); //選択中の行用文字色
124 private Font _fntDetail; //発言詳細部用フォント
125 private Color _clDetail; //発言詳細部用色
126 private Color _clDetailLink; //発言詳細部用リンク文字色
127 private Color _clDetailBackcolor; //発言詳細部用背景色
128 private Color _clSelf; //自分の発言用背景色
129 private Color _clAtSelf; //自分宛返信用背景色
130 private Color _clTarget; //選択発言者の他の発言用背景色
131 private Color _clAtTarget; //選択発言中の返信先用背景色
132 private Color _clAtFromTarget; //選択発言者への返信発言用背景色
133 private Color _clAtTo; //選択発言の唯一@先
134 private Color _clListBackcolor; //リスト部通常発言背景色
135 private Color _clInputBackcolor; //入力欄背景色
136 private Color _clInputFont; //入力欄文字色
137 private Font _fntInputFont; //入力欄フォント
138 private ImageCache IconCache; //アイコン画像リスト
139 private Icon NIconAt; //At.ico タスクトレイアイコン:通常時
140 private Icon NIconAtRed; //AtRed.ico タスクトレイアイコン:通信エラー時
141 private Icon NIconAtSmoke; //AtSmoke.ico タスクトレイアイコン:オフライン時
142 private Icon[] NIconRefresh = new Icon[4]; //Refresh.ico タスクトレイアイコン:更新中(アニメーション用に4種類を保持するリスト)
143 private Icon TabIcon; //Tab.ico 未読のあるタブ用アイコン
144 private Icon MainIcon; //Main.ico 画面左上のアイコン
145 private Icon ReplyIcon; //5g
146 private Icon ReplyIconBlink; //6g
148 private ImageList _listViewImageList = new ImageList(); //ListViewItemの高さ変更用
150 private PostClass _anchorPost;
151 private bool _anchorFlag; //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
153 private List<PostingStatus> _history = new List<PostingStatus>(); //発言履歴
154 private int _hisIdx; //発言履歴カレントインデックス
156 //発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
157 private long? _reply_to_id; // リプライ先のステータスID 0の場合はリプライではない 注:複数あてのものはリプライではない
158 private string _reply_to_name; // リプライ先ステータスの書き込み者の名前
161 private List<DateTime> _postTimestamps = new List<DateTime>();
162 private List<DateTime> _favTimestamps = new List<DateTime>();
163 private Dictionary<DateTime, int> _tlTimestamps = new Dictionary<DateTime, int>();
164 private int _tlCount;
167 private SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
168 private SolidBrush _brsBackColorMine;
169 private SolidBrush _brsBackColorAt;
170 private SolidBrush _brsBackColorYou;
171 private SolidBrush _brsBackColorAtYou;
172 private SolidBrush _brsBackColorAtFromTarget;
173 private SolidBrush _brsBackColorAtTo;
174 private SolidBrush _brsBackColorNone;
175 private SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace)); //Listにフォーカスないときの選択行の背景色
176 private StringFormat sfTab = new StringFormat();
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////
179 private ToolStripAPIGauge _apiGauge;
180 private TabInformations _statuses;
182 // ListViewItem のキャッシュ関連
183 private int _itemCacheIndex;
184 private ListViewItem[] _itemCache;
185 private PostClass[] _postCache;
186 private ReaderWriterLockSlim itemCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
188 private TabPage _curTab;
189 private int _curItemIndex;
190 private DetailsListView _curList;
191 private PostClass _curPost;
192 private bool _isColumnChanged = false;
193 private bool _waitTimeline = false;
194 private bool _waitReply = false;
195 private bool _waitDm = false;
196 private bool _waitFav = false;
197 private bool _waitPubSearch = false;
198 private bool _waitUserTimeline = false;
199 private bool _waitLists = false;
200 private BackgroundWorker[] _bw = new BackgroundWorker[20];
201 private BackgroundWorker _bwFollower;
203 private int UnreadCounter = -1;
204 private int UnreadAtCounter = -1;
206 private string[] ColumnOrgText = new string[9];
207 private string[] ColumnText = new string[9];
209 private bool _DoFavRetweetFlags = false;
210 private bool osResumed = false;
212 //////////////////////////////////////////////////////////////////////////////////////////////////////////
213 private string _postBrowserStatusText = "";
215 private bool _colorize = false;
217 private System.Timers.Timer TimerTimeline = new System.Timers.Timer();
219 private ImageListViewItem displayItem;
222 /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
224 protected SizeF currentScaleFactor = new SizeF();
227 private struct urlUndo
229 public string Before;
233 private List<urlUndo> urlUndoBuffer = null;
235 private struct ReplyChain
237 public long OriginalId;
238 public long InReplyToId;
239 public TabPage OriginalTab;
241 public ReplyChain(long originalId, long inReplyToId, TabPage originalTab)
243 this.OriginalId = originalId;
244 this.InReplyToId = inReplyToId;
245 this.OriginalTab = originalTab;
249 private Stack<ReplyChain> replyChains; //[, ]でのリプライ移動の履歴
250 private Stack<Tuple<TabPage, PostClass>> selectPostChains = new Stack<Tuple<TabPage, PostClass>>(); //ポスト選択履歴
252 //Backgroundworkerの処理結果通知用引数構造体
253 private class GetWorkerResult
255 public string retMsg = ""; //処理結果詳細メッセージ。エラー時に値がセットされる
256 public MyCommon.WORKERTYPE type; //処理種別
257 public string tName = ""; //Fav追加・削除時のタブ名
258 public List<long> sIds = null; //Fav追加・削除成功分のID
259 public bool newDM = false;
261 public PostingStatus status;
264 //Backgroundworkerへ処理内容を通知するための引数用構造体
265 private class GetWorkerArg
267 public int page; //処理対象ページ番号
268 public MyCommon.WORKERTYPE type; //処理種別
269 public PostingStatus status = new PostingStatus(); //発言POST時の発言内容
270 public List<long> ids; //Fav追加・削除時のItemIndex
271 public List<long> sIds; //Fav追加・削除成功分のItemIndex
272 public string tName = ""; //Fav追加・削除時のタブ名
276 private enum SEARCHTYPE
283 private class PostingStatus
285 public string status = "";
286 public long? inReplyToId = null;
287 public string inReplyToName = null;
288 public string imageService = ""; //画像投稿サービス名
289 public string[] imagePath = null;
290 public PostingStatus()
293 public PostingStatus(string status, long? replyToId, string replyToName)
295 this.status = status;
296 this.inReplyToId = replyToId;
297 this.inReplyToName = replyToName;
301 private void TweenMain_Activated(object sender, EventArgs e)
303 //画面がアクティブになったら、発言欄の背景色戻す
304 if (StatusText.Focused)
306 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
310 private bool disposed = false;
313 /// 使用中のリソースをすべてクリーンアップします。
315 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
316 protected override void Dispose(bool disposing)
318 base.Dispose(disposing);
325 if (this.components != null)
326 this.components.Dispose();
329 SettingDialog.Dispose();
330 SearchDialog.Dispose();
333 if (NIconAt != null) NIconAt.Dispose();
334 if (NIconAtRed != null) NIconAtRed.Dispose();
335 if (NIconAtSmoke != null) NIconAtSmoke.Dispose();
336 if (NIconRefresh[0] != null) NIconRefresh[0].Dispose();
337 if (NIconRefresh[1] != null) NIconRefresh[1].Dispose();
338 if (NIconRefresh[2] != null) NIconRefresh[2].Dispose();
339 if (NIconRefresh[3] != null) NIconRefresh[3].Dispose();
340 if (TabIcon != null) TabIcon.Dispose();
341 if (MainIcon != null) MainIcon.Dispose();
342 if (ReplyIcon != null) ReplyIcon.Dispose();
343 if (ReplyIconBlink != null) ReplyIconBlink.Dispose();
344 _listViewImageList.Dispose();
345 _brsHighLight.Dispose();
346 if (_brsBackColorMine != null) _brsBackColorMine.Dispose();
347 if (_brsBackColorAt != null) _brsBackColorAt.Dispose();
348 if (_brsBackColorYou != null) _brsBackColorYou.Dispose();
349 if (_brsBackColorAtYou != null) _brsBackColorAtYou.Dispose();
350 if (_brsBackColorAtFromTarget != null) _brsBackColorAtFromTarget.Dispose();
351 if (_brsBackColorAtTo != null) _brsBackColorAtTo.Dispose();
352 if (_brsBackColorNone != null) _brsBackColorNone.Dispose();
353 if (_brsDeactiveSelection != null) _brsDeactiveSelection.Dispose();
356 foreach (BackgroundWorker bw in _bw)
361 if (_bwFollower != null)
363 _bwFollower.Dispose();
365 this._apiGauge.Dispose();
366 if (IconCache != null)
368 this.IconCache.CancelAsync();
369 this.IconCache.Dispose();
372 if (this.thumbnailTokenSource != null)
373 this.thumbnailTokenSource.Dispose();
375 this.itemCacheLock.Dispose();
377 this._hookGlobalHotkey.Dispose();
380 // 終了時にRemoveHandlerしておかないとメモリリークする
381 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
382 Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
384 this.disposed = true;
387 private void LoadIcon(ref Icon IconInstance, string FileName)
389 string dir = Application.StartupPath;
390 if (File.Exists(Path.Combine(dir, FileName)))
394 IconInstance = new Icon(Path.Combine(dir, FileName));
402 private void LoadIcons()
406 string dir = Application.StartupPath;
408 NIconAt = Properties.Resources.At;
409 NIconAtRed = Properties.Resources.AtRed;
410 NIconAtSmoke = Properties.Resources.AtSmoke;
411 NIconRefresh[0] = Properties.Resources.Refresh;
412 NIconRefresh[1] = Properties.Resources.Refresh2;
413 NIconRefresh[2] = Properties.Resources.Refresh3;
414 NIconRefresh[3] = Properties.Resources.Refresh4;
415 TabIcon = Properties.Resources.TabIcon;
416 MainIcon = Properties.Resources.MIcon;
417 ReplyIcon = Properties.Resources.Reply;
418 ReplyIconBlink = Properties.Resources.ReplyBlink;
420 if (!Directory.Exists(Path.Combine(dir, "Icons")))
423 LoadIcon(ref NIconAt, "Icons\\At.ico");
426 LoadIcon(ref NIconAtRed, "Icons\\AtRed.ico");
429 LoadIcon(ref NIconAtSmoke, "Icons\\AtSmoke.ico");
432 //アニメーション対応により4種類読み込み
433 LoadIcon(ref NIconRefresh[0], "Icons\\Refresh.ico");
434 LoadIcon(ref NIconRefresh[1], "Icons\\Refresh2.ico");
435 LoadIcon(ref NIconRefresh[2], "Icons\\Refresh3.ico");
436 LoadIcon(ref NIconRefresh[3], "Icons\\Refresh4.ico");
439 LoadIcon(ref TabIcon, "Icons\\Tab.ico");
442 LoadIcon(ref MainIcon, "Icons\\MIcon.ico");
445 LoadIcon(ref ReplyIcon, "Icons\\Reply.ico");
448 LoadIcon(ref ReplyIconBlink, "Icons\\ReplyBlink.ico");
451 private void InitColumns(ListView list, bool startup)
453 ColumnHeader _colHd1 = new ColumnHeader(); //アイコン
454 ColumnHeader _colHd2 = new ColumnHeader(); //ニックネーム
455 ColumnHeader _colHd3 = new ColumnHeader(); //本文
456 ColumnHeader _colHd4 = new ColumnHeader(); //日付
457 ColumnHeader _colHd5 = new ColumnHeader(); //ユーザID
458 ColumnHeader _colHd6 = new ColumnHeader(); //未読
459 ColumnHeader _colHd7 = new ColumnHeader(); //マーク&プロテクト
460 ColumnHeader _colHd8 = new ColumnHeader(); //ソース
464 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd2, _colHd3, _colHd4, _colHd5, _colHd6, _colHd7, _colHd8 });
468 list.Columns.AddRange(new ColumnHeader[] { _colHd1, _colHd3 });
472 _colHd1.Text = ColumnText[0];
474 _colHd2.Text = ColumnText[1];
476 _colHd3.Text = ColumnText[2];
478 _colHd4.Text = ColumnText[3];
480 _colHd5.Text = ColumnText[4];
482 _colHd6.Text = ColumnText[5];
484 _colHd7.Text = ColumnText[6];
486 _colHd8.Text = ColumnText[7];
489 int[] dispOrder = new int[8];
492 for (int i = 0; i < _curList.Columns.Count; i++)
494 for (int j = 0; j < _curList.Columns.Count; j++)
496 if (_curList.Columns[j].DisplayIndex == i)
503 for (int i = 0; i < _curList.Columns.Count; i++)
505 list.Columns[i].Width = _curList.Columns[i].Width;
506 list.Columns[dispOrder[i]].DisplayIndex = i;
513 list.Columns[0].Width = _cfgLocal.Width1;
514 list.Columns[1].Width = _cfgLocal.Width3;
515 list.Columns[0].DisplayIndex = 0;
516 list.Columns[1].DisplayIndex = 1;
520 for (int i = 0; i <= 7; i++)
522 if (_cfgLocal.DisplayIndex1 == i)
524 else if (_cfgLocal.DisplayIndex2 == i)
526 else if (_cfgLocal.DisplayIndex3 == i)
528 else if (_cfgLocal.DisplayIndex4 == i)
530 else if (_cfgLocal.DisplayIndex5 == i)
532 else if (_cfgLocal.DisplayIndex6 == i)
534 else if (_cfgLocal.DisplayIndex7 == i)
536 else if (_cfgLocal.DisplayIndex8 == i)
539 list.Columns[0].Width = _cfgLocal.Width1;
540 list.Columns[1].Width = _cfgLocal.Width2;
541 list.Columns[2].Width = _cfgLocal.Width3;
542 list.Columns[3].Width = _cfgLocal.Width4;
543 list.Columns[4].Width = _cfgLocal.Width5;
544 list.Columns[5].Width = _cfgLocal.Width6;
545 list.Columns[6].Width = _cfgLocal.Width7;
546 list.Columns[7].Width = _cfgLocal.Width8;
547 for (int i = 0; i <= 7; i++)
549 list.Columns[dispOrder[i]].DisplayIndex = i;
555 private void InitColumnText()
558 ColumnText[1] = Properties.Resources.AddNewTabText2;
559 ColumnText[2] = Properties.Resources.AddNewTabText3;
560 ColumnText[3] = Properties.Resources.AddNewTabText4_2;
561 ColumnText[4] = Properties.Resources.AddNewTabText5;
564 ColumnText[7] = "Source";
566 ColumnOrgText[0] = "";
567 ColumnOrgText[1] = Properties.Resources.AddNewTabText2;
568 ColumnOrgText[2] = Properties.Resources.AddNewTabText3;
569 ColumnOrgText[3] = Properties.Resources.AddNewTabText4_2;
570 ColumnOrgText[4] = Properties.Resources.AddNewTabText5;
571 ColumnOrgText[5] = "";
572 ColumnOrgText[6] = "";
573 ColumnOrgText[7] = "Source";
576 switch (_statuses.SortMode)
578 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
581 case IdComparerClass.ComparerMode.Data: //本文
584 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
587 case IdComparerClass.ComparerMode.Name: //名前
590 case IdComparerClass.ComparerMode.Source: //Source
597 if (_statuses.SortOrder == SortOrder.Descending)
599 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
600 ColumnText[2] = ColumnOrgText[2] + "▾";
604 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
605 ColumnText[2] = ColumnOrgText[2] + "▴";
610 if (_statuses.SortOrder == SortOrder.Descending)
612 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
613 ColumnText[c] = ColumnOrgText[c] + "▾";
617 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
618 ColumnText[c] = ColumnOrgText[c] + "▴";
623 private void InitializeTraceFrag()
626 TraceOutToolStripMenuItem.Checked = true;
627 MyCommon.TraceFlag = true;
629 if (!MyCommon.FileVersion.EndsWith("0"))
631 TraceOutToolStripMenuItem.Checked = true;
632 MyCommon.TraceFlag = true;
636 private void TweenMain_Load(object sender, EventArgs e)
638 _ignoreConfigSave = true;
639 this.Visible = false;
641 //Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
643 new InternetSecurityManager(PostBrowser);
644 this.PostBrowser.AllowWebBrowserDrop = false; // COMException を回避するため、ActiveX の初期化が終わってから設定する
646 MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
647 Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
649 if (MyApplication.StartupOptions.ContainsKey("d"))
650 MyCommon.TraceFlag = true;
652 Regex.CacheSize = 100;
654 InitializeTraceFrag();
655 LoadIcons(); // アイコン読み込み
658 _statuses = TabInformations.GetInstance();
661 this.Icon = MainIcon; //メインフォーム(TweenMain)
662 NotifyIcon1.Icon = NIconAt; //タスクトレイ
663 TabImage.Images.Add(TabIcon); //タブ見出し
665 SettingDialog.Owner = this;;
666 SearchDialog.Owner = this;
667 fltDialog.Owner = this;
668 UrlDialog.Owner = this;
670 _history.Add(new PostingStatus());
673 _reply_to_name = null;
675 //<<<<<<<<<設定関連>>>>>>>>>
682 ThumbnailGenerator.InitializeGenerator();
684 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
685 imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
686 imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
688 Thumbnail.Services.TonTwitterCom.InitializeOAuthToken = x =>
689 x.Initialize(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret,
690 this.tw.AccessToken, this.tw.AccessTokenSecret, "", "");
693 NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
694 this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
697 _fntUnread = _cfgLocal.FontUnread;
698 _clUnread = _cfgLocal.ColorUnread;
699 _fntReaded = _cfgLocal.FontRead;
700 _clReaded = _cfgLocal.ColorRead;
701 _clFav = _cfgLocal.ColorFav;
702 _clOWL = _cfgLocal.ColorOWL;
703 _clRetweet = _cfgLocal.ColorRetweet;
704 _fntDetail = _cfgLocal.FontDetail;
705 _clDetail = _cfgLocal.ColorDetail;
706 _clDetailLink = _cfgLocal.ColorDetailLink;
707 _clDetailBackcolor = _cfgLocal.ColorDetailBackcolor;
708 _clSelf = _cfgLocal.ColorSelf;
709 _clAtSelf = _cfgLocal.ColorAtSelf;
710 _clTarget = _cfgLocal.ColorTarget;
711 _clAtTarget = _cfgLocal.ColorAtTarget;
712 _clAtFromTarget = _cfgLocal.ColorAtFromTarget;
713 _clAtTo = _cfgLocal.ColorAtTo;
714 _clListBackcolor = _cfgLocal.ColorListBackcolor;
715 _clInputBackcolor = _cfgLocal.ColorInputBackcolor;
716 _clInputFont = _cfgLocal.ColorInputFont;
717 _fntInputFont = _cfgLocal.FontInputFont;
719 var fontUIGlobal = this._cfgLocal.FontUIGlobal;
720 if (fontUIGlobal != null)
722 OTBaseForm.GlobalFont = fontUIGlobal;
723 this.Font = fontUIGlobal;
726 // StringFormatオブジェクトへの事前設定
727 //sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
728 //sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
729 //sf.FormatFlags = StringFormatFlags.LineLimit; //
730 sfTab.Alignment = StringAlignment.Center;
731 sfTab.LineAlignment = StringAlignment.Center;
734 if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
736 if (this._cfgCommon.TimelinePeriod < 15 && this._cfgCommon.TimelinePeriod > 0)
737 this._cfgCommon.TimelinePeriod = 15;
739 if (this._cfgCommon.ReplyPeriod < 15 && this._cfgCommon.ReplyPeriod > 0)
740 this._cfgCommon.ReplyPeriod = 15;
742 if (this._cfgCommon.DMPeriod < 15 && this._cfgCommon.DMPeriod > 0)
743 this._cfgCommon.DMPeriod = 15;
745 if (this._cfgCommon.PubSearchPeriod < 30 && this._cfgCommon.PubSearchPeriod > 0)
746 this._cfgCommon.PubSearchPeriod = 30;
748 if (this._cfgCommon.UserTimelinePeriod < 15 && this._cfgCommon.UserTimelinePeriod > 0)
749 this._cfgCommon.UserTimelinePeriod = 15;
751 if (this._cfgCommon.ListsPeriod < 15 && this._cfgCommon.ListsPeriod > 0)
752 this._cfgCommon.ListsPeriod = 15;
756 this.SettingDialog.LoadConfig(this._cfgCommon, this._cfgLocal);
757 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
758 SettingDialog.TwitterApiUrl = _cfgCommon.TwitterUrl;
761 if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
762 tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
764 SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
766 //新着取得時のリストスクロールをするか。trueならスクロールしない
767 ListLockMenuItem.Checked = _cfgCommon.ListLock;
768 this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
769 SettingDialog.IconSz = _cfgCommon.IconSize;
771 SettingDialog.Status = _cfgLocal.StatusText;
773 SettingDialog.UnreadManage = _cfgCommon.UnreadManage;
775 SettingDialog.PlaySound = _cfgCommon.PlaySound;
776 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
777 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
778 //片思い表示。trueなら片思い表示する
779 SettingDialog.OneWayLove = _cfgCommon.OneWayLove;
781 SettingDialog.FontUnread = _fntUnread;
782 SettingDialog.ColorUnread = _clUnread;
783 SettingDialog.FontReaded = _fntReaded;
784 SettingDialog.ColorReaded = _clReaded;
785 SettingDialog.ColorFav = _clFav;
786 SettingDialog.ColorOWL = _clOWL;
787 SettingDialog.ColorRetweet = _clRetweet;
788 SettingDialog.FontDetail = _fntDetail;
789 SettingDialog.ColorDetail = _clDetail;
790 SettingDialog.ColorDetailLink = _clDetailLink;
791 SettingDialog.ColorDetailBackcolor = _clDetailBackcolor;
792 SettingDialog.ColorSelf = _clSelf;
793 SettingDialog.ColorAtSelf = _clAtSelf;
794 SettingDialog.ColorTarget = _clTarget;
795 SettingDialog.ColorAtTarget = _clAtTarget;
796 SettingDialog.ColorAtFromTarget = _clAtFromTarget;
797 SettingDialog.ColorAtTo = _clAtTo;
798 SettingDialog.ColorListBackcolor = _clListBackcolor;
799 SettingDialog.ColorInputBackcolor = _clInputBackcolor;
800 SettingDialog.ColorInputFont = _clInputFont;
801 SettingDialog.FontInputFont = _fntInputFont;
803 SettingDialog.NameBalloon = _cfgCommon.NameBalloon;
804 SettingDialog.PostCtrlEnter = _cfgCommon.PostCtrlEnter;
805 SettingDialog.PostShiftEnter = _cfgCommon.PostShiftEnter;
807 SettingDialog.CountApi = _cfgCommon.CountApi;
808 SettingDialog.CountApiReply = _cfgCommon.CountApiReply;
809 if (SettingDialog.CountApi < 20 || SettingDialog.CountApi > 200) SettingDialog.CountApi = 60;
810 if (SettingDialog.CountApiReply < 20 || SettingDialog.CountApiReply > 200) SettingDialog.CountApiReply = 40;
812 SettingDialog.BrowserPath = _cfgLocal.BrowserPath;
813 SettingDialog.PostAndGet = _cfgCommon.PostAndGet;
814 SettingDialog.UseRecommendStatus = _cfgLocal.UseRecommendStatus;
815 SettingDialog.DispUsername = _cfgCommon.DispUsername;
816 SettingDialog.CloseToExit = _cfgCommon.CloseToExit;
817 SettingDialog.MinimizeToTray = _cfgCommon.MinimizeToTray;
818 SettingDialog.DispLatestPost = _cfgCommon.DispLatestPost;
819 SettingDialog.SortOrderLock = _cfgCommon.SortOrderLock;
820 SettingDialog.ViewTabBottom = _cfgCommon.ViewTabBottom;
821 SettingDialog.TinyUrlResolve = _cfgCommon.TinyUrlResolve;
823 SettingDialog.SelectedProxyType = _cfgLocal.ProxyType;
824 SettingDialog.ProxyAddress = _cfgLocal.ProxyAddress;
825 SettingDialog.ProxyPort = _cfgLocal.ProxyPort;
826 SettingDialog.ProxyUser = _cfgLocal.ProxyUser;
827 SettingDialog.ProxyPassword = _cfgLocal.ProxyPassword;
829 SettingDialog.RestrictFavCheck = _cfgCommon.RestrictFavCheck;
830 SettingDialog.AlwaysTop = _cfgCommon.AlwaysTop;
831 SettingDialog.UrlConvertAuto = false;
832 //SettingDialog.UrlConvertAuto = _cfgCommon.UrlConvertAuto;
834 SettingDialog.UseUnreadStyle = _cfgCommon.UseUnreadStyle;
835 SettingDialog.DefaultTimeOut = _cfgCommon.DefaultTimeOut;
836 SettingDialog.RetweetNoConfirm = _cfgCommon.RetweetNoConfirm;
837 SettingDialog.PlaySound = _cfgCommon.PlaySound;
838 SettingDialog.DateTimeFormat = _cfgCommon.DateTimeFormat;
839 SettingDialog.LimitBalloon = _cfgCommon.LimitBalloon;
840 SettingDialog.EventNotifyEnabled = _cfgCommon.EventNotifyEnabled;
841 SettingDialog.EventNotifyFlag = _cfgCommon.EventNotifyFlag;
842 SettingDialog.IsMyEventNotifyFlag = _cfgCommon.IsMyEventNotifyFlag;
843 SettingDialog.ForceEventNotify = _cfgCommon.ForceEventNotify;
844 SettingDialog.FavEventUnread = _cfgCommon.FavEventUnread;
845 SettingDialog.TranslateLanguage = _cfgCommon.TranslateLanguage;
846 SettingDialog.EventSoundFile = _cfgCommon.EventSoundFile;
848 //廃止サービスが選択されていた場合bit.lyへ読み替え
849 if (_cfgCommon.AutoShortUrlFirst < 0)
850 _cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
852 SettingDialog.AutoShortUrlFirst = _cfgCommon.AutoShortUrlFirst;
853 SettingDialog.TabIconDisp = _cfgCommon.TabIconDisp;
854 SettingDialog.ReplyIconState = _cfgCommon.ReplyIconState;
855 SettingDialog.ReadOwnPost = _cfgCommon.ReadOwnPost;
856 SettingDialog.ReadOldPosts = _cfgCommon.ReadOldPosts;
857 SettingDialog.BitlyUser = _cfgCommon.BilyUser;
858 SettingDialog.BitlyPwd = _cfgCommon.BitlyPwd;
859 SettingDialog.ShowGrid = _cfgCommon.ShowGrid;
860 SettingDialog.Language = _cfgCommon.Language;
861 SettingDialog.UseAtIdSupplement = _cfgCommon.UseAtIdSupplement;
862 SettingDialog.UseHashSupplement = _cfgCommon.UseHashSupplement;
863 SettingDialog.PreviewEnable = _cfgCommon.PreviewEnable;
864 SettingDialog.StatusAreaAtBottom = _cfgCommon.StatusAreaAtBottom;
865 AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
867 SettingDialog.IsMonospace = _cfgCommon.IsMonospace;
869 this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
870 this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
872 //Regex statregex = new Regex("^0*");
873 SettingDialog.RecommendStatusText = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
878 if (DateTime.Now.ToString(SettingDialog.DateTimeFormat).Length == 0)
880 // このブロックは絶対に実行されないはず
881 // 変換が成功した場合にLengthが0にならない
882 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
885 catch (FormatException)
887 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
888 SettingDialog.DateTimeFormat = "yyyy/MM/dd H:mm:ss";
891 SettingDialog.Nicoms = _cfgCommon.Nicoms;
892 SettingDialog.HotkeyEnabled = _cfgCommon.HotkeyEnabled;
893 SettingDialog.HotkeyMod = _cfgCommon.HotkeyModifier;
894 SettingDialog.HotkeyKey = _cfgCommon.HotkeyKey;
895 SettingDialog.HotkeyValue = _cfgCommon.HotkeyValue;
897 SettingDialog.BlinkNewMentions = _cfgCommon.BlinkNewMentions;
899 SettingDialog.UseAdditionalCount = _cfgCommon.UseAdditionalCount;
900 SettingDialog.MoreCountApi = _cfgCommon.MoreCountApi;
901 SettingDialog.FirstCountApi = _cfgCommon.FirstCountApi;
902 SettingDialog.SearchCountApi = _cfgCommon.SearchCountApi;
903 SettingDialog.FavoritesCountApi = _cfgCommon.FavoritesCountApi;
904 SettingDialog.UserTimelineCountApi = _cfgCommon.UserTimelineCountApi;
905 SettingDialog.ListCountApi = _cfgCommon.ListCountApi;
907 SettingDialog.OpenUserTimeline = _cfgCommon.OpenUserTimeline;
908 SettingDialog.ListDoubleClickAction = _cfgCommon.ListDoubleClickAction;
909 SettingDialog.UserAppointUrl = _cfgCommon.UserAppointUrl;
910 SettingDialog.HideDuplicatedRetweets = _cfgCommon.HideDuplicatedRetweets;
912 SettingDialog.EnableImgAzyobuziNet = _cfgCommon.EnableImgAzyobuziNet;
913 SettingDialog.ImgAzyobuziNetDisabledInDM = _cfgCommon.ImgAzyobuziNetDisabledInDM;
914 SettingDialog.MapThumbnailProvider = _cfgCommon.MapThumbnailProvider;
915 SettingDialog.MapThumbnailHeight = _cfgCommon.MapThumbnailHeight;
916 SettingDialog.MapThumbnailWidth = _cfgCommon.MapThumbnailWidth;
917 SettingDialog.MapThumbnailZoom = _cfgCommon.MapThumbnailZoom;
918 SettingDialog.IsListStatusesIncludeRts = _cfgCommon.IsListsIncludeRts;
919 SettingDialog.TabMouseLock = _cfgCommon.TabMouseLock;
920 SettingDialog.IsRemoveSameEvent = _cfgCommon.IsRemoveSameEvent;
921 SettingDialog.IsNotifyUseGrowl = _cfgCommon.IsUseNotifyGrowl;
924 HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
925 HashMgr = new HashtagManage(HashSupl,
926 _cfgCommon.HashTags.ToArray(),
927 _cfgCommon.HashSelected,
928 _cfgCommon.HashIsPermanent,
929 _cfgCommon.HashIsHead,
930 _cfgCommon.HashIsNotAddToAtReply);
931 if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
935 Networking.Initialize();
938 this.IconCache = new ImageCache();
940 bool saveRequired = false;
941 bool firstRun = false;
943 //ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
944 if (string.IsNullOrEmpty(tw.Username))
948 SettingDialog.ShowInTaskbar = true;
950 //設定せずにキャンセルされた場合はプログラム終了
951 if (SettingDialog.ShowDialog(this) == DialogResult.Cancel)
953 Application.Exit(); //強制終了
956 //設定されたが、依然ユーザー名とパスワードが未設定ならプログラム終了
957 if (string.IsNullOrEmpty(tw.Username))
959 Application.Exit(); //強制終了
962 SettingDialog.ShowInTaskbar = false;
966 _fntUnread = SettingDialog.FontUnread;
967 _clUnread = SettingDialog.ColorUnread;
968 _fntReaded = SettingDialog.FontReaded;
969 _clReaded = SettingDialog.ColorReaded;
970 _clFav = SettingDialog.ColorFav;
971 _clOWL = SettingDialog.ColorOWL;
972 _clRetweet = SettingDialog.ColorRetweet;
973 _fntDetail = SettingDialog.FontDetail;
974 _clDetail = SettingDialog.ColorDetail;
975 _clDetailLink = SettingDialog.ColorDetailLink;
976 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
977 _clSelf = SettingDialog.ColorSelf;
978 _clAtSelf = SettingDialog.ColorAtSelf;
979 _clTarget = SettingDialog.ColorTarget;
980 _clAtTarget = SettingDialog.ColorAtTarget;
981 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
982 _clAtTo = SettingDialog.ColorAtTo;
983 _clListBackcolor = SettingDialog.ColorListBackcolor;
984 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
985 _clInputFont = SettingDialog.ColorInputFont;
986 _fntInputFont = SettingDialog.FontInputFont;
988 //他の設定項目は、随時設定画面で保持している値を読み出して使用
991 _brsBackColorMine = new SolidBrush(_clSelf);
992 _brsBackColorAt = new SolidBrush(_clAtSelf);
993 _brsBackColorYou = new SolidBrush(_clTarget);
994 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
995 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
996 _brsBackColorAtTo = new SolidBrush(_clAtTo);
997 //_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
998 _brsBackColorNone = new SolidBrush(_clListBackcolor);
1000 InitDetailHtmlFormat();
1002 if (SettingDialog.HotkeyEnabled)
1005 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
1006 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
1007 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
1008 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
1009 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
1011 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
1015 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
1016 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
1017 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
1018 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
1020 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
1021 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
1022 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
1023 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
1024 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
1025 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
1026 tw.TrackWord = _cfgCommon.TrackWord;
1027 TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
1028 tw.AllAtReply = _cfgCommon.AllAtReply;
1029 AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
1032 ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
1035 this.ClientSize = _cfgLocal.FormSize;
1036 _mySize = _cfgLocal.FormSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1037 _myLoc = _cfgLocal.FormLocation;
1039 if (this.WindowState != FormWindowState.Minimized)
1041 this.DesktopLocation = _cfgLocal.FormLocation;
1042 Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
1043 bool outOfScreen = true;
1044 if (Screen.AllScreens.Length == 1) //ハングするとの報告
1046 foreach (Screen scr in Screen.AllScreens)
1048 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1050 outOfScreen = false;
1056 this.DesktopLocation = new Point(0, 0);
1057 _myLoc = this.DesktopLocation;
1061 this.TopMost = SettingDialog.AlwaysTop;
1062 _mySpDis = _cfgLocal.SplitterDistance;
1063 _mySpDis2 = _cfgLocal.StatusTextHeight;
1064 _mySpDis3 = _cfgLocal.PreviewDistance;
1065 if (_mySpDis3 == -1)
1067 _mySpDis3 = _mySize.Width - 150;
1068 if (_mySpDis3 < 1) _mySpDis3 = 50;
1069 _cfgLocal.PreviewDistance = _mySpDis3;
1071 MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
1072 //this.Tween_ClientSizeChanged(this, null);
1073 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
1074 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
1076 StatusText.Font = _fntInputFont;
1077 StatusText.ForeColor = _clInputFont;
1079 // NameLabel のフォントを OTBaseForm.GlobalFont に変更
1080 this.NameLabel.Font = this.ReplaceToGlobalFont(this.NameLabel.Font);
1082 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
1083 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
1085 //全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1086 if (SettingDialog.UnreadManage == false)
1088 ReadedStripMenuItem.Enabled = false;
1089 UnreadStripMenuItem.Enabled = false;
1092 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
1095 TimerTimeline.AutoReset = true;
1096 TimerTimeline.SynchronizingObject = this;
1098 TimerTimeline.Interval = 1000;
1099 TimerTimeline.Enabled = true;
1102 TimerRefreshIcon.Interval = 200;
1103 TimerRefreshIcon.Enabled = true;
1106 StatusLabel.Text = "";
1107 StatusLabel.AutoToolTip = false;
1108 StatusLabel.ToolTipText = "";
1110 lblLen.Text = GetRestStatusCount(true, false).ToString();
1112 ////////////////////////////////////////////////////////////////////////////////
1113 _statuses.SortOrder = (SortOrder)_cfgCommon.SortOrder;
1114 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
1115 switch (_cfgCommon.SortColumn)
1117 case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1121 mode = IdComparerClass.ComparerMode.Id; //Idソートに読み替え
1124 mode = IdComparerClass.ComparerMode.Nickname;
1127 mode = IdComparerClass.ComparerMode.Data;
1130 mode = IdComparerClass.ComparerMode.Id;
1133 mode = IdComparerClass.ComparerMode.Name;
1136 mode = IdComparerClass.ComparerMode.Source;
1139 _statuses.SortMode = mode;
1140 ////////////////////////////////////////////////////////////////////////////////
1142 ApplyListViewIconSize(SettingDialog.IconSz);
1144 StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
1145 StatusLabelUrl.Text = ""; //画面左下のリンク先URL表示部を初期化
1146 NameLabel.Text = ""; //発言詳細部名前ラベル初期化
1147 DateTimeLabel.Text = ""; //発言詳細部日時ラベル初期化
1148 SourceLinkLabel.Text = ""; //Source部分初期化
1150 //<<<<<<<<タブ関連>>>>>>>
1151 //デフォルトタブの存在チェック、ない場合には追加
1152 if (_statuses.GetTabByType(MyCommon.TabUsageType.Home) == null)
1155 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.RECENT, out tab))
1157 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1161 tab.TabType = MyCommon.TabUsageType.Home;
1164 if (_statuses.GetTabByType(MyCommon.TabUsageType.Mentions) == null)
1167 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.REPLY, out tab))
1169 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1173 tab.TabType = MyCommon.TabUsageType.Mentions;
1176 if (_statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage) == null)
1179 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.DM, out tab))
1181 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1185 tab.TabType = MyCommon.TabUsageType.DirectMessage;
1188 if (_statuses.GetTabByType(MyCommon.TabUsageType.Favorites) == null)
1191 if (!_statuses.Tabs.TryGetValue(MyCommon.DEFAULTTAB.FAV, out tab))
1193 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1197 tab.TabType = MyCommon.TabUsageType.Favorites;
1200 foreach (var tab in _statuses.Tabs.Values)
1202 if (tab.TabType == MyCommon.TabUsageType.Undefined)
1204 tab.TabType = MyCommon.TabUsageType.UserDefined;
1206 if (!AddNewTab(tab.TabName, true, tab.TabType, tab.ListInfo))
1207 throw new TabException(Properties.Resources.TweenMain_LoadText1);
1210 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1211 CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1212 CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1213 CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1215 if (SettingDialog.MinimizeToTray == false || this.WindowState != FormWindowState.Minimized)
1217 this.Visible = true;
1219 _curTab = ListTab.SelectedTab;
1221 _curList = (DetailsListView)_curTab.Tag;
1222 SetMainWindowTitle();
1223 SetNotifyIconText();
1225 if (SettingDialog.TabIconDisp)
1227 ListTab.DrawMode = TabDrawMode.Normal;
1231 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1232 ListTab.DrawItem += ListTab_DrawItem;
1233 ListTab.ImageList = null;
1236 _ignoreConfigSave = false;
1237 this.TweenMain_Resize(null, null);
1238 if (saveRequired) SaveConfigsAll(false);
1242 tw.VerifyCredentials();
1243 foreach (UserAccount ua in _cfgCommon.UserAccounts)
1245 if (ua.Username.ToLower() == tw.Username.ToLower())
1247 ua.UserId = tw.UserId;
1252 foreach (UserAccount ua in SettingDialog.UserAccounts)
1254 if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
1256 ua.UserId = tw.UserId;
1263 // 初回起動時だけ右下のメニューを目立たせる
1264 HashStripSplitButton.ShowDropDown();
1271 private void InitDetailHtmlFormat()
1273 if (SettingDialog.IsMonospace)
1275 detailHtmlFormatHeader = detailHtmlFormatMono1;
1276 detailHtmlFormatFooter = detailHtmlFormatMono7;
1280 detailHtmlFormatHeader = detailHtmlFormat1;
1281 detailHtmlFormatFooter = detailHtmlFormat7;
1283 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();
1284 if (SettingDialog.IsMonospace)
1286 detailHtmlFormatHeader += detailHtmlFormatMono6;
1290 detailHtmlFormatHeader += detailHtmlFormat6;
1294 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1299 txt = ListTab.TabPages[e.Index].Text;
1306 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1307 if (e.State == DrawItemState.Selected)
1309 e.DrawFocusRectangle();
1314 if (_statuses.Tabs[txt].UnreadCount > 0)
1317 fore = System.Drawing.SystemBrushes.ControlText;
1321 fore = System.Drawing.SystemBrushes.ControlText;
1323 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, sfTab);
1326 private void LoadConfig()
1328 _cfgCommon = SettingCommon.Load();
1329 SettingCommon.Instance = this._cfgCommon;
1330 if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
1332 _cfgCommon.UserAccounts = new List<UserAccount>();
1333 if (!string.IsNullOrEmpty(_cfgCommon.UserName))
1335 UserAccount account = new UserAccount();
1336 account.Username = _cfgCommon.UserName;
1337 account.UserId = _cfgCommon.UserId;
1338 account.Token = _cfgCommon.Token;
1339 account.TokenSecret = _cfgCommon.TokenSecret;
1341 _cfgCommon.UserAccounts.Add(account);
1344 _cfgLocal = SettingLocal.Load();
1345 List<TabClass> tabs = SettingTabs.Load().Tabs;
1346 foreach (TabClass tb in tabs)
1350 _statuses.Tabs.Add(tb.TabName, tb);
1354 tb.TabName = _statuses.GetUniqueTabName();
1355 _statuses.Tabs.Add(tb.TabName, tb);
1358 if (_statuses.Tabs.Count == 0)
1360 _statuses.AddTab(MyCommon.DEFAULTTAB.RECENT, MyCommon.TabUsageType.Home, null);
1361 _statuses.AddTab(MyCommon.DEFAULTTAB.REPLY, MyCommon.TabUsageType.Mentions, null);
1362 _statuses.AddTab(MyCommon.DEFAULTTAB.DM, MyCommon.TabUsageType.DirectMessage, null);
1363 _statuses.AddTab(MyCommon.DEFAULTTAB.FAV, MyCommon.TabUsageType.Favorites, null);
1367 private void TimerInterval_Changed(object sender, IntervalChangedEventArgs e) //Handles SettingDialog.IntervalChanged
1369 if (!TimerTimeline.Enabled) return;
1373 private IntervalChangedEventArgs ResetTimers = new IntervalChangedEventArgs();
1375 private static int homeCounter = 0;
1376 private static int mentionCounter = 0;
1377 private static int dmCounter = 0;
1378 private static int pubSearchCounter = 0;
1379 private static int userTimelineCounter = 0;
1380 private static int listsCounter = 0;
1381 private static int usCounter = 0;
1382 private static int ResumeWait = 0;
1383 private static int refreshFollowers = 0;
1385 private void TimerTimeline_Elapsed(object sender, EventArgs e)
1387 if (homeCounter > 0) Interlocked.Decrement(ref homeCounter);
1388 if (mentionCounter > 0) Interlocked.Decrement(ref mentionCounter);
1389 if (dmCounter > 0) Interlocked.Decrement(ref dmCounter);
1390 if (pubSearchCounter > 0) Interlocked.Decrement(ref pubSearchCounter);
1391 if (userTimelineCounter > 0) Interlocked.Decrement(ref userTimelineCounter);
1392 if (listsCounter > 0) Interlocked.Decrement(ref listsCounter);
1393 if (usCounter > 0) Interlocked.Decrement(ref usCounter);
1394 Interlocked.Increment(ref refreshFollowers);
1397 if (ResetTimers.Timeline || homeCounter <= 0 && this._cfgCommon.TimelinePeriod > 0)
1399 Interlocked.Exchange(ref homeCounter, this._cfgCommon.TimelinePeriod);
1400 if (!tw.IsUserstreamDataReceived && !ResetTimers.Timeline) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1401 ResetTimers.Timeline = false;
1403 if (ResetTimers.Reply || mentionCounter <= 0 && this._cfgCommon.ReplyPeriod > 0)
1405 Interlocked.Exchange(ref mentionCounter, this._cfgCommon.ReplyPeriod);
1406 if (!tw.IsUserstreamDataReceived && !ResetTimers.Reply) GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1407 ResetTimers.Reply = false;
1409 if (ResetTimers.DirectMessage || dmCounter <= 0 && this._cfgCommon.DMPeriod > 0)
1411 Interlocked.Exchange(ref dmCounter, this._cfgCommon.DMPeriod);
1412 if (!tw.IsUserstreamDataReceived && !ResetTimers.DirectMessage) GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1413 ResetTimers.DirectMessage = false;
1415 if (ResetTimers.PublicSearch || pubSearchCounter <= 0 && this._cfgCommon.PubSearchPeriod > 0)
1417 Interlocked.Exchange(ref pubSearchCounter, this._cfgCommon.PubSearchPeriod);
1418 if (!ResetTimers.PublicSearch) GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1419 ResetTimers.PublicSearch = false;
1421 if (ResetTimers.UserTimeline || userTimelineCounter <= 0 && this._cfgCommon.UserTimelinePeriod > 0)
1423 Interlocked.Exchange(ref userTimelineCounter, this._cfgCommon.UserTimelinePeriod);
1424 if (!ResetTimers.UserTimeline) GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1425 ResetTimers.UserTimeline = false;
1427 if (ResetTimers.Lists || listsCounter <= 0 && this._cfgCommon.ListsPeriod > 0)
1429 Interlocked.Exchange(ref listsCounter, this._cfgCommon.ListsPeriod);
1430 if (!ResetTimers.Lists) GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1431 ResetTimers.Lists = false;
1433 if (ResetTimers.UserStream || usCounter <= 0 && this._cfgCommon.UserstreamPeriod > 0)
1435 Interlocked.Exchange(ref usCounter, this._cfgCommon.UserstreamPeriod);
1436 if (this._isActiveUserstream) RefreshTimeline(true);
1437 ResetTimers.UserStream = false;
1439 if (refreshFollowers > 6 * 3600)
1441 Interlocked.Exchange(ref refreshFollowers, 0);
1442 doGetFollowersMenu();
1443 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
1444 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1448 Interlocked.Increment(ref ResumeWait);
1449 if (ResumeWait > 30)
1452 Interlocked.Exchange(ref ResumeWait, 0);
1453 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
1454 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
1455 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
1456 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, "");
1457 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, "");
1458 GetTimeline(MyCommon.WORKERTYPE.List, 1, "");
1459 doGetFollowersMenu();
1460 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
1465 private void RefreshTimeline(bool isUserStream)
1467 if (isUserStream) this.RefreshTasktrayIcon(true);
1469 int smode = -1; //-1:制御しない,-2:最新へ,その他:topitem使用
1470 long topId = GetScrollPos(ref smode);
1471 int befCnt = _curList.VirtualListSize;
1474 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
1475 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
1476 SaveSelectedStatus(selId, focusedId);
1479 int dmCount = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount;
1482 PostClass[] notifyPosts = null;
1483 string soundFile = "";
1485 bool isMention = false;
1486 bool isDelete = false;
1487 addCount = _statuses.SubmitUpdate(ref soundFile, ref notifyPosts, ref isMention, ref isDelete, isUserStream);
1489 if (MyCommon._endingFlag) return;
1494 foreach (TabPage tab in ListTab.TabPages)
1496 DetailsListView lst = (DetailsListView)tab.Tag;
1497 TabClass tabInfo = _statuses.Tabs[tab.Text];
1498 using (ControlTransaction.Update(lst))
1500 if (isDelete || lst.VirtualListSize != tabInfo.AllCount)
1502 if (lst.Equals(_curList))
1504 this.PurgeListViewItemCache();
1508 lst.VirtualListSize = tabInfo.AllCount; //リスト件数更新
1514 this.SelectListItem(lst,
1515 tabInfo.IndexOf(selId[tab.Text]),
1516 tabInfo.IndexOf(focusedId[tab.Text]));
1519 if (tabInfo.UnreadCount > 0)
1520 if (SettingDialog.TabIconDisp)
1521 if (tab.ImageIndex == -1) tab.ImageIndex = 0; //タブアイコン
1523 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
1527 //ex.Data["Msg"] = "Ref1, UseAPI=" + SettingDialog.UseAPI.ToString();
1536 if (befCnt != _curList.VirtualListSize)
1542 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(0);
1546 if (_curList.VirtualListSize > 0) _curList.EnsureVisible(_curList.VirtualListSize - 1);
1553 if (_curList.VirtualListSize > 0 && _statuses.IndexOf(_curTab.Text, topId) > -1)
1555 _curList.EnsureVisible(_curList.VirtualListSize - 1);
1556 _curList.EnsureVisible(_statuses.IndexOf(_curTab.Text, topId));
1562 catch (Exception ex)
1564 ex.Data["Msg"] = "Ref2";
1570 NotifyNewPosts(notifyPosts,
1573 isMention || dmCount != _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).AllCount);
1575 SetMainWindowTitle();
1576 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
1578 HashSupl.AddRangeItem(tw.GetHashList());
1582 private long GetScrollPos(ref int smode)
1585 if (_curList != null && _curTab != null && _curList.VirtualListSize > 0)
1587 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
1589 if (_statuses.SortOrder == SortOrder.Ascending)
1592 if (ListLockMenuItem.Checked)
1597 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1602 //最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1604 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1); //一番下
1605 if (_item == null) _item = _curList.Items[_curList.VirtualListSize - 1];
1606 if (_item.Index == _curList.VirtualListSize - 1)
1613 //if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1621 if (ListLockMenuItem.Checked)
1624 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1629 //最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1632 _item = _curList.GetItemAt(0, 10); //一番上
1633 if (_item == null) _item = _curList.Items[0];
1634 if (_item.Index == 0)
1640 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1649 if (_curList.TopItem != null) topId = _statuses.GetId(_curTab.Text, _curList.TopItem.Index);
1660 private void SaveSelectedStatus(Dictionary<string, long[]> selId, Dictionary<string, long[]> focusedId)
1662 if (MyCommon._endingFlag) return;
1663 foreach (TabPage tab in ListTab.TabPages)
1665 var lst = (DetailsListView)tab.Tag;
1666 var tabInfo = _statuses.Tabs[tab.Text];
1667 if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
1669 selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
1673 selId.Add(tab.Text, new long[1] {-2});
1676 var fIds = new long[2]; // 0 = focus, 1 = selection mark
1677 var item = lst.FocusedItem;
1678 fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
1679 var mIdx = lst.SelectionMark;
1680 fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
1681 focusedId.Add(tab.Text, fIds);
1686 private bool BalloonRequired()
1688 Twitter.FormattedEvent ev = new Twitter.FormattedEvent();
1689 ev.Eventtype = MyCommon.EVENTTYPE.None;
1691 return BalloonRequired(ev);
1694 private bool IsEventNotifyAsEventType(MyCommon.EVENTTYPE type)
1696 return SettingDialog.EventNotifyEnabled && (type & SettingDialog.EventNotifyFlag) != 0 || type == MyCommon.EVENTTYPE.None;
1699 private bool IsMyEventNotityAsEventType(Twitter.FormattedEvent ev)
1701 return (ev.Eventtype & SettingDialog.IsMyEventNotifyFlag) != 0 ? true : !ev.IsMe;
1704 private bool BalloonRequired(Twitter.FormattedEvent ev)
1707 IsEventNotifyAsEventType(ev.Eventtype) && IsMyEventNotityAsEventType(ev) &&
1708 (NewPostPopMenuItem.Checked || (SettingDialog.ForceEventNotify && ev.Eventtype != MyCommon.EVENTTYPE.None)) &&
1712 SettingDialog.LimitBalloon &&
1714 this.WindowState == FormWindowState.Minimized ||
1716 Form.ActiveForm == null
1719 !SettingDialog.LimitBalloon
1722 !NativeMethods.IsScreenSaverRunning())
1732 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1734 if (notifyPosts != null &&
1735 notifyPosts.Length > 0 &&
1736 this.SettingDialog.ReadOwnPost &&
1737 notifyPosts.All((post) => { return post.UserId == tw.UserId || post.ScreenName == tw.Username; }))
1743 if (BalloonRequired())
1745 if (notifyPosts != null && notifyPosts.Length > 0)
1747 //Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1748 if (SettingDialog.IsNotifyUseGrowl)
1750 StringBuilder sb = new StringBuilder();
1754 foreach (PostClass post in notifyPosts)
1756 if (!(notifyPosts.Length > 3))
1762 if (post.IsReply && !post.IsExcludeReply) reply = true;
1763 if (post.IsDm) dm = true;
1764 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1765 switch (SettingDialog.NameBalloon)
1767 case MyCommon.NameBalloonEnum.UserID:
1768 sb.Append(post.ScreenName).Append(" : ");
1770 case MyCommon.NameBalloonEnum.NickName:
1771 sb.Append(post.Nickname).Append(" : ");
1774 sb.Append(post.TextFromApi);
1775 if (notifyPosts.Length > 3)
1777 if (notifyPosts.Last() != post) continue;
1780 StringBuilder title = new StringBuilder();
1781 GrowlHelper.NotifyType nt;
1782 if (SettingDialog.DispUsername)
1784 title.Append(tw.Username);
1785 title.Append(" - ");
1793 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1794 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1795 title.Append(Application.ProductName);
1796 title.Append(" [DM] ");
1797 title.Append(Properties.Resources.RefreshDirectMessageText1);
1799 title.Append(addCount);
1800 title.Append(Properties.Resources.RefreshDirectMessageText2);
1801 nt = GrowlHelper.NotifyType.DirectMessage;
1805 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1806 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1807 title.Append(Application.ProductName);
1808 title.Append(" [Reply!] ");
1809 title.Append(Properties.Resources.RefreshTimelineText1);
1811 title.Append(addCount);
1812 title.Append(Properties.Resources.RefreshTimelineText2);
1813 nt = GrowlHelper.NotifyType.Reply;
1817 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1818 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1819 title.Append(Application.ProductName);
1821 title.Append(Properties.Resources.RefreshTimelineText1);
1823 title.Append(addCount);
1824 title.Append(Properties.Resources.RefreshTimelineText2);
1825 nt = GrowlHelper.NotifyType.Notify;
1827 string bText = sb.ToString();
1828 if (string.IsNullOrEmpty(bText)) return;
1830 var image = this.IconCache.TryGetFromCache(post.ImageUrl);
1831 gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image == null ? null : image.Image, post.ImageUrl);
1836 StringBuilder sb = new StringBuilder();
1839 foreach (PostClass post in notifyPosts)
1841 if (post.IsReply && !post.IsExcludeReply) reply = true;
1842 if (post.IsDm) dm = true;
1843 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1844 switch (SettingDialog.NameBalloon)
1846 case MyCommon.NameBalloonEnum.UserID:
1847 sb.Append(post.ScreenName).Append(" : ");
1849 case MyCommon.NameBalloonEnum.NickName:
1850 sb.Append(post.Nickname).Append(" : ");
1853 sb.Append(post.TextFromApi);
1856 //if (SettingDialog.DispUsername) { NotifyIcon1.BalloonTipTitle = tw.Username + " - "; } else { NotifyIcon1.BalloonTipTitle = ""; }
1857 StringBuilder title = new StringBuilder();
1859 if (SettingDialog.DispUsername)
1861 title.Append(tw.Username);
1862 title.Append(" - ");
1870 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1871 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [DM] " + Properties.Resources.RefreshDirectMessageText1 + " " + addCount.ToString() + Properties.Resources.RefreshDirectMessageText2;
1872 ntIcon = ToolTipIcon.Warning;
1873 title.Append(Application.ProductName);
1874 title.Append(" [DM] ");
1875 title.Append(Properties.Resources.RefreshDirectMessageText1);
1877 title.Append(addCount);
1878 title.Append(Properties.Resources.RefreshDirectMessageText2);
1882 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
1883 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [Reply!] " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1884 ntIcon = ToolTipIcon.Warning;
1885 title.Append(Application.ProductName);
1886 title.Append(" [Reply!] ");
1887 title.Append(Properties.Resources.RefreshTimelineText1);
1889 title.Append(addCount);
1890 title.Append(Properties.Resources.RefreshTimelineText2);
1894 //NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
1895 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " " + Properties.Resources.RefreshTimelineText1 + " " + addCount.ToString() + Properties.Resources.RefreshTimelineText2;
1896 ntIcon = ToolTipIcon.Info;
1897 title.Append(Application.ProductName);
1899 title.Append(Properties.Resources.RefreshTimelineText1);
1901 title.Append(addCount);
1902 title.Append(Properties.Resources.RefreshTimelineText2);
1904 string bText = sb.ToString();
1905 if (string.IsNullOrEmpty(bText)) return;
1906 //NotifyIcon1.BalloonTipText = sb.ToString();
1907 //NotifyIcon1.ShowBalloonTip(500);
1908 NotifyIcon1.BalloonTipTitle = title.ToString();
1909 NotifyIcon1.BalloonTipText = bText;
1910 NotifyIcon1.BalloonTipIcon = ntIcon;
1911 NotifyIcon1.ShowBalloonTip(500);
1917 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(soundFile))
1921 string dir = Application.StartupPath;
1922 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1924 dir = Path.Combine(dir, "Sounds");
1926 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, soundFile)))
1936 //mentions新着時に画面ブリンク
1937 if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1939 NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
1943 private void MyList_SelectedIndexChanged(object sender, EventArgs e)
1945 if (_curList == null || !_curList.Equals(sender) || _curList.SelectedIndices.Count != 1) return;
1947 _curItemIndex = _curList.SelectedIndices[0];
1948 if (_curItemIndex > _curList.VirtualListSize - 1) return;
1952 _curPost = GetCurTabPost(_curItemIndex);
1954 catch (ArgumentException)
1959 this.PushSelectPostChain();
1961 if (SettingDialog.UnreadManage) _statuses.SetReadAllTab(true, _curTab.Text, _curItemIndex);
1963 ChangeCacheStyleRead(true, _curItemIndex); //既読へ(フォント、文字色)
1969 private void ChangeCacheStyleRead(bool Read, int Index)
1971 var tabInfo = _statuses.Tabs[_curTab.Text];
1972 //Read:true=既読 false=未読
1973 //未読管理していなかったら既読として扱う
1974 if (!tabInfo.UnreadManage ||
1975 !SettingDialog.UnreadManage) Read = true;
1978 ListViewItem itm = null;
1979 PostClass post = null;
1981 this.TryGetListViewItemCache(Index, out itm, out post);
1983 if (itm == null || post == null)
1985 itm = ((DetailsListView)_curTab.Tag).Items[Index];
1986 post = tabInfo[Index];
1989 ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
1992 private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
1999 Item.SubItems[5].Text = "";
2004 Item.SubItems[5].Text = "★";
2010 else if (Post.RetweetedId != null)
2012 else if (Post.IsOwl && (Post.IsDm || SettingDialog.OneWayLove))
2014 else if (Read || !SettingDialog.UseUnreadStyle)
2019 if (DList == null || Item.Index == -1)
2021 Item.ForeColor = cl;
2022 if (SettingDialog.UseUnreadStyle)
2028 if (SettingDialog.UseUnreadStyle)
2029 DList.ChangeItemFontAndColor(Item.Index, cl, fnt);
2031 DList.ChangeItemForeColor(Item.Index, cl);
2032 //if (_itemCache != null) DList.RedrawItems(_itemCacheIndex, _itemCacheIndex + _itemCache.Length - 1, false);
2036 private void ColorizeList()
2038 //Index:更新対象のListviewItem.Index。Colorを返す。
2039 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2042 _post = _anchorPost;
2046 if (_post == null) return;
2048 var itemColors = new Color[] { };
2051 this.itemCacheLock.EnterReadLock();
2054 if (this._itemCache == null) return;
2057 from i in Enumerable.Range(0, this._itemCache.Length)
2058 select this.JudgeColor(_post, this._postCache[i]);
2060 itemColors = query.ToArray();
2061 itemIndex = _itemCacheIndex;
2063 finally { this.itemCacheLock.ExitReadLock(); }
2065 if (itemIndex < 0) return;
2067 foreach (var backColor in itemColors)
2069 // この処理中に MyList_CacheVirtualItems が呼ばれることがあるため、
2070 // 同一スレッド内での二重ロックを避けるためにロックの外で実行する必要がある
2071 _curList.ChangeItemBackColor(itemIndex++, backColor);
2075 private void ColorizeList(ListViewItem Item, int Index)
2077 //Index:更新対象のListviewItem.Index。Colorを返す。
2078 //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
2081 _post = _anchorPost;
2085 PostClass tPost = GetCurTabPost(Index);
2087 if (_post == null) return;
2089 if (Item.Index == -1)
2090 Item.BackColor = JudgeColor(_post, tPost);
2092 _curList.ChangeItemBackColor(Item.Index, JudgeColor(_post, tPost));
2095 private Color JudgeColor(PostClass BasePost, PostClass TargetPost)
2098 if (TargetPost.StatusId == BasePost.InReplyToStatusId)
2101 else if (TargetPost.IsMe)
2104 else if (TargetPost.IsReply)
2107 else if (BasePost.ReplyToList.Contains(TargetPost.ScreenName.ToLower()))
2109 cl = _clAtFromTarget;
2110 else if (TargetPost.ReplyToList.Contains(BasePost.ScreenName.ToLower()))
2113 else if (TargetPost.ScreenName.Equals(BasePost.ScreenName, StringComparison.OrdinalIgnoreCase))
2118 cl = _clListBackcolor;
2123 private async void PostButton_Click(object sender, EventArgs e)
2125 if (StatusText.Text.Trim().Length == 0)
2127 if (!ImageSelector.Enabled)
2134 if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", _curPost.ScreenName, _curPost.TextFromApi))
2136 DialogResult rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2138 MessageBoxButtons.YesNoCancel,
2139 MessageBoxIcon.Question);
2142 case DialogResult.Yes:
2143 doReTweetOfficial(false);
2144 StatusText.Text = "";
2146 case DialogResult.Cancel:
2151 _history[_history.Count - 1] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
2153 if (SettingDialog.Nicoms)
2155 StatusText.SelectionStart = StatusText.Text.Length;
2156 await UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2158 //if (SettingDialog.UrlConvertAuto)
2160 // StatusText.SelectionStart = StatusText.Text.Length;
2161 // UrlConvertAutoToolStripMenuItem_Click(null, null);
2163 //else if (SettingDialog.Nicoms)
2165 // StatusText.SelectionStart = StatusText.Text.Length;
2166 // UrlConvert(UrlConverter.Nicoms);
2168 StatusText.SelectionStart = StatusText.Text.Length;
2169 GetWorkerArg args = new GetWorkerArg();
2171 args.type = MyCommon.WORKERTYPE.PostMessage;
2172 CheckReplyTo(StatusText.Text);
2175 int adjustCount = 0;
2176 string tmpStatus = StatusText.Text.Trim();
2177 if (ToolStripMenuItemApiCommandEvasion.Checked)
2180 if (Regex.IsMatch(tmpStatus,
2181 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2182 RegexOptions.IgnoreCase)
2183 && tmpStatus.EndsWith(" .") == false) adjustCount += 2;
2186 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2189 adjustCount += Regex.Matches(tmpStatus, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+").Count;
2192 bool isCutOff = false;
2193 bool isRemoveFooter = MyCommon.IsKeyDown(Keys.Shift);
2194 if (StatusText.Multiline && !SettingDialog.PostCtrlEnter)
2196 //複数行でEnter投稿の場合、Ctrlも押されていたらフッタ付加しない
2197 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2199 if (SettingDialog.PostShiftEnter)
2201 isRemoveFooter = MyCommon.IsKeyDown(Keys.Control);
2203 if (!isRemoveFooter && (StatusText.Text.Contains("RT @") || StatusText.Text.Contains("QT @")))
2205 isRemoveFooter = true;
2207 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2209 if (MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
2212 //if (!SettingDialog.UrlConvertAuto) UrlConvertAutoToolStripMenuItem_Click(null, null);
2213 if (GetRestStatusCount(false, !isRemoveFooter) - adjustCount < 0)
2215 isRemoveFooter = true;
2226 if (StatusText.Text.StartsWith("D ") || StatusText.Text.StartsWith("d "))
2234 if (HashMgr.IsNotAddToAtReply)
2236 if (!string.IsNullOrEmpty(HashMgr.UseHash) && _reply_to_id == null && string.IsNullOrEmpty(_reply_to_name))
2239 header = HashMgr.UseHash + " ";
2241 footer = " " + HashMgr.UseHash;
2246 if (!string.IsNullOrEmpty(HashMgr.UseHash))
2249 header = HashMgr.UseHash + " ";
2251 footer = " " + HashMgr.UseHash;
2254 if (!isRemoveFooter)
2256 if (SettingDialog.UseRecommendStatus)
2258 footer += SettingDialog.RecommendStatusText;
2260 // テキストボックスに入力されている文字列を使用する
2261 footer += " " + SettingDialog.Status.Trim();
2264 args.status.status = header + StatusText.Text + footer;
2266 if (ToolStripMenuItemApiCommandEvasion.Checked)
2269 if (Regex.IsMatch(args.status.status,
2270 @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(get|g|fav|follow|f|on|off|stop|quit|leave|l|whois|w|nudge|n|stats|invite|track|untrack|tracks|tracking|\*)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)",
2271 RegexOptions.IgnoreCase)
2272 && args.status.status.EndsWith(" .") == false) args.status.status += " .";
2275 if (ToolStripMenuItemUrlMultibyteSplit.Checked)
2278 Match mc2 = Regex.Match(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+");
2279 if (mc2.Success) args.status.status = Regex.Replace(args.status.status, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
2282 if (IdeographicSpaceToSpaceToolStripMenuItem.Checked)
2284 // 文中の全角スペースを半角スペース1個にする
2285 args.status.status = args.status.status.Replace(" ", " ");
2288 if (isCutOff && args.status.status.Length > 140)
2290 args.status.status = args.status.status.Substring(0, 140);
2291 string AtId = @"(@|@)[a-z0-9_/]+$";
2292 string HashTag = @"(^|[^0-9A-Z&\/\?]+)(#|#)([0-9A-Z_]*[A-Z_]+)$";
2293 string Url = @"https?:\/\/[a-z0-9!\*'\(\);:&=\+\$\/%#\[\]\-_\.,~?]+$"; //簡易判定
2294 string pattern = string.Format("({0})|({1})|({2})", AtId, HashTag, Url);
2295 Match mc = Regex.Match(args.status.status, pattern, RegexOptions.IgnoreCase);
2298 //さらに@ID、ハッシュタグ、URLと推測される文字列をカットする
2299 args.status.status = args.status.status.Substring(0, 140 - mc.Value.Length);
2301 if (MessageBox.Show(args.status.status, "Post or Cancel?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) return;
2304 args.status.inReplyToId = _reply_to_id;
2305 args.status.inReplyToName = _reply_to_name;
2306 if (ImageSelector.Visible)
2309 if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
2315 _reply_to_id = null;
2316 _reply_to_name = null;
2317 StatusText.Text = "";
2318 _history.Add(new PostingStatus());
2319 _hisIdx = _history.Count - 1;
2320 if (!ToolStripFocusLockMenuItem.Checked)
2321 ((Control)ListTab.SelectedTab.Tag).Focus();
2322 urlUndoBuffer = null;
2323 UrlUndoToolStripMenuItem.Enabled = false; //Undoをできないように設定
2326 if (StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && StatusText.Text.Trim().Length > 7)
2328 string tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeUriString(StatusText.Text.Substring(7)));
2329 await this.OpenUriAsync(tmp);
2333 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2335 MyCommon._endingFlag = true;
2339 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2341 if (!SettingDialog.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon._endingFlag == false)
2343 //_endingFlag=false:フォームの×ボタン
2345 this.Visible = false;
2349 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
2350 _ignoreConfigSave = true;
2351 MyCommon._endingFlag = true;
2352 TimerTimeline.Enabled = false;
2353 TimerRefreshIcon.Enabled = false;
2357 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2359 this.Visible = true;
2360 if (this.WindowState == FormWindowState.Minimized)
2362 this.WindowState = FormWindowState.Normal;
2365 this.BringToFront();
2368 private static int errorCount = 0;
2370 private static bool CheckAccountValid()
2372 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2378 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2387 private void GetTimelineWorker_DoWork(object sender, DoWorkEventArgs e)
2389 BackgroundWorker bw = (BackgroundWorker)sender;
2390 if (bw.CancellationPending || MyCommon._endingFlag)
2396 Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;
2398 MyApplication.InitCulture();
2401 GetWorkerResult rslt = new GetWorkerResult();
2403 bool read = !SettingDialog.UnreadManage;
2404 if (_initial && SettingDialog.UnreadManage) read = this._cfgCommon.Read;
2406 GetWorkerArg args = (GetWorkerArg)e.Argument;
2408 if (!CheckAccountValid())
2410 rslt.retMsg = "Auth error. Check your account";
2411 rslt.type = MyCommon.WORKERTYPE.ErrorState; //エラー表示のみ行ない、後処理キャンセル
2412 rslt.tName = args.tName;
2417 bw.ReportProgress(0, ""); //Notifyアイコンアニメーション開始
2421 case MyCommon.WORKERTYPE.Timeline:
2422 case MyCommon.WORKERTYPE.Reply:
2423 bw.ReportProgress(50, MakeStatusMessage(args, false));
2424 ret = tw.GetTimelineApi(read, args.type, args.page == -1, _initial);
2426 if (string.IsNullOrEmpty(ret) && args.type == MyCommon.WORKERTYPE.Timeline && SettingDialog.ReadOldPosts)
2427 _statuses.SetRead();
2429 rslt.addCount = _statuses.DistributePosts();
2431 case MyCommon.WORKERTYPE.DirectMessegeRcv: //送信分もまとめて取得
2432 bw.ReportProgress(50, MakeStatusMessage(args, false));
2433 ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, args.page == -1);
2434 if (string.IsNullOrEmpty(ret)) ret = tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, args.page == -1);
2435 rslt.addCount = _statuses.DistributePosts();
2438 case MyCommon.WORKERTYPE.FavAdd:
2442 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2444 for (int i = 0; i <= args.ids.Count - 1; i++)
2446 var post = tab.Posts[args.ids[i]];
2449 bw.ReportProgress(50, MakeStatusMessage(args, false));
2452 if (post.RetweetedId == null)
2453 ret = tw.PostFavAdd(post.StatusId);
2455 ret = tw.PostFavAdd(post.RetweetedId.Value);
2457 if (ret.Length == 0)
2459 args.sIds.Add(post.StatusId);
2460 post.IsFav = true; //リスト再描画必要
2461 _favTimestamps.Add(DateTime.Now);
2462 if (string.IsNullOrEmpty(post.RelTabName))
2464 //検索,リストUserTimeline.Relatedタブからのfavは、favタブへ追加せず。それ以外は追加
2465 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(post.StatusId, post.IsRead, false);
2469 //検索,リスト,UserTimeline.Relatedタブからのfavで、TLでも取得済みならfav反映
2470 if (_statuses.ContainsKey(post.StatusId))
2472 PostClass postTl = _statuses[post.StatusId];
2473 postTl.IsFav = true;
2474 _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).Add(postTl.StatusId, postTl.IsRead, false);
2477 //検索,リスト,UserTimeline,Relatedの各タブに反映
2478 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2480 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = true;
2486 rslt.sIds = args.sIds;
2490 case MyCommon.WORKERTYPE.FavRemove:
2494 if (_statuses.Tabs.TryGetValue(args.tName, out tab))
2496 for (int i = 0; i <= args.ids.Count - 1; i++)
2498 var post = tab.Posts[args.ids[i]];
2501 bw.ReportProgress(50, MakeStatusMessage(args, false));
2504 if (post.RetweetedId == null)
2505 ret = tw.PostFavRemove(post.StatusId);
2507 ret = tw.PostFavRemove(post.RetweetedId.Value);
2509 if (ret.Length == 0)
2511 args.sIds.Add(post.StatusId);
2512 post.IsFav = false; //リスト再描画必要
2513 if (_statuses.ContainsKey(post.StatusId)) _statuses[post.StatusId].IsFav = false;
2514 //検索,リスト,UserTimeline,Relatedの各タブに反映
2515 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch | MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.UserTimeline | MyCommon.TabUsageType.Related))
2517 if (tb.Contains(post.StatusId)) tb.Posts[post.StatusId].IsFav = false;
2523 rslt.sIds = args.sIds;
2527 case MyCommon.WORKERTYPE.PostMessage:
2528 bw.ReportProgress(200);
2529 if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
2531 ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
2535 var service = ImageSelector.GetService(args.status.imageService);
2538 service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
2541 catch (AggregateException ex)
2543 ret = ex.InnerException.Message;
2546 bw.ReportProgress(300);
2547 rslt.status = args.status;
2549 case MyCommon.WORKERTYPE.Retweet:
2550 bw.ReportProgress(200);
2551 for (int i = 0; i <= args.ids.Count - 1; i++)
2553 ret = tw.PostRetweet(args.ids[i], read);
2555 bw.ReportProgress(300);
2557 case MyCommon.WORKERTYPE.Follower:
2558 bw.ReportProgress(50, Properties.Resources.UpdateFollowersMenuItem1_ClickText1);
2561 tw.RefreshFollowerIds();
2563 catch (WebApiException ex) { ret = ex.Message; }
2565 case MyCommon.WORKERTYPE.NoRetweetIds:
2568 tw.RefreshNoRetweetIds();
2570 catch (WebApiException ex) { ret = ex.Message; }
2572 case MyCommon.WORKERTYPE.Configuration:
2575 this.SettingDialog.TwitterConfiguration = tw.ConfigurationApi();
2577 catch (WebApiException ex) { ret = ex.Message; }
2579 case MyCommon.WORKERTYPE.Favorites:
2580 bw.ReportProgress(50, MakeStatusMessage(args, false));
2581 ret = tw.GetFavoritesApi(read, args.type, args.page == -1);
2582 rslt.addCount = _statuses.DistributePosts();
2584 case MyCommon.WORKERTYPE.PublicSearch:
2585 bw.ReportProgress(50, MakeStatusMessage(args, false));
2586 if (string.IsNullOrEmpty(args.tName))
2588 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
2590 //if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetPhoenixSearch(read, tb, false);
2591 if (!string.IsNullOrEmpty(tb.SearchWords)) ret = tw.GetSearch(read, tb, false);
2596 TabClass tb = _statuses.GetTabByName(args.tName);
2599 //ret = tw.GetPhoenixSearch(read, tb, false);
2600 ret = tw.GetSearch(read, tb, false);
2601 if (string.IsNullOrEmpty(ret) && args.page == -1)
2603 //ret = tw.GetPhoenixSearch(read, tb, true)
2604 ret = tw.GetSearch(read, tb, true);
2609 rslt.addCount = _statuses.DistributePosts();
2611 case MyCommon.WORKERTYPE.UserTimeline:
2612 bw.ReportProgress(50, MakeStatusMessage(args, false));
2614 if (SettingDialog.UseAdditionalCount) count = SettingDialog.UserTimelineCountApi;
2615 if (string.IsNullOrEmpty(args.tName))
2617 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
2619 if (!string.IsNullOrEmpty(tb.User)) ret = tw.GetUserTimelineApi(read, count, tb.User, tb, false);
2624 TabClass tb = _statuses.GetTabByName(args.tName);
2627 ret = tw.GetUserTimelineApi(read, count, tb.User, tb, args.page == -1);
2631 rslt.addCount = _statuses.DistributePosts();
2633 case MyCommon.WORKERTYPE.List:
2634 bw.ReportProgress(50, MakeStatusMessage(args, false));
2635 if (string.IsNullOrEmpty(args.tName))
2638 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists))
2640 if (tb.ListInfo != null && tb.ListInfo.Id != 0) ret = tw.GetListStatus(read, tb, false, _initial);
2646 TabClass tb = _statuses.GetTabByName(args.tName);
2649 ret = tw.GetListStatus(read, tb, args.page == -1, _initial);
2653 rslt.addCount = _statuses.DistributePosts();
2656 case MyCommon.WORKERTYPE.Related:
2658 bw.ReportProgress(50, MakeStatusMessage(args, false));
2659 TabClass tab = _statuses.GetTabByName(args.tName);
2660 ret = tw.GetRelatedResult(read, tab);
2661 rslt.addCount = _statuses.DistributePosts();
2665 case MyCommon.WORKERTYPE.BlockIds:
2666 bw.ReportProgress(50, Properties.Resources.UpdateBlockUserText1);
2669 tw.RefreshBlockIds();
2671 catch (WebApiException ex) { ret = ex.Message; }
2675 if (bw.CancellationPending)
2682 if (args.type == MyCommon.WORKERTYPE.FavAdd)
2684 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2685 for (int i = _favTimestamps.Count - 1; i >= 0; i--)
2687 if (_favTimestamps[i].CompareTo(oneHour) < 0)
2689 _favTimestamps.RemoveAt(i);
2693 if (args.type == MyCommon.WORKERTYPE.Timeline && !_initial)
2697 DateTime tm = DateTime.Now;
2698 if (_tlTimestamps.ContainsKey(tm))
2699 _tlTimestamps[tm] += rslt.addCount;
2701 _tlTimestamps.Add(tm, rslt.addCount);
2703 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2704 List<DateTime> keys = new List<DateTime>();
2706 foreach (DateTime key in _tlTimestamps.Keys)
2708 if (key.CompareTo(oneHour) < 0)
2714 _tlCount += _tlTimestamps[key];
2717 foreach (DateTime key in keys)
2719 _tlTimestamps.Remove(key);
2726 bw.ReportProgress(100, MakeStatusMessage(args, true)); //ステータス書き換え、Notifyアイコンアニメーション開始
2729 rslt.type = args.type;
2730 rslt.tName = args.tName;
2735 private string MakeStatusMessage(GetWorkerArg AsyncArg, bool Finish)
2741 switch (AsyncArg.type)
2743 case MyCommon.WORKERTYPE.Timeline:
2744 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2746 case MyCommon.WORKERTYPE.Reply:
2747 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2749 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2750 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8 + AsyncArg.page.ToString() + Properties.Resources.GetTimelineWorker_RunWorkerCompletedText6;
2752 case MyCommon.WORKERTYPE.FavAdd:
2753 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2754 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText16 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2756 case MyCommon.WORKERTYPE.FavRemove:
2757 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17 + AsyncArg.page.ToString() + "/" + AsyncArg.ids.Count.ToString() +
2758 Properties.Resources.GetTimelineWorker_RunWorkerCompletedText18 + (AsyncArg.page - AsyncArg.sIds.Count - 1).ToString();
2760 case MyCommon.WORKERTYPE.Favorites:
2761 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19;
2763 case MyCommon.WORKERTYPE.PublicSearch:
2764 smsg = "Search refreshing...";
2766 case MyCommon.WORKERTYPE.List:
2767 smsg = "List refreshing...";
2769 case MyCommon.WORKERTYPE.Related:
2770 smsg = "Related refreshing...";
2772 case MyCommon.WORKERTYPE.UserTimeline:
2773 smsg = "UserTimeline refreshing...";
2780 switch (AsyncArg.type)
2782 case MyCommon.WORKERTYPE.Timeline:
2783 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1;
2785 case MyCommon.WORKERTYPE.Reply:
2786 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9;
2788 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2789 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11;
2791 case MyCommon.WORKERTYPE.DirectMessegeSnt:
2792 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText13;
2794 case MyCommon.WORKERTYPE.FavAdd:
2797 case MyCommon.WORKERTYPE.FavRemove:
2800 case MyCommon.WORKERTYPE.Favorites:
2801 smsg = Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20;
2803 case MyCommon.WORKERTYPE.Follower:
2804 smsg = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2806 case MyCommon.WORKERTYPE.NoRetweetIds:
2807 smsg = "NoRetweetIds refreshed";
2809 case MyCommon.WORKERTYPE.Configuration:
2812 case MyCommon.WORKERTYPE.PublicSearch:
2813 smsg = "Search refreshed";
2815 case MyCommon.WORKERTYPE.List:
2816 smsg = "List refreshed";
2818 case MyCommon.WORKERTYPE.Related:
2819 smsg = "Related refreshed";
2821 case MyCommon.WORKERTYPE.UserTimeline:
2822 smsg = "UserTimeline refreshed";
2824 case MyCommon.WORKERTYPE.BlockIds:
2825 smsg = Properties.Resources.UpdateBlockUserText3;
2832 private void GetTimelineWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
2834 if (MyCommon._endingFlag) return;
2835 if (e.ProgressPercentage > 100)
2838 if (e.ProgressPercentage == 200) //開始
2839 StatusLabel.Text = "Posting...";
2840 if (e.ProgressPercentage == 300) //終了
2841 StatusLabel.Text = Properties.Resources.PostWorker_RunWorkerCompletedText4;
2845 string smsg = (string)e.UserState;
2846 if (smsg.Length > 0) StatusLabel.Text = smsg;
2850 private void GetTimelineWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
2852 if (MyCommon._endingFlag || e.Cancelled) return; //キャンセル
2854 if (e.Error != null)
2856 _myStatusError = true;
2857 _waitTimeline = false;
2861 _waitPubSearch = false;
2862 _waitUserTimeline = false;
2864 throw new Exception("BackgroundWorker Exception", e.Error);
2867 GetWorkerResult rslt = (GetWorkerResult)e.Result;
2870 if (rslt.retMsg.Length > 0)
2872 _myStatusError = true;
2873 StatusLabel.Text = rslt.retMsg;
2876 if (rslt.type == MyCommon.WORKERTYPE.ErrorState) return;
2878 if (rslt.type == MyCommon.WORKERTYPE.FavRemove)
2880 this.RemovePostFromFavTab(rslt.sIds.ToArray());
2884 //bool busy = false;
2885 //foreach (BackgroundWorker bw in _bw)
2887 // if (bw != null && bw.IsBusy)
2893 //if (!busy) RefreshTimeline(); //background処理なければ、リスト反映
2894 if (rslt.type == MyCommon.WORKERTYPE.Timeline ||
2895 rslt.type == MyCommon.WORKERTYPE.Reply ||
2896 rslt.type == MyCommon.WORKERTYPE.List ||
2897 rslt.type == MyCommon.WORKERTYPE.PublicSearch ||
2898 rslt.type == MyCommon.WORKERTYPE.DirectMessegeRcv ||
2899 rslt.type == MyCommon.WORKERTYPE.DirectMessegeSnt ||
2900 rslt.type == MyCommon.WORKERTYPE.Favorites ||
2901 rslt.type == MyCommon.WORKERTYPE.Follower ||
2902 rslt.type == MyCommon.WORKERTYPE.NoRetweetIds ||
2903 rslt.type == MyCommon.WORKERTYPE.FavAdd ||
2904 rslt.type == MyCommon.WORKERTYPE.FavRemove ||
2905 rslt.type == MyCommon.WORKERTYPE.Related ||
2906 rslt.type == MyCommon.WORKERTYPE.UserTimeline ||
2907 rslt.type == MyCommon.WORKERTYPE.BlockIds ||
2908 rslt.type == MyCommon.WORKERTYPE.Configuration)
2910 RefreshTimeline(false); //リスト反映
2915 case MyCommon.WORKERTYPE.Timeline:
2916 _waitTimeline = false;
2919 // //API使用時の取得調整は別途考える(カウント調整?)
2922 case MyCommon.WORKERTYPE.Reply:
2924 if (rslt.newDM && !_initial)
2926 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
2929 case MyCommon.WORKERTYPE.Favorites:
2932 case MyCommon.WORKERTYPE.DirectMessegeRcv:
2935 case MyCommon.WORKERTYPE.FavAdd:
2936 case MyCommon.WORKERTYPE.FavRemove:
2937 if (_curList != null && _curTab != null)
2939 using (ControlTransaction.Update(this._curList))
2941 if (rslt.type == MyCommon.WORKERTYPE.FavRemove && _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.Favorites)
2947 for (int i = 0; i <= rslt.sIds.Count - 1; i++)
2949 if (_curTab.Text.Equals(rslt.tName))
2951 int idx = _statuses.Tabs[rslt.tName].IndexOf(rslt.sIds[i]);
2954 PostClass post = null;
2955 TabClass tb = _statuses.Tabs[rslt.tName];
2958 if (tb.TabType == MyCommon.TabUsageType.Lists || tb.TabType == MyCommon.TabUsageType.PublicSearch)
2960 post = tb.Posts[rslt.sIds[i]];
2964 post = _statuses[rslt.sIds[i]];
2966 ChangeCacheStyleRead(post.IsRead, idx);
2968 if (idx == _curItemIndex) DispSelectedPost(true); //選択アイテム再表示
2976 case MyCommon.WORKERTYPE.PostMessage:
2977 if (string.IsNullOrEmpty(rslt.retMsg) ||
2978 rslt.retMsg.StartsWith("OK:") ||
2979 rslt.retMsg == "Warn:Status is a duplicate.")
2981 _postTimestamps.Add(DateTime.Now);
2982 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
2983 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
2985 if (_postTimestamps[i].CompareTo(oneHour) < 0)
2987 _postTimestamps.RemoveAt(i);
2991 if (!HashMgr.IsPermanent && !string.IsNullOrEmpty(HashMgr.UseHash))
2993 HashMgr.ClearHashtag();
2994 this.HashStripSplitButton.Text = "#[-]";
2995 this.HashToggleMenuItem.Checked = false;
2996 this.HashToggleToolStripMenuItem.Checked = false;
2998 SetMainWindowTitle();
3006 retry = MessageBox.Show(string.Format("{0} ---> [ " + rslt.retMsg + " ]" + Environment.NewLine + "\"" + rslt.status.status + "\"" + Environment.NewLine + "{1}",
3007 Properties.Resources.StatusUpdateFailed1,
3008 Properties.Resources.StatusUpdateFailed2),
3009 "Failed to update status",
3010 MessageBoxButtons.RetryCancel,
3011 MessageBoxIcon.Question);
3015 retry = DialogResult.Abort;
3017 if (retry == DialogResult.Retry)
3019 GetWorkerArg args = new GetWorkerArg();
3021 args.type = MyCommon.WORKERTYPE.PostMessage;
3022 args.status = rslt.status;
3027 if (ToolStripFocusLockMenuItem.Checked)
3029 //連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
3030 StatusText_Enter(StatusText, new EventArgs());
3034 if (rslt.retMsg.Length == 0 && this._cfgCommon.PostAndGet)
3036 if (_isActiveUserstream)
3038 RefreshTimeline(true);
3042 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3046 case MyCommon.WORKERTYPE.Retweet:
3047 if (rslt.retMsg.Length == 0)
3049 _postTimestamps.Add(DateTime.Now);
3050 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
3051 for (int i = _postTimestamps.Count - 1; i >= 0; i--)
3053 if (_postTimestamps[i].CompareTo(oneHour) < 0)
3055 _postTimestamps.RemoveAt(i);
3058 if (!_isActiveUserstream && this._cfgCommon.PostAndGet) GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3061 case MyCommon.WORKERTYPE.Follower:
3062 //_waitFollower = false;
3063 this.PurgeListViewItemCache();
3064 if (_curList != null) _curList.Refresh();
3066 case MyCommon.WORKERTYPE.NoRetweetIds:
3068 case MyCommon.WORKERTYPE.Configuration:
3069 //_waitFollower = false
3070 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
3072 foreach (var service in this.ImageSelector.GetServices())
3074 service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
3077 this.PurgeListViewItemCache();
3078 if (_curList != null) _curList.Refresh();
3080 case MyCommon.WORKERTYPE.PublicSearch:
3081 _waitPubSearch = false;
3083 case MyCommon.WORKERTYPE.UserTimeline:
3084 _waitUserTimeline = false;
3086 case MyCommon.WORKERTYPE.List:
3089 case MyCommon.WORKERTYPE.Related:
3090 TabClass tab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
3091 if (tab != null && tab.RelationTargetPost != null && tab.Contains(tab.RelationTargetPost.StatusId))
3093 foreach (TabPage tp in ListTab.TabPages)
3095 if (tp.Text == tab.TabName)
3097 ((DetailsListView)tp.Tag).SelectedIndices.Add(tab.IndexOf(tab.RelationTargetPost.StatusId));
3098 ((DetailsListView)tp.Tag).Items[tab.IndexOf(tab.RelationTargetPost.StatusId)].Focused = true;
3107 private async Task RefreshMuteUserIdsAsync()
3109 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
3113 await tw.RefreshMuteUserIdsAsync();
3115 catch (WebApiException ex)
3117 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
3121 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
3124 private void RemovePostFromFavTab(Int64[] ids)
3126 string favTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Favorites).TabName;
3128 if (_curTab.Text.Equals(favTabName))
3130 if (_curList.FocusedItem != null)
3131 fidx = _curList.FocusedItem.Index;
3132 else if (_curList.TopItem != null)
3133 fidx = _curList.TopItem.Index;
3138 foreach (long i in ids)
3142 _statuses.RemoveFavPost(i);
3149 if (_curTab != null && _curTab.Text.Equals(favTabName))
3151 this.PurgeListViewItemCache();
3153 //_curItemIndex = -1;
3155 foreach (TabPage tp in ListTab.TabPages)
3157 if (tp.Text == favTabName)
3159 ((DetailsListView)tp.Tag).VirtualListSize = _statuses.Tabs[favTabName].AllCount;
3163 if (_curTab.Text.Equals(favTabName))
3167 _curList.SelectedIndices.Clear();
3169 while (_curList.SelectedIndices.Count > 0);
3171 if (_statuses.Tabs[favTabName].AllCount > 0)
3173 if (_statuses.Tabs[favTabName].AllCount - 1 > fidx && fidx > -1)
3175 _curList.SelectedIndices.Add(fidx);
3179 _curList.SelectedIndices.Add(_statuses.Tabs[favTabName].AllCount - 1);
3181 if (_curList.SelectedIndices.Count > 0)
3183 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3184 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3190 private static Dictionary<MyCommon.WORKERTYPE, DateTime> lastTime = new Dictionary<MyCommon.WORKERTYPE, DateTime>();
3192 private void GetTimeline(MyCommon.WORKERTYPE WkType, int fromPage, string tabName)
3194 if (!this.IsNetworkAvailable()) return;
3197 GetWorkerArg args = new GetWorkerArg();
3198 args.page = fromPage;
3200 args.tName = tabName;
3202 if (!lastTime.ContainsKey(WkType)) lastTime.Add(WkType, new DateTime());
3203 double period = DateTime.Now.Subtract(lastTime[WkType]).TotalSeconds;
3204 if (period > 1 || period < -1)
3206 lastTime[WkType] = DateTime.Now;
3210 //Timeline取得モードの場合はReplyも同時に取得
3211 //if (!SettingDialog.UseAPI &&
3213 // WkType == MyCommon.WORKERTYPE.Timeline &&
3214 // SettingDialog.CheckReply)
3216 // //TimerReply.Enabled = false;
3217 // _mentionCounter = SettingDialog.ReplyPeriodInt;
3218 // GetWorkerArg _args = new GetWorkerArg();
3219 // _args.page = fromPage;
3220 // _args.endPage = toPage;
3221 // _args.type = MyCommon.WORKERTYPE.Reply;
3226 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
3228 if (e.Button == MouseButtons.Left)
3230 this.Visible = true;
3231 if (this.WindowState == FormWindowState.Minimized)
3233 this.WindowState = _formWindowState;
3236 this.BringToFront();
3240 private void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
3242 switch (SettingDialog.ListDoubleClickAction)
3245 MakeReplyOrDirectStatus();
3248 FavoriteChange(true);
3251 if (_curPost != null)
3252 ShowUserStatus(_curPost.ScreenName, false);
3258 ShowRelatedStatusesMenuItem_Click(null, null);
3261 MoveToHomeToolStripMenuItem_Click(null, null);
3264 StatusOpenMenuItem_Click(null, null);
3272 private void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
3274 FavoriteChange(true);
3277 private void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
3279 FavoriteChange(false);
3283 private void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
3285 FavoritesRetweetOriginal();
3288 private void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
3290 FavoritesRetweetUnofficial();
3293 private void FavoriteChange(bool FavAdd , bool multiFavoriteChangeDialogEnable = true)
3295 //trueでFavAdd,falseでFavRemove
3296 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || _curList.SelectedIndices.Count == 0
3297 || !this.ExistCurrentPost) return;
3300 if (_curList.SelectedIndices.Count > 250 && FavAdd)
3302 MessageBox.Show(Properties.Resources.FavoriteLimitCountText);
3303 _DoFavRetweetFlags = false;
3306 else if (multiFavoriteChangeDialogEnable && _curList.SelectedIndices.Count > 1)
3310 string QuestionText = Properties.Resources.FavAddToolStripMenuItem_ClickText1;
3311 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText3;
3312 if (MessageBox.Show(QuestionText, Properties.Resources.FavAddToolStripMenuItem_ClickText2,
3313 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3315 _DoFavRetweetFlags = false;
3321 if (MessageBox.Show(Properties.Resources.FavRemoveToolStripMenuItem_ClickText1, Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
3322 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
3329 GetWorkerArg args = new GetWorkerArg();
3330 args.ids = new List<long>();
3331 args.sIds = new List<long>();
3332 args.tName = _curTab.Text;
3335 args.type = MyCommon.WORKERTYPE.FavAdd;
3339 args.type = MyCommon.WORKERTYPE.FavRemove;
3341 foreach (int idx in _curList.SelectedIndices)
3343 PostClass post = GetCurTabPost(idx);
3346 if (!post.IsFav) args.ids.Add(post.StatusId);
3350 if (post.IsFav) args.ids.Add(post.StatusId);
3353 if (args.ids.Count == 0)
3356 StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
3358 StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
3366 private PostClass GetCurTabPost(int Index)
3368 this.itemCacheLock.EnterReadLock();
3371 if (_postCache != null && Index >= _itemCacheIndex && Index < _itemCacheIndex + _postCache.Length)
3372 return _postCache[Index - _itemCacheIndex];
3374 finally { this.itemCacheLock.ExitReadLock(); }
3376 return _statuses[_curTab.Text, Index];
3380 private void MoveToHomeToolStripMenuItem_Click(object sender, EventArgs e)
3382 if (_curList.SelectedIndices.Count > 0)
3383 OpenUriAsync(MyCommon.TwitterUrl + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName);
3384 else if (_curList.SelectedIndices.Count == 0)
3385 OpenUriAsync(MyCommon.TwitterUrl);
3388 private void MoveToFavToolStripMenuItem_Click(object sender, EventArgs e)
3390 if (_curList.SelectedIndices.Count > 0)
3391 OpenUriAsync(MyCommon.TwitterUrl + "#!/" + GetCurTabPost(_curList.SelectedIndices[0]).ScreenName + "/favorites");
3394 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3396 if ((!_initialLayout) && this.Visible)
3398 if (this.WindowState == FormWindowState.Normal)
3400 _mySize = this.ClientSize;
3401 _mySpDis = this.SplitContainer1.SplitterDistance;
3402 _mySpDis3 = this.SplitContainer3.SplitterDistance;
3403 if (StatusText.Multiline) _mySpDis2 = this.StatusText.Height;
3404 _modifySettingLocal = true;
3409 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3411 if (SettingDialog.SortOrderLock) return;
3412 IdComparerClass.ComparerMode mode = IdComparerClass.ComparerMode.Id;
3415 mode = IdComparerClass.ComparerMode.Id;
3423 case 6: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
3427 mode = IdComparerClass.ComparerMode.Nickname;
3430 mode = IdComparerClass.ComparerMode.Data;
3433 mode = IdComparerClass.ComparerMode.Id;
3436 mode = IdComparerClass.ComparerMode.Name;
3439 mode = IdComparerClass.ComparerMode.Source;
3443 _statuses.ToggleSortOrder(mode);
3446 DetailsListView list = (DetailsListView)sender;
3449 list.Columns[0].Text = ColumnOrgText[0];
3450 list.Columns[1].Text = ColumnText[2];
3454 for (int i = 0; i <= 7; i++)
3456 list.Columns[i].Text = ColumnOrgText[i];
3458 list.Columns[e.Column].Text = ColumnText[e.Column];
3461 this.PurgeListViewItemCache();
3463 if (_statuses.Tabs[_curTab.Text].AllCount > 0 && _curPost != null)
3465 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_curPost.StatusId);
3468 SelectListItem(_curList, idx);
3469 _curList.EnsureVisible(idx);
3473 _modifySettingCommon = true;
3476 private void TweenMain_LocationChanged(object sender, EventArgs e)
3478 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
3480 _myLoc = this.DesktopLocation;
3481 _modifySettingLocal = true;
3485 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3487 if (ListTab.SelectedTab == null) return;
3488 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
3489 if (!this.ExistCurrentPost)
3491 ReplyStripMenuItem.Enabled = false;
3492 ReplyAllStripMenuItem.Enabled = false;
3493 DMStripMenuItem.Enabled = false;
3494 ShowProfileMenuItem.Enabled = false;
3495 ShowUserTimelineContextMenuItem.Enabled = false;
3496 ListManageUserContextToolStripMenuItem2.Enabled = false;
3497 MoveToFavToolStripMenuItem.Enabled = false;
3498 TabMenuItem.Enabled = false;
3499 IDRuleMenuItem.Enabled = false;
3500 ReadedStripMenuItem.Enabled = false;
3501 UnreadStripMenuItem.Enabled = false;
3505 ShowProfileMenuItem.Enabled = true;
3506 ListManageUserContextToolStripMenuItem2.Enabled = true;
3507 ReplyStripMenuItem.Enabled = true;
3508 ReplyAllStripMenuItem.Enabled = true;
3509 DMStripMenuItem.Enabled = true;
3510 ShowUserTimelineContextMenuItem.Enabled = true;
3511 MoveToFavToolStripMenuItem.Enabled = true;
3512 TabMenuItem.Enabled = true;
3513 IDRuleMenuItem.Enabled = true;
3514 ReadedStripMenuItem.Enabled = true;
3515 UnreadStripMenuItem.Enabled = true;
3517 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3518 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
3520 FavAddToolStripMenuItem.Enabled = false;
3521 FavRemoveToolStripMenuItem.Enabled = false;
3522 StatusOpenMenuItem.Enabled = false;
3523 FavorareMenuItem.Enabled = false;
3524 ShowRelatedStatusesMenuItem.Enabled = false;
3526 ReTweetStripMenuItem.Enabled = false;
3527 ReTweetOriginalStripMenuItem.Enabled = false;
3528 QuoteStripMenuItem.Enabled = false;
3529 FavoriteRetweetContextMenu.Enabled = false;
3530 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3531 if (this.ExistCurrentPost && _curPost.IsDm)
3532 DeleteStripMenuItem.Enabled = true;
3534 DeleteStripMenuItem.Enabled = false;
3538 FavAddToolStripMenuItem.Enabled = true;
3539 FavRemoveToolStripMenuItem.Enabled = true;
3540 StatusOpenMenuItem.Enabled = true;
3541 FavorareMenuItem.Enabled = true;
3542 ShowRelatedStatusesMenuItem.Enabled = true; //PublicSearchの時問題出るかも
3546 ReTweetOriginalStripMenuItem.Enabled = false;
3547 FavoriteRetweetContextMenu.Enabled = false;
3548 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3550 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3554 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3556 DeleteStripMenuItem.Enabled = true;
3560 if (string.IsNullOrEmpty(_curPost.RetweetedBy))
3562 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3566 DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3568 DeleteStripMenuItem.Enabled = false;
3569 if (_curPost.IsProtect)
3571 ReTweetOriginalStripMenuItem.Enabled = false;
3572 ReTweetStripMenuItem.Enabled = false;
3573 QuoteStripMenuItem.Enabled = false;
3574 FavoriteRetweetContextMenu.Enabled = false;
3575 FavoriteRetweetUnofficialContextMenu.Enabled = false;
3579 ReTweetOriginalStripMenuItem.Enabled = true;
3580 ReTweetStripMenuItem.Enabled = true;
3581 QuoteStripMenuItem.Enabled = true;
3582 FavoriteRetweetContextMenu.Enabled = true;
3583 FavoriteRetweetUnofficialContextMenu.Enabled = true;
3587 //if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
3589 // RefreshMoreStripMenuItem.Enabled = true;
3593 // RefreshMoreStripMenuItem.Enabled = false;
3595 if (!this.ExistCurrentPost
3596 || _curPost.InReplyToStatusId == null)
3598 RepliedStatusOpenMenuItem.Enabled = false;
3602 RepliedStatusOpenMenuItem.Enabled = true;
3604 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
3606 MoveToRTHomeMenuItem.Enabled = false;
3610 MoveToRTHomeMenuItem.Enabled = true;
3614 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3616 MakeReplyOrDirectStatus(false, true);
3619 private void DMStripMenuItem_Click(object sender, EventArgs e)
3621 MakeReplyOrDirectStatus(false, false);
3624 private void doStatusDelete()
3626 if (_curTab == null || _curList == null) return;
3627 if (_statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
3629 bool myPost = false;
3630 foreach (int idx in _curList.SelectedIndices)
3632 if (GetCurTabPost(idx).IsMe ||
3633 GetCurTabPost(idx).RetweetedBy.ToLower() == tw.Username.ToLower())
3639 if (!myPost) return;
3643 if (_curList.SelectedIndices.Count == 0)
3647 string tmp = string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine);
3649 if (MessageBox.Show(tmp, Properties.Resources.DeleteStripMenuItem_ClickText2,
3650 MessageBoxButtons.OKCancel,
3651 MessageBoxIcon.Question) == DialogResult.Cancel) return;
3654 if (_curList.FocusedItem != null)
3655 fidx = _curList.FocusedItem.Index;
3656 else if (_curList.TopItem != null)
3657 fidx = _curList.TopItem.Index;
3663 this.Cursor = Cursors.WaitCursor;
3666 foreach (long Id in _statuses.GetId(_curTab.Text, _curList.SelectedIndices))
3669 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
3671 rtn = tw.RemoveDirectMessage(Id, _statuses[Id]);
3675 if (_statuses[Id].IsMe || _statuses[Id].RetweetedBy.ToLower() == tw.Username.ToLower())
3676 rtn = tw.RemoveStatus(Id);
3687 _statuses.RemovePost(Id);
3692 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; //失敗
3694 StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; //成功
3696 this.PurgeListViewItemCache();
3699 foreach (TabPage tb in ListTab.TabPages)
3701 ((DetailsListView)tb.Tag).VirtualListSize = _statuses.Tabs[tb.Text].AllCount;
3702 if (_curTab.Equals(tb))
3706 _curList.SelectedIndices.Clear();
3708 while (_curList.SelectedIndices.Count > 0);
3710 if (_statuses.Tabs[tb.Text].AllCount > 0)
3712 if (_statuses.Tabs[tb.Text].AllCount - 1 > fidx && fidx > -1)
3713 _curList.SelectedIndices.Add(fidx);
3715 _curList.SelectedIndices.Add(_statuses.Tabs[tb.Text].AllCount - 1);
3717 if (_curList.SelectedIndices.Count > 0)
3719 _curList.EnsureVisible(_curList.SelectedIndices[0]);
3720 _curList.FocusedItem = _curList.Items[_curList.SelectedIndices[0]];
3724 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3726 if (SettingDialog.TabIconDisp)
3728 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3732 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3736 this.Cursor = Cursors.Default;
3740 private void DeleteStripMenuItem_Click(object sender, EventArgs e)
3745 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3747 using (ControlTransaction.Update(this._curList))
3749 if (SettingDialog.UnreadManage)
3751 foreach (int idx in _curList.SelectedIndices)
3753 _statuses.SetReadAllTab(true, _curTab.Text, idx);
3756 foreach (int idx in _curList.SelectedIndices)
3758 ChangeCacheStyleRead(true, idx);
3762 foreach (TabPage tb in ListTab.TabPages)
3764 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
3766 if (SettingDialog.TabIconDisp)
3768 if (tb.ImageIndex == 0) tb.ImageIndex = -1; //タブアイコン
3772 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3775 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3777 using (ControlTransaction.Update(this._curList))
3779 if (SettingDialog.UnreadManage)
3781 foreach (int idx in _curList.SelectedIndices)
3783 _statuses.SetReadAllTab(false, _curTab.Text, idx);
3786 foreach (int idx in _curList.SelectedIndices)
3788 ChangeCacheStyleRead(false, idx);
3792 foreach (TabPage tb in ListTab.TabPages)
3794 if (_statuses.Tabs[tb.Text].UnreadCount > 0)
3796 if (SettingDialog.TabIconDisp)
3798 if (tb.ImageIndex == -1) tb.ImageIndex = 0; //タブアイコン
3802 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
3805 private void RefreshStripMenuItem_Click(object sender, EventArgs e)
3810 private void DoRefresh()
3812 if (_curTab != null)
3814 switch (_statuses.Tabs[_curTab.Text].TabType)
3816 case MyCommon.TabUsageType.Mentions:
3817 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
3819 case MyCommon.TabUsageType.DirectMessage:
3820 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
3822 case MyCommon.TabUsageType.Favorites:
3823 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
3825 //case MyCommon.TabUsageType.Profile:
3827 case MyCommon.TabUsageType.PublicSearch:
3829 TabClass tb = _statuses.Tabs[_curTab.Text];
3830 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3831 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, _curTab.Text);
3833 case MyCommon.TabUsageType.UserTimeline:
3834 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, _curTab.Text);
3836 case MyCommon.TabUsageType.Lists:
3838 TabClass tab = _statuses.Tabs[_curTab.Text];
3839 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3840 GetTimeline(MyCommon.WORKERTYPE.List, 1, _curTab.Text);
3843 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3849 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
3853 private void DoRefreshMore()
3856 if (_curTab != null)
3858 switch (_statuses.Tabs[_curTab.Text].TabType)
3860 case MyCommon.TabUsageType.Mentions:
3861 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
3863 case MyCommon.TabUsageType.DirectMessage:
3864 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
3866 case MyCommon.TabUsageType.Favorites:
3867 GetTimeline(MyCommon.WORKERTYPE.Favorites, -1, "");
3869 case MyCommon.TabUsageType.Profile:
3872 case MyCommon.TabUsageType.PublicSearch:
3874 TabClass tb = _statuses.Tabs[_curTab.Text];
3875 if (string.IsNullOrEmpty(tb.SearchWords)) return;
3876 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, -1, _curTab.Text);
3878 case MyCommon.TabUsageType.UserTimeline:
3879 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, -1, _curTab.Text);
3881 case MyCommon.TabUsageType.Lists:
3883 TabClass tab = _statuses.Tabs[_curTab.Text];
3884 if (tab.ListInfo == null || tab.ListInfo.Id == 0) return;
3885 GetTimeline(MyCommon.WORKERTYPE.List, -1, _curTab.Text);
3888 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3894 GetTimeline(MyCommon.WORKERTYPE.Timeline, -1, "");
3898 private void SettingStripMenuItem_Click(object sender, EventArgs e)
3900 DialogResult result;
3901 string uid = tw.Username.ToLower();
3902 var oldIconSz = SettingDialog.IconSz;
3906 result = SettingDialog.ShowDialog(this);
3913 if (result == DialogResult.OK)
3917 this.SettingDialog.SaveConfig(this._cfgCommon, this._cfgLocal);
3919 tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
3920 tw.ReadOwnPost = SettingDialog.ReadOwnPost;
3921 ShortUrl.Instance.DisableExpanding = !SettingDialog.TinyUrlResolve;
3922 ShortUrl.Instance.BitlyId = SettingDialog.BitlyUser;
3923 ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
3924 HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
3926 Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
3927 Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
3928 this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
3929 this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
3931 ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
3935 if (SettingDialog.TabIconDisp)
3937 ListTab.DrawItem -= ListTab_DrawItem;
3938 ListTab.DrawMode = TabDrawMode.Normal;
3939 ListTab.ImageList = this.TabImage;
3943 ListTab.DrawItem -= ListTab_DrawItem;
3944 ListTab.DrawItem += ListTab_DrawItem;
3945 ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3946 ListTab.ImageList = null;
3949 catch (Exception ex)
3951 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3952 ex.Data["IsTerminatePermission"] = false;
3958 if (!SettingDialog.UnreadManage)
3960 ReadedStripMenuItem.Enabled = false;
3961 UnreadStripMenuItem.Enabled = false;
3962 if (SettingDialog.TabIconDisp)
3964 foreach (TabPage myTab in ListTab.TabPages)
3966 myTab.ImageIndex = -1;
3972 ReadedStripMenuItem.Enabled = true;
3973 UnreadStripMenuItem.Enabled = true;
3976 catch (Exception ex)
3978 ex.Data["Instance"] = "ListTab(UnreadManage)";
3979 ex.Data["IsTerminatePermission"] = false;
3986 SplitContainer1.IsPanelInverted = !SettingDialog.StatusAreaAtBottom;
3988 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3989 imgazyobizinet.Enabled = this.SettingDialog.EnableImgAzyobuziNet;
3990 imgazyobizinet.DisabledInDM = this.SettingDialog.ImgAzyobuziNetDisabledInDM;
3992 PlaySoundMenuItem.Checked = SettingDialog.PlaySound;
3993 this.PlaySoundFileMenuItem.Checked = SettingDialog.PlaySound;
3994 _fntUnread = SettingDialog.FontUnread;
3995 _clUnread = SettingDialog.ColorUnread;
3996 _fntReaded = SettingDialog.FontReaded;
3997 _clReaded = SettingDialog.ColorReaded;
3998 _clFav = SettingDialog.ColorFav;
3999 _clOWL = SettingDialog.ColorOWL;
4000 _clRetweet = SettingDialog.ColorRetweet;
4001 _fntDetail = SettingDialog.FontDetail;
4002 _clDetail = SettingDialog.ColorDetail;
4003 _clDetailLink = SettingDialog.ColorDetailLink;
4004 _clDetailBackcolor = SettingDialog.ColorDetailBackcolor;
4005 _clSelf = SettingDialog.ColorSelf;
4006 _clAtSelf = SettingDialog.ColorAtSelf;
4007 _clTarget = SettingDialog.ColorTarget;
4008 _clAtTarget = SettingDialog.ColorAtTarget;
4009 _clAtFromTarget = SettingDialog.ColorAtFromTarget;
4010 _clAtTo = SettingDialog.ColorAtTo;
4011 _clListBackcolor = SettingDialog.ColorListBackcolor;
4012 _clInputBackcolor = SettingDialog.ColorInputBackcolor;
4013 _clInputFont = SettingDialog.ColorInputFont;
4014 _fntInputFont = SettingDialog.FontInputFont;
4015 _brsBackColorMine.Dispose();
4016 _brsBackColorAt.Dispose();
4017 _brsBackColorYou.Dispose();
4018 _brsBackColorAtYou.Dispose();
4019 _brsBackColorAtFromTarget.Dispose();
4020 _brsBackColorAtTo.Dispose();
4021 _brsBackColorNone.Dispose();
4022 _brsBackColorMine = new SolidBrush(_clSelf);
4023 _brsBackColorAt = new SolidBrush(_clAtSelf);
4024 _brsBackColorYou = new SolidBrush(_clTarget);
4025 _brsBackColorAtYou = new SolidBrush(_clAtTarget);
4026 _brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
4027 _brsBackColorAtTo = new SolidBrush(_clAtTo);
4028 _brsBackColorNone = new SolidBrush(_clListBackcolor);
4032 if (StatusText.Focused) StatusText.BackColor = _clInputBackcolor;
4033 StatusText.Font = _fntInputFont;
4034 StatusText.ForeColor = _clInputFont;
4036 catch (Exception ex)
4038 MessageBox.Show(ex.Message);
4043 InitDetailHtmlFormat();
4045 catch (Exception ex)
4047 ex.Data["Instance"] = "Font";
4048 ex.Data["IsTerminatePermission"] = false;
4054 _statuses.SetUnreadManage(SettingDialog.UnreadManage);
4056 catch (Exception ex)
4058 ex.Data["Instance"] = "_statuses";
4059 ex.Data["IsTerminatePermission"] = false;
4065 foreach (TabPage tb in ListTab.TabPages)
4067 if (SettingDialog.TabIconDisp)
4069 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
4076 catch (Exception ex)
4078 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
4079 ex.Data["IsTerminatePermission"] = false;
4085 var oldIconCol = _iconCol;
4087 if (SettingDialog.IconSz != oldIconSz)
4088 ApplyListViewIconSize(SettingDialog.IconSz);
4090 foreach (TabPage tp in ListTab.TabPages)
4092 DetailsListView lst = (DetailsListView)tp.Tag;
4094 using (ControlTransaction.Update(lst))
4096 lst.GridLines = SettingDialog.ShowGrid;
4097 lst.Font = _fntReaded;
4098 lst.BackColor = _clListBackcolor;
4100 if (_iconCol != oldIconCol)
4105 catch (Exception ex)
4107 ex.Data["Instance"] = "ListView(IconSize)";
4108 ex.Data["IsTerminatePermission"] = false;
4112 SetMainWindowTitle();
4113 SetNotifyIconText();
4115 this.PurgeListViewItemCache();
4116 if (_curList != null) _curList.Refresh();
4119 _hookGlobalHotkey.UnregisterAllOriginalHotkey();
4120 if (SettingDialog.HotkeyEnabled)
4122 ///グローバルホットキーの登録。設定で変更可能にするかも
4123 HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
4124 if ((SettingDialog.HotkeyMod & Keys.Alt) == Keys.Alt) modKey = modKey | HookGlobalHotkey.ModKeys.Alt;
4125 if ((SettingDialog.HotkeyMod & Keys.Control) == Keys.Control) modKey = modKey | HookGlobalHotkey.ModKeys.Ctrl;
4126 if ((SettingDialog.HotkeyMod & Keys.Shift) == Keys.Shift) modKey = modKey | HookGlobalHotkey.ModKeys.Shift;
4127 if ((SettingDialog.HotkeyMod & Keys.LWin) == Keys.LWin) modKey = modKey | HookGlobalHotkey.ModKeys.Win;
4129 _hookGlobalHotkey.RegisterOriginalHotkey(SettingDialog.HotkeyKey, SettingDialog.HotkeyValue, modKey);
4132 if (uid != tw.Username) this.doGetFollowersMenu();
4134 if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
4137 StatusText_TextChanged(null, null);
4145 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
4147 this.TopMost = SettingDialog.AlwaysTop;
4148 SaveConfigsAll(false);
4154 private void SetTabAlignment()
4156 var newAlignment = SettingDialog.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
4157 if (ListTab.Alignment == newAlignment) return;
4160 Dictionary<string, long[]> selId = new Dictionary<string, long[]>();
4161 Dictionary<string, long[]> focusedId = new Dictionary<string, long[]>();
4162 SaveSelectedStatus(selId, focusedId);
4164 ListTab.Alignment = newAlignment;
4167 foreach (TabPage tab in ListTab.TabPages)
4169 DetailsListView lst = (DetailsListView)tab.Tag;
4170 TabClass tabInfo = _statuses.Tabs[tab.Text];
4171 using (ControlTransaction.Update(lst))
4173 this.SelectListItem(lst,
4174 tabInfo.IndexOf(selId[tab.Text]),
4175 tabInfo.IndexOf(focusedId[tab.Text]));
4180 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
4186 case MyCommon.IconSizes.IconNone:
4189 case MyCommon.IconSizes.Icon16:
4192 case MyCommon.IconSizes.Icon24:
4195 case MyCommon.IconSizes.Icon48:
4198 case MyCommon.IconSizes.Icon48_2:
4206 // ディスプレイの DPI 設定を考慮したサイズを設定する
4207 _listViewImageList.ImageSize = new Size(
4209 (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
4213 _listViewImageList.ImageSize = new Size(1, 1);
4217 private void ResetColumns(DetailsListView list)
4219 using (ControlTransaction.Update(list))
4220 using (ControlTransaction.Layout(list, false))
4223 list.ColumnClick -= MyList_ColumnClick;
4224 list.DrawColumnHeader -= MyList_DrawColumnHeader;
4225 list.ColumnReordered -= MyList_ColumnReordered;
4226 list.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4228 var cols = list.Columns.Cast<ColumnHeader>().ToList();
4229 list.Columns.Clear();
4230 cols.ForEach(col => col.Dispose());
4233 InitColumns(list, true);
4235 list.ColumnClick += MyList_ColumnClick;
4236 list.DrawColumnHeader += MyList_DrawColumnHeader;
4237 list.ColumnReordered += MyList_ColumnReordered;
4238 list.ColumnWidthChanged += MyList_ColumnWidthChanged;
4242 private void PostBrowser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
4244 if (e.Url.AbsoluteUri != "about:blank")
4247 OpenUriAsync(e.Url.OriginalString);
4251 private void PostBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
4253 if (e.Url.Scheme == "data")
4255 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4257 else if (e.Url.AbsoluteUri != "about:blank")
4261 if (e.Url.AbsoluteUri.StartsWith("http://twitter.com/search?q=%23") ||
4262 e.Url.AbsoluteUri.StartsWith("https://twitter.com/search?q=%23"))
4265 string urlStr = Uri.UnescapeDataString(e.Url.AbsoluteUri);
4266 int i = urlStr.IndexOf('#');
4267 if (i == -1) return;
4269 string hash = urlStr.Substring(i);
4270 HashSupl.AddItem(hash);
4271 HashMgr.AddHashToHistory(hash.Trim(), false);
4272 AddNewTabForSearch(hash);
4277 Match m = Regex.Match(e.Url.AbsoluteUri, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
4278 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
4280 // Ctrlを押しながらリンクをクリックした場合は設定と逆の動作をする
4281 if (SettingDialog.OpenUserTimeline)
4283 if (MyCommon.IsKeyDown(Keys.Control))
4284 OpenUriAsync(e.Url.OriginalString);
4286 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4290 if (MyCommon.IsKeyDown(Keys.Control))
4291 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
4293 OpenUriAsync(e.Url.OriginalString);
4298 OpenUriAsync(e.Url.OriginalString);
4304 public void AddNewTabForSearch(string searchWord)
4306 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4307 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.PublicSearch))
4309 if (tb.SearchWords == searchWord && string.IsNullOrEmpty(tb.SearchLang))
4311 foreach (TabPage tp in ListTab.TabPages)
4313 if (tb.TabName == tp.Text)
4315 ListTab.SelectedTab = tp;
4322 string tabName = searchWord;
4323 for (int i = 0; i <= 100; i++)
4325 if (_statuses.ContainsTab(tabName))
4331 _statuses.AddTab(tabName, MyCommon.TabUsageType.PublicSearch, null);
4332 AddNewTab(tabName, false, MyCommon.TabUsageType.PublicSearch);
4334 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4336 ComboBox cmb = (ComboBox)ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"];
4337 cmb.Items.Add(searchWord);
4338 cmb.Text = searchWord;
4341 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
4344 private void ShowUserTimeline()
4346 if (!this.ExistCurrentPost) return;
4347 AddNewTabForUserTimeline(_curPost.ScreenName);
4350 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
4352 if (e.KeyCode == Keys.Escape)
4354 TabPage relTp = ListTab.SelectedTab;
4355 RemoveSpecifiedTab(relTp.Text, false);
4357 e.SuppressKeyPress = true;
4361 public void AddNewTabForUserTimeline(string user)
4363 //同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
4364 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.UserTimeline))
4366 if (tb.User == user)
4368 foreach (TabPage tp in ListTab.TabPages)
4370 if (tb.TabName == tp.Text)
4372 ListTab.SelectedTab = tp;
4379 string tabName = "user:" + user;
4380 while (_statuses.ContainsTab(tabName))
4385 _statuses.AddTab(tabName, MyCommon.TabUsageType.UserTimeline, null);
4386 _statuses.Tabs[tabName].User = user;
4387 AddNewTab(tabName, false, MyCommon.TabUsageType.UserTimeline);
4389 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
4393 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, tabName);
4396 public bool AddNewTab(string tabName, bool startup, MyCommon.TabUsageType tabType, ListElement listInfo = null)
4399 foreach (TabPage tb in ListTab.TabPages)
4401 if (tb.Text == tabName) return false;
4405 if (tabName == Properties.Resources.AddNewTabText1) return false;
4410 if (tabType == MyCommon.TabUsageType.DirectMessage ||
4411 tabType == MyCommon.TabUsageType.Favorites ||
4412 tabType == MyCommon.TabUsageType.Home ||
4413 tabType == MyCommon.TabUsageType.Mentions ||
4414 tabType == MyCommon.TabUsageType.Related)
4416 if (_statuses.GetTabByType(tabType) != null) return false;
4420 TabPage _tabPage = new TabPage();
4421 DetailsListView _listCustom = new DetailsListView();
4423 int cnt = ListTab.TabPages.Count;
4425 ///ToDo:Create and set controls follow tabtypes
4427 using (ControlTransaction.Update(_listCustom))
4428 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4429 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4430 using (ControlTransaction.Layout(this.SplitContainer1, false))
4431 using (ControlTransaction.Layout(this.ListTab, false))
4432 using (ControlTransaction.Layout(this))
4433 using (ControlTransaction.Layout(_tabPage, false))
4437 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4439 label = new Label();
4440 label.Dock = DockStyle.Top;
4441 label.Name = "labelUser";
4442 if (tabType == MyCommon.TabUsageType.Lists)
4444 label.Text = listInfo.ToString();
4448 label.Text = _statuses.Tabs[tabName].User + "'s Timeline";
4450 label.TextAlign = ContentAlignment.MiddleLeft;
4451 using (ComboBox tmpComboBox = new ComboBox())
4453 label.Height = tmpComboBox.Height;
4455 _tabPage.Controls.Add(label);
4460 if (tabType == MyCommon.TabUsageType.PublicSearch)
4464 Label lbl = new Label();
4465 ComboBox cmb = new ComboBox();
4466 Button btn = new Button();
4467 ComboBox cmbLang = new ComboBox();
4469 pnl.SuspendLayout();
4471 pnl.Controls.Add(cmb);
4472 pnl.Controls.Add(cmbLang);
4473 pnl.Controls.Add(btn);
4474 pnl.Controls.Add(lbl);
4475 pnl.Name = "panelSearch";
4476 pnl.Dock = DockStyle.Top;
4477 pnl.Height = cmb.Height;
4478 pnl.Enter += SearchControls_Enter;
4479 pnl.Leave += SearchControls_Leave;
4482 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4483 cmb.Dock = DockStyle.Fill;
4484 cmb.Name = "comboSearch";
4485 cmb.DropDownStyle = ComboBoxStyle.DropDown;
4486 cmb.ImeMode = ImeMode.NoControl;
4487 cmb.TabStop = false;
4488 cmb.AutoCompleteMode = AutoCompleteMode.None;
4489 cmb.KeyDown += SearchComboBox_KeyDown;
4491 if (_statuses.ContainsTab(tabName))
4493 cmb.Items.Add(_statuses.Tabs[tabName].SearchWords);
4494 cmb.Text = _statuses.Tabs[tabName].SearchWords;
4498 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
4499 cmbLang.Dock = DockStyle.Right;
4501 cmbLang.Name = "comboLang";
4502 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
4503 cmbLang.TabStop = false;
4504 cmbLang.Items.Add("");
4505 cmbLang.Items.Add("ja");
4506 cmbLang.Items.Add("en");
4507 cmbLang.Items.Add("ar");
4508 cmbLang.Items.Add("da");
4509 cmbLang.Items.Add("nl");
4510 cmbLang.Items.Add("fa");
4511 cmbLang.Items.Add("fi");
4512 cmbLang.Items.Add("fr");
4513 cmbLang.Items.Add("de");
4514 cmbLang.Items.Add("hu");
4515 cmbLang.Items.Add("is");
4516 cmbLang.Items.Add("it");
4517 cmbLang.Items.Add("no");
4518 cmbLang.Items.Add("pl");
4519 cmbLang.Items.Add("pt");
4520 cmbLang.Items.Add("ru");
4521 cmbLang.Items.Add("es");
4522 cmbLang.Items.Add("sv");
4523 cmbLang.Items.Add("th");
4524 if (_statuses.ContainsTab(tabName)) cmbLang.Text = _statuses.Tabs[tabName].SearchLang;
4526 lbl.Text = "Search(C-S-f)";
4527 lbl.Name = "label1";
4528 lbl.Dock = DockStyle.Left;
4530 lbl.Height = cmb.Height;
4531 lbl.TextAlign = ContentAlignment.MiddleLeft;
4533 btn.Text = "Search";
4534 btn.Name = "buttonSearch";
4535 btn.UseVisualStyleBackColor = true;
4536 btn.Dock = DockStyle.Right;
4537 btn.TabStop = false;
4538 btn.Click += SearchButton_Click;
4541 this.ListTab.Controls.Add(_tabPage);
4542 _tabPage.Controls.Add(_listCustom);
4544 if (tabType == MyCommon.TabUsageType.PublicSearch) _tabPage.Controls.Add(pnl);
4545 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists) _tabPage.Controls.Add(label);
4547 _tabPage.Location = new Point(4, 4);
4548 _tabPage.Name = "CTab" + cnt.ToString();
4549 _tabPage.Size = new Size(380, 260);
4550 _tabPage.TabIndex = 2 + cnt;
4551 _tabPage.Text = tabName;
4552 _tabPage.UseVisualStyleBackColor = true;
4554 _listCustom.AllowColumnReorder = true;
4555 _listCustom.ContextMenuStrip = this.ContextMenuOperate;
4556 _listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4557 _listCustom.Dock = DockStyle.Fill;
4558 _listCustom.FullRowSelect = true;
4559 _listCustom.HideSelection = false;
4560 _listCustom.Location = new Point(0, 0);
4561 _listCustom.Margin = new Padding(0);
4562 _listCustom.Name = "CList" + Environment.TickCount.ToString();
4563 _listCustom.ShowItemToolTips = true;
4564 _listCustom.Size = new Size(380, 260);
4565 _listCustom.UseCompatibleStateImageBehavior = false;
4566 _listCustom.View = View.Details;
4567 _listCustom.OwnerDraw = true;
4568 _listCustom.VirtualMode = true;
4569 _listCustom.Font = _fntReaded;
4570 _listCustom.BackColor = _clListBackcolor;
4572 _listCustom.GridLines = SettingDialog.ShowGrid;
4573 _listCustom.AllowDrop = true;
4575 _listCustom.SmallImageList = _listViewImageList;
4577 InitColumns(_listCustom, startup);
4579 _listCustom.SelectedIndexChanged += MyList_SelectedIndexChanged;
4580 _listCustom.MouseDoubleClick += MyList_MouseDoubleClick;
4581 _listCustom.ColumnClick += MyList_ColumnClick;
4582 _listCustom.DrawColumnHeader += MyList_DrawColumnHeader;
4583 _listCustom.DragDrop += TweenMain_DragDrop;
4584 _listCustom.DragEnter += TweenMain_DragEnter;
4585 _listCustom.DragOver += TweenMain_DragOver;
4586 _listCustom.DrawItem += MyList_DrawItem;
4587 _listCustom.MouseClick += MyList_MouseClick;
4588 _listCustom.ColumnReordered += MyList_ColumnReordered;
4589 _listCustom.ColumnWidthChanged += MyList_ColumnWidthChanged;
4590 _listCustom.CacheVirtualItems += MyList_CacheVirtualItems;
4591 _listCustom.RetrieveVirtualItem += MyList_RetrieveVirtualItem;
4592 _listCustom.DrawSubItem += MyList_DrawSubItem;
4593 _listCustom.HScrolled += MyList_HScrolled;
4595 if (tabType == MyCommon.TabUsageType.PublicSearch) pnl.ResumeLayout(false);
4598 _tabPage.Tag = _listCustom;
4602 public bool RemoveSpecifiedTab(string TabName, bool confirm)
4604 if (_statuses.IsDefaultTab(TabName) || _statuses.Tabs[TabName].Protected) return false;
4608 string tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4609 if (MessageBox.Show(tmp, TabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4610 MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
4616 var _tabPage = ListTab.TabPages.Cast<TabPage>().FirstOrDefault<TabPage>(tp => tp.Text == TabName);
4617 if (_tabPage == null) return false;
4619 SetListProperty(); //他のタブに列幅等を反映
4621 MyCommon.TabUsageType tabType = _statuses.Tabs[TabName].TabType;
4624 DetailsListView _listCustom = (DetailsListView)_tabPage.Tag;
4625 _tabPage.Tag = null;
4627 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4628 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4629 using (ControlTransaction.Layout(this.SplitContainer1, false))
4630 using (ControlTransaction.Layout(this.ListTab, false))
4631 using (ControlTransaction.Layout(this))
4632 using (ControlTransaction.Layout(_tabPage, false))
4634 if (this.ListTab.SelectedTab == _tabPage)
4636 this.ListTab.SelectTab((this._beforeSelectedTab != null && this.ListTab.TabPages.Contains(this._beforeSelectedTab)) ? this._beforeSelectedTab : this.ListTab.TabPages[0]);
4637 this._beforeSelectedTab = null;
4639 this.ListTab.Controls.Remove(_tabPage);
4642 if (tabType == MyCommon.TabUsageType.UserTimeline || tabType == MyCommon.TabUsageType.Lists)
4644 using (Control label = _tabPage.Controls["labelUser"])
4646 _tabPage.Controls.Remove(label);
4649 else if (tabType == MyCommon.TabUsageType.PublicSearch)
4651 using (Control pnl = _tabPage.Controls["panelSearch"])
4653 pnl.Enter -= SearchControls_Enter;
4654 pnl.Leave -= SearchControls_Leave;
4655 _tabPage.Controls.Remove(pnl);
4657 foreach (Control ctrl in pnl.Controls)
4659 if (ctrl.Name == "buttonSearch")
4661 ctrl.Click -= SearchButton_Click;
4663 else if (ctrl.Name == "comboSearch")
4665 ctrl.KeyDown -= SearchComboBox_KeyDown;
4667 pnl.Controls.Remove(ctrl);
4673 _tabPage.Controls.Remove(_listCustom);
4675 _listCustom.SelectedIndexChanged -= MyList_SelectedIndexChanged;
4676 _listCustom.MouseDoubleClick -= MyList_MouseDoubleClick;
4677 _listCustom.ColumnClick -= MyList_ColumnClick;
4678 _listCustom.DrawColumnHeader -= MyList_DrawColumnHeader;
4679 _listCustom.DragDrop -= TweenMain_DragDrop;
4680 _listCustom.DragEnter -= TweenMain_DragEnter;
4681 _listCustom.DragOver -= TweenMain_DragOver;
4682 _listCustom.DrawItem -= MyList_DrawItem;
4683 _listCustom.MouseClick -= MyList_MouseClick;
4684 _listCustom.ColumnReordered -= MyList_ColumnReordered;
4685 _listCustom.ColumnWidthChanged -= MyList_ColumnWidthChanged;
4686 _listCustom.CacheVirtualItems -= MyList_CacheVirtualItems;
4687 _listCustom.RetrieveVirtualItem -= MyList_RetrieveVirtualItem;
4688 _listCustom.DrawSubItem -= MyList_DrawSubItem;
4689 _listCustom.HScrolled -= MyList_HScrolled;
4691 var cols = _listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4692 _listCustom.Columns.Clear();
4693 cols.ForEach(col => col.Dispose());
4696 _listCustom.ContextMenuStrip = null;
4697 _listCustom.ColumnHeaderContextMenuStrip = null;
4698 _listCustom.Font = null;
4700 _listCustom.SmallImageList = null;
4701 _listCustom.ListViewItemSorter = null;
4704 if (_curTab.Equals(_tabPage))
4711 this.PurgeListViewItemCache();
4715 _listCustom.Dispose();
4716 _statuses.RemoveTab(TabName);
4718 foreach (TabPage tp in ListTab.TabPages)
4720 DetailsListView lst = (DetailsListView)tp.Tag;
4721 var count = _statuses.Tabs[tp.Text].AllCount;
4722 if (lst.VirtualListSize != count)
4724 lst.VirtualListSize = count;
4731 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4733 this.PurgeListViewItemCache();
4734 _beforeSelectedTab = e.TabPage;
4737 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4741 if (!SettingDialog.TabMouseLock && e.Button == MouseButtons.Left && _tabDrag)
4744 Rectangle dragEnableRectangle = new Rectangle((int)(_tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2)), (int)(_tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2)), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4745 if (!dragEnableRectangle.Contains(e.Location))
4747 //タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4748 tn = ListTab.SelectedTab.Text;
4751 if (string.IsNullOrEmpty(tn)) return;
4753 foreach (TabPage tb in ListTab.TabPages)
4757 ListTab.DoDragDrop(tb, DragDropEffects.All);
4767 Point cpos = new Point(e.X, e.Y);
4768 for (int i = 0; i < ListTab.TabPages.Count; i++)
4770 Rectangle rect = ListTab.GetTabRect(i);
4771 if (rect.Left <= cpos.X & cpos.X <= rect.Right &
4772 rect.Top <= cpos.Y & cpos.Y <= rect.Bottom)
4774 _rclickTabName = ListTab.TabPages[i].Text;
4780 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4782 //_curList.Refresh();
4784 SetMainWindowTitle();
4785 SetStatusLabelUrl();
4786 if (ListTab.Focused || ((Control)ListTab.SelectedTab.Tag).Focused) this.Tag = ListTab.Tag;
4787 TabMenuControl(ListTab.SelectedTab.Text);
4788 this.PushSelectPostChain();
4791 private void SetListProperty()
4793 //削除などで見つからない場合は処理せず
4794 if (_curList == null) return;
4795 if (!_isColumnChanged) return;
4797 int[] dispOrder = new int[_curList.Columns.Count];
4798 for (int i = 0; i < _curList.Columns.Count; i++)
4800 for (int j = 0; j < _curList.Columns.Count; j++)
4802 if (_curList.Columns[j].DisplayIndex == i)
4811 foreach (TabPage tb in ListTab.TabPages)
4813 if (!tb.Equals(_curTab))
4815 if (tb.Tag != null && tb.Controls.Count > 0)
4817 DetailsListView lst = (DetailsListView)tb.Tag;
4818 for (int i = 0; i < lst.Columns.Count; i++)
4820 lst.Columns[dispOrder[i]].DisplayIndex = i;
4821 lst.Columns[i].Width = _curList.Columns[i].Width;
4827 _isColumnChanged = false;
4830 private void PostBrowser_StatusTextChanged(object sender, EventArgs e)
4834 if (PostBrowser.StatusText.StartsWith("http") || PostBrowser.StatusText.StartsWith("ftp")
4835 || PostBrowser.StatusText.StartsWith("data"))
4837 StatusLabelUrl.Text = PostBrowser.StatusText.Replace("&", "&&");
4839 if (string.IsNullOrEmpty(PostBrowser.StatusText))
4841 SetStatusLabelUrl();
4849 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4851 if (e.KeyChar == '@')
4853 if (!SettingDialog.UseAtIdSupplement) return;
4855 int cnt = AtIdSupl.ItemCount;
4856 ShowSuplDialog(StatusText, AtIdSupl);
4857 if (cnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
4860 else if (e.KeyChar == '#')
4862 if (!SettingDialog.UseHashSupplement) return;
4863 ShowSuplDialog(StatusText, HashSupl);
4868 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4870 ShowSuplDialog(owner, dialog, 0, "");
4873 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4875 ShowSuplDialog(owner, dialog, offset, "");
4878 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4880 dialog.StartsWith = startswith;
4887 dialog.ShowDialog();
4889 this.TopMost = SettingDialog.AlwaysTop;
4890 int selStart = owner.SelectionStart;
4893 if (dialog.DialogResult == DialogResult.OK)
4895 if (!string.IsNullOrEmpty(dialog.inputText))
4899 fHalf = owner.Text.Substring(0, selStart - offset);
4901 if (selStart < owner.Text.Length)
4903 eHalf = owner.Text.Substring(selStart);
4905 owner.Text = fHalf + dialog.inputText + eHalf;
4906 owner.SelectionStart = selStart + dialog.inputText.Length;
4913 fHalf = owner.Text.Substring(0, selStart);
4915 if (selStart < owner.Text.Length)
4917 eHalf = owner.Text.Substring(selStart);
4919 owner.Text = fHalf + eHalf;
4922 owner.SelectionStart = selStart;
4928 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4931 if (!e.Alt && !e.Control && !e.Shift)
4933 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4935 bool isSpace = false;
4936 foreach (char c in StatusText.Text.ToCharArray())
4938 if (c == ' ' || c == ' ')
4951 StatusText.Text = "";
4952 JumpUnreadMenuItem_Click(null, null);
4956 this.StatusText_TextChanged(null, null);
4959 private void StatusText_TextChanged(object sender, EventArgs e)
4962 int pLen = GetRestStatusCount(true, false);
4963 lblLen.Text = pLen.ToString();
4966 StatusText.ForeColor = Color.Red;
4970 StatusText.ForeColor = _clInputFont;
4972 if (string.IsNullOrEmpty(StatusText.Text))
4974 _reply_to_id = null;
4975 _reply_to_name = null;
4979 private int GetRestStatusCount(bool isAuto, bool isAddFooter)
4982 var statusText = this.StatusText.Text;
4983 statusText = statusText.Replace("\r\n", "\n");
4985 int pLen = 140 - statusText.Length;
4986 if (this.NotifyIcon1 == null || !this.NotifyIcon1.Visible) return pLen;
4987 if ((isAuto && !MyCommon.IsKeyDown(Keys.Control) && SettingDialog.PostShiftEnter) ||
4988 (isAuto && !MyCommon.IsKeyDown(Keys.Shift) && !SettingDialog.PostShiftEnter) ||
4989 (!isAuto && isAddFooter))
4991 if (SettingDialog.UseRecommendStatus)
4992 pLen -= SettingDialog.RecommendStatusText.Length;
4993 else if (SettingDialog.Status.Length > 0)
4994 pLen -= SettingDialog.Status.Length + 1;
4996 if (!string.IsNullOrEmpty(HashMgr.UseHash))
4998 pLen -= HashMgr.UseHash.Length + 1;
5000 //foreach (Match m in Regex.Matches(statusText, "https?:\/\/[-_.!~*//()a-zA-Z0-9;\/?:\@&=+\$,%#^]+"))
5002 // pLen += m.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5004 foreach (Match m in Regex.Matches(statusText, Twitter.rgUrl, RegexOptions.IgnoreCase))
5006 string before = m.Result("${before}");
5007 string url = m.Result("${url}");
5008 string protocol = m.Result("${protocol}");
5009 string domain = m.Result("${domain}");
5010 string path = m.Result("${path}");
5011 if (protocol.Length == 0)
5013 if (Regex.IsMatch(before, Twitter.url_invalid_without_protocol_preceding_chars))
5018 bool last_url_invalid_match = false;
5019 string lasturl = null;
5020 foreach (Match mm in Regex.Matches(domain, Twitter.url_valid_ascii_domain, RegexOptions.IgnoreCase))
5022 lasturl = mm.ToString();
5023 last_url_invalid_match = Regex.IsMatch(lasturl, Twitter.url_invalid_short_domain, RegexOptions.IgnoreCase);
5024 if (!last_url_invalid_match)
5026 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5030 if (path.Length != 0)
5032 if (last_url_invalid_match)
5034 pLen += lasturl.Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5036 pLen += path.Length;
5041 int shortUrlLength = protocol == "https://"
5042 ? SettingDialog.TwitterConfiguration.ShortUrlLengthHttps
5043 : SettingDialog.TwitterConfiguration.ShortUrlLength;
5045 pLen += url.Length - shortUrlLength;
5048 //if (m.Result("${url}").Length > SettingDialog.TwitterConfiguration.ShortUrlLength)
5050 // pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
5053 if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
5055 pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
5060 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
5062 this.itemCacheLock.EnterUpgradeableReadLock();
5065 if (_curList.Equals(sender))
5067 if (_itemCache != null &&
5068 e.StartIndex >= _itemCacheIndex &&
5069 e.EndIndex < _itemCacheIndex + _itemCache.Length)
5071 //If the newly requested cache is a subset of the old cache,
5072 //no need to rebuild everything, so do nothing.
5076 //Now we need to rebuild the cache.
5077 CreateCache(e.StartIndex, e.EndIndex);
5080 finally { this.itemCacheLock.ExitUpgradeableReadLock(); }
5083 private async void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
5085 ListViewItem item = null;
5086 PostClass cacheItemPost = null;
5088 if (_curList.Equals(sender))
5089 this.TryGetListViewItemCache(e.ItemIndex, out item, out cacheItemPost);
5093 //A cache miss, so create a new ListViewItem and pass it back.
5094 TabPage tb = (TabPage)((DetailsListView)sender).Parent;
5097 item = this.CreateItem(tb, _statuses[tb.Text, e.ItemIndex], e.ItemIndex);
5102 string[] sitem = {"", "", "", "", "", "", "", ""};
5103 item = new ImageListViewItem(sitem);
5107 // e.Item に値をセットする前に await しないこと
5110 await ((ImageListViewItem)item).GetImageAsync();
5113 private void CreateCache(int StartIndex, int EndIndex)
5115 this.itemCacheLock.EnterWriteLock();
5118 var tabInfo = _statuses.Tabs[_curTab.Text];
5120 //キャッシュ要求(要求範囲±30を作成)
5122 if (StartIndex < 0) StartIndex = 0;
5124 if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
5125 _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
5126 _itemCacheIndex = StartIndex;
5128 _itemCache = new ListViewItem[0] {};
5129 Array.Resize(ref _itemCache, _postCache.Length);
5131 for (int i = 0; i < _postCache.Length; i++)
5133 _itemCache[i] = CreateItem(_curTab, _postCache[i], StartIndex + i);
5138 //キャッシュ要求が実データとずれるため(イベントの遅延?)
5140 _itemCacheIndex = -1;
5143 finally { this.itemCacheLock.ExitWriteLock(); }
5147 /// DetailsListView のための ListViewItem のキャッシュを消去する
5149 private void PurgeListViewItemCache()
5151 this.itemCacheLock.EnterWriteLock();
5154 this._itemCache = null;
5155 this._itemCacheIndex = -1;
5156 this._postCache = null;
5158 finally { this.itemCacheLock.ExitWriteLock(); }
5161 private bool TryGetListViewItemCache(int index, out ListViewItem item, out PostClass post)
5163 this.itemCacheLock.EnterReadLock();
5166 if (this._itemCache != null && index >= this._itemCacheIndex && index < this._itemCacheIndex + this._itemCache.Length)
5168 item = this._itemCache[index - _itemCacheIndex];
5169 post = this._postCache[index - _itemCacheIndex];
5173 finally { this.itemCacheLock.ExitReadLock(); }
5180 private ListViewItem CreateItem(TabPage Tab, PostClass Post, int Index)
5182 StringBuilder mk = new StringBuilder();
5183 //if (Post.IsDeleted) mk.Append("×");
5184 //if (Post.IsMark) mk.Append("♪");
5185 //if (Post.IsProtect) mk.Append("Ю");
5186 //if (Post.InReplyToStatusId != null) mk.Append("⇒");
5187 if (Post.FavoritedCount > 0) mk.Append("+" + Post.FavoritedCount.ToString());
5188 ImageListViewItem itm;
5189 if (Post.RetweetedId == null)
5191 string[] sitem= {"",
5193 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5194 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5199 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5203 string[] sitem = {"",
5205 Post.IsDeleted ? "(DELETED)" : Post.TextSingleLine,
5206 Post.CreatedAt.ToString(SettingDialog.DateTimeFormat),
5207 Post.ScreenName + Environment.NewLine + "(RT:" + Post.RetweetedBy + ")",
5211 itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
5213 itm.StateIndex = Post.StateIndex;
5215 bool read = Post.IsRead;
5216 //未読管理していなかったら既読として扱う
5217 if (!_statuses.Tabs[Tab.Text].UnreadManage || !SettingDialog.UnreadManage) read = true;
5218 ChangeItemStyleRead(read, itm, Post, null);
5219 if (Tab.Equals(_curTab)) ColorizeList(itm, Index);
5224 /// 全てのタブの振り分けルールを反映し直します
5226 private void ApplyPostFilters()
5230 this.Cursor = Cursors.WaitCursor;
5232 this.PurgeListViewItemCache();
5233 this._curPost = null;
5234 this._curItemIndex = -1;
5235 this._statuses.FilterAll();
5237 foreach (TabPage tabPage in this.ListTab.TabPages)
5239 var tab = this._statuses.Tabs[tabPage.Text];
5241 var listview = (DetailsListView)tabPage.Tag;
5242 listview.VirtualListSize = tab.AllCount;
5244 if (this.SettingDialog.TabIconDisp)
5246 if (tab.UnreadCount > 0)
5247 tabPage.ImageIndex = 0;
5249 tabPage.ImageIndex = -1;
5253 if (!this.SettingDialog.TabIconDisp)
5254 this.ListTab.Refresh();
5258 this.Cursor = Cursors.Default;
5262 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
5264 e.DrawDefault = true;
5267 private void MyList_HScrolled(object sender, EventArgs e)
5269 DetailsListView listView = (DetailsListView)sender;
5273 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
5275 if (e.State == 0) return;
5276 e.DrawDefault = false;
5278 SolidBrush brs2 = null;
5279 if (!e.Item.Selected) //e.ItemStateでうまく判定できない???
5281 if (e.Item.BackColor == _clSelf)
5282 brs2 = _brsBackColorMine;
5283 else if (e.Item.BackColor == _clAtSelf)
5284 brs2 = _brsBackColorAt;
5285 else if (e.Item.BackColor == _clTarget)
5286 brs2 = _brsBackColorYou;
5287 else if (e.Item.BackColor == _clAtTarget)
5288 brs2 = _brsBackColorAtYou;
5289 else if (e.Item.BackColor == _clAtFromTarget)
5290 brs2 = _brsBackColorAtFromTarget;
5291 else if (e.Item.BackColor == _clAtTo)
5292 brs2 = _brsBackColorAtTo;
5294 brs2 = _brsBackColorNone;
5299 if (((Control)sender).Focused)
5300 brs2 = _brsHighLight;
5302 brs2 = _brsDeactiveSelection;
5304 e.Graphics.FillRectangle(brs2, e.Bounds);
5305 e.DrawFocusRectangle();
5306 this.DrawListViewItemIcon(e);
5309 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
5311 if (e.ItemState == 0) return;
5313 if (e.ColumnIndex > 0)
5316 RectangleF rct = e.Bounds;
5317 rct.Width = e.Header.Width;
5318 int fontHeight = e.Item.Font.Height;
5321 rct.Y += fontHeight;
5322 rct.Height -= fontHeight;
5326 int drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out heightDiff));
5328 //if (heightDiff > fontHeight * 0.7)
5330 // rct.Height += fontHeight;
5331 // drawLineCount += 1;
5334 //フォントの高さの半分を足してるのは保険。無くてもいいかも。
5335 if (!_iconCol && drawLineCount <= 1)
5337 //rct.Inflate(0, heightDiff / -2);
5338 //rct.Height += fontHeight / 2;
5340 else if (heightDiff < fontHeight * 0.7)
5342 //最終行が70%以上欠けていたら、最終行は表示しない
5343 //rct.Height = (float)((fontHeight * drawLineCount) + (fontHeight / 2));
5344 rct.Height = (fontHeight * drawLineCount) - 1;
5351 //if (!_iconCol && drawLineCount > 1)
5353 // rct.Y += fontHeight * 0.2;
5354 // if (heightDiff >= fontHeight * 0.8) rct.Height -= fontHeight * 0.2;
5359 Color color = (!e.Item.Selected) ? e.Item.ForeColor : //選択されていない行
5360 (((Control)sender).Focused) ? _clHighLight : //選択中の行
5365 Rectangle rctB = e.Bounds;
5366 rctB.Width = e.Header.Width;
5367 rctB.Height = fontHeight;
5369 using (Font fnt = new Font(e.Item.Font, FontStyle.Bold))
5371 TextRenderer.DrawText(e.Graphics,
5372 e.Item.SubItems[2].Text,
5374 Rectangle.Round(rct),
5376 TextFormatFlags.WordBreak |
5377 TextFormatFlags.EndEllipsis |
5378 TextFormatFlags.GlyphOverhangPadding |
5379 TextFormatFlags.NoPrefix);
5380 TextRenderer.DrawText(e.Graphics,
5381 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 + "]",
5385 TextFormatFlags.SingleLine |
5386 TextFormatFlags.EndEllipsis |
5387 TextFormatFlags.GlyphOverhangPadding |
5388 TextFormatFlags.NoPrefix);
5391 else if (drawLineCount == 1)
5393 TextRenderer.DrawText(e.Graphics,
5396 Rectangle.Round(rct),
5398 TextFormatFlags.SingleLine |
5399 TextFormatFlags.EndEllipsis |
5400 TextFormatFlags.GlyphOverhangPadding |
5401 TextFormatFlags.NoPrefix |
5402 TextFormatFlags.VerticalCenter);
5406 TextRenderer.DrawText(e.Graphics,
5409 Rectangle.Round(rct),
5411 TextFormatFlags.WordBreak |
5412 TextFormatFlags.EndEllipsis |
5413 TextFormatFlags.GlyphOverhangPadding |
5414 TextFormatFlags.NoPrefix);
5416 //if (e.ColumnIndex == 6) this.DrawListViewItemStateIcon(e, rct);
5421 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
5423 if (_iconSz == 0) return;
5425 ImageListViewItem item = (ImageListViewItem)e.Item;
5427 //e.Bounds.Leftが常に0を指すから自前で計算
5428 Rectangle itemRect = item.Bounds;
5429 var col0 = e.Item.ListView.Columns[0];
5430 itemRect.Width = col0.Width;
5432 if (col0.DisplayIndex > 0)
5434 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5436 if (clm.DisplayIndex < col0.DisplayIndex)
5437 itemRect.X += clm.Width;
5441 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5442 var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
5443 var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
5446 var img = item.Image;
5449 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5450 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5452 if (iconRect.Width > 0)
5454 e.Graphics.FillRectangle(Brushes.White, iconRect);
5455 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5458 e.Graphics.DrawImage(img.Image, iconRect);
5460 catch (ArgumentException)
5462 item.RefreshImageAsync();
5468 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5469 //iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5472 if (item.StateIndex > -1)
5474 Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5475 if (stateRect.Width > 0)
5477 //e.Graphics.FillRectangle(Brushes.White, stateRect);
5478 //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5479 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5484 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5486 base.ScaleControl(factor, specified);
5488 const int baseDpi = 96;
5490 // デザイン時の DPI (96dpi) との比を更新する
5491 this.currentScaleFactor = new SizeF(
5492 this.CurrentAutoScaleDimensions.Width / baseDpi,
5493 this.CurrentAutoScaleDimensions.Height / baseDpi);
5496 //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
5498 // ImageListViewItem item = (ImageListViewItem)e.Item;
5499 // if (item.StateImageIndex > -1)
5501 // ////e.Bounds.Leftが常に0を指すから自前で計算
5502 // //Rectangle itemRect = item.Bounds;
5503 // //itemRect.Width = e.Item.ListView.Columns[4].Width;
5505 // //foreach (ColumnHeader clm in e.Item.ListView.Columns)
5507 // // if (clm.DisplayIndex < e.Item.ListView.Columns[4].DisplayIndex)
5509 // // itemRect.X += clm.Width;
5513 // //Rectangle iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(_iconSz, _iconSz)), itemRect);
5514 // //iconRect.Offset(0, Math.Max(0, (itemRect.Height - _iconSz) / 2));
5516 // if (rct.Width > 0)
5518 // RectangleF stateRect = RectangleF.Intersect(rct, new RectangleF(rct.Location, new Size(18, 16)));
5519 // //e.Graphics.FillRectangle(Brushes.White, rct);
5520 // //e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
5521 // e.Graphics.DrawImage(this.PostStateImageList.Images(item.StateImageIndex), stateRect);
5526 private void DoTabSearch(string _word,
5536 if (_curList.VirtualListSize == 0)
5538 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5541 if (_curList.SelectedIndices.Count > 0)
5543 cidx = _curList.SelectedIndices[0];
5545 toIdx = _curList.VirtualListSize;
5549 case SEARCHTYPE.DialogSearch: //ダイアログからの検索
5550 if (_curList.SelectedIndices.Count > 0)
5551 cidx = _curList.SelectedIndices[0];
5555 case SEARCHTYPE.NextSearch: //次を検索
5556 if (_curList.SelectedIndices.Count > 0)
5558 cidx = _curList.SelectedIndices[0] + 1;
5559 if (cidx > toIdx) cidx = toIdx;
5566 case SEARCHTYPE.PrevSearch: //前を検索
5567 if (_curList.SelectedIndices.Count > 0)
5569 cidx = _curList.SelectedIndices[0] - 1;
5570 if (cidx < 0) cidx = 0;
5581 RegexOptions regOpt = RegexOptions.None;
5582 StringComparison fndOpt = StringComparison.Ordinal;
5585 regOpt = RegexOptions.IgnoreCase;
5586 fndOpt = StringComparison.OrdinalIgnoreCase;
5597 _search = new Regex(_word, regOpt);
5598 for (int idx = cidx; idx != toIdx; idx += stp)
5603 post = _statuses[_curTab.Text, idx];
5609 if (_search.IsMatch(post.Nickname)
5610 || _search.IsMatch(post.TextFromApi)
5611 || _search.IsMatch(post.ScreenName))
5613 SelectListItem(_curList, idx);
5614 _curList.EnsureVisible(idx);
5619 catch (ArgumentException)
5621 MessageBox.Show(Properties.Resources.DoTabSearchText1, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
5628 for (int idx = cidx; idx != toIdx; idx += stp)
5633 post = _statuses[_curTab.Text, idx];
5639 if (post.Nickname.IndexOf(_word, fndOpt) > -1
5640 || post.TextFromApi.IndexOf(_word, fndOpt) > -1
5641 || post.ScreenName.IndexOf(_word, fndOpt) > -1)
5643 SelectListItem(_curList, idx);
5644 _curList.EnsureVisible(idx);
5654 case SEARCHTYPE.DialogSearch:
5655 case SEARCHTYPE.NextSearch:
5659 case SEARCHTYPE.PrevSearch:
5661 cidx = _curList.VirtualListSize - 1;
5668 catch (ArgumentOutOfRangeException)
5671 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5674 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5677 this.ShowSearchDialog();
5680 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5682 var previousSearch = this.SearchDialog.ResultOptions;
5683 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5685 this.SearchDialog.Reset();
5686 this.ShowSearchDialog();
5692 previousSearch.Query,
5693 previousSearch.CaseSensitive,
5694 previousSearch.UseRegex,
5695 SEARCHTYPE.NextSearch);
5698 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5700 var previousSearch = this.SearchDialog.ResultOptions;
5701 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5703 this.SearchDialog.Reset();
5704 this.ShowSearchDialog();
5710 previousSearch.Query,
5711 previousSearch.CaseSensitive,
5712 previousSearch.UseRegex,
5713 SEARCHTYPE.PrevSearch);
5717 /// 検索ダイアログを表示し、検索を実行します
5719 private void ShowSearchDialog()
5721 // Recentタブの検索時以外では「新規タブに表示」ボタンを無効化する
5722 if (this._statuses.Tabs[this._curTab.Text].TabType == MyCommon.TabUsageType.Home)
5723 this.SearchDialog.DisableNewTabButton = false;
5725 this.SearchDialog.DisableNewTabButton = true;
5727 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5729 this.TopMost = this.SettingDialog.AlwaysTop;
5732 this.TopMost = this.SettingDialog.AlwaysTop;
5734 var searchOptions = this.SearchDialog.ResultOptions;
5735 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5737 if (searchOptions.NewTab)
5739 var tabName = searchOptions.Query;
5743 tabName = this._statuses.MakeTabName(tabName);
5745 catch (TabException ex)
5747 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5750 this.AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined);
5751 this._statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null);
5753 var filter = new PostFilterRule
5755 FilterBody = new[] { searchOptions.Query },
5756 UseRegex = searchOptions.UseRegex,
5757 CaseSensitive = searchOptions.CaseSensitive,
5759 this._statuses.Tabs[tabName].AddFilter(filter);
5761 var tabPage = this.ListTab.TabPages.Cast<TabPage>()
5762 .First(x => x.Text == tabName);
5764 this.ListTab.SelectedTab = tabPage;
5765 this.ListTabSelect(tabPage);
5767 this.ApplyPostFilters();
5768 this.SaveConfigsTabs();
5773 searchOptions.Query,
5774 searchOptions.CaseSensitive,
5775 searchOptions.UseRegex,
5776 SEARCHTYPE.DialogSearch);
5779 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5781 this.AddNewTabForSearch(searchOptions.Query);
5785 private void AboutMenuItem_Click(object sender, EventArgs e)
5787 using (TweenAboutBox about = new TweenAboutBox())
5789 about.ShowDialog(this);
5791 this.TopMost = SettingDialog.AlwaysTop;
5794 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5796 int bgnIdx = ListTab.TabPages.IndexOf(_curTab);
5798 DetailsListView lst = null;
5800 if (ImageSelector.Enabled)
5804 for (int i = bgnIdx; i < ListTab.TabPages.Count; i++)
5807 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5810 ListTab.SelectedIndex = i;
5811 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5812 //_curTab = ListTab.TabPages[i];
5817 //未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5818 if (idx == -1 && bgnIdx > 0)
5820 for (int i = 0; i < bgnIdx; i++)
5822 idx = _statuses.GetOldestUnreadIndex(ListTab.TabPages[i].Text);
5825 ListTab.SelectedIndex = i;
5826 lst = (DetailsListView)ListTab.TabPages[i].Tag;
5827 //_curTab = ListTab.TabPages[i];
5833 //全部調べたが未読見つからず→先頭タブの最新発言へ
5836 ListTab.SelectedIndex = 0;
5837 lst = (DetailsListView)ListTab.TabPages[0].Tag;
5838 //_curTab = ListTab.TabPages[0];
5839 if (_statuses.SortOrder == SortOrder.Ascending)
5840 idx = lst.VirtualListSize - 1;
5845 if (lst.VirtualListSize > 0 && idx > -1 && lst.VirtualListSize > idx)
5847 SelectListItem(lst, idx);
5848 if (_statuses.SortMode == IdComparerClass.ComparerMode.Id)
5850 if (_statuses.SortOrder == SortOrder.Ascending && lst.Items[idx].Position.Y > lst.ClientSize.Height - _iconSz - 10 ||
5851 _statuses.SortOrder == SortOrder.Descending && lst.Items[idx].Position.Y < _iconSz + 10)
5857 lst.EnsureVisible(idx);
5862 lst.EnsureVisible(idx);
5868 private void StatusOpenMenuItem_Click(object sender, EventArgs e)
5870 if (_curList.SelectedIndices.Count > 0 && _statuses.Tabs[_curTab.Text].TabType != MyCommon.TabUsageType.DirectMessage)
5872 var post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5873 OpenUriAsync(MyCommon.GetStatusUrl(post));
5877 private void FavorareMenuItem_Click(object sender, EventArgs e)
5879 if (_curList.SelectedIndices.Count > 0)
5881 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[0]];
5882 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + post.ScreenName + "/recent");
5886 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5888 await this.CheckNewVersion(false);
5891 private void RunTweenUp()
5893 ProcessStartInfo pinfo = new ProcessStartInfo();
5894 pinfo.UseShellExecute = true;
5895 pinfo.WorkingDirectory = MyCommon.settingPath;
5896 pinfo.FileName = Path.Combine(MyCommon.settingPath, "TweenUp3.exe");
5897 pinfo.Arguments = "\"" + Application.StartupPath + "\"";
5900 Process.Start(pinfo);
5904 MessageBox.Show("Failed to execute TweenUp3.exe.");
5908 public class VersionInfo
5910 public Version Version { get; set; }
5911 public Uri DownloadUri { get; set; }
5912 public string ReleaseNote { get; set; }
5916 /// OpenTween の最新バージョンの情報を取得します
5918 public async Task<VersionInfo> GetVersionInfoAsync()
5920 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5921 DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5923 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5924 .ConfigureAwait(false);
5926 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5927 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5929 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5930 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5932 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5934 return new VersionInfo
5936 Version = Version.Parse(msgHeader[0]),
5937 DownloadUri = new Uri(msgHeader[1]),
5938 ReleaseNote = msgBody,
5942 private async Task CheckNewVersion(bool startup = false)
5944 if (ApplicationSettings.VersionInfoUrl == null)
5945 return; // 更新チェック無効化
5949 var versionInfo = await this.GetVersionInfoAsync();
5951 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5956 var msgtext = string.Format(Properties.Resources.CheckNewVersionText7,
5957 MyCommon.GetReadableVersion(), MyCommon.GetReadableVersion(versionInfo.Version));
5958 msgtext = MyCommon.ReplaceAppName(msgtext);
5960 MessageBox.Show(msgtext,
5961 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5962 MessageBoxButtons.OK, MessageBoxIcon.Information);
5967 using (var dialog = new UpdateDialog())
5969 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5970 MyCommon.GetReadableVersion(versionInfo.Version));
5971 dialog.DetailsText = versionInfo.ReleaseNote;
5973 if (dialog.ShowDialog(this) == DialogResult.Yes)
5975 await this.OpenUriAsync(versionInfo.DownloadUri.OriginalString);
5981 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5984 MessageBox.Show(Properties.Resources.CheckNewVersionText10,
5985 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5986 MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
5991 private void Colorize()
5995 //件数関連の場合、タイトル即時書き換え
5996 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
5997 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5998 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5999 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
6001 SetMainWindowTitle();
6003 if (!StatusLabelUrl.Text.StartsWith("http")) SetStatusLabelUrl();
6004 foreach (TabPage tb in ListTab.TabPages)
6006 if (_statuses.Tabs[tb.Text].UnreadCount == 0)
6008 if (SettingDialog.TabIconDisp)
6010 if (tb.ImageIndex == 0) tb.ImageIndex = -1;
6014 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
6017 public string createDetailHtml(string orgdata)
6019 return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter;
6022 private async void DisplayItemImage_Downloaded(object sender, EventArgs e)
6024 if (sender.Equals(displayItem))
6026 this.ClearUserPicture();
6028 var img = displayItem.Image;
6032 img = await img.CloneAsync();
6034 UserPicture.Image = img;
6038 UserPicture.ShowErrorImage();
6043 private void DispSelectedPost()
6045 DispSelectedPost(false);
6048 private PostClass displayPost = new PostClass();
6051 /// サムネイルの表示処理を表すタスク
6053 private Task thumbnailTask = null;
6056 /// サムネイル表示に使用する CancellationToken の生成元
6058 private CancellationTokenSource thumbnailTokenSource = null;
6060 private void DispSelectedPost(bool forceupdate)
6062 if (_curList.SelectedIndices.Count == 0 || _curPost == null)
6065 var oldDisplayPost = this.displayPost;
6066 this.displayPost = this._curPost;
6068 if (!forceupdate && this._curPost.Equals(oldDisplayPost))
6071 if (displayItem != null)
6073 displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
6076 displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
6077 displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
6079 using (ControlTransaction.Update(this.TableLayoutPanel1))
6081 var sourceText = "";
6082 string sourceUrl = null;
6085 var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
6088 var src = mc.Groups["sourceurl"].Value;
6089 if (Regex.IsMatch(src, "^https?://"))
6092 sourceUrl = "https://twitter.com/" + src;
6095 if (_curPost.Source != null)
6096 sourceText = _curPost.Source;
6098 SourceLinkLabel.Text = sourceText;
6099 SourceLinkLabel.Tag = sourceUrl;
6100 SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
6106 nameText = "DM FROM <- ";
6108 nameText = "DM TO -> ";
6114 nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
6115 if (_curPost.RetweetedId != null)
6116 nameText += " (RT:" + _curPost.RetweetedBy + ")";
6118 NameLabel.Text = nameText;
6119 NameLabel.Tag = _curPost.ScreenName;
6121 var nameForeColor = SystemColors.ControlText;
6122 if (_curPost.IsOwl && (this.SettingDialog.OneWayLove || _curPost.IsDm))
6123 nameForeColor = this._clOWL;
6124 if (_curPost.RetweetedId != null)
6125 nameForeColor = this._clRetweet;
6127 nameForeColor = this._clFav;
6128 NameLabel.ForeColor = nameForeColor;
6130 this.ClearUserPicture();
6132 if (!string.IsNullOrEmpty(_curPost.ImageUrl))
6134 var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
6137 UserPicture.Image = image != null ? image.Clone() : null;
6141 UserPicture.ShowErrorImage();
6145 DateTimeLabel.Text = _curPost.CreatedAt.ToString();
6147 if (DumpPostClassToolStripMenuItem.Checked)
6149 StringBuilder sb = new StringBuilder(512);
6151 sb.Append("-----Start PostClass Dump<br>");
6152 sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
6153 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
6154 sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
6155 //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
6156 sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
6157 sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
6158 sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
6159 sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
6160 sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
6161 sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
6162 sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
6163 sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
6164 sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
6165 sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
6166 sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
6168 foreach (string nm in _curPost.ReplyToList)
6170 sb.AppendFormat("ReplyToList : {0}<br>", nm);
6173 sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
6174 sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
6175 sb.AppendFormat("Text : {0}<br>", _curPost.Text);
6176 sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
6177 sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
6178 sb.AppendFormat("Source : {0}<br>", _curPost.Source);
6179 sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
6180 sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
6181 sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
6182 sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
6183 sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
6184 sb.Append("-----End PostClass Dump<br>");
6186 PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
6190 // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
6191 // (同一ツイートの RT は文面が同じであるため同様に更新しない)
6192 if (_curPost.StatusId != oldDisplayPost.StatusId)
6194 this.PostBrowser.DocumentText =
6195 this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
6197 this.PostBrowser.Document.Window.ScrollTo(0, 0);
6199 this.SplitContainer3.Panel2Collapsed = true;
6201 if (this.IsPreviewEnable)
6203 if (this.thumbnailTokenSource != null)
6205 var oldTokenSource = this.thumbnailTokenSource;
6207 var cancelTask = Task.Run(() => oldTokenSource.Cancel());
6209 Task.WhenAll(this.thumbnailTask, cancelTask)
6210 .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
6213 this.thumbnailTokenSource = new CancellationTokenSource();
6215 var token = this.thumbnailTokenSource.Token;
6216 this.thumbnailTask = this.tweetThumbnail1.ShowThumbnailAsync(_curPost, token);
6223 private void MatomeMenuItem_Click(object sender, EventArgs e)
6225 OpenApplicationWebsite();
6228 private void OpenApplicationWebsite()
6230 OpenUriAsync(ApplicationSettings.WebsiteUrl);
6233 private void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
6235 OpenUriAsync(ApplicationSettings.ShortcutKeyUrl);
6238 private void ListTab_KeyDown(object sender, KeyEventArgs e)
6240 if (ListTab.SelectedTab != null)
6242 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6244 Control pnl = ListTab.SelectedTab.Controls["panelSearch"];
6245 if (pnl.Controls["comboSearch"].Focused ||
6246 pnl.Controls["comboLang"].Focused ||
6247 pnl.Controls["buttonSearch"].Focused) return;
6249 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
6250 if (State == ModifierState.NotFlags) return;
6251 if (State != ModifierState.None) _anchorFlag = false;
6252 if (CommonKeyDown(e.KeyCode, FocusedControl.ListTab, State))
6255 e.SuppressKeyPress = true;
6260 private ModifierState GetModifierState(bool sControl, bool sShift, bool sAlt)
6262 ModifierState state = ModifierState.None;
6263 if (sControl) state = state | ModifierState.Ctrl;
6264 if (sShift) state = state | ModifierState.Shift;
6265 if (sAlt) state = state | ModifierState.Alt;
6270 private enum ModifierState
6282 //PostBrowser = 102,
6286 private enum FocusedControl : int
6294 private bool CommonKeyDown(Keys KeyCode, FocusedControl Focused, ModifierState Modifier)
6296 //リストのカーソル移動関係(上下キー、PageUp/Downに該当)
6297 if (Focused == FocusedControl.ListTab)
6299 if (Modifier == (ModifierState.Ctrl | ModifierState.Shift) ||
6300 Modifier == ModifierState.Ctrl ||
6301 Modifier == ModifierState.None ||
6302 Modifier == ModifierState.Shift)
6304 if (KeyCode == Keys.J)
6306 SendKeys.Send("{DOWN}");
6309 else if (KeyCode == Keys.K)
6311 SendKeys.Send("{UP}");
6315 if (Modifier == ModifierState.Shift ||
6316 Modifier == ModifierState.None)
6318 if (KeyCode == Keys.F)
6320 SendKeys.Send("{PGDN}");
6323 else if (KeyCode == Keys.B)
6325 SendKeys.Send("{PGUP}");
6334 case ModifierState.None:
6339 OpenApplicationWebsite();
6342 MenuItemSearchNext_Click(null, null);
6348 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
6351 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
6354 if (Focused != FocusedControl.StatusText)
6360 case Keys.ProcessKey:
6361 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6362 JumpUnreadMenuItem_Click(null, null);
6365 if (Focused == FocusedControl.ListTab) _anchorFlag = false;
6366 ShowRelatedStatusesMenuItem_Click(null, null);
6370 if (Focused == FocusedControl.ListTab)
6383 case Keys.OemPeriod:
6387 if (this.StatusText.Enabled) this.StatusText.Focus();
6390 MakeReplyOrDirectStatus();
6397 _anchorFlag = false;
6417 // ] in_reply_to参照元へ戻る
6418 GoInReplyToPostTree();
6421 // [ in_reply_toへジャンプ
6422 GoBackInReplyToPostTree();
6425 if (ListTab.SelectedTab != null)
6427 MyCommon.TabUsageType tabtype = _statuses.Tabs[ListTab.SelectedTab.Text].TabType;
6428 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch)
6430 TabPage relTp = ListTab.SelectedTab;
6431 RemoveSpecifiedTab(relTp.Text, false);
6439 else if (Focused == FocusedControl.PostBrowser)
6446 //スクロールを発生させるため、true を返す
6451 case ModifierState.Ctrl:
6456 MakeReplyOrDirectStatus(false, true);
6462 MakeReplyOrDirectStatus(false, false);
6465 FavoriteChange(true);
6468 doRepliedStatusOpen();
6474 ReadedStripMenuItem_Click(null, null);
6477 HashManageMenuItem_Click(null, null);
6480 UrlConvertAutoToolStripMenuItem_Click(null, null);
6483 if (Focused != FocusedControl.PostBrowser)
6485 MultiLineMenuItem_Click(null, null);
6490 MenuItemSubSearch_Click(null, null);
6497 MoveToHomeToolStripMenuItem_Click(null, null);
6501 MoveToFavToolStripMenuItem_Click(null, null);
6505 StatusOpenMenuItem_Click(null, null);
6509 OpenURLMenuItem_Click(null, null);
6513 if (Focused == FocusedControl.ListTab)
6520 return false; //スルーする
6538 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
6539 int tabNo = KeyCode - Keys.D1;
6540 if (ListTab.TabPages.Count < tabNo)
6542 ListTab.SelectedIndex = tabNo;
6543 ListTabSelect(ListTab.TabPages[tabNo]);
6546 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
6547 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
6551 else if (Focused == FocusedControl.StatusText)
6557 StatusText.SelectAll();
6561 if (!string.IsNullOrWhiteSpace(StatusText.Text))
6563 _history[_hisIdx] = new PostingStatus(StatusText.Text, _reply_to_id, _reply_to_name);
6565 if (KeyCode == Keys.Up)
6568 if (_hisIdx < 0) _hisIdx = 0;
6573 if (_hisIdx > _history.Count - 1) _hisIdx = _history.Count - 1;
6575 StatusText.Text = _history[_hisIdx].status;
6576 _reply_to_id = _history[_hisIdx].inReplyToId;
6577 _reply_to_name = _history[_hisIdx].inReplyToName;
6578 StatusText.SelectionStart = StatusText.Text.Length;
6582 if (ListTab.SelectedIndex == 0)
6584 ListTab.SelectedIndex = ListTab.TabCount - 1;
6588 ListTab.SelectedIndex -= 1;
6594 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
6596 ListTab.SelectedIndex = 0;
6600 ListTab.SelectedIndex += 1;
6608 //フォーカスPostBrowserもしくは関係なし
6612 PostBrowser.Document.ExecCommand("SelectAll", false, null);
6616 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
6617 if (!string.IsNullOrEmpty(_selText))
6621 Clipboard.SetDataObject(_selText, false, 5, 100);
6623 catch (Exception ex)
6625 MessageBox.Show(ex.Message);
6630 MultiLineMenuItem.Checked = !MultiLineMenuItem.Checked;
6631 MultiLineMenuItem_Click(null, null);
6636 case ModifierState.Shift:
6641 MenuItemSearchPrev_Click(null, null);
6647 GetTimeline(MyCommon.WORKERTYPE.Reply, -1, "");
6650 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, -1, "");
6654 if (Focused != FocusedControl.StatusText)
6656 if (KeyCode == Keys.R)
6663 if (Focused == FocusedControl.ListTab)
6683 GoBackInReplyToPostTree(true, false);
6686 GoBackInReplyToPostTree(true, true);
6690 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6695 // お気に入り前後ジャンプ(SHIFT+N←/P→)
6699 this.GoBackSelectPostChain();
6704 case ModifierState.Alt:
6708 doReTweetOfficial(true);
6711 if (_curPost != null)
6713 doShowUserStatus(_curPost.ScreenName, false);
6718 ScrollDownPostBrowser(false);
6721 ScrollDownPostBrowser(true);
6724 PageDownPostBrowser(false);
6727 PageDownPostBrowser(true);
6730 if (Focused == FocusedControl.ListTab)
6732 // 別タブの同じ書き込みへ(ALT+←/→)
6733 if (KeyCode == Keys.Right)
6735 GoSamePostToAnotherTab(false);
6738 else if (KeyCode == Keys.Left)
6740 GoSamePostToAnotherTab(true);
6745 case ModifierState.Ctrl | ModifierState.Shift:
6749 MakeReplyOrDirectStatus(false, true, true);
6755 if (ListTab.SelectedTab != null)
6757 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
6759 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
6765 FavoriteChange(false);
6768 UnreadStripMenuItem_Click(null, null);
6771 HashToggleMenuItem_Click(null, null);
6774 ImageSelectMenuItem_Click(null, null);
6780 FavorareMenuItem_Click(null, null);
6783 if (Focused == FocusedControl.StatusText)
6789 if (_curList != null && _curList.VirtualListSize != 0 &&
6790 _curList.SelectedIndices.Count > 0 && _curList.SelectedIndices[0] > 0)
6792 idx = _curList.SelectedIndices[0] - 1;
6793 SelectListItem(_curList, idx);
6794 _curList.EnsureVisible(idx);
6799 if (_curList != null && _curList.VirtualListSize != 0 && _curList.SelectedIndices.Count > 0
6800 && _curList.SelectedIndices[0] < _curList.VirtualListSize - 1)
6802 idx = _curList.SelectedIndices[0] + 1;
6803 SelectListItem(_curList, idx);
6804 _curList.EnsureVisible(idx);
6809 if (StatusText.SelectionStart > 0)
6811 int endidx = StatusText.SelectionStart - 1;
6812 string startstr = "";
6813 bool pressed = false;
6814 for (int i = StatusText.SelectionStart - 1; i >= 0; i--)
6816 char c = StatusText.Text[i];
6817 if (Char.IsLetterOrDigit(c) || c == '_')
6824 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6825 int cnt = AtIdSupl.ItemCount;
6826 ShowSuplDialog(StatusText, AtIdSupl, startstr.Length + 1, startstr);
6827 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
6832 startstr = StatusText.Text.Substring(i + 1, endidx - i);
6833 ShowSuplDialog(StatusText, HashSupl, startstr.Length + 1, startstr);
6845 else if (Focused == FocusedControl.ListTab)
6847 DetailsListView lst = (DetailsListView)ListTab.SelectedTab.Tag;
6859 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6860 int colNo = KeyCode - Keys.D1;
6861 if (lst.Columns.Count < colNo) return false;
6862 col = lst.Columns.Cast<ColumnHeader>().Where((x) => { return x.DisplayIndex == colNo; }).FirstOrDefault();
6863 if (col == null) return false;
6864 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6867 col = lst.Columns.Cast<ColumnHeader>().OrderByDescending((x) => { return x.DisplayIndex; }).First();
6868 MyList_ColumnClick(lst, new ColumnClickEventArgs(col.Index));
6873 case ModifierState.Ctrl | ModifierState.Alt:
6874 if (KeyCode == Keys.S)
6876 FavoritesRetweetOriginal();
6879 else if (KeyCode == Keys.R)
6881 FavoritesRetweetUnofficial();
6884 else if (KeyCode == Keys.H)
6886 OpenUserAppointUrl();
6890 case ModifierState.Alt | ModifierState.Shift:
6891 if (Focused == FocusedControl.PostBrowser)
6893 if (KeyCode == Keys.R)
6894 doReTweetUnofficial();
6895 else if (KeyCode == Keys.C)
6902 if (!this.ExistCurrentPost) return false;
6903 doTranslation(_curPost.TextFromApi);
6906 doReTweetUnofficial();
6912 this.tweetThumbnail1.ScrollUp();
6915 this.tweetThumbnail1.ScrollDown();
6918 if (Focused == FocusedControl.ListTab && KeyCode == Keys.Enter)
6920 if (!this.SplitContainer3.Panel2Collapsed)
6922 OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail);
6932 private void ScrollDownPostBrowser(bool forward)
6934 var doc = PostBrowser.Document;
6935 if (doc == null) return;
6937 var tags = doc.GetElementsByTagName("html");
6941 tags[0].ScrollTop += SettingDialog.FontDetail.Height;
6943 tags[0].ScrollTop -= SettingDialog.FontDetail.Height;
6947 private void PageDownPostBrowser(bool forward)
6949 var doc = PostBrowser.Document;
6950 if (doc == null) return;
6952 var tags = doc.GetElementsByTagName("html");
6956 tags[0].ScrollTop += PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6958 tags[0].ScrollTop -= PostBrowser.ClientRectangle.Height - SettingDialog.FontDetail.Height;
6962 private void GoNextTab(bool forward)
6964 int idx = ListTab.SelectedIndex;
6968 if (idx > ListTab.TabPages.Count - 1) idx = 0;
6973 if (idx < 0) idx = ListTab.TabPages.Count - 1;
6975 ListTab.SelectedIndex = idx;
6976 ListTabSelect(ListTab.TabPages[idx]);
6979 private void CopyStot()
6982 StringBuilder sb = new StringBuilder();
6983 bool IsProtected = false;
6985 if (this._curTab != null && this._statuses.GetTabByName(this._curTab.Text) != null) isDm = this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage;
6986 foreach (int idx in _curList.SelectedIndices)
6988 PostClass post = _statuses[_curTab.Text, idx];
6994 if (post.IsDeleted) continue;
6997 if (post.RetweetedId != null)
6998 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
7000 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7004 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
7009 MessageBox.Show(Properties.Resources.CopyStotText1);
7013 clstr = sb.ToString();
7016 Clipboard.SetDataObject(clstr, false, 5, 100);
7018 catch (Exception ex)
7020 MessageBox.Show(ex.Message);
7025 private void CopyIdUri()
7028 StringBuilder sb = new StringBuilder();
7029 if (this._curTab == null) return;
7030 if (this._statuses.GetTabByName(this._curTab.Text) == null) return;
7031 if (this._statuses.GetTabByName(this._curTab.Text).TabType == MyCommon.TabUsageType.DirectMessage) return;
7032 foreach (int idx in _curList.SelectedIndices)
7034 var post = _statuses[_curTab.Text, idx];
7035 sb.Append(MyCommon.GetStatusUrl(post));
7036 sb.Append(Environment.NewLine);
7040 clstr = sb.ToString();
7043 Clipboard.SetDataObject(clstr, false, 5, 100);
7045 catch (Exception ex)
7047 MessageBox.Show(ex.Message);
7052 private void GoFav(bool forward)
7054 if (_curList.VirtualListSize == 0) return;
7061 if (_curList.SelectedIndices.Count == 0)
7067 fIdx = _curList.SelectedIndices[0] + 1;
7068 if (fIdx > _curList.VirtualListSize - 1) return;
7070 toIdx = _curList.VirtualListSize;
7075 if (_curList.SelectedIndices.Count == 0)
7077 fIdx = _curList.VirtualListSize - 1;
7081 fIdx = _curList.SelectedIndices[0] - 1;
7082 if (fIdx < 0) return;
7088 for (int idx = fIdx; idx != toIdx; idx += stp)
7090 if (_statuses[_curTab.Text, idx].IsFav)
7092 SelectListItem(_curList, idx);
7093 _curList.EnsureVisible(idx);
7099 private void GoSamePostToAnotherTab(bool left)
7101 if (_curList.VirtualListSize == 0) return;
7107 if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage) return; // Directタブは対象外(見つかるはずがない)
7108 if (_curList.SelectedIndices.Count == 0) return; //未選択も処理しない
7110 targetId = GetCurTabPost(_curList.SelectedIndices[0]).StatusId;
7115 if (ListTab.SelectedIndex == 0)
7121 fIdx = ListTab.SelectedIndex - 1;
7129 if (ListTab.SelectedIndex == ListTab.TabCount - 1)
7135 fIdx = ListTab.SelectedIndex + 1;
7137 toIdx = ListTab.TabCount;
7142 for (int tabidx = fIdx; tabidx != toIdx; tabidx += stp)
7144 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage) continue; // Directタブは対象外
7145 for (int idx = 0; idx < ((DetailsListView)ListTab.TabPages[tabidx].Tag).VirtualListSize; idx++)
7147 if (_statuses[ListTab.TabPages[tabidx].Text, idx].StatusId == targetId)
7149 ListTab.SelectedIndex = tabidx;
7150 ListTabSelect(ListTab.TabPages[tabidx]);
7151 SelectListItem(_curList, idx);
7152 _curList.EnsureVisible(idx);
7161 private void GoPost(bool forward)
7163 if (_curList.SelectedIndices.Count == 0 || _curPost == null) return;
7170 fIdx = _curList.SelectedIndices[0] + 1;
7171 if (fIdx > _curList.VirtualListSize - 1) return;
7172 toIdx = _curList.VirtualListSize;
7177 fIdx = _curList.SelectedIndices[0] - 1;
7178 if (fIdx < 0) return;
7184 if (_curPost.RetweetedId == null)
7186 name = _curPost.ScreenName;
7190 name = _curPost.RetweetedBy;
7192 for (int idx = fIdx; idx != toIdx; idx += stp)
7194 if (_statuses[_curTab.Text, idx].RetweetedId == null)
7196 if (_statuses[_curTab.Text, idx].ScreenName == name)
7198 SelectListItem(_curList, idx);
7199 _curList.EnsureVisible(idx);
7205 if (_statuses[_curTab.Text, idx].RetweetedBy == name)
7207 SelectListItem(_curList, idx);
7208 _curList.EnsureVisible(idx);
7215 private void GoRelPost(bool forward)
7217 if (_curList.SelectedIndices.Count == 0) return;
7224 fIdx = _curList.SelectedIndices[0] + 1;
7225 if (fIdx > _curList.VirtualListSize - 1) return;
7226 toIdx = _curList.VirtualListSize;
7231 fIdx = _curList.SelectedIndices[0] - 1;
7232 if (fIdx < 0) return;
7239 if (_curPost == null) return;
7240 _anchorPost = _curPost;
7245 if (_anchorPost == null) return;
7248 for (int idx = fIdx; idx != toIdx; idx += stp)
7250 PostClass post = _statuses[_curTab.Text, idx];
7251 if (post.ScreenName == _anchorPost.ScreenName ||
7252 post.RetweetedBy == _anchorPost.ScreenName ||
7253 post.ScreenName == _anchorPost.RetweetedBy ||
7254 (!string.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == _anchorPost.RetweetedBy) ||
7255 _anchorPost.ReplyToList.Contains(post.ScreenName.ToLower()) ||
7256 _anchorPost.ReplyToList.Contains(post.RetweetedBy.ToLower()) ||
7257 post.ReplyToList.Contains(_anchorPost.ScreenName.ToLower()) ||
7258 post.ReplyToList.Contains(_anchorPost.RetweetedBy.ToLower()))
7260 SelectListItem(_curList, idx);
7261 _curList.EnsureVisible(idx);
7267 private void GoAnchor()
7269 if (_anchorPost == null) return;
7270 int idx = _statuses.Tabs[_curTab.Text].IndexOf(_anchorPost.StatusId);
7271 if (idx == -1) return;
7273 SelectListItem(_curList, idx);
7274 _curList.EnsureVisible(idx);
7277 private void GoTopEnd(bool GoTop)
7284 _item = _curList.GetItemAt(0, 25);
7292 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7294 idx = _curList.VirtualListSize - 1;
7298 SelectListItem(_curList, idx);
7301 private void GoMiddle()
7308 _item = _curList.GetItemAt(0, 0);
7318 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
7321 idx2 = _curList.VirtualListSize - 1;
7327 idx3 = (idx1 + idx2) / 2;
7329 SelectListItem(_curList, idx3);
7332 private void GoLast()
7334 if (_curList.VirtualListSize == 0) return;
7336 if (_statuses.SortOrder == SortOrder.Ascending)
7338 SelectListItem(_curList, _curList.VirtualListSize - 1);
7339 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7343 SelectListItem(_curList, 0);
7344 _curList.EnsureVisible(0);
7348 private void MoveTop()
7350 if (_curList.SelectedIndices.Count == 0) return;
7351 int idx = _curList.SelectedIndices[0];
7352 if (_statuses.SortOrder == SortOrder.Ascending)
7354 _curList.EnsureVisible(_curList.VirtualListSize - 1);
7358 _curList.EnsureVisible(0);
7360 _curList.EnsureVisible(idx);
7363 private void GoInReplyToPostTree()
7365 if (_curPost == null) return;
7367 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7369 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
7371 PostClass post = null;
7372 string r = tw.GetStatusApi(false, _curPost.StatusId, ref post);
7373 if (string.IsNullOrEmpty(r) && post != null)
7375 _curPost.InReplyToStatusId = post.InReplyToStatusId;
7376 _curPost.InReplyToUser = post.InReplyToUser;
7377 _curPost.IsReply = post.IsReply;
7378 this.PurgeListViewItemCache();
7379 _curList.RedrawItems(_curItemIndex, _curItemIndex, false);
7383 this.StatusLabel.Text = r;
7387 if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
7389 if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
7391 replyChains = new Stack<ReplyChain>();
7393 replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
7396 string inReplyToTabName;
7397 long inReplyToId = _curPost.InReplyToStatusId.Value;
7398 string inReplyToUser = _curPost.InReplyToUser;
7399 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7401 var inReplyToPosts = from tab in _statuses.Tabs.Values
7402 orderby tab != curTabClass
7403 from post in tab.Posts.Values
7404 where post.StatusId == inReplyToId
7405 let index = tab.IndexOf(post.StatusId)
7407 select new {Tab = tab, Index = index};
7411 var inReplyPost = inReplyToPosts.First();
7412 inReplyToTabName = inReplyPost.Tab.TabName;
7413 inReplyToIndex = inReplyPost.Index;
7415 catch (InvalidOperationException)
7417 PostClass post = null;
7418 string r = tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value, ref post);
7419 if (string.IsNullOrEmpty(r) && post != null)
7422 _statuses.AddPost(post);
7423 _statuses.DistributePosts();
7424 //_statuses.SubmitUpdate(null, null, null, false);
7425 this.RefreshTimeline(false);
7428 var inReplyPost = inReplyToPosts.First();
7429 inReplyToTabName = inReplyPost.Tab.TabName;
7430 inReplyToIndex = inReplyPost.Index;
7432 catch (InvalidOperationException)
7434 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7440 this.StatusLabel.Text = r;
7441 OpenUriAsync("https://twitter.com/" + inReplyToUser + "/statuses/" + inReplyToId.ToString());
7446 TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
7447 DetailsListView listView = (DetailsListView)tabPage.Tag;
7449 if (_curTab != tabPage)
7451 this.ListTab.SelectTab(tabPage);
7454 this.SelectListItem(listView, inReplyToIndex);
7455 listView.EnsureVisible(inReplyToIndex);
7458 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
7460 if (_curPost == null) return;
7462 TabClass curTabClass = _statuses.Tabs[_curTab.Text];
7463 //Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
7467 if (_curPost.InReplyToStatusId != null)
7469 var posts = from t in _statuses.Tabs
7470 from p in t.Value.Posts
7471 where p.Value.StatusId != _curPost.StatusId && p.Value.InReplyToStatusId == _curPost.InReplyToStatusId
7472 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7474 orderby isForward ? indexOf : indexOf * -1
7475 orderby t.Value != curTabClass
7476 select new {Tab = t.Value, Post = p.Value, Index = indexOf};
7479 var postList = posts.ToList();
7480 for (int i = postList.Count - 1; i >= 0; i--)
7483 if (postList.FindIndex((pst) => { return pst.Post.StatusId == postList[index].Post.StatusId; }) != index)
7485 postList.RemoveAt(index);
7488 var post = postList.FirstOrDefault((pst) => { return pst.Tab == curTabClass && isForward ? pst.Index > _curItemIndex : pst.Index < _curItemIndex; });
7489 if (post == null) post = postList.FirstOrDefault((pst) => { return pst.Tab != curTabClass; });
7490 if (post == null) post = postList.First();
7491 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7492 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7493 SelectListItem(listView, post.Index);
7494 listView.EnsureVisible(post.Index);
7496 catch (InvalidOperationException)
7504 if (replyChains == null || replyChains.Count < 1)
7506 var posts = from t in _statuses.Tabs
7507 from p in t.Value.Posts
7508 where p.Value.InReplyToStatusId == _curPost.StatusId
7509 let indexOf = t.Value.IndexOf(p.Value.StatusId)
7512 orderby t.Value != curTabClass
7513 select new {Tab = t.Value, Index = indexOf};
7516 var post = posts.First();
7517 this.ListTab.SelectTab(this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == post.Tab.TabName; }));
7518 DetailsListView listView = (DetailsListView)this.ListTab.SelectedTab.Tag;
7519 SelectListItem(listView, post.Index);
7520 listView.EnsureVisible(post.Index);
7522 catch (InvalidOperationException)
7529 ReplyChain chainHead = replyChains.Pop();
7530 if (chainHead.InReplyToId == _curPost.StatusId)
7532 int idx = _statuses.Tabs[chainHead.OriginalTab.Text].IndexOf(chainHead.OriginalId);
7541 ListTab.SelectTab(chainHead.OriginalTab);
7547 SelectListItem(_curList, idx);
7548 _curList.EnsureVisible(idx);
7554 this.GoBackInReplyToPostTree(parallel);
7560 private void GoBackSelectPostChain()
7562 if (this.selectPostChains.Count > 1)
7571 this.selectPostChains.Pop();
7572 var tabPostPair = this.selectPostChains.Peek();
7574 if (!this.ListTab.TabPages.Contains(tabPostPair.Item1)) continue; //該当タブが存在しないので無視
7576 if (tabPostPair.Item2 != null)
7578 idx = this._statuses.Tabs[tabPostPair.Item1.Text].IndexOf(tabPostPair.Item2.StatusId);
7579 if (idx == -1) continue; //該当ポストが存在しないので無視
7582 tp = tabPostPair.Item1;
7584 this.selectPostChains.Pop();
7586 catch (InvalidOperationException)
7592 while (this.selectPostChains.Count > 1);
7597 //履歴が残り1つであればクリアしておく
7598 if (this.selectPostChains.Count == 1)
7599 this.selectPostChains.Clear();
7603 DetailsListView lst = (DetailsListView)tp.Tag;
7604 this.ListTab.SelectedTab = tp;
7607 SelectListItem(lst, idx);
7608 lst.EnsureVisible(idx);
7614 private void PushSelectPostChain()
7616 int count = this.selectPostChains.Count;
7619 var p = this.selectPostChains.Peek();
7620 if (p.Item1 == this._curTab)
7622 if (p.Item2 == this._curPost) return; //最新の履歴と同一
7623 if (p.Item2 == null) this.selectPostChains.Pop(); //置き換えるため削除
7626 if (count >= 2500) TrimPostChain();
7627 this.selectPostChains.Push(Tuple.Create(this._curTab, this._curPost));
7630 private void TrimPostChain()
7632 if (this.selectPostChains.Count <= 2000) return;
7633 var p = new Stack<Tuple<TabPage, PostClass>>(2000);
7634 for (int i = 0; i < 2000; i++)
7636 p.Push(this.selectPostChains.Pop());
7638 this.selectPostChains.Clear();
7639 for (int i = 0; i < 2000; i++)
7641 this.selectPostChains.Push(p.Pop());
7645 private bool GoStatus(long statusId)
7647 if (statusId == 0) return false;
7648 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7650 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType != MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7652 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7653 ListTab.SelectedIndex = tabidx;
7654 ListTabSelect(ListTab.TabPages[tabidx]);
7655 SelectListItem(_curList, idx);
7656 _curList.EnsureVisible(idx);
7663 private bool GoDirectMessage(long statusId)
7665 if (statusId == 0) return false;
7666 for (int tabidx = 0; tabidx < ListTab.TabCount; tabidx++)
7668 if (_statuses.Tabs[ListTab.TabPages[tabidx].Text].TabType == MyCommon.TabUsageType.DirectMessage && _statuses.Tabs[ListTab.TabPages[tabidx].Text].Contains(statusId))
7670 int idx = _statuses.Tabs[ListTab.TabPages[tabidx].Text].IndexOf(statusId);
7671 ListTab.SelectedIndex = tabidx;
7672 ListTabSelect(ListTab.TabPages[tabidx]);
7673 SelectListItem(_curList, idx);
7674 _curList.EnsureVisible(idx);
7681 private void MyList_MouseClick(object sender, MouseEventArgs e)
7683 _anchorFlag = false;
7686 private void StatusText_Enter(object sender, EventArgs e)
7688 // フォーカスの戻り先を StatusText に設定
7689 this.Tag = StatusText;
7690 StatusText.BackColor = _clInputBackcolor;
7693 public Color InputBackColor
7695 get { return _clInputBackcolor; }
7696 set { _clInputBackcolor = value; }
7699 private void StatusText_Leave(object sender, EventArgs e)
7701 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
7702 if (ListTab.SelectedTab != null && MenuStrip1.Tag == null) this.Tag = ListTab.SelectedTab.Tag;
7703 StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
7706 private void StatusText_KeyDown(object sender, KeyEventArgs e)
7708 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
7709 if (State == ModifierState.NotFlags) return;
7710 if (CommonKeyDown(e.KeyCode, FocusedControl.StatusText, State))
7713 e.SuppressKeyPress = true;
7716 this.StatusText_TextChanged(null, null);
7719 private void SaveConfigsAll(bool ifModified)
7723 SaveConfigsCommon();
7730 if (_modifySettingCommon) SaveConfigsCommon();
7731 if (_modifySettingLocal) SaveConfigsLocal();
7732 if (_modifySettingAtId) SaveConfigsAtId();
7736 private void SaveConfigsAtId()
7738 if (_ignoreConfigSave || !SettingDialog.UseAtIdSupplement && AtIdSupl == null) return;
7740 _modifySettingAtId = false;
7741 SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
7745 private void SaveConfigsCommon()
7747 if (_ignoreConfigSave) return;
7749 _modifySettingCommon = false;
7752 _cfgCommon.UserName = tw.Username;
7753 _cfgCommon.UserId = tw.UserId;
7754 _cfgCommon.Password = tw.Password;
7755 _cfgCommon.Token = tw.AccessToken;
7756 _cfgCommon.TokenSecret = tw.AccessTokenSecret;
7757 _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
7758 _cfgCommon.IconSize = SettingDialog.IconSz;
7759 _cfgCommon.UnreadManage = SettingDialog.UnreadManage;
7760 _cfgCommon.PlaySound = SettingDialog.PlaySound;
7761 _cfgCommon.OneWayLove = SettingDialog.OneWayLove;
7763 _cfgCommon.NameBalloon = SettingDialog.NameBalloon;
7764 _cfgCommon.PostCtrlEnter = SettingDialog.PostCtrlEnter;
7765 _cfgCommon.PostShiftEnter = SettingDialog.PostShiftEnter;
7766 _cfgCommon.CountApi = SettingDialog.CountApi;
7767 _cfgCommon.CountApiReply = SettingDialog.CountApiReply;
7768 _cfgCommon.DispUsername = SettingDialog.DispUsername;
7769 _cfgCommon.MinimizeToTray = SettingDialog.MinimizeToTray;
7770 _cfgCommon.CloseToExit = SettingDialog.CloseToExit;
7771 _cfgCommon.DispLatestPost = SettingDialog.DispLatestPost;
7772 _cfgCommon.SortOrderLock = SettingDialog.SortOrderLock;
7773 _cfgCommon.ViewTabBottom = SettingDialog.ViewTabBottom;
7774 _cfgCommon.TinyUrlResolve = SettingDialog.TinyUrlResolve;
7775 _cfgCommon.RestrictFavCheck = SettingDialog.RestrictFavCheck;
7776 _cfgCommon.AlwaysTop = SettingDialog.AlwaysTop;
7777 _cfgCommon.UrlConvertAuto = SettingDialog.UrlConvertAuto;
7778 _cfgCommon.UseUnreadStyle = SettingDialog.UseUnreadStyle;
7779 _cfgCommon.DateTimeFormat = SettingDialog.DateTimeFormat;
7780 _cfgCommon.DefaultTimeOut = SettingDialog.DefaultTimeOut;
7781 _cfgCommon.RetweetNoConfirm = SettingDialog.RetweetNoConfirm;
7782 _cfgCommon.LimitBalloon = SettingDialog.LimitBalloon;
7783 _cfgCommon.EventNotifyEnabled = SettingDialog.EventNotifyEnabled;
7784 _cfgCommon.EventNotifyFlag = SettingDialog.EventNotifyFlag;
7785 _cfgCommon.IsMyEventNotifyFlag = SettingDialog.IsMyEventNotifyFlag;
7786 _cfgCommon.ForceEventNotify = SettingDialog.ForceEventNotify;
7787 _cfgCommon.FavEventUnread = SettingDialog.FavEventUnread;
7788 _cfgCommon.TranslateLanguage = SettingDialog.TranslateLanguage;
7789 _cfgCommon.EventSoundFile = SettingDialog.EventSoundFile;
7790 _cfgCommon.AutoShortUrlFirst = SettingDialog.AutoShortUrlFirst;
7791 _cfgCommon.TabIconDisp = SettingDialog.TabIconDisp;
7792 _cfgCommon.ReplyIconState = SettingDialog.ReplyIconState;
7793 _cfgCommon.ReadOwnPost = SettingDialog.ReadOwnPost;
7794 _cfgCommon.IsMonospace = SettingDialog.IsMonospace;
7795 if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
7796 IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)
7798 _cfgCommon.WideSpaceConvert = this.IdeographicSpaceToSpaceToolStripMenuItem.Checked;
7800 _cfgCommon.ReadOldPosts = SettingDialog.ReadOldPosts;
7801 _cfgCommon.BilyUser = SettingDialog.BitlyUser;
7802 _cfgCommon.BitlyPwd = SettingDialog.BitlyPwd;
7803 _cfgCommon.ShowGrid = SettingDialog.ShowGrid;
7804 _cfgCommon.UseAtIdSupplement = SettingDialog.UseAtIdSupplement;
7805 _cfgCommon.UseHashSupplement = SettingDialog.UseHashSupplement;
7806 _cfgCommon.PreviewEnable = SettingDialog.PreviewEnable;
7807 _cfgCommon.StatusAreaAtBottom = SettingDialog.StatusAreaAtBottom;
7808 _cfgCommon.Language = SettingDialog.Language;
7810 _cfgCommon.SortOrder = (int)_statuses.SortOrder;
7811 switch (_statuses.SortMode)
7813 case IdComparerClass.ComparerMode.Nickname: //ニックネーム
7814 _cfgCommon.SortColumn = 1;
7816 case IdComparerClass.ComparerMode.Data: //本文
7817 _cfgCommon.SortColumn = 2;
7819 case IdComparerClass.ComparerMode.Id: //時刻=発言Id
7820 _cfgCommon.SortColumn = 3;
7822 case IdComparerClass.ComparerMode.Name: //名前
7823 _cfgCommon.SortColumn = 4;
7825 case IdComparerClass.ComparerMode.Source: //Source
7826 _cfgCommon.SortColumn = 7;
7830 _cfgCommon.Nicoms = SettingDialog.Nicoms;
7831 _cfgCommon.HashTags = HashMgr.HashHistories;
7832 if (HashMgr.IsPermanent)
7834 _cfgCommon.HashSelected = HashMgr.UseHash;
7838 _cfgCommon.HashSelected = "";
7840 _cfgCommon.HashIsHead = HashMgr.IsHead;
7841 _cfgCommon.HashIsPermanent = HashMgr.IsPermanent;
7842 _cfgCommon.HashIsNotAddToAtReply = HashMgr.IsNotAddToAtReply;
7843 _cfgCommon.TwitterUrl = SettingDialog.TwitterApiUrl;
7844 _cfgCommon.HotkeyEnabled = SettingDialog.HotkeyEnabled;
7845 _cfgCommon.HotkeyModifier = SettingDialog.HotkeyMod;
7846 _cfgCommon.HotkeyKey = SettingDialog.HotkeyKey;
7847 _cfgCommon.HotkeyValue = SettingDialog.HotkeyValue;
7848 _cfgCommon.BlinkNewMentions = SettingDialog.BlinkNewMentions;
7849 if (ToolStripFocusLockMenuItem != null &&
7850 ToolStripFocusLockMenuItem.IsDisposed == false)
7852 _cfgCommon.FocusLockToStatusText = this.ToolStripFocusLockMenuItem.Checked;
7854 _cfgCommon.UseAdditionalCount = SettingDialog.UseAdditionalCount;
7855 _cfgCommon.MoreCountApi = SettingDialog.MoreCountApi;
7856 _cfgCommon.FirstCountApi = SettingDialog.FirstCountApi;
7857 _cfgCommon.SearchCountApi = SettingDialog.SearchCountApi;
7858 _cfgCommon.FavoritesCountApi = SettingDialog.FavoritesCountApi;
7859 _cfgCommon.UserTimelineCountApi = SettingDialog.UserTimelineCountApi;
7860 _cfgCommon.TrackWord = tw.TrackWord;
7861 _cfgCommon.AllAtReply = tw.AllAtReply;
7862 _cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
7863 _cfgCommon.ListCountApi = SettingDialog.ListCountApi;
7864 _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
7865 _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
7866 _cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
7867 _cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
7868 _cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
7869 _cfgCommon.EnableImgAzyobuziNet = SettingDialog.EnableImgAzyobuziNet;
7870 _cfgCommon.ImgAzyobuziNetDisabledInDM = SettingDialog.ImgAzyobuziNetDisabledInDM;
7871 _cfgCommon.MapThumbnailProvider = SettingDialog.MapThumbnailProvider;
7872 _cfgCommon.MapThumbnailHeight = SettingDialog.MapThumbnailHeight;
7873 _cfgCommon.MapThumbnailWidth = SettingDialog.MapThumbnailWidth;
7874 _cfgCommon.MapThumbnailZoom = SettingDialog.MapThumbnailZoom;
7875 _cfgCommon.IsListsIncludeRts = SettingDialog.IsListStatusesIncludeRts;
7876 _cfgCommon.TabMouseLock = SettingDialog.TabMouseLock;
7877 _cfgCommon.IsRemoveSameEvent = SettingDialog.IsRemoveSameEvent;
7878 _cfgCommon.IsUseNotifyGrowl = SettingDialog.IsNotifyUseGrowl;
7884 private void SaveConfigsLocal()
7886 if (_ignoreConfigSave) return;
7889 _modifySettingLocal = false;
7890 _cfgLocal.FormSize = _mySize;
7891 _cfgLocal.FormLocation = _myLoc;
7892 _cfgLocal.SplitterDistance = _mySpDis;
7893 _cfgLocal.PreviewDistance = _mySpDis3;
7894 _cfgLocal.StatusMultiline = StatusText.Multiline;
7895 _cfgLocal.StatusTextHeight = _mySpDis2;
7896 _cfgLocal.StatusText = SettingDialog.Status;
7898 _cfgLocal.FontUnread = _fntUnread;
7899 _cfgLocal.ColorUnread = _clUnread;
7900 _cfgLocal.FontRead = _fntReaded;
7901 _cfgLocal.ColorRead = _clReaded;
7902 _cfgLocal.FontDetail = _fntDetail;
7903 _cfgLocal.ColorDetail = _clDetail;
7904 _cfgLocal.ColorDetailBackcolor = _clDetailBackcolor;
7905 _cfgLocal.ColorDetailLink = _clDetailLink;
7906 _cfgLocal.ColorFav = _clFav;
7907 _cfgLocal.ColorOWL = _clOWL;
7908 _cfgLocal.ColorRetweet = _clRetweet;
7909 _cfgLocal.ColorSelf = _clSelf;
7910 _cfgLocal.ColorAtSelf = _clAtSelf;
7911 _cfgLocal.ColorTarget = _clTarget;
7912 _cfgLocal.ColorAtTarget = _clAtTarget;
7913 _cfgLocal.ColorAtFromTarget = _clAtFromTarget;
7914 _cfgLocal.ColorAtTo = _clAtTo;
7915 _cfgLocal.ColorListBackcolor = _clListBackcolor;
7916 _cfgLocal.ColorInputBackcolor = _clInputBackcolor;
7917 _cfgLocal.ColorInputFont = _clInputFont;
7918 _cfgLocal.FontInputFont = _fntInputFont;
7920 _cfgLocal.BrowserPath = SettingDialog.BrowserPath;
7921 _cfgLocal.UseRecommendStatus = SettingDialog.UseRecommendStatus;
7922 _cfgLocal.ProxyType = SettingDialog.SelectedProxyType;
7923 _cfgLocal.ProxyAddress = SettingDialog.ProxyAddress;
7924 _cfgLocal.ProxyPort = SettingDialog.ProxyPort;
7925 _cfgLocal.ProxyUser = SettingDialog.ProxyUser;
7926 _cfgLocal.ProxyPassword = SettingDialog.ProxyPassword;
7927 if (_ignoreConfigSave) return;
7932 private void SaveConfigsTabs()
7934 SettingTabs tabSetting = new SettingTabs();
7935 for (int i = 0; i < ListTab.TabPages.Count; i++)
7937 if (_statuses.Tabs[ListTab.TabPages[i].Text].TabType != MyCommon.TabUsageType.Related) tabSetting.Tabs.Add(_statuses.Tabs[ListTab.TabPages[i].Text]);
7942 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7945 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out inputText);
7946 if (ret != DialogResult.OK)
7949 var match = Twitter.StatusUrlRegex.Match(inputText);
7952 MessageBox.Show(this, Properties.Resources.OpenURL_InvalidFormat,
7953 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7957 var statusId = long.Parse(match.Groups["StatusId"].Value);
7959 var post = this._statuses[statusId];
7964 post = await Task.Run(() =>
7966 PostClass newPost = null;
7968 var err = this.tw.GetStatusApi(false, statusId, ref newPost);
7969 if (!string.IsNullOrEmpty(err))
7970 throw new WebApiException(err);
7975 catch (WebApiException ex)
7977 var message = ex.Message;
7978 MessageBox.Show(this, string.Format(Properties.Resources.OpenURL_LoadFailed, message),
7979 Properties.Resources.OpenURL_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
7986 this.OpenRelatedTab(post);
7988 catch (TabException ex)
7990 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7994 private void SaveLogMenuItem_Click(object sender, EventArgs e)
7996 DialogResult rslt = MessageBox.Show(string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
7997 Properties.Resources.SaveLogMenuItem_ClickText2,
7998 MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
7999 if (rslt == DialogResult.Cancel) return;
8001 SaveFileDialog1.FileName = MyCommon.GetAssemblyName() + "Posts" + DateTime.Now.ToString("yyMMdd-HHmmss") + ".tsv";
8002 SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
8003 SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
8004 SaveFileDialog1.FilterIndex = 0;
8005 SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
8006 SaveFileDialog1.RestoreDirectory = true;
8008 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
8010 if (!SaveFileDialog1.ValidateNames) return;
8011 using (StreamWriter sw = new StreamWriter(SaveFileDialog1.FileName, false, Encoding.UTF8))
8013 if (rslt == DialogResult.Yes)
8016 for (int idx = 0; idx < _curList.VirtualListSize; idx++)
8018 PostClass post = _statuses[_curTab.Text, idx];
8019 string protect = "";
8020 if (post.IsProtect) protect = "Protect";
8021 sw.WriteLine(post.Nickname + "\t" +
8022 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8023 post.CreatedAt.ToString() + "\t" +
8024 post.ScreenName + "\t" +
8025 post.StatusId.ToString() + "\t" +
8026 post.ImageUrl + "\t" +
8027 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8033 foreach (int idx in _curList.SelectedIndices)
8035 PostClass post = _statuses[_curTab.Text, idx];
8036 string protect = "";
8037 if (post.IsProtect) protect = "Protect";
8038 sw.WriteLine(post.Nickname + "\t" +
8039 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8040 post.CreatedAt.ToString() + "\t" +
8041 post.ScreenName + "\t" +
8042 post.StatusId.ToString() + "\t" +
8043 post.ImageUrl + "\t" +
8044 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
8050 this.TopMost = SettingDialog.AlwaysTop;
8053 private void PostBrowser_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
8055 ModifierState State = GetModifierState(e.Control, e.Shift, e.Alt);
8056 if (State == ModifierState.NotFlags) return;
8057 bool KeyRes = CommonKeyDown(e.KeyCode, FocusedControl.PostBrowser, State);
8060 e.IsInputKey = true;
8063 public bool TabRename(ref string tabName)
8066 string newTabText = null;
8067 using (InputTabName inputName = new InputTabName())
8069 inputName.TabName = tabName;
8070 inputName.ShowDialog();
8071 if (inputName.DialogResult == DialogResult.Cancel) return false;
8072 newTabText = inputName.TabName;
8074 this.TopMost = SettingDialog.AlwaysTop;
8075 if (!string.IsNullOrEmpty(newTabText))
8078 for (int i = 0; i < ListTab.TabCount; i++)
8080 if (ListTab.TabPages[i].Text == newTabText)
8082 string tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabText);
8083 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8087 //タブ名のリスト作り直し(デフォルトタブ以外は再作成)
8088 for (int i = 0; i < ListTab.TabCount; i++)
8090 if (ListTab.TabPages[i].Text == tabName)
8092 ListTab.TabPages[i].Text = newTabText;
8095 _statuses.RenameTab(tabName, newTabText);
8097 for (int i = 0; i < ListTab.TabCount; i++)
8099 if (_statuses.IsDistributableTab(ListTab.TabPages[i].Text))
8101 if (ListTab.TabPages[i].Text == tabName)
8103 ListTab.TabPages[i].Text = newTabText;
8107 SaveConfigsCommon();
8109 _rclickTabName = newTabText;
8110 tabName = newTabText;
8119 private void ListTab_MouseClick(object sender, MouseEventArgs e)
8121 if (e.Button == MouseButtons.Middle)
8123 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
8125 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8127 this.RemoveSpecifiedTab(this.ListTab.TabPages[i].Text, true);
8128 this.SaveConfigsTabs();
8135 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
8137 string tn = ListTab.SelectedTab.Text;
8141 private void ListTab_MouseDown(object sender, MouseEventArgs e)
8143 if (SettingDialog.TabMouseLock) return;
8144 Point cpos = new Point(e.X, e.Y);
8145 if (e.Button == MouseButtons.Left)
8147 for (int i = 0; i < ListTab.TabPages.Count; i++)
8149 if (this.ListTab.GetTabRect(i).Contains(e.Location))
8152 _tabMouseDownPoint = e.Location;
8163 private void ListTab_DragEnter(object sender, DragEventArgs e)
8165 if (e.Data.GetDataPresent(typeof(TabPage)))
8166 e.Effect = DragDropEffects.Move;
8168 e.Effect = DragDropEffects.None;
8171 private void ListTab_DragDrop(object sender, DragEventArgs e)
8173 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
8178 Point cpos = new Point(e.X, e.Y);
8179 Point spos = ListTab.PointToClient(cpos);
8181 for (i = 0; i < ListTab.TabPages.Count; i++)
8183 Rectangle rect = ListTab.GetTabRect(i);
8184 if (rect.Left <= spos.X && spos.X <= rect.Right &&
8185 rect.Top <= spos.Y && spos.Y <= rect.Bottom)
8187 tn = ListTab.TabPages[i].Text;
8188 if (spos.X <= (rect.Left + rect.Right) / 2)
8197 //タブのないところにドロップ->最後尾へ移動
8198 if (string.IsNullOrEmpty(tn))
8200 tn = ListTab.TabPages[ListTab.TabPages.Count - 1].Text;
8202 i = ListTab.TabPages.Count - 1;
8205 TabPage tp = (TabPage)e.Data.GetData(typeof(TabPage));
8206 if (tp.Text == tn) return;
8208 ReOrderTab(tp.Text, tn, bef);
8211 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
8214 for (baseIndex = 0; baseIndex < ListTab.TabPages.Count; baseIndex++)
8216 if (ListTab.TabPages[baseIndex].Text == baseTabText) break;
8219 using (ControlTransaction.Layout(this.ListTab))
8222 for (int j = 0; j < ListTab.TabPages.Count; j++)
8224 if (ListTab.TabPages[j].Text == targetTabText)
8226 mTp = ListTab.TabPages[j];
8227 ListTab.TabPages.Remove(mTp);
8228 if (j < baseIndex) baseIndex -= 1;
8232 if (isBeforeBaseTab)
8233 ListTab.TabPages.Insert(baseIndex, mTp);
8235 ListTab.TabPages.Insert(baseIndex + 1, mTp);
8241 private void MakeReplyOrDirectStatus(bool isAuto = true, bool isReply = true, bool isAll = false)
8243 //isAuto:true=先頭に挿入、false=カーソル位置に挿入
8244 //isReply:true=@,false=DM
8245 if (!StatusText.Enabled) return;
8246 if (_curList == null) return;
8247 if (_curTab == null) return;
8248 if (!this.ExistCurrentPost) return;
8250 // 複数あてリプライはReplyではなく通常ポスト
8251 //↑仕様変更で全部リプライ扱いでOK(先頭ドット付加しない)
8252 //090403暫定でドットを付加しないようにだけ修正。単独と複数の処理は統合できると思われる。
8253 //090513 all @ replies 廃止の仕様変更によりドット付加に戻し(syo68k)
8255 if (_curList.SelectedIndices.Count > 0)
8258 if (_curList.SelectedIndices.Count == 1 && !isAll && this.ExistCurrentPost)
8261 if ((_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && isAuto) || (!isAuto && !isReply))
8264 StatusText.Text = "D " + _curPost.ScreenName + " " + StatusText.Text;
8265 StatusText.SelectionStart = StatusText.Text.Length;
8267 _reply_to_id = null;
8268 _reply_to_name = null;
8271 if (string.IsNullOrEmpty(StatusText.Text))
8275 // ステータステキストが入力されていない場合先頭に@ユーザー名を追加する
8276 StatusText.Text = "@" + _curPost.ScreenName + " ";
8277 if (_curPost.RetweetedId != null)
8279 _reply_to_id = _curPost.RetweetedId.Value;
8283 _reply_to_id = _curPost.StatusId;
8285 _reply_to_name = _curPost.ScreenName;
8293 //1件選んでEnter or DoubleClick
8294 if (StatusText.Text.Contains("@" + _curPost.ScreenName + " "))
8296 if (_reply_to_id != null && _reply_to_name == _curPost.ScreenName)
8299 if (_curPost.RetweetedId != null)
8301 _reply_to_id = _curPost.RetweetedId.Value;
8305 _reply_to_id = _curPost.StatusId;
8307 _reply_to_name = _curPost.ScreenName;
8311 if (!StatusText.Text.StartsWith("@"))
8314 if (StatusText.Text.StartsWith(". "))
8317 StatusText.Text = StatusText.Text.Insert(2, "@" + _curPost.ScreenName + " ");
8318 _reply_to_id = null;
8319 _reply_to_name = null;
8324 StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8325 if (_curPost.RetweetedId != null)
8327 _reply_to_id = _curPost.RetweetedId.Value;
8331 _reply_to_id = _curPost.StatusId;
8333 _reply_to_name = _curPost.ScreenName;
8340 StatusText.Text = ". @" + _curPost.ScreenName + " " + StatusText.Text;
8341 //StatusText.Text = "@" + _curPost.ScreenName + " " + StatusText.Text;
8342 _reply_to_id = null;
8343 _reply_to_name = null;
8348 //1件選んでCtrl-Rの場合(返信先操作せず)
8349 int sidx = StatusText.SelectionStart;
8350 string id = "@" + _curPost.ScreenName + " ";
8353 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8358 StatusText.Text = StatusText.Text.Insert(sidx, id);
8360 //if (StatusText.Text.StartsWith("@"))
8363 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8364 // sidx += 5 + _curPost.ScreenName.Length;
8369 // StatusText.Text = StatusText.Text.Insert(sidx, " @" + _curPost.ScreenName + " ");
8370 // sidx += 3 + _curPost.ScreenName.Length;
8372 StatusText.SelectionStart = sidx;
8375 //_reply_to_name = null;
8383 if (!isAuto && !isReply) return;
8385 //C-S-rか、複数の宛先を選択中にEnter/DoubleClick/C-r/C-S-r
8389 //Enter or DoubleClick
8391 string sTxt = StatusText.Text;
8392 if (!sTxt.StartsWith(". "))
8395 _reply_to_id = null;
8396 _reply_to_name = null;
8398 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8400 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8401 if (!sTxt.Contains("@" + post.ScreenName + " "))
8403 sTxt = sTxt.Insert(2, "@" + post.ScreenName + " ");
8404 //sTxt = "@" + post.ScreenName + " " + sTxt;
8407 StatusText.Text = sTxt;
8412 if (_curList.SelectedIndices.Count > 1)
8417 int sidx = StatusText.SelectionStart;
8418 for (int cnt = 0; cnt < _curList.SelectedIndices.Count; cnt++)
8420 PostClass post = _statuses[_curTab.Text, _curList.SelectedIndices[cnt]];
8421 if (!ids.Contains("@" + post.ScreenName + " ") &&
8422 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8424 ids += "@" + post.ScreenName + " ";
8428 foreach (string nm in post.ReplyToList)
8430 if (!ids.Contains("@" + nm + " ") &&
8431 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8433 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8435 ids += "@" + m.Result("${id}") + " ";
8437 ids += "@" + nm + " ";
8442 if (ids.Length == 0) return;
8443 if (!StatusText.Text.StartsWith(". "))
8445 StatusText.Text = ". " + StatusText.Text;
8447 _reply_to_id = null;
8448 _reply_to_name = null;
8452 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8457 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8459 //if (StatusText.Text.StartsWith("@"))
8461 // StatusText.Text = ". " + StatusText.Text.Insert(sidx, ids);
8462 // sidx += 2 + ids.Length;
8466 // StatusText.Text = StatusText.Text.Insert(sidx, ids);
8467 // sidx += 1 + ids.Length;
8469 StatusText.SelectionStart = sidx;
8475 //1件のみ選択のC-S-r(返信元付加する可能性あり)
8478 int sidx = StatusText.SelectionStart;
8479 PostClass post = _curPost;
8480 if (!ids.Contains("@" + post.ScreenName + " ") &&
8481 !post.ScreenName.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8483 ids += "@" + post.ScreenName + " ";
8485 foreach (string nm in post.ReplyToList)
8487 if (!ids.Contains("@" + nm + " ") &&
8488 !nm.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8490 Match m = Regex.Match(post.TextFromApi, "[@@](?<id>" + nm + ")([^a-zA-Z0-9]|$)", RegexOptions.IgnoreCase);
8492 ids += "@" + m.Result("${id}") + " ";
8494 ids += "@" + nm + " ";
8497 if (!string.IsNullOrEmpty(post.RetweetedBy))
8499 if (!ids.Contains("@" + post.RetweetedBy + " ") &&
8500 !post.RetweetedBy.Equals(tw.Username, StringComparison.CurrentCultureIgnoreCase))
8502 ids += "@" + post.RetweetedBy + " ";
8505 if (ids.Length == 0) return;
8506 if (string.IsNullOrEmpty(StatusText.Text))
8509 StatusText.Text = ids;
8510 StatusText.SelectionStart = ids.Length;
8512 if (post.RetweetedId != null)
8514 _reply_to_id = post.RetweetedId.Value;
8518 _reply_to_id = post.StatusId;
8520 _reply_to_name = post.ScreenName;
8526 if (StatusText.Text.Substring(sidx - 1, 1) != " ")
8531 StatusText.Text = StatusText.Text.Insert(sidx, ids);
8533 StatusText.SelectionStart = sidx;
8539 StatusText.SelectionStart = StatusText.Text.Length;
8544 private void ListTab_MouseUp(object sender, MouseEventArgs e)
8549 private static int iconCnt = 0;
8550 private static int blinkCnt = 0;
8551 private static bool blink = false;
8552 private static bool idle = false;
8554 private void RefreshTasktrayIcon(bool forceRefresh)
8556 if (_colorize) Colorize();
8557 if (!TimerRefreshIcon.Enabled) return;
8558 //Static usCheckCnt As int = 0
8560 //Static iconDlListTopItem As ListViewItem = null
8562 if (forceRefresh) idle = false;
8564 //if (((ListView)ListTab.SelectedTab.Tag).TopItem == iconDlListTopItem)
8565 // ((ImageDictionary)this.TIconDic).PauseGetImage = false;
8567 // ((ImageDictionary)this.TIconDic).PauseGetImage = true;
8569 //iconDlListTopItem = ((ListView)ListTab.SelectedTab.Tag).TopItem;
8575 //if (usCheckCnt > 300) //1min
8578 // if (!this.IsReceivedUserStream)
8580 // TraceOut("ReconnectUserStream");
8581 // tw.ReconnectUserStream();
8586 foreach (BackgroundWorker bw in this._bw)
8588 if (bw != null && bw.IsBusy)
8603 SaveConfigsAll(true);
8608 NotifyIcon1.Icon = NIconRefresh[iconCnt];
8610 _myStatusError = false;
8614 TabClass tb = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
8615 if (SettingDialog.ReplyIconState != MyCommon.REPLY_ICONSTATE.None && tb != null && tb.UnreadCount > 0)
8617 if (blinkCnt > 0) return;
8619 if (blink || SettingDialog.ReplyIconState == MyCommon.REPLY_ICONSTATE.StaticIcon)
8621 NotifyIcon1.Icon = ReplyIcon;
8625 NotifyIcon1.Icon = ReplyIconBlink;
8633 //優先度:エラー→オフライン→アイドル
8637 NotifyIcon1.Icon = NIconAtRed;
8640 if (_myStatusOnline)
8642 NotifyIcon1.Icon = NIconAt;
8646 NotifyIcon1.Icon = NIconAtSmoke;
8650 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
8653 this.RefreshTasktrayIcon(false);
8656 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
8658 //右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
8659 if (string.IsNullOrEmpty(_rclickTabName) || sender != ContextMenuTabProperty)
8661 if (ListTab != null && ListTab.SelectedTab != null)
8662 _rclickTabName = ListTab.SelectedTab.Text;
8667 if (_statuses == null) return;
8668 if (_statuses.Tabs == null) return;
8670 TabClass tb = _statuses.Tabs[_rclickTabName];
8671 if (tb == null) return;
8673 NotifyDispMenuItem.Checked = tb.Notify;
8674 this.NotifyTbMenuItem.Checked = tb.Notify;
8676 soundfileListup = true;
8677 SoundFileComboBox.Items.Clear();
8678 this.SoundFileTbComboBox.Items.Clear();
8679 SoundFileComboBox.Items.Add("");
8680 this.SoundFileTbComboBox.Items.Add("");
8681 DirectoryInfo oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
8682 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
8684 oDir = oDir.GetDirectories("Sounds")[0];
8686 foreach (FileInfo oFile in oDir.GetFiles("*.wav"))
8688 SoundFileComboBox.Items.Add(oFile.Name);
8689 this.SoundFileTbComboBox.Items.Add(oFile.Name);
8691 int idx = SoundFileComboBox.Items.IndexOf(tb.SoundFile);
8692 if (idx == -1) idx = 0;
8693 SoundFileComboBox.SelectedIndex = idx;
8694 this.SoundFileTbComboBox.SelectedIndex = idx;
8695 soundfileListup = false;
8696 UreadManageMenuItem.Checked = tb.UnreadManage;
8697 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
8699 TabMenuControl(_rclickTabName);
8702 private void TabMenuControl(string tabName)
8704 this.FilterEditMenuItem.Enabled = true;
8705 this.EditRuleTbMenuItem.Enabled = true;
8707 if (_statuses.IsDefaultTab(tabName))
8709 this.ProtectTabMenuItem.Enabled = false;
8710 this.ProtectTbMenuItem.Enabled = false;
8714 this.ProtectTabMenuItem.Enabled = true;
8715 this.ProtectTbMenuItem.Enabled = true;
8718 if (_statuses.IsDefaultTab(tabName) || _statuses.Tabs[tabName].Protected)
8720 this.ProtectTabMenuItem.Checked = true;
8721 this.ProtectTbMenuItem.Checked = true;
8722 this.DeleteTabMenuItem.Enabled = false;
8723 this.DeleteTbMenuItem.Enabled = false;
8727 this.ProtectTabMenuItem.Checked = false;
8728 this.ProtectTbMenuItem.Checked = false;
8729 this.DeleteTabMenuItem.Enabled = true;
8730 this.DeleteTbMenuItem.Enabled = true;
8734 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
8736 var checkState = ((ToolStripMenuItem)sender).Checked;
8739 this.ProtectTbMenuItem.Checked = checkState;
8740 this.ProtectTabMenuItem.Checked = checkState;
8743 this.DeleteTabMenuItem.Enabled = !checkState;
8744 this.DeleteTbMenuItem.Enabled = !checkState;
8746 if (string.IsNullOrEmpty(_rclickTabName)) return;
8747 _statuses.Tabs[_rclickTabName].Protected = checkState;
8752 private void UreadManageMenuItem_Click(object sender, EventArgs e)
8754 UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8755 this.UnreadMngTbMenuItem.Checked = UreadManageMenuItem.Checked;
8757 if (string.IsNullOrEmpty(_rclickTabName)) return;
8758 ChangeTabUnreadManage(_rclickTabName, UreadManageMenuItem.Checked);
8763 public void ChangeTabUnreadManage(string tabName, bool isManage)
8766 for (idx = 0; idx < ListTab.TabCount; idx++)
8768 if (ListTab.TabPages[idx].Text == tabName) break;
8771 _statuses.SetTabUnreadManage(tabName, isManage);
8772 if (SettingDialog.TabIconDisp)
8774 if (_statuses.Tabs[tabName].UnreadCount > 0)
8775 ListTab.TabPages[idx].ImageIndex = 0;
8777 ListTab.TabPages[idx].ImageIndex = -1;
8780 if (_curTab.Text == tabName)
8782 this.PurgeListViewItemCache();
8786 SetMainWindowTitle();
8787 SetStatusLabelUrl();
8788 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
8791 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
8793 NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8794 this.NotifyTbMenuItem.Checked = NotifyDispMenuItem.Checked;
8796 if (string.IsNullOrEmpty(_rclickTabName)) return;
8798 _statuses.Tabs[_rclickTabName].Notify = NotifyDispMenuItem.Checked;
8803 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
8805 if (soundfileListup || string.IsNullOrEmpty(_rclickTabName)) return;
8807 _statuses.Tabs[_rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
8812 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
8814 if (string.IsNullOrEmpty(_rclickTabName) || sender == this.DeleteTbMenuItem) _rclickTabName = ListTab.SelectedTab.Text;
8816 RemoveSpecifiedTab(_rclickTabName, true);
8820 private void FilterEditMenuItem_Click(object sender, EventArgs e)
8822 if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
8823 fltDialog.SetCurrent(_rclickTabName);
8824 fltDialog.ShowDialog(this);
8825 this.TopMost = SettingDialog.AlwaysTop;
8827 this.ApplyPostFilters();
8831 private void AddTabMenuItem_Click(object sender, EventArgs e)
8833 string tabName = null;
8834 MyCommon.TabUsageType tabUsage;
8835 using (InputTabName inputName = new InputTabName())
8837 inputName.TabName = _statuses.GetUniqueTabName();
8838 inputName.IsShowUsage = true;
8839 inputName.ShowDialog();
8840 if (inputName.DialogResult == DialogResult.Cancel) return;
8841 tabName = inputName.TabName;
8842 tabUsage = inputName.Usage;
8844 this.TopMost = SettingDialog.AlwaysTop;
8845 if (!string.IsNullOrEmpty(tabName))
8848 ListElement list = null;
8849 if (tabUsage == MyCommon.TabUsageType.Lists)
8851 using (ListAvailable listAvail = new ListAvailable())
8853 if (listAvail.ShowDialog(this) == DialogResult.Cancel) return;
8854 if (listAvail.SelectedList == null) return;
8855 list = listAvail.SelectedList;
8858 if (!_statuses.AddTab(tabName, tabUsage, list) || !AddNewTab(tabName, false, tabUsage, list))
8860 string tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
8861 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8867 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
8869 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8870 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8871 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
8873 if (tabUsage == MyCommon.TabUsageType.Lists)
8875 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
8876 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
8877 GetTimeline(MyCommon.WORKERTYPE.List, 1, tabName);
8883 private void TabMenuItem_Click(object sender, EventArgs e)
8886 foreach (int idx in _curList.SelectedIndices)
8890 if (!SelectTab(out tabName)) return;
8892 fltDialog.SetCurrent(tabName);
8893 if (_statuses[_curTab.Text, idx].RetweetedId == null)
8895 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].ScreenName, _statuses[_curTab.Text, idx].TextFromApi);
8899 fltDialog.AddNewFilter(_statuses[_curTab.Text, idx].RetweetedBy, _statuses[_curTab.Text, idx].TextFromApi);
8901 fltDialog.ShowDialog(this);
8902 this.TopMost = SettingDialog.AlwaysTop;
8905 this.ApplyPostFilters();
8907 if (this.ListTab.SelectedTab != null &&
8908 ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices.Count > 0)
8910 _curPost = _statuses[this.ListTab.SelectedTab.Text, ((DetailsListView)this.ListTab.SelectedTab.Tag).SelectedIndices[0]];
8914 protected override bool ProcessDialogKey(Keys keyData)
8916 //TextBox1でEnterを押してもビープ音が鳴らないようにする
8917 if ((keyData & Keys.KeyCode) == Keys.Enter)
8919 if (StatusText.Focused)
8921 bool _NewLine = false;
8924 if (SettingDialog.PostCtrlEnter) //Ctrl+Enter投稿時
8926 if (StatusText.Multiline)
8928 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8930 if ((keyData & Keys.Control) == Keys.Control) _Post = true;
8934 if (((keyData & Keys.Control) == Keys.Control)) _Post = true;
8938 else if (SettingDialog.PostShiftEnter) //SHift+Enter投稿時
8940 if (StatusText.Multiline)
8942 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) _NewLine = true;
8944 if ((keyData & Keys.Shift) == Keys.Shift) _Post = true;
8948 if (((keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8954 if (StatusText.Multiline)
8956 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) _NewLine = true;
8958 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
8959 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) _Post = true;
8963 if (((keyData & Keys.Shift) == Keys.Shift) ||
8964 (((keyData & Keys.Control) != Keys.Control) &&
8965 ((keyData & Keys.Shift) != Keys.Shift))) _Post = true;
8971 int pos1 = StatusText.SelectionStart;
8972 if (StatusText.SelectionLength > 0)
8974 StatusText.Text = StatusText.Text.Remove(pos1, StatusText.SelectionLength); //選択状態文字列削除
8976 StatusText.Text = StatusText.Text.Insert(pos1, Environment.NewLine); //改行挿入
8977 StatusText.SelectionStart = pos1 + Environment.NewLine.Length; //カーソルを改行の次の文字へ移動
8982 PostButton_Click(null, null);
8986 else if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch &&
8987 (ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focused ||
8988 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboLang"].Focused))
8990 this.SearchButton_Click(ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"], null);
8995 return base.ProcessDialogKey(keyData);
8998 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
9000 MakeReplyOrDirectStatus(false, true, true);
9003 private void IDRuleMenuItem_Click(object sender, EventArgs e)
9008 if (_curList.SelectedIndices.Count == 0) return;
9011 if (!SelectTab(out tabName)) return;
9015 MoveOrCopy(ref mv, ref mk);
9017 List<string> ids = new List<string>();
9018 foreach (int idx in _curList.SelectedIndices)
9020 PostClass post = _statuses[_curTab.Text, idx];
9021 if (!ids.Contains(post.ScreenName))
9023 PostFilterRule fc = new PostFilterRule();
9024 ids.Add(post.ScreenName);
9025 if (post.RetweetedId == null)
9027 fc.FilterName = post.ScreenName;
9031 fc.FilterName = post.RetweetedBy;
9033 fc.UseNameField = true;
9034 fc.MoveMatches = mv;
9035 fc.MarkMatches = mk;
9036 fc.UseRegex = false;
9037 fc.FilterByUrl = false;
9038 _statuses.Tabs[tabName].AddFilter(fc);
9043 List<string> atids = new List<string>();
9044 foreach (string id in ids)
9046 atids.Add("@" + id);
9048 int cnt = AtIdSupl.ItemCount;
9049 AtIdSupl.AddRangeItem(atids.ToArray());
9050 if (AtIdSupl.ItemCount != cnt) _modifySettingAtId = true;
9053 this.ApplyPostFilters();
9057 private bool SelectTab(out string tabName)
9064 using (var dialog = new TabsDialog(_statuses))
9066 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
9068 var selectedTab = dialog.SelectedTab;
9069 tabName = selectedTab == null ? null : selectedTab.TabName;
9072 ListTab.SelectedTab.Focus();
9074 if (tabName == null)
9076 using (InputTabName inputName = new InputTabName())
9078 inputName.TabName = _statuses.GetUniqueTabName();
9079 inputName.ShowDialog();
9080 if (inputName.DialogResult == DialogResult.Cancel) return false;
9081 tabName = inputName.TabName;
9083 this.TopMost = SettingDialog.AlwaysTop;
9084 if (!string.IsNullOrEmpty(tabName))
9086 if (!_statuses.AddTab(tabName, MyCommon.TabUsageType.UserDefined, null) || !AddNewTab(tabName, false, MyCommon.TabUsageType.UserDefined))
9088 string tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
9089 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
9107 private void MoveOrCopy(ref bool move, ref bool mark)
9111 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
9112 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9120 string _tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
9121 if (MessageBox.Show(_tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
9127 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
9132 private void CopyURLMenuItem_Click(object sender, EventArgs e)
9137 private void SelectAllMenuItem_Click(object sender, EventArgs e)
9139 if (StatusText.Focused)
9142 StatusText.SelectAll();
9146 // ListView上でのCtrl+A
9147 for (int i = 0; i < _curList.VirtualListSize; i++)
9149 _curList.SelectedIndices.Add(i);
9154 private void MoveMiddle()
9160 if (_curList.SelectedIndices.Count == 0) return;
9162 int idx = _curList.SelectedIndices[0];
9164 _item = _curList.GetItemAt(0, 25);
9170 _item = _curList.GetItemAt(0, _curList.ClientSize.Height - 1);
9172 idx2 = _curList.VirtualListSize - 1;
9176 idx -= Math.Abs(idx1 - idx2) / 2;
9177 if (idx < 0) idx = 0;
9179 _curList.EnsureVisible(_curList.VirtualListSize - 1);
9180 _curList.EnsureVisible(idx);
9183 private void OpenURLMenuItem_Click(object sender, EventArgs e)
9185 if (PostBrowser.Document.Links.Count > 0)
9187 UrlDialog.ClearUrl();
9189 string openUrlStr = "";
9191 if (PostBrowser.Document.Links.Count == 1)
9196 urlStr = MyCommon.IDNEncode(PostBrowser.Document.Links[0].GetAttribute("href"));
9198 catch (ArgumentException)
9207 if (string.IsNullOrEmpty(urlStr)) return;
9208 openUrlStr = MyCommon.urlEncodeMultibyteChar(urlStr);
9212 foreach (HtmlElement linkElm in PostBrowser.Document.Links)
9215 string linkText = "";
9219 urlStr = linkElm.GetAttribute("title");
9220 href = MyCommon.IDNEncode(linkElm.GetAttribute("href"));
9221 if (string.IsNullOrEmpty(urlStr)) urlStr = href;
9222 linkText = linkElm.InnerText;
9223 if (!linkText.StartsWith("http") && !linkText.StartsWith("#") && !linkText.Contains("."))
9225 linkText = "@" + linkText;
9228 catch (ArgumentException)
9237 if (string.IsNullOrEmpty(urlStr)) continue;
9238 UrlDialog.AddUrl(new OpenUrlItem(linkText, MyCommon.urlEncodeMultibyteChar(urlStr), href));
9242 if (UrlDialog.ShowDialog() == DialogResult.OK)
9244 openUrlStr = UrlDialog.SelectedUrl;
9251 this.TopMost = SettingDialog.AlwaysTop;
9253 if (string.IsNullOrEmpty(openUrlStr)) return;
9255 if (openUrlStr.StartsWith("http://twitter.com/search?q=") ||
9256 openUrlStr.StartsWith("https://twitter.com/search?q="))
9259 string urlStr = Uri.UnescapeDataString(openUrlStr);
9260 string hash = urlStr.Substring(urlStr.IndexOf("#"));
9261 HashSupl.AddItem(hash);
9262 HashMgr.AddHashToHistory(hash.Trim(), false);
9263 AddNewTabForSearch(hash);
9268 Match m = Regex.Match(openUrlStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9269 if (SettingDialog.OpenUserTimeline && m.Success && IsTwitterId(m.Result("${ScreenName}")))
9270 this.AddNewTabForUserTimeline(m.Result("${ScreenName}"));
9272 OpenUriAsync(openUrlStr);
9278 private void ClearTabMenuItem_Click(object sender, EventArgs e)
9280 if (string.IsNullOrEmpty(_rclickTabName)) return;
9281 ClearTab(_rclickTabName, true);
9284 private void ClearTab(string tabName, bool showWarning)
9288 string tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
9289 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9295 _statuses.ClearTabIds(tabName);
9296 if (ListTab.SelectedTab.Text == tabName)
9299 _anchorFlag = false;
9300 this.PurgeListViewItemCache();
9304 foreach (TabPage tb in ListTab.TabPages)
9306 if (tb.Text == tabName)
9309 ((DetailsListView)tb.Tag).VirtualListSize = 0;
9313 if (!SettingDialog.TabIconDisp) ListTab.Refresh();
9315 SetMainWindowTitle();
9316 SetStatusLabelUrl();
9319 private static long followers = 0;
9321 private void SetMainWindowTitle()
9324 StringBuilder ttl = new StringBuilder(256);
9327 if (SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.None &&
9328 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Post &&
9329 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
9330 SettingDialog.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
9332 foreach (var tab in _statuses.Tabs.Values)
9334 ur += tab.UnreadCount;
9339 if (SettingDialog.DispUsername) ttl.Append(tw.Username).Append(" - ");
9340 ttl.Append(Application.ProductName);
9342 switch (SettingDialog.DispLatestPost)
9344 case MyCommon.DispTitleEnum.Ver:
9345 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
9347 case MyCommon.DispTitleEnum.Post:
9348 if (_history != null && _history.Count > 1)
9349 ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
9351 case MyCommon.DispTitleEnum.UnreadRepCount:
9352 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9354 case MyCommon.DispTitleEnum.UnreadAllCount:
9355 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
9357 case MyCommon.DispTitleEnum.UnreadAllRepCount:
9358 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
9360 case MyCommon.DispTitleEnum.UnreadCountAllCount:
9361 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
9363 case MyCommon.DispTitleEnum.OwnStatus:
9364 if (followers == 0 && tw.FollowersCount > 0) followers = tw.FollowersCount;
9365 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, tw.StatusesCount, tw.FriendsCount, tw.FollowersCount, tw.FollowersCount - followers);
9371 this.Text = ttl.ToString();
9373 catch (AccessViolationException)
9375 //原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
9379 private string GetStatusLabelText()
9382 //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
9383 if (_statuses == null) return "";
9384 TabClass tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
9385 TabClass tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
9386 if (tbRep == null || tbDm == null) return "";
9387 int urat = tbRep.UnreadCount + tbDm.UnreadCount;
9392 StringBuilder slbl = new StringBuilder(256);
9395 foreach (var tab in _statuses.Tabs.Values)
9397 ur += tab.UnreadCount;
9399 if (_curTab != null && tab.TabName.Equals(_curTab.Text))
9401 tur = tab.UnreadCount;
9412 UnreadAtCounter = urat;
9414 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, _tlCount);
9415 if (this._cfgCommon.TimelinePeriod == 0)
9417 slbl.Append(Properties.Resources.SetStatusLabelText2);
9421 slbl.Append(this._cfgCommon.TimelinePeriod + Properties.Resources.SetStatusLabelText3);
9423 return slbl.ToString();
9426 private void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
9430 if (this.InvokeRequired && !this.IsDisposed)
9432 this.Invoke((MethodInvoker)(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e)));
9436 var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
9437 if (endpointName == "/statuses/home_timeline" || endpointName == null)
9439 this._apiGauge.ApiLimit = MyCommon.TwitterApiInfo.AccessLimit["/statuses/home_timeline"];
9443 catch (ObjectDisposedException)
9447 catch (InvalidOperationException)
9453 private void SetStatusLabelUrl()
9455 StatusLabelUrl.Text = GetStatusLabelText();
9458 public void SetStatusLabel(string text)
9460 StatusLabel.Text = text;
9463 private static StringBuilder ur = new StringBuilder(64);
9465 private void SetNotifyIconText()
9467 // タスクトレイアイコンのツールチップテキスト書き換え
9469 ur.Remove(0, ur.Length);
9470 if (SettingDialog.DispUsername)
9472 ur.Append(tw.Username);
9475 ur.Append(Application.ProductName);
9477 ur.Append("(Debug Build)");
9479 if (UnreadCounter != -1 && UnreadAtCounter != -1)
9482 ur.Append(UnreadCounter);
9484 ur.Append(UnreadAtCounter);
9487 NotifyIcon1.Text = ur.ToString();
9490 internal void CheckReplyTo(string StatusText)
9494 m = Regex.Matches(StatusText, Twitter.HASHTAG, RegexOptions.IgnoreCase);
9496 foreach (Match hm in m)
9498 if (!hstr.Contains("#" + hm.Result("$3") + " "))
9500 hstr += "#" + hm.Result("$3") + " ";
9501 HashSupl.AddItem("#" + hm.Result("$3"));
9504 if (!string.IsNullOrEmpty(HashMgr.UseHash) && !hstr.Contains(HashMgr.UseHash + " "))
9506 hstr += HashMgr.UseHash;
9508 if (!string.IsNullOrEmpty(hstr)) HashMgr.AddHashToHistory(hstr.Trim(), false);
9510 // 本当にリプライ先指定すべきかどうかの判定
9511 m = Regex.Matches(StatusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
9513 if (SettingDialog.UseAtIdSupplement)
9515 int bCnt = AtIdSupl.ItemCount;
9516 foreach (Match mid in m)
9518 AtIdSupl.AddItem(mid.Result("${id}"));
9520 if (bCnt != AtIdSupl.ItemCount) _modifySettingAtId = true;
9523 // リプライ先ステータスIDの指定がない場合は指定しない
9524 if (_reply_to_id == null) return;
9526 // リプライ先ユーザー名がない場合も指定しない
9527 if (string.IsNullOrEmpty(_reply_to_name))
9529 _reply_to_id = null;
9534 // 次の条件を満たす場合に in_reply_to_status_id 指定
9535 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
9536 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
9537 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
9541 if (StatusText.StartsWith("@"))
9543 if (StatusText.StartsWith("@" + _reply_to_name)) return;
9547 foreach (Match mid in m)
9549 if (StatusText.Contains("QT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + _reply_to_name) return;
9554 _reply_to_id = null;
9555 _reply_to_name = null;
9559 private void TweenMain_Resize(object sender, EventArgs e)
9561 if (!_initialLayout && SettingDialog.MinimizeToTray && WindowState == FormWindowState.Minimized)
9563 this.Visible = false;
9565 if (_initialLayout && _cfgLocal != null && this.WindowState == FormWindowState.Normal && this.Visible)
9567 this.ClientSize = _cfgLocal.FormSize;
9568 //_mySize = this.ClientSize; //サイズ保持(最小化・最大化されたまま終了した場合の対応用)
9569 this.DesktopLocation = _cfgLocal.FormLocation;
9570 //_myLoc = this.DesktopLocation; //位置保持(最小化・最大化されたまま終了した場合の対応用)
9571 if (_cfgLocal.SplitterDistance > this.SplitContainer1.Panel1MinSize &&
9572 _cfgLocal.SplitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
9574 this.SplitContainer1.SplitterDistance = _cfgLocal.SplitterDistance; //Splitterの位置設定
9577 StatusText.Multiline = _cfgLocal.StatusMultiline;
9578 if (StatusText.Multiline)
9580 int dis = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9581 if (dis > SplitContainer2.Panel1MinSize && dis < SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth)
9583 SplitContainer2.SplitterDistance = SplitContainer2.Height - _cfgLocal.StatusTextHeight - SplitContainer2.SplitterWidth;
9585 StatusText.Height = _cfgLocal.StatusTextHeight;
9589 if (SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth > 0)
9591 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9594 if (_cfgLocal.PreviewDistance > this.SplitContainer3.Panel1MinSize && _cfgLocal.PreviewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
9596 this.SplitContainer3.SplitterDistance = _cfgLocal.PreviewDistance;
9598 _initialLayout = false;
9600 if (this.WindowState != FormWindowState.Minimized)
9602 _formWindowState = this.WindowState;
9606 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
9608 PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
9609 this.PlaySoundFileMenuItem.Checked = PlaySoundMenuItem.Checked;
9610 if (PlaySoundMenuItem.Checked)
9612 SettingDialog.PlaySound = true;
9616 SettingDialog.PlaySound = false;
9618 _modifySettingCommon = true;
9621 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
9623 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
9625 _mySpDis = SplitContainer1.SplitterDistance;
9626 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
9627 _modifySettingLocal = true;
9631 private void doRepliedStatusOpen()
9633 if (this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)
9635 if (MyCommon.IsKeyDown(Keys.Shift))
9637 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9640 if (_statuses.ContainsKey(_curPost.InReplyToStatusId.Value))
9642 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9643 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9647 foreach (TabClass tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
9649 if (tb == null || !tb.Contains(_curPost.InReplyToStatusId.Value)) break;
9650 PostClass repPost = _statuses[_curPost.InReplyToStatusId.Value];
9651 MessageBox.Show(repPost.ScreenName + " / " + repPost.Nickname + " (" + repPost.CreatedAt.ToString() + ")" + Environment.NewLine + repPost.TextFromApi);
9654 OpenUriAsync(MyCommon.GetStatusUrl(_curPost.InReplyToUser, _curPost.InReplyToStatusId.Value));
9659 private void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
9661 doRepliedStatusOpen();
9665 /// UserPicture.Image に設定されている画像を破棄します。
9667 private void ClearUserPicture()
9669 if (this.UserPicture.Image != null)
9671 var oldImage = this.UserPicture.Image;
9672 this.UserPicture.Image = null;
9677 private void ContextMenuUserPicture_Opening(object sender, CancelEventArgs e)
9679 //発言詳細のアイコン右クリック時のメニュー制御
9680 if (_curList.SelectedIndices.Count > 0 && _curPost != null)
9682 string name = _curPost.ImageUrl;
9683 if (name != null && name.Length > 0)
9685 int idx = name.LastIndexOf('/');
9688 name = Path.GetFileName(name.Substring(idx));
9689 if (name.Contains("_normal.") || name.EndsWith("_normal"))
9691 name = name.Replace("_normal", "");
9692 this.IconNameToolStripMenuItem.Text = name;
9693 this.IconNameToolStripMenuItem.Enabled = true;
9697 this.IconNameToolStripMenuItem.Enabled = false;
9698 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9703 this.IconNameToolStripMenuItem.Enabled = false;
9704 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9707 this.ReloadIconToolStripMenuItem.Enabled = true;
9709 if (this.IconCache.TryGetFromCache(_curPost.ImageUrl) != null)
9711 this.SaveIconPictureToolStripMenuItem.Enabled = true;
9715 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9720 this.IconNameToolStripMenuItem.Enabled = false;
9721 this.ReloadIconToolStripMenuItem.Enabled = false;
9722 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9723 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText1;
9728 this.IconNameToolStripMenuItem.Enabled = false;
9729 this.ReloadIconToolStripMenuItem.Enabled = false;
9730 this.SaveIconPictureToolStripMenuItem.Enabled = false;
9731 this.IconNameToolStripMenuItem.Text = Properties.Resources.ContextMenuStrip3_OpeningText2;
9733 if (NameLabel.Tag != null)
9735 string id = (string)NameLabel.Tag;
9736 if (id == tw.Username)
9738 FollowToolStripMenuItem.Enabled = false;
9739 UnFollowToolStripMenuItem.Enabled = false;
9740 ShowFriendShipToolStripMenuItem.Enabled = false;
9741 ShowUserStatusToolStripMenuItem.Enabled = true;
9742 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9743 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9744 ListManageUserContextToolStripMenuItem3.Enabled = true;
9748 FollowToolStripMenuItem.Enabled = true;
9749 UnFollowToolStripMenuItem.Enabled = true;
9750 ShowFriendShipToolStripMenuItem.Enabled = true;
9751 ShowUserStatusToolStripMenuItem.Enabled = true;
9752 SearchPostsDetailNameToolStripMenuItem.Enabled = true;
9753 SearchAtPostsDetailNameToolStripMenuItem.Enabled = true;
9754 ListManageUserContextToolStripMenuItem3.Enabled = true;
9759 FollowToolStripMenuItem.Enabled = false;
9760 UnFollowToolStripMenuItem.Enabled = false;
9761 ShowFriendShipToolStripMenuItem.Enabled = false;
9762 ShowUserStatusToolStripMenuItem.Enabled = false;
9763 SearchPostsDetailNameToolStripMenuItem.Enabled = false;
9764 SearchAtPostsDetailNameToolStripMenuItem.Enabled = false;
9765 ListManageUserContextToolStripMenuItem3.Enabled = false;
9769 private void IconNameToolStripMenuItem_Click(object sender, EventArgs e)
9771 if (_curPost == null) return;
9772 string name = _curPost.ImageUrl;
9773 OpenUriAsync(name.Remove(name.LastIndexOf("_normal"), 7)); // "_normal".Length
9776 private async void ReloadIconToolStripMenuItem_Click(object sender, EventArgs e)
9778 if (this._curPost == null) return;
9780 await this.UserPicture.SetImageFromTask(async () =>
9782 var imageUrl = this._curPost.ImageUrl;
9784 var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
9785 .ConfigureAwait(false);
9787 return await image.CloneAsync()
9788 .ConfigureAwait(false);
9792 private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9794 if (_curPost == null) return;
9795 string name = _curPost.ImageUrl;
9796 name = Path.GetFileNameWithoutExtension(name.Substring(name.LastIndexOf('/')));
9798 this.SaveFileDialog1.FileName = name.Substring(0, name.Length - 8); // "_normal".Length + 1
9800 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9806 private void SaveIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
9808 if (_curPost == null) return;
9809 string name = _curPost.ImageUrl;
9811 this.SaveFileDialog1.FileName = name.Substring(name.LastIndexOf('/') + 1);
9813 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
9817 using (Image orgBmp = new Bitmap(IconCache.TryGetFromCache(name).Image))
9819 using (Bitmap bmp2 = new Bitmap(orgBmp.Size.Width, orgBmp.Size.Height))
9821 using (Graphics g = Graphics.FromImage(bmp2))
9823 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
9824 g.DrawImage(orgBmp, 0, 0, orgBmp.Size.Width, orgBmp.Size.Height);
9826 bmp2.Save(this.SaveFileDialog1.FileName);
9832 //処理中にキャッシュアウトする可能性あり
9837 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
9839 this.StatusText.Multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
9840 MultiLineMenuItem.Checked = this.StatusText.Multiline;
9841 _modifySettingLocal = true;
9844 private void StatusText_MultilineChanged(object sender, EventArgs e)
9846 if (this.StatusText.Multiline)
9847 this.StatusText.ScrollBars = ScrollBars.Vertical;
9849 this.StatusText.ScrollBars = ScrollBars.None;
9851 _modifySettingLocal = true;
9854 private void MultiLineMenuItem_Click(object sender, EventArgs e)
9857 StatusText.Multiline = MultiLineMenuItem.Checked;
9858 _cfgLocal.StatusMultiline = MultiLineMenuItem.Checked;
9859 if (MultiLineMenuItem.Checked)
9861 if (SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth < 0)
9862 SplitContainer2.SplitterDistance = 0;
9864 SplitContainer2.SplitterDistance = SplitContainer2.Height - _mySpDis2 - SplitContainer2.SplitterWidth;
9868 SplitContainer2.SplitterDistance = SplitContainer2.Height - SplitContainer2.Panel2MinSize - SplitContainer2.SplitterWidth;
9870 _modifySettingLocal = true;
9873 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter Converter_Type)
9875 //t.coで投稿時自動短縮する場合は、外部サービスでの短縮禁止
9876 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco) return;
9878 //Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
9879 //参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
9880 //Appendix A. Collected ABNF for URI
9881 //http://www.ietf.org/rfc/rfc3986.txt
9885 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
9887 if (StatusText.SelectionLength > 0)
9889 string tmp = StatusText.SelectedText;
9890 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
9891 if (tmp.StartsWith("http"))
9893 // 文字列が選択されている場合はその文字列について処理
9895 //nico.ms使用、nicovideoにマッチしたら変換
9896 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9898 result = nicoms.Shorten(tmp);
9900 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9902 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9905 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9906 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9907 result = resultUri.ToString();
9909 catch (WebApiException e)
9911 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9914 catch (UriFormatException e)
9916 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9925 if (!string.IsNullOrEmpty(result))
9927 urlUndo undotmp = new urlUndo();
9929 StatusText.Select(StatusText.Text.IndexOf(tmp, StringComparison.Ordinal), tmp.Length);
9930 StatusText.SelectedText = result;
9933 undotmp.Before = tmp;
9934 undotmp.After = result;
9936 if (urlUndoBuffer == null)
9938 urlUndoBuffer = new List<urlUndo>();
9939 UrlUndoToolStripMenuItem.Enabled = true;
9942 urlUndoBuffer.Add(undotmp);
9948 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
9949 @"(?<url>(?<protocol>https?://)" +
9950 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
9951 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
9952 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
9953 // 正規表現にマッチしたURL文字列をtinyurl化
9954 foreach (Match mt in Regex.Matches(StatusText.Text, url, RegexOptions.IgnoreCase))
9956 if (StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1) continue;
9957 string tmp = mt.Result("${url}");
9958 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase)) tmp = "http://" + tmp;
9959 urlUndo undotmp = new urlUndo();
9962 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
9964 //nico.ms使用、nicovideoにマッチしたら変換
9965 if (SettingDialog.Nicoms && Regex.IsMatch(tmp, nico))
9967 result = nicoms.Shorten(tmp);
9969 else if (Converter_Type != MyCommon.UrlConverter.Nicoms)
9971 //短縮URL変換 日本語を含むかもしれないのでURLエンコードする
9974 var srcUri = new Uri(MyCommon.urlEncodeMultibyteChar(tmp));
9975 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
9976 result = resultUri.ToString();
9978 catch (HttpRequestException e)
9980 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
9981 // のように長いので「:」が含まれていればそれ以降のみを抽出する
9982 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
9984 this.StatusLabel.Text = Converter_Type + ":" + message;
9987 catch (WebApiException e)
9989 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
9992 catch (UriFormatException e)
9994 this.StatusLabel.Text = Converter_Type + ":" + e.Message;
10003 if (!string.IsNullOrEmpty(result))
10005 StatusText.Select(StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
10006 StatusText.SelectedText = result;
10008 undotmp.Before = mt.Result("${url}");
10009 undotmp.After = result;
10011 if (urlUndoBuffer == null)
10013 urlUndoBuffer = new List<urlUndo>();
10014 UrlUndoToolStripMenuItem.Enabled = true;
10017 urlUndoBuffer.Add(undotmp);
10025 private void doUrlUndo()
10027 if (urlUndoBuffer != null)
10029 string tmp = StatusText.Text;
10030 foreach (urlUndo data in urlUndoBuffer)
10032 tmp = tmp.Replace(data.After, data.Before);
10034 StatusText.Text = tmp;
10035 urlUndoBuffer = null;
10036 UrlUndoToolStripMenuItem.Enabled = false;
10037 StatusText.SelectionStart = 0;
10038 StatusText.SelectionLength = 0;
10042 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
10044 await UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
10047 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
10049 await UrlConvertAsync(MyCommon.UrlConverter.Isgd);
10052 private async void TwurlnlToolStripMenuItem_Click(object sender, EventArgs e)
10054 await UrlConvertAsync(MyCommon.UrlConverter.Twurl);
10057 private async void UxnuMenuItem_Click(object sender, EventArgs e)
10059 await UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
10062 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
10064 if (!await UrlConvertAsync(SettingDialog.AutoShortUrlFirst))
10066 MyCommon.UrlConverter svc = SettingDialog.AutoShortUrlFirst;
10067 Random rnd = new Random();
10068 // 前回使用した短縮URLサービス以外を選択する
10071 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
10073 while (svc == SettingDialog.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
10074 await UrlConvertAsync(svc);
10078 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
10083 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
10085 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10086 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
10087 _cfgCommon.NewAllPop = NewPostPopMenuItem.Checked;
10088 _modifySettingCommon = true;
10091 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
10093 ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
10094 this.LockListFileMenuItem.Checked = ListLockMenuItem.Checked;
10095 _cfgCommon.ListLock = ListLockMenuItem.Checked;
10096 _modifySettingCommon = true;
10099 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
10101 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
10102 MenuStrip1.Tag = new Object();
10103 MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
10106 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
10108 if (this.Tag != null) // 設定された戻り先へ遷移
10110 if (this.Tag == this.ListTab.SelectedTab)
10111 ((Control)this.ListTab.SelectedTab.Tag).Select();
10113 ((Control)this.Tag).Select();
10115 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
10117 if (ListTab.SelectedIndex > -1 && ListTab.SelectedTab.HasChildren)
10119 this.Tag = ListTab.SelectedTab.Tag;
10120 ((Control)this.Tag).Select();
10123 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
10124 MenuStrip1.Tag = null;
10127 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
10129 DetailsListView lst = (DetailsListView)sender;
10130 if (_cfgLocal == null) return;
10134 _cfgLocal.Width1 = lst.Columns[0].Width;
10135 _cfgLocal.Width3 = lst.Columns[1].Width;
10139 int[] darr = new int[lst.Columns.Count];
10140 for (int i = 0; i < lst.Columns.Count; i++)
10142 darr[lst.Columns[i].DisplayIndex] = i;
10144 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
10146 for (int i = 0; i < lst.Columns.Count; i++)
10151 _cfgLocal.DisplayIndex1 = i;
10154 _cfgLocal.DisplayIndex2 = i;
10157 _cfgLocal.DisplayIndex3 = i;
10160 _cfgLocal.DisplayIndex4 = i;
10163 _cfgLocal.DisplayIndex5 = i;
10166 _cfgLocal.DisplayIndex6 = i;
10169 _cfgLocal.DisplayIndex7 = i;
10172 _cfgLocal.DisplayIndex8 = i;
10176 _cfgLocal.Width1 = lst.Columns[0].Width;
10177 _cfgLocal.Width2 = lst.Columns[1].Width;
10178 _cfgLocal.Width3 = lst.Columns[2].Width;
10179 _cfgLocal.Width4 = lst.Columns[3].Width;
10180 _cfgLocal.Width5 = lst.Columns[4].Width;
10181 _cfgLocal.Width6 = lst.Columns[5].Width;
10182 _cfgLocal.Width7 = lst.Columns[6].Width;
10183 _cfgLocal.Width8 = lst.Columns[7].Width;
10185 _modifySettingLocal = true;
10186 _isColumnChanged = true;
10189 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
10191 DetailsListView lst = (DetailsListView)sender;
10192 if (_cfgLocal == null) return;
10195 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10197 _cfgLocal.Width1 = lst.Columns[0].Width;
10198 _modifySettingLocal = true;
10199 _isColumnChanged = true;
10201 if (_cfgLocal.Width3 != lst.Columns[1].Width)
10203 _cfgLocal.Width3 = lst.Columns[1].Width;
10204 _modifySettingLocal = true;
10205 _isColumnChanged = true;
10210 if (_cfgLocal.Width1 != lst.Columns[0].Width)
10212 _cfgLocal.Width1 = lst.Columns[0].Width;
10213 _modifySettingLocal = true;
10214 _isColumnChanged = true;
10216 if (_cfgLocal.Width2 != lst.Columns[1].Width)
10218 _cfgLocal.Width2 = lst.Columns[1].Width;
10219 _modifySettingLocal = true;
10220 _isColumnChanged = true;
10222 if (_cfgLocal.Width3 != lst.Columns[2].Width)
10224 _cfgLocal.Width3 = lst.Columns[2].Width;
10225 _modifySettingLocal = true;
10226 _isColumnChanged = true;
10228 if (_cfgLocal.Width4 != lst.Columns[3].Width)
10230 _cfgLocal.Width4 = lst.Columns[3].Width;
10231 _modifySettingLocal = true;
10232 _isColumnChanged = true;
10234 if (_cfgLocal.Width5 != lst.Columns[4].Width)
10236 _cfgLocal.Width5 = lst.Columns[4].Width;
10237 _modifySettingLocal = true;
10238 _isColumnChanged = true;
10240 if (_cfgLocal.Width6 != lst.Columns[5].Width)
10242 _cfgLocal.Width6 = lst.Columns[5].Width;
10243 _modifySettingLocal = true;
10244 _isColumnChanged = true;
10246 if (_cfgLocal.Width7 != lst.Columns[6].Width)
10248 _cfgLocal.Width7 = lst.Columns[6].Width;
10249 _modifySettingLocal = true;
10250 _isColumnChanged = true;
10252 if (_cfgLocal.Width8 != lst.Columns[7].Width)
10254 _cfgLocal.Width8 = lst.Columns[7].Width;
10255 _modifySettingLocal = true;
10256 _isColumnChanged = true;
10259 // 非表示の時にColumnChangedが呼ばれた場合はForm初期化処理中なので保存しない
10262 // SaveConfigsLocal();
10266 public string WebBrowser_GetSelectionText(ref WebBrowser ComponentInstance)
10268 //発言詳細で「選択文字列をコピー」を行う
10269 //WebBrowserコンポーネントのインスタンスを渡す
10270 Type typ = ComponentInstance.ActiveXInstance.GetType();
10271 object _SelObj = typ.InvokeMember("selection", BindingFlags.GetProperty, null, ComponentInstance.Document.DomDocument, null);
10272 object _objRange = _SelObj.GetType().InvokeMember("createRange", BindingFlags.InvokeMethod, null, _SelObj, null);
10273 return (string)_objRange.GetType().InvokeMember("text", BindingFlags.GetProperty, null, _objRange, null);
10276 private void SelectionCopyContextMenuItem_Click(object sender, EventArgs e)
10279 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10282 Clipboard.SetDataObject(_selText, false, 5, 100);
10284 catch (Exception ex)
10286 MessageBox.Show(ex.Message);
10290 private void doSearchToolStrip(string url)
10292 //発言詳細で「選択文字列で検索」(選択文字列取得)
10293 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10295 if (_selText != null)
10297 if (url == Properties.Resources.SearchItem4Url)
10300 AddNewTabForSearch(_selText);
10304 string tmp = string.Format(url, Uri.EscapeUriString(_selText));
10309 private void SelectionAllContextMenuItem_Click(object sender, EventArgs e)
10312 PostBrowser.Document.ExecCommand("SelectAll", false, null);
10315 private void SearchWikipediaContextMenuItem_Click(object sender, EventArgs e)
10317 doSearchToolStrip(Properties.Resources.SearchItem1Url);
10320 private void SearchGoogleContextMenuItem_Click(object sender, EventArgs e)
10322 doSearchToolStrip(Properties.Resources.SearchItem2Url);
10325 private void SearchPublicSearchContextMenuItem_Click(object sender, EventArgs e)
10327 doSearchToolStrip(Properties.Resources.SearchItem4Url);
10330 private void UrlCopyContextMenuItem_Click(object sender, EventArgs e)
10334 MatchCollection mc = Regex.Matches(this.PostBrowser.DocumentText, @"<a[^>]*href=""(?<url>" + this._postBrowserStatusText.Replace(".", @"\.") + @")""[^>]*title=""(?<title>https?://[^""]+)""", RegexOptions.IgnoreCase);
10335 foreach (Match m in mc)
10337 if (m.Groups["url"].Value == this._postBrowserStatusText)
10339 Clipboard.SetDataObject(m.Groups["title"].Value, false, 5, 100);
10345 Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10347 //Clipboard.SetDataObject(this._postBrowserStatusText, false, 5, 100);
10349 catch (Exception ex)
10351 MessageBox.Show(ex.Message);
10355 private void ContextMenuPostBrowser_Opening(object ender, CancelEventArgs e)
10357 // URLコピーの項目の表示/非表示
10358 if (PostBrowser.StatusText.StartsWith("http"))
10360 this._postBrowserStatusText = PostBrowser.StatusText;
10361 string name = GetUserId();
10362 UrlCopyContextMenuItem.Enabled = true;
10365 FollowContextMenuItem.Enabled = true;
10366 RemoveContextMenuItem.Enabled = true;
10367 FriendshipContextMenuItem.Enabled = true;
10368 ShowUserStatusContextMenuItem.Enabled = true;
10369 SearchPostsDetailToolStripMenuItem.Enabled = true;
10370 IdFilterAddMenuItem.Enabled = true;
10371 ListManageUserContextToolStripMenuItem.Enabled = true;
10372 SearchAtPostsDetailToolStripMenuItem.Enabled = true;
10376 FollowContextMenuItem.Enabled = false;
10377 RemoveContextMenuItem.Enabled = false;
10378 FriendshipContextMenuItem.Enabled = false;
10379 ShowUserStatusContextMenuItem.Enabled = false;
10380 SearchPostsDetailToolStripMenuItem.Enabled = false;
10381 IdFilterAddMenuItem.Enabled = false;
10382 ListManageUserContextToolStripMenuItem.Enabled = false;
10383 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10386 if (Regex.IsMatch(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23"))
10387 UseHashtagMenuItem.Enabled = true;
10389 UseHashtagMenuItem.Enabled = false;
10393 this._postBrowserStatusText = "";
10394 UrlCopyContextMenuItem.Enabled = false;
10395 FollowContextMenuItem.Enabled = false;
10396 RemoveContextMenuItem.Enabled = false;
10397 FriendshipContextMenuItem.Enabled = false;
10398 ShowUserStatusContextMenuItem.Enabled = false;
10399 SearchPostsDetailToolStripMenuItem.Enabled = false;
10400 SearchAtPostsDetailToolStripMenuItem.Enabled = false;
10401 UseHashtagMenuItem.Enabled = false;
10402 IdFilterAddMenuItem.Enabled = false;
10403 ListManageUserContextToolStripMenuItem.Enabled = false;
10405 // 文字列選択されていないときは選択文字列関係の項目を非表示に
10406 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10407 if (_selText == null)
10409 SelectionSearchContextMenuItem.Enabled = false;
10410 SelectionCopyContextMenuItem.Enabled = false;
10411 SelectionTranslationToolStripMenuItem.Enabled = false;
10415 SelectionSearchContextMenuItem.Enabled = true;
10416 SelectionCopyContextMenuItem.Enabled = true;
10417 SelectionTranslationToolStripMenuItem.Enabled = true;
10419 //発言内に自分以外のユーザーが含まれてればフォロー状態全表示を有効に
10420 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
10421 bool fAllFlag = false;
10422 foreach (Match mu in ma)
10424 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
10430 this.FriendshipAllMenuItem.Enabled = fAllFlag;
10432 if (_curPost == null)
10433 TranslationToolStripMenuItem.Enabled = false;
10435 TranslationToolStripMenuItem.Enabled = true;
10440 private void CurrentTabToolStripMenuItem_Click(object sender, EventArgs e)
10442 //発言詳細の選択文字列で現在のタブを検索
10443 string _selText = WebBrowser_GetSelectionText(ref PostBrowser);
10445 if (_selText != null)
10447 var searchOptions = new SearchWordDialog.SearchOptions(
10448 SearchWordDialog.SearchType.Timeline,
10451 caseSensitive: false,
10454 this.SearchDialog.ResultOptions = searchOptions;
10457 searchOptions.Query,
10458 searchOptions.CaseSensitive,
10459 searchOptions.UseRegex,
10460 SEARCHTYPE.NextSearch);
10464 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
10466 if (StatusText.Multiline) _mySpDis2 = StatusText.Height;
10467 _modifySettingLocal = true;
10470 private void TweenMain_DragDrop(object sender, DragEventArgs e)
10472 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10474 SelectMedia_DragDrop(e);
10476 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10478 var url = GetUrlFromDataObject(e.Data);
10481 if (url.Item2 == null)
10482 appendText = url.Item1;
10484 appendText = url.Item2 + " " + url.Item1;
10486 if (this.StatusText.TextLength == 0)
10487 this.StatusText.Text = appendText;
10489 this.StatusText.Text += " " + appendText;
10491 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10493 string data = (string)e.Data.GetData(DataFormats.StringFormat, true);
10494 if (data != null) StatusText.Text += data;
10499 /// IDataObject から URL とタイトルの対を取得します
10502 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
10504 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
10505 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
10506 internal static Tuple<string, string> GetUrlFromDataObject(IDataObject data)
10508 if (data.GetDataPresent("text/x-moz-url"))
10510 // Firefox, Google Chrome で利用可能
10511 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
10513 using (var stream = (MemoryStream)data.GetData("text/x-moz-url"))
10515 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
10516 if (lines.Length < 2)
10517 throw new ArgumentException("不正な text/x-moz-url フォーマットです", "data");
10519 return new Tuple<string, string>(lines[0], lines[1]);
10522 else if (data.GetDataPresent("IESiteModeToUrl"))
10524 // Internet Exproler 用
10525 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
10527 using (var stream = (MemoryStream)data.GetData("IESiteModeToUrl"))
10529 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
10530 if (lines.Length < 2)
10531 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", "data");
10533 return new Tuple<string, string>(lines[0], lines[1]);
10536 else if (data.GetDataPresent("UniformResourceLocatorW"))
10540 using (var stream = (MemoryStream)data.GetData("UniformResourceLocatorW"))
10542 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
10543 return new Tuple<string, string>(url, null);
10547 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
10550 private void TweenMain_DragEnter(object sender, DragEventArgs e)
10552 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10554 SelectMedia_DragEnter(e);
10558 private void TweenMain_DragOver(object sender, DragEventArgs e)
10560 if (e.Data.GetDataPresent(DataFormats.FileDrop))
10562 SelectMedia_DragOver(e);
10564 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
10566 e.Effect = DragDropEffects.Copy;
10568 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
10570 e.Effect = DragDropEffects.Copy;
10574 e.Effect = DragDropEffects.None;
10578 public bool IsNetworkAvailable()
10581 nw = MyCommon.IsNetworkAvailable();
10582 _myStatusOnline = nw;
10586 public Task OpenUriAsync(string UriString)
10588 return Task.Run(() =>
10590 string myPath = UriString;
10594 var configBrowserPath = SettingDialog.BrowserPath;
10595 if (!string.IsNullOrEmpty(configBrowserPath))
10597 if (configBrowserPath.StartsWith("\"") && configBrowserPath.Length > 2 && configBrowserPath.IndexOf("\"", 2) > -1)
10599 int sep = configBrowserPath.IndexOf("\"", 2);
10600 string browserPath = configBrowserPath.Substring(1, sep - 1);
10602 if (sep < configBrowserPath.Length - 1)
10604 arg = configBrowserPath.Substring(sep + 1);
10606 myPath = arg + " " + myPath;
10607 System.Diagnostics.Process.Start(browserPath, myPath);
10611 System.Diagnostics.Process.Start(configBrowserPath, myPath);
10616 System.Diagnostics.Process.Start(myPath);
10621 //MessageBox.Show("ブラウザの起動に失敗、またはタイムアウトしました。" + ex.ToString());
10626 private void ListTabSelect(TabPage _tab)
10630 this.PurgeListViewItemCache();
10633 _curList = (DetailsListView)_tab.Tag;
10634 if (_curList.SelectedIndices.Count > 0)
10636 _curItemIndex = _curList.SelectedIndices[0];
10637 _curPost = GetCurTabPost(_curItemIndex);
10641 _curItemIndex = -1;
10645 _anchorPost = null;
10646 _anchorFlag = false;
10650 ((DetailsListView)_tab.Tag).Columns[1].Text = ColumnText[2];
10654 for (int i = 0; i < _curList.Columns.Count; i++)
10656 ((DetailsListView)_tab.Tag).Columns[i].Text = ColumnText[i];
10661 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
10663 ListTabSelect(e.TabPage);
10666 private void SelectListItem(DetailsListView LView, int Index)
10669 Rectangle bnd = new Rectangle();
10671 var item = LView.FocusedItem;
10680 LView.SelectedIndices.Clear();
10682 while (LView.SelectedIndices.Count > 0);
10683 item = LView.Items[Index];
10684 item.Selected = true;
10685 item.Focused = true;
10687 if (flg) LView.Invalidate(bnd);
10690 private void SelectListItem(DetailsListView LView , int[] Index, int[] FocusedIndex)
10693 Rectangle bnd = new Rectangle();
10695 var item = LView.FocusedItem;
10703 if (Index != null && !(Index.Length == 1 && Index[0] == -1))
10707 LView.SelectedIndices.Clear();
10709 while (LView.SelectedIndices.Count > 0);
10710 foreach (int idx in Index)
10712 if (idx > -1 && LView.VirtualListSize > idx)
10714 LView.SelectedIndices.Add(idx);
10715 if (fIdx == -1) fIdx = idx;
10719 if (FocusedIndex[1] > -1 && LView.VirtualListSize > FocusedIndex[1])
10721 LView.SelectionMark = FocusedIndex[1];
10723 if (FocusedIndex[0] > -1 && LView.VirtualListSize > FocusedIndex[0])
10725 LView.Items[FocusedIndex[0]].Focused = true;
10727 else if (fIdx > -1)
10729 LView.Items[fIdx].Focused = true;
10732 if (flg) LView.Invalidate(bnd);
10735 private void RunAsync(GetWorkerArg args)
10737 BackgroundWorker bw = null;
10738 if (args.type != MyCommon.WORKERTYPE.Follower)
10740 for (int i = 0; i < _bw.Length; i++)
10742 if (_bw[i] != null && !_bw[i].IsBusy)
10750 for (int i = 0; i < _bw.Length; i++)
10752 if (_bw[i] == null)
10754 _bw[i] = new BackgroundWorker();
10756 bw.WorkerReportsProgress = true;
10757 bw.WorkerSupportsCancellation = true;
10758 bw.DoWork += GetTimelineWorker_DoWork;
10759 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10760 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10768 if (_bwFollower == null)
10770 _bwFollower = new BackgroundWorker();
10772 bw.WorkerReportsProgress = true;
10773 bw.WorkerSupportsCancellation = true;
10774 bw.DoWork += GetTimelineWorker_DoWork;
10775 bw.ProgressChanged += GetTimelineWorker_ProgressChanged;
10776 bw.RunWorkerCompleted += GetTimelineWorker_RunWorkerCompleted;
10780 if (_bwFollower.IsBusy == false)
10784 if (bw == null) return;
10786 bw.RunWorkerAsync(args);
10789 private void StartUserStream()
10791 tw.NewPostFromStream += tw_NewPostFromStream;
10792 tw.UserStreamStarted += tw_UserStreamStarted;
10793 tw.UserStreamStopped += tw_UserStreamStopped;
10794 tw.PostDeleted += tw_PostDeleted;
10795 tw.UserStreamEventReceived += tw_UserStreamEventArrived;
10797 MenuItemUserStream.Text = "&UserStream ■";
10798 MenuItemUserStream.Enabled = true;
10799 StopToolStripMenuItem.Text = "&Start";
10800 StopToolStripMenuItem.Enabled = true;
10801 if (this._cfgCommon.UserstreamStartup) tw.StartUserStream();
10804 private async void TweenMain_Shown(object sender, EventArgs e)
10808 PostBrowser.Url = new Uri("about:blank");
10809 PostBrowser.DocumentText = ""; //発言詳細部初期化
10815 NotifyIcon1.Visible = true;
10817 if (this.IsNetworkAvailable())
10819 this.RefreshMuteUserIdsAsync();
10820 GetTimeline(MyCommon.WORKERTYPE.BlockIds, 0, "");
10821 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10822 if (this._cfgCommon.StartupFollowers)
10824 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10826 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10828 _waitTimeline = true;
10829 GetTimeline(MyCommon.WORKERTYPE.Timeline, 1, "");
10831 GetTimeline(MyCommon.WORKERTYPE.Reply, 1, "");
10833 GetTimeline(MyCommon.WORKERTYPE.DirectMessegeRcv, 1, "");
10834 if (this._cfgCommon.GetFav)
10837 GetTimeline(MyCommon.WORKERTYPE.Favorites, 1, "");
10839 _waitPubSearch = true;
10840 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, ""); //tabname="":全タブ
10841 _waitUserTimeline = true;
10842 GetTimeline(MyCommon.WORKERTYPE.UserTimeline, 1, ""); //tabname="":全タブ
10844 GetTimeline(MyCommon.WORKERTYPE.List, 1, ""); //tabname="":全タブ
10847 while (this.IsInitialRead())
10849 await Task.Delay(5000);
10852 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
10854 if (MyCommon._endingFlag)
10858 if (MyCommon._endingFlag) return;
10860 if (ApplicationSettings.VersionInfoUrl != null)
10862 //バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
10863 if (this._cfgCommon.StartupVersion)
10864 await this.CheckNewVersion(true);
10868 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
10869 this.VerUpMenuItem.Enabled = false;
10870 this.VerUpMenuItem.Available = false;
10871 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
10875 if (!tw.GetFollowersSuccess && this._cfgCommon.StartupFollowers)
10876 GetTimeline(MyCommon.WORKERTYPE.Follower, 0, "");
10879 if (!tw.GetNoRetweetSuccess)
10880 GetTimeline(MyCommon.WORKERTYPE.NoRetweetIds, 0, "");
10883 if (SettingDialog.TwitterConfiguration.PhotoSizeLimit == 0)
10884 GetTimeline(MyCommon.WORKERTYPE.Configuration, 0, "");
10886 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
10887 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
10889 MessageBox.Show(Properties.Resources.ReAuthorizeText);
10890 SettingStripMenuItem_Click(null, null);
10897 TimerTimeline.Enabled = true;
10900 private bool IsInitialRead()
10902 return _waitTimeline || _waitReply || _waitDm || _waitFav || _waitPubSearch || _waitUserTimeline || _waitLists;
10905 private void doGetFollowersMenu()
10907 GetTimeline(MyCommon.WORKERTYPE.Follower, 1, "");
10908 DispSelectedPost(true);
10911 private void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
10913 doGetFollowersMenu();
10916 private void doReTweetUnofficial()
10919 if (this.ExistCurrentPost)
10921 if (_curPost.IsDm ||
10922 !StatusText.Enabled) return;
10924 if (_curPost.IsProtect)
10926 MessageBox.Show("Protected.");
10929 string rtdata = _curPost.Text;
10930 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
10932 this._reply_to_id = null;
10933 this._reply_to_name = null;
10935 StatusText.Text = "RT @" + _curPost.ScreenName + ": " + rtdata;
10937 StatusText.SelectionStart = 0;
10938 StatusText.Focus();
10942 private void ReTweetStripMenuItem_Click(object sender, EventArgs e)
10944 doReTweetUnofficial();
10947 private void doReTweetOfficial(bool isConfirm)
10950 if (this.ExistCurrentPost)
10952 if (_curPost.IsProtect)
10954 MessageBox.Show("Protected.");
10955 _DoFavRetweetFlags = false;
10958 if (_curList.SelectedIndices.Count > 15)
10960 MessageBox.Show(Properties.Resources.RetweetLimitText);
10961 _DoFavRetweetFlags = false;
10964 else if (_curList.SelectedIndices.Count > 1)
10966 string QuestionText = Properties.Resources.RetweetQuestion2;
10967 if (_DoFavRetweetFlags) QuestionText = Properties.Resources.FavoriteRetweetQuestionText1;
10968 switch (MessageBox.Show(QuestionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
10970 case DialogResult.Cancel:
10971 case DialogResult.No:
10972 _DoFavRetweetFlags = false;
10978 if (_curPost.IsDm || _curPost.IsMe)
10980 _DoFavRetweetFlags = false;
10983 if (!SettingDialog.RetweetNoConfirm)
10985 string Questiontext = Properties.Resources.RetweetQuestion1;
10986 if (_DoFavRetweetFlags) Questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
10987 if (isConfirm && MessageBox.Show(Questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
10989 _DoFavRetweetFlags = false;
10994 GetWorkerArg args = new GetWorkerArg();
10995 args.ids = new List<long>();
10996 args.sIds = new List<long>();
10997 args.tName = _curTab.Text;
10998 args.type = MyCommon.WORKERTYPE.Retweet;
10999 foreach (int idx in _curList.SelectedIndices)
11001 PostClass post = GetCurTabPost(idx);
11002 if (!post.IsMe && !post.IsProtect && !post.IsDm) args.ids.Add(post.StatusId);
11008 private void ReTweetOriginalStripMenuItem_Click(object sender, EventArgs e)
11010 doReTweetOfficial(true);
11013 private void FavoritesRetweetOriginal()
11015 if (!this.ExistCurrentPost) return;
11016 _DoFavRetweetFlags = true;
11017 doReTweetOfficial(true);
11018 if (_DoFavRetweetFlags)
11020 _DoFavRetweetFlags = false;
11021 FavoriteChange(true, false);
11025 private void FavoritesRetweetUnofficial()
11027 if (this.ExistCurrentPost && !_curPost.IsDm)
11029 _DoFavRetweetFlags = true;
11030 FavoriteChange(true);
11031 if (!_curPost.IsProtect && _DoFavRetweetFlags)
11033 _DoFavRetweetFlags = false;
11034 doReTweetUnofficial();
11040 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
11042 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
11043 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
11044 /// <returns>復元されたツイート本文</returns>
11045 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
11047 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
11050 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
11052 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11054 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
11058 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
11060 statusHtml = statusHtml.Replace("<br>", " ");
11062 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
11063 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
11064 statusHtml = statusHtml.Replace(" ", " ");
11066 return WebUtility.HtmlDecode(statusHtml);
11069 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
11071 if (_curPost != null)
11072 DispSelectedPost(true);
11075 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
11077 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
11078 DebugModeToolStripMenuItem.Visible = true;
11080 DebugModeToolStripMenuItem.Visible = false;
11083 private void ToolStripMenuItemUrlAutoShorten_CheckedChanged(object sender, EventArgs e)
11085 SettingDialog.UrlConvertAuto = ToolStripMenuItemUrlAutoShorten.Checked;
11088 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
11090 ToolStripMenuItemUrlAutoShorten.Checked = SettingDialog.UrlConvertAuto;
11093 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
11095 if (TraceOutToolStripMenuItem.Checked)
11096 MyCommon.TraceFlag = true;
11098 MyCommon.TraceFlag = false;
11101 private void TweenMain_Deactivate(object sender, EventArgs e)
11103 //画面が非アクティブになったら、発言欄の背景色をデフォルトへ
11104 this.StatusText_Leave(StatusText, System.EventArgs.Empty);
11107 private void TabRenameMenuItem_Click(object sender, EventArgs e)
11109 if (string.IsNullOrEmpty(_rclickTabName)) return;
11110 TabRename(ref _rclickTabName);
11113 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
11115 await UrlConvertAsync(MyCommon.UrlConverter.Bitly);
11118 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
11120 await UrlConvertAsync(MyCommon.UrlConverter.Jmp);
11124 private void GetApiInfo_Dowork(object sender, DoWorkEventArgs e)
11126 e.Result = tw.GetInfoApi();
11129 private void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
11131 StringBuilder tmp = new StringBuilder();
11133 using (FormInfo dlg = new FormInfo(this, Properties.Resources.ApiInfo6, GetApiInfo_Dowork))
11137 var result = (TwitterApiStatus)dlg.Result;
11139 if (result == null)
11141 var accessLevel = result.AccessLevel;
11142 var timelineLimit = result.AccessLimit["/statuses/home_timeline"];
11143 var mediaLimit = result.MediaUploadLimit;
11145 tmp.AppendLine(Properties.Resources.ApiInfo1 + timelineLimit.AccessLimitCount);
11146 tmp.AppendLine(Properties.Resources.ApiInfo2 + timelineLimit.AccessLimitRemain);
11147 tmp.AppendLine(Properties.Resources.ApiInfo3 + timelineLimit.AccessLimitResetDate);
11148 tmp.AppendLine(Properties.Resources.ApiInfo7 + (tw.UserStreamEnabled ? Properties.Resources.Enable : Properties.Resources.Disable));
11151 tmp.AppendLine(Properties.Resources.ApiInfo8 + accessLevel);
11152 SetStatusLabelUrl();
11155 tmp.AppendLine(Properties.Resources.ApiInfo9 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitCount.ToString()));
11156 tmp.AppendLine(Properties.Resources.ApiInfo10 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitRemain.ToString()));
11157 tmp.AppendLine(Properties.Resources.ApiInfo11 + (mediaLimit == null ? Properties.Resources.ApiInfo91 : mediaLimit.AccessLimitResetDate.ToString()));
11161 tmp.Append(Properties.Resources.ApiInfo5);
11165 MessageBox.Show(tmp.ToString(), Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
11168 private void FollowCommandMenuItem_Click(object sender, EventArgs e)
11171 if (_curPost != null) id = _curPost.ScreenName;
11175 private void FollowCommand_DoWork(object sender, DoWorkEventArgs e)
11177 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11178 e.Result = arg.tw.PostFollowCommand(arg.id);
11181 private void FollowCommand(string id)
11183 using (InputTabName inputName = new InputTabName())
11185 inputName.FormTitle = "Follow";
11186 inputName.FormDescription = Properties.Resources.FRMessage1;
11187 inputName.TabName = id;
11188 if (inputName.ShowDialog() == DialogResult.OK &&
11189 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11191 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11193 arg.id = inputName.TabName.Trim();
11194 using (FormInfo _info = new FormInfo(this, Properties.Resources.FollowCommandText1,
11195 FollowCommand_DoWork,
11199 _info.ShowDialog();
11200 string ret = (string)_info.Result;
11201 if (!string.IsNullOrEmpty(ret))
11202 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11204 MessageBox.Show(Properties.Resources.FRMessage3);
11210 private void RemoveCommandMenuItem_Click(object sender, EventArgs e)
11213 if (_curPost != null) id = _curPost.ScreenName;
11214 RemoveCommand(id, false);
11217 private class FollowRemoveCommandArgs
11223 private void RemoveCommand_DoWork(object sender , DoWorkEventArgs e)
11225 FollowRemoveCommandArgs arg = (FollowRemoveCommandArgs)e.Argument;
11226 e.Result = arg.tw.PostRemoveCommand(arg.id);
11229 private void RemoveCommand(string id, bool skipInput)
11231 FollowRemoveCommandArgs arg = new FollowRemoveCommandArgs();
11236 using (InputTabName inputName = new InputTabName())
11238 inputName.FormTitle = "Unfollow";
11239 inputName.FormDescription = Properties.Resources.FRMessage1;
11240 inputName.TabName = id;
11241 if (inputName.ShowDialog() == DialogResult.OK &&
11242 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11245 arg.id = inputName.TabName.Trim();
11254 using (FormInfo _info = new FormInfo(this, Properties.Resources.RemoveCommandText1,
11255 RemoveCommand_DoWork,
11259 _info.ShowDialog();
11260 string ret = (string)_info.Result;
11261 if (!string.IsNullOrEmpty(ret))
11262 MessageBox.Show(Properties.Resources.FRMessage2 + ret);
11264 MessageBox.Show(Properties.Resources.FRMessage3);
11268 private void FriendshipMenuItem_Click(object sender, EventArgs e)
11271 if (_curPost != null)
11272 id = _curPost.ScreenName;
11274 ShowFriendship(id);
11277 private class ShowFriendshipArgs
11280 public class FriendshipInfo
11282 public string id = "";
11283 public bool isFollowing = false;
11284 public bool isFollowed = false;
11285 public FriendshipInfo(string id)
11290 public List<FriendshipInfo> ids = new List<FriendshipInfo>();
11293 private void ShowFriendship_DoWork(object sender, DoWorkEventArgs e)
11295 ShowFriendshipArgs arg = (ShowFriendshipArgs)e.Argument;
11296 string result = "";
11297 foreach (ShowFriendshipArgs.FriendshipInfo fInfo in arg.ids)
11299 string rt = arg.tw.GetFriendshipInfo(fInfo.id, ref fInfo.isFollowing, ref fInfo.isFollowed);
11300 if (!string.IsNullOrEmpty(rt))
11302 if (string.IsNullOrEmpty(result)) result = rt;
11308 private void ShowFriendship(string id)
11310 ShowFriendshipArgs args = new ShowFriendshipArgs();
11312 using (InputTabName inputName = new InputTabName())
11314 inputName.FormTitle = "Show Friendships";
11315 inputName.FormDescription = Properties.Resources.FRMessage1;
11316 inputName.TabName = id;
11317 if (inputName.ShowDialog() == DialogResult.OK &&
11318 !string.IsNullOrEmpty(inputName.TabName.Trim()))
11321 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(inputName.TabName.Trim()));
11322 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11323 ShowFriendship_DoWork,
11327 _info.ShowDialog();
11328 ret = (string)_info.Result;
11330 string result = "";
11331 if (string.IsNullOrEmpty(ret))
11333 if (args.ids[0].isFollowing)
11335 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
11339 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
11341 if (args.ids[0].isFollowed)
11343 result += Properties.Resources.GetFriendshipInfo3;
11347 result += Properties.Resources.GetFriendshipInfo4;
11349 result = args.ids[0].id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
11355 MessageBox.Show(result);
11360 private void ShowFriendship(string[] ids)
11362 foreach (string id in ids)
11365 ShowFriendshipArgs args = new ShowFriendshipArgs();
11367 args.ids.Add(new ShowFriendshipArgs.FriendshipInfo(id.Trim()));
11368 using (FormInfo _info = new FormInfo(this, Properties.Resources.ShowFriendshipText1,
11369 ShowFriendship_DoWork,
11373 _info.ShowDialog();
11374 ret = (string)_info.Result;
11376 string result = "";
11377 ShowFriendshipArgs.FriendshipInfo fInfo = args.ids[0];
11379 if (string.IsNullOrEmpty(ret))
11382 if (fInfo.isFollowing)
11384 ff += Properties.Resources.GetFriendshipInfo1;
11388 ff += Properties.Resources.GetFriendshipInfo2;
11391 ff += System.Environment.NewLine + " ";
11392 if (fInfo.isFollowed)
11394 ff += Properties.Resources.GetFriendshipInfo3;
11398 ff += Properties.Resources.GetFriendshipInfo4;
11400 result += fInfo.id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
11401 if (fInfo.isFollowing)
11403 if (MessageBox.Show(
11404 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result, Properties.Resources.GetFriendshipInfo8,
11405 MessageBoxButtons.YesNo,
11406 MessageBoxIcon.Question,
11407 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
11409 RemoveCommand(fInfo.id, true);
11414 MessageBox.Show(result);
11419 MessageBox.Show(ret);
11424 private void OwnStatusMenuItem_Click(object sender, EventArgs e)
11426 doShowUserStatus(tw.Username, false);
11427 //if (!string.IsNullOrEmpty(tw.UserInfoXml))
11429 // doShowUserStatus(tw.Username, false);
11433 // MessageBox.Show(Properties.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information);
11438 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
11439 // URLから切り出した文字列を渡す
11441 public bool IsTwitterId(string name)
11443 if (SettingDialog.TwitterConfiguration.NonUsernamePaths == null || SettingDialog.TwitterConfiguration.NonUsernamePaths.Length == 0)
11444 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
11446 return !SettingDialog.TwitterConfiguration.NonUsernamePaths.Contains(name.ToLower());
11449 private string GetUserId()
11451 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?$");
11452 if (m.Success && IsTwitterId(m.Result("${ScreenName}")))
11453 return m.Result("${ScreenName}");
11458 private void FollowContextMenuItem_Click(object sender, EventArgs e)
11460 string name = GetUserId();
11461 if (name != null) FollowCommand(name);
11464 private void RemoveContextMenuItem_Click(object sender, EventArgs e)
11466 string name = GetUserId();
11467 if (name != null) RemoveCommand(name, false);
11470 private void FriendshipContextMenuItem_Click(object sender, EventArgs e)
11472 string name = GetUserId();
11473 if (name != null) ShowFriendship(name);
11476 private void FriendshipAllMenuItem_Click(object sender, EventArgs e)
11478 MatchCollection ma = Regex.Matches(this.PostBrowser.DocumentText, @"href=""https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/[0-9]+)?""");
11479 List<string> ids = new List<string>();
11480 foreach (Match mu in ma)
11482 if (mu.Result("${ScreenName}").ToLower() != tw.Username.ToLower())
11484 ids.Add(mu.Result("${ScreenName}"));
11487 ShowFriendship(ids.ToArray());
11490 private void ShowUserStatusContextMenuItem_Click(object sender, EventArgs e)
11492 string name = GetUserId();
11493 if (name != null) ShowUserStatus(name);
11496 private void SearchPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11498 string name = GetUserId();
11499 if (name != null) AddNewTabForUserTimeline(name);
11502 private void SearchAtPostsDetailToolStripMenuItem_Click(object sender, EventArgs e)
11504 string name = GetUserId();
11505 if (name != null) AddNewTabForSearch("@" + name);
11508 private void IdeographicSpaceToSpaceToolStripMenuItem_Click(object sender, EventArgs e)
11510 _modifySettingCommon = true;
11513 private void ToolStripFocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
11515 _modifySettingCommon = true;
11518 private void doQuote()
11522 if (this.ExistCurrentPost)
11524 if (_curPost.IsDm ||
11525 !StatusText.Enabled) return;
11527 if (_curPost.IsProtect)
11529 MessageBox.Show("Protected.");
11532 string rtdata = _curPost.Text;
11533 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
11535 StatusText.Text = " QT @" + _curPost.ScreenName + ": " + rtdata;
11536 if (_curPost.RetweetedId == null)
11538 _reply_to_id = _curPost.StatusId;
11542 _reply_to_id = _curPost.RetweetedId.Value;
11544 _reply_to_name = _curPost.ScreenName;
11546 StatusText.SelectionStart = 0;
11547 StatusText.Focus();
11551 private void QuoteStripMenuItem_Click(object sender, EventArgs e) // Handles QuoteStripMenuItem.Click, QtOpMenuItem.Click
11556 private void SearchButton_Click(object sender, EventArgs e)
11559 Control pnl = ((Control)sender).Parent;
11560 if (pnl == null) return;
11561 string tbName = pnl.Parent.Text;
11562 TabClass tb = _statuses.Tabs[tbName];
11563 ComboBox cmb = (ComboBox)pnl.Controls["comboSearch"];
11564 ComboBox cmbLang = (ComboBox)pnl.Controls["comboLang"];
11565 cmb.Text = cmb.Text.Trim();
11566 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
11567 bool Quote = false;
11568 StringBuilder buf = new StringBuilder();
11569 char[] c = cmb.Text.ToCharArray();
11570 for (int cnt = 0; cnt < cmb.Text.Length; cnt++)
11572 if (cnt > cmb.Text.Length - 4)
11574 buf.Append(cmb.Text.Substring(cnt));
11583 if (!Quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
11585 buf.Append(" OR ");
11590 buf.Append(c[cnt]);
11592 cmb.Text = buf.ToString();
11594 tb.SearchWords = cmb.Text;
11595 tb.SearchLang = cmbLang.Text;
11596 if (string.IsNullOrEmpty(cmb.Text))
11598 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11602 if (tb.IsQueryChanged())
11604 int idx = ((ComboBox)pnl.Controls["comboSearch"]).Items.IndexOf(tb.SearchWords);
11605 if (idx > -1) ((ComboBox)pnl.Controls["comboSearch"]).Items.RemoveAt(idx);
11606 ((ComboBox)pnl.Controls["comboSearch"]).Items.Insert(0, tb.SearchWords);
11607 cmb.Text = tb.SearchWords;
11609 DetailsListView lst = (DetailsListView)pnl.Parent.Tag;
11610 this.PurgeListViewItemCache();
11611 lst.VirtualListSize = 0;
11612 _statuses.ClearTabIds(tbName);
11613 SaveConfigsTabs(); //検索条件の保存
11616 GetTimeline(MyCommon.WORKERTYPE.PublicSearch, 1, tbName);
11617 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
11620 private void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
11626 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
11628 if (_statuses.RemovedTab.Count == 0)
11630 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
11635 TabClass tb = _statuses.RemovedTab.Pop();
11636 if (tb.TabType == MyCommon.TabUsageType.Related)
11638 var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
11639 if (relatedTab != null)
11641 // 関連発言なら既存のタブを置き換える
11642 tb.TabName = relatedTab.TabName;
11643 this.ClearTab(tb.TabName, false);
11644 _statuses.Tabs[tb.TabName] = tb;
11645 for (int i = 0; i < ListTab.TabPages.Count; i++)
11647 if (tb.TabName == ListTab.TabPages[i].Text)
11649 ListTab.SelectedIndex = i;
11650 ListTabSelect(ListTab.TabPages[i]);
11657 const string TabName = "Related Tweets";
11658 string renamed = TabName;
11659 for (int i = 2; i <= 100; i++)
11661 if (!_statuses.ContainsTab(renamed)) break;
11662 renamed = TabName + i.ToString();
11664 tb.TabName = renamed;
11665 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11666 _statuses.Tabs.Add(renamed, tb); // 後に
11667 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11668 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11673 string renamed = tb.TabName;
11674 for (int i = 1; i < int.MaxValue; i++)
11676 if (!_statuses.ContainsTab(renamed)) break;
11677 renamed = tb.TabName + "(" + i.ToString() + ")";
11679 tb.TabName = renamed;
11680 _statuses.Tabs.Add(renamed, tb); // 先に
11681 AddNewTab(renamed, false, tb.TabType, tb.ListInfo);
11682 ListTab.SelectedIndex = ListTab.TabPages.Count - 1;
11683 ListTabSelect(ListTab.TabPages[ListTab.TabPages.Count - 1]);
11689 private void doMoveToRTHome()
11691 if (_curList.SelectedIndices.Count > 0)
11693 PostClass post = GetCurTabPost(_curList.SelectedIndices[0]);
11694 if (post.RetweetedId != null)
11696 OpenUriAsync("https://twitter.com/" + GetCurTabPost(_curList.SelectedIndices[0]).RetweetedBy);
11701 private void MoveToRTHomeMenuItem_Click(object sender, EventArgs e)
11706 private void IdFilterAddMenuItem_Click(object sender, EventArgs e)
11708 string name = GetUserId();
11714 if (_curList.SelectedIndices.Count == 0) return;
11717 if (!SelectTab(out tabName)) return;
11721 MoveOrCopy(ref mv, ref mk);
11723 PostFilterRule fc = new PostFilterRule();
11724 fc.FilterName = name;
11725 fc.UseNameField = true;
11726 fc.MoveMatches = mv;
11727 fc.MarkMatches = mk;
11728 fc.UseRegex = false;
11729 fc.FilterByUrl = false;
11730 _statuses.Tabs[tabName].AddFilter(fc);
11732 this.ApplyPostFilters();
11737 private void ListManageUserContextToolStripMenuItem_Click(object sender, EventArgs e)
11741 ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
11743 if (menuItem.Owner == this.ContextMenuPostBrowser)
11745 user = GetUserId();
11746 if (user == null) return;
11748 else if (this._curPost != null)
11750 user = this._curPost.ScreenName;
11757 if (TabInformations.GetInstance().SubscribableLists.Count == 0)
11759 string res = this.tw.GetListsApi();
11761 if (!string.IsNullOrEmpty(res))
11763 MessageBox.Show("Failed to get lists. (" + res + ")");
11768 using (MyLists listSelectForm = new MyLists(user, this.tw))
11770 listSelectForm.ShowDialog(this);
11774 private void SearchControls_Enter(object sender, EventArgs e)
11776 Control pnl = (Control)sender;
11777 foreach (Control ctl in pnl.Controls)
11779 ctl.TabStop = true;
11783 private void SearchControls_Leave(object sender, EventArgs e)
11785 Control pnl = (Control)sender;
11786 foreach (Control ctl in pnl.Controls)
11788 ctl.TabStop = false;
11792 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
11794 if (ListTab.SelectedTab != null)
11796 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.PublicSearch) return;
11797 ListTab.SelectedTab.Controls["panelSearch"].Controls["comboSearch"].Focus();
11801 private void UseHashtagMenuItem_Click(object sender, EventArgs e)
11803 Match m = Regex.Match(this._postBrowserStatusText, @"^https?://twitter.com/search\?q=%23(?<hash>.+)$");
11806 HashMgr.SetPermanentHash("#" + Uri.UnescapeDataString(m.Result("${hash}")));
11807 HashStripSplitButton.Text = HashMgr.UseHash;
11808 HashToggleMenuItem.Checked = true;
11809 HashToggleToolStripMenuItem.Checked = true;
11811 _modifySettingCommon = true;
11815 private void StatusLabel_DoubleClick(object sender, EventArgs e)
11817 MessageBox.Show(StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
11820 private void HashManageMenuItem_Click(object sender, EventArgs e)
11822 DialogResult rslt = DialogResult.Cancel;
11825 rslt = HashMgr.ShowDialog();
11831 this.TopMost = SettingDialog.AlwaysTop;
11832 if (rslt == DialogResult.Cancel) return;
11833 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11835 HashStripSplitButton.Text = HashMgr.UseHash;
11836 HashToggleMenuItem.Checked = true;
11837 HashToggleToolStripMenuItem.Checked = true;
11841 HashStripSplitButton.Text = "#[-]";
11842 HashToggleMenuItem.Checked = false;
11843 HashToggleToolStripMenuItem.Checked = false;
11845 //if (HashMgr.IsInsert && HashMgr.UseHash != "")
11847 // int sidx = StatusText.SelectionStart;
11848 // string hash = HashMgr.UseHash + " ";
11851 // if (StatusText.Text.Substring(sidx - 1, 1) != " ")
11852 // hash = " " + hash;
11854 // StatusText.Text = StatusText.Text.Insert(sidx, hash);
11855 // sidx += hash.Length;
11856 // StatusText.SelectionStart = sidx;
11857 // StatusText.Focus();
11859 _modifySettingCommon = true;
11860 this.StatusText_TextChanged(null, null);
11863 private void HashToggleMenuItem_Click(object sender, EventArgs e)
11865 HashMgr.ToggleHash();
11866 if (!string.IsNullOrEmpty(HashMgr.UseHash))
11868 HashStripSplitButton.Text = HashMgr.UseHash;
11869 HashToggleMenuItem.Checked = true;
11870 HashToggleToolStripMenuItem.Checked = true;
11874 HashStripSplitButton.Text = "#[-]";
11875 HashToggleMenuItem.Checked = false;
11876 HashToggleToolStripMenuItem.Checked = false;
11878 _modifySettingCommon = true;
11879 this.StatusText_TextChanged(null, null);
11882 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
11884 HashToggleMenuItem_Click(null, null);
11887 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
11889 if (ListTab.SelectedTab == null) return;
11890 if (_statuses == null || _statuses.Tabs == null || !_statuses.Tabs.ContainsKey(ListTab.SelectedTab.Text)) return;
11891 if (!this.ExistCurrentPost)
11893 this.ReplyOpMenuItem.Enabled = false;
11894 this.ReplyAllOpMenuItem.Enabled = false;
11895 this.DmOpMenuItem.Enabled = false;
11896 this.ShowProfMenuItem.Enabled = false;
11897 this.ShowUserTimelineToolStripMenuItem.Enabled = false;
11898 this.ListManageMenuItem.Enabled = false;
11899 this.OpenFavOpMenuItem.Enabled = false;
11900 this.CreateTabRuleOpMenuItem.Enabled = false;
11901 this.CreateIdRuleOpMenuItem.Enabled = false;
11902 this.ReadOpMenuItem.Enabled = false;
11903 this.UnreadOpMenuItem.Enabled = false;
11907 this.ReplyOpMenuItem.Enabled = true;
11908 this.ReplyAllOpMenuItem.Enabled = true;
11909 this.DmOpMenuItem.Enabled = true;
11910 this.ShowProfMenuItem.Enabled = true;
11911 this.ShowUserTimelineToolStripMenuItem.Enabled = true;
11912 this.ListManageMenuItem.Enabled = true;
11913 this.OpenFavOpMenuItem.Enabled = true;
11914 this.CreateTabRuleOpMenuItem.Enabled = true;
11915 this.CreateIdRuleOpMenuItem.Enabled = true;
11916 this.ReadOpMenuItem.Enabled = true;
11917 this.UnreadOpMenuItem.Enabled = true;
11920 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || _curPost.IsDm)
11922 this.FavOpMenuItem.Enabled = false;
11923 this.UnFavOpMenuItem.Enabled = false;
11924 this.OpenStatusOpMenuItem.Enabled = false;
11925 this.OpenFavotterOpMenuItem.Enabled = false;
11926 this.ShowRelatedStatusesMenuItem2.Enabled = false;
11927 this.RtOpMenuItem.Enabled = false;
11928 this.RtUnOpMenuItem.Enabled = false;
11929 this.QtOpMenuItem.Enabled = false;
11930 this.FavoriteRetweetMenuItem.Enabled = false;
11931 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11932 if (this.ExistCurrentPost && _curPost.IsDm) this.DelOpMenuItem.Enabled = true;
11936 this.FavOpMenuItem.Enabled = true;
11937 this.UnFavOpMenuItem.Enabled = true;
11938 this.OpenStatusOpMenuItem.Enabled = true;
11939 this.OpenFavotterOpMenuItem.Enabled = true;
11940 this.ShowRelatedStatusesMenuItem2.Enabled = true; //PublicSearchの時問題出るかも
11944 this.RtOpMenuItem.Enabled = false;
11945 this.FavoriteRetweetMenuItem.Enabled = false;
11946 this.DelOpMenuItem.Enabled = true;
11950 this.DelOpMenuItem.Enabled = false;
11951 if (_curPost.IsProtect)
11953 this.RtOpMenuItem.Enabled = false;
11954 this.RtUnOpMenuItem.Enabled = false;
11955 this.QtOpMenuItem.Enabled = false;
11956 this.FavoriteRetweetMenuItem.Enabled = false;
11957 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
11961 this.RtOpMenuItem.Enabled = true;
11962 this.RtUnOpMenuItem.Enabled = true;
11963 this.QtOpMenuItem.Enabled = true;
11964 this.FavoriteRetweetMenuItem.Enabled = true;
11965 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
11970 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType != MyCommon.TabUsageType.Favorites)
11972 this.RefreshPrevOpMenuItem.Enabled = true;
11976 this.RefreshPrevOpMenuItem.Enabled = false;
11978 if (!this.ExistCurrentPost
11979 || _curPost.InReplyToStatusId == null)
11981 OpenRepSourceOpMenuItem.Enabled = false;
11985 OpenRepSourceOpMenuItem.Enabled = true;
11987 if (!this.ExistCurrentPost || string.IsNullOrEmpty(_curPost.RetweetedBy))
11989 OpenRterHomeMenuItem.Enabled = false;
11993 OpenRterHomeMenuItem.Enabled = true;
11997 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
11999 ContextMenuTabProperty_Opening(sender, null);
12002 public Twitter TwitterInstance
12007 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
12009 if (this.WindowState == FormWindowState.Normal && !_initialLayout)
12011 _mySpDis3 = SplitContainer3.SplitterDistance;
12012 _modifySettingLocal = true;
12016 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
12018 if (_statuses.RemovedTab.Count == 0)
12020 UndoRemoveTabMenuItem.Enabled = false;
12024 UndoRemoveTabMenuItem.Enabled = true;
12026 if (ListTab.SelectedTab != null)
12028 if (_statuses.Tabs[ListTab.SelectedTab.Text].TabType == MyCommon.TabUsageType.PublicSearch)
12029 PublicSearchQueryMenuItem.Enabled = true;
12031 PublicSearchQueryMenuItem.Enabled = false;
12035 PublicSearchQueryMenuItem.Enabled = false;
12037 if (!this.ExistCurrentPost)
12039 this.CopySTOTMenuItem.Enabled = false;
12040 this.CopyURLMenuItem.Enabled = false;
12041 this.CopyUserIdStripMenuItem.Enabled = false;
12045 this.CopySTOTMenuItem.Enabled = true;
12046 this.CopyURLMenuItem.Enabled = true;
12047 this.CopyUserIdStripMenuItem.Enabled = true;
12048 if (_curPost.IsDm) this.CopyURLMenuItem.Enabled = false;
12049 if (_curPost.IsProtect) this.CopySTOTMenuItem.Enabled = false;
12053 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
12055 SetNotifyIconText();
12058 private void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12061 if (_curPost != null)
12063 id = _curPost.ScreenName;
12065 ShowUserStatus(id);
12068 private class GetUserInfoArgs
12072 public TwitterUser user;
12075 private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
12077 GetUserInfoArgs args = (GetUserInfoArgs)e.Argument;
12078 e.Result = args.tw.GetUserInfo(args.id, ref args.user);
12081 private void doShowUserStatus(string id, bool ShowInputDialog)
12083 TwitterUser user = null;
12084 GetUserInfoArgs args = new GetUserInfoArgs();
12085 if (ShowInputDialog)
12087 using (InputTabName inputName = new InputTabName())
12089 inputName.FormTitle = "Show UserStatus";
12090 inputName.FormDescription = Properties.Resources.FRMessage1;
12091 inputName.TabName = id;
12092 if (inputName.ShowDialog() == DialogResult.OK &&
12093 !string.IsNullOrEmpty(inputName.TabName.Trim()))
12095 id = inputName.TabName.Trim();
12099 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12100 GetUserInfo_DoWork,
12104 _info.ShowDialog();
12105 string ret = (string)_info.Result;
12106 if (string.IsNullOrEmpty(ret))
12107 doShowUserStatus(args.user);
12109 MessageBox.Show(ret);
12119 using (FormInfo _info = new FormInfo(this, Properties.Resources.doShowUserStatusText1,
12120 GetUserInfo_DoWork,
12124 _info.ShowDialog();
12125 string ret = (string)_info.Result;
12126 if (string.IsNullOrEmpty(ret))
12128 doShowUserStatus(args.user);
12132 MessageBox.Show(ret);
12138 private async void doShowUserStatus(TwitterUser user)
12140 using (var userDialog = new UserInfoDialog(this, this.tw))
12142 var showUserTask = userDialog.ShowUserAsync(user);
12143 userDialog.ShowDialog(this);
12146 this.BringToFront();
12148 // ユーザー情報の表示が完了するまで userDialog を破棄しない
12149 await showUserTask;
12153 private void ShowUserStatus(string id, bool ShowInputDialog)
12155 doShowUserStatus(id, ShowInputDialog);
12158 private void ShowUserStatus(string id)
12160 doShowUserStatus(id, true);
12163 private void FollowToolStripMenuItem_Click(object sender, EventArgs e)
12165 if (NameLabel.Tag != null)
12167 string id = (string)NameLabel.Tag;
12168 if (id != tw.Username)
12175 private void UnFollowToolStripMenuItem_Click(object sender, EventArgs e)
12177 if (NameLabel.Tag != null)
12179 string id = (string)NameLabel.Tag;
12180 if (id != tw.Username)
12182 RemoveCommand(id, false);
12187 private void ShowFriendShipToolStripMenuItem_Click(object sender, EventArgs e)
12189 if (NameLabel.Tag != null)
12191 string id = (string)NameLabel.Tag;
12192 if (id != tw.Username)
12194 ShowFriendship(id);
12199 private void ShowUserStatusToolStripMenuItem_Click(object sender, EventArgs e)
12201 if (NameLabel.Tag != null)
12203 string id = (string)NameLabel.Tag;
12204 ShowUserStatus(id, false);
12208 private void SearchPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12210 if (NameLabel.Tag != null)
12212 string id = (string)NameLabel.Tag;
12213 AddNewTabForUserTimeline(id);
12217 private void SearchAtPostsDetailNameToolStripMenuItem_Click(object sender, EventArgs e)
12219 if (NameLabel.Tag != null)
12221 string id = (string)NameLabel.Tag;
12222 AddNewTabForSearch("@" + id);
12226 private void ShowProfileMenuItem_Click(object sender, EventArgs e)
12228 if (_curPost != null)
12230 ShowUserStatus(_curPost.ScreenName, false);
12234 private void GetRetweet_DoWork(object sender, DoWorkEventArgs e)
12239 if (_curPost.RetweetedId != null)
12241 statusid = _curPost.RetweetedId.Value;
12245 statusid = _curPost.StatusId;
12247 tw.GetStatus_Retweeted_Count(statusid, ref counter);
12249 e.Result = counter;
12252 private void RtCountMenuItem_Click(object sender, EventArgs e)
12254 if (this.ExistCurrentPost)
12256 using (FormInfo _info = new FormInfo(this, Properties.Resources.RtCountMenuItem_ClickText1,
12257 GetRetweet_DoWork))
12259 int retweet_count = 0;
12262 _info.ShowDialog();
12263 retweet_count = (int)_info.Result;
12264 if (retweet_count < 0)
12266 MessageBox.Show(Properties.Resources.RtCountText2);
12270 MessageBox.Show(retweet_count.ToString() + Properties.Resources.RtCountText1);
12276 private HookGlobalHotkey _hookGlobalHotkey;
12279 _hookGlobalHotkey = new HookGlobalHotkey(this);
12281 // この呼び出しは、Windows フォーム デザイナで必要です。
12282 InitializeComponent();
12284 // InitializeComponent() 呼び出しの後で初期化を追加します。
12286 this.SettingDialog.IntervalChanged += this.TimerInterval_Changed;
12287 this.TimerTimeline.Elapsed += this.TimerTimeline_Elapsed;
12288 this._hookGlobalHotkey.HotkeyPressed += _hookGlobalHotkey_HotkeyPressed;
12289 this.gh.NotifyClicked += GrowlHelper_Callback;
12291 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
12292 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
12294 this._apiGauge = new ToolStripAPIGauge();
12295 this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
12296 this.StatusStrip1.Items.Insert(2, this._apiGauge);
12298 this.ImageSelector.Visible = false;
12299 this.ImageSelector.Enabled = false;
12300 this.ImageSelector.FilePickDialog = OpenFileDialog1;
12302 this.ReplaceAppName();
12305 private void _hookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
12307 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
12310 this.Visible = false;
12312 else if (Form.ActiveForm == null)
12314 this.Visible = true;
12315 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
12317 this.BringToFront();
12318 this.StatusText.Focus();
12322 private void UserPicture_MouseEnter(object sender, EventArgs e)
12324 this.UserPicture.Cursor = Cursors.Hand;
12327 private void UserPicture_MouseLeave(object sender, EventArgs e)
12329 this.UserPicture.Cursor = Cursors.Default;
12332 private void UserPicture_DoubleClick(object sender, EventArgs e)
12334 if (NameLabel.Tag != null)
12336 OpenUriAsync(MyCommon.TwitterUrl + NameLabel.Tag.ToString());
12340 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
12342 this.MultiLineMenuItem.PerformClick();
12345 public PostClass CurPost
12347 get { return _curPost; }
12350 public bool IsPreviewEnable
12352 get { return SettingDialog.PreviewEnable; }
12356 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
12358 if (ImageSelector.Visible)
12359 ImageSelector.EndSelection();
12361 ImageSelector.BeginSelection();
12364 private void SelectMedia_DragEnter(DragEventArgs e)
12366 if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0], true))
12368 e.Effect = DragDropEffects.Copy;
12371 e.Effect = DragDropEffects.None;
12374 private void SelectMedia_DragOver(DragEventArgs e)
12379 private void SelectMedia_DragDrop(DragEventArgs e)
12382 this.BringToFront();
12383 ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
12384 StatusText.Focus();
12387 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
12389 TimelinePanel.Visible = false;
12390 TimelinePanel.Enabled = false;
12393 private void ImageSelector_EndSelecting(object sender, EventArgs e)
12395 TimelinePanel.Visible = true;
12396 TimelinePanel.Enabled = true;
12397 ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
12400 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
12402 this.AllowDrop = false;
12405 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
12407 this.AllowDrop = true;
12410 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
12412 if (ImageSelector.Visible)
12414 _modifySettingCommon = true;
12415 SaveConfigsAll(true);
12417 if (ImageSelector.ServiceName.Equals("Twitter"))
12418 this.StatusText_TextChanged(null, null);
12422 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
12424 this.StatusText_TextChanged(null, null);
12428 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
12430 using (ListManage form = new ListManage(tw))
12432 form.ShowDialog(this);
12436 public bool ModifySettingCommon
12438 set { _modifySettingCommon = value; }
12441 public bool ModifySettingLocal
12443 set { _modifySettingLocal = value; }
12446 public bool ModifySettingAtId
12448 set { _modifySettingAtId = value; }
12451 private void SourceLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
12453 string link = (string)SourceLinkLabel.Tag;
12454 if (!string.IsNullOrEmpty(link) && e.Button == MouseButtons.Left)
12456 OpenUriAsync(link);
12460 private void SourceLinkLabel_MouseEnter(object sender, EventArgs e)
12462 string link = (string)SourceLinkLabel.Tag;
12463 if (!string.IsNullOrEmpty(link))
12465 StatusLabelUrl.Text = MyCommon.ConvertToReadableUrl(link);
12469 private void SourceLinkLabel_MouseLeave(object sender, EventArgs e)
12471 SetStatusLabelUrl();
12474 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
12476 if (this.ExistCurrentPost && !_curPost.IsDm)
12477 RtCountMenuItem.Enabled = true;
12479 RtCountMenuItem.Enabled = false;
12481 //if (SettingDialog.UrlConvertAuto && SettingDialog.ShortenTco)
12482 // TinyUrlConvertToolStripMenuItem.Enabled = false;
12484 // TinyUrlConvertToolStripMenuItem.Enabled = true;
12487 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
12492 private void CopyUserId()
12494 if (_curPost == null) return;
12495 string clstr = _curPost.ScreenName;
12498 Clipboard.SetDataObject(clstr, false, 5, 100);
12500 catch (Exception ex)
12502 MessageBox.Show(ex.Message);
12506 private void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e) // Handles ShowRelatedStatusesMenuItem.Click, ShowRelatedStatusesMenuItem2.Click
12508 if (this.ExistCurrentPost && !_curPost.IsDm)
12512 this.OpenRelatedTab(this._curPost);
12514 catch (TabException ex)
12516 MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
12522 /// 指定されたツイートに対する関連発言タブを開きます
12524 /// <param name="post">表示する対象となるツイート</param>
12525 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
12526 private void OpenRelatedTab(PostClass post)
12528 var tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12531 if (tabRelated == null)
12533 tabName = this._statuses.MakeTabName("Related Tweets");
12535 this.AddNewTab(tabName, false, MyCommon.TabUsageType.Related);
12536 this._statuses.AddTab(tabName, MyCommon.TabUsageType.Related, null);
12538 tabRelated = this._statuses.GetTabByType(MyCommon.TabUsageType.Related);
12539 tabRelated.UnreadManage = false;
12540 tabRelated.Notify = false;
12544 tabName = tabRelated.TabName;
12547 tabRelated.RelationTargetPost = post;
12548 this.ClearTab(tabName, false);
12550 for (int i = 0; i < this.ListTab.TabPages.Count; i++)
12552 var tabPage = this.ListTab.TabPages[i];
12553 if (tabName == tabPage.Text)
12555 this.ListTab.SelectedIndex = i;
12556 this.ListTabSelect(tabPage);
12561 this.GetTimeline(MyCommon.WORKERTYPE.Related, 1, tabName);
12564 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
12566 StringBuilder buf = new StringBuilder();
12567 //buf.AppendFormat("キャッシュメモリ容量 : {0}bytes({1}MB)" + Environment.NewLine, IconCache.CacheMemoryLimit, ((ImageDictionary)IconCache).CacheMemoryLimit / 1048576);
12568 //buf.AppendFormat("物理メモリ使用割合 : {0}%" + Environment.NewLine, IconCache.PhysicalMemoryLimit);
12569 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, IconCache.CacheCount);
12570 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, IconCache.CacheRemoveCount);
12571 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
12574 private void tw_UserIdChanged()
12576 this._modifySettingCommon = true;
12579 #region "Userstream"
12580 private bool _isActiveUserstream = false;
12582 private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
12586 if (InvokeRequired && !IsDisposed)
12588 Invoke((Action) (() =>
12590 _statuses.RemovePostReserve(e.StatusId);
12591 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
12593 this.PurgeListViewItemCache();
12594 ((DetailsListView)_curTab.Tag).Update();
12595 if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
12601 catch (ObjectDisposedException)
12605 catch (InvalidOperationException)
12611 private void tw_NewPostFromStream(object sender, EventArgs e)
12613 if (SettingDialog.ReadOldPosts)
12615 _statuses.SetRead(); //新着時未読クリア
12618 int rsltAddCount = _statuses.DistributePosts();
12621 DateTime tm = DateTime.Now;
12622 if (_tlTimestamps.ContainsKey(tm))
12624 _tlTimestamps[tm] += rsltAddCount;
12628 _tlTimestamps.Add(tm, rsltAddCount);
12630 DateTime oneHour = DateTime.Now.Subtract(new TimeSpan(1, 0, 0));
12631 List<DateTime> keys = new List<DateTime>();
12633 foreach (DateTime key in _tlTimestamps.Keys)
12635 if (key.CompareTo(oneHour) < 0)
12638 _tlCount += _tlTimestamps[key];
12640 foreach (DateTime key in keys)
12642 _tlTimestamps.Remove(key);
12646 //Static DateTime before = Now;
12647 //if (before.Subtract(Now).Seconds > -5) return;
12651 if (this._cfgCommon.UserstreamPeriod > 0) return;
12655 if (InvokeRequired && !IsDisposed)
12657 Invoke(new Action<bool>(RefreshTimeline), true);
12661 catch (ObjectDisposedException)
12665 catch (InvalidOperationException)
12671 private void tw_UserStreamStarted(object sender, EventArgs e)
12673 this._isActiveUserstream = true;
12676 if (InvokeRequired && !IsDisposed)
12678 Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
12682 catch (ObjectDisposedException)
12686 catch (InvalidOperationException)
12691 MenuItemUserStream.Text = "&UserStream ▶";
12692 MenuItemUserStream.Enabled = true;
12693 StopToolStripMenuItem.Text = "&Stop";
12694 StopToolStripMenuItem.Enabled = true;
12696 StatusLabel.Text = "UserStream Started.";
12699 private void tw_UserStreamStopped(object sender, EventArgs e)
12701 this._isActiveUserstream = false;
12704 if (InvokeRequired && !IsDisposed)
12706 Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
12710 catch (ObjectDisposedException)
12714 catch (InvalidOperationException)
12719 MenuItemUserStream.Text = "&UserStream ■";
12720 MenuItemUserStream.Enabled = true;
12721 StopToolStripMenuItem.Text = "&Start";
12722 StopToolStripMenuItem.Enabled = true;
12724 StatusLabel.Text = "UserStream Stopped.";
12727 private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
12731 if (InvokeRequired && !IsDisposed)
12733 Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
12737 catch (ObjectDisposedException)
12741 catch (InvalidOperationException)
12745 var ev = e.EventData;
12746 StatusLabel.Text = "Event: " + ev.Event;
12747 //if (ev.Event == "favorite")
12749 // NotifyFavorite(ev);
12752 if (ev.Event == "favorite" || ev.Event == "unfavorite")
12754 if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(ev.Id))
12756 this.PurgeListViewItemCache();
12757 ((DetailsListView)_curTab.Tag).Update();
12759 if (ev.Event == "unfavorite" && ev.Username.ToLower().Equals(tw.Username.ToLower()))
12761 RemovePostFromFavTab(new long[] {ev.Id});
12766 private void NotifyEvent(Twitter.FormattedEvent ev)
12769 if (BalloonRequired(ev))
12771 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12772 //if (SettingDialog.DispUsername) NotifyIcon1.BalloonTipTitle = tw.Username + " - "; else NotifyIcon1.BalloonTipTitle = "";
12773 //NotifyIcon1.BalloonTipTitle += Application.ProductName + " [" + ev.Event.ToUpper() + "] by " + ((string)(!string.IsNullOrEmpty(ev.Username) ? ev.Username : ""), string);
12774 StringBuilder title = new StringBuilder();
12775 if (SettingDialog.DispUsername)
12777 title.Append(tw.Username);
12778 title.Append(" - ");
12784 title.Append(Application.ProductName);
12785 title.Append(" [");
12786 title.Append(ev.Event.ToUpper());
12787 title.Append("] by ");
12788 if (!string.IsNullOrEmpty(ev.Username))
12790 title.Append(ev.Username.ToString());
12794 //title.Append("");
12797 if (!string.IsNullOrEmpty(ev.Target))
12799 //NotifyIcon1.BalloonTipText = ev.Target;
12804 //NotifyIcon1.BalloonTipText = " ";
12807 //NotifyIcon1.ShowBalloonTip(500);
12808 if (SettingDialog.IsNotifyUseGrowl)
12810 gh.Notify(GrowlHelper.NotifyType.UserStreamEvent,
12811 ev.Id.ToString(), title.ToString(), text);
12815 NotifyIcon1.BalloonTipIcon = ToolTipIcon.Warning;
12816 NotifyIcon1.BalloonTipTitle = title.ToString();
12817 NotifyIcon1.BalloonTipText = text;
12818 NotifyIcon1.ShowBalloonTip(500);
12823 string snd = SettingDialog.EventSoundFile;
12824 if (!_initial && SettingDialog.PlaySound && !string.IsNullOrEmpty(snd))
12826 if ((ev.Eventtype & SettingDialog.EventNotifyFlag) != 0 && IsMyEventNotityAsEventType(ev))
12830 string dir = Application.StartupPath;
12831 if (Directory.Exists(Path.Combine(dir, "Sounds")))
12833 dir = Path.Combine(dir, "Sounds");
12835 using (SoundPlayer player = new SoundPlayer(Path.Combine(dir, snd)))
12847 private void StopToolStripMenuItem_Click(object sender, EventArgs e)
12849 MenuItemUserStream.Enabled = false;
12850 if (StopRefreshAllMenuItem.Checked)
12852 StopRefreshAllMenuItem.Checked = false;
12855 if (this._isActiveUserstream)
12857 tw.StopUserStream();
12861 tw.StartUserStream();
12865 private static string inputTrack = "";
12867 private void TrackToolStripMenuItem_Click(object sender, EventArgs e)
12869 if (TrackToolStripMenuItem.Checked)
12871 using (InputTabName inputForm = new InputTabName())
12873 inputForm.TabName = inputTrack;
12874 inputForm.FormTitle = "Input track word";
12875 inputForm.FormDescription = "Track word";
12876 if (inputForm.ShowDialog() != DialogResult.OK)
12878 TrackToolStripMenuItem.Checked = false;
12881 inputTrack = inputForm.TabName.Trim();
12883 if (!inputTrack.Equals(tw.TrackWord))
12885 tw.TrackWord = inputTrack;
12886 this._modifySettingCommon = true;
12887 TrackToolStripMenuItem.Checked = !string.IsNullOrEmpty(inputTrack);
12888 tw.ReconnectUserStream();
12894 tw.ReconnectUserStream();
12896 this._modifySettingCommon = true;
12899 private void AllrepliesToolStripMenuItem_Click(object sender, EventArgs e)
12901 tw.AllAtReply = AllrepliesToolStripMenuItem.Checked;
12902 this._modifySettingCommon = true;
12903 tw.ReconnectUserStream();
12906 private void EventViewerMenuItem_Click(object sender, EventArgs e)
12908 if (evtDialog == null || evtDialog.IsDisposed)
12911 evtDialog = new EventViewerDialog();
12912 evtDialog.Owner = this;
12914 Point pos = evtDialog.Location;
12915 pos.X = Convert.ToInt32(this.Location.X + this.Size.Width / 2 - evtDialog.Size.Width / 2);
12916 pos.Y = Convert.ToInt32(this.Location.Y + this.Size.Height / 2 - evtDialog.Size.Height / 2);
12917 evtDialog.Location = pos;
12919 evtDialog.EventSource = tw.StoredEvent;
12920 if (!evtDialog.Visible)
12922 evtDialog.Show(this);
12926 evtDialog.Activate();
12928 this.TopMost = this.SettingDialog.AlwaysTop;
12932 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
12934 MyCommon._endingFlag = true;
12938 Application.Restart();
12942 MessageBox.Show("Failed to restart. Please run " + Application.ProductName + " manually.");
12946 private void OpenOwnFavedMenuItem_Click(object sender, EventArgs e)
12948 if (!string.IsNullOrEmpty(tw.Username)) OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + tw.Username + "/recent");
12951 private void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
12953 OpenUriAsync(MyCommon.TwitterUrl + tw.Username);
12956 private async Task doTranslation(string str)
12958 if (string.IsNullOrEmpty(str))
12961 var bing = new Bing();
12964 var translatedText = await bing.TranslateAsync(str,
12966 langTo: this.SettingDialog.TranslateLanguage);
12968 this.PostBrowser.DocumentText = this.createDetailHtml(translatedText);
12970 catch (HttpRequestException e)
12972 this.StatusLabel.Text = "Err:" + e.Message;
12976 private async void TranslationToolStripMenuItem_Click(object sender, EventArgs e)
12978 if (!this.ExistCurrentPost)
12981 await this.doTranslation(this._curPost.TextFromApi);
12984 private async void SelectionTranslationToolStripMenuItem_Click(object sender, EventArgs e)
12986 var text = this.WebBrowser_GetSelectionText(ref this.PostBrowser);
12987 await this.doTranslation(text);
12990 private bool ExistCurrentPost
12994 if (_curPost == null) return false;
12995 if (_curPost.IsDeleted) return false;
13000 private void ShowUserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13002 ShowUserTimeline();
13005 public bool FavEventChangeUnread
13007 get { return SettingDialog.FavEventUnread; }
13010 private string GetUserIdFromCurPostOrInput(string caption)
13013 if (_curPost != null)
13015 id = _curPost.ScreenName;
13017 using (InputTabName inputName = new InputTabName())
13019 inputName.FormTitle = caption;
13020 inputName.FormDescription = Properties.Resources.FRMessage1;
13021 inputName.TabName = id;
13022 if (inputName.ShowDialog() == DialogResult.OK &&
13023 !string.IsNullOrEmpty(inputName.TabName.Trim()))
13025 id = inputName.TabName.Trim();
13035 private void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
13037 string id = GetUserIdFromCurPostOrInput("Show UserTimeline");
13038 if (!string.IsNullOrEmpty(id))
13040 AddNewTabForUserTimeline(id);
13044 private void UserFavorareToolStripMenuItem_Click(object sender, EventArgs e)
13046 string id = GetUserIdFromCurPostOrInput("Show Favstar");
13047 if (!string.IsNullOrEmpty(id))
13049 OpenUriAsync(Properties.Resources.FavstarUrl + "users/" + id + "/recent");
13053 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
13055 if (e.Mode == Microsoft.Win32.PowerModes.Resume) osResumed = true;
13058 private void TimelineRefreshEnableChange(bool isEnable)
13062 tw.StartUserStream();
13066 tw.StopUserStream();
13068 TimerTimeline.Enabled = isEnable;
13071 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
13073 TimelineRefreshEnableChange(!StopRefreshAllMenuItem.Checked);
13076 private void OpenUserAppointUrl()
13078 if (SettingDialog.UserAppointUrl != null)
13080 if (SettingDialog.UserAppointUrl.Contains("{ID}") || SettingDialog.UserAppointUrl.Contains("{STATUS}"))
13082 if (_curPost != null)
13084 string xUrl = SettingDialog.UserAppointUrl;
13085 xUrl = xUrl.Replace("{ID}", _curPost.ScreenName);
13086 if (_curPost.RetweetedId != null)
13088 xUrl = xUrl.Replace("{STATUS}", _curPost.RetweetedId.ToString());
13092 xUrl = xUrl.Replace("{STATUS}", _curPost.StatusId.ToString());
13094 OpenUriAsync(xUrl);
13099 OpenUriAsync(SettingDialog.UserAppointUrl);
13104 private void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
13106 OpenUserAppointUrl();
13109 private void SourceCopyMenuItem_Click(object sender, EventArgs e)
13111 string selText = SourceLinkLabel.Text;
13114 Clipboard.SetDataObject(selText, false, 5, 100);
13116 catch (Exception ex)
13118 MessageBox.Show(ex.Message);
13122 private void SourceUrlCopyMenuItem_Click(object sender, EventArgs e)
13124 string selText = (string)SourceLinkLabel.Tag;
13127 Clipboard.SetDataObject(selText, false, 5, 100);
13129 catch (Exception ex)
13131 MessageBox.Show(ex.Message);
13135 private void ContextMenuSource_Opening(object sender, CancelEventArgs e)
13137 if (_curPost == null || !ExistCurrentPost || _curPost.IsDm)
13139 SourceCopyMenuItem.Enabled = false;
13140 SourceUrlCopyMenuItem.Enabled = false;
13144 SourceCopyMenuItem.Enabled = true;
13145 SourceUrlCopyMenuItem.Enabled = true;
13149 private void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
13151 if (Form.ActiveForm == null)
13153 this.BeginInvoke((Action) (() =>
13155 this.Visible = true;
13156 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
13158 this.BringToFront();
13159 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
13161 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
13165 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
13171 private void ReplaceAppName()
13173 MatomeMenuItem.Text = MyCommon.ReplaceAppName(MatomeMenuItem.Text);
13174 AboutMenuItem.Text = MyCommon.ReplaceAppName(AboutMenuItem.Text);
13177 private void tweetThumbnail1_ThumbnailLoading(object sender, EventArgs e)
13179 this.SplitContainer3.Panel2Collapsed = false;
13181 // PreviewDistance が起動のたびに広がっていく問題の回避策
13182 // FixedPanel が Panel2 に設定された状態で Panel2 を開くと、初回だけ SplitterDistance が再計算されておかしくなるため、
13183 // None で開いた後に設定するようにする
13184 if (this.SplitContainer3.FixedPanel == FixedPanel.None)
13185 this.SplitContainer3.FixedPanel = FixedPanel.Panel2;
13188 private void tweetThumbnail1_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
13190 this.OpenThumbnailPicture(e.Thumbnail);
13193 private void tweetThumbnail1_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
13195 this.OpenUriAsync(e.ImageUrl);
13198 private void OpenThumbnailPicture(ThumbnailInfo thumbnail)
13200 this.OpenUriAsync(Uri.EscapeUriString(thumbnail.ImageUrl));
13203 private void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
13205 this.OpenUriAsync(Twitter.ServiceAvailabilityStatusUrl);
13208 private void PostButton_KeyDown(object sender, KeyEventArgs e)
13210 if (e.KeyCode == Keys.Space)
13212 this.JumpUnreadMenuItem_Click(null, null);
13214 e.SuppressKeyPress = true;
13218 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
13220 this.IconSizeNoneToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.IconNone;
13221 this.IconSize16ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon16;
13222 this.IconSize24ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon24;
13223 this.IconSize48ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48;
13224 this.IconSize48_2ToolStripMenuItem.Checked = SettingDialog.IconSz == MyCommon.IconSizes.Icon48_2;
13226 this.LockListSortOrderToolStripMenuItem.Checked = SettingDialog.SortOrderLock;
13229 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
13231 ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
13234 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
13236 ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
13239 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
13241 ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
13244 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
13246 ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
13249 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
13251 ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
13254 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
13256 if (SettingDialog.IconSz == iconSize) return;
13258 var oldIconCol = _iconCol;
13260 SettingDialog.IconSz = iconSize;
13261 ApplyListViewIconSize(iconSize);
13263 if (_iconCol != oldIconCol)
13265 foreach (TabPage tp in ListTab.TabPages)
13267 ResetColumns((DetailsListView)tp.Tag);
13271 if (_curList != null) _curList.Refresh();
13273 _modifySettingCommon = true;
13276 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
13278 var state = this.LockListSortOrderToolStripMenuItem.Checked;
13279 if (SettingDialog.SortOrderLock == state) return;
13281 SettingDialog.SortOrderLock = state;
13283 _modifySettingCommon = true;