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.
30 // "c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
31 // "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
34 using System.Collections.Concurrent;
35 using System.Collections.Generic;
36 using System.ComponentModel;
37 using System.Diagnostics;
38 using System.Diagnostics.CodeAnalysis;
40 using System.Globalization;
45 using System.Net.Http;
46 using System.Reflection;
47 using System.Runtime.InteropServices;
49 using System.Text.RegularExpressions;
50 using System.Threading;
51 using System.Threading.Tasks;
52 using System.Windows.Forms;
54 using OpenTween.Api.DataModel;
55 using OpenTween.Connection;
56 using OpenTween.MediaUploadServices;
57 using OpenTween.Models;
58 using OpenTween.OpenTweenCustomControl;
59 using OpenTween.Setting;
60 using OpenTween.Thumbnail;
64 public partial class TweenMain : OTBaseForm
68 /// <summary>画面サイズ</summary>
71 /// <summary>画面位置</summary>
74 /// <summary>区切り位置</summary>
77 /// <summary>発言欄区切り位置</summary>
80 /// <summary>プレビュー区切り位置</summary>
83 /// <summary>アイコンサイズ</summary>
85 /// 現在は16、24、48の3種類。将来直接数字指定可能とする
86 /// 注:24x24の場合に26と指定しているのはMSゴシック系フォントのための仕様
90 private bool iconCol; // 1列表示の時true(48サイズのとき)
93 private bool initial; // true:起動時処理中
94 private bool initialLayout = true;
95 private bool ignoreConfigSave; // true:起動時処理中
97 /// <summary>タブドラッグ中フラグ(DoDragDropを実行するかの判定用)</summary>
100 private TabPage? beforeSelectedTab; // タブが削除されたときに前回選択されていたときのタブを選択する為に保持
101 private Point tabMouseDownPoint;
103 /// <summary>右クリックしたタブの名前(Tabコントロール機能不足対応)</summary>
104 private string? rclickTabName;
106 private readonly object syncObject = new object(); // ロック用
108 private const string DetailHtmlFormatHead =
109 "<head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\">"
110 + "<style type=\"text/css\"><!-- "
111 + "body, p, pre {margin: 0;} "
112 + "body {font-family: \"%FONT_FAMILY%\", sans-serif; font-size: %FONT_SIZE%pt; background-color:rgb(%BG_COLOR%); word-wrap: break-word; color:rgb(%FONT_COLOR%);} "
113 + "pre {font-family: inherit;} "
114 + "a:link, a:visited, a:active, a:hover {color:rgb(%LINK_COLOR%); } "
115 + "img.emoji {width: 1em; height: 1em; margin: 0 .05em 0 .1em; vertical-align: -0.1em; border: none;} "
116 + ".quote-tweet {border: 1px solid #ccc; margin: 1em; padding: 0.5em;} "
117 + ".quote-tweet.reply {border-color: rgb(%BG_REPLY_COLOR%);} "
118 + ".quote-tweet-link {color: inherit !important; text-decoration: none;}"
122 private const string DetailHtmlFormatTemplateMono =
123 "<html>" + DetailHtmlFormatHead + "<body><pre>%CONTENT_HTML%</pre></body></html>";
125 private const string DetailHtmlFormatTemplateNormal =
126 "<html>" + DetailHtmlFormatHead + "<body><p>%CONTENT_HTML%</p></body></html>";
128 private string detailHtmlFormatPreparedTemplate = null!;
130 private bool myStatusError = false;
131 private bool myStatusOnline = false;
132 private bool soundfileListup = false;
133 private FormWindowState formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
136 private readonly TwitterApi twitterApi = new TwitterApi(ApplicationSettings.TwitterConsumerKey, ApplicationSettings.TwitterConsumerSecret);
137 private Twitter tw = null!;
140 private readonly GrowlHelper gh = new GrowlHelper(ApplicationSettings.ApplicationName);
144 /// <summary>検索画面インスタンス</summary>
145 internal SearchWordDialog SearchDialog = new SearchWordDialog();
147 private readonly OpenURL urlDialog = new OpenURL();
149 /// <summary>@id補助</summary>
150 public AtIdSupplement AtIdSupl = null!;
152 /// <summary>Hashtag補助</summary>
153 public AtIdSupplement HashSupl = null!;
155 public HashtagManage HashMgr = null!;
159 /// <summary>未読用フォント</summary>
160 private Font fntUnread = null!;
162 /// <summary>未読用文字色</summary>
163 private Color clUnread;
165 /// <summary>既読用フォント</summary>
166 private Font fntReaded = null!;
168 /// <summary>既読用文字色</summary>
169 private Color clReaded;
171 /// <summary>Fav用文字色</summary>
174 /// <summary>片思い用文字色</summary>
177 /// <summary>Retweet用文字色</summary>
178 private Color clRetweet;
180 /// <summary>選択中の行用文字色</summary>
181 private readonly Color clHighLight = Color.FromKnownColor(KnownColor.HighlightText);
183 /// <summary>発言詳細部用フォント</summary>
184 private Font fntDetail = null!;
186 /// <summary>発言詳細部用色</summary>
187 private Color clDetail;
189 /// <summary>発言詳細部用リンク文字色</summary>
190 private Color clDetailLink;
192 /// <summary>発言詳細部用背景色</summary>
193 private Color clDetailBackcolor;
195 /// <summary>自分の発言用背景色</summary>
196 private Color clSelf;
198 /// <summary>自分宛返信用背景色</summary>
199 private Color clAtSelf;
201 /// <summary>選択発言者の他の発言用背景色</summary>
202 private Color clTarget;
204 /// <summary>選択発言中の返信先用背景色</summary>
205 private Color clAtTarget;
207 /// <summary>選択発言者への返信発言用背景色</summary>
208 private Color clAtFromTarget;
210 /// <summary>選択発言の唯一@先</summary>
211 private Color clAtTo;
213 /// <summary>リスト部通常発言背景色</summary>
214 private Color clListBackcolor;
216 /// <summary>入力欄背景色</summary>
217 private Color clInputBackcolor;
219 /// <summary>入力欄文字色</summary>
220 private Color clInputFont;
222 /// <summary>入力欄フォント</summary>
223 private Font fntInputFont = null!;
225 /// <summary>アイコン画像リスト</summary>
226 private ImageCache iconCache = null!;
228 /// <summary>タスクトレイアイコン:通常時 (At.ico)</summary>
229 private Icon nIconAt = null!;
231 /// <summary>タスクトレイアイコン:通信エラー時 (AtRed.ico)</summary>
232 private Icon nIconAtRed = null!;
234 /// <summary>タスクトレイアイコン:オフライン時 (AtSmoke.ico)</summary>
235 private Icon nIconAtSmoke = null!;
237 /// <summary>タスクトレイアイコン:更新中 (Refresh.ico)</summary>
238 private Icon[] nIconRefresh = new Icon[4];
240 /// <summary>未読のあるタブ用アイコン (Tab.ico)</summary>
241 private Icon tabIcon = null!;
243 /// <summary>画面左上のアイコン (Main.ico)</summary>
244 private Icon mainIcon = null!;
246 private Icon replyIcon = null!;
247 private Icon replyIconBlink = null!;
249 private readonly ImageList listViewImageList = new ImageList(); // ListViewItemの高さ変更用
251 private PostClass? anchorPost;
252 private bool anchorFlag; // true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
254 /// <summary>発言履歴</summary>
255 private readonly List<StatusTextHistory> history = new List<StatusTextHistory>();
257 /// <summary>発言履歴カレントインデックス</summary>
260 // 発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
262 /// <summary>リプライ先のステータスID・スクリーン名</summary>
263 private (long StatusId, string ScreenName)? inReplyTo = null;
266 private readonly List<DateTimeUtc> postTimestamps = new List<DateTimeUtc>();
267 private readonly List<DateTimeUtc> favTimestamps = new List<DateTimeUtc>();
270 private readonly SolidBrush brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
271 private SolidBrush brsBackColorMine = null!;
272 private SolidBrush brsBackColorAt = null!;
273 private SolidBrush brsBackColorYou = null!;
274 private SolidBrush brsBackColorAtYou = null!;
275 private SolidBrush brsBackColorAtFromTarget = null!;
276 private SolidBrush brsBackColorAtTo = null!;
277 private SolidBrush brsBackColorNone = null!;
279 /// <summary>Listにフォーカスないときの選択行の背景色</summary>
280 private readonly SolidBrush brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace));
282 private readonly StringFormat sfTab = new StringFormat();
284 //////////////////////////////////////////////////////////////////////////////////////////////////////////
285 private TabInformations statuses = null!;
288 /// 現在表示している発言一覧の <see cref="ListView"/> に対するキャッシュ
291 /// キャッシュクリアのために null が代入されることがあるため、
292 /// 使用する場合には <see cref="listItemCache"/> に対して直接メソッド等を呼び出さずに
293 /// 一旦ローカル変数に代入してから参照すること。
295 private ListViewItemCache? listItemCache = null;
297 internal class ListViewItemCache
299 /// <summary>アイテムをキャッシュする対象の <see cref="ListView"/></summary>
300 public ListView TargetList { get; set; } = null!;
302 /// <summary>キャッシュする範囲の開始インデックス</summary>
303 public int StartIndex { get; set; }
305 /// <summary>キャッシュする範囲の終了インデックス</summary>
306 public int EndIndex { get; set; }
308 /// <summary>キャッシュされた範囲に対応する <see cref="ListViewItem"/> と <see cref="PostClass"/> の組</summary>
309 public (ListViewItem, PostClass)[] Cache { get; set; } = null!;
311 /// <summary>キャッシュされたアイテムの件数</summary>
313 => this.EndIndex - this.StartIndex + 1;
315 /// <summary>指定されたインデックスがキャッシュの範囲内であるか判定します</summary>
316 /// <returns><paramref name="index"/> がキャッシュの範囲内であれば true、それ以外は false</returns>
317 public bool Contains(int index)
318 => index >= this.StartIndex && index <= this.EndIndex;
320 /// <summary>指定されたインデックスの範囲が全てキャッシュの範囲内であるか判定します</summary>
321 /// <returns><paramref name="rangeStart"/> から <paramref name="rangeEnd"/> の範囲が全てキャッシュの範囲内であれば true、それ以外は false</returns>
322 public bool IsSupersetOf(int rangeStart, int rangeEnd)
323 => rangeStart >= this.StartIndex && rangeEnd <= this.EndIndex;
325 /// <summary>指定されたインデックスの <see cref="ListViewItem"/> と <see cref="PostClass"/> をキャッシュから取得することを試みます</summary>
326 /// <returns>取得に成功すれば true、それ以外は false</returns>
327 public bool TryGetValue(int index, [NotNullWhen(true)] out ListViewItem? item, [NotNullWhen(true)] out PostClass? post)
329 if (this.Contains(index))
331 (item, post) = this.Cache[index - this.StartIndex];
343 private bool isColumnChanged = false;
345 private const int MaxWorderThreads = 20;
346 private readonly SemaphoreSlim workerSemaphore = new SemaphoreSlim(MaxWorderThreads);
347 private readonly CancellationTokenSource workerCts = new CancellationTokenSource();
348 private readonly IProgress<string> workerProgress = null!;
350 private int unreadCounter = -1;
351 private int unreadAtCounter = -1;
353 private readonly string[] columnOrgText = new string[9];
354 private readonly string[] columnText = new string[9];
356 private bool doFavRetweetFlags = false;
358 //////////////////////////////////////////////////////////////////////////////////////////////////////////
360 private readonly TimelineScheduler timelineScheduler = new TimelineScheduler();
361 private DebounceTimer selectionDebouncer = null!;
362 private DebounceTimer saveConfigDebouncer = null!;
364 private string recommendedStatusFooter = null!;
365 private bool urlMultibyteSplit = false;
366 private bool preventSmsCommand = true;
369 private struct UrlUndo
371 public string Before;
375 private List<UrlUndo>? urlUndoBuffer = null;
377 private readonly struct ReplyChain
379 public readonly long OriginalId;
380 public readonly long InReplyToId;
381 public readonly TabModel OriginalTab;
383 public ReplyChain(long originalId, long inReplyToId, TabModel originalTab)
385 this.OriginalId = originalId;
386 this.InReplyToId = inReplyToId;
387 this.OriginalTab = originalTab;
391 /// <summary>[, ]でのリプライ移動の履歴</summary>
392 private Stack<ReplyChain>? replyChains;
394 /// <summary>ポスト選択履歴</summary>
395 private readonly Stack<(TabModel, PostClass?)> selectPostChains = new Stack<(TabModel, PostClass?)>();
397 public TabModel CurrentTab
398 => this.statuses.SelectedTab;
400 public string CurrentTabName
401 => this.statuses.SelectedTabName;
403 public TabPage CurrentTabPage
404 => this.ListTab.TabPages[this.statuses.Tabs.IndexOf(this.CurrentTabName)];
406 public DetailsListView CurrentListView
407 => (DetailsListView)this.CurrentTabPage.Tag;
409 public PostClass? CurrentPost
410 => this.CurrentTab.SelectedPost;
412 /// <summary>検索処理タイプ</summary>
413 internal enum SEARCHTYPE
420 private class StatusTextHistory
422 public string Status { get; } = "";
424 public (long StatusId, string ScreenName)? InReplyTo { get; } = null;
426 /// <summary>画像投稿サービス名</summary>
427 public string ImageService { get; set; } = "";
429 public IMediaItem[]? MediaItems { get; set; } = null;
431 public StatusTextHistory()
435 public StatusTextHistory(string status, (long StatusId, string ScreenName)? inReplyTo)
437 this.Status = status;
438 this.InReplyTo = inReplyTo;
442 private void TweenMain_Activated(object sender, EventArgs e)
444 // 画面がアクティブになったら、発言欄の背景色戻す
445 if (this.StatusText.Focused)
447 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
451 private bool disposed = false;
454 /// 使用中のリソースをすべてクリーンアップします。
456 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
457 protected override void Dispose(bool disposing)
459 base.Dispose(disposing);
466 this.components?.Dispose();
469 this.SearchDialog.Dispose();
470 this.urlDialog.Dispose();
471 this.nIconAt?.Dispose();
472 this.nIconAtRed?.Dispose();
473 this.nIconAtSmoke?.Dispose();
474 foreach (var iconRefresh in this.nIconRefresh)
476 iconRefresh?.Dispose();
478 this.tabIcon?.Dispose();
479 this.mainIcon?.Dispose();
480 this.replyIcon?.Dispose();
481 this.replyIconBlink?.Dispose();
482 this.listViewImageList.Dispose();
483 this.brsHighLight.Dispose();
484 this.brsBackColorMine?.Dispose();
485 this.brsBackColorAt?.Dispose();
486 this.brsBackColorYou?.Dispose();
487 this.brsBackColorAtYou?.Dispose();
488 this.brsBackColorAtFromTarget?.Dispose();
489 this.brsBackColorAtTo?.Dispose();
490 this.brsBackColorNone?.Dispose();
491 this.brsDeactiveSelection?.Dispose();
492 this.sfTab.Dispose();
494 this.timelineScheduler.Dispose();
495 this.workerCts.Cancel();
497 if (this.iconCache != null)
499 this.iconCache.CancelAsync();
500 this.iconCache.Dispose();
503 this.thumbnailTokenSource?.Dispose();
505 this.twitterApi.Dispose();
506 this.hookGlobalHotkey.Dispose();
509 // 終了時にRemoveHandlerしておかないとメモリリークする
510 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
511 Microsoft.Win32.SystemEvents.PowerModeChanged -= this.SystemEvents_PowerModeChanged;
512 Microsoft.Win32.SystemEvents.TimeChanged -= this.SystemEvents_TimeChanged;
514 this.disposed = true;
517 private void LoadIcons()
519 // Icons フォルダ以下のアイコンを読み込み(着せ替えアイコン対応)
520 var iconsDir = Path.Combine(Application.StartupPath, "Icons");
523 var iconMain = this.LoadIcon(Path.Combine(iconsDir, "MIcon.ico"));
526 var iconTab = this.LoadIcon(Path.Combine(iconsDir, "Tab.ico"));
529 var iconAt = this.LoadIcon(Path.Combine(iconsDir, "At.ico"));
532 var iconAtRed = this.LoadIcon(Path.Combine(iconsDir, "AtRed.ico"));
534 // タスクトレイ: オフライン時アイコン
535 var iconAtSmoke = this.LoadIcon(Path.Combine(iconsDir, "AtSmoke.ico"));
537 // タスクトレイ: Reply通知アイコン (最大2枚でアニメーション可能)
538 var iconReply = this.LoadIcon(Path.Combine(iconsDir, "Reply.ico"));
539 var iconReplyBlink = this.LoadIcon(Path.Combine(iconsDir, "ReplyBlink.ico"));
541 // タスクトレイ: 更新中アイコン (最大4枚でアニメーション可能)
542 var iconRefresh1 = this.LoadIcon(Path.Combine(iconsDir, "Refresh.ico"));
543 var iconRefresh2 = this.LoadIcon(Path.Combine(iconsDir, "Refresh2.ico"));
544 var iconRefresh3 = this.LoadIcon(Path.Combine(iconsDir, "Refresh3.ico"));
545 var iconRefresh4 = this.LoadIcon(Path.Combine(iconsDir, "Refresh4.ico"));
547 // 読み込んだアイコンを設定 (不足するアイコンはデフォルトのものを設定)
549 this.mainIcon = iconMain ?? Properties.Resources.MIcon;
550 this.tabIcon = iconTab ?? Properties.Resources.TabIcon;
551 this.nIconAt = iconAt ?? iconMain ?? Properties.Resources.At;
552 this.nIconAtRed = iconAtRed ?? Properties.Resources.AtRed;
553 this.nIconAtSmoke = iconAtSmoke ?? Properties.Resources.AtSmoke;
555 if (iconReply != null && iconReplyBlink != null)
557 this.replyIcon = iconReply;
558 this.replyIconBlink = iconReplyBlink;
562 this.replyIcon = iconReply ?? iconReplyBlink ?? Properties.Resources.Reply;
563 this.replyIconBlink = this.nIconAt;
566 if (iconRefresh1 == null)
568 this.nIconRefresh = new[]
570 Properties.Resources.Refresh, Properties.Resources.Refresh2,
571 Properties.Resources.Refresh3, Properties.Resources.Refresh4,
574 else if (iconRefresh2 == null)
576 this.nIconRefresh = new[] { iconRefresh1 };
578 else if (iconRefresh3 == null)
580 this.nIconRefresh = new[] { iconRefresh1, iconRefresh2 };
582 else if (iconRefresh4 == null)
584 this.nIconRefresh = new[] { iconRefresh1, iconRefresh2, iconRefresh3 };
586 else // iconRefresh1 から iconRefresh4 まで全て揃っている
588 this.nIconRefresh = new[] { iconRefresh1, iconRefresh2, iconRefresh3, iconRefresh4 };
592 private Icon? LoadIcon(string filePath)
594 if (!File.Exists(filePath))
599 return new Icon(filePath);
607 private void InitColumns(ListView list, bool startup)
609 this.InitColumnText();
611 ColumnHeader[]? columns = null;
618 new ColumnHeader(), // アイコン
619 new ColumnHeader(), // 本文
622 columns[0].Text = this.columnText[0];
623 columns[1].Text = this.columnText[2];
627 var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / SettingManager.Local.ScaleDimension.Width;
629 columns[0].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width1);
630 columns[1].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width3);
631 columns[0].DisplayIndex = 0;
632 columns[1].DisplayIndex = 1;
637 foreach (var curListColumn in this.CurrentListView.Columns.Cast<ColumnHeader>())
639 columns[idx].Width = curListColumn.Width;
640 columns[idx].DisplayIndex = curListColumn.DisplayIndex;
649 new ColumnHeader(), // アイコン
650 new ColumnHeader(), // ニックネーム
651 new ColumnHeader(), // 本文
652 new ColumnHeader(), // 日付
653 new ColumnHeader(), // ユーザID
654 new ColumnHeader(), // 未読
655 new ColumnHeader(), // マーク&プロテクト
656 new ColumnHeader(), // ソース
659 foreach (var i in Enumerable.Range(0, columns.Length))
660 columns[i].Text = this.columnText[i];
664 var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / SettingManager.Local.ScaleDimension.Width;
666 columns[0].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width1);
667 columns[1].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width2);
668 columns[2].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width3);
669 columns[3].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width4);
670 columns[4].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width5);
671 columns[5].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width6);
672 columns[6].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width7);
673 columns[7].Width = ScaleBy(widthScaleFactor, SettingManager.Local.Width8);
675 var displayIndex = new[]
677 SettingManager.Local.DisplayIndex1, SettingManager.Local.DisplayIndex2,
678 SettingManager.Local.DisplayIndex3, SettingManager.Local.DisplayIndex4,
679 SettingManager.Local.DisplayIndex5, SettingManager.Local.DisplayIndex6,
680 SettingManager.Local.DisplayIndex7, SettingManager.Local.DisplayIndex8,
683 foreach (var i in Enumerable.Range(0, displayIndex.Length))
685 columns[i].DisplayIndex = displayIndex[i];
691 foreach (var curListColumn in this.CurrentListView.Columns.Cast<ColumnHeader>())
693 columns[idx].Width = curListColumn.Width;
694 columns[idx].DisplayIndex = curListColumn.DisplayIndex;
700 list.Columns.AddRange(columns);
708 foreach (var column in columns)
714 private void InitColumnText()
716 this.columnText[0] = "";
717 this.columnText[1] = Properties.Resources.AddNewTabText2;
718 this.columnText[2] = Properties.Resources.AddNewTabText3;
719 this.columnText[3] = Properties.Resources.AddNewTabText4_2;
720 this.columnText[4] = Properties.Resources.AddNewTabText5;
721 this.columnText[5] = "";
722 this.columnText[6] = "";
723 this.columnText[7] = "Source";
725 this.columnOrgText[0] = "";
726 this.columnOrgText[1] = Properties.Resources.AddNewTabText2;
727 this.columnOrgText[2] = Properties.Resources.AddNewTabText3;
728 this.columnOrgText[3] = Properties.Resources.AddNewTabText4_2;
729 this.columnOrgText[4] = Properties.Resources.AddNewTabText5;
730 this.columnOrgText[5] = "";
731 this.columnOrgText[6] = "";
732 this.columnOrgText[7] = "Source";
734 var c = this.statuses.SortMode switch
736 ComparerMode.Nickname => 1, // ニックネーム
737 ComparerMode.Data => 2, // 本文
738 ComparerMode.Id => 3, // 時刻=発言Id
739 ComparerMode.Name => 4, // 名前
740 ComparerMode.Source => 7, // Source
746 if (this.statuses.SortOrder == SortOrder.Descending)
748 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
749 this.columnText[2] = this.columnOrgText[2] + "▾";
753 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
754 this.columnText[2] = this.columnOrgText[2] + "▴";
759 if (this.statuses.SortOrder == SortOrder.Descending)
761 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
762 this.columnText[c] = this.columnOrgText[c] + "▾";
766 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
767 this.columnText[c] = this.columnOrgText[c] + "▴";
772 private void InitializeTraceFrag()
775 this.TraceOutToolStripMenuItem.Checked = true;
776 MyCommon.TraceFlag = true;
778 if (!MyCommon.FileVersion.EndsWith("0", StringComparison.Ordinal))
780 this.TraceOutToolStripMenuItem.Checked = true;
781 MyCommon.TraceFlag = true;
785 private void TweenMain_Load(object sender, EventArgs e)
787 this.ignoreConfigSave = true;
788 this.Visible = false;
790 if (ApplicationEvents.StartupOptions.ContainsKey("d"))
791 MyCommon.TraceFlag = true;
793 this.InitializeTraceFrag();
795 Microsoft.Win32.SystemEvents.PowerModeChanged += this.SystemEvents_PowerModeChanged;
797 Regex.CacheSize = 100;
800 this.statuses = TabInformations.GetInstance();
804 this.Icon = this.mainIcon; // メインフォーム(TweenMain)
805 this.NotifyIcon1.Icon = this.nIconAt; // タスクトレイ
806 this.TabImage.Images.Add(this.tabIcon); // タブ見出し
808 // <<<<<<<<<設定関連>>>>>>>>>
812 // 現在の DPI と設定保存時の DPI との比を取得する
813 var configScaleFactor = SettingManager.Local.GetConfigScaleFactor(this.CurrentAutoScaleDimensions);
816 var fontUIGlobal = SettingManager.Local.FontUIGlobal;
817 if (fontUIGlobal != null)
819 OTBaseForm.GlobalFont = fontUIGlobal;
820 this.Font = fontUIGlobal;
824 if (!ApplicationEvents.StartupOptions.ContainsKey("nolimit"))
826 if (SettingManager.Common.TimelinePeriod < 15 && SettingManager.Common.TimelinePeriod > 0)
827 SettingManager.Common.TimelinePeriod = 15;
829 if (SettingManager.Common.ReplyPeriod < 15 && SettingManager.Common.ReplyPeriod > 0)
830 SettingManager.Common.ReplyPeriod = 15;
832 if (SettingManager.Common.DMPeriod < 15 && SettingManager.Common.DMPeriod > 0)
833 SettingManager.Common.DMPeriod = 15;
835 if (SettingManager.Common.PubSearchPeriod < 30 && SettingManager.Common.PubSearchPeriod > 0)
836 SettingManager.Common.PubSearchPeriod = 30;
838 if (SettingManager.Common.UserTimelinePeriod < 15 && SettingManager.Common.UserTimelinePeriod > 0)
839 SettingManager.Common.UserTimelinePeriod = 15;
841 if (SettingManager.Common.ListsPeriod < 15 && SettingManager.Common.ListsPeriod > 0)
842 SettingManager.Common.ListsPeriod = 15;
845 if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, SettingManager.Common.CountApi))
846 SettingManager.Common.CountApi = 60;
847 if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, SettingManager.Common.CountApiReply))
848 SettingManager.Common.CountApiReply = 40;
850 if (SettingManager.Common.MoreCountApi != 0 && !Twitter.VerifyMoreApiResultCount(SettingManager.Common.MoreCountApi))
851 SettingManager.Common.MoreCountApi = 200;
852 if (SettingManager.Common.FirstCountApi != 0 && !Twitter.VerifyFirstApiResultCount(SettingManager.Common.FirstCountApi))
853 SettingManager.Common.FirstCountApi = 100;
855 if (SettingManager.Common.FavoritesCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, SettingManager.Common.FavoritesCountApi))
856 SettingManager.Common.FavoritesCountApi = 40;
857 if (SettingManager.Common.ListCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.List, SettingManager.Common.ListCountApi))
858 SettingManager.Common.ListCountApi = 100;
859 if (SettingManager.Common.SearchCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, SettingManager.Common.SearchCountApi))
860 SettingManager.Common.SearchCountApi = 100;
861 if (SettingManager.Common.UserTimelineCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, SettingManager.Common.UserTimelineCountApi))
862 SettingManager.Common.UserTimelineCountApi = 20;
864 // 廃止サービスが選択されていた場合ux.nuへ読み替え
865 if (SettingManager.Common.AutoShortUrlFirst < 0)
866 SettingManager.Common.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
868 TwitterApiConnection.RestApiHost = SettingManager.Common.TwitterApiHost;
869 this.tw = new Twitter(this.twitterApi);
872 if (MyCommon.IsNullOrEmpty(SettingManager.Common.Token)) SettingManager.Common.UserName = "";
873 this.tw.Initialize(SettingManager.Common.Token, SettingManager.Common.TokenSecret, SettingManager.Common.UserName, SettingManager.Common.UserId);
877 Networking.Initialize();
879 var saveRequired = false;
880 var firstRun = false;
882 // ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
883 if (MyCommon.IsNullOrEmpty(this.tw.Username))
888 // 設定せずにキャンセルされたか、設定されたが依然ユーザー名が未設定ならプログラム終了
889 if (this.ShowSettingDialog(showTaskbarIcon: true) != DialogResult.OK ||
890 MyCommon.IsNullOrEmpty(this.tw.Username))
892 Application.Exit(); // 強制終了
898 Networking.DefaultTimeout = TimeSpan.FromSeconds(SettingManager.Common.DefaultTimeOut);
899 Networking.UploadImageTimeout = TimeSpan.FromSeconds(SettingManager.Common.UploadImageTimeout);
900 Networking.SetWebProxy(
901 SettingManager.Local.ProxyType,
902 SettingManager.Local.ProxyAddress,
903 SettingManager.Local.ProxyPort,
904 SettingManager.Local.ProxyUser,
905 SettingManager.Local.ProxyPassword);
906 Networking.ForceIPv4 = SettingManager.Common.ForceIPv4;
908 TwitterApiConnection.RestApiHost = SettingManager.Common.TwitterApiHost;
909 this.tw.RestrictFavCheck = SettingManager.Common.RestrictFavCheck;
910 this.tw.ReadOwnPost = SettingManager.Common.ReadOwnPost;
911 ShortUrl.Instance.DisableExpanding = !SettingManager.Common.TinyUrlResolve;
912 ShortUrl.Instance.BitlyAccessToken = SettingManager.Common.BitlyAccessToken;
913 ShortUrl.Instance.BitlyId = SettingManager.Common.BilyUser;
914 ShortUrl.Instance.BitlyKey = SettingManager.Common.BitlyPwd;
916 // アクセストークンが有効であるか確認する
917 // ここが Twitter API への最初のアクセスになるようにすること
920 this.tw.VerifyCredentials();
922 catch (WebApiException ex)
926 string.Format(Properties.Resources.StartupAuthError_Text, ex.Message),
927 ApplicationSettings.ApplicationName,
928 MessageBoxButtons.OK,
929 MessageBoxIcon.Warning);
933 // プロキシ設定等の通信まわりの初期化が済んでから処理する
934 ThumbnailGenerator.InitializeGenerator();
936 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
937 imgazyobizinet.Enabled = SettingManager.Common.EnableImgAzyobuziNet;
938 imgazyobizinet.DisabledInDM = SettingManager.Common.ImgAzyobuziNetDisabledInDM;
940 Thumbnail.Services.TonTwitterCom.GetApiConnection = () => this.twitterApi.Connection;
943 this.ImageSelector.Initialize(this.tw, this.tw.Configuration, SettingManager.Common.UseImageServiceName, SettingManager.Common.UseImageService);
946 this.AtIdSupl = new AtIdSupplement(SettingManager.AtIdList.AtIdList, "@");
947 this.HashSupl = new AtIdSupplement(SettingManager.Common.HashTags, "#");
948 this.HashMgr = new HashtagManage(this.HashSupl,
949 SettingManager.Common.HashTags.ToArray(),
950 SettingManager.Common.HashSelected,
951 SettingManager.Common.HashIsPermanent,
952 SettingManager.Common.HashIsHead,
953 SettingManager.Common.HashIsNotAddToAtReply);
954 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash) && this.HashMgr.IsPermanent) this.HashStripSplitButton.Text = this.HashMgr.UseHash;
957 this.iconCache = new ImageCache();
958 this.tweetDetailsView.IconCache = this.iconCache;
961 this.fntUnread = SettingManager.Local.FontUnread;
962 this.clUnread = SettingManager.Local.ColorUnread;
963 this.fntReaded = SettingManager.Local.FontRead;
964 this.clReaded = SettingManager.Local.ColorRead;
965 this.clFav = SettingManager.Local.ColorFav;
966 this.clOWL = SettingManager.Local.ColorOWL;
967 this.clRetweet = SettingManager.Local.ColorRetweet;
968 this.fntDetail = SettingManager.Local.FontDetail;
969 this.clDetail = SettingManager.Local.ColorDetail;
970 this.clDetailLink = SettingManager.Local.ColorDetailLink;
971 this.clDetailBackcolor = SettingManager.Local.ColorDetailBackcolor;
972 this.clSelf = SettingManager.Local.ColorSelf;
973 this.clAtSelf = SettingManager.Local.ColorAtSelf;
974 this.clTarget = SettingManager.Local.ColorTarget;
975 this.clAtTarget = SettingManager.Local.ColorAtTarget;
976 this.clAtFromTarget = SettingManager.Local.ColorAtFromTarget;
977 this.clAtTo = SettingManager.Local.ColorAtTo;
978 this.clListBackcolor = SettingManager.Local.ColorListBackcolor;
979 this.clInputBackcolor = SettingManager.Local.ColorInputBackcolor;
980 this.clInputFont = SettingManager.Local.ColorInputFont;
981 this.fntInputFont = SettingManager.Local.FontInputFont;
983 this.brsBackColorMine = new SolidBrush(this.clSelf);
984 this.brsBackColorAt = new SolidBrush(this.clAtSelf);
985 this.brsBackColorYou = new SolidBrush(this.clTarget);
986 this.brsBackColorAtYou = new SolidBrush(this.clAtTarget);
987 this.brsBackColorAtFromTarget = new SolidBrush(this.clAtFromTarget);
988 this.brsBackColorAtTo = new SolidBrush(this.clAtTo);
989 this.brsBackColorNone = new SolidBrush(this.clListBackcolor);
991 // StringFormatオブジェクトへの事前設定
992 this.sfTab.Alignment = StringAlignment.Center;
993 this.sfTab.LineAlignment = StringAlignment.Center;
995 this.InitDetailHtmlFormat();
996 this.tweetDetailsView.ClearPostBrowser();
998 this.recommendedStatusFooter = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
1000 this.history.Add(new StatusTextHistory());
1002 this.inReplyTo = null;
1005 this.SearchDialog.Owner = this;
1006 this.urlDialog.Owner = this;
1008 // 新着バルーン通知のチェック状態設定
1009 this.NewPostPopMenuItem.Checked = SettingManager.Common.NewAllPop;
1010 this.NotifyFileMenuItem.Checked = this.NewPostPopMenuItem.Checked;
1012 // 新着取得時のリストスクロールをするか。trueならスクロールしない
1013 this.ListLockMenuItem.Checked = SettingManager.Common.ListLock;
1014 this.LockListFileMenuItem.Checked = SettingManager.Common.ListLock;
1015 // サウンド再生(タブ別設定より優先)
1016 this.PlaySoundMenuItem.Checked = SettingManager.Common.PlaySound;
1017 this.PlaySoundFileMenuItem.Checked = SettingManager.Common.PlaySound;
1020 this.ClientSize = ScaleBy(configScaleFactor, SettingManager.Local.FormSize);
1021 this.mySize = this.ClientSize; // サイズ保持(最小化・最大化されたまま終了した場合の対応用)
1022 this.myLoc = SettingManager.Local.FormLocation;
1024 if (this.WindowState != FormWindowState.Minimized)
1026 var tbarRect = new Rectangle(this.myLoc, new Size(this.mySize.Width, SystemInformation.CaptionHeight));
1027 var outOfScreen = true;
1028 if (Screen.AllScreens.Length == 1) // ハングするとの報告
1030 foreach (var scr in Screen.AllScreens)
1032 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
1034 outOfScreen = false;
1040 this.myLoc = new Point(0, 0);
1042 this.DesktopLocation = this.myLoc;
1044 this.TopMost = SettingManager.Common.AlwaysTop;
1045 this.mySpDis = ScaleBy(configScaleFactor.Height, SettingManager.Local.SplitterDistance);
1046 this.mySpDis2 = ScaleBy(configScaleFactor.Height, SettingManager.Local.StatusTextHeight);
1047 if (SettingManager.Local.PreviewDistance == -1)
1049 this.mySpDis3 = this.mySize.Width - ScaleBy(this.CurrentScaleFactor.Width, 150);
1050 if (this.mySpDis3 < 1) this.mySpDis3 = ScaleBy(this.CurrentScaleFactor.Width, 50);
1051 SettingManager.Local.PreviewDistance = this.mySpDis3;
1055 this.mySpDis3 = ScaleBy(configScaleFactor.Width, SettingManager.Local.PreviewDistance);
1057 this.PlaySoundMenuItem.Checked = SettingManager.Common.PlaySound;
1058 this.PlaySoundFileMenuItem.Checked = SettingManager.Common.PlaySound;
1060 this.StatusText.Font = this.fntInputFont;
1061 this.StatusText.ForeColor = this.clInputFont;
1063 // SplitContainer2.Panel2MinSize を一行表示の入力欄の高さに合わせる (MS UI Gothic 12pt (96dpi) の場合は 19px)
1064 this.StatusText.Multiline = false; // SettingManager.Local.StatusMultiline の設定は後で反映される
1065 this.SplitContainer2.Panel2MinSize = this.StatusText.Height;
1067 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
1068 this.SplitContainer1.IsPanelInverted = !SettingManager.Common.StatusAreaAtBottom;
1070 // 全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
1071 if (SettingManager.Common.UnreadManage == false)
1073 this.ReadedStripMenuItem.Enabled = false;
1074 this.UnreadStripMenuItem.Enabled = false;
1077 // リンク先URL表示部の初期化(画面左下)
1078 this.StatusLabelUrl.Text = "";
1080 this.StatusLabel.Text = "";
1081 this.StatusLabel.AutoToolTip = false;
1082 this.StatusLabel.ToolTipText = "";
1084 this.lblLen.Text = this.GetRestStatusCount(this.FormatStatusTextExtended("")).ToString();
1086 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
1087 this.CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
1088 this.CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
1089 this.CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
1091 // SourceLinkLabel のテキストが SplitContainer2.Panel2.AccessibleName にセットされるのを防ぐ
1092 // (タブオーダー順で SourceLinkLabel の次にある PostBrowser が TabStop = false となっているため、
1093 // さらに次のコントロールである SplitContainer2.Panel2 の AccessibleName がデフォルトで SourceLinkLabel のテキストになってしまう)
1094 this.SplitContainer2.Panel2.AccessibleName = "";
1096 ////////////////////////////////////////////////////////////////////////////////
1097 var sortOrder = (SortOrder)SettingManager.Common.SortOrder;
1098 var mode = ComparerMode.Id;
1099 switch (SettingManager.Common.SortColumn)
1101 case 0: // 0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
1105 mode = ComparerMode.Id; // Idソートに読み替え
1108 mode = ComparerMode.Nickname;
1111 mode = ComparerMode.Data;
1114 mode = ComparerMode.Id;
1117 mode = ComparerMode.Name;
1120 mode = ComparerMode.Source;
1123 this.statuses.SetSortMode(mode, sortOrder);
1124 ////////////////////////////////////////////////////////////////////////////////
1126 this.ApplyListViewIconSize(SettingManager.Common.IconSize);
1128 // <<<<<<<<タブ関連>>>>>>>
1129 foreach (var tab in this.statuses.Tabs)
1131 if (!this.AddNewTab(tab, startup: true))
1132 throw new TabException(Properties.Resources.TweenMain_LoadText1);
1135 this.statuses.SelectTab(this.ListTab.SelectedTab.Text);
1138 this.SetTabAlignment();
1140 MyCommon.TwitterApiInfo.AccessLimitUpdated += this.TwitterApiStatus_AccessLimitUpdated;
1141 Microsoft.Win32.SystemEvents.TimeChanged += this.SystemEvents_TimeChanged;
1143 if (SettingManager.Common.TabIconDisp)
1145 this.ListTab.DrawMode = TabDrawMode.Normal;
1149 this.ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
1150 this.ListTab.DrawItem += this.ListTab_DrawItem;
1151 this.ListTab.ImageList = null;
1154 if (SettingManager.Common.HotkeyEnabled)
1157 var modKey = HookGlobalHotkey.ModKeys.None;
1158 if ((SettingManager.Common.HotkeyModifier & Keys.Alt) == Keys.Alt)
1159 modKey |= HookGlobalHotkey.ModKeys.Alt;
1160 if ((SettingManager.Common.HotkeyModifier & Keys.Control) == Keys.Control)
1161 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
1162 if ((SettingManager.Common.HotkeyModifier & Keys.Shift) == Keys.Shift)
1163 modKey |= HookGlobalHotkey.ModKeys.Shift;
1164 if ((SettingManager.Common.HotkeyModifier & Keys.LWin) == Keys.LWin)
1165 modKey |= HookGlobalHotkey.ModKeys.Win;
1167 this.hookGlobalHotkey.RegisterOriginalHotkey(SettingManager.Common.HotkeyKey, SettingManager.Common.HotkeyValue, modKey);
1170 if (SettingManager.Common.IsUseNotifyGrowl)
1171 this.gh.RegisterGrowl();
1173 this.StatusLabel.Text = Properties.Resources.Form1_LoadText1; // 画面右下の状態表示を変更
1175 this.SetMainWindowTitle();
1176 this.SetNotifyIconText();
1178 if (!SettingManager.Common.MinimizeToTray || this.WindowState != FormWindowState.Minimized)
1180 this.Visible = true;
1185 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Home] = () => this.InvokeAsync(() => this.RefreshTabAsync<HomeTabModel>());
1186 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Mention] = () => this.InvokeAsync(() => this.RefreshTabAsync<MentionsTabModel>());
1187 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Dm] = () => this.InvokeAsync(() => this.RefreshTabAsync<DirectMessagesTabModel>());
1188 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.PublicSearch] = () => this.InvokeAsync(() => this.RefreshTabAsync<PublicSearchTabModel>());
1189 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.User] = () => this.InvokeAsync(() => this.RefreshTabAsync<UserTimelineTabModel>());
1190 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.List] = () => this.InvokeAsync(() => this.RefreshTabAsync<ListTimelineTabModel>());
1191 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Config] = () => this.InvokeAsync(() => Task.WhenAll(new[]
1193 this.DoGetFollowersMenu(),
1194 this.RefreshBlockIdsAsync(),
1195 this.RefreshMuteUserIdsAsync(),
1196 this.RefreshNoRetweetIdsAsync(),
1197 this.RefreshTwitterConfigurationAsync(),
1199 this.RefreshTimelineScheduler();
1201 this.selectionDebouncer = DebounceTimer.Create(() => this.InvokeAsync(() => this.UpdateSelectedPost()), TimeSpan.FromMilliseconds(100), leading: true);
1202 this.saveConfigDebouncer = DebounceTimer.Create(() => this.InvokeAsync(() => this.SaveConfigsAll(ifModified: true)), TimeSpan.FromSeconds(1));
1205 this.TimerRefreshIcon.Interval = 200;
1206 this.TimerRefreshIcon.Enabled = false;
1208 this.ignoreConfigSave = false;
1209 this.TweenMain_Resize(this, EventArgs.Empty);
1210 if (saveRequired) this.SaveConfigsAll(false);
1212 foreach (var ua in SettingManager.Common.UserAccounts)
1214 if (ua.UserId == 0 && ua.Username.Equals(this.tw.Username, StringComparison.InvariantCultureIgnoreCase))
1216 ua.UserId = this.tw.UserId;
1223 // 初回起動時だけ右下のメニューを目立たせる
1224 this.HashStripSplitButton.ShowDropDown();
1228 private void InitDetailHtmlFormat()
1230 var htmlTemplate = SettingManager.Common.IsMonospace ? DetailHtmlFormatTemplateMono : DetailHtmlFormatTemplateNormal;
1232 this.detailHtmlFormatPreparedTemplate = htmlTemplate
1233 .Replace("%FONT_FAMILY%", this.fntDetail.Name)
1234 .Replace("%FONT_SIZE%", this.fntDetail.Size.ToString())
1235 .Replace("%FONT_COLOR%", $"{this.clDetail.R},{this.clDetail.G},{this.clDetail.B}")
1236 .Replace("%LINK_COLOR%", $"{this.clDetailLink.R},{this.clDetailLink.G},{this.clDetailLink.B}")
1237 .Replace("%BG_COLOR%", $"{this.clDetailBackcolor.R},{this.clDetailBackcolor.G},{this.clDetailBackcolor.B}")
1238 .Replace("%BG_REPLY_COLOR%", $"{this.clAtTo.R}, {this.clAtTo.G}, {this.clAtTo.B}");
1241 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
1246 txt = this.statuses.Tabs[e.Index].TabName;
1253 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
1254 if (e.State == DrawItemState.Selected)
1256 e.DrawFocusRectangle();
1261 if (this.statuses.Tabs[txt].UnreadCount > 0)
1264 fore = System.Drawing.SystemBrushes.ControlText;
1268 fore = System.Drawing.SystemBrushes.ControlText;
1270 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, this.sfTab);
1273 private void LoadConfig()
1275 SettingManager.Local = SettingManager.Local;
1277 // v1.2.4 以前の設定には ScaleDimension の項目がないため、現在の DPI と同じとして扱う
1278 if (SettingManager.Local.ScaleDimension.IsEmpty)
1279 SettingManager.Local.ScaleDimension = this.CurrentAutoScaleDimensions;
1281 var tabSettings = SettingManager.Tabs;
1282 foreach (var tabSetting in tabSettings.Tabs)
1285 switch (tabSetting.TabType)
1287 case MyCommon.TabUsageType.Home:
1288 tab = new HomeTabModel(tabSetting.TabName);
1290 case MyCommon.TabUsageType.Mentions:
1291 tab = new MentionsTabModel(tabSetting.TabName);
1293 case MyCommon.TabUsageType.DirectMessage:
1294 tab = new DirectMessagesTabModel(tabSetting.TabName);
1296 case MyCommon.TabUsageType.Favorites:
1297 tab = new FavoritesTabModel(tabSetting.TabName);
1299 case MyCommon.TabUsageType.UserDefined:
1300 tab = new FilterTabModel(tabSetting.TabName);
1302 case MyCommon.TabUsageType.UserTimeline:
1303 tab = new UserTimelineTabModel(tabSetting.TabName, tabSetting.User!);
1305 case MyCommon.TabUsageType.PublicSearch:
1306 tab = new PublicSearchTabModel(tabSetting.TabName)
1308 SearchWords = tabSetting.SearchWords,
1309 SearchLang = tabSetting.SearchLang,
1312 case MyCommon.TabUsageType.Lists:
1313 tab = new ListTimelineTabModel(tabSetting.TabName, tabSetting.ListInfo!);
1315 case MyCommon.TabUsageType.Mute:
1316 tab = new MuteTabModel(tabSetting.TabName);
1322 tab.UnreadManage = tabSetting.UnreadManage;
1323 tab.Protected = tabSetting.Protected;
1324 tab.Notify = tabSetting.Notify;
1325 tab.SoundFile = tabSetting.SoundFile;
1327 if (tab.IsDistributableTabType)
1329 var filterTab = (FilterTabModel)tab;
1330 filterTab.FilterArray = tabSetting.FilterArray;
1331 filterTab.FilterModified = false;
1334 if (this.statuses.ContainsTab(tab.TabName))
1335 tab.TabName = this.statuses.MakeTabName("MyTab");
1337 this.statuses.AddTab(tab);
1340 this.statuses.AddDefaultTabs();
1343 private void TimerInterval_Changed(object sender, IntervalChangedEventArgs e)
1345 this.RefreshTimelineScheduler();
1348 private void RefreshTimelineScheduler()
1350 static TimeSpan IntervalSecondsOrDisabled(int seconds)
1351 => seconds == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(seconds);
1353 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Home] = IntervalSecondsOrDisabled(SettingManager.Common.TimelinePeriod);
1354 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Mention] = IntervalSecondsOrDisabled(SettingManager.Common.ReplyPeriod);
1355 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Dm] = IntervalSecondsOrDisabled(SettingManager.Common.DMPeriod);
1356 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.PublicSearch] = IntervalSecondsOrDisabled(SettingManager.Common.PubSearchPeriod);
1357 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.User] = IntervalSecondsOrDisabled(SettingManager.Common.UserTimelinePeriod);
1358 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.List] = IntervalSecondsOrDisabled(SettingManager.Common.ListsPeriod);
1359 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Config] = TimeSpan.FromHours(6);
1360 this.timelineScheduler.UpdateAfterSystemResume = TimeSpan.FromSeconds(30);
1362 this.timelineScheduler.RefreshSchedule();
1365 private void MarkSettingCommonModified()
1367 if (this.saveConfigDebouncer == null)
1370 this.ModifySettingCommon = true;
1371 _ = this.saveConfigDebouncer.Call();
1374 private void MarkSettingLocalModified()
1376 if (this.saveConfigDebouncer == null)
1379 this.ModifySettingLocal = true;
1380 _ = this.saveConfigDebouncer.Call();
1383 internal void MarkSettingAtIdModified()
1385 if (this.saveConfigDebouncer == null)
1388 this.ModifySettingAtId = true;
1389 _ = this.saveConfigDebouncer.Call();
1392 private void RefreshTimeline()
1394 var curTabModel = this.CurrentTab;
1395 var curListView = this.CurrentListView;
1397 // 現在表示中のタブのスクロール位置を退避
1398 var curListScroll = this.SaveListViewScroll(curListView, curTabModel);
1400 // 各タブのリスト上の選択位置などを退避
1401 var listSelections = this.SaveListViewSelection();
1405 addCount = this.statuses.SubmitUpdate(
1407 out var notifyPosts,
1408 out var newMentionOrDm,
1411 if (MyCommon.EndingFlag) return;
1414 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
1416 var tabPage = this.ListTab.TabPages[index];
1417 var listView = (DetailsListView)tabPage.Tag;
1419 if (listView.VirtualListSize != tab.AllCount || isDelete)
1421 using (ControlTransaction.Update(listView))
1423 if (listView == curListView)
1424 this.PurgeListViewItemCache();
1429 listView.VirtualListSize = tab.AllCount;
1431 catch (NullReferenceException ex)
1433 // WinForms 内部で ListView.set_TopItem が発生させている例外
1434 // https://ja.osdn.net/ticket/browse.php?group_id=6526&tid=36588
1435 MyCommon.TraceOut(ex, $"TabType: {tab.TabType}, Count: {tab.AllCount}, ListSize: {listView.VirtualListSize}");
1439 this.RestoreListViewSelection(listView, tab, listSelections[tab.TabName]);
1446 if (SettingManager.Common.TabIconDisp)
1448 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
1450 var tabPage = this.ListTab.TabPages[index];
1451 if (tab.UnreadCount > 0 && tabPage.ImageIndex != 0)
1452 tabPage.ImageIndex = 0; // 未読アイコン
1457 this.ListTab.Refresh();
1462 this.RestoreListViewScroll(curListView, curTabModel, curListScroll);
1465 this.NotifyNewPosts(notifyPosts, soundFile, addCount, newMentionOrDm);
1467 this.SetMainWindowTitle();
1468 if (!this.StatusLabelUrl.Text.StartsWith("http", StringComparison.Ordinal)) this.SetStatusLabelUrl();
1470 this.HashSupl.AddRangeItem(this.tw.GetHashList());
1473 internal struct ListViewScroll
1475 public ScrollLockMode ScrollLockMode { get; set; }
1477 public long? TopItemStatusId { get; set; }
1480 internal enum ScrollLockMode
1482 /// <summary>固定しない</summary>
1485 /// <summary>最上部に固定する</summary>
1488 /// <summary>最下部に固定する</summary>
1491 /// <summary><see cref="ListViewScroll.TopItemStatusId"/> の位置に固定する</summary>
1496 /// <see cref="ListView"/> のスクロール位置に関する情報を <see cref="ListViewScroll"/> として返します
1498 private ListViewScroll SaveListViewScroll(DetailsListView listView, TabModel tab)
1500 var listScroll = new ListViewScroll
1502 ScrollLockMode = this.GetScrollLockMode(listView),
1505 if (listScroll.ScrollLockMode == ScrollLockMode.FixedToItem)
1507 var topItemIndex = listView.TopItem?.Index ?? -1;
1508 if (topItemIndex != -1 && topItemIndex < tab.AllCount)
1509 listScroll.TopItemStatusId = tab.GetStatusIdAt(topItemIndex);
1515 private ScrollLockMode GetScrollLockMode(DetailsListView listView)
1517 if (this.statuses.SortMode == ComparerMode.Id)
1519 if (this.statuses.SortOrder == SortOrder.Ascending)
1522 if (this.ListLockMenuItem.Checked)
1523 return ScrollLockMode.None;
1525 // 最下行が表示されていたら、最下行へ強制スクロール。最下行が表示されていなかったら制御しない
1528 var bottomItem = listView.GetItemAt(0, listView.ClientSize.Height - 1);
1529 if (bottomItem == null || bottomItem.Index == listView.VirtualListSize - 1)
1530 return ScrollLockMode.FixedToBottom;
1532 return ScrollLockMode.None;
1537 if (this.ListLockMenuItem.Checked)
1538 return ScrollLockMode.FixedToItem;
1540 // 最上行が表示されていたら、制御しない。最上行が表示されていなかったら、現在表示位置へ強制スクロール
1541 var topItem = listView.TopItem;
1542 if (topItem == null || topItem.Index == 0)
1543 return ScrollLockMode.FixedToTop;
1545 return ScrollLockMode.FixedToItem;
1550 return ScrollLockMode.FixedToItem;
1554 internal struct ListViewSelection
1556 public long[]? SelectedStatusIds { get; set; }
1558 public long? SelectionMarkStatusId { get; set; }
1560 public long? FocusedStatusId { get; set; }
1564 /// <see cref="ListView"/> の選択状態を <see cref="ListViewSelection"/> として返します
1566 private IReadOnlyDictionary<string, ListViewSelection> SaveListViewSelection()
1568 var listsDict = new Dictionary<string, ListViewSelection>();
1570 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
1572 var listView = (DetailsListView)this.ListTab.TabPages[index].Tag;
1573 listsDict[tab.TabName] = this.SaveListViewSelection(listView, tab);
1580 /// <see cref="ListView"/> の選択状態を <see cref="ListViewSelection"/> として返します
1582 private ListViewSelection SaveListViewSelection(DetailsListView listView, TabModel tab)
1584 if (listView.VirtualListSize == 0)
1586 return new ListViewSelection
1588 SelectedStatusIds = Array.Empty<long>(),
1589 SelectionMarkStatusId = null,
1590 FocusedStatusId = null,
1594 return new ListViewSelection
1596 SelectedStatusIds = tab.SelectedStatusIds,
1597 FocusedStatusId = this.GetFocusedStatusId(listView, tab),
1598 SelectionMarkStatusId = this.GetSelectionMarkStatusId(listView, tab),
1602 private long? GetFocusedStatusId(DetailsListView listView, TabModel tab)
1604 var index = listView.FocusedItem?.Index ?? -1;
1606 return index != -1 && index < tab.AllCount ? tab.GetStatusIdAt(index) : (long?)null;
1609 private long? GetSelectionMarkStatusId(DetailsListView listView, TabModel tab)
1611 var index = listView.SelectionMark;
1613 return index != -1 && index < tab.AllCount ? tab.GetStatusIdAt(index) : (long?)null;
1617 /// <see cref="SaveListViewScroll"/> によって保存されたスクロール位置を復元します
1619 private void RestoreListViewScroll(DetailsListView listView, TabModel tab, ListViewScroll listScroll)
1621 if (listView.VirtualListSize == 0)
1624 switch (listScroll.ScrollLockMode)
1626 case ScrollLockMode.FixedToTop:
1627 listView.EnsureVisible(0);
1629 case ScrollLockMode.FixedToBottom:
1630 listView.EnsureVisible(listView.VirtualListSize - 1);
1632 case ScrollLockMode.FixedToItem:
1633 var topIndex = listScroll.TopItemStatusId != null ? tab.IndexOf(listScroll.TopItemStatusId.Value) : -1;
1636 var topItem = listView.Items[topIndex];
1639 listView.TopItem = topItem;
1641 catch (NullReferenceException)
1643 listView.EnsureVisible(listView.VirtualListSize - 1);
1644 listView.EnsureVisible(topIndex);
1648 case ScrollLockMode.None:
1655 /// <see cref="SaveListViewSelection"/> によって保存された選択状態を復元します
1657 private void RestoreListViewSelection(DetailsListView listView, TabModel tab, ListViewSelection listSelection)
1659 // status_id から ListView 上のインデックスに変換
1660 int[]? selectedIndices = null;
1661 if (listSelection.SelectedStatusIds != null)
1662 selectedIndices = tab.IndexOf(listSelection.SelectedStatusIds).Where(x => x != -1).ToArray();
1664 var focusedIndex = -1;
1665 if (listSelection.FocusedStatusId != null)
1666 focusedIndex = tab.IndexOf(listSelection.FocusedStatusId.Value);
1668 var selectionMarkIndex = -1;
1669 if (listSelection.SelectionMarkStatusId != null)
1670 selectionMarkIndex = tab.IndexOf(listSelection.SelectionMarkStatusId.Value);
1672 this.SelectListItem(listView, selectedIndices, focusedIndex, selectionMarkIndex);
1675 private bool BalloonRequired()
1680 if (NativeMethods.IsScreenSaverRunning())
1684 if (!this.NewPostPopMenuItem.Checked)
1687 // 「画面最小化・アイコン時のみバルーンを表示する」が有効
1688 if (SettingManager.Common.LimitBalloon)
1690 if (this.WindowState != FormWindowState.Minimized && this.Visible && Form.ActiveForm != null)
1697 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
1699 if (SettingManager.Common.ReadOwnPost)
1701 if (notifyPosts != null && notifyPosts.Length > 0 && notifyPosts.All(x => x.UserId == this.tw.UserId))
1706 if (this.BalloonRequired())
1708 if (notifyPosts != null && notifyPosts.Length > 0)
1710 // Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
1711 if (SettingManager.Common.IsUseNotifyGrowl)
1713 var sb = new StringBuilder();
1717 foreach (var post in notifyPosts)
1719 if (!(notifyPosts.Length > 3))
1725 if (post.IsReply && !post.IsExcludeReply) reply = true;
1726 if (post.IsDm) dm = true;
1727 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1728 switch (SettingManager.Common.NameBalloon)
1730 case MyCommon.NameBalloonEnum.UserID:
1731 sb.Append(post.ScreenName).Append(" : ");
1733 case MyCommon.NameBalloonEnum.NickName:
1734 sb.Append(post.Nickname).Append(" : ");
1737 sb.Append(post.TextFromApi);
1738 if (notifyPosts.Length > 3)
1740 if (notifyPosts.Last() != post) continue;
1743 var title = new StringBuilder();
1744 GrowlHelper.NotifyType nt;
1745 if (SettingManager.Common.DispUsername)
1747 title.Append(this.tw.Username);
1748 title.Append(" - ");
1753 title.Append(ApplicationSettings.ApplicationName);
1754 title.Append(" [DM] ");
1755 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1756 nt = GrowlHelper.NotifyType.DirectMessage;
1760 title.Append(ApplicationSettings.ApplicationName);
1761 title.Append(" [Reply!] ");
1762 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1763 nt = GrowlHelper.NotifyType.Reply;
1767 title.Append(ApplicationSettings.ApplicationName);
1769 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1770 nt = GrowlHelper.NotifyType.Notify;
1772 var bText = sb.ToString();
1773 if (MyCommon.IsNullOrEmpty(bText)) return;
1775 var image = this.iconCache.TryGetFromCache(post.ImageUrl);
1776 this.gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image?.Image, post.ImageUrl);
1781 var sb = new StringBuilder();
1784 foreach (var post in notifyPosts)
1786 if (post.IsReply && !post.IsExcludeReply) reply = true;
1787 if (post.IsDm) dm = true;
1788 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1789 switch (SettingManager.Common.NameBalloon)
1791 case MyCommon.NameBalloonEnum.UserID:
1792 sb.Append(post.ScreenName).Append(" : ");
1794 case MyCommon.NameBalloonEnum.NickName:
1795 sb.Append(post.Nickname).Append(" : ");
1798 sb.Append(post.TextFromApi);
1801 var title = new StringBuilder();
1803 if (SettingManager.Common.DispUsername)
1805 title.Append(this.tw.Username);
1806 title.Append(" - ");
1811 ntIcon = ToolTipIcon.Warning;
1812 title.Append(ApplicationSettings.ApplicationName);
1813 title.Append(" [DM] ");
1814 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1818 ntIcon = ToolTipIcon.Warning;
1819 title.Append(ApplicationSettings.ApplicationName);
1820 title.Append(" [Reply!] ");
1821 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1825 ntIcon = ToolTipIcon.Info;
1826 title.Append(ApplicationSettings.ApplicationName);
1828 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1830 var bText = sb.ToString();
1831 if (MyCommon.IsNullOrEmpty(bText)) return;
1833 this.NotifyIcon1.BalloonTipTitle = title.ToString();
1834 this.NotifyIcon1.BalloonTipText = bText;
1835 this.NotifyIcon1.BalloonTipIcon = ntIcon;
1836 this.NotifyIcon1.ShowBalloonTip(500);
1842 if (!this.initial && SettingManager.Common.PlaySound && !MyCommon.IsNullOrEmpty(soundFile))
1846 var dir = Application.StartupPath;
1847 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1849 dir = Path.Combine(dir, "Sounds");
1851 using var player = new SoundPlayer(Path.Combine(dir, soundFile));
1859 // mentions新着時に画面ブリンク
1860 if (!this.initial && SettingManager.Common.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1862 NativeMethods.FlashMyWindow(this.Handle, 3);
1866 private async void MyList_SelectedIndexChanged(object sender, EventArgs e)
1868 var listView = this.CurrentListView;
1869 if (listView != sender)
1872 var indices = listView.SelectedIndices.Cast<int>().ToArray();
1873 this.CurrentTab.SelectPosts(indices);
1875 if (indices.Length != 1)
1878 var index = indices[0];
1879 if (index > listView.VirtualListSize - 1) return;
1881 this.PushSelectPostChain();
1883 var post = this.CurrentPost!;
1884 this.statuses.SetReadAllTab(post.StatusId, read: true);
1887 this.ChangeCacheStyleRead(true, index); // 既読へ(フォント、文字色)
1889 this.ColorizeList();
1890 await this.selectionDebouncer.Call();
1893 private void ChangeCacheStyleRead(bool read, int index)
1895 var tabInfo = this.CurrentTab;
1896 // Read:true=既読 false=未読
1897 // 未読管理していなかったら既読として扱う
1898 if (!tabInfo.UnreadManage ||
1899 !SettingManager.Common.UnreadManage) read = true;
1901 var listCache = this.listItemCache;
1902 if (listCache == null)
1905 // キャッシュに含まれていないアイテムは対象外
1906 if (!listCache.TryGetValue(index, out var itm, out var post))
1909 this.ChangeItemStyleRead(read, itm, post, (DetailsListView)listCache.TargetList);
1912 private void ChangeItemStyleRead(bool read, ListViewItem item, PostClass post, DetailsListView? dList)
1919 fnt = this.fntReaded;
1924 fnt = this.fntUnread;
1927 if (item.SubItems[5].Text != star)
1928 item.SubItems[5].Text = star;
1934 else if (post.RetweetedId != null)
1935 cl = this.clRetweet;
1936 else if (post.IsOwl && (post.IsDm || SettingManager.Common.OneWayLove))
1938 else if (read || !SettingManager.Common.UseUnreadStyle)
1943 if (dList == null || item.Index == -1)
1945 item.ForeColor = cl;
1946 if (SettingManager.Common.UseUnreadStyle)
1952 if (SettingManager.Common.UseUnreadStyle)
1953 dList.ChangeItemFontAndColor(item, cl, fnt);
1955 dList.ChangeItemForeColor(item, cl);
1959 private void ColorizeList()
1961 // Index:更新対象のListviewItem.Index。Colorを返す。
1962 // -1は全キャッシュ。Colorは返さない(ダミーを戻す)
1964 if (this.anchorFlag)
1965 post = this.anchorPost;
1967 post = this.CurrentPost;
1969 if (post == null) return;
1971 var listCache = this.listItemCache;
1972 if (listCache == null)
1975 var listView = (DetailsListView)listCache.TargetList;
1977 // ValidateRectが呼ばれる前に選択色などの描画を済ませておく
1980 foreach (var (listViewItem, cachedPost) in listCache.Cache)
1982 var backColor = this.JudgeColor(post, cachedPost);
1983 listView.ChangeItemBackColor(listViewItem, backColor);
1987 private void ColorizeList(ListViewItem item, PostClass post)
1989 // Index:更新対象のListviewItem.Index。Colorを返す。
1990 // -1は全キャッシュ。Colorは返さない(ダミーを戻す)
1991 PostClass? basePost;
1992 if (this.anchorFlag)
1993 basePost = this.anchorPost;
1995 basePost = this.CurrentPost;
1997 if (basePost == null) return;
1999 if (item.Index == -1)
2000 item.BackColor = this.JudgeColor(basePost, post);
2002 this.CurrentListView.ChangeItemBackColor(item, this.JudgeColor(basePost, post));
2005 private Color JudgeColor(PostClass basePost, PostClass targetPost)
2008 if (targetPost.StatusId == basePost.InReplyToStatusId)
2011 else if (targetPost.IsMe)
2014 else if (targetPost.IsReply)
2017 else if (basePost.ReplyToList.Any(x => x.UserId == targetPost.UserId))
2019 cl = this.clAtFromTarget;
2020 else if (targetPost.ReplyToList.Any(x => x.UserId == basePost.UserId))
2022 cl = this.clAtTarget;
2023 else if (targetPost.UserId == basePost.UserId)
2028 cl = this.clListBackcolor;
2033 private void StatusTextHistoryBack()
2035 if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
2036 this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
2039 if (this.hisIdx < 0)
2042 var historyItem = this.history[this.hisIdx];
2043 this.inReplyTo = historyItem.InReplyTo;
2044 this.StatusText.Text = historyItem.Status;
2045 this.StatusText.SelectionStart = this.StatusText.Text.Length;
2048 private void StatusTextHistoryForward()
2050 if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
2051 this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
2054 if (this.hisIdx > this.history.Count - 1)
2055 this.hisIdx = this.history.Count - 1;
2057 var historyItem = this.history[this.hisIdx];
2058 this.inReplyTo = historyItem.InReplyTo;
2059 this.StatusText.Text = historyItem.Status;
2060 this.StatusText.SelectionStart = this.StatusText.Text.Length;
2063 private async void PostButton_Click(object sender, EventArgs e)
2065 if (this.StatusText.Text.Trim().Length == 0)
2067 if (!this.ImageSelector.Enabled)
2069 await this.DoRefresh();
2074 var currentPost = this.CurrentPost;
2075 if (this.ExistCurrentPost && currentPost != null && this.StatusText.Text.Trim() == string.Format("RT @{0}: {1}", currentPost.ScreenName, currentPost.TextFromApi))
2077 var rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
2079 MessageBoxButtons.YesNoCancel,
2080 MessageBoxIcon.Question);
2083 case DialogResult.Yes:
2084 this.StatusText.Text = "";
2085 await this.DoReTweetOfficial(false);
2087 case DialogResult.Cancel:
2092 if (TextContainsOnlyMentions(this.StatusText.Text))
2094 var message = string.Format(Properties.Resources.PostConfirmText, this.StatusText.Text);
2095 var ret = MessageBox.Show(message, ApplicationSettings.ApplicationName, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
2097 if (ret != DialogResult.OK)
2101 this.history[this.history.Count - 1] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
2103 if (SettingManager.Common.Nicoms)
2105 this.StatusText.SelectionStart = this.StatusText.Text.Length;
2106 await this.UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
2109 this.StatusText.SelectionStart = this.StatusText.Text.Length;
2110 this.CheckReplyTo(this.StatusText.Text);
2112 var status = new PostStatusParams();
2114 var statusTextCompat = this.FormatStatusText(this.StatusText.Text);
2115 if (this.GetRestStatusCount(statusTextCompat) >= 0)
2117 // auto_populate_reply_metadata や attachment_url を使用しなくても 140 字以内に
2118 // 収まる場合はこれらのオプションを使用せずに投稿する
2119 status.Text = statusTextCompat;
2120 status.InReplyToStatusId = this.inReplyTo?.StatusId;
2124 status.Text = this.FormatStatusTextExtended(this.StatusText.Text, out var autoPopulatedUserIds, out var attachmentUrl);
2125 status.InReplyToStatusId = this.inReplyTo?.StatusId;
2127 status.AttachmentUrl = attachmentUrl;
2129 // リプライ先がセットされていても autoPopulatedUserIds が空の場合は auto_populate_reply_metadata を有効にしない
2131 var replyToPost = this.inReplyTo != null ? this.statuses[this.inReplyTo.Value.StatusId] : null;
2132 if (replyToPost != null && autoPopulatedUserIds.Length != 0)
2134 status.AutoPopulateReplyMetadata = true;
2136 // ReplyToList のうち autoPopulatedUserIds に含まれていないユーザー ID を抽出
2137 status.ExcludeReplyUserIds = replyToPost.ReplyToList.Select(x => x.UserId).Except(autoPopulatedUserIds)
2142 if (this.GetRestStatusCount(status.Text) < 0)
2144 // 文字数制限を超えているが強制的に投稿するか
2145 var ret = MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
2146 if (ret != DialogResult.OK)
2150 IMediaUploadService? uploadService = null;
2151 IMediaItem[]? uploadItems = null;
2152 if (this.ImageSelector.Visible)
2155 if (!this.ImageSelector.TryGetSelectedMedia(out var serviceName, out uploadItems))
2158 uploadService = this.ImageSelector.GetService(serviceName);
2161 this.inReplyTo = null;
2162 this.StatusText.Text = "";
2163 this.history.Add(new StatusTextHistory());
2164 this.hisIdx = this.history.Count - 1;
2165 if (!SettingManager.Common.FocusLockToStatusText)
2166 this.CurrentListView.Focus();
2167 this.urlUndoBuffer = null;
2168 this.UrlUndoToolStripMenuItem.Enabled = false; // Undoをできないように設定
2171 if (this.StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && this.StatusText.Text.Trim().Length > 7)
2173 var tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeDataString(this.StatusText.Text.Substring(7)));
2174 await MyCommon.OpenInBrowserAsync(this, tmp);
2177 await this.PostMessageAsync(status, uploadService, uploadItems);
2180 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
2182 MyCommon.EndingFlag = true;
2186 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
2188 if (!SettingManager.Common.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon.EndingFlag == false)
2190 // _endingFlag=false:フォームの×ボタン
2192 this.Visible = false;
2196 this.hookGlobalHotkey.UnregisterAllOriginalHotkey();
2197 this.ignoreConfigSave = true;
2198 MyCommon.EndingFlag = true;
2199 this.timelineScheduler.Enabled = false;
2200 this.TimerRefreshIcon.Enabled = false;
2204 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
2206 this.Visible = true;
2207 if (this.WindowState == FormWindowState.Minimized)
2209 this.WindowState = FormWindowState.Normal;
2212 this.BringToFront();
2215 private static int errorCount = 0;
2217 private static bool CheckAccountValid()
2219 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
2225 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2234 /// <summary>指定された型 <typeparamref name="T"/> に合致する全てのタブを更新します</summary>
2235 private Task RefreshTabAsync<T>()
2237 => this.RefreshTabAsync<T>(backward: false);
2239 /// <summary>指定された型 <typeparamref name="T"/> に合致する全てのタブを更新します</summary>
2240 private Task RefreshTabAsync<T>(bool backward)
2244 from tab in this.statuses.GetTabsByType<T>()
2245 select this.RefreshTabAsync(tab, backward);
2247 return Task.WhenAll(loadTasks);
2250 /// <summary>指定されたタブ <paramref name="tab"/> を更新します</summary>
2251 private Task RefreshTabAsync(TabModel tab)
2252 => this.RefreshTabAsync(tab, backward: false);
2254 /// <summary>指定されたタブ <paramref name="tab"/> を更新します</summary>
2255 private async Task RefreshTabAsync(TabModel tab, bool backward)
2257 await this.workerSemaphore.WaitAsync();
2261 this.RefreshTasktrayIcon();
2262 await Task.Run(() => tab.RefreshAsync(this.tw, backward, this.initial, this.workerProgress));
2264 catch (WebApiException ex)
2266 this.myStatusError = true;
2267 var tabType = tab switch
2269 HomeTabModel _ => "GetTimeline",
2270 MentionsTabModel _ => "GetTimeline",
2271 DirectMessagesTabModel _ => "GetDirectMessage",
2272 FavoritesTabModel _ => "GetFavorites",
2273 PublicSearchTabModel _ => "GetSearch",
2274 UserTimelineTabModel _ => "GetUserTimeline",
2275 ListTimelineTabModel _ => "GetListStatus",
2276 RelatedPostsTabModel _ => "GetRelatedTweets",
2277 _ => tab.GetType().Name.Replace("Model", ""),
2279 this.StatusLabel.Text = $"Err:{ex.Message}({tabType})";
2283 this.RefreshTimeline();
2284 this.workerSemaphore.Release();
2288 private async Task FavAddAsync(long statusId, TabModel tab)
2290 await this.workerSemaphore.WaitAsync();
2294 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
2296 this.RefreshTasktrayIcon();
2297 await this.FavAddAsyncInternal(progress, this.workerCts.Token, statusId, tab);
2299 catch (WebApiException ex)
2301 this.myStatusError = true;
2302 this.StatusLabel.Text = $"Err:{ex.Message}(PostFavAdd)";
2306 this.workerSemaphore.Release();
2310 private async Task FavAddAsyncInternal(IProgress<string> p, CancellationToken ct, long statusId, TabModel tab)
2312 if (ct.IsCancellationRequested)
2315 if (!CheckAccountValid())
2316 throw new WebApiException("Auth error. Check your account");
2318 if (!tab.Posts.TryGetValue(statusId, out var post))
2324 await Task.Run(async () =>
2326 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 0, 1, 0));
2332 await this.twitterApi.FavoritesCreate(post.RetweetedId ?? post.StatusId)
2334 .ConfigureAwait(false);
2336 catch (TwitterApiException ex)
2337 when (ex.Errors.All(x => x.Code == TwitterErrorCode.AlreadyFavorited))
2339 // エラーコード 139 のみの場合は成功と見なす
2342 if (SettingManager.Common.RestrictFavCheck)
2344 var status = await this.twitterApi.StatusesShow(post.RetweetedId ?? post.StatusId)
2345 .ConfigureAwait(false);
2347 if (status.Favorited != true)
2348 throw new WebApiException("NG(Restricted?)");
2351 this.favTimestamps.Add(DateTimeUtc.Now);
2354 if (this.statuses.Posts.TryGetValue(statusId, out var postTl))
2356 postTl.IsFav = true;
2358 var favTab = this.statuses.FavoriteTab;
2359 favTab.AddPostQueue(postTl);
2362 // 検索,リスト,UserTimeline,Relatedの各タブに反映
2363 foreach (var tb in this.statuses.GetTabsInnerStorageType())
2365 if (tb.Contains(statusId))
2366 tb.Posts[statusId].IsFav = true;
2369 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 1, 1, 0));
2371 catch (WebApiException)
2373 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 1, 1, 1));
2378 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
2379 foreach (var i in MyCommon.CountDown(this.favTimestamps.Count - 1, 0))
2381 if (this.favTimestamps[i] < oneHour)
2382 this.favTimestamps.RemoveAt(i);
2385 this.statuses.DistributePosts();
2388 if (ct.IsCancellationRequested)
2391 this.RefreshTimeline();
2393 if (this.CurrentTabName == tab.TabName)
2395 using (ControlTransaction.Update(this.CurrentListView))
2397 var idx = tab.IndexOf(statusId);
2399 this.ChangeCacheStyleRead(post.IsRead, idx);
2402 var currentPost = this.CurrentPost;
2403 if (currentPost != null && statusId == currentPost.StatusId)
2404 this.DispSelectedPost(true); // 選択アイテム再表示
2408 private async Task FavRemoveAsync(IReadOnlyList<long> statusIds, TabModel tab)
2410 await this.workerSemaphore.WaitAsync();
2414 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
2416 this.RefreshTasktrayIcon();
2417 await this.FavRemoveAsyncInternal(progress, this.workerCts.Token, statusIds, tab);
2419 catch (WebApiException ex)
2421 this.myStatusError = true;
2422 this.StatusLabel.Text = $"Err:{ex.Message}(PostFavRemove)";
2426 this.workerSemaphore.Release();
2430 private async Task FavRemoveAsyncInternal(IProgress<string> p, CancellationToken ct, IReadOnlyList<long> statusIds, TabModel tab)
2432 if (ct.IsCancellationRequested)
2435 if (!CheckAccountValid())
2436 throw new WebApiException("Auth error. Check your account");
2438 var successIds = new List<long>();
2440 await Task.Run(async () =>
2444 var failedCount = 0;
2445 foreach (var statusId in statusIds)
2449 var post = tab.Posts[statusId];
2451 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17, allCount, statusIds.Count, failedCount));
2458 await this.twitterApi.FavoritesDestroy(post.RetweetedId ?? post.StatusId)
2460 .ConfigureAwait(false);
2462 catch (WebApiException)
2468 successIds.Add(statusId);
2469 post.IsFav = false; // リスト再描画必要
2471 if (this.statuses.Posts.TryGetValue(statusId, out var tabinfoPost))
2472 tabinfoPost.IsFav = false;
2474 // 検索,リスト,UserTimeline,Relatedの各タブに反映
2475 foreach (var tb in this.statuses.GetTabsInnerStorageType())
2477 if (tb.Contains(statusId))
2478 tb.Posts[statusId].IsFav = false;
2483 if (ct.IsCancellationRequested)
2486 var favTab = this.statuses.FavoriteTab;
2487 foreach (var statusId in successIds)
2489 // ツイートが削除された訳ではないので IsDeleted はセットしない
2490 favTab.EnqueueRemovePost(statusId, setIsDeleted: false);
2493 this.RefreshTimeline();
2495 if (this.CurrentTabName == tab.TabName)
2497 if (tab.TabType == MyCommon.TabUsageType.Favorites)
2503 using (ControlTransaction.Update(this.CurrentListView))
2505 foreach (var statusId in successIds)
2507 var idx = tab.IndexOf(statusId);
2511 var post = tab.Posts[statusId];
2512 this.ChangeCacheStyleRead(post.IsRead, idx);
2516 var currentPost = this.CurrentPost;
2517 if (currentPost != null && successIds.Contains(currentPost.StatusId))
2518 this.DispSelectedPost(true); // 選択アイテム再表示
2523 private async Task PostMessageAsync(PostStatusParams postParams, IMediaUploadService? uploadService, IMediaItem[]? uploadItems)
2525 await this.workerSemaphore.WaitAsync();
2529 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
2531 this.RefreshTasktrayIcon();
2532 await this.PostMessageAsyncInternal(progress, this.workerCts.Token, postParams, uploadService, uploadItems);
2534 catch (WebApiException ex)
2536 this.myStatusError = true;
2537 this.StatusLabel.Text = $"Err:{ex.Message}(PostMessage)";
2541 this.workerSemaphore.Release();
2545 private async Task PostMessageAsyncInternal(
2546 IProgress<string> p,
2547 CancellationToken ct,
2548 PostStatusParams postParams,
2549 IMediaUploadService? uploadService,
2550 IMediaItem[]? uploadItems)
2552 if (ct.IsCancellationRequested)
2555 if (!CheckAccountValid())
2556 throw new WebApiException("Auth error. Check your account");
2558 p.Report("Posting...");
2560 PostClass? post = null;
2565 await Task.Run(async () =>
2567 var postParamsWithMedia = postParams;
2569 if (uploadService != null && uploadItems != null && uploadItems.Length > 0)
2571 postParamsWithMedia = await uploadService.UploadAsync(uploadItems, postParamsWithMedia)
2572 .ConfigureAwait(false);
2575 post = await this.tw.PostStatus(postParamsWithMedia)
2576 .ConfigureAwait(false);
2579 p.Report(Properties.Resources.PostWorker_RunWorkerCompletedText4);
2581 catch (WebApiException ex)
2583 // 処理は中断せずエラーの表示のみ行う
2584 errMsg = $"Err:{ex.Message}(PostMessage)";
2586 this.myStatusError = true;
2588 catch (UnauthorizedAccessException ex)
2590 // アップロード対象のファイルが開けなかった場合など
2591 errMsg = $"Err:{ex.Message}(PostMessage)";
2593 this.myStatusError = true;
2597 // 使い終わった MediaItem は破棄する
2598 if (uploadItems != null)
2600 foreach (var disposableItem in uploadItems.OfType<IDisposable>())
2602 disposableItem.Dispose();
2607 if (ct.IsCancellationRequested)
2610 if (!MyCommon.IsNullOrEmpty(errMsg) &&
2611 !errMsg.StartsWith("OK:", StringComparison.Ordinal) &&
2612 !errMsg.StartsWith("Warn:", StringComparison.Ordinal))
2614 var message = string.Format(Properties.Resources.StatusUpdateFailed, errMsg, postParams.Text);
2616 var ret = MessageBox.Show(
2618 "Failed to update status",
2619 MessageBoxButtons.RetryCancel,
2620 MessageBoxIcon.Question);
2622 if (ret == DialogResult.Retry)
2624 await this.PostMessageAsync(postParams, uploadService, uploadItems);
2628 this.StatusTextHistoryBack();
2629 this.StatusText.Focus();
2631 // 連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
2632 if (SettingManager.Common.FocusLockToStatusText)
2633 this.StatusText_Enter(this.StatusText, EventArgs.Empty);
2638 this.postTimestamps.Add(DateTimeUtc.Now);
2640 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
2641 foreach (var i in MyCommon.CountDown(this.postTimestamps.Count - 1, 0))
2643 if (this.postTimestamps[i] < oneHour)
2644 this.postTimestamps.RemoveAt(i);
2647 if (!this.HashMgr.IsPermanent && !MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
2649 this.HashMgr.ClearHashtag();
2650 this.HashStripSplitButton.Text = "#[-]";
2651 this.HashTogglePullDownMenuItem.Checked = false;
2652 this.HashToggleMenuItem.Checked = false;
2655 this.SetMainWindowTitle();
2658 if (SettingManager.Common.PostAndGet)
2660 await this.RefreshTabAsync<HomeTabModel>();
2666 this.statuses.AddPost(post);
2667 this.statuses.DistributePosts();
2669 this.RefreshTimeline();
2673 private async Task RetweetAsync(IReadOnlyList<long> statusIds)
2675 await this.workerSemaphore.WaitAsync();
2679 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
2681 this.RefreshTasktrayIcon();
2682 await this.RetweetAsyncInternal(progress, this.workerCts.Token, statusIds);
2684 catch (WebApiException ex)
2686 this.myStatusError = true;
2687 this.StatusLabel.Text = $"Err:{ex.Message}(PostRetweet)";
2691 this.workerSemaphore.Release();
2695 private async Task RetweetAsyncInternal(IProgress<string> p, CancellationToken ct, IReadOnlyList<long> statusIds)
2697 if (ct.IsCancellationRequested)
2700 if (!CheckAccountValid())
2701 throw new WebApiException("Auth error. Check your account");
2704 if (!SettingManager.Common.UnreadManage)
2707 read = this.initial && SettingManager.Common.Read;
2709 p.Report("Posting...");
2711 var posts = new List<PostClass>();
2713 await Task.Run(async () =>
2715 foreach (var statusId in statusIds)
2717 var post = await this.tw.PostRetweet(statusId, read).ConfigureAwait(false);
2718 if (post != null) posts.Add(post);
2722 if (ct.IsCancellationRequested)
2725 p.Report(Properties.Resources.PostWorker_RunWorkerCompletedText4);
2727 this.postTimestamps.Add(DateTimeUtc.Now);
2729 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
2730 foreach (var i in MyCommon.CountDown(this.postTimestamps.Count - 1, 0))
2732 if (this.postTimestamps[i] < oneHour)
2733 this.postTimestamps.RemoveAt(i);
2736 // 自分のRTはTLの更新では取得できない場合があるので、
2737 // 投稿時取得の有無に関わらず追加しておく
2738 posts.ForEach(post => this.statuses.AddPost(post));
2740 if (SettingManager.Common.PostAndGet)
2742 await this.RefreshTabAsync<HomeTabModel>();
2746 this.statuses.DistributePosts();
2747 this.RefreshTimeline();
2751 private async Task RefreshFollowerIdsAsync()
2753 await this.workerSemaphore.WaitAsync();
2757 this.RefreshTasktrayIcon();
2758 this.StatusLabel.Text = Properties.Resources.UpdateFollowersMenuItem1_ClickText1;
2760 await this.tw.RefreshFollowerIds();
2762 this.StatusLabel.Text = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
2764 this.RefreshTimeline();
2765 this.PurgeListViewItemCache();
2766 this.CurrentListView.Refresh();
2768 catch (WebApiException ex)
2770 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshFollowersIds)";
2774 this.workerSemaphore.Release();
2778 private async Task RefreshNoRetweetIdsAsync()
2780 await this.workerSemaphore.WaitAsync();
2784 this.RefreshTasktrayIcon();
2785 await this.tw.RefreshNoRetweetIds();
2787 this.StatusLabel.Text = "NoRetweetIds refreshed";
2789 catch (WebApiException ex)
2791 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshNoRetweetIds)";
2795 this.workerSemaphore.Release();
2799 private async Task RefreshBlockIdsAsync()
2801 await this.workerSemaphore.WaitAsync();
2805 this.RefreshTasktrayIcon();
2806 this.StatusLabel.Text = Properties.Resources.UpdateBlockUserText1;
2808 await this.tw.RefreshBlockIds();
2810 this.StatusLabel.Text = Properties.Resources.UpdateBlockUserText3;
2812 catch (WebApiException ex)
2814 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshBlockIds)";
2818 this.workerSemaphore.Release();
2822 private async Task RefreshTwitterConfigurationAsync()
2824 await this.workerSemaphore.WaitAsync();
2828 this.RefreshTasktrayIcon();
2829 await this.tw.RefreshConfiguration();
2831 if (this.tw.Configuration.PhotoSizeLimit != 0)
2833 foreach (var service in this.ImageSelector.GetServices())
2835 service.UpdateTwitterConfiguration(this.tw.Configuration);
2839 this.PurgeListViewItemCache();
2840 this.CurrentListView.Refresh();
2842 catch (WebApiException ex)
2844 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshConfiguration)";
2848 this.workerSemaphore.Release();
2852 private async Task RefreshMuteUserIdsAsync()
2854 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
2858 await this.tw.RefreshMuteUserIdsAsync();
2860 catch (WebApiException ex)
2862 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
2866 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
2869 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
2871 if (e.Button == MouseButtons.Left)
2873 this.Visible = true;
2874 if (this.WindowState == FormWindowState.Minimized)
2876 this.WindowState = this.formWindowState;
2879 this.BringToFront();
2883 private async void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
2884 => await this.ListItemDoubleClickAction();
2886 private async Task ListItemDoubleClickAction()
2888 switch (SettingManager.Common.ListDoubleClickAction)
2890 case MyCommon.ListItemDoubleClickActionType.Reply:
2891 this.MakeReplyText();
2893 case MyCommon.ListItemDoubleClickActionType.Favorite:
2894 await this.FavoriteChange(true);
2896 case MyCommon.ListItemDoubleClickActionType.ShowProfile:
2897 var post = this.CurrentPost;
2899 await this.ShowUserStatus(post.ScreenName, false);
2901 case MyCommon.ListItemDoubleClickActionType.ShowTimeline:
2902 await this.ShowUserTimeline();
2904 case MyCommon.ListItemDoubleClickActionType.ShowRelated:
2905 this.ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty);
2907 case MyCommon.ListItemDoubleClickActionType.OpenHomeInBrowser:
2908 this.AuthorOpenInBrowserMenuItem_Click(this.AuthorOpenInBrowserContextMenuItem, EventArgs.Empty);
2910 case MyCommon.ListItemDoubleClickActionType.OpenStatusInBrowser:
2911 this.StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty);
2913 case MyCommon.ListItemDoubleClickActionType.None:
2920 private async void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
2921 => await this.FavoriteChange(true);
2923 private async void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
2924 => await this.FavoriteChange(false);
2926 private async void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
2927 => await this.FavoritesRetweetOfficial();
2929 private async void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
2930 => await this.FavoritesRetweetUnofficial();
2932 private async Task FavoriteChange(bool favAdd, bool multiFavoriteChangeDialogEnable = true)
2934 var tab = this.CurrentTab;
2935 var posts = tab.SelectedPosts;
2937 // trueでFavAdd,falseでFavRemove
2938 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || posts.Length == 0
2939 || !this.ExistCurrentPost) return;
2941 if (posts.Length > 1)
2946 // https://support.twitter.com/articles/76915#favoriting
2947 MessageBox.Show(string.Format(Properties.Resources.FavoriteLimitCountText, 1));
2948 this.doFavRetweetFlags = false;
2953 if (multiFavoriteChangeDialogEnable)
2955 var confirm = MessageBox.Show(
2956 Properties.Resources.FavRemoveToolStripMenuItem_ClickText1,
2957 Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
2958 MessageBoxButtons.OKCancel,
2959 MessageBoxIcon.Question);
2961 if (confirm == DialogResult.Cancel)
2969 var selectedPost = posts.Single();
2970 if (selectedPost.IsFav)
2972 this.StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
2976 await this.FavAddAsync(selectedPost.StatusId, tab);
2980 var selectedPosts = posts.Where(x => x.IsFav);
2981 var statusIds = selectedPosts.Select(x => x.StatusId).ToArray();
2982 if (statusIds.Length == 0)
2984 this.StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
2988 await this.FavRemoveAsync(statusIds, tab);
2992 private PostClass GetCurTabPost(int index)
2994 var listCache = this.listItemCache;
2995 if (listCache != null)
2997 if (listCache.TryGetValue(index, out _, out var post))
3001 return this.CurrentTab[index];
3004 private async void AuthorOpenInBrowserMenuItem_Click(object sender, EventArgs e)
3006 var post = this.CurrentPost;
3008 await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + post.ScreenName);
3010 await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl);
3013 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
3015 if ((!this.initialLayout) && this.Visible)
3017 if (this.WindowState == FormWindowState.Normal)
3019 this.mySize = this.ClientSize;
3020 this.mySpDis = this.SplitContainer1.SplitterDistance;
3021 this.mySpDis3 = this.SplitContainer3.SplitterDistance;
3022 if (this.StatusText.Multiline) this.mySpDis2 = this.StatusText.Height;
3023 this.MarkSettingLocalModified();
3028 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
3030 var comparerMode = this.GetComparerModeByColumnIndex(e.Column);
3031 if (comparerMode == null)
3034 this.SetSortColumn(comparerMode.Value);
3038 /// 列インデックスからソートを行う ComparerMode を求める
3040 /// <param name="columnIndex">ソートを行うカラムのインデックス (表示上の順序とは異なる)</param>
3041 /// <returns>ソートを行う ComparerMode。null であればソートを行わない</returns>
3042 private ComparerMode? GetComparerModeByColumnIndex(int columnIndex)
3045 return ComparerMode.Id;
3047 return columnIndex switch
3049 1 => ComparerMode.Nickname, // ニックネーム
3050 2 => ComparerMode.Data, // 本文
3051 3 => ComparerMode.Id, // 時刻=発言Id
3052 4 => ComparerMode.Name, // 名前
3053 7 => ComparerMode.Source, // Source
3054 _ => (ComparerMode?)null, // 0:アイコン, 5:未読マーク, 6:プロテクト・フィルターマーク
3059 /// 発言一覧の指定した位置の列でソートする
3061 /// <param name="columnIndex">ソートする列の位置 (表示上の順序で指定)</param>
3062 private void SetSortColumnByDisplayIndex(int columnIndex)
3064 // 表示上の列の位置から ColumnHeader を求める
3065 var col = this.CurrentListView.Columns.Cast<ColumnHeader>()
3066 .FirstOrDefault(x => x.DisplayIndex == columnIndex);
3071 var comparerMode = this.GetComparerModeByColumnIndex(col.Index);
3072 if (comparerMode == null)
3075 this.SetSortColumn(comparerMode.Value);
3079 /// 発言一覧の最後列の項目でソートする
3081 private void SetSortLastColumn()
3083 // 表示上の最後列にある ColumnHeader を求める
3084 var col = this.CurrentListView.Columns.Cast<ColumnHeader>()
3085 .OrderByDescending(x => x.DisplayIndex)
3088 var comparerMode = this.GetComparerModeByColumnIndex(col.Index);
3089 if (comparerMode == null)
3092 this.SetSortColumn(comparerMode.Value);
3096 /// 発言一覧を指定された ComparerMode に基づいてソートする
3098 private void SetSortColumn(ComparerMode sortColumn)
3100 if (SettingManager.Common.SortOrderLock)
3103 this.statuses.ToggleSortOrder(sortColumn);
3104 this.InitColumnText();
3106 var list = this.CurrentListView;
3109 list.Columns[0].Text = this.columnText[0];
3110 list.Columns[1].Text = this.columnText[2];
3114 for (var i = 0; i <= 7; i++)
3116 list.Columns[i].Text = this.columnText[i];
3120 this.PurgeListViewItemCache();
3122 var tab = this.CurrentTab;
3123 var post = this.CurrentPost;
3124 if (tab.AllCount > 0 && post != null)
3126 var idx = tab.IndexOf(post.StatusId);
3129 this.SelectListItem(list, idx);
3130 list.EnsureVisible(idx);
3135 this.MarkSettingCommonModified();
3138 private void TweenMain_LocationChanged(object sender, EventArgs e)
3140 if (this.WindowState == FormWindowState.Normal && !this.initialLayout)
3142 this.myLoc = this.DesktopLocation;
3143 this.MarkSettingLocalModified();
3147 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
3149 var post = this.CurrentPost;
3150 if (!this.ExistCurrentPost)
3152 this.ReplyStripMenuItem.Enabled = false;
3153 this.ReplyAllStripMenuItem.Enabled = false;
3154 this.DMStripMenuItem.Enabled = false;
3155 this.TabMenuItem.Enabled = false;
3156 this.IDRuleMenuItem.Enabled = false;
3157 this.SourceRuleMenuItem.Enabled = false;
3158 this.ReadedStripMenuItem.Enabled = false;
3159 this.UnreadStripMenuItem.Enabled = false;
3160 this.AuthorContextMenuItem.Visible = false;
3161 this.RetweetedByContextMenuItem.Visible = false;
3165 this.ReplyStripMenuItem.Enabled = true;
3166 this.ReplyAllStripMenuItem.Enabled = true;
3167 this.DMStripMenuItem.Enabled = true;
3168 this.TabMenuItem.Enabled = true;
3169 this.IDRuleMenuItem.Enabled = true;
3170 this.SourceRuleMenuItem.Enabled = true;
3171 this.ReadedStripMenuItem.Enabled = true;
3172 this.UnreadStripMenuItem.Enabled = true;
3173 this.AuthorContextMenuItem.Visible = true;
3174 this.AuthorContextMenuItem.Text = $"@{post!.ScreenName}";
3175 this.RetweetedByContextMenuItem.Visible = post.RetweetedByUserId != null;
3176 this.RetweetedByContextMenuItem.Text = $"@{post.RetweetedBy}";
3178 var tab = this.CurrentTab;
3179 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
3181 this.FavAddToolStripMenuItem.Enabled = false;
3182 this.FavRemoveToolStripMenuItem.Enabled = false;
3183 this.StatusOpenMenuItem.Enabled = false;
3184 this.ShowRelatedStatusesMenuItem.Enabled = false;
3186 this.ReTweetStripMenuItem.Enabled = false;
3187 this.ReTweetUnofficialStripMenuItem.Enabled = false;
3188 this.QuoteStripMenuItem.Enabled = false;
3189 this.FavoriteRetweetContextMenu.Enabled = false;
3190 this.FavoriteRetweetUnofficialContextMenu.Enabled = false;
3194 this.FavAddToolStripMenuItem.Enabled = true;
3195 this.FavRemoveToolStripMenuItem.Enabled = true;
3196 this.StatusOpenMenuItem.Enabled = true;
3197 this.ShowRelatedStatusesMenuItem.Enabled = true; // PublicSearchの時問題出るかも
3199 if (!post.CanRetweetBy(this.twitterApi.CurrentUserId))
3201 this.ReTweetStripMenuItem.Enabled = false;
3202 this.ReTweetUnofficialStripMenuItem.Enabled = false;
3203 this.QuoteStripMenuItem.Enabled = false;
3204 this.FavoriteRetweetContextMenu.Enabled = false;
3205 this.FavoriteRetweetUnofficialContextMenu.Enabled = false;
3209 this.ReTweetStripMenuItem.Enabled = true;
3210 this.ReTweetUnofficialStripMenuItem.Enabled = true;
3211 this.QuoteStripMenuItem.Enabled = true;
3212 this.FavoriteRetweetContextMenu.Enabled = true;
3213 this.FavoriteRetweetUnofficialContextMenu.Enabled = true;
3217 if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
3219 this.RepliedStatusOpenMenuItem.Enabled = false;
3223 this.RepliedStatusOpenMenuItem.Enabled = true;
3226 if (this.ExistCurrentPost && post != null)
3228 this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
3229 if (post.RetweetedByUserId == this.tw.UserId)
3230 this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
3232 this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
3236 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
3237 => this.MakeReplyText();
3239 private void DMStripMenuItem_Click(object sender, EventArgs e)
3240 => this.MakeDirectMessageText();
3242 private async Task DoStatusDelete()
3244 var posts = this.CurrentTab.SelectedPosts;
3245 if (posts.Length == 0)
3248 // 選択されたツイートの中に削除可能なものが一つでもあるか
3249 if (!posts.Any(x => x.CanDeleteBy(this.tw.UserId)))
3252 var ret = MessageBox.Show(
3254 string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine),
3255 Properties.Resources.DeleteStripMenuItem_ClickText2,
3256 MessageBoxButtons.OKCancel,
3257 MessageBoxIcon.Question);
3259 if (ret != DialogResult.OK)
3262 var currentListView = this.CurrentListView;
3263 var focusedIndex = currentListView.FocusedItem?.Index ?? currentListView.TopItem?.Index ?? 0;
3265 using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
3267 Exception? lastException = null;
3268 foreach (var post in posts)
3270 if (!post.CanDeleteBy(this.tw.UserId))
3277 await this.twitterApi.DirectMessagesEventsDestroy(post.StatusId.ToString(CultureInfo.InvariantCulture));
3281 if (post.RetweetedByUserId == this.tw.UserId)
3283 // 自分が RT したツイート (自分が RT した自分のツイートも含む)
3285 await this.twitterApi.StatusesDestroy(post.StatusId)
3290 if (post.UserId == this.tw.UserId)
3292 if (post.RetweetedId != null)
3294 // 他人に RT された自分のツイート
3295 // => RT 元の自分のツイートを削除
3296 await this.twitterApi.StatusesDestroy(post.RetweetedId.Value)
3303 await this.twitterApi.StatusesDestroy(post.StatusId)
3310 catch (WebApiException ex)
3316 this.statuses.RemovePostFromAllTabs(post.StatusId, setIsDeleted: true);
3319 if (lastException == null)
3320 this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; // 成功
3322 this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; // 失敗
3324 this.PurgeListViewItemCache();
3326 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3328 var tabPage = this.ListTab.TabPages[index];
3329 var listView = (DetailsListView)tabPage.Tag;
3331 using (ControlTransaction.Update(listView))
3333 listView.VirtualListSize = tab.AllCount;
3335 if (tab.TabName == this.CurrentTabName)
3337 listView.SelectedIndices.Clear();
3339 if (tab.AllCount != 0)
3342 if (tab.AllCount - 1 > focusedIndex && focusedIndex > -1)
3343 selectedIndex = focusedIndex;
3345 selectedIndex = tab.AllCount - 1;
3347 listView.SelectedIndices.Add(selectedIndex);
3348 listView.EnsureVisible(selectedIndex);
3349 listView.FocusedItem = listView.Items[selectedIndex];
3354 if (SettingManager.Common.TabIconDisp && tab.UnreadCount == 0)
3356 if (tabPage.ImageIndex == 0)
3357 tabPage.ImageIndex = -1; // タブアイコン
3361 if (!SettingManager.Common.TabIconDisp)
3362 this.ListTab.Refresh();
3366 private async void DeleteStripMenuItem_Click(object sender, EventArgs e)
3367 => await this.DoStatusDelete();
3369 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
3371 using (ControlTransaction.Update(this.CurrentListView))
3373 var tab = this.CurrentTab;
3374 foreach (var statusId in tab.SelectedStatusIds)
3376 this.statuses.SetReadAllTab(statusId, read: true);
3377 var idx = tab.IndexOf(statusId);
3378 this.ChangeCacheStyleRead(true, idx);
3380 this.ColorizeList();
3382 if (SettingManager.Common.TabIconDisp)
3384 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3386 if (tab.UnreadCount == 0)
3388 var tabPage = this.ListTab.TabPages[index];
3389 if (tabPage.ImageIndex == 0)
3390 tabPage.ImageIndex = -1; // タブアイコン
3394 if (!SettingManager.Common.TabIconDisp) this.ListTab.Refresh();
3397 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
3399 using (ControlTransaction.Update(this.CurrentListView))
3401 var tab = this.CurrentTab;
3402 foreach (var statusId in tab.SelectedStatusIds)
3404 this.statuses.SetReadAllTab(statusId, read: false);
3405 var idx = tab.IndexOf(statusId);
3406 this.ChangeCacheStyleRead(false, idx);
3408 this.ColorizeList();
3410 if (SettingManager.Common.TabIconDisp)
3412 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3414 if (tab.UnreadCount > 0)
3416 var tabPage = this.ListTab.TabPages[index];
3417 if (tabPage.ImageIndex == -1)
3418 tabPage.ImageIndex = 0; // タブアイコン
3422 if (!SettingManager.Common.TabIconDisp) this.ListTab.Refresh();
3425 private async void RefreshStripMenuItem_Click(object sender, EventArgs e)
3426 => await this.DoRefresh();
3428 private async Task DoRefresh()
3429 => await this.RefreshTabAsync(this.CurrentTab);
3431 private async Task DoRefreshMore()
3432 => await this.RefreshTabAsync(this.CurrentTab, backward: true);
3434 private DialogResult ShowSettingDialog(bool showTaskbarIcon = false)
3436 var result = DialogResult.Abort;
3438 using var settingDialog = new AppendSettingDialog();
3439 settingDialog.Icon = this.mainIcon;
3440 settingDialog.Owner = this;
3441 settingDialog.ShowInTaskbar = showTaskbarIcon;
3442 settingDialog.IntervalChanged += this.TimerInterval_Changed;
3444 settingDialog.Tw = this.tw;
3445 settingDialog.TwitterApi = this.twitterApi;
3447 settingDialog.LoadConfig(SettingManager.Common, SettingManager.Local);
3451 result = settingDialog.ShowDialog(this);
3455 return DialogResult.Abort;
3458 if (result == DialogResult.OK)
3460 lock (this.syncObject)
3462 settingDialog.SaveConfig(SettingManager.Common, SettingManager.Local);
3469 private async void SettingStripMenuItem_Click(object sender, EventArgs e)
3472 var oldUser = new { this.tw.AccessToken, this.tw.AccessTokenSecret, this.tw.Username, this.tw.UserId };
3474 var oldIconSz = SettingManager.Common.IconSize;
3476 if (this.ShowSettingDialog() == DialogResult.OK)
3478 lock (this.syncObject)
3480 this.tw.RestrictFavCheck = SettingManager.Common.RestrictFavCheck;
3481 this.tw.ReadOwnPost = SettingManager.Common.ReadOwnPost;
3482 ShortUrl.Instance.DisableExpanding = !SettingManager.Common.TinyUrlResolve;
3483 ShortUrl.Instance.BitlyAccessToken = SettingManager.Common.BitlyAccessToken;
3484 ShortUrl.Instance.BitlyId = SettingManager.Common.BilyUser;
3485 ShortUrl.Instance.BitlyKey = SettingManager.Common.BitlyPwd;
3486 TwitterApiConnection.RestApiHost = SettingManager.Common.TwitterApiHost;
3488 Networking.DefaultTimeout = TimeSpan.FromSeconds(SettingManager.Common.DefaultTimeOut);
3489 Networking.UploadImageTimeout = TimeSpan.FromSeconds(SettingManager.Common.UploadImageTimeout);
3490 Networking.SetWebProxy(
3491 SettingManager.Local.ProxyType,
3492 SettingManager.Local.ProxyAddress,
3493 SettingManager.Local.ProxyPort,
3494 SettingManager.Local.ProxyUser,
3495 SettingManager.Local.ProxyPassword);
3496 Networking.ForceIPv4 = SettingManager.Common.ForceIPv4;
3498 this.ImageSelector.Reset(this.tw, this.tw.Configuration);
3502 if (SettingManager.Common.TabIconDisp)
3504 this.ListTab.DrawItem -= this.ListTab_DrawItem;
3505 this.ListTab.DrawMode = TabDrawMode.Normal;
3506 this.ListTab.ImageList = this.TabImage;
3510 this.ListTab.DrawItem -= this.ListTab_DrawItem;
3511 this.ListTab.DrawItem += this.ListTab_DrawItem;
3512 this.ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
3513 this.ListTab.ImageList = null;
3516 catch (Exception ex)
3518 ex.Data["Instance"] = "ListTab(TabIconDisp)";
3519 ex.Data["IsTerminatePermission"] = false;
3525 if (!SettingManager.Common.UnreadManage)
3527 this.ReadedStripMenuItem.Enabled = false;
3528 this.UnreadStripMenuItem.Enabled = false;
3529 if (SettingManager.Common.TabIconDisp)
3531 foreach (TabPage myTab in this.ListTab.TabPages)
3533 myTab.ImageIndex = -1;
3539 this.ReadedStripMenuItem.Enabled = true;
3540 this.UnreadStripMenuItem.Enabled = true;
3543 catch (Exception ex)
3545 ex.Data["Instance"] = "ListTab(UnreadManage)";
3546 ex.Data["IsTerminatePermission"] = false;
3551 this.SetTabAlignment();
3553 this.SplitContainer1.IsPanelInverted = !SettingManager.Common.StatusAreaAtBottom;
3555 var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
3556 imgazyobizinet.Enabled = SettingManager.Common.EnableImgAzyobuziNet;
3557 imgazyobizinet.DisabledInDM = SettingManager.Common.ImgAzyobuziNetDisabledInDM;
3559 this.NewPostPopMenuItem.Checked = SettingManager.Common.NewAllPop;
3560 this.NotifyFileMenuItem.Checked = SettingManager.Common.NewAllPop;
3561 this.PlaySoundMenuItem.Checked = SettingManager.Common.PlaySound;
3562 this.PlaySoundFileMenuItem.Checked = SettingManager.Common.PlaySound;
3563 this.fntUnread = SettingManager.Local.FontUnread;
3564 this.clUnread = SettingManager.Local.ColorUnread;
3565 this.fntReaded = SettingManager.Local.FontRead;
3566 this.clReaded = SettingManager.Local.ColorRead;
3567 this.clFav = SettingManager.Local.ColorFav;
3568 this.clOWL = SettingManager.Local.ColorOWL;
3569 this.clRetweet = SettingManager.Local.ColorRetweet;
3570 this.fntDetail = SettingManager.Local.FontDetail;
3571 this.clDetail = SettingManager.Local.ColorDetail;
3572 this.clDetailLink = SettingManager.Local.ColorDetailLink;
3573 this.clDetailBackcolor = SettingManager.Local.ColorDetailBackcolor;
3574 this.clSelf = SettingManager.Local.ColorSelf;
3575 this.clAtSelf = SettingManager.Local.ColorAtSelf;
3576 this.clTarget = SettingManager.Local.ColorTarget;
3577 this.clAtTarget = SettingManager.Local.ColorAtTarget;
3578 this.clAtFromTarget = SettingManager.Local.ColorAtFromTarget;
3579 this.clAtTo = SettingManager.Local.ColorAtTo;
3580 this.clListBackcolor = SettingManager.Local.ColorListBackcolor;
3581 this.clInputBackcolor = SettingManager.Local.ColorInputBackcolor;
3582 this.clInputFont = SettingManager.Local.ColorInputFont;
3583 this.fntInputFont = SettingManager.Local.FontInputFont;
3584 this.brsBackColorMine.Dispose();
3585 this.brsBackColorAt.Dispose();
3586 this.brsBackColorYou.Dispose();
3587 this.brsBackColorAtYou.Dispose();
3588 this.brsBackColorAtFromTarget.Dispose();
3589 this.brsBackColorAtTo.Dispose();
3590 this.brsBackColorNone.Dispose();
3591 this.brsBackColorMine = new SolidBrush(this.clSelf);
3592 this.brsBackColorAt = new SolidBrush(this.clAtSelf);
3593 this.brsBackColorYou = new SolidBrush(this.clTarget);
3594 this.brsBackColorAtYou = new SolidBrush(this.clAtTarget);
3595 this.brsBackColorAtFromTarget = new SolidBrush(this.clAtFromTarget);
3596 this.brsBackColorAtTo = new SolidBrush(this.clAtTo);
3597 this.brsBackColorNone = new SolidBrush(this.clListBackcolor);
3601 if (this.StatusText.Focused) this.StatusText.BackColor = this.clInputBackcolor;
3602 this.StatusText.Font = this.fntInputFont;
3603 this.StatusText.ForeColor = this.clInputFont;
3605 catch (Exception ex)
3607 MessageBox.Show(ex.Message);
3612 this.InitDetailHtmlFormat();
3614 catch (Exception ex)
3616 ex.Data["Instance"] = "Font";
3617 ex.Data["IsTerminatePermission"] = false;
3623 if (SettingManager.Common.TabIconDisp)
3625 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3627 var tabPage = this.ListTab.TabPages[index];
3628 if (tab.UnreadCount == 0)
3629 tabPage.ImageIndex = -1;
3631 tabPage.ImageIndex = 0;
3635 catch (Exception ex)
3637 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
3638 ex.Data["IsTerminatePermission"] = false;
3644 var oldIconCol = this.iconCol;
3646 if (SettingManager.Common.IconSize != oldIconSz)
3647 this.ApplyListViewIconSize(SettingManager.Common.IconSize);
3649 foreach (TabPage tp in this.ListTab.TabPages)
3651 var lst = (DetailsListView)tp.Tag;
3653 using (ControlTransaction.Update(lst))
3655 lst.GridLines = SettingManager.Common.ShowGrid;
3656 lst.Font = this.fntReaded;
3657 lst.BackColor = this.clListBackcolor;
3659 if (this.iconCol != oldIconCol)
3660 this.ResetColumns(lst);
3664 catch (Exception ex)
3666 ex.Data["Instance"] = "ListView(IconSize)";
3667 ex.Data["IsTerminatePermission"] = false;
3671 this.SetMainWindowTitle();
3672 this.SetNotifyIconText();
3674 this.PurgeListViewItemCache();
3675 this.CurrentListView.Refresh();
3676 this.ListTab.Refresh();
3678 this.hookGlobalHotkey.UnregisterAllOriginalHotkey();
3679 if (SettingManager.Common.HotkeyEnabled)
3681 // グローバルホットキーの登録。設定で変更可能にするかも
3682 var modKey = HookGlobalHotkey.ModKeys.None;
3683 if ((SettingManager.Common.HotkeyModifier & Keys.Alt) == Keys.Alt)
3684 modKey |= HookGlobalHotkey.ModKeys.Alt;
3685 if ((SettingManager.Common.HotkeyModifier & Keys.Control) == Keys.Control)
3686 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
3687 if ((SettingManager.Common.HotkeyModifier & Keys.Shift) == Keys.Shift)
3688 modKey |= HookGlobalHotkey.ModKeys.Shift;
3689 if ((SettingManager.Common.HotkeyModifier & Keys.LWin) == Keys.LWin)
3690 modKey |= HookGlobalHotkey.ModKeys.Win;
3692 this.hookGlobalHotkey.RegisterOriginalHotkey(SettingManager.Common.HotkeyKey, SettingManager.Common.HotkeyValue, modKey);
3695 if (SettingManager.Common.IsUseNotifyGrowl) this.gh.RegisterGrowl();
3698 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
3707 // キャンセル時は Twitter クラスの認証情報を画面表示前の状態に戻す
3708 this.tw.Initialize(oldUser.AccessToken, oldUser.AccessTokenSecret, oldUser.Username, oldUser.UserId);
3711 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
3713 this.TopMost = SettingManager.Common.AlwaysTop;
3714 this.SaveConfigsAll(false);
3716 if (this.tw.UserId != oldUser.UserId)
3717 await this.DoGetFollowersMenu();
3723 private void SetTabAlignment()
3725 var newAlignment = SettingManager.Common.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
3726 if (this.ListTab.Alignment == newAlignment) return;
3728 // 各タブのリスト上の選択位置などを退避
3729 var listSelections = this.SaveListViewSelection();
3731 this.ListTab.Alignment = newAlignment;
3733 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3735 var lst = (DetailsListView)this.ListTab.TabPages[index].Tag;
3736 using (ControlTransaction.Update(lst))
3739 this.RestoreListViewSelection(lst, tab, listSelections[tab.TabName]);
3744 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
3747 this.iconSz = iconSz switch
3749 MyCommon.IconSizes.IconNone => 0,
3750 MyCommon.IconSizes.Icon16 => 16,
3751 MyCommon.IconSizes.Icon24 => 26,
3752 MyCommon.IconSizes.Icon48 => 48,
3753 MyCommon.IconSizes.Icon48_2 => 48,
3754 _ => throw new InvalidEnumArgumentException(nameof(iconSz), (int)iconSz, typeof(MyCommon.IconSizes)),
3756 this.iconCol = iconSz == MyCommon.IconSizes.Icon48_2;
3758 this.PurgeListViewItemCache();
3760 if (this.iconSz > 0)
3762 // ディスプレイの DPI 設定を考慮したサイズを設定する
3763 this.listViewImageList.ImageSize = new Size(
3765 (int)Math.Ceiling(this.iconSz * this.CurrentScaleFactor.Height));
3769 this.listViewImageList.ImageSize = new Size(1, 1);
3773 private void ResetColumns(DetailsListView list)
3775 using (ControlTransaction.Update(list))
3776 using (ControlTransaction.Layout(list, false))
3779 list.ColumnClick -= this.MyList_ColumnClick;
3780 list.DrawColumnHeader -= this.MyList_DrawColumnHeader;
3781 list.ColumnReordered -= this.MyList_ColumnReordered;
3782 list.ColumnWidthChanged -= this.MyList_ColumnWidthChanged;
3784 var cols = list.Columns.Cast<ColumnHeader>().ToList();
3785 list.Columns.Clear();
3786 cols.ForEach(col => col.Dispose());
3789 this.InitColumns(list, true);
3791 list.ColumnClick += this.MyList_ColumnClick;
3792 list.DrawColumnHeader += this.MyList_DrawColumnHeader;
3793 list.ColumnReordered += this.MyList_ColumnReordered;
3794 list.ColumnWidthChanged += this.MyList_ColumnWidthChanged;
3798 public void AddNewTabForSearch(string searchWord)
3800 // 同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
3801 foreach (var tb in this.statuses.GetTabsByType<PublicSearchTabModel>())
3803 if (tb.SearchWords == searchWord && MyCommon.IsNullOrEmpty(tb.SearchLang))
3805 var tabIndex = this.statuses.Tabs.IndexOf(tb);
3806 this.ListTab.SelectedIndex = tabIndex;
3811 var tabName = searchWord;
3812 for (var i = 0; i <= 100; i++)
3814 if (this.statuses.ContainsTab(tabName))
3820 var tab = new PublicSearchTabModel(tabName);
3821 this.statuses.AddTab(tab);
3822 this.AddNewTab(tab, startup: false);
3824 this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1;
3826 var tabPage = this.CurrentTabPage;
3827 var cmb = (ComboBox)tabPage.Controls["panelSearch"].Controls["comboSearch"];
3828 cmb.Items.Add(searchWord);
3829 cmb.Text = searchWord;
3830 this.SaveConfigsTabs();
3832 this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
3835 private async Task ShowUserTimeline()
3837 var post = this.CurrentPost;
3838 if (post == null || !this.ExistCurrentPost) return;
3839 await this.AddNewTabForUserTimeline(post.ScreenName);
3842 private async Task ShowRetweeterTimeline()
3844 var retweetedBy = this.CurrentPost?.RetweetedBy;
3845 if (retweetedBy == null || !this.ExistCurrentPost) return;
3846 await this.AddNewTabForUserTimeline(retweetedBy);
3849 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
3851 if (e.KeyCode == Keys.Escape)
3853 this.RemoveSpecifiedTab(this.CurrentTabName, false);
3854 this.SaveConfigsTabs();
3855 e.SuppressKeyPress = true;
3859 public async Task AddNewTabForUserTimeline(string user)
3861 // 同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
3862 foreach (var tb in this.statuses.GetTabsByType<UserTimelineTabModel>())
3864 if (tb.ScreenName == user)
3866 var tabIndex = this.statuses.Tabs.IndexOf(tb);
3867 this.ListTab.SelectedIndex = tabIndex;
3872 var tabName = "user:" + user;
3873 while (this.statuses.ContainsTab(tabName))
3878 var tab = new UserTimelineTabModel(tabName, user);
3879 this.statuses.AddTab(tab);
3880 this.AddNewTab(tab, startup: false);
3882 this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1;
3883 this.SaveConfigsTabs();
3885 await this.RefreshTabAsync(tab);
3888 public bool AddNewTab(TabModel tab, bool startup)
3891 if (this.ListTab.TabPages.Cast<TabPage>().Any(x => x.Text == tab.TabName))
3895 if (tab.TabName == Properties.Resources.AddNewTabText1) return false;
3897 var tabPage = new TabPage();
3898 var listCustom = new DetailsListView();
3900 var cnt = this.statuses.Tabs.Count;
3902 // ToDo:Create and set controls follow tabtypes
3904 using (ControlTransaction.Update(listCustom))
3905 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
3906 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
3907 using (ControlTransaction.Layout(this.SplitContainer1, false))
3908 using (ControlTransaction.Layout(this.ListTab, false))
3909 using (ControlTransaction.Layout(this))
3910 using (ControlTransaction.Layout(tabPage, false))
3912 tabPage.Controls.Add(listCustom);
3915 var userTab = tab as UserTimelineTabModel;
3916 var listTab = tab as ListTimelineTabModel;
3917 var searchTab = tab as PublicSearchTabModel;
3919 if (userTab != null || listTab != null)
3921 var label = new Label
3923 Dock = DockStyle.Top,
3928 if (listTab != null)
3930 label.Text = listTab.ListInfo.ToString();
3932 else if (userTab != null)
3934 label.Text = userTab.ScreenName + "'s Timeline";
3936 label.TextAlign = ContentAlignment.MiddleLeft;
3937 using (var tmpComboBox = new ComboBox())
3939 label.Height = tmpComboBox.Height;
3941 tabPage.Controls.Add(label);
3944 else if (searchTab != null)
3946 var pnl = new Panel();
3948 var lbl = new Label();
3949 var cmb = new ComboBox();
3950 var btn = new Button();
3951 var cmbLang = new ComboBox();
3953 using (ControlTransaction.Layout(pnl, false))
3955 pnl.Controls.Add(cmb);
3956 pnl.Controls.Add(cmbLang);
3957 pnl.Controls.Add(btn);
3958 pnl.Controls.Add(lbl);
3959 pnl.Name = "panelSearch";
3961 pnl.Dock = DockStyle.Top;
3962 pnl.Height = cmb.Height;
3963 pnl.Enter += this.SearchControls_Enter;
3964 pnl.Leave += this.SearchControls_Leave;
3967 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
3968 cmb.Dock = DockStyle.Fill;
3969 cmb.Name = "comboSearch";
3970 cmb.DropDownStyle = ComboBoxStyle.DropDown;
3971 cmb.ImeMode = ImeMode.NoControl;
3972 cmb.TabStop = false;
3974 cmb.AutoCompleteMode = AutoCompleteMode.None;
3975 cmb.KeyDown += this.SearchComboBox_KeyDown;
3978 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
3979 cmbLang.Dock = DockStyle.Right;
3981 cmbLang.Name = "comboLang";
3982 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
3983 cmbLang.TabStop = false;
3984 cmbLang.TabIndex = 2;
3985 cmbLang.Items.Add("");
3986 cmbLang.Items.Add("ja");
3987 cmbLang.Items.Add("en");
3988 cmbLang.Items.Add("ar");
3989 cmbLang.Items.Add("da");
3990 cmbLang.Items.Add("nl");
3991 cmbLang.Items.Add("fa");
3992 cmbLang.Items.Add("fi");
3993 cmbLang.Items.Add("fr");
3994 cmbLang.Items.Add("de");
3995 cmbLang.Items.Add("hu");
3996 cmbLang.Items.Add("is");
3997 cmbLang.Items.Add("it");
3998 cmbLang.Items.Add("no");
3999 cmbLang.Items.Add("pl");
4000 cmbLang.Items.Add("pt");
4001 cmbLang.Items.Add("ru");
4002 cmbLang.Items.Add("es");
4003 cmbLang.Items.Add("sv");
4004 cmbLang.Items.Add("th");
4006 lbl.Text = "Search(C-S-f)";
4007 lbl.Name = "label1";
4008 lbl.Dock = DockStyle.Left;
4010 lbl.Height = cmb.Height;
4011 lbl.TextAlign = ContentAlignment.MiddleLeft;
4014 btn.Text = "Search";
4015 btn.Name = "buttonSearch";
4016 btn.UseVisualStyleBackColor = true;
4017 btn.Dock = DockStyle.Right;
4018 btn.TabStop = false;
4020 btn.Click += this.SearchButton_Click;
4022 if (!MyCommon.IsNullOrEmpty(searchTab.SearchWords))
4024 cmb.Items.Add(searchTab.SearchWords);
4025 cmb.Text = searchTab.SearchWords;
4028 cmbLang.Text = searchTab.SearchLang;
4030 tabPage.Controls.Add(pnl);
4034 tabPage.Tag = listCustom;
4035 this.ListTab.Controls.Add(tabPage);
4037 tabPage.Location = new Point(4, 4);
4038 tabPage.Name = "CTab" + cnt;
4039 tabPage.Size = new Size(380, 260);
4040 tabPage.TabIndex = 2 + cnt;
4041 tabPage.Text = tab.TabName;
4042 tabPage.UseVisualStyleBackColor = true;
4043 tabPage.AccessibleRole = AccessibleRole.PageTab;
4045 listCustom.AccessibleName = Properties.Resources.AddNewTab_ListView_AccessibleName;
4046 listCustom.TabIndex = 1;
4047 listCustom.AllowColumnReorder = true;
4048 listCustom.ContextMenuStrip = this.ContextMenuOperate;
4049 listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
4050 listCustom.Dock = DockStyle.Fill;
4051 listCustom.FullRowSelect = true;
4052 listCustom.HideSelection = false;
4053 listCustom.Location = new Point(0, 0);
4054 listCustom.Margin = new Padding(0);
4055 listCustom.Name = "CList" + Environment.TickCount;
4056 listCustom.ShowItemToolTips = true;
4057 listCustom.Size = new Size(380, 260);
4058 listCustom.UseCompatibleStateImageBehavior = false;
4059 listCustom.View = View.Details;
4060 listCustom.OwnerDraw = true;
4061 listCustom.VirtualMode = true;
4062 listCustom.Font = this.fntReaded;
4063 listCustom.BackColor = this.clListBackcolor;
4065 listCustom.GridLines = SettingManager.Common.ShowGrid;
4066 listCustom.AllowDrop = true;
4068 listCustom.SmallImageList = this.listViewImageList;
4070 this.InitColumns(listCustom, startup);
4072 listCustom.SelectedIndexChanged += this.MyList_SelectedIndexChanged;
4073 listCustom.MouseDoubleClick += this.MyList_MouseDoubleClick;
4074 listCustom.ColumnClick += this.MyList_ColumnClick;
4075 listCustom.DrawColumnHeader += this.MyList_DrawColumnHeader;
4076 listCustom.DragDrop += this.TweenMain_DragDrop;
4077 listCustom.DragEnter += this.TweenMain_DragEnter;
4078 listCustom.DragOver += this.TweenMain_DragOver;
4079 listCustom.DrawItem += this.MyList_DrawItem;
4080 listCustom.MouseClick += this.MyList_MouseClick;
4081 listCustom.ColumnReordered += this.MyList_ColumnReordered;
4082 listCustom.ColumnWidthChanged += this.MyList_ColumnWidthChanged;
4083 listCustom.CacheVirtualItems += this.MyList_CacheVirtualItems;
4084 listCustom.RetrieveVirtualItem += this.MyList_RetrieveVirtualItem;
4085 listCustom.DrawSubItem += this.MyList_DrawSubItem;
4086 listCustom.HScrolled += this.MyList_HScrolled;
4092 public bool RemoveSpecifiedTab(string tabName, bool confirm)
4094 var tabInfo = this.statuses.GetTabByName(tabName);
4095 if (tabInfo == null || tabInfo.IsDefaultTabType || tabInfo.Protected)
4100 var tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
4101 var result = MessageBox.Show(
4103 tabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
4104 MessageBoxButtons.OKCancel,
4105 MessageBoxIcon.Question,
4106 MessageBoxDefaultButton.Button2);
4107 if (result == DialogResult.Cancel)
4113 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
4117 var tabPage = this.ListTab.TabPages[tabIndex];
4119 this.SetListProperty(); // 他のタブに列幅等を反映
4122 var listCustom = (DetailsListView)tabPage.Tag;
4125 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
4126 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
4127 using (ControlTransaction.Layout(this.SplitContainer1, false))
4128 using (ControlTransaction.Layout(this.ListTab, false))
4129 using (ControlTransaction.Layout(this))
4130 using (ControlTransaction.Layout(tabPage, false))
4132 if (this.CurrentTabName == tabName)
4134 this.ListTab.SelectTab((this.beforeSelectedTab != null && this.ListTab.TabPages.Contains(this.beforeSelectedTab)) ? this.beforeSelectedTab : this.ListTab.TabPages[0]);
4135 this.beforeSelectedTab = null;
4137 this.ListTab.Controls.Remove(tabPage);
4140 if (tabInfo.TabType == MyCommon.TabUsageType.UserTimeline || tabInfo.TabType == MyCommon.TabUsageType.Lists)
4142 using var label = tabPage.Controls["labelUser"];
4143 tabPage.Controls.Remove(label);
4145 else if (tabInfo.TabType == MyCommon.TabUsageType.PublicSearch)
4147 using var pnl = tabPage.Controls["panelSearch"];
4149 pnl.Enter -= this.SearchControls_Enter;
4150 pnl.Leave -= this.SearchControls_Leave;
4151 tabPage.Controls.Remove(pnl);
4153 foreach (Control ctrl in pnl.Controls)
4155 if (ctrl.Name == "buttonSearch")
4157 ctrl.Click -= this.SearchButton_Click;
4159 else if (ctrl.Name == "comboSearch")
4161 ctrl.KeyDown -= this.SearchComboBox_KeyDown;
4163 pnl.Controls.Remove(ctrl);
4168 tabPage.Controls.Remove(listCustom);
4170 listCustom.SelectedIndexChanged -= this.MyList_SelectedIndexChanged;
4171 listCustom.MouseDoubleClick -= this.MyList_MouseDoubleClick;
4172 listCustom.ColumnClick -= this.MyList_ColumnClick;
4173 listCustom.DrawColumnHeader -= this.MyList_DrawColumnHeader;
4174 listCustom.DragDrop -= this.TweenMain_DragDrop;
4175 listCustom.DragEnter -= this.TweenMain_DragEnter;
4176 listCustom.DragOver -= this.TweenMain_DragOver;
4177 listCustom.DrawItem -= this.MyList_DrawItem;
4178 listCustom.MouseClick -= this.MyList_MouseClick;
4179 listCustom.ColumnReordered -= this.MyList_ColumnReordered;
4180 listCustom.ColumnWidthChanged -= this.MyList_ColumnWidthChanged;
4181 listCustom.CacheVirtualItems -= this.MyList_CacheVirtualItems;
4182 listCustom.RetrieveVirtualItem -= this.MyList_RetrieveVirtualItem;
4183 listCustom.DrawSubItem -= this.MyList_DrawSubItem;
4184 listCustom.HScrolled -= this.MyList_HScrolled;
4186 var cols = listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
4187 listCustom.Columns.Clear();
4188 cols.ForEach(col => col.Dispose());
4191 listCustom.ContextMenuStrip = null;
4192 listCustom.ColumnHeaderContextMenuStrip = null;
4193 listCustom.Font = null;
4195 listCustom.SmallImageList = null;
4196 listCustom.ListViewItemSorter = null;
4199 this.PurgeListViewItemCache();
4203 listCustom.Dispose();
4204 this.statuses.RemoveTab(tabName);
4206 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
4208 var lst = (DetailsListView)this.ListTab.TabPages[index].Tag;
4209 lst.VirtualListSize = tab.AllCount;
4215 private void ListTab_Deselected(object sender, TabControlEventArgs e)
4217 this.PurgeListViewItemCache();
4218 this.beforeSelectedTab = e.TabPage;
4221 private void ListTab_MouseMove(object sender, MouseEventArgs e)
4225 if (!SettingManager.Common.TabMouseLock && e.Button == MouseButtons.Left && this.tabDrag)
4228 var dragEnableRectangle = new Rectangle(this.tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2), this.tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
4229 if (!dragEnableRectangle.Contains(e.Location))
4231 // タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
4232 tn = this.CurrentTabName;
4235 if (MyCommon.IsNullOrEmpty(tn)) return;
4237 var tabIndex = this.statuses.Tabs.IndexOf(tn);
4240 var tabPage = this.ListTab.TabPages[tabIndex];
4241 this.ListTab.DoDragDrop(tabPage, DragDropEffects.All);
4246 this.tabDrag = false;
4249 var cpos = new Point(e.X, e.Y);
4250 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
4252 var rect = this.ListTab.GetTabRect(index);
4253 if (rect.Contains(cpos))
4255 this.rclickTabName = tab.TabName;
4261 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
4263 this.SetMainWindowTitle();
4264 this.SetStatusLabelUrl();
4265 this.SetApiStatusLabel();
4266 if (this.ListTab.Focused || ((Control)this.CurrentTabPage.Tag).Focused)
4267 this.Tag = this.ListTab.Tag;
4268 this.TabMenuControl(this.CurrentTabName);
4269 this.PushSelectPostChain();
4270 this.DispSelectedPost();
4273 private void SetListProperty()
4275 if (!this.isColumnChanged) return;
4277 var currentListView = this.CurrentListView;
4279 var dispOrder = new int[currentListView.Columns.Count];
4280 for (var i = 0; i < currentListView.Columns.Count; i++)
4282 for (var j = 0; j < currentListView.Columns.Count; j++)
4284 if (currentListView.Columns[j].DisplayIndex == i)
4293 foreach (TabPage tb in this.ListTab.TabPages)
4295 if (tb.Text == this.CurrentTabName)
4298 if (tb.Tag != null && tb.Controls.Count > 0)
4300 var lst = (DetailsListView)tb.Tag;
4301 for (var i = 0; i < lst.Columns.Count; i++)
4303 lst.Columns[dispOrder[i]].DisplayIndex = i;
4304 lst.Columns[i].Width = currentListView.Columns[i].Width;
4309 this.isColumnChanged = false;
4312 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
4314 if (e.KeyChar == '@')
4316 if (!SettingManager.Common.UseAtIdSupplement) return;
4318 var cnt = this.AtIdSupl.ItemCount;
4319 this.ShowSuplDialog(this.StatusText, this.AtIdSupl);
4320 if (cnt != this.AtIdSupl.ItemCount)
4321 this.MarkSettingAtIdModified();
4324 else if (e.KeyChar == '#')
4326 if (!SettingManager.Common.UseHashSupplement) return;
4327 this.ShowSuplDialog(this.StatusText, this.HashSupl);
4332 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
4333 => this.ShowSuplDialog(owner, dialog, 0, "");
4335 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
4336 => this.ShowSuplDialog(owner, dialog, offset, "");
4338 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
4340 dialog.StartsWith = startswith;
4347 dialog.ShowDialog();
4349 this.TopMost = SettingManager.Common.AlwaysTop;
4350 var selStart = owner.SelectionStart;
4353 if (dialog.DialogResult == DialogResult.OK)
4355 if (!MyCommon.IsNullOrEmpty(dialog.InputText))
4359 fHalf = owner.Text.Substring(0, selStart - offset);
4361 if (selStart < owner.Text.Length)
4363 eHalf = owner.Text.Substring(selStart);
4365 owner.Text = fHalf + dialog.InputText + eHalf;
4366 owner.SelectionStart = selStart + dialog.InputText.Length;
4373 fHalf = owner.Text.Substring(0, selStart);
4375 if (selStart < owner.Text.Length)
4377 eHalf = owner.Text.Substring(selStart);
4379 owner.Text = fHalf + eHalf;
4382 owner.SelectionStart = selStart;
4388 private void StatusText_KeyUp(object sender, KeyEventArgs e)
4391 if (!e.Alt && !e.Control && !e.Shift)
4393 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
4395 var isSpace = false;
4396 foreach (var c in this.StatusText.Text)
4398 if (c == ' ' || c == ' ')
4411 this.StatusText.Text = "";
4412 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
4416 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
4419 private void StatusText_TextChanged(object sender, EventArgs e)
4422 var pLen = this.GetRestStatusCount(this.FormatStatusTextExtended(this.StatusText.Text));
4423 this.lblLen.Text = pLen.ToString();
4426 this.StatusText.ForeColor = Color.Red;
4430 this.StatusText.ForeColor = this.clInputFont;
4433 this.StatusText.AccessibleDescription = string.Format(Properties.Resources.StatusText_AccessibleDescription, pLen);
4435 if (MyCommon.IsNullOrEmpty(this.StatusText.Text))
4437 this.inReplyTo = null;
4442 /// メンション以外の文字列が含まれていないテキストであるか判定します
4444 internal static bool TextContainsOnlyMentions(string text)
4446 var mentions = TweetExtractor.ExtractMentionEntities(text).OrderBy(x => x.Indices[0]);
4449 foreach (var mention in mentions)
4451 var textPart = text.Substring(startIndex, mention.Indices[0] - startIndex);
4453 if (!string.IsNullOrWhiteSpace(textPart))
4456 startIndex = mention.Indices[1];
4459 var textPartLast = text.Substring(startIndex);
4461 if (!string.IsNullOrWhiteSpace(textPartLast))
4468 /// 投稿時に auto_populate_reply_metadata オプションによって自動で追加されるメンションを除去します
4470 private string RemoveAutoPopuratedMentions(string statusText, out long[] autoPopulatedUserIds)
4472 var autoPopulatedUserIdList = new List<long>();
4474 var replyToPost = this.inReplyTo != null ? this.statuses[this.inReplyTo.Value.StatusId] : null;
4475 if (replyToPost != null)
4477 if (statusText.StartsWith($"@{replyToPost.ScreenName} ", StringComparison.Ordinal))
4479 statusText = statusText.Substring(replyToPost.ScreenName.Length + 2);
4480 autoPopulatedUserIdList.Add(replyToPost.UserId);
4482 foreach (var (userId, screenName) in replyToPost.ReplyToList)
4484 if (statusText.StartsWith($"@{screenName} ", StringComparison.Ordinal))
4486 statusText = statusText.Substring(screenName.Length + 2);
4487 autoPopulatedUserIdList.Add(userId);
4493 autoPopulatedUserIds = autoPopulatedUserIdList.ToArray();
4499 /// attachment_url に指定可能な URL が含まれていれば除去
4501 private string RemoveAttachmentUrl(string statusText, out string? attachmentUrl)
4503 attachmentUrl = null;
4505 // attachment_url は media_id と同時に使用できない
4506 if (this.ImageSelector.Visible && this.ImageSelector.SelectedService is TwitterPhoto)
4509 var match = Twitter.AttachmentUrlRegex.Match(statusText);
4513 attachmentUrl = match.Value;
4516 statusText = statusText.Substring(0, match.Index);
4518 // テキストと URL の間にスペースが含まれていれば除去
4519 return statusText.TrimEnd(' ');
4522 private string FormatStatusTextExtended(string statusText)
4523 => this.FormatStatusTextExtended(statusText, out _, out _);
4526 /// <see cref="FormatStatusText"/> に加えて、拡張モードで140字にカウントされない文字列の除去を行います
4528 private string FormatStatusTextExtended(string statusText, out long[] autoPopulatedUserIds, out string? attachmentUrl)
4530 statusText = this.RemoveAutoPopuratedMentions(statusText, out autoPopulatedUserIds);
4532 statusText = this.RemoveAttachmentUrl(statusText, out attachmentUrl);
4534 return this.FormatStatusText(statusText);
4538 /// ツイート投稿前のフッター付与などの前処理を行います
4540 private string FormatStatusText(string statusText)
4542 statusText = statusText.Replace("\r\n", "\n");
4544 if (this.urlMultibyteSplit)
4547 statusText = Regex.Replace(statusText, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
4550 if (SettingManager.Common.WideSpaceConvert)
4552 // 文中の全角スペースを半角スペース1個にする
4553 statusText = statusText.Replace(" ", " ");
4556 // DM の場合はこれ以降の処理を行わない
4557 if (statusText.StartsWith("D ", StringComparison.OrdinalIgnoreCase))
4561 if (SettingManager.Common.PostShiftEnter)
4563 disableFooter = MyCommon.IsKeyDown(Keys.Control);
4567 if (this.StatusText.Multiline && !SettingManager.Common.PostCtrlEnter)
4568 disableFooter = MyCommon.IsKeyDown(Keys.Control);
4570 disableFooter = MyCommon.IsKeyDown(Keys.Shift);
4573 if (statusText.Contains("RT @"))
4574 disableFooter = true;
4576 // 自分宛のリプライの場合は先頭の「@screen_name 」の部分を除去する (in_reply_to_status_id は維持される)
4577 if (this.inReplyTo != null && this.inReplyTo.Value.ScreenName == this.tw.Username)
4579 var mentionSelf = $"@{this.tw.Username} ";
4580 if (statusText.StartsWith(mentionSelf, StringComparison.OrdinalIgnoreCase))
4582 if (statusText.Length > mentionSelf.Length || this.GetSelectedImageService() != null)
4583 statusText = statusText.Substring(mentionSelf.Length);
4590 var hashtag = this.HashMgr.UseHash;
4591 if (!MyCommon.IsNullOrEmpty(hashtag) && !(this.HashMgr.IsNotAddToAtReply && this.inReplyTo != null))
4593 if (this.HashMgr.IsHead)
4594 header = this.HashMgr.UseHash + " ";
4596 footer = " " + this.HashMgr.UseHash;
4601 if (SettingManager.Local.UseRecommendStatus)
4604 footer += this.recommendedStatusFooter;
4606 else if (!MyCommon.IsNullOrEmpty(SettingManager.Local.StatusText))
4608 // テキストボックスに入力されている文字列を使用する
4609 footer += " " + SettingManager.Local.StatusText.Trim();
4613 statusText = header + statusText + footer;
4615 if (this.preventSmsCommand)
4617 // ツイートが意図せず SMS コマンドとして解釈されることを回避 (D, DM, M のみ)
4618 // 参照: https://support.twitter.com/articles/14020
4620 if (Regex.IsMatch(statusText, @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(d|dm|m)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)", RegexOptions.IgnoreCase)
4621 && !Twitter.DMSendTextRegex.IsMatch(statusText))
4623 // U+200B (ZERO WIDTH SPACE) を先頭に加えて回避
4624 statusText = '\u200b' + statusText;
4632 /// 投稿欄に表示する入力可能な文字数を計算します
4634 private int GetRestStatusCount(string statusText)
4636 var remainCount = this.tw.GetTextLengthRemain(statusText);
4638 var uploadService = this.GetSelectedImageService();
4639 if (uploadService != null)
4641 // TODO: ImageSelector で選択中の画像の枚数が mediaCount 引数に渡るようにする
4642 remainCount -= uploadService.GetReservedTextLength(1);
4648 private IMediaUploadService? GetSelectedImageService()
4649 => this.ImageSelector.Visible ? this.ImageSelector.SelectedService : null;
4651 private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
4653 if (sender != this.CurrentListView)
4656 var listCache = this.listItemCache;
4657 if (listCache?.TargetList == sender && listCache.IsSupersetOf(e.StartIndex, e.EndIndex))
4659 // If the newly requested cache is a subset of the old cache,
4660 // no need to rebuild everything, so do nothing.
4664 // Now we need to rebuild the cache.
4665 this.CreateCache(e.StartIndex, e.EndIndex);
4668 private void MyList_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
4670 var listCache = this.listItemCache;
4671 if (listCache?.TargetList == sender)
4673 if (listCache.TryGetValue(e.ItemIndex, out var item, out _))
4680 // A cache miss, so create a new ListViewItem and pass it back.
4681 var tabPage = (TabPage)((DetailsListView)sender).Parent;
4682 var tab = this.statuses.Tabs[tabPage.Text];
4685 e.Item = this.CreateItem(tab, tab[e.ItemIndex]);
4689 // 不正な要求に対する間に合わせの応答
4690 string[] sitem = { "", "", "", "", "", "", "", "" };
4691 e.Item = new ImageListViewItem(sitem);
4695 private void CreateCache(int startIndex, int endIndex)
4697 var tabInfo = this.CurrentTab;
4699 if (tabInfo.AllCount == 0)
4702 // インデックスを 0...(tabInfo.AllCount - 1) の範囲内にする
4703 int FilterRange(int index)
4704 => Math.Max(Math.Min(index, tabInfo.AllCount - 1), 0);
4706 // キャッシュ要求(要求範囲±30を作成)
4707 startIndex = FilterRange(startIndex - 30);
4708 endIndex = FilterRange(endIndex + 30);
4710 var cacheLength = endIndex - startIndex + 1;
4712 var tab = this.CurrentTab;
4713 var posts = tabInfo[startIndex, endIndex]; // 配列で取得
4714 var listItems = Enumerable.Range(0, cacheLength)
4715 .Select(x => this.CreateItem(tab, posts[x]))
4718 var listCache = new ListViewItemCache
4720 TargetList = this.CurrentListView,
4721 StartIndex = startIndex,
4722 EndIndex = endIndex,
4723 Cache = Enumerable.Zip(listItems, posts, (x, y) => (x, y)).ToArray(),
4726 Interlocked.Exchange(ref this.listItemCache, listCache);
4730 /// DetailsListView のための ListViewItem のキャッシュを消去する
4732 private void PurgeListViewItemCache()
4733 => Interlocked.Exchange(ref this.listItemCache, null);
4735 private ListViewItem CreateItem(TabModel tab, PostClass post)
4737 var mk = new StringBuilder();
4739 if (post.FavoritedCount > 0) mk.Append("+" + post.FavoritedCount);
4741 var scaledIconSz = (int)Math.Ceiling(this.iconSz * this.CurrentScaleFactor.Width);
4743 ImageListViewItem itm;
4744 if (post.RetweetedId == null)
4750 post.IsDeleted ? "(DELETED)" : post.AccessibleText.Replace('\n', ' '),
4751 post.CreatedAt.ToLocalTimeString(SettingManager.Common.DateTimeFormat),
4757 itm = new ImageListViewItem(sitem, this.iconCache, post.ImageUrl, scaledIconSz);
4765 post.IsDeleted ? "(DELETED)" : post.AccessibleText.Replace('\n', ' '),
4766 post.CreatedAt.ToLocalTimeString(SettingManager.Common.DateTimeFormat),
4767 post.ScreenName + Environment.NewLine + "(RT:" + post.RetweetedBy + ")",
4772 itm = new ImageListViewItem(sitem, this.iconCache, post.ImageUrl, scaledIconSz);
4774 itm.StateIndex = post.StateIndex;
4777 var read = post.IsRead;
4778 // 未読管理していなかったら既読として扱う
4779 if (!tab.UnreadManage || !SettingManager.Common.UnreadManage)
4782 this.ChangeItemStyleRead(read, itm, post, null);
4784 if (tab.TabName == this.CurrentTabName)
4785 this.ColorizeList(itm, post);
4791 /// 全てのタブの振り分けルールを反映し直します
4793 private void ApplyPostFilters()
4795 using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
4797 this.PurgeListViewItemCache();
4798 this.statuses.FilterAll();
4800 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
4802 var tabPage = this.ListTab.TabPages[index];
4803 var listview = (DetailsListView)tabPage.Tag;
4804 using (ControlTransaction.Update(listview))
4806 listview.VirtualListSize = tab.AllCount;
4809 if (SettingManager.Common.TabIconDisp)
4811 if (tab.UnreadCount > 0)
4812 tabPage.ImageIndex = 0;
4814 tabPage.ImageIndex = -1;
4818 if (!SettingManager.Common.TabIconDisp)
4819 this.ListTab.Refresh();
4821 this.SetMainWindowTitle();
4822 this.SetStatusLabelUrl();
4826 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
4827 => e.DrawDefault = true;
4829 private void MyList_HScrolled(object sender, EventArgs e)
4830 => ((DetailsListView)sender).Refresh();
4832 private void MyList_DrawItem(object sender, DrawListViewItemEventArgs e)
4834 if (e.State == 0) return;
4835 e.DrawDefault = false;
4838 if (!e.Item.Selected) // e.ItemStateでうまく判定できない???
4840 if (e.Item.BackColor == this.clSelf)
4841 brs2 = this.brsBackColorMine;
4842 else if (e.Item.BackColor == this.clAtSelf)
4843 brs2 = this.brsBackColorAt;
4844 else if (e.Item.BackColor == this.clTarget)
4845 brs2 = this.brsBackColorYou;
4846 else if (e.Item.BackColor == this.clAtTarget)
4847 brs2 = this.brsBackColorAtYou;
4848 else if (e.Item.BackColor == this.clAtFromTarget)
4849 brs2 = this.brsBackColorAtFromTarget;
4850 else if (e.Item.BackColor == this.clAtTo)
4851 brs2 = this.brsBackColorAtTo;
4853 brs2 = this.brsBackColorNone;
4858 if (((Control)sender).Focused)
4859 brs2 = this.brsHighLight;
4861 brs2 = this.brsDeactiveSelection;
4863 e.Graphics.FillRectangle(brs2, e.Bounds);
4864 e.DrawFocusRectangle();
4865 this.DrawListViewItemIcon(e);
4868 private void MyList_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
4870 if (e.ItemState == 0) return;
4872 if (e.ColumnIndex > 0)
4875 var post = (PostClass)e.Item.Tag;
4877 RectangleF rct = e.Bounds;
4878 rct.Width = e.Header.Width;
4879 var fontHeight = e.Item.Font.Height;
4882 rct.Y += fontHeight;
4883 rct.Height -= fontHeight;
4886 var drawLineCount = Math.Max(1, Math.DivRem((int)rct.Height, fontHeight, out var heightDiff));
4888 // フォントの高さの半分を足してるのは保険。無くてもいいかも。
4889 if (this.iconCol || drawLineCount > 1)
4891 if (heightDiff < fontHeight * 0.7)
4893 // 最終行が70%以上欠けていたら、最終行は表示しない
4894 rct.Height = (fontHeight * drawLineCount) - 1;
4904 var color = (!e.Item.Selected) ? e.Item.ForeColor : // 選択されていない行
4905 ((Control)sender).Focused ? this.clHighLight : // 選択中の行
4910 var rctB = e.Bounds;
4911 rctB.Width = e.Header.Width;
4912 rctB.Height = fontHeight;
4914 using var fnt = new Font(e.Item.Font, FontStyle.Bold);
4915 var formatFlags1 = TextFormatFlags.WordBreak |
4916 TextFormatFlags.EndEllipsis |
4917 TextFormatFlags.GlyphOverhangPadding |
4918 TextFormatFlags.NoPrefix;
4920 TextRenderer.DrawText(
4922 post.IsDeleted ? "(DELETED)" : post.TextSingleLine,
4924 Rectangle.Round(rct),
4928 var formatFlags2 = TextFormatFlags.SingleLine |
4929 TextFormatFlags.EndEllipsis |
4930 TextFormatFlags.GlyphOverhangPadding |
4931 TextFormatFlags.NoPrefix;
4933 TextRenderer.DrawText(
4935 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 + "]",
4944 if (e.ColumnIndex != 2)
4945 text = e.SubItem.Text;
4947 text = post.IsDeleted ? "(DELETED)" : post.TextSingleLine;
4949 if (drawLineCount == 1)
4951 var formatFlags = TextFormatFlags.SingleLine |
4952 TextFormatFlags.EndEllipsis |
4953 TextFormatFlags.GlyphOverhangPadding |
4954 TextFormatFlags.NoPrefix |
4955 TextFormatFlags.VerticalCenter;
4957 TextRenderer.DrawText(
4961 Rectangle.Round(rct),
4967 var formatFlags = TextFormatFlags.WordBreak |
4968 TextFormatFlags.EndEllipsis |
4969 TextFormatFlags.GlyphOverhangPadding |
4970 TextFormatFlags.NoPrefix;
4972 TextRenderer.DrawText(
4976 Rectangle.Round(rct),
4985 private void DrawListViewItemIcon(DrawListViewItemEventArgs e)
4987 if (this.iconSz == 0) return;
4989 var item = (ImageListViewItem)e.Item;
4991 // e.Bounds.Leftが常に0を指すから自前で計算
4992 var itemRect = item.Bounds;
4993 var col0 = e.Item.ListView.Columns[0];
4994 itemRect.Width = col0.Width;
4996 if (col0.DisplayIndex > 0)
4998 foreach (ColumnHeader clm in e.Item.ListView.Columns)
5000 if (clm.DisplayIndex < col0.DisplayIndex)
5001 itemRect.X += clm.Width;
5005 // ディスプレイの DPI 設定を考慮したアイコンサイズ
5006 var realIconSize = new SizeF(this.iconSz * this.CurrentScaleFactor.Width, this.iconSz * this.CurrentScaleFactor.Height).ToSize();
5007 var realStateSize = new SizeF(16 * this.CurrentScaleFactor.Width, 16 * this.CurrentScaleFactor.Height).ToSize();
5010 var img = item.Image;
5013 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, realIconSize), itemRect);
5014 iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
5016 if (iconRect.Width > 0)
5018 e.Graphics.FillRectangle(Brushes.White, iconRect);
5019 e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
5022 e.Graphics.DrawImage(img.Image, iconRect);
5024 catch (ArgumentException)
5026 item.RefreshImageAsync();
5032 iconRect = Rectangle.Intersect(new Rectangle(e.Item.GetBounds(ItemBoundsPortion.Icon).Location, new Size(1, 1)), itemRect);
5034 item.GetImageAsync();
5037 if (item.StateIndex > -1)
5039 var stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
5040 if (stateRect.Width > 0)
5041 e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
5045 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
5047 base.ScaleControl(factor, specified);
5049 ScaleChildControl(this.TabImage, factor);
5051 var tabpages = this.ListTab.TabPages.Cast<TabPage>();
5052 var listviews = tabpages.Select(x => x.Tag).Cast<ListView>();
5054 foreach (var listview in listviews)
5056 ScaleChildControl(listview, factor);
5060 internal void DoTabSearch(string searchWord, bool caseSensitive, bool useRegex, SEARCHTYPE searchType)
5062 var tab = this.CurrentTab;
5064 if (tab.AllCount == 0)
5066 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5070 var selectedIndex = tab.SelectedIndex;
5075 case SEARCHTYPE.NextSearch: // 次を検索
5076 if (selectedIndex != -1)
5077 startIndex = Math.Min(selectedIndex + 1, tab.AllCount - 1);
5081 case SEARCHTYPE.PrevSearch: // 前を検索
5082 if (selectedIndex != -1)
5083 startIndex = Math.Max(selectedIndex - 1, 0);
5085 startIndex = tab.AllCount - 1;
5087 case SEARCHTYPE.DialogSearch: // ダイアログからの検索
5089 if (selectedIndex != -1)
5090 startIndex = selectedIndex;
5096 Func<string, bool> stringComparer;
5099 stringComparer = this.CreateSearchComparer(searchWord, useRegex, caseSensitive);
5101 catch (ArgumentException)
5103 MessageBox.Show(Properties.Resources.DoTabSearchText1, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Error);
5107 var reverse = searchType == SEARCHTYPE.PrevSearch;
5108 var foundIndex = tab.SearchPostsAll(stringComparer, startIndex, reverse)
5109 .DefaultIfEmpty(-1).First();
5111 if (foundIndex == -1)
5113 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5117 var listView = this.CurrentListView;
5118 this.SelectListItem(listView, foundIndex);
5119 listView.EnsureVisible(foundIndex);
5122 private void MenuItemSubSearch_Click(object sender, EventArgs e)
5123 => this.ShowSearchDialog(); // 検索メニュー
5125 private void MenuItemSearchNext_Click(object sender, EventArgs e)
5127 var previousSearch = this.SearchDialog.ResultOptions;
5128 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5130 this.SearchDialog.Reset();
5131 this.ShowSearchDialog();
5137 previousSearch.Query,
5138 previousSearch.CaseSensitive,
5139 previousSearch.UseRegex,
5140 SEARCHTYPE.NextSearch);
5143 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
5145 var previousSearch = this.SearchDialog.ResultOptions;
5146 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
5148 this.SearchDialog.Reset();
5149 this.ShowSearchDialog();
5155 previousSearch.Query,
5156 previousSearch.CaseSensitive,
5157 previousSearch.UseRegex,
5158 SEARCHTYPE.PrevSearch);
5162 /// 検索ダイアログを表示し、検索を実行します
5164 private void ShowSearchDialog()
5166 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
5168 this.TopMost = SettingManager.Common.AlwaysTop;
5171 this.TopMost = SettingManager.Common.AlwaysTop;
5173 var searchOptions = this.SearchDialog.ResultOptions!;
5174 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
5176 if (searchOptions.NewTab)
5178 var tabName = Properties.Resources.SearchResults_TabName;
5182 tabName = this.statuses.MakeTabName(tabName);
5184 catch (TabException ex)
5186 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5189 var resultTab = new LocalSearchTabModel(tabName);
5190 this.AddNewTab(resultTab, startup: false);
5191 this.statuses.AddTab(resultTab);
5193 var targetTab = this.CurrentTab;
5195 Func<string, bool> stringComparer;
5198 stringComparer = this.CreateSearchComparer(searchOptions.Query, searchOptions.UseRegex, searchOptions.CaseSensitive);
5200 catch (ArgumentException)
5202 MessageBox.Show(Properties.Resources.DoTabSearchText1, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Error);
5206 var foundIndices = targetTab.SearchPostsAll(stringComparer).ToArray();
5207 if (foundIndices.Length == 0)
5209 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
5213 var foundPosts = foundIndices.Select(x => targetTab[x]);
5214 foreach (var post in foundPosts)
5216 resultTab.AddPostQueue(post);
5219 this.statuses.DistributePosts();
5220 this.RefreshTimeline();
5222 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
5223 this.ListTab.SelectedIndex = tabIndex;
5228 searchOptions.Query,
5229 searchOptions.CaseSensitive,
5230 searchOptions.UseRegex,
5231 SEARCHTYPE.DialogSearch);
5234 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
5236 this.AddNewTabForSearch(searchOptions.Query);
5240 /// <summary>発言検索に使用するメソッドを生成します</summary>
5241 /// <exception cref="ArgumentException">
5242 /// <paramref name="useRegex"/> が true かつ、<paramref name="query"/> が不正な正規表現な場合
5244 private Func<string, bool> CreateSearchComparer(string query, bool useRegex, bool caseSensitive)
5248 var regexOption = caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;
5249 var regex = new Regex(query, regexOption);
5251 return x => regex.IsMatch(x);
5255 var comparisonType = caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
5257 return x => x.IndexOf(query, comparisonType) != -1;
5261 private void AboutMenuItem_Click(object sender, EventArgs e)
5263 using (var about = new TweenAboutBox())
5265 about.ShowDialog(this);
5267 this.TopMost = SettingManager.Common.AlwaysTop;
5270 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
5272 var bgnIdx = this.statuses.SelectedTabIndex;
5274 if (this.ImageSelector.Enabled)
5277 TabModel? foundTab = null;
5281 foreach (var (tab, index) in this.statuses.Tabs.WithIndex().Skip(bgnIdx))
5283 var unreadIndex = tab.NextUnreadIndex;
5284 if (unreadIndex != -1)
5286 this.ListTab.SelectedIndex = index;
5288 foundIndex = unreadIndex;
5293 // 未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
5294 if (foundTab == null && bgnIdx > 0)
5296 foreach (var (tab, index) in this.statuses.Tabs.WithIndex().Take(bgnIdx))
5298 var unreadIndex = tab.NextUnreadIndex;
5299 if (unreadIndex != -1)
5301 this.ListTab.SelectedIndex = index;
5303 foundIndex = unreadIndex;
5309 DetailsListView lst;
5311 if (foundTab == null)
5313 // 全部調べたが未読見つからず→先頭タブの最新発言へ
5314 this.ListTab.SelectedIndex = 0;
5315 var tabPage = this.ListTab.TabPages[0];
5316 var tab = this.statuses.Tabs[0];
5318 if (tab.AllCount == 0)
5321 if (this.statuses.SortOrder == SortOrder.Ascending)
5322 foundIndex = tab.AllCount - 1;
5326 lst = (DetailsListView)tabPage.Tag;
5330 var foundTabIndex = this.statuses.Tabs.IndexOf(foundTab);
5331 lst = (DetailsListView)this.ListTab.TabPages[foundTabIndex].Tag;
5334 this.SelectListItem(lst, foundIndex);
5336 if (this.statuses.SortMode == ComparerMode.Id)
5338 if (this.statuses.SortOrder == SortOrder.Ascending && lst.Items[foundIndex].Position.Y > lst.ClientSize.Height - this.iconSz - 10 ||
5339 this.statuses.SortOrder == SortOrder.Descending && lst.Items[foundIndex].Position.Y < this.iconSz + 10)
5345 lst.EnsureVisible(foundIndex);
5350 lst.EnsureVisible(foundIndex);
5356 private async void StatusOpenMenuItem_Click(object sender, EventArgs e)
5358 var tab = this.CurrentTab;
5359 var post = this.CurrentPost;
5360 if (post != null && tab.TabType != MyCommon.TabUsageType.DirectMessage)
5361 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(post));
5364 private async void VerUpMenuItem_Click(object sender, EventArgs e)
5365 => await this.CheckNewVersion(false);
5367 private void RunTweenUp()
5369 var pinfo = new ProcessStartInfo
5371 UseShellExecute = true,
5372 WorkingDirectory = MyCommon.SettingPath,
5373 FileName = Path.Combine(MyCommon.SettingPath, "TweenUp3.exe"),
5374 Arguments = "\"" + Application.StartupPath + "\"",
5379 Process.Start(pinfo);
5383 MessageBox.Show("Failed to execute TweenUp3.exe.");
5387 public class VersionInfo
5389 public Version Version { get; }
5391 public Uri DownloadUri { get; }
5393 public string ReleaseNote { get; }
5395 public VersionInfo(Version version, Uri downloadUri, string releaseNote)
5396 => (this.Version, this.DownloadUri, this.ReleaseNote) = (version, downloadUri, releaseNote);
5400 /// OpenTween の最新バージョンの情報を取得します
5402 public async Task<VersionInfo> GetVersionInfoAsync()
5404 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
5405 DateTimeUtc.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
5407 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
5408 .ConfigureAwait(false);
5410 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
5411 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
5413 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
5414 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
5416 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
5418 return new VersionInfo(
5419 version: Version.Parse(msgHeader[0]),
5420 downloadUri: new Uri(msgHeader[1]),
5421 releaseNote: msgBody
5425 private async Task CheckNewVersion(bool startup = false)
5427 if (ApplicationSettings.VersionInfoUrl == null)
5428 return; // 更新チェック無効化
5432 var versionInfo = await this.GetVersionInfoAsync();
5434 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
5439 var msgtext = string.Format(
5440 Properties.Resources.CheckNewVersionText7,
5441 MyCommon.GetReadableVersion(),
5442 MyCommon.GetReadableVersion(versionInfo.Version));
5443 msgtext = MyCommon.ReplaceAppName(msgtext);
5447 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5448 MessageBoxButtons.OK,
5449 MessageBoxIcon.Information);
5454 if (startup && versionInfo.Version <= SettingManager.Common.SkipUpdateVersion)
5457 using var dialog = new UpdateDialog();
5459 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
5460 MyCommon.GetReadableVersion(versionInfo.Version));
5461 dialog.DetailsText = versionInfo.ReleaseNote;
5463 if (dialog.ShowDialog(this) == DialogResult.Yes)
5465 await MyCommon.OpenInBrowserAsync(this, versionInfo.DownloadUri.OriginalString);
5467 else if (dialog.SkipButtonPressed)
5469 SettingManager.Common.SkipUpdateVersion = versionInfo.Version;
5470 this.MarkSettingCommonModified();
5475 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
5479 Properties.Resources.CheckNewVersionText10,
5480 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
5481 MessageBoxButtons.OK,
5482 MessageBoxIcon.Exclamation,
5483 MessageBoxDefaultButton.Button2);
5488 private void UpdateSelectedPost()
5490 // 件数関連の場合、タイトル即時書き換え
5491 if (SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.None &&
5492 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.Post &&
5493 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
5494 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
5496 this.SetMainWindowTitle();
5498 if (!this.StatusLabelUrl.Text.StartsWith("http", StringComparison.OrdinalIgnoreCase))
5499 this.SetStatusLabelUrl();
5501 if (SettingManager.Common.TabIconDisp)
5503 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
5505 if (tab.UnreadCount == 0)
5507 var tabPage = this.ListTab.TabPages[index];
5508 if (tabPage.ImageIndex == 0)
5509 tabPage.ImageIndex = -1;
5515 this.ListTab.Refresh();
5518 this.DispSelectedPost();
5521 public string CreateDetailHtml(string orgdata)
5522 => this.detailHtmlFormatPreparedTemplate.Replace("%CONTENT_HTML%", orgdata);
5524 private void DispSelectedPost()
5525 => this.DispSelectedPost(false);
5527 private PostClass displayPost = new PostClass();
5530 /// サムネイル表示に使用する CancellationToken の生成元
5532 private CancellationTokenSource? thumbnailTokenSource = null;
5534 private void DispSelectedPost(bool forceupdate)
5536 var currentPost = this.CurrentPost;
5537 if (currentPost == null)
5540 var oldDisplayPost = this.displayPost;
5541 this.displayPost = currentPost;
5543 if (!forceupdate && currentPost.Equals(oldDisplayPost))
5546 var loadTasks = new List<Task>
5548 this.tweetDetailsView.ShowPostDetails(currentPost),
5551 this.SplitContainer3.Panel2Collapsed = true;
5553 if (SettingManager.Common.PreviewEnable)
5555 var oldTokenSource = Interlocked.Exchange(ref this.thumbnailTokenSource, new CancellationTokenSource());
5556 oldTokenSource?.Cancel();
5558 var token = this.thumbnailTokenSource!.Token;
5559 loadTasks.Add(this.tweetThumbnail1.ShowThumbnailAsync(currentPost, token));
5562 async Task DelayedTasks()
5566 await Task.WhenAll(loadTasks);
5568 catch (OperationCanceledException)
5573 // サムネイルの読み込みを待たずに次に選択されたツイートを表示するため await しない
5577 private async void MatomeMenuItem_Click(object sender, EventArgs e)
5578 => await this.OpenApplicationWebsite();
5580 private async Task OpenApplicationWebsite()
5581 => await MyCommon.OpenInBrowserAsync(this, ApplicationSettings.WebsiteUrl);
5583 private async void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
5584 => await MyCommon.OpenInBrowserAsync(this, ApplicationSettings.ShortcutKeyUrl);
5586 private async void ListTab_KeyDown(object sender, KeyEventArgs e)
5588 var tab = this.CurrentTab;
5589 if (tab.TabType == MyCommon.TabUsageType.PublicSearch)
5591 var pnl = this.CurrentTabPage.Controls["panelSearch"];
5592 if (pnl.Controls["comboSearch"].Focused ||
5593 pnl.Controls["comboLang"].Focused ||
5594 pnl.Controls["buttonSearch"].Focused) return;
5597 if (e.Control || e.Shift || e.Alt)
5598 this.anchorFlag = false;
5600 if (this.CommonKeyDown(e.KeyData, FocusedControl.ListTab, out var asyncTask))
5603 e.SuppressKeyPress = true;
5606 if (asyncTask != null)
5610 private ShortcutCommand[] shortcutCommands = Array.Empty<ShortcutCommand>();
5612 private void InitializeShortcuts()
5614 this.shortcutCommands = new[]
5616 // リストのカーソル移動関係(上下キー、PageUp/Downに該当)
5617 ShortcutCommand.Create(Keys.J, Keys.Control | Keys.J, Keys.Shift | Keys.J, Keys.Control | Keys.Shift | Keys.J)
5618 .FocusedOn(FocusedControl.ListTab)
5619 .Do(() => SendKeys.Send("{DOWN}")),
5621 ShortcutCommand.Create(Keys.K, Keys.Control | Keys.K, Keys.Shift | Keys.K, Keys.Control | Keys.Shift | Keys.K)
5622 .FocusedOn(FocusedControl.ListTab)
5623 .Do(() => SendKeys.Send("{UP}")),
5625 ShortcutCommand.Create(Keys.F, Keys.Shift | Keys.F)
5626 .FocusedOn(FocusedControl.ListTab)
5627 .Do(() => SendKeys.Send("{PGDN}")),
5629 ShortcutCommand.Create(Keys.B, Keys.Shift | Keys.B)
5630 .FocusedOn(FocusedControl.ListTab)
5631 .Do(() => SendKeys.Send("{PGUP}")),
5633 ShortcutCommand.Create(Keys.F1)
5634 .Do(() => this.OpenApplicationWebsite()),
5636 ShortcutCommand.Create(Keys.F3)
5637 .Do(() => this.MenuItemSearchNext_Click(this.MenuItemSearchNext, EventArgs.Empty)),
5639 ShortcutCommand.Create(Keys.F5)
5640 .Do(() => this.DoRefresh()),
5642 ShortcutCommand.Create(Keys.F6)
5643 .Do(() => this.RefreshTabAsync<MentionsTabModel>()),
5645 ShortcutCommand.Create(Keys.F7)
5646 .Do(() => this.RefreshTabAsync<DirectMessagesTabModel>()),
5648 ShortcutCommand.Create(Keys.Space, Keys.ProcessKey)
5649 .NotFocusedOn(FocusedControl.StatusText)
5652 this.anchorFlag = false;
5653 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
5656 ShortcutCommand.Create(Keys.G)
5657 .NotFocusedOn(FocusedControl.StatusText)
5660 this.anchorFlag = false;
5661 this.ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty);
5664 ShortcutCommand.Create(Keys.Right, Keys.N)
5665 .FocusedOn(FocusedControl.ListTab)
5666 .Do(() => this.GoRelPost(forward: true)),
5668 ShortcutCommand.Create(Keys.Left, Keys.P)
5669 .FocusedOn(FocusedControl.ListTab)
5670 .Do(() => this.GoRelPost(forward: false)),
5672 ShortcutCommand.Create(Keys.OemPeriod)
5673 .FocusedOn(FocusedControl.ListTab)
5674 .Do(() => this.GoAnchor()),
5676 ShortcutCommand.Create(Keys.I)
5677 .FocusedOn(FocusedControl.ListTab)
5678 .OnlyWhen(() => this.StatusText.Enabled)
5679 .Do(() => this.StatusText.Focus()),
5681 ShortcutCommand.Create(Keys.Enter)
5682 .FocusedOn(FocusedControl.ListTab)
5683 .Do(() => this.ListItemDoubleClickAction()),
5685 ShortcutCommand.Create(Keys.R)
5686 .FocusedOn(FocusedControl.ListTab)
5687 .Do(() => this.DoRefresh()),
5689 ShortcutCommand.Create(Keys.L)
5690 .FocusedOn(FocusedControl.ListTab)
5693 this.anchorFlag = false;
5694 this.GoPost(forward: true);
5697 ShortcutCommand.Create(Keys.H)
5698 .FocusedOn(FocusedControl.ListTab)
5701 this.anchorFlag = false;
5702 this.GoPost(forward: false);
5705 ShortcutCommand.Create(Keys.Z, Keys.Oemcomma)
5706 .FocusedOn(FocusedControl.ListTab)
5709 this.anchorFlag = false;
5713 ShortcutCommand.Create(Keys.S)
5714 .FocusedOn(FocusedControl.ListTab)
5717 this.anchorFlag = false;
5718 this.GoNextTab(forward: true);
5721 ShortcutCommand.Create(Keys.A)
5722 .FocusedOn(FocusedControl.ListTab)
5725 this.anchorFlag = false;
5726 this.GoNextTab(forward: false);
5729 // ] in_reply_to参照元へ戻る
5730 ShortcutCommand.Create(Keys.Oem4)
5731 .FocusedOn(FocusedControl.ListTab)
5734 this.anchorFlag = false;
5735 return this.GoInReplyToPostTree();
5738 // [ in_reply_toへジャンプ
5739 ShortcutCommand.Create(Keys.Oem6)
5740 .FocusedOn(FocusedControl.ListTab)
5743 this.anchorFlag = false;
5744 this.GoBackInReplyToPostTree();
5747 ShortcutCommand.Create(Keys.Escape)
5748 .FocusedOn(FocusedControl.ListTab)
5751 this.anchorFlag = false;
5752 var tab = this.CurrentTab;
5753 var tabtype = tab.TabType;
5754 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch || tabtype == MyCommon.TabUsageType.SearchResults)
5756 this.RemoveSpecifiedTab(tab.TabName, false);
5757 this.SaveConfigsTabs();
5761 // 上下キー, PageUp/Downキー, Home/Endキー は既定の動作を残しつつアンカー初期化
5762 ShortcutCommand.Create(Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown, Keys.Home, Keys.End)
5763 .FocusedOn(FocusedControl.ListTab)
5764 .Do(() => this.anchorFlag = false, preventDefault: false),
5766 // PreviewKeyDownEventArgs.IsInputKey を true にしてスクロールを発生させる
5767 ShortcutCommand.Create(Keys.Up, Keys.Down)
5768 .FocusedOn(FocusedControl.PostBrowser)
5771 ShortcutCommand.Create(Keys.Control | Keys.R)
5772 .Do(() => this.MakeReplyText()),
5774 ShortcutCommand.Create(Keys.Control | Keys.D)
5775 .Do(() => this.DoStatusDelete()),
5777 ShortcutCommand.Create(Keys.Control | Keys.M)
5778 .Do(() => this.MakeDirectMessageText()),
5780 ShortcutCommand.Create(Keys.Control | Keys.S)
5781 .Do(() => this.FavoriteChange(favAdd: true)),
5783 ShortcutCommand.Create(Keys.Control | Keys.I)
5784 .Do(() => this.DoRepliedStatusOpen()),
5786 ShortcutCommand.Create(Keys.Control | Keys.Q)
5787 .Do(() => this.DoQuoteOfficial()),
5789 ShortcutCommand.Create(Keys.Control | Keys.B)
5790 .Do(() => this.ReadedStripMenuItem_Click(this.ReadedStripMenuItem, EventArgs.Empty)),
5792 ShortcutCommand.Create(Keys.Control | Keys.T)
5793 .Do(() => this.HashManageMenuItem_Click(this.HashManageMenuItem, EventArgs.Empty)),
5795 ShortcutCommand.Create(Keys.Control | Keys.L)
5796 .Do(() => this.UrlConvertAutoToolStripMenuItem_Click(this.UrlConvertAutoToolStripMenuItem, EventArgs.Empty)),
5798 ShortcutCommand.Create(Keys.Control | Keys.Y)
5799 .NotFocusedOn(FocusedControl.PostBrowser)
5800 .Do(() => this.MultiLineMenuItem_Click(this.MultiLineMenuItem, EventArgs.Empty)),
5802 ShortcutCommand.Create(Keys.Control | Keys.F)
5803 .Do(() => this.MenuItemSubSearch_Click(this.MenuItemSubSearch, EventArgs.Empty)),
5805 ShortcutCommand.Create(Keys.Control | Keys.U)
5806 .Do(() => this.ShowUserTimeline()),
5808 ShortcutCommand.Create(Keys.Control | Keys.H)
5809 .Do(() => this.AuthorOpenInBrowserMenuItem_Click(this.AuthorOpenInBrowserContextMenuItem, EventArgs.Empty)),
5811 ShortcutCommand.Create(Keys.Control | Keys.O)
5812 .Do(() => this.StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty)),
5814 ShortcutCommand.Create(Keys.Control | Keys.E)
5815 .Do(() => this.OpenURLMenuItem_Click(this.OpenURLMenuItem, EventArgs.Empty)),
5817 ShortcutCommand.Create(Keys.Control | Keys.Home, Keys.Control | Keys.End)
5818 .FocusedOn(FocusedControl.ListTab)
5819 .Do(() => this.selectionDebouncer.Call(), preventDefault: false),
5821 ShortcutCommand.Create(Keys.Control | Keys.N)
5822 .FocusedOn(FocusedControl.ListTab)
5823 .Do(() => this.GoNextTab(forward: true)),
5825 ShortcutCommand.Create(Keys.Control | Keys.P)
5826 .FocusedOn(FocusedControl.ListTab)
5827 .Do(() => this.GoNextTab(forward: false)),
5829 ShortcutCommand.Create(Keys.Control | Keys.C, Keys.Control | Keys.Insert)
5830 .FocusedOn(FocusedControl.ListTab)
5831 .Do(() => this.CopyStot()),
5833 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
5834 ShortcutCommand.Create(Keys.Control | Keys.D1)
5835 .FocusedOn(FocusedControl.ListTab)
5836 .OnlyWhen(() => this.statuses.Tabs.Count >= 1)
5837 .Do(() => this.ListTab.SelectedIndex = 0),
5839 ShortcutCommand.Create(Keys.Control | Keys.D2)
5840 .FocusedOn(FocusedControl.ListTab)
5841 .OnlyWhen(() => this.statuses.Tabs.Count >= 2)
5842 .Do(() => this.ListTab.SelectedIndex = 1),
5844 ShortcutCommand.Create(Keys.Control | Keys.D3)
5845 .FocusedOn(FocusedControl.ListTab)
5846 .OnlyWhen(() => this.statuses.Tabs.Count >= 3)
5847 .Do(() => this.ListTab.SelectedIndex = 2),
5849 ShortcutCommand.Create(Keys.Control | Keys.D4)
5850 .FocusedOn(FocusedControl.ListTab)
5851 .OnlyWhen(() => this.statuses.Tabs.Count >= 4)
5852 .Do(() => this.ListTab.SelectedIndex = 3),
5854 ShortcutCommand.Create(Keys.Control | Keys.D5)
5855 .FocusedOn(FocusedControl.ListTab)
5856 .OnlyWhen(() => this.statuses.Tabs.Count >= 5)
5857 .Do(() => this.ListTab.SelectedIndex = 4),
5859 ShortcutCommand.Create(Keys.Control | Keys.D6)
5860 .FocusedOn(FocusedControl.ListTab)
5861 .OnlyWhen(() => this.statuses.Tabs.Count >= 6)
5862 .Do(() => this.ListTab.SelectedIndex = 5),
5864 ShortcutCommand.Create(Keys.Control | Keys.D7)
5865 .FocusedOn(FocusedControl.ListTab)
5866 .OnlyWhen(() => this.statuses.Tabs.Count >= 7)
5867 .Do(() => this.ListTab.SelectedIndex = 6),
5869 ShortcutCommand.Create(Keys.Control | Keys.D8)
5870 .FocusedOn(FocusedControl.ListTab)
5871 .OnlyWhen(() => this.statuses.Tabs.Count >= 8)
5872 .Do(() => this.ListTab.SelectedIndex = 7),
5874 ShortcutCommand.Create(Keys.Control | Keys.D9)
5875 .FocusedOn(FocusedControl.ListTab)
5876 .Do(() => this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1),
5878 ShortcutCommand.Create(Keys.Control | Keys.A)
5879 .FocusedOn(FocusedControl.StatusText)
5880 .Do(() => this.StatusText.SelectAll()),
5882 ShortcutCommand.Create(Keys.Control | Keys.V)
5883 .FocusedOn(FocusedControl.StatusText)
5884 .Do(() => this.ProcClipboardFromStatusTextWhenCtrlPlusV()),
5886 ShortcutCommand.Create(Keys.Control | Keys.Up)
5887 .FocusedOn(FocusedControl.StatusText)
5888 .Do(() => this.StatusTextHistoryBack()),
5890 ShortcutCommand.Create(Keys.Control | Keys.Down)
5891 .FocusedOn(FocusedControl.StatusText)
5892 .Do(() => this.StatusTextHistoryForward()),
5894 ShortcutCommand.Create(Keys.Control | Keys.PageUp, Keys.Control | Keys.P)
5895 .FocusedOn(FocusedControl.StatusText)
5898 if (this.ListTab.SelectedIndex == 0)
5900 this.ListTab.SelectedIndex = this.ListTab.TabCount - 1;
5904 this.ListTab.SelectedIndex -= 1;
5906 this.StatusText.Focus();
5909 ShortcutCommand.Create(Keys.Control | Keys.PageDown, Keys.Control | Keys.N)
5910 .FocusedOn(FocusedControl.StatusText)
5913 if (this.ListTab.SelectedIndex == this.ListTab.TabCount - 1)
5915 this.ListTab.SelectedIndex = 0;
5919 this.ListTab.SelectedIndex += 1;
5921 this.StatusText.Focus();
5924 ShortcutCommand.Create(Keys.Control | Keys.Y)
5925 .FocusedOn(FocusedControl.PostBrowser)
5928 var multiline = !SettingManager.Local.StatusMultiline;
5929 SettingManager.Local.StatusMultiline = multiline;
5930 this.MultiLineMenuItem.Checked = multiline;
5931 this.MultiLineMenuItem_Click(this.MultiLineMenuItem, EventArgs.Empty);
5934 ShortcutCommand.Create(Keys.Shift | Keys.F3)
5935 .Do(() => this.MenuItemSearchPrev_Click(this.MenuItemSearchPrev, EventArgs.Empty)),
5937 ShortcutCommand.Create(Keys.Shift | Keys.F5)
5938 .Do(() => this.DoRefreshMore()),
5940 ShortcutCommand.Create(Keys.Shift | Keys.F6)
5941 .Do(() => this.RefreshTabAsync<MentionsTabModel>(backward: true)),
5943 ShortcutCommand.Create(Keys.Shift | Keys.F7)
5944 .Do(() => this.RefreshTabAsync<DirectMessagesTabModel>(backward: true)),
5946 ShortcutCommand.Create(Keys.Shift | Keys.R)
5947 .NotFocusedOn(FocusedControl.StatusText)
5948 .Do(() => this.DoRefreshMore()),
5950 ShortcutCommand.Create(Keys.Shift | Keys.H)
5951 .FocusedOn(FocusedControl.ListTab)
5952 .Do(() => this.GoTopEnd(goTop: true)),
5954 ShortcutCommand.Create(Keys.Shift | Keys.L)
5955 .FocusedOn(FocusedControl.ListTab)
5956 .Do(() => this.GoTopEnd(goTop: false)),
5958 ShortcutCommand.Create(Keys.Shift | Keys.M)
5959 .FocusedOn(FocusedControl.ListTab)
5960 .Do(() => this.GoMiddle()),
5962 ShortcutCommand.Create(Keys.Shift | Keys.G)
5963 .FocusedOn(FocusedControl.ListTab)
5964 .Do(() => this.GoLast()),
5966 ShortcutCommand.Create(Keys.Shift | Keys.Z)
5967 .FocusedOn(FocusedControl.ListTab)
5968 .Do(() => this.MoveMiddle()),
5970 ShortcutCommand.Create(Keys.Shift | Keys.Oem4)
5971 .FocusedOn(FocusedControl.ListTab)
5972 .Do(() => this.GoBackInReplyToPostTree(parallel: true, isForward: false)),
5974 ShortcutCommand.Create(Keys.Shift | Keys.Oem6)
5975 .FocusedOn(FocusedControl.ListTab)
5976 .Do(() => this.GoBackInReplyToPostTree(parallel: true, isForward: true)),
5978 // お気に入り前後ジャンプ(SHIFT+N←/P→)
5979 ShortcutCommand.Create(Keys.Shift | Keys.Right, Keys.Shift | Keys.N)
5980 .FocusedOn(FocusedControl.ListTab)
5981 .Do(() => this.GoFav(forward: true)),
5983 // お気に入り前後ジャンプ(SHIFT+N←/P→)
5984 ShortcutCommand.Create(Keys.Shift | Keys.Left, Keys.Shift | Keys.P)
5985 .FocusedOn(FocusedControl.ListTab)
5986 .Do(() => this.GoFav(forward: false)),
5988 ShortcutCommand.Create(Keys.Shift | Keys.Space)
5989 .FocusedOn(FocusedControl.ListTab)
5990 .Do(() => this.GoBackSelectPostChain()),
5992 ShortcutCommand.Create(Keys.Alt | Keys.R)
5993 .Do(() => this.DoReTweetOfficial(isConfirm: true)),
5995 ShortcutCommand.Create(Keys.Alt | Keys.P)
5996 .OnlyWhen(() => this.CurrentPost != null)
5997 .Do(() => this.DoShowUserStatus(this.CurrentPost!.ScreenName, showInputDialog: false)),
5999 ShortcutCommand.Create(Keys.Alt | Keys.Up)
6000 .Do(() => this.tweetDetailsView.ScrollDownPostBrowser(forward: false)),
6002 ShortcutCommand.Create(Keys.Alt | Keys.Down)
6003 .Do(() => this.tweetDetailsView.ScrollDownPostBrowser(forward: true)),
6005 ShortcutCommand.Create(Keys.Alt | Keys.PageUp)
6006 .Do(() => this.tweetDetailsView.PageDownPostBrowser(forward: false)),
6008 ShortcutCommand.Create(Keys.Alt | Keys.PageDown)
6009 .Do(() => this.tweetDetailsView.PageDownPostBrowser(forward: true)),
6011 // 別タブの同じ書き込みへ(ALT+←/→)
6012 ShortcutCommand.Create(Keys.Alt | Keys.Right)
6013 .FocusedOn(FocusedControl.ListTab)
6014 .Do(() => this.GoSamePostToAnotherTab(left: false)),
6016 ShortcutCommand.Create(Keys.Alt | Keys.Left)
6017 .FocusedOn(FocusedControl.ListTab)
6018 .Do(() => this.GoSamePostToAnotherTab(left: true)),
6020 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.R)
6021 .Do(() => this.MakeReplyText(atAll: true)),
6023 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.C, Keys.Control | Keys.Shift | Keys.Insert)
6024 .Do(() => this.CopyIdUri()),
6026 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.F)
6027 .OnlyWhen(() => this.CurrentTab.TabType == MyCommon.TabUsageType.PublicSearch)
6028 .Do(() => this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus()),
6030 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.S)
6031 .Do(() => this.FavoriteChange(favAdd: false)),
6033 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.B)
6034 .Do(() => this.UnreadStripMenuItem_Click(this.UnreadStripMenuItem, EventArgs.Empty)),
6036 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.T)
6037 .Do(() => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty)),
6039 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.P)
6040 .Do(() => this.ImageSelectMenuItem_Click(this.ImageSelectMenuItem, EventArgs.Empty)),
6042 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.H)
6043 .Do(() => this.DoMoveToRTHome()),
6045 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Up)
6046 .FocusedOn(FocusedControl.StatusText)
6049 var tab = this.CurrentTab;
6050 var selectedIndex = tab.SelectedIndex;
6051 if (selectedIndex != -1 && selectedIndex > 0)
6053 var listView = this.CurrentListView;
6054 var idx = selectedIndex - 1;
6055 this.SelectListItem(listView, idx);
6056 listView.EnsureVisible(idx);
6060 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Down)
6061 .FocusedOn(FocusedControl.StatusText)
6064 var tab = this.CurrentTab;
6065 var selectedIndex = tab.SelectedIndex;
6066 if (selectedIndex != -1 && selectedIndex < tab.AllCount - 1)
6068 var listView = this.CurrentListView;
6069 var idx = selectedIndex + 1;
6070 this.SelectListItem(listView, idx);
6071 listView.EnsureVisible(idx);
6075 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Space)
6076 .FocusedOn(FocusedControl.StatusText)
6079 if (this.StatusText.SelectionStart > 0)
6081 var endidx = this.StatusText.SelectionStart - 1;
6083 for (var i = this.StatusText.SelectionStart - 1; i >= 0; i--)
6085 var c = this.StatusText.Text[i];
6086 if (char.IsLetterOrDigit(c) || c == '_')
6092 startstr = this.StatusText.Text.Substring(i + 1, endidx - i);
6093 var cnt = this.AtIdSupl.ItemCount;
6094 this.ShowSuplDialog(this.StatusText, this.AtIdSupl, startstr.Length + 1, startstr);
6095 if (this.AtIdSupl.ItemCount != cnt)
6096 this.MarkSettingAtIdModified();
6100 startstr = this.StatusText.Text.Substring(i + 1, endidx - i);
6101 this.ShowSuplDialog(this.StatusText, this.HashSupl, startstr.Length + 1, startstr);
6111 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
6112 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D1)
6113 .FocusedOn(FocusedControl.ListTab)
6114 .Do(() => this.SetSortColumnByDisplayIndex(0)),
6116 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D2)
6117 .FocusedOn(FocusedControl.ListTab)
6118 .Do(() => this.SetSortColumnByDisplayIndex(1)),
6120 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D3)
6121 .FocusedOn(FocusedControl.ListTab)
6122 .Do(() => this.SetSortColumnByDisplayIndex(2)),
6124 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D4)
6125 .FocusedOn(FocusedControl.ListTab)
6126 .Do(() => this.SetSortColumnByDisplayIndex(3)),
6128 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D5)
6129 .FocusedOn(FocusedControl.ListTab)
6130 .Do(() => this.SetSortColumnByDisplayIndex(4)),
6132 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D6)
6133 .FocusedOn(FocusedControl.ListTab)
6134 .Do(() => this.SetSortColumnByDisplayIndex(5)),
6136 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D7)
6137 .FocusedOn(FocusedControl.ListTab)
6138 .Do(() => this.SetSortColumnByDisplayIndex(6)),
6140 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D8)
6141 .FocusedOn(FocusedControl.ListTab)
6142 .Do(() => this.SetSortColumnByDisplayIndex(7)),
6144 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D9)
6145 .FocusedOn(FocusedControl.ListTab)
6146 .Do(() => this.SetSortLastColumn()),
6148 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.S)
6149 .FocusedOn(FocusedControl.ListTab)
6150 .Do(() => this.FavoritesRetweetOfficial()),
6152 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.R)
6153 .FocusedOn(FocusedControl.ListTab)
6154 .Do(() => this.FavoritesRetweetUnofficial()),
6156 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.H)
6157 .FocusedOn(FocusedControl.ListTab)
6158 .Do(() => this.OpenUserAppointUrl()),
6160 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.R)
6161 .FocusedOn(FocusedControl.PostBrowser)
6162 .Do(() => this.DoReTweetUnofficial()),
6164 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.T)
6165 .OnlyWhen(() => this.ExistCurrentPost)
6166 .Do(() => this.tweetDetailsView.DoTranslation()),
6168 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.R)
6169 .Do(() => this.DoReTweetUnofficial()),
6171 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.C, Keys.Alt | Keys.Shift | Keys.Insert)
6172 .Do(() => this.CopyUserId()),
6174 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Up)
6175 .Do(() => this.tweetThumbnail1.ScrollUp()),
6177 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Down)
6178 .Do(() => this.tweetThumbnail1.ScrollDown()),
6180 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Enter)
6181 .FocusedOn(FocusedControl.ListTab)
6182 .OnlyWhen(() => !this.SplitContainer3.Panel2Collapsed)
6183 .Do(() => this.OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail)),
6187 internal bool CommonKeyDown(Keys keyData, FocusedControl focusedOn, out Task? asyncTask)
6189 // Task を返す非同期処理があれば asyncTask に代入する
6192 // ShortcutCommand に対応しているコマンドはここで処理される
6193 foreach (var command in this.shortcutCommands)
6195 if (command.IsMatch(keyData, focusedOn))
6197 asyncTask = command.RunCommand();
6198 return command.PreventDefault;
6205 private void GoNextTab(bool forward)
6207 var idx = this.statuses.SelectedTabIndex;
6208 var tabCount = this.statuses.Tabs.Count;
6212 if (idx > tabCount - 1) idx = 0;
6217 if (idx < 0) idx = tabCount - 1;
6219 this.ListTab.SelectedIndex = idx;
6222 private void CopyStot()
6224 var sb = new StringBuilder();
6225 var tab = this.CurrentTab;
6226 var isProtected = false;
6227 var isDm = tab.TabType == MyCommon.TabUsageType.DirectMessage;
6228 foreach (var post in tab.SelectedPosts)
6230 if (post.IsDeleted) continue;
6233 if (post.RetweetedId != null)
6234 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
6236 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6240 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
6245 MessageBox.Show(Properties.Resources.CopyStotText1);
6249 var clstr = sb.ToString();
6252 Clipboard.SetDataObject(clstr, false, 5, 100);
6254 catch (Exception ex)
6256 MessageBox.Show(ex.Message);
6261 private void CopyIdUri()
6263 var tab = this.CurrentTab;
6264 if (tab == null || tab is DirectMessagesTabModel)
6267 var copyUrls = new List<string>();
6268 foreach (var post in tab.SelectedPosts)
6269 copyUrls.Add(MyCommon.GetStatusUrl(post));
6271 if (copyUrls.Count == 0)
6276 Clipboard.SetDataObject(string.Join(Environment.NewLine, copyUrls), false, 5, 100);
6278 catch (ExternalException ex)
6280 MessageBox.Show(ex.Message);
6284 private void GoFav(bool forward)
6286 var tab = this.CurrentTab;
6287 if (tab.AllCount == 0)
6290 var selectedIndex = tab.SelectedIndex;
6298 if (selectedIndex == -1)
6304 fIdx = selectedIndex + 1;
6305 if (fIdx > tab.AllCount - 1)
6308 toIdx = tab.AllCount;
6313 if (selectedIndex == -1)
6315 fIdx = tab.AllCount - 1;
6319 fIdx = selectedIndex - 1;
6327 for (var idx = fIdx; idx != toIdx; idx += stp)
6331 var listView = this.CurrentListView;
6332 this.SelectListItem(listView, idx);
6333 listView.EnsureVisible(idx);
6339 private void GoSamePostToAnotherTab(bool left)
6341 var tab = this.CurrentTab;
6343 // Directタブは対象外(見つかるはずがない)
6344 if (tab.TabType == MyCommon.TabUsageType.DirectMessage)
6347 var selectedStatusId = tab.SelectedStatusId;
6348 if (selectedStatusId == -1)
6351 int fIdx, toIdx, stp;
6356 if (this.ListTab.SelectedIndex == 0)
6362 fIdx = this.ListTab.SelectedIndex - 1;
6370 if (this.ListTab.SelectedIndex == this.ListTab.TabCount - 1)
6376 fIdx = this.ListTab.SelectedIndex + 1;
6378 toIdx = this.ListTab.TabCount;
6382 for (var tabidx = fIdx; tabidx != toIdx; tabidx += stp)
6384 var targetTab = this.statuses.Tabs[tabidx];
6387 if (targetTab.TabType == MyCommon.TabUsageType.DirectMessage)
6390 var foundIndex = targetTab.IndexOf(selectedStatusId);
6391 if (foundIndex != -1)
6393 this.ListTab.SelectedIndex = tabidx;
6394 var listView = this.CurrentListView;
6395 this.SelectListItem(listView, foundIndex);
6396 listView.EnsureVisible(foundIndex);
6402 private void GoPost(bool forward)
6404 var tab = this.CurrentTab;
6405 var currentPost = this.CurrentPost;
6407 if (currentPost == null)
6410 var selectedIndex = tab.SelectedIndex;
6412 int fIdx, toIdx, stp;
6416 fIdx = selectedIndex + 1;
6417 if (fIdx > tab.AllCount - 1) return;
6418 toIdx = tab.AllCount;
6423 fIdx = selectedIndex - 1;
6424 if (fIdx < 0) return;
6430 if (currentPost.RetweetedBy == null)
6432 name = currentPost.ScreenName;
6436 name = currentPost.RetweetedBy;
6438 for (var idx = fIdx; idx != toIdx; idx += stp)
6440 var post = tab[idx];
6441 if (post.RetweetedId == null)
6443 if (post.ScreenName == name)
6445 var listView = this.CurrentListView;
6446 this.SelectListItem(listView, idx);
6447 listView.EnsureVisible(idx);
6453 if (post.RetweetedBy == name)
6455 var listView = this.CurrentListView;
6456 this.SelectListItem(listView, idx);
6457 listView.EnsureVisible(idx);
6464 private void GoRelPost(bool forward)
6466 var tab = this.CurrentTab;
6467 var selectedIndex = tab.SelectedIndex;
6469 if (selectedIndex == -1)
6472 int fIdx, toIdx, stp;
6476 fIdx = selectedIndex + 1;
6477 if (fIdx > tab.AllCount - 1) return;
6478 toIdx = tab.AllCount;
6483 fIdx = selectedIndex - 1;
6484 if (fIdx < 0) return;
6489 if (!this.anchorFlag)
6491 var currentPost = this.CurrentPost;
6492 if (currentPost == null) return;
6493 this.anchorPost = currentPost;
6494 this.anchorFlag = true;
6498 if (this.anchorPost == null) return;
6501 for (var idx = fIdx; idx != toIdx; idx += stp)
6503 var post = tab[idx];
6504 if (post.ScreenName == this.anchorPost.ScreenName ||
6505 post.RetweetedBy == this.anchorPost.ScreenName ||
6506 post.ScreenName == this.anchorPost.RetweetedBy ||
6507 (!MyCommon.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == this.anchorPost.RetweetedBy) ||
6508 this.anchorPost.ReplyToList.Any(x => x.UserId == post.UserId) ||
6509 this.anchorPost.ReplyToList.Any(x => x.UserId == post.RetweetedByUserId) ||
6510 post.ReplyToList.Any(x => x.UserId == this.anchorPost.UserId) ||
6511 post.ReplyToList.Any(x => x.UserId == this.anchorPost.RetweetedByUserId))
6513 var listView = this.CurrentListView;
6514 this.SelectListItem(listView, idx);
6515 listView.EnsureVisible(idx);
6521 private void GoAnchor()
6523 if (this.anchorPost == null) return;
6524 var idx = this.CurrentTab.IndexOf(this.anchorPost.StatusId);
6525 if (idx == -1) return;
6527 var listView = this.CurrentListView;
6528 this.SelectListItem(listView, idx);
6529 listView.EnsureVisible(idx);
6532 private void GoTopEnd(bool goTop)
6534 var listView = this.CurrentListView;
6535 if (listView.VirtualListSize == 0)
6543 item = listView.GetItemAt(0, 25);
6551 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
6553 idx = listView.VirtualListSize - 1;
6557 this.SelectListItem(listView, idx);
6560 private void GoMiddle()
6562 var listView = this.CurrentListView;
6563 if (listView.VirtualListSize == 0)
6571 item = listView.GetItemAt(0, 0);
6581 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
6584 idx2 = listView.VirtualListSize - 1;
6590 idx3 = (idx1 + idx2) / 2;
6592 this.SelectListItem(listView, idx3);
6595 private void GoLast()
6597 var listView = this.CurrentListView;
6598 if (listView.VirtualListSize == 0) return;
6600 if (this.statuses.SortOrder == SortOrder.Ascending)
6602 this.SelectListItem(listView, listView.VirtualListSize - 1);
6603 listView.EnsureVisible(listView.VirtualListSize - 1);
6607 this.SelectListItem(listView, 0);
6608 listView.EnsureVisible(0);
6612 private void MoveTop()
6614 var listView = this.CurrentListView;
6615 if (listView.SelectedIndices.Count == 0) return;
6616 var idx = listView.SelectedIndices[0];
6617 if (this.statuses.SortOrder == SortOrder.Ascending)
6619 listView.EnsureVisible(listView.VirtualListSize - 1);
6623 listView.EnsureVisible(0);
6625 listView.EnsureVisible(idx);
6628 private async Task GoInReplyToPostTree()
6630 var curTabClass = this.CurrentTab;
6631 var currentPost = this.CurrentPost;
6633 if (currentPost == null)
6636 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && currentPost.InReplyToStatusId == null && currentPost.TextFromApi.Contains("@"))
6640 var post = await this.tw.GetStatusApi(false, currentPost.StatusId);
6642 currentPost.InReplyToStatusId = post.InReplyToStatusId;
6643 currentPost.InReplyToUser = post.InReplyToUser;
6644 currentPost.IsReply = post.IsReply;
6645 this.PurgeListViewItemCache();
6647 var index = curTabClass.SelectedIndex;
6648 this.CurrentListView.RedrawItems(index, index, false);
6650 catch (WebApiException ex)
6652 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
6656 if (!(this.ExistCurrentPost && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)) return;
6658 if (this.replyChains == null || (this.replyChains.Count > 0 && this.replyChains.Peek().InReplyToId != currentPost.StatusId))
6660 this.replyChains = new Stack<ReplyChain>();
6662 this.replyChains.Push(new ReplyChain(currentPost.StatusId, currentPost.InReplyToStatusId.Value, curTabClass));
6665 string inReplyToTabName;
6666 var inReplyToId = currentPost.InReplyToStatusId.Value;
6667 var inReplyToUser = currentPost.InReplyToUser;
6669 var inReplyToPosts = from tab in this.statuses.Tabs
6670 orderby tab != curTabClass
6671 from post in tab.Posts.Values
6672 where post.StatusId == inReplyToId
6673 let index = tab.IndexOf(post.StatusId)
6675 select new { Tab = tab, Index = index };
6677 var inReplyPost = inReplyToPosts.FirstOrDefault();
6678 if (inReplyPost == null)
6682 await Task.Run(async () =>
6684 var post = await this.tw.GetStatusApi(false, currentPost.InReplyToStatusId.Value)
6685 .ConfigureAwait(false);
6688 this.statuses.AddPost(post);
6689 this.statuses.DistributePosts();
6692 catch (WebApiException ex)
6694 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
6695 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
6699 this.RefreshTimeline();
6701 inReplyPost = inReplyToPosts.FirstOrDefault();
6702 if (inReplyPost == null)
6704 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
6708 inReplyToTabName = inReplyPost.Tab.TabName;
6709 inReplyToIndex = inReplyPost.Index;
6711 var tabIndex = this.statuses.Tabs.IndexOf(inReplyToTabName);
6712 var tabPage = this.ListTab.TabPages[tabIndex];
6713 var listView = (DetailsListView)tabPage.Tag;
6715 if (this.CurrentTabName != inReplyToTabName)
6717 this.ListTab.SelectedIndex = tabIndex;
6720 this.SelectListItem(listView, inReplyToIndex);
6721 listView.EnsureVisible(inReplyToIndex);
6724 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
6726 var curTabClass = this.CurrentTab;
6727 var currentPost = this.CurrentPost;
6729 if (currentPost == null)
6734 if (currentPost.InReplyToStatusId != null)
6736 var posts = from t in this.statuses.Tabs
6738 where p.Value.StatusId != currentPost.StatusId && p.Value.InReplyToStatusId == currentPost.InReplyToStatusId
6739 let indexOf = t.IndexOf(p.Value.StatusId)
6741 orderby isForward ? indexOf : indexOf * -1
6742 orderby t != curTabClass
6743 select new { Tab = t, Post = p.Value, Index = indexOf };
6746 var postList = posts.ToList();
6747 for (var i = postList.Count - 1; i >= 0; i--)
6750 if (postList.FindIndex(pst => pst.Post.StatusId == postList[index].Post.StatusId) != index)
6752 postList.RemoveAt(index);
6755 var currentIndex = this.CurrentTab.SelectedIndex;
6756 var post = postList.FirstOrDefault(pst => pst.Tab == curTabClass && isForward ? pst.Index > currentIndex : pst.Index < currentIndex);
6757 if (post == null) post = postList.FirstOrDefault(pst => pst.Tab != curTabClass);
6758 if (post == null) post = postList.First();
6759 var tabIndex = this.statuses.Tabs.IndexOf(post.Tab);
6760 this.ListTab.SelectedIndex = tabIndex;
6761 var listView = this.CurrentListView;
6762 this.SelectListItem(listView, post.Index);
6763 listView.EnsureVisible(post.Index);
6765 catch (InvalidOperationException)
6773 if (this.replyChains == null || this.replyChains.Count < 1)
6775 var posts = from t in this.statuses.Tabs
6777 where p.Value.InReplyToStatusId == currentPost.StatusId
6778 let indexOf = t.IndexOf(p.Value.StatusId)
6781 orderby t != curTabClass
6782 select new { Tab = t, Index = indexOf };
6785 var post = posts.First();
6786 var tabIndex = this.statuses.Tabs.IndexOf(post.Tab);
6787 this.ListTab.SelectedIndex = tabIndex;
6788 var listView = this.CurrentListView;
6789 this.SelectListItem(listView, post.Index);
6790 listView.EnsureVisible(post.Index);
6792 catch (InvalidOperationException)
6799 var chainHead = this.replyChains.Pop();
6800 if (chainHead.InReplyToId == currentPost.StatusId)
6802 var tab = chainHead.OriginalTab;
6803 if (!this.statuses.Tabs.Contains(tab))
6805 this.replyChains = null;
6809 var idx = tab.IndexOf(chainHead.OriginalId);
6812 this.replyChains = null;
6816 var tabIndex = this.statuses.Tabs.IndexOf(tab);
6819 this.ListTab.SelectedIndex = tabIndex;
6823 this.replyChains = null;
6825 var listView = this.CurrentListView;
6826 this.SelectListItem(listView, idx);
6827 listView.EnsureVisible(idx);
6833 this.replyChains = null;
6834 this.GoBackInReplyToPostTree(parallel);
6840 private void GoBackSelectPostChain()
6842 if (this.selectPostChains.Count > 1)
6845 TabModel? foundTab = null;
6851 this.selectPostChains.Pop();
6852 var (tab, post) = this.selectPostChains.Peek();
6854 if (!this.statuses.Tabs.Contains(tab))
6855 continue; // 該当タブが存在しないので無視
6859 idx = tab.IndexOf(post.StatusId);
6860 if (idx == -1) continue; // 該当ポストが存在しないので無視
6865 this.selectPostChains.Pop();
6867 catch (InvalidOperationException)
6873 while (this.selectPostChains.Count > 1);
6875 if (foundTab == null)
6878 // 履歴が残り1つであればクリアしておく
6879 if (this.selectPostChains.Count == 1)
6880 this.selectPostChains.Clear();
6884 var tabIndex = this.statuses.Tabs.IndexOf(foundTab);
6885 var tabPage = this.ListTab.TabPages[tabIndex];
6886 var lst = (DetailsListView)tabPage.Tag;
6887 this.ListTab.SelectedIndex = tabIndex;
6891 this.SelectListItem(lst, idx);
6892 lst.EnsureVisible(idx);
6898 private void PushSelectPostChain()
6900 var currentTab = this.CurrentTab;
6901 var currentPost = this.CurrentPost;
6903 var count = this.selectPostChains.Count;
6906 var (tab, post) = this.selectPostChains.Peek();
6907 if (tab == currentTab)
6909 if (post == currentPost) return; // 最新の履歴と同一
6910 if (post == null) this.selectPostChains.Pop(); // 置き換えるため削除
6913 if (count >= 2500) this.TrimPostChain();
6914 this.selectPostChains.Push((currentTab, currentPost));
6917 private void TrimPostChain()
6919 if (this.selectPostChains.Count <= 2000) return;
6920 var p = new Stack<(TabModel, PostClass?)>(2000);
6921 for (var i = 0; i < 2000; i++)
6923 p.Push(this.selectPostChains.Pop());
6925 this.selectPostChains.Clear();
6926 for (var i = 0; i < 2000; i++)
6928 this.selectPostChains.Push(p.Pop());
6932 private bool GoStatus(long statusId)
6934 if (statusId == 0) return false;
6936 var tab = this.statuses.Tabs
6937 .Where(x => x.TabType != MyCommon.TabUsageType.DirectMessage)
6938 .Where(x => x.Contains(statusId))
6944 var index = tab.IndexOf(statusId);
6946 var tabIndex = this.statuses.Tabs.IndexOf(tab);
6947 this.ListTab.SelectedIndex = tabIndex;
6949 var listView = this.CurrentListView;
6950 this.SelectListItem(listView, index);
6951 listView.EnsureVisible(index);
6956 private bool GoDirectMessage(long statusId)
6958 if (statusId == 0) return false;
6960 var tab = this.statuses.DirectMessageTab;
6961 var index = tab.IndexOf(statusId);
6966 var tabIndex = this.statuses.Tabs.IndexOf(tab);
6967 this.ListTab.SelectedIndex = tabIndex;
6969 var listView = this.CurrentListView;
6970 this.SelectListItem(listView, index);
6971 listView.EnsureVisible(index);
6976 private void MyList_MouseClick(object sender, MouseEventArgs e)
6977 => this.anchorFlag = false;
6979 private void StatusText_Enter(object sender, EventArgs e)
6981 // フォーカスの戻り先を StatusText に設定
6982 this.Tag = this.StatusText;
6983 this.StatusText.BackColor = this.clInputBackcolor;
6986 public Color InputBackColor
6988 get => this.clInputBackcolor;
6989 set => this.clInputBackcolor = value;
6992 private void StatusText_Leave(object sender, EventArgs e)
6994 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
6995 if (this.ListTab.SelectedTab != null && this.MenuStrip1.Tag == null) this.Tag = this.ListTab.SelectedTab.Tag;
6996 this.StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
6999 private async void StatusText_KeyDown(object sender, KeyEventArgs e)
7001 if (this.CommonKeyDown(e.KeyData, FocusedControl.StatusText, out var asyncTask))
7004 e.SuppressKeyPress = true;
7007 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
7009 if (asyncTask != null)
7013 private void SaveConfigsAll(bool ifModified)
7017 this.SaveConfigsCommon();
7018 this.SaveConfigsLocal();
7019 this.SaveConfigsTabs();
7020 this.SaveConfigsAtId();
7024 if (this.ModifySettingCommon) this.SaveConfigsCommon();
7025 if (this.ModifySettingLocal) this.SaveConfigsLocal();
7026 if (this.ModifySettingAtId) this.SaveConfigsAtId();
7030 private void SaveConfigsAtId()
7032 if (this.ignoreConfigSave || !SettingManager.Common.UseAtIdSupplement && this.AtIdSupl == null) return;
7034 this.ModifySettingAtId = false;
7035 SettingManager.AtIdList.AtIdList = this.AtIdSupl.GetItemList();
7036 SettingManager.SaveAtIdList();
7039 private void SaveConfigsCommon()
7041 if (this.ignoreConfigSave) return;
7043 this.ModifySettingCommon = false;
7044 lock (this.syncObject)
7046 SettingManager.Common.UserName = this.tw.Username;
7047 SettingManager.Common.UserId = this.tw.UserId;
7048 SettingManager.Common.Token = this.tw.AccessToken;
7049 SettingManager.Common.TokenSecret = this.tw.AccessTokenSecret;
7050 SettingManager.Common.SortOrder = (int)this.statuses.SortOrder;
7051 SettingManager.Common.SortColumn = this.statuses.SortMode switch
7053 ComparerMode.Nickname => 1, // ニックネーム
7054 ComparerMode.Data => 2, // 本文
7055 ComparerMode.Id => 3, // 時刻=発言Id
7056 ComparerMode.Name => 4, // 名前
7057 ComparerMode.Source => 7, // Source
7058 _ => throw new InvalidOperationException($"Invalid sort mode: {this.statuses.SortMode}"),
7060 SettingManager.Common.HashTags = this.HashMgr.HashHistories;
7061 if (this.HashMgr.IsPermanent)
7063 SettingManager.Common.HashSelected = this.HashMgr.UseHash;
7067 SettingManager.Common.HashSelected = "";
7069 SettingManager.Common.HashIsHead = this.HashMgr.IsHead;
7070 SettingManager.Common.HashIsPermanent = this.HashMgr.IsPermanent;
7071 SettingManager.Common.HashIsNotAddToAtReply = this.HashMgr.IsNotAddToAtReply;
7072 SettingManager.Common.UseImageService = this.ImageSelector.ServiceIndex;
7073 SettingManager.Common.UseImageServiceName = this.ImageSelector.ServiceName;
7075 SettingManager.SaveCommon();
7079 private void SaveConfigsLocal()
7081 if (this.ignoreConfigSave) return;
7082 lock (this.syncObject)
7084 this.ModifySettingLocal = false;
7085 SettingManager.Local.ScaleDimension = this.CurrentAutoScaleDimensions;
7086 SettingManager.Local.FormSize = this.mySize;
7087 SettingManager.Local.FormLocation = this.myLoc;
7088 SettingManager.Local.SplitterDistance = this.mySpDis;
7089 SettingManager.Local.PreviewDistance = this.mySpDis3;
7090 SettingManager.Local.StatusMultiline = this.StatusText.Multiline;
7091 SettingManager.Local.StatusTextHeight = this.mySpDis2;
7093 SettingManager.Local.FontUnread = this.fntUnread;
7094 SettingManager.Local.ColorUnread = this.clUnread;
7095 SettingManager.Local.FontRead = this.fntReaded;
7096 SettingManager.Local.ColorRead = this.clReaded;
7097 SettingManager.Local.FontDetail = this.fntDetail;
7098 SettingManager.Local.ColorDetail = this.clDetail;
7099 SettingManager.Local.ColorDetailBackcolor = this.clDetailBackcolor;
7100 SettingManager.Local.ColorDetailLink = this.clDetailLink;
7101 SettingManager.Local.ColorFav = this.clFav;
7102 SettingManager.Local.ColorOWL = this.clOWL;
7103 SettingManager.Local.ColorRetweet = this.clRetweet;
7104 SettingManager.Local.ColorSelf = this.clSelf;
7105 SettingManager.Local.ColorAtSelf = this.clAtSelf;
7106 SettingManager.Local.ColorTarget = this.clTarget;
7107 SettingManager.Local.ColorAtTarget = this.clAtTarget;
7108 SettingManager.Local.ColorAtFromTarget = this.clAtFromTarget;
7109 SettingManager.Local.ColorAtTo = this.clAtTo;
7110 SettingManager.Local.ColorListBackcolor = this.clListBackcolor;
7111 SettingManager.Local.ColorInputBackcolor = this.clInputBackcolor;
7112 SettingManager.Local.ColorInputFont = this.clInputFont;
7113 SettingManager.Local.FontInputFont = this.fntInputFont;
7115 if (this.ignoreConfigSave) return;
7116 SettingManager.SaveLocal();
7120 private void SaveConfigsTabs()
7122 var tabSettingList = new List<SettingTabs.SettingTabItem>();
7124 var tabs = this.statuses.Tabs.Append(this.statuses.MuteTab);
7126 foreach (var tab in tabs)
7128 if (!tab.IsPermanentTabType)
7131 var tabSetting = new SettingTabs.SettingTabItem
7133 TabName = tab.TabName,
7134 TabType = tab.TabType,
7135 UnreadManage = tab.UnreadManage,
7136 Protected = tab.Protected,
7137 Notify = tab.Notify,
7138 SoundFile = tab.SoundFile,
7143 case FilterTabModel filterTab:
7144 tabSetting.FilterArray = filterTab.FilterArray;
7146 case UserTimelineTabModel userTab:
7147 tabSetting.User = userTab.ScreenName;
7149 case PublicSearchTabModel searchTab:
7150 tabSetting.SearchWords = searchTab.SearchWords;
7151 tabSetting.SearchLang = searchTab.SearchLang;
7153 case ListTimelineTabModel listTab:
7154 tabSetting.ListInfo = listTab.ListInfo;
7158 tabSettingList.Add(tabSetting);
7161 SettingManager.Tabs.Tabs = tabSettingList;
7162 SettingManager.SaveTabs();
7165 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
7167 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out var inputText);
7168 if (ret != DialogResult.OK)
7171 var match = Twitter.StatusUrlRegex.Match(inputText);
7176 Properties.Resources.OpenURL_InvalidFormat,
7177 Properties.Resources.OpenURL_Caption,
7178 MessageBoxButtons.OK,
7179 MessageBoxIcon.Error);
7185 var statusId = long.Parse(match.Groups["StatusId"].Value);
7186 await this.OpenRelatedTab(statusId);
7188 catch (TabException ex)
7190 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
7194 private void SaveLogMenuItem_Click(object sender, EventArgs e)
7196 var tab = this.CurrentTab;
7198 var rslt = MessageBox.Show(
7199 string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
7200 Properties.Resources.SaveLogMenuItem_ClickText2,
7201 MessageBoxButtons.YesNoCancel,
7202 MessageBoxIcon.Question);
7203 if (rslt == DialogResult.Cancel) return;
7205 this.SaveFileDialog1.FileName = $"{ApplicationSettings.AssemblyName}Posts{DateTimeUtc.Now.ToLocalTime():yyMMdd-HHmmss}.tsv";
7206 this.SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
7207 this.SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
7208 this.SaveFileDialog1.FilterIndex = 0;
7209 this.SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
7210 this.SaveFileDialog1.RestoreDirectory = true;
7212 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
7214 if (!this.SaveFileDialog1.ValidateNames) return;
7215 using var sw = new StreamWriter(this.SaveFileDialog1.FileName, false, Encoding.UTF8);
7216 if (rslt == DialogResult.Yes)
7219 for (var idx = 0; idx < tab.AllCount; idx++)
7221 var post = tab[idx];
7224 protect = "Protect";
7225 sw.WriteLine(post.Nickname + "\t" +
7226 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7227 post.CreatedAt.ToLocalTimeString() + "\t" +
7228 post.ScreenName + "\t" +
7229 post.StatusId + "\t" +
7230 post.ImageUrl + "\t" +
7231 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7237 foreach (var post in this.CurrentTab.SelectedPosts)
7241 protect = "Protect";
7242 sw.WriteLine(post.Nickname + "\t" +
7243 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7244 post.CreatedAt.ToLocalTimeString() + "\t" +
7245 post.ScreenName + "\t" +
7246 post.StatusId + "\t" +
7247 post.ImageUrl + "\t" +
7248 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
7253 this.TopMost = SettingManager.Common.AlwaysTop;
7256 public bool TabRename(string origTabName, [NotNullWhen(true)] out string? newTabName)
7260 using (var inputName = new InputTabName())
7262 inputName.TabName = origTabName;
7263 inputName.ShowDialog();
7264 if (inputName.DialogResult == DialogResult.Cancel) return false;
7265 newTabName = inputName.TabName;
7267 this.TopMost = SettingManager.Common.AlwaysTop;
7268 if (!MyCommon.IsNullOrEmpty(newTabName))
7271 if (this.statuses.ContainsTab(newTabName))
7273 var tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabName);
7274 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
7278 var tabIndex = this.statuses.Tabs.IndexOf(origTabName);
7279 var tabPage = this.ListTab.TabPages[tabIndex];
7282 if (tabPage != null)
7283 tabPage.Text = newTabName;
7285 this.statuses.RenameTab(origTabName, newTabName);
7287 this.SaveConfigsCommon();
7288 this.SaveConfigsTabs();
7289 this.rclickTabName = newTabName;
7298 private void ListTab_MouseClick(object sender, MouseEventArgs e)
7300 if (e.Button == MouseButtons.Middle)
7302 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
7304 if (this.ListTab.GetTabRect(index).Contains(e.Location))
7306 this.RemoveSpecifiedTab(tab.TabName, true);
7307 this.SaveConfigsTabs();
7314 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
7315 => this.TabRename(this.CurrentTabName, out _);
7317 private void ListTab_MouseDown(object sender, MouseEventArgs e)
7319 if (SettingManager.Common.TabMouseLock) return;
7320 if (e.Button == MouseButtons.Left)
7322 foreach (var i in Enumerable.Range(0, this.statuses.Tabs.Count))
7324 if (this.ListTab.GetTabRect(i).Contains(e.Location))
7326 this.tabDrag = true;
7327 this.tabMouseDownPoint = e.Location;
7334 this.tabDrag = false;
7338 private void ListTab_DragEnter(object sender, DragEventArgs e)
7340 if (e.Data.GetDataPresent(typeof(TabPage)))
7341 e.Effect = DragDropEffects.Move;
7343 e.Effect = DragDropEffects.None;
7346 private void ListTab_DragDrop(object sender, DragEventArgs e)
7348 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
7350 this.tabDrag = false;
7353 var cpos = new Point(e.X, e.Y);
7354 var spos = this.ListTab.PointToClient(cpos);
7355 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
7357 var rect = this.ListTab.GetTabRect(index);
7358 if (rect.Contains(spos))
7361 if (spos.X <= (rect.Left + rect.Right) / 2)
7370 // タブのないところにドロップ->最後尾へ移動
7371 if (MyCommon.IsNullOrEmpty(tn))
7373 var lastTab = this.statuses.Tabs.Last();
7374 tn = lastTab.TabName;
7378 var tp = (TabPage)e.Data.GetData(typeof(TabPage));
7379 if (tp.Text == tn) return;
7381 this.ReOrderTab(tp.Text, tn, bef);
7384 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
7386 var baseIndex = this.GetTabPageIndex(baseTabText);
7387 if (baseIndex == -1)
7390 var targetIndex = this.GetTabPageIndex(targetTabText);
7391 if (targetIndex == -1)
7394 using (ControlTransaction.Layout(this.ListTab))
7396 var tab = this.statuses.Tabs[targetIndex];
7397 var tabPage = this.ListTab.TabPages[targetIndex];
7399 this.ListTab.TabPages.Remove(tabPage);
7401 if (targetIndex < baseIndex)
7404 if (!isBeforeBaseTab)
7407 this.statuses.MoveTab(baseIndex, tab);
7409 this.ListTab.TabPages.Insert(baseIndex, tabPage);
7412 this.SaveConfigsTabs();
7415 private void MakeDirectMessageText()
7417 var selectedPosts = this.CurrentTab.SelectedPosts;
7418 if (selectedPosts.Length > 1)
7421 var post = selectedPosts.Single();
7422 var text = $"D {post.ScreenName} {this.StatusText.Text}";
7424 this.inReplyTo = null;
7425 this.StatusText.Text = text;
7426 this.StatusText.SelectionStart = text.Length;
7427 this.StatusText.Focus();
7430 private void MakeReplyText(bool atAll = false)
7432 var selectedPosts = this.CurrentTab.SelectedPosts;
7433 if (selectedPosts.Any(x => x.IsDm))
7435 this.MakeDirectMessageText();
7439 if (selectedPosts.Length == 1)
7441 var post = selectedPosts.Single();
7442 var inReplyToStatusId = post.RetweetedId ?? post.StatusId;
7443 var inReplyToScreenName = post.ScreenName;
7444 this.inReplyTo = (inReplyToStatusId, inReplyToScreenName);
7448 this.inReplyTo = null;
7451 var selfScreenName = this.tw.Username;
7452 var targetScreenNames = new List<string>();
7453 foreach (var post in selectedPosts)
7455 if (post.ScreenName != selfScreenName)
7456 targetScreenNames.Add(post.ScreenName);
7460 foreach (var (_, screenName) in post.ReplyToList)
7462 if (screenName != selfScreenName)
7463 targetScreenNames.Add(screenName);
7468 if (this.inReplyTo != null)
7470 var (_, screenName) = this.inReplyTo.Value;
7471 if (screenName == selfScreenName)
7472 targetScreenNames.Insert(0, screenName);
7475 var text = this.StatusText.Text;
7476 foreach (var screenName in targetScreenNames.AsEnumerable().Reverse())
7478 var atText = $"@{screenName} ";
7479 if (!text.Contains(atText))
7480 text = atText + text;
7483 this.StatusText.Text = text;
7484 this.StatusText.SelectionStart = text.Length;
7485 this.StatusText.Focus();
7488 private void ListTab_MouseUp(object sender, MouseEventArgs e)
7489 => this.tabDrag = false;
7491 private int iconCnt = 0;
7492 private int blinkCnt = 0;
7493 private bool blink = false;
7495 private void RefreshTasktrayIcon()
7497 void EnableTasktrayAnimation()
7498 => this.TimerRefreshIcon.Enabled = true;
7500 void DisableTasktrayAnimation()
7501 => this.TimerRefreshIcon.Enabled = false;
7503 var busyTasks = this.workerSemaphore.CurrentCount != MaxWorderThreads;
7507 if (this.iconCnt >= this.nIconRefresh.Length)
7510 this.NotifyIcon1.Icon = this.nIconRefresh[this.iconCnt];
7511 this.myStatusError = false;
7512 EnableTasktrayAnimation();
7516 var replyIconType = SettingManager.Common.ReplyIconState;
7518 if (replyIconType != MyCommon.REPLY_ICONSTATE.None)
7520 var replyTab = this.statuses.GetTabByType<MentionsTabModel>();
7521 if (replyTab != null && replyTab.UnreadCount > 0)
7525 if (replyIconType == MyCommon.REPLY_ICONSTATE.BlinkIcon && reply)
7528 if (this.blinkCnt > 10)
7531 if (this.blinkCnt == 0)
7532 this.blink = !this.blink;
7534 this.NotifyIcon1.Icon = this.blink ? this.replyIconBlink : this.replyIcon;
7535 EnableTasktrayAnimation();
7539 DisableTasktrayAnimation();
7545 // 優先度:リプライ→エラー→オフライン→アイドル
7546 // エラーは更新アイコンでクリアされる
7547 if (replyIconType == MyCommon.REPLY_ICONSTATE.StaticIcon && reply)
7548 this.NotifyIcon1.Icon = this.replyIcon;
7549 else if (this.myStatusError)
7550 this.NotifyIcon1.Icon = this.nIconAtRed;
7551 else if (this.myStatusOnline)
7552 this.NotifyIcon1.Icon = this.nIconAt;
7554 this.NotifyIcon1.Icon = this.nIconAtSmoke;
7557 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
7558 => this.RefreshTasktrayIcon(); // 200ms
7560 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
7562 // 右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
7563 if (MyCommon.IsNullOrEmpty(this.rclickTabName) || sender != this.ContextMenuTabProperty)
7564 this.rclickTabName = this.CurrentTabName;
7566 if (this.statuses == null) return;
7567 if (this.statuses.Tabs == null) return;
7569 if (!this.statuses.Tabs.TryGetValue(this.rclickTabName, out var tb))
7572 this.NotifyDispMenuItem.Checked = tb.Notify;
7573 this.NotifyTbMenuItem.Checked = tb.Notify;
7575 this.soundfileListup = true;
7576 this.SoundFileComboBox.Items.Clear();
7577 this.SoundFileTbComboBox.Items.Clear();
7578 this.SoundFileComboBox.Items.Add("");
7579 this.SoundFileTbComboBox.Items.Add("");
7580 var oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
7581 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
7583 oDir = oDir.GetDirectories("Sounds")[0];
7585 foreach (var oFile in oDir.GetFiles("*.wav"))
7587 this.SoundFileComboBox.Items.Add(oFile.Name);
7588 this.SoundFileTbComboBox.Items.Add(oFile.Name);
7590 var idx = this.SoundFileComboBox.Items.IndexOf(tb.SoundFile);
7591 if (idx == -1) idx = 0;
7592 this.SoundFileComboBox.SelectedIndex = idx;
7593 this.SoundFileTbComboBox.SelectedIndex = idx;
7594 this.soundfileListup = false;
7595 this.UreadManageMenuItem.Checked = tb.UnreadManage;
7596 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
7598 this.TabMenuControl(this.rclickTabName);
7601 private void TabMenuControl(string tabName)
7603 var tabInfo = this.statuses.GetTabByName(tabName)!;
7605 this.FilterEditMenuItem.Enabled = true;
7606 this.EditRuleTbMenuItem.Enabled = true;
7608 if (tabInfo.IsDefaultTabType)
7610 this.ProtectTabMenuItem.Enabled = false;
7611 this.ProtectTbMenuItem.Enabled = false;
7615 this.ProtectTabMenuItem.Enabled = true;
7616 this.ProtectTbMenuItem.Enabled = true;
7619 if (tabInfo.IsDefaultTabType || tabInfo.Protected)
7621 this.ProtectTabMenuItem.Checked = true;
7622 this.ProtectTbMenuItem.Checked = true;
7623 this.DeleteTabMenuItem.Enabled = false;
7624 this.DeleteTbMenuItem.Enabled = false;
7628 this.ProtectTabMenuItem.Checked = false;
7629 this.ProtectTbMenuItem.Checked = false;
7630 this.DeleteTabMenuItem.Enabled = true;
7631 this.DeleteTbMenuItem.Enabled = true;
7635 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
7637 var checkState = ((ToolStripMenuItem)sender).Checked;
7640 this.ProtectTbMenuItem.Checked = checkState;
7641 this.ProtectTabMenuItem.Checked = checkState;
7644 this.DeleteTabMenuItem.Enabled = !checkState;
7645 this.DeleteTbMenuItem.Enabled = !checkState;
7647 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
7648 this.statuses.Tabs[this.rclickTabName].Protected = checkState;
7650 this.SaveConfigsTabs();
7653 private void UreadManageMenuItem_Click(object sender, EventArgs e)
7655 this.UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
7656 this.UnreadMngTbMenuItem.Checked = this.UreadManageMenuItem.Checked;
7658 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
7659 this.ChangeTabUnreadManage(this.rclickTabName, this.UreadManageMenuItem.Checked);
7661 this.SaveConfigsTabs();
7664 public void ChangeTabUnreadManage(string tabName, bool isManage)
7666 var idx = this.GetTabPageIndex(tabName);
7670 var tab = this.statuses.Tabs[tabName];
7671 tab.UnreadManage = isManage;
7673 if (SettingManager.Common.TabIconDisp)
7675 var tabPage = this.ListTab.TabPages[idx];
7676 if (tab.UnreadCount > 0)
7677 tabPage.ImageIndex = 0;
7679 tabPage.ImageIndex = -1;
7682 if (this.CurrentTabName == tabName)
7684 this.PurgeListViewItemCache();
7685 this.CurrentListView.Refresh();
7688 this.SetMainWindowTitle();
7689 this.SetStatusLabelUrl();
7690 if (!SettingManager.Common.TabIconDisp) this.ListTab.Refresh();
7693 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
7695 this.NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
7696 this.NotifyTbMenuItem.Checked = this.NotifyDispMenuItem.Checked;
7698 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
7700 this.statuses.Tabs[this.rclickTabName].Notify = this.NotifyDispMenuItem.Checked;
7702 this.SaveConfigsTabs();
7705 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
7707 if (this.soundfileListup || MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
7709 this.statuses.Tabs[this.rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
7711 this.SaveConfigsTabs();
7714 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
7716 if (MyCommon.IsNullOrEmpty(this.rclickTabName) || sender == this.DeleteTbMenuItem)
7717 this.rclickTabName = this.CurrentTabName;
7719 this.RemoveSpecifiedTab(this.rclickTabName, true);
7720 this.SaveConfigsTabs();
7723 private void FilterEditMenuItem_Click(object sender, EventArgs e)
7725 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) this.rclickTabName = this.statuses.HomeTab.TabName;
7727 using (var fltDialog = new FilterDialog())
7729 fltDialog.Owner = this;
7730 fltDialog.SetCurrent(this.rclickTabName);
7731 fltDialog.ShowDialog(this);
7733 this.TopMost = SettingManager.Common.AlwaysTop;
7735 this.ApplyPostFilters();
7736 this.SaveConfigsTabs();
7739 private async void AddTabMenuItem_Click(object sender, EventArgs e)
7741 string? tabName = null;
7742 MyCommon.TabUsageType tabUsage;
7743 using (var inputName = new InputTabName())
7745 inputName.TabName = this.statuses.MakeTabName("MyTab");
7746 inputName.IsShowUsage = true;
7747 inputName.ShowDialog();
7748 if (inputName.DialogResult == DialogResult.Cancel) return;
7749 tabName = inputName.TabName;
7750 tabUsage = inputName.Usage;
7752 this.TopMost = SettingManager.Common.AlwaysTop;
7753 if (!MyCommon.IsNullOrEmpty(tabName))
7756 ListElement? list = null;
7757 if (tabUsage == MyCommon.TabUsageType.Lists)
7759 using var listAvail = new ListAvailable();
7760 if (listAvail.ShowDialog(this) == DialogResult.Cancel)
7762 if (listAvail.SelectedList == null)
7764 list = listAvail.SelectedList;
7770 case MyCommon.TabUsageType.UserDefined:
7771 tab = new FilterTabModel(tabName);
7773 case MyCommon.TabUsageType.PublicSearch:
7774 tab = new PublicSearchTabModel(tabName);
7776 case MyCommon.TabUsageType.Lists:
7777 tab = new ListTimelineTabModel(tabName, list!);
7783 if (!this.statuses.AddTab(tab) || !this.AddNewTab(tab, startup: false))
7785 var tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
7786 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
7791 this.SaveConfigsTabs();
7793 var tabIndex = this.statuses.Tabs.Count - 1;
7795 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
7797 this.ListTab.SelectedIndex = tabIndex;
7798 this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus();
7800 if (tabUsage == MyCommon.TabUsageType.Lists)
7802 this.ListTab.SelectedIndex = tabIndex;
7803 await this.RefreshTabAsync(this.CurrentTab);
7809 private void TabMenuItem_Click(object sender, EventArgs e)
7812 foreach (var post in this.CurrentTab.SelectedPosts)
7815 if (!this.SelectTab(out var tab))
7818 using (var fltDialog = new FilterDialog())
7820 fltDialog.Owner = this;
7821 fltDialog.SetCurrent(tab.TabName);
7823 if (post.RetweetedBy == null)
7825 fltDialog.AddNewFilter(post.ScreenName, post.TextFromApi);
7829 fltDialog.AddNewFilter(post.RetweetedBy, post.TextFromApi);
7831 fltDialog.ShowDialog(this);
7834 this.TopMost = SettingManager.Common.AlwaysTop;
7837 this.ApplyPostFilters();
7838 this.SaveConfigsTabs();
7841 protected override bool ProcessDialogKey(Keys keyData)
7843 // TextBox1でEnterを押してもビープ音が鳴らないようにする
7844 if ((keyData & Keys.KeyCode) == Keys.Enter)
7846 if (this.StatusText.Focused)
7848 var newLine = false;
7851 if (SettingManager.Common.PostCtrlEnter) // Ctrl+Enter投稿時
7853 if (this.StatusText.Multiline)
7855 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) newLine = true;
7857 if ((keyData & Keys.Control) == Keys.Control) post = true;
7861 if ((keyData & Keys.Control) == Keys.Control) post = true;
7864 else if (SettingManager.Common.PostShiftEnter) // SHift+Enter投稿時
7866 if (this.StatusText.Multiline)
7868 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) newLine = true;
7870 if ((keyData & Keys.Shift) == Keys.Shift) post = true;
7874 if ((keyData & Keys.Shift) == Keys.Shift) post = true;
7879 if (this.StatusText.Multiline)
7881 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) newLine = true;
7883 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
7884 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) post = true;
7888 if (((keyData & Keys.Shift) == Keys.Shift) ||
7889 (((keyData & Keys.Control) != Keys.Control) &&
7890 ((keyData & Keys.Shift) != Keys.Shift))) post = true;
7896 var pos1 = this.StatusText.SelectionStart;
7897 if (this.StatusText.SelectionLength > 0)
7899 this.StatusText.Text = this.StatusText.Text.Remove(pos1, this.StatusText.SelectionLength); // 選択状態文字列削除
7901 this.StatusText.Text = this.StatusText.Text.Insert(pos1, Environment.NewLine); // 改行挿入
7902 this.StatusText.SelectionStart = pos1 + Environment.NewLine.Length; // カーソルを改行の次の文字へ移動
7907 this.PostButton_Click(this.PostButton, EventArgs.Empty);
7913 var tab = this.CurrentTab;
7914 if (tab.TabType == MyCommon.TabUsageType.PublicSearch)
7916 var tabPage = this.CurrentTabPage;
7917 if (tabPage.Controls["panelSearch"].Controls["comboSearch"].Focused ||
7918 tabPage.Controls["panelSearch"].Controls["comboLang"].Focused)
7920 this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
7927 return base.ProcessDialogKey(keyData);
7930 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
7931 => this.MakeReplyText(atAll: true);
7933 private void IDRuleMenuItem_Click(object sender, EventArgs e)
7935 var tab = this.CurrentTab;
7936 var selectedPosts = tab.SelectedPosts;
7939 if (selectedPosts.Length == 0)
7942 var screenNameArray = selectedPosts
7943 .Select(x => x.RetweetedBy ?? x.ScreenName)
7946 this.AddFilterRuleByScreenName(screenNameArray);
7948 if (screenNameArray.Length != 0)
7950 var atids = new List<string>();
7951 foreach (var screenName in screenNameArray)
7953 atids.Add("@" + screenName);
7955 var cnt = this.AtIdSupl.ItemCount;
7956 this.AtIdSupl.AddRangeItem(atids.ToArray());
7957 if (this.AtIdSupl.ItemCount != cnt)
7958 this.MarkSettingAtIdModified();
7962 private void SourceRuleMenuItem_Click(object sender, EventArgs e)
7964 var tab = this.CurrentTab;
7965 var selectedPosts = tab.SelectedPosts;
7967 if (selectedPosts.Length == 0)
7970 var sourceArray = selectedPosts.Select(x => x.Source).ToArray();
7972 this.AddFilterRuleBySource(sourceArray);
7975 public void AddFilterRuleByScreenName(params string[] screenNameArray)
7978 if (!this.SelectTab(out var tab)) return;
7982 if (tab.TabType != MyCommon.TabUsageType.Mute)
7984 this.MoveOrCopy(out mv, out mk);
7988 // ミュートタブでは常に MoveMatches を true にする
7993 foreach (var screenName in screenNameArray)
7995 tab.AddFilter(new PostFilterRule
7997 FilterName = screenName,
7998 UseNameField = true,
8002 FilterByUrl = false,
8006 this.ApplyPostFilters();
8007 this.SaveConfigsTabs();
8010 public void AddFilterRuleBySource(params string[] sourceArray)
8012 // タブ選択ダイアログを表示(or追加)
8013 if (!this.SelectTab(out var filterTab))
8018 if (filterTab.TabType != MyCommon.TabUsageType.Mute)
8020 // フィルタ動作選択ダイアログを表示(移動/コピー, マーク有無)
8021 this.MoveOrCopy(out mv, out mk);
8025 // ミュートタブでは常に MoveMatches を true にする
8030 // 振り分けルールに追加するSource
8031 foreach (var source in sourceArray)
8033 filterTab.AddFilter(new PostFilterRule
8035 FilterSource = source,
8039 FilterByUrl = false,
8043 this.ApplyPostFilters();
8044 this.SaveConfigsTabs();
8047 private bool SelectTab([NotNullWhen(true)] out FilterTabModel? tab)
8054 using (var dialog = new TabsDialog(this.statuses))
8056 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
8058 tab = dialog.SelectedTab;
8061 this.CurrentTabPage.Focus();
8066 using (var inputName = new InputTabName())
8068 inputName.TabName = this.statuses.MakeTabName("MyTab");
8069 inputName.ShowDialog();
8070 if (inputName.DialogResult == DialogResult.Cancel) return false;
8071 tabName = inputName.TabName;
8073 this.TopMost = SettingManager.Common.AlwaysTop;
8074 if (!MyCommon.IsNullOrEmpty(tabName))
8076 var newTab = new FilterTabModel(tabName);
8077 if (!this.statuses.AddTab(newTab) || !this.AddNewTab(newTab, startup: false))
8079 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
8080 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
8099 private void MoveOrCopy(out bool move, out bool mark)
8103 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
8104 if (MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
8112 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
8113 if (MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
8124 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
8127 private void CopyURLMenuItem_Click(object sender, EventArgs e)
8128 => this.CopyIdUri();
8130 private void SelectAllMenuItem_Click(object sender, EventArgs e)
8132 if (this.StatusText.Focused)
8135 this.StatusText.SelectAll();
8139 // ListView上でのCtrl+A
8140 NativeMethods.SelectAllItems(this.CurrentListView);
8144 private void MoveMiddle()
8150 var listView = this.CurrentListView;
8151 if (listView.SelectedIndices.Count == 0) return;
8153 var idx = listView.SelectedIndices[0];
8155 item = listView.GetItemAt(0, 25);
8161 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
8163 idx2 = listView.VirtualListSize - 1;
8167 idx -= Math.Abs(idx1 - idx2) / 2;
8168 if (idx < 0) idx = 0;
8170 listView.EnsureVisible(listView.VirtualListSize - 1);
8171 listView.EnsureVisible(idx);
8174 private async void OpenURLMenuItem_Click(object sender, EventArgs e)
8176 var linkElements = this.tweetDetailsView.GetLinkElements();
8178 if (linkElements.Length == 0)
8181 var links = new List<OpenUrlItem>(linkElements.Length);
8183 foreach (var linkElm in linkElements)
8185 var displayUrl = linkElm.GetAttribute("title");
8186 var href = linkElm.GetAttribute("href");
8187 var linkedText = linkElm.InnerText;
8189 if (MyCommon.IsNullOrEmpty(displayUrl))
8192 links.Add(new OpenUrlItem(linkedText, displayUrl, href));
8196 bool isReverseSettings;
8198 if (links.Count == 1)
8200 // ツイートに含まれる URL が 1 つのみの場合
8201 // => OpenURL ダイアログを表示せずにリンクを開く
8202 selectedUrl = links[0].Href;
8204 // Ctrl+E で呼ばれた場合を考慮し isReverseSettings の判定を行わない
8205 isReverseSettings = false;
8209 // ツイートに含まれる URL が複数ある場合
8210 // => OpenURL を表示しユーザーが選択したリンクを開く
8211 this.urlDialog.ClearUrl();
8213 foreach (var link in links)
8214 this.urlDialog.AddUrl(link);
8216 if (this.urlDialog.ShowDialog(this) != DialogResult.OK)
8219 this.TopMost = SettingManager.Common.AlwaysTop;
8221 selectedUrl = this.urlDialog.SelectedUrl;
8223 // Ctrlを押しながらリンクを開いた場合は、設定と逆の動作をするフラグを true としておく
8224 isReverseSettings = MyCommon.IsKeyDown(Keys.Control);
8227 await this.OpenUriAsync(new Uri(selectedUrl), isReverseSettings);
8230 private void ClearTabMenuItem_Click(object sender, EventArgs e)
8232 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
8233 this.ClearTab(this.rclickTabName, true);
8236 private void ClearTab(string tabName, bool showWarning)
8240 var tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
8241 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
8247 this.statuses.ClearTabIds(tabName);
8248 if (this.CurrentTabName == tabName)
8250 this.anchorPost = null;
8251 this.anchorFlag = false;
8252 this.PurgeListViewItemCache();
8255 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
8256 var tabPage = this.ListTab.TabPages[tabIndex];
8257 tabPage.ImageIndex = -1;
8259 var listView = (DetailsListView)tabPage.Tag;
8260 listView.VirtualListSize = 0;
8262 if (!SettingManager.Common.TabIconDisp) this.ListTab.Refresh();
8264 this.SetMainWindowTitle();
8265 this.SetStatusLabelUrl();
8268 private static long followers = 0;
8270 private void SetMainWindowTitle()
8272 // メインウインドウタイトルの書き換え
8273 var ttl = new StringBuilder(256);
8276 if (SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.None &&
8277 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.Post &&
8278 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
8279 SettingManager.Common.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
8281 foreach (var tab in this.statuses.Tabs)
8283 ur += tab.UnreadCount;
8288 if (SettingManager.Common.DispUsername) ttl.Append(this.tw.Username).Append(" - ");
8289 ttl.Append(ApplicationSettings.ApplicationName);
8291 switch (SettingManager.Common.DispLatestPost)
8293 case MyCommon.DispTitleEnum.Ver:
8294 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
8296 case MyCommon.DispTitleEnum.Post:
8297 if (this.history != null && this.history.Count > 1)
8298 ttl.Append(this.history[this.history.Count - 2].Status.Replace("\r\n", " "));
8300 case MyCommon.DispTitleEnum.UnreadRepCount:
8301 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, this.statuses.MentionTab.UnreadCount + this.statuses.DirectMessageTab.UnreadCount);
8303 case MyCommon.DispTitleEnum.UnreadAllCount:
8304 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
8306 case MyCommon.DispTitleEnum.UnreadAllRepCount:
8307 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, this.statuses.MentionTab.UnreadCount + this.statuses.DirectMessageTab.UnreadCount);
8309 case MyCommon.DispTitleEnum.UnreadCountAllCount:
8310 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
8312 case MyCommon.DispTitleEnum.OwnStatus:
8313 if (followers == 0 && this.tw.FollowersCount > 0) followers = this.tw.FollowersCount;
8314 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, this.tw.StatusesCount, this.tw.FriendsCount, this.tw.FollowersCount, this.tw.FollowersCount - followers);
8320 this.Text = ttl.ToString();
8322 catch (AccessViolationException)
8324 // 原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
8328 private string GetStatusLabelText()
8331 // タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
8332 if (this.statuses == null) return "";
8333 var tbRep = this.statuses.MentionTab;
8334 var tbDm = this.statuses.DirectMessageTab;
8335 if (tbRep == null || tbDm == null) return "";
8336 var urat = tbRep.UnreadCount + tbDm.UnreadCount;
8341 var slbl = new StringBuilder(256);
8344 foreach (var tab in this.statuses.Tabs)
8346 ur += tab.UnreadCount;
8348 if (tab.TabName == this.CurrentTabName)
8350 tur = tab.UnreadCount;
8360 this.unreadCounter = ur;
8361 this.unreadAtCounter = urat;
8363 var homeTab = this.statuses.HomeTab;
8365 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, this.postTimestamps.Count, this.favTimestamps.Count, homeTab.TweetsPerHour);
8366 if (SettingManager.Common.TimelinePeriod == 0)
8368 slbl.Append(Properties.Resources.SetStatusLabelText2);
8372 slbl.Append(SettingManager.Common.TimelinePeriod + Properties.Resources.SetStatusLabelText3);
8374 return slbl.ToString();
8377 private async void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
8381 if (this.InvokeRequired && !this.IsDisposed)
8383 await this.InvokeAsync(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e));
8387 var endpointName = ((TwitterApiStatus.AccessLimitUpdatedEventArgs)e).EndpointName;
8388 this.SetApiStatusLabel(endpointName);
8391 catch (ObjectDisposedException)
8395 catch (InvalidOperationException)
8401 private void SetApiStatusLabel(string? endpointName = null)
8403 var tabType = this.CurrentTab.TabType;
8405 if (endpointName == null)
8408 endpointName = tabType switch
8410 MyCommon.TabUsageType.Home => "/statuses/home_timeline",
8411 MyCommon.TabUsageType.UserDefined => "/statuses/home_timeline",
8412 MyCommon.TabUsageType.Mentions => "/statuses/mentions_timeline",
8413 MyCommon.TabUsageType.Favorites => "/favorites/list",
8414 MyCommon.TabUsageType.DirectMessage => "/direct_messages/events/list",
8415 MyCommon.TabUsageType.UserTimeline => "/statuses/user_timeline",
8416 MyCommon.TabUsageType.Lists => "/lists/statuses",
8417 MyCommon.TabUsageType.PublicSearch => "/search/tweets",
8418 MyCommon.TabUsageType.Related => "/statuses/show/:id",
8421 this.toolStripApiGauge.ApiEndpoint = endpointName;
8425 // 表示中のタブに関連する endpoint であれば更新
8426 var update = endpointName switch
8428 "/statuses/home_timeline" => tabType == MyCommon.TabUsageType.Home || tabType == MyCommon.TabUsageType.UserDefined,
8429 "/statuses/mentions_timeline" => tabType == MyCommon.TabUsageType.Mentions,
8430 "/favorites/list" => tabType == MyCommon.TabUsageType.Favorites,
8431 "/direct_messages/events/list" => tabType == MyCommon.TabUsageType.DirectMessage,
8432 "/statuses/user_timeline" => tabType == MyCommon.TabUsageType.UserTimeline,
8433 "/lists/statuses" => tabType == MyCommon.TabUsageType.Lists,
8434 "/search/tweets" => tabType == MyCommon.TabUsageType.PublicSearch,
8435 "/statuses/show/:id" => tabType == MyCommon.TabUsageType.Related,
8440 this.toolStripApiGauge.ApiEndpoint = endpointName;
8445 private void SetStatusLabelUrl()
8446 => this.StatusLabelUrl.Text = this.GetStatusLabelText();
8448 public void SetStatusLabel(string text)
8449 => this.StatusLabel.Text = text;
8451 private void SetNotifyIconText()
8453 var ur = new StringBuilder(64);
8455 // タスクトレイアイコンのツールチップテキスト書き換え
8457 ur.Remove(0, ur.Length);
8458 if (SettingManager.Common.DispUsername)
8460 ur.Append(this.tw.Username);
8463 ur.Append(ApplicationSettings.ApplicationName);
8465 ur.Append("(Debug Build)");
8467 if (this.unreadCounter != -1 && this.unreadAtCounter != -1)
8470 ur.Append(this.unreadCounter);
8472 ur.Append(this.unreadAtCounter);
8475 this.NotifyIcon1.Text = ur.ToString();
8478 internal void CheckReplyTo(string statusText)
8482 m = Regex.Matches(statusText, Twitter.Hashtag, RegexOptions.IgnoreCase);
8484 foreach (Match hm in m)
8486 if (!hstr.Contains("#" + hm.Result("$3") + " "))
8488 hstr += "#" + hm.Result("$3") + " ";
8489 this.HashSupl.AddItem("#" + hm.Result("$3"));
8492 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash) && !hstr.Contains(this.HashMgr.UseHash + " "))
8494 hstr += this.HashMgr.UseHash;
8496 if (!MyCommon.IsNullOrEmpty(hstr)) this.HashMgr.AddHashToHistory(hstr.Trim(), false);
8498 // 本当にリプライ先指定すべきかどうかの判定
8499 m = Regex.Matches(statusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
8501 if (SettingManager.Common.UseAtIdSupplement)
8503 var bCnt = this.AtIdSupl.ItemCount;
8504 foreach (Match mid in m)
8506 this.AtIdSupl.AddItem(mid.Result("${id}"));
8508 if (bCnt != this.AtIdSupl.ItemCount)
8509 this.MarkSettingAtIdModified();
8512 // リプライ先ステータスIDの指定がない場合は指定しない
8513 if (this.inReplyTo == null)
8517 // 次の条件を満たす場合に in_reply_to_status_id 指定
8518 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
8519 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
8520 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
8524 var inReplyToScreenName = this.inReplyTo.Value.ScreenName;
8525 if (statusText.StartsWith("@", StringComparison.Ordinal))
8527 if (statusText.StartsWith("@" + inReplyToScreenName, StringComparison.Ordinal)) return;
8531 foreach (Match mid in m)
8533 if (statusText.Contains("RT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + inReplyToScreenName) return;
8538 this.inReplyTo = null;
8541 private void TweenMain_Resize(object sender, EventArgs e)
8543 if (!this.initialLayout && SettingManager.Common.MinimizeToTray && this.WindowState == FormWindowState.Minimized)
8545 this.Visible = false;
8547 if (this.initialLayout && SettingManager.Local != null && this.WindowState == FormWindowState.Normal && this.Visible)
8549 // 現在の DPI と設定保存時の DPI との比を取得する
8550 var configScaleFactor = SettingManager.Local.GetConfigScaleFactor(this.CurrentAutoScaleDimensions);
8552 this.ClientSize = ScaleBy(configScaleFactor, SettingManager.Local.FormSize);
8555 var splitterDistance = ScaleBy(configScaleFactor.Height, SettingManager.Local.SplitterDistance);
8556 if (splitterDistance > this.SplitContainer1.Panel1MinSize &&
8557 splitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
8559 this.SplitContainer1.SplitterDistance = splitterDistance;
8563 this.StatusText.Multiline = SettingManager.Local.StatusMultiline;
8564 if (this.StatusText.Multiline)
8566 var statusTextHeight = ScaleBy(configScaleFactor.Height, SettingManager.Local.StatusTextHeight);
8567 var dis = this.SplitContainer2.Height - statusTextHeight - this.SplitContainer2.SplitterWidth;
8568 if (dis > this.SplitContainer2.Panel1MinSize && dis < this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth)
8570 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - statusTextHeight - this.SplitContainer2.SplitterWidth;
8572 this.StatusText.Height = statusTextHeight;
8576 if (this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth > 0)
8578 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth;
8582 var previewDistance = ScaleBy(configScaleFactor.Width, SettingManager.Local.PreviewDistance);
8583 if (previewDistance > this.SplitContainer3.Panel1MinSize && previewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
8585 this.SplitContainer3.SplitterDistance = previewDistance;
8588 // Panel2Collapsed は SplitterDistance の設定を終えるまで true にしない
8589 this.SplitContainer3.Panel2Collapsed = true;
8591 this.initialLayout = false;
8593 if (this.WindowState != FormWindowState.Minimized)
8595 this.formWindowState = this.WindowState;
8599 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
8601 this.PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8602 this.PlaySoundFileMenuItem.Checked = this.PlaySoundMenuItem.Checked;
8603 if (this.PlaySoundMenuItem.Checked)
8605 SettingManager.Common.PlaySound = true;
8609 SettingManager.Common.PlaySound = false;
8611 this.MarkSettingCommonModified();
8614 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
8616 if (this.initialLayout)
8619 int splitterDistance;
8620 switch (this.WindowState)
8622 case FormWindowState.Normal:
8623 splitterDistance = this.SplitContainer1.SplitterDistance;
8625 case FormWindowState.Maximized:
8626 // 最大化時は、通常時のウィンドウサイズに換算した SplitterDistance を算出する
8627 var normalContainerHeight = this.mySize.Height - this.ToolStripContainer1.TopToolStripPanel.Height - this.ToolStripContainer1.BottomToolStripPanel.Height;
8628 splitterDistance = this.SplitContainer1.SplitterDistance - (this.SplitContainer1.Height - normalContainerHeight);
8629 splitterDistance = Math.Min(splitterDistance, normalContainerHeight - this.SplitContainer1.SplitterWidth - this.SplitContainer1.Panel2MinSize);
8635 this.mySpDis = splitterDistance;
8636 this.MarkSettingLocalModified();
8639 private async Task DoRepliedStatusOpen()
8641 var currentPost = this.CurrentPost;
8642 if (this.ExistCurrentPost && currentPost != null && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)
8644 if (MyCommon.IsKeyDown(Keys.Shift))
8646 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.Value));
8649 if (this.statuses.Posts.TryGetValue(currentPost.InReplyToStatusId.Value, out var repPost))
8651 MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname} ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
8655 foreach (var tb in this.statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
8657 if (tb == null || !tb.Contains(currentPost.InReplyToStatusId.Value)) break;
8658 repPost = tb.Posts[currentPost.InReplyToStatusId.Value];
8659 MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname} ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
8662 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.Value));
8667 private async void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
8668 => await this.DoRepliedStatusOpen();
8670 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
8672 if (this.initialLayout)
8673 return; // SettingLocal の反映が完了するまで multiline の判定を行わない
8675 var multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
8676 if (multiline != this.StatusText.Multiline)
8678 this.StatusText.Multiline = multiline;
8679 SettingManager.Local.StatusMultiline = multiline;
8680 this.MarkSettingLocalModified();
8684 private void StatusText_MultilineChanged(object sender, EventArgs e)
8686 if (this.StatusText.Multiline)
8687 this.StatusText.ScrollBars = ScrollBars.Vertical;
8689 this.StatusText.ScrollBars = ScrollBars.None;
8691 if (!this.initialLayout)
8692 this.MarkSettingLocalModified();
8695 private void MultiLineMenuItem_Click(object sender, EventArgs e)
8698 var menuItemChecked = ((ToolStripMenuItem)sender).Checked;
8699 this.StatusText.Multiline = menuItemChecked;
8700 SettingManager.Local.StatusMultiline = menuItemChecked;
8701 if (menuItemChecked)
8703 if (this.SplitContainer2.Height - this.mySpDis2 - this.SplitContainer2.SplitterWidth < 0)
8704 this.SplitContainer2.SplitterDistance = 0;
8706 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.mySpDis2 - this.SplitContainer2.SplitterWidth;
8710 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth;
8712 this.MarkSettingLocalModified();
8715 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter converterType)
8717 if (converterType == MyCommon.UrlConverter.Bitly || converterType == MyCommon.UrlConverter.Jmp)
8719 // OAuth2 アクセストークンまたは API キー (旧方式) のいずれも設定されていなければ短縮しない
8720 if (MyCommon.IsNullOrEmpty(SettingManager.Common.BitlyAccessToken) &&
8721 (MyCommon.IsNullOrEmpty(SettingManager.Common.BilyUser) || MyCommon.IsNullOrEmpty(SettingManager.Common.BitlyPwd)))
8723 MessageBox.Show(this, Properties.Resources.UrlConvert_BitlyAuthRequired, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
8728 // Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
8729 // 参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
8730 // Appendix A. Collected ABNF for URI
8731 // http://www.ietf.org/rfc/rfc3986.txt
8733 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
8736 if (this.StatusText.SelectionLength > 0)
8738 var tmp = this.StatusText.SelectedText;
8739 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
8740 if (tmp.StartsWith("http", StringComparison.OrdinalIgnoreCase))
8742 // 文字列が選択されている場合はその文字列について処理
8744 // nico.ms使用、nicovideoにマッチしたら変換
8745 if (SettingManager.Common.Nicoms && Regex.IsMatch(tmp, nico))
8747 result = Nicoms.Shorten(tmp);
8749 else if (converterType != MyCommon.UrlConverter.Nicoms)
8754 var srcUri = new Uri(tmp);
8755 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(converterType, srcUri);
8756 result = resultUri.AbsoluteUri;
8758 catch (WebApiException e)
8760 this.StatusLabel.Text = converterType + ":" + e.Message;
8763 catch (UriFormatException e)
8765 this.StatusLabel.Text = converterType + ":" + e.Message;
8774 if (!MyCommon.IsNullOrEmpty(result))
8776 var undotmp = new UrlUndo();
8778 // 短縮 URL が生成されるまでの間に投稿欄から元の URL が削除されていたら中断する
8779 var origUrlIndex = this.StatusText.Text.IndexOf(tmp, StringComparison.Ordinal);
8780 if (origUrlIndex == -1)
8783 this.StatusText.Select(origUrlIndex, tmp.Length);
8784 this.StatusText.SelectedText = result;
8787 undotmp.Before = tmp;
8788 undotmp.After = result;
8790 if (this.urlUndoBuffer == null)
8792 this.urlUndoBuffer = new List<UrlUndo>();
8793 this.UrlUndoToolStripMenuItem.Enabled = true;
8796 this.urlUndoBuffer.Add(undotmp);
8802 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
8803 @"(?<url>(?<protocol>https?://)" +
8804 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
8805 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
8806 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
8807 // 正規表現にマッチしたURL文字列をtinyurl化
8808 foreach (Match mt in Regex.Matches(this.StatusText.Text, url, RegexOptions.IgnoreCase))
8810 if (this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1)
8812 var tmp = mt.Result("${url}");
8813 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase))
8814 tmp = "http://" + tmp;
8815 var undotmp = new UrlUndo();
8818 this.StatusText.Select(this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
8820 // nico.ms使用、nicovideoにマッチしたら変換
8821 if (SettingManager.Common.Nicoms && Regex.IsMatch(tmp, nico))
8823 result = Nicoms.Shorten(tmp);
8825 else if (converterType != MyCommon.UrlConverter.Nicoms)
8830 var srcUri = new Uri(tmp);
8831 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(converterType, srcUri);
8832 result = resultUri.AbsoluteUri;
8834 catch (HttpRequestException e)
8836 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
8837 // のように長いので「:」が含まれていればそれ以降のみを抽出する
8838 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
8840 this.StatusLabel.Text = converterType + ":" + message;
8843 catch (WebApiException e)
8845 this.StatusLabel.Text = converterType + ":" + e.Message;
8848 catch (UriFormatException e)
8850 this.StatusLabel.Text = converterType + ":" + e.Message;
8859 if (!MyCommon.IsNullOrEmpty(result))
8861 // 短縮 URL が生成されるまでの間に投稿欄から元の URL が削除されていたら中断する
8862 var origUrlIndex = this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal);
8863 if (origUrlIndex == -1)
8866 this.StatusText.Select(origUrlIndex, mt.Result("${url}").Length);
8867 this.StatusText.SelectedText = result;
8869 undotmp.Before = mt.Result("${url}");
8870 undotmp.After = result;
8872 if (this.urlUndoBuffer == null)
8874 this.urlUndoBuffer = new List<UrlUndo>();
8875 this.UrlUndoToolStripMenuItem.Enabled = true;
8878 this.urlUndoBuffer.Add(undotmp);
8886 private void DoUrlUndo()
8888 if (this.urlUndoBuffer != null)
8890 var tmp = this.StatusText.Text;
8891 foreach (var data in this.urlUndoBuffer)
8893 tmp = tmp.Replace(data.After, data.Before);
8895 this.StatusText.Text = tmp;
8896 this.urlUndoBuffer = null;
8897 this.UrlUndoToolStripMenuItem.Enabled = false;
8898 this.StatusText.SelectionStart = 0;
8899 this.StatusText.SelectionLength = 0;
8903 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
8904 => await this.UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
8906 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
8907 => await this.UrlConvertAsync(MyCommon.UrlConverter.Isgd);
8909 private async void UxnuMenuItem_Click(object sender, EventArgs e)
8910 => await this.UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
8912 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
8914 if (!await this.UrlConvertAsync(SettingManager.Common.AutoShortUrlFirst))
8916 var rnd = new Random();
8918 MyCommon.UrlConverter svc;
8919 // 前回使用した短縮URLサービス以外を選択する
8922 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
8924 while (svc == SettingManager.Common.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
8925 await this.UrlConvertAsync(svc);
8929 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
8930 => this.DoUrlUndo();
8932 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
8934 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8935 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
8936 SettingManager.Common.NewAllPop = this.NewPostPopMenuItem.Checked;
8937 this.MarkSettingCommonModified();
8940 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
8942 this.ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
8943 this.LockListFileMenuItem.Checked = this.ListLockMenuItem.Checked;
8944 SettingManager.Common.ListLock = this.ListLockMenuItem.Checked;
8945 this.MarkSettingCommonModified();
8948 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
8950 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
8951 this.MenuStrip1.Tag = new object();
8952 this.MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
8955 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
8957 var currentTabPage = this.CurrentTabPage;
8958 if (this.Tag != null) // 設定された戻り先へ遷移
8960 if (this.Tag == currentTabPage)
8961 ((Control)currentTabPage.Tag).Select();
8963 ((Control)this.Tag).Select();
8965 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
8967 this.Tag = currentTabPage.Tag;
8968 ((Control)this.Tag).Select();
8970 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
8971 this.MenuStrip1.Tag = null;
8974 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
8976 var lst = (DetailsListView)sender;
8977 if (SettingManager.Local == null) return;
8981 SettingManager.Local.Width1 = lst.Columns[0].Width;
8982 SettingManager.Local.Width3 = lst.Columns[1].Width;
8986 var darr = new int[lst.Columns.Count];
8987 for (var i = 0; i < lst.Columns.Count; i++)
8989 darr[lst.Columns[i].DisplayIndex] = i;
8991 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
8993 for (var i = 0; i < lst.Columns.Count; i++)
8998 SettingManager.Local.DisplayIndex1 = i;
9001 SettingManager.Local.DisplayIndex2 = i;
9004 SettingManager.Local.DisplayIndex3 = i;
9007 SettingManager.Local.DisplayIndex4 = i;
9010 SettingManager.Local.DisplayIndex5 = i;
9013 SettingManager.Local.DisplayIndex6 = i;
9016 SettingManager.Local.DisplayIndex7 = i;
9019 SettingManager.Local.DisplayIndex8 = i;
9023 SettingManager.Local.Width1 = lst.Columns[0].Width;
9024 SettingManager.Local.Width2 = lst.Columns[1].Width;
9025 SettingManager.Local.Width3 = lst.Columns[2].Width;
9026 SettingManager.Local.Width4 = lst.Columns[3].Width;
9027 SettingManager.Local.Width5 = lst.Columns[4].Width;
9028 SettingManager.Local.Width6 = lst.Columns[5].Width;
9029 SettingManager.Local.Width7 = lst.Columns[6].Width;
9030 SettingManager.Local.Width8 = lst.Columns[7].Width;
9032 this.MarkSettingLocalModified();
9033 this.isColumnChanged = true;
9036 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
9038 var lst = (DetailsListView)sender;
9039 if (SettingManager.Local == null) return;
9041 var modified = false;
9044 if (SettingManager.Local.Width1 != lst.Columns[0].Width)
9046 SettingManager.Local.Width1 = lst.Columns[0].Width;
9049 if (SettingManager.Local.Width3 != lst.Columns[1].Width)
9051 SettingManager.Local.Width3 = lst.Columns[1].Width;
9057 if (SettingManager.Local.Width1 != lst.Columns[0].Width)
9059 SettingManager.Local.Width1 = lst.Columns[0].Width;
9062 if (SettingManager.Local.Width2 != lst.Columns[1].Width)
9064 SettingManager.Local.Width2 = lst.Columns[1].Width;
9067 if (SettingManager.Local.Width3 != lst.Columns[2].Width)
9069 SettingManager.Local.Width3 = lst.Columns[2].Width;
9072 if (SettingManager.Local.Width4 != lst.Columns[3].Width)
9074 SettingManager.Local.Width4 = lst.Columns[3].Width;
9077 if (SettingManager.Local.Width5 != lst.Columns[4].Width)
9079 SettingManager.Local.Width5 = lst.Columns[4].Width;
9082 if (SettingManager.Local.Width6 != lst.Columns[5].Width)
9084 SettingManager.Local.Width6 = lst.Columns[5].Width;
9087 if (SettingManager.Local.Width7 != lst.Columns[6].Width)
9089 SettingManager.Local.Width7 = lst.Columns[6].Width;
9092 if (SettingManager.Local.Width8 != lst.Columns[7].Width)
9094 SettingManager.Local.Width8 = lst.Columns[7].Width;
9100 this.MarkSettingLocalModified();
9101 this.isColumnChanged = true;
9105 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
9107 if (this.StatusText.Multiline) this.mySpDis2 = this.StatusText.Height;
9108 this.MarkSettingLocalModified();
9111 private void TweenMain_DragDrop(object sender, DragEventArgs e)
9113 if (e.Data.GetDataPresent(DataFormats.FileDrop))
9115 if (!e.Data.GetDataPresent(DataFormats.Html, false)) // WebBrowserコントロールからの絵文字画像Drag&Dropは弾く
9117 this.SelectMedia_DragDrop(e);
9120 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
9122 var (url, title) = GetUrlFromDataObject(e.Data);
9128 appendText = title + " " + url;
9130 if (this.StatusText.TextLength == 0)
9131 this.StatusText.Text = appendText;
9133 this.StatusText.Text += " " + appendText;
9135 else if (e.Data.GetDataPresent(DataFormats.UnicodeText))
9137 var text = (string)e.Data.GetData(DataFormats.UnicodeText);
9139 this.StatusText.Text += text;
9141 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
9143 var data = (string)e.Data.GetData(DataFormats.StringFormat, true);
9144 if (data != null) this.StatusText.Text += data;
9149 /// IDataObject から URL とタイトルの対を取得します
9152 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
9154 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
9155 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
9156 internal static (string Url, string? Title) GetUrlFromDataObject(IDataObject data)
9158 if (data.GetDataPresent("text/x-moz-url"))
9160 // Firefox, Google Chrome で利用可能
9161 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
9163 using var stream = (MemoryStream)data.GetData("text/x-moz-url");
9164 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
9165 if (lines.Length < 2)
9166 throw new ArgumentException("不正な text/x-moz-url フォーマットです", nameof(data));
9168 return (lines[0], lines[1]);
9170 else if (data.GetDataPresent("IESiteModeToUrl"))
9172 // Internet Exproler 用
9173 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
9175 using var stream = (MemoryStream)data.GetData("IESiteModeToUrl");
9176 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
9177 if (lines.Length < 2)
9178 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", nameof(data));
9180 return (lines[0], lines[1]);
9182 else if (data.GetDataPresent("UniformResourceLocatorW"))
9186 using var stream = (MemoryStream)data.GetData("UniformResourceLocatorW");
9187 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
9191 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
9194 private void TweenMain_DragEnter(object sender, DragEventArgs e)
9196 if (e.Data.GetDataPresent(DataFormats.FileDrop))
9198 if (!e.Data.GetDataPresent(DataFormats.Html, false)) // WebBrowserコントロールからの絵文字画像Drag&Dropは弾く
9200 this.SelectMedia_DragEnter(e);
9204 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
9206 e.Effect = DragDropEffects.Copy;
9209 else if (e.Data.GetDataPresent(DataFormats.UnicodeText))
9211 e.Effect = DragDropEffects.Copy;
9214 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
9216 e.Effect = DragDropEffects.Copy;
9220 e.Effect = DragDropEffects.None;
9223 private void TweenMain_DragOver(object sender, DragEventArgs e)
9227 public bool IsNetworkAvailable()
9229 var nw = MyCommon.IsNetworkAvailable();
9230 this.myStatusOnline = nw;
9234 public async Task OpenUriAsync(Uri uri, bool isReverseSettings = false)
9236 var uriStr = uri.AbsoluteUri;
9238 // OpenTween 内部で使用する URL
9239 if (uri.Authority == "opentween")
9241 await this.OpenInternalUriAsync(uri);
9245 // ハッシュタグを含む Twitter 検索
9246 if (uri.Host == "twitter.com" && uri.AbsolutePath == "/search" && uri.Query.Contains("q=%23"))
9249 var unescapedQuery = Uri.UnescapeDataString(uri.Query);
9250 var pos = unescapedQuery.IndexOf('#');
9251 if (pos == -1) return;
9253 var hash = unescapedQuery.Substring(pos);
9254 this.HashSupl.AddItem(hash);
9255 this.HashMgr.AddHashToHistory(hash.Trim(), false);
9256 this.AddNewTabForSearch(hash);
9261 // フラグが立っている場合は設定と逆の動作をする
9262 if (SettingManager.Common.OpenUserTimeline && !isReverseSettings ||
9263 !SettingManager.Common.OpenUserTimeline && isReverseSettings)
9265 var userUriMatch = Regex.Match(uriStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
9266 if (userUriMatch.Success)
9268 var screenName = userUriMatch.Groups["ScreenName"].Value;
9269 if (this.IsTwitterId(screenName))
9271 await this.AddNewTabForUserTimeline(screenName);
9278 await MyCommon.OpenInBrowserAsync(this, uriStr);
9282 /// OpenTween 内部の機能を呼び出すための URL を開きます
9284 private async Task OpenInternalUriAsync(Uri uri)
9286 // ツイートを開く (//opentween/status/:status_id)
9287 var match = Regex.Match(uri.AbsolutePath, @"^/status/(\d+)$");
9290 var statusId = long.Parse(match.Groups[1].Value);
9291 await this.OpenRelatedTab(statusId);
9296 private void ListTabSelect(TabPage tab)
9298 this.SetListProperty();
9300 this.PurgeListViewItemCache();
9302 this.statuses.SelectTab(tab.Text);
9304 var listView = this.CurrentListView;
9306 this.anchorPost = null;
9307 this.anchorFlag = false;
9311 listView.Columns[1].Text = this.columnText[2];
9315 for (var i = 0; i < listView.Columns.Count; i++)
9317 listView.Columns[i].Text = this.columnText[i];
9322 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
9323 => this.ListTabSelect(e.TabPage);
9325 private void SelectListItem(DetailsListView lView, int index)
9328 var bnd = new Rectangle();
9330 var item = lView.FocusedItem;
9339 lView.SelectedIndices.Clear();
9341 while (lView.SelectedIndices.Count > 0);
9342 item = lView.Items[index];
9343 item.Selected = true;
9344 item.Focused = true;
9346 if (flg) lView.Invalidate(bnd);
9349 private void SelectListItem(DetailsListView lView, int[]? index, int focusedIndex, int selectionMarkIndex)
9352 var bnd = new Rectangle();
9354 var item = lView.FocusedItem;
9363 lView.SelectItems(index);
9365 if (selectionMarkIndex > -1 && lView.VirtualListSize > selectionMarkIndex)
9367 lView.SelectionMark = selectionMarkIndex;
9369 if (focusedIndex > -1 && lView.VirtualListSize > focusedIndex)
9371 lView.Items[focusedIndex].Focused = true;
9373 else if (index != null && index.Length != 0)
9375 lView.Items[index.Last()].Focused = true;
9378 if (flg) lView.Invalidate(bnd);
9381 private async void TweenMain_Shown(object sender, EventArgs e)
9383 this.NotifyIcon1.Visible = true;
9385 if (this.IsNetworkAvailable())
9387 var loadTasks = new List<Task>
9389 this.RefreshMuteUserIdsAsync(),
9390 this.RefreshBlockIdsAsync(),
9391 this.RefreshNoRetweetIdsAsync(),
9392 this.RefreshTwitterConfigurationAsync(),
9393 this.RefreshTabAsync<HomeTabModel>(),
9394 this.RefreshTabAsync<MentionsTabModel>(),
9395 this.RefreshTabAsync<DirectMessagesTabModel>(),
9396 this.RefreshTabAsync<PublicSearchTabModel>(),
9397 this.RefreshTabAsync<UserTimelineTabModel>(),
9398 this.RefreshTabAsync<ListTimelineTabModel>(),
9401 if (SettingManager.Common.StartupFollowers)
9402 loadTasks.Add(this.RefreshFollowerIdsAsync());
9404 if (SettingManager.Common.GetFav)
9405 loadTasks.Add(this.RefreshTabAsync<FavoritesTabModel>());
9407 var allTasks = Task.WhenAll(loadTasks);
9412 var timeout = Task.Delay(5000);
9413 if (await Task.WhenAny(allTasks, timeout) != timeout)
9417 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
9419 if (MyCommon.EndingFlag)
9423 if (MyCommon.EndingFlag) return;
9425 if (ApplicationSettings.VersionInfoUrl != null)
9427 // バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
9428 if (SettingManager.Common.StartupVersion)
9429 await this.CheckNewVersion(true);
9433 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
9434 this.VerUpMenuItem.Enabled = false;
9435 this.VerUpMenuItem.Available = false;
9436 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
9439 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
9440 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
9442 MessageBox.Show(Properties.Resources.ReAuthorizeText);
9443 this.SettingStripMenuItem_Click(this.SettingStripMenuItem, EventArgs.Empty);
9447 var reloadTasks = new List<Task>();
9449 if (!this.tw.GetFollowersSuccess && SettingManager.Common.StartupFollowers)
9450 reloadTasks.Add(this.RefreshFollowerIdsAsync());
9452 if (!this.tw.GetNoRetweetSuccess)
9453 reloadTasks.Add(this.RefreshNoRetweetIdsAsync());
9455 if (this.tw.Configuration.PhotoSizeLimit == 0)
9456 reloadTasks.Add(this.RefreshTwitterConfigurationAsync());
9458 await Task.WhenAll(reloadTasks);
9461 this.initial = false;
9463 this.timelineScheduler.Enabled = true;
9466 private async Task DoGetFollowersMenu()
9468 await this.RefreshFollowerIdsAsync();
9469 this.DispSelectedPost(true);
9472 private async void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
9473 => await this.DoGetFollowersMenu();
9475 private void ReTweetUnofficialStripMenuItem_Click(object sender, EventArgs e)
9476 => this.DoReTweetUnofficial();
9478 private async Task DoReTweetOfficial(bool isConfirm)
9481 if (this.ExistCurrentPost)
9483 var selectedPosts = this.CurrentTab.SelectedPosts;
9485 if (selectedPosts.Any(x => !x.CanRetweetBy(this.twitterApi.CurrentUserId)))
9487 if (selectedPosts.Any(x => x.IsProtect))
9488 MessageBox.Show("Protected.");
9490 this.doFavRetweetFlags = false;
9494 if (selectedPosts.Length > 15)
9496 MessageBox.Show(Properties.Resources.RetweetLimitText);
9497 this.doFavRetweetFlags = false;
9500 else if (selectedPosts.Length > 1)
9502 var questionText = Properties.Resources.RetweetQuestion2;
9503 if (this.doFavRetweetFlags) questionText = Properties.Resources.FavoriteRetweetQuestionText1;
9504 switch (MessageBox.Show(questionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
9506 case DialogResult.Cancel:
9507 case DialogResult.No:
9508 this.doFavRetweetFlags = false;
9514 if (!SettingManager.Common.RetweetNoConfirm)
9516 var questiontext = Properties.Resources.RetweetQuestion1;
9517 if (this.doFavRetweetFlags) questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
9518 if (isConfirm && MessageBox.Show(questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
9520 this.doFavRetweetFlags = false;
9526 var statusIds = selectedPosts.Select(x => x.StatusId).ToList();
9528 await this.RetweetAsync(statusIds);
9532 private async void ReTweetStripMenuItem_Click(object sender, EventArgs e)
9533 => await this.DoReTweetOfficial(true);
9535 private async Task FavoritesRetweetOfficial()
9537 if (!this.ExistCurrentPost) return;
9538 this.doFavRetweetFlags = true;
9539 var retweetTask = this.DoReTweetOfficial(true);
9540 if (this.doFavRetweetFlags)
9542 this.doFavRetweetFlags = false;
9543 var favoriteTask = this.FavoriteChange(true, false);
9545 await Task.WhenAll(retweetTask, favoriteTask);
9553 private async Task FavoritesRetweetUnofficial()
9555 var post = this.CurrentPost;
9556 if (this.ExistCurrentPost && post != null && !post.IsDm)
9558 this.doFavRetweetFlags = true;
9559 var favoriteTask = this.FavoriteChange(true);
9560 if (!post.IsProtect && this.doFavRetweetFlags)
9562 this.doFavRetweetFlags = false;
9563 this.DoReTweetUnofficial();
9571 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
9573 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
9574 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
9575 /// <returns>復元されたツイート本文</returns>
9576 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
9578 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
9581 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
9583 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
9585 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
9587 statusHtml = Regex.Replace(statusHtml, "<img class=\"emoji\" src=\".+?\" alt=\"(?<text>.+?)\" />", "${text}");
9591 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
9593 statusHtml = statusHtml.Replace("<br>", " ");
9595 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
9596 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
9597 statusHtml = statusHtml.Replace(" ", " ");
9599 return WebUtility.HtmlDecode(statusHtml);
9602 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
9604 this.tweetDetailsView.DumpPostClass = this.DumpPostClassToolStripMenuItem.Checked;
9606 if (this.CurrentPost != null)
9607 this.DispSelectedPost(true);
9610 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
9612 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
9613 this.DebugModeToolStripMenuItem.Visible = true;
9615 this.DebugModeToolStripMenuItem.Visible = false;
9618 private void UrlMultibyteSplitMenuItem_CheckedChanged(object sender, EventArgs e)
9619 => this.urlMultibyteSplit = ((ToolStripMenuItem)sender).Checked;
9621 private void PreventSmsCommandMenuItem_CheckedChanged(object sender, EventArgs e)
9622 => this.preventSmsCommand = ((ToolStripMenuItem)sender).Checked;
9624 private void UrlAutoShortenMenuItem_CheckedChanged(object sender, EventArgs e)
9625 => SettingManager.Common.UrlConvertAuto = ((ToolStripMenuItem)sender).Checked;
9627 private void IdeographicSpaceToSpaceMenuItem_Click(object sender, EventArgs e)
9629 SettingManager.Common.WideSpaceConvert = ((ToolStripMenuItem)sender).Checked;
9630 this.MarkSettingCommonModified();
9633 private void FocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
9635 SettingManager.Common.FocusLockToStatusText = ((ToolStripMenuItem)sender).Checked;
9636 this.MarkSettingCommonModified();
9639 private void PostModeMenuItem_DropDownOpening(object sender, EventArgs e)
9641 this.UrlMultibyteSplitMenuItem.Checked = this.urlMultibyteSplit;
9642 this.PreventSmsCommandMenuItem.Checked = this.preventSmsCommand;
9643 this.UrlAutoShortenMenuItem.Checked = SettingManager.Common.UrlConvertAuto;
9644 this.IdeographicSpaceToSpaceMenuItem.Checked = SettingManager.Common.WideSpaceConvert;
9645 this.MultiLineMenuItem.Checked = SettingManager.Local.StatusMultiline;
9646 this.FocusLockMenuItem.Checked = SettingManager.Common.FocusLockToStatusText;
9649 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
9651 this.UrlMultibyteSplitPullDownMenuItem.Checked = this.urlMultibyteSplit;
9652 this.PreventSmsCommandPullDownMenuItem.Checked = this.preventSmsCommand;
9653 this.UrlAutoShortenPullDownMenuItem.Checked = SettingManager.Common.UrlConvertAuto;
9654 this.IdeographicSpaceToSpacePullDownMenuItem.Checked = SettingManager.Common.WideSpaceConvert;
9655 this.MultiLinePullDownMenuItem.Checked = SettingManager.Local.StatusMultiline;
9656 this.FocusLockPullDownMenuItem.Checked = SettingManager.Common.FocusLockToStatusText;
9659 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
9661 if (this.TraceOutToolStripMenuItem.Checked)
9662 MyCommon.TraceFlag = true;
9664 MyCommon.TraceFlag = false;
9667 private void TweenMain_Deactivate(object sender, EventArgs e)
9668 => this.StatusText_Leave(this.StatusText, EventArgs.Empty); // 画面が非アクティブになったら、発言欄の背景色をデフォルトへ
9670 private void TabRenameMenuItem_Click(object sender, EventArgs e)
9672 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
9674 _ = this.TabRename(this.rclickTabName, out _);
9677 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
9678 => await this.UrlConvertAsync(MyCommon.UrlConverter.Bitly);
9680 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
9681 => await this.UrlConvertAsync(MyCommon.UrlConverter.Jmp);
9683 private async void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
9685 TwitterApiStatus? apiStatus;
9687 using (var dialog = new WaitingDialog(Properties.Resources.ApiInfo6))
9689 var cancellationToken = dialog.EnableCancellation();
9693 var task = this.tw.GetInfoApi();
9694 apiStatus = await dialog.WaitForAsync(this, task);
9696 catch (WebApiException)
9701 if (cancellationToken.IsCancellationRequested)
9704 if (apiStatus == null)
9706 MessageBox.Show(Properties.Resources.ApiInfo5, Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
9711 using var apiDlg = new ApiInfoDialog();
9712 apiDlg.ShowDialog(this);
9715 private async void FollowCommandMenuItem_Click(object sender, EventArgs e)
9717 var id = this.CurrentPost?.ScreenName ?? "";
9719 await this.FollowCommand(id);
9722 internal async Task FollowCommand(string id)
9724 using (var inputName = new InputTabName())
9726 inputName.FormTitle = "Follow";
9727 inputName.FormDescription = Properties.Resources.FRMessage1;
9728 inputName.TabName = id;
9730 if (inputName.ShowDialog(this) != DialogResult.OK)
9732 if (string.IsNullOrWhiteSpace(inputName.TabName))
9735 id = inputName.TabName.Trim();
9738 using (var dialog = new WaitingDialog(Properties.Resources.FollowCommandText1))
9742 var task = this.twitterApi.FriendshipsCreate(id).IgnoreResponse();
9743 await dialog.WaitForAsync(this, task);
9745 catch (WebApiException ex)
9747 MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
9752 MessageBox.Show(Properties.Resources.FRMessage3);
9755 private async void RemoveCommandMenuItem_Click(object sender, EventArgs e)
9757 var id = this.CurrentPost?.ScreenName ?? "";
9759 await this.RemoveCommand(id, false);
9762 internal async Task RemoveCommand(string id, bool skipInput)
9766 using var inputName = new InputTabName();
9767 inputName.FormTitle = "Unfollow";
9768 inputName.FormDescription = Properties.Resources.FRMessage1;
9769 inputName.TabName = id;
9771 if (inputName.ShowDialog(this) != DialogResult.OK)
9773 if (string.IsNullOrWhiteSpace(inputName.TabName))
9776 id = inputName.TabName.Trim();
9779 using (var dialog = new WaitingDialog(Properties.Resources.RemoveCommandText1))
9783 var task = this.twitterApi.FriendshipsDestroy(id).IgnoreResponse();
9784 await dialog.WaitForAsync(this, task);
9786 catch (WebApiException ex)
9788 MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
9793 MessageBox.Show(Properties.Resources.FRMessage3);
9796 private async void FriendshipMenuItem_Click(object sender, EventArgs e)
9798 var id = this.CurrentPost?.ScreenName ?? "";
9800 await this.ShowFriendship(id);
9803 internal async Task ShowFriendship(string id)
9805 using (var inputName = new InputTabName())
9807 inputName.FormTitle = "Show Friendships";
9808 inputName.FormDescription = Properties.Resources.FRMessage1;
9809 inputName.TabName = id;
9811 if (inputName.ShowDialog(this) != DialogResult.OK)
9813 if (string.IsNullOrWhiteSpace(inputName.TabName))
9816 id = inputName.TabName.Trim();
9819 bool isFollowing, isFollowed;
9821 using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
9823 var cancellationToken = dialog.EnableCancellation();
9827 var task = this.twitterApi.FriendshipsShow(this.twitterApi.CurrentScreenName, id);
9828 var friendship = await dialog.WaitForAsync(this, task);
9830 isFollowing = friendship.Relationship.Source.Following;
9831 isFollowed = friendship.Relationship.Source.FollowedBy;
9833 catch (WebApiException ex)
9835 if (!cancellationToken.IsCancellationRequested)
9836 MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
9840 if (cancellationToken.IsCancellationRequested)
9847 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
9851 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
9855 result += Properties.Resources.GetFriendshipInfo3;
9859 result += Properties.Resources.GetFriendshipInfo4;
9861 result = id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
9862 MessageBox.Show(result);
9865 internal async Task ShowFriendship(string[] ids)
9867 foreach (var id in ids)
9869 bool isFollowing, isFollowed;
9871 using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
9873 var cancellationToken = dialog.EnableCancellation();
9877 var task = this.twitterApi.FriendshipsShow(this.twitterApi.CurrentScreenName, id);
9878 var friendship = await dialog.WaitForAsync(this, task);
9880 isFollowing = friendship.Relationship.Source.Following;
9881 isFollowed = friendship.Relationship.Source.FollowedBy;
9883 catch (WebApiException ex)
9885 if (!cancellationToken.IsCancellationRequested)
9886 MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
9890 if (cancellationToken.IsCancellationRequested)
9900 ff += Properties.Resources.GetFriendshipInfo1;
9904 ff += Properties.Resources.GetFriendshipInfo2;
9907 ff += System.Environment.NewLine + " ";
9910 ff += Properties.Resources.GetFriendshipInfo3;
9914 ff += Properties.Resources.GetFriendshipInfo4;
9916 result += id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
9919 if (MessageBox.Show(
9920 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result,
9921 Properties.Resources.GetFriendshipInfo8,
9922 MessageBoxButtons.YesNo,
9923 MessageBoxIcon.Question,
9924 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
9926 await this.RemoveCommand(id, true);
9931 MessageBox.Show(result);
9936 private async void OwnStatusMenuItem_Click(object sender, EventArgs e)
9937 => await this.DoShowUserStatus(this.tw.Username, false);
9939 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
9942 public bool IsTwitterId(string name)
9944 if (this.tw.Configuration.NonUsernamePaths == null || this.tw.Configuration.NonUsernamePaths.Length == 0)
9945 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
9947 return !this.tw.Configuration.NonUsernamePaths.Contains(name, StringComparer.InvariantCultureIgnoreCase);
9950 private void DoQuoteOfficial()
9952 var post = this.CurrentPost;
9953 if (this.ExistCurrentPost && post != null)
9955 if (post.IsDm || !this.StatusText.Enabled)
9960 MessageBox.Show("Protected.");
9964 var selection = (this.StatusText.SelectionStart, this.StatusText.SelectionLength);
9966 this.inReplyTo = null;
9968 this.StatusText.Text += " " + MyCommon.GetStatusUrl(post);
9970 (this.StatusText.SelectionStart, this.StatusText.SelectionLength) = selection;
9971 this.StatusText.Focus();
9975 private void DoReTweetUnofficial()
9978 var post = this.CurrentPost;
9979 if (this.ExistCurrentPost && post != null)
9981 if (post.IsDm || !this.StatusText.Enabled)
9986 MessageBox.Show("Protected.");
9989 var rtdata = post.Text;
9990 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
9992 var selection = (this.StatusText.SelectionStart, this.StatusText.SelectionLength);
9994 // 投稿時に in_reply_to_status_id を付加する
9995 var inReplyToStatusId = post.RetweetedId ?? post.StatusId;
9996 var inReplyToScreenName = post.ScreenName;
9997 this.inReplyTo = (inReplyToStatusId, inReplyToScreenName);
9999 this.StatusText.Text += " RT @" + post.ScreenName + ": " + rtdata;
10001 (this.StatusText.SelectionStart, this.StatusText.SelectionLength) = selection;
10002 this.StatusText.Focus();
10006 private void QuoteStripMenuItem_Click(object sender, EventArgs e)
10007 => this.DoQuoteOfficial();
10009 private async void SearchButton_Click(object sender, EventArgs e)
10012 var pnl = ((Control)sender).Parent;
10013 if (pnl == null) return;
10014 var tbName = pnl.Parent.Text;
10015 var tb = (PublicSearchTabModel)this.statuses.Tabs[tbName];
10016 var cmb = (ComboBox)pnl.Controls["comboSearch"];
10017 var cmbLang = (ComboBox)pnl.Controls["comboLang"];
10018 cmb.Text = cmb.Text.Trim();
10019 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
10021 var buf = new StringBuilder();
10022 var c = cmb.Text.ToCharArray();
10023 for (var cnt = 0; cnt < cmb.Text.Length; cnt++)
10025 if (cnt > cmb.Text.Length - 4)
10027 buf.Append(cmb.Text.Substring(cnt));
10036 if (!quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
10038 buf.Append(" OR ");
10043 buf.Append(c[cnt]);
10045 cmb.Text = buf.ToString();
10047 var listView = (DetailsListView)pnl.Parent.Tag;
10049 var queryChanged = tb.SearchWords != cmb.Text || tb.SearchLang != cmbLang.Text;
10051 tb.SearchWords = cmb.Text;
10052 tb.SearchLang = cmbLang.Text;
10053 if (MyCommon.IsNullOrEmpty(cmb.Text))
10056 this.SaveConfigsTabs();
10061 var idx = cmb.Items.IndexOf(tb.SearchWords);
10062 if (idx > -1) cmb.Items.RemoveAt(idx);
10063 cmb.Items.Insert(0, tb.SearchWords);
10064 cmb.Text = tb.SearchWords;
10066 this.PurgeListViewItemCache();
10067 listView.VirtualListSize = 0;
10068 this.statuses.ClearTabIds(tbName);
10069 this.SaveConfigsTabs(); // 検索条件の保存
10073 await this.RefreshTabAsync(tb);
10076 private async void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
10077 => await this.DoRefreshMore(); // もっと前を取得
10080 /// 指定されたタブのListTabにおける位置を返します
10083 /// 非表示のタブについて -1 が返ることを常に考慮して下さい
10085 public int GetTabPageIndex(string tabName)
10086 => this.statuses.Tabs.IndexOf(tabName);
10088 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
10090 if (this.statuses.RemovedTab.Count == 0)
10092 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
10097 DetailsListView? listView;
10099 var tb = this.statuses.RemovedTab.Pop();
10100 if (tb.TabType == MyCommon.TabUsageType.Related)
10102 var relatedTab = this.statuses.GetTabByType(MyCommon.TabUsageType.Related);
10103 if (relatedTab != null)
10105 // 関連発言なら既存のタブを置き換える
10106 tb.TabName = relatedTab.TabName;
10107 this.ClearTab(tb.TabName, false);
10109 this.statuses.ReplaceTab(tb);
10111 var tabIndex = this.statuses.Tabs.IndexOf(tb);
10112 var tabPage = this.ListTab.TabPages[tabIndex];
10113 listView = (DetailsListView)tabPage.Tag;
10114 this.ListTab.SelectedIndex = tabIndex;
10118 const string TabName = "Related Tweets";
10119 var renamed = TabName;
10120 for (var i = 2; i <= 100; i++)
10122 if (!this.statuses.ContainsTab(renamed))
10124 renamed = TabName + i;
10126 tb.TabName = renamed;
10128 this.statuses.AddTab(tb);
10129 this.AddNewTab(tb, startup: false);
10131 var tabIndex = this.statuses.Tabs.Count - 1;
10132 var tabPage = this.ListTab.TabPages[tabIndex];
10134 listView = (DetailsListView)tabPage.Tag;
10135 this.ListTab.SelectedIndex = tabIndex;
10140 var renamed = tb.TabName;
10141 for (var i = 1; i < int.MaxValue; i++)
10143 if (!this.statuses.ContainsTab(renamed))
10145 renamed = tb.TabName + "(" + i + ")";
10147 tb.TabName = renamed;
10149 this.statuses.AddTab(tb);
10150 this.AddNewTab(tb, startup: false);
10152 var tabIndex = this.statuses.Tabs.Count - 1;
10153 var tabPage = this.ListTab.TabPages[tabIndex];
10155 listView = (DetailsListView)tabPage.Tag;
10156 this.ListTab.SelectedIndex = tabIndex;
10158 this.SaveConfigsTabs();
10160 if (listView != null)
10162 using (ControlTransaction.Update(listView))
10164 listView.VirtualListSize = tb.AllCount;
10170 private async Task DoMoveToRTHome()
10172 var post = this.CurrentPost;
10173 if (post != null && post.RetweetedId != null)
10174 await MyCommon.OpenInBrowserAsync(this, "https://twitter.com/" + post.RetweetedBy);
10177 private async void RetweetedByOpenInBrowserMenuItem_Click(object sender, EventArgs e)
10178 => await this.DoMoveToRTHome();
10180 private void AuthorListManageMenuItem_Click(object sender, EventArgs e)
10182 var screenName = this.CurrentPost?.ScreenName;
10183 if (screenName != null)
10184 this.ListManageUserContext(screenName);
10187 private void RetweetedByListManageMenuItem_Click(object sender, EventArgs e)
10189 var screenName = this.CurrentPost?.RetweetedBy;
10190 if (screenName != null)
10191 this.ListManageUserContext(screenName);
10194 public void ListManageUserContext(string screenName)
10196 using var listSelectForm = new MyLists(screenName, this.twitterApi);
10197 listSelectForm.ShowDialog(this);
10200 private void SearchControls_Enter(object sender, EventArgs e)
10202 var pnl = (Control)sender;
10203 foreach (Control ctl in pnl.Controls)
10205 ctl.TabStop = true;
10209 private void SearchControls_Leave(object sender, EventArgs e)
10211 var pnl = (Control)sender;
10212 foreach (Control ctl in pnl.Controls)
10214 ctl.TabStop = false;
10218 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
10220 var tab = this.CurrentTab;
10221 if (tab.TabType != MyCommon.TabUsageType.PublicSearch) return;
10222 this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus();
10225 private void StatusLabel_DoubleClick(object sender, EventArgs e)
10226 => MessageBox.Show(this.StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
10228 private void HashManageMenuItem_Click(object sender, EventArgs e)
10233 rslt = this.HashMgr.ShowDialog();
10239 this.TopMost = SettingManager.Common.AlwaysTop;
10240 if (rslt == DialogResult.Cancel) return;
10241 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
10243 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
10244 this.HashTogglePullDownMenuItem.Checked = true;
10245 this.HashToggleMenuItem.Checked = true;
10249 this.HashStripSplitButton.Text = "#[-]";
10250 this.HashTogglePullDownMenuItem.Checked = false;
10251 this.HashToggleMenuItem.Checked = false;
10254 this.MarkSettingCommonModified();
10255 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
10258 private void HashToggleMenuItem_Click(object sender, EventArgs e)
10260 this.HashMgr.ToggleHash();
10261 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
10263 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
10264 this.HashToggleMenuItem.Checked = true;
10265 this.HashTogglePullDownMenuItem.Checked = true;
10269 this.HashStripSplitButton.Text = "#[-]";
10270 this.HashToggleMenuItem.Checked = false;
10271 this.HashTogglePullDownMenuItem.Checked = false;
10273 this.MarkSettingCommonModified();
10274 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
10277 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
10278 => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty);
10280 public void SetPermanentHashtag(string hashtag)
10282 this.HashMgr.SetPermanentHash("#" + hashtag);
10283 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
10284 this.HashTogglePullDownMenuItem.Checked = true;
10285 this.HashToggleMenuItem.Checked = true;
10287 this.MarkSettingCommonModified();
10290 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
10292 var tab = this.CurrentTab;
10293 var post = this.CurrentPost;
10294 if (!this.ExistCurrentPost)
10296 this.ReplyOpMenuItem.Enabled = false;
10297 this.ReplyAllOpMenuItem.Enabled = false;
10298 this.DmOpMenuItem.Enabled = false;
10299 this.CreateTabRuleOpMenuItem.Enabled = false;
10300 this.CreateIdRuleOpMenuItem.Enabled = false;
10301 this.CreateSourceRuleOpMenuItem.Enabled = false;
10302 this.ReadOpMenuItem.Enabled = false;
10303 this.UnreadOpMenuItem.Enabled = false;
10304 this.AuthorMenuItem.Visible = false;
10305 this.RetweetedByMenuItem.Visible = false;
10309 this.ReplyOpMenuItem.Enabled = true;
10310 this.ReplyAllOpMenuItem.Enabled = true;
10311 this.DmOpMenuItem.Enabled = true;
10312 this.CreateTabRuleOpMenuItem.Enabled = true;
10313 this.CreateIdRuleOpMenuItem.Enabled = true;
10314 this.CreateSourceRuleOpMenuItem.Enabled = true;
10315 this.ReadOpMenuItem.Enabled = true;
10316 this.UnreadOpMenuItem.Enabled = true;
10317 this.AuthorMenuItem.Visible = true;
10318 this.AuthorMenuItem.Text = $"@{post!.ScreenName}";
10319 this.RetweetedByMenuItem.Visible = post.RetweetedByUserId != null;
10320 this.RetweetedByMenuItem.Text = $"@{post.RetweetedBy}";
10323 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
10325 this.FavOpMenuItem.Enabled = false;
10326 this.UnFavOpMenuItem.Enabled = false;
10327 this.OpenStatusOpMenuItem.Enabled = false;
10328 this.ShowRelatedStatusesMenuItem2.Enabled = false;
10329 this.RtOpMenuItem.Enabled = false;
10330 this.RtUnOpMenuItem.Enabled = false;
10331 this.QtOpMenuItem.Enabled = false;
10332 this.FavoriteRetweetMenuItem.Enabled = false;
10333 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
10337 this.FavOpMenuItem.Enabled = true;
10338 this.UnFavOpMenuItem.Enabled = true;
10339 this.OpenStatusOpMenuItem.Enabled = true;
10340 this.ShowRelatedStatusesMenuItem2.Enabled = true; // PublicSearchの時問題出るかも
10342 if (!post.CanRetweetBy(this.twitterApi.CurrentUserId))
10344 this.RtOpMenuItem.Enabled = false;
10345 this.RtUnOpMenuItem.Enabled = false;
10346 this.QtOpMenuItem.Enabled = false;
10347 this.FavoriteRetweetMenuItem.Enabled = false;
10348 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
10352 this.RtOpMenuItem.Enabled = true;
10353 this.RtUnOpMenuItem.Enabled = true;
10354 this.QtOpMenuItem.Enabled = true;
10355 this.FavoriteRetweetMenuItem.Enabled = true;
10356 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
10360 if (tab.TabType != MyCommon.TabUsageType.Favorites)
10362 this.RefreshPrevOpMenuItem.Enabled = true;
10366 this.RefreshPrevOpMenuItem.Enabled = false;
10368 if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
10370 this.OpenRepSourceOpMenuItem.Enabled = false;
10374 this.OpenRepSourceOpMenuItem.Enabled = true;
10377 if (this.ExistCurrentPost && post != null)
10379 this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
10383 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
10384 => this.ContextMenuTabProperty_Opening(sender, null!);
10386 public Twitter TwitterInstance
10389 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
10391 if (this.initialLayout)
10394 int splitterDistance;
10395 switch (this.WindowState)
10397 case FormWindowState.Normal:
10398 splitterDistance = this.SplitContainer3.SplitterDistance;
10400 case FormWindowState.Maximized:
10401 // 最大化時は、通常時のウィンドウサイズに換算した SplitterDistance を算出する
10402 var normalContainerWidth = this.mySize.Width - SystemInformation.Border3DSize.Width * 2;
10403 splitterDistance = this.SplitContainer3.SplitterDistance - (this.SplitContainer3.Width - normalContainerWidth);
10404 splitterDistance = Math.Min(splitterDistance, normalContainerWidth - this.SplitContainer3.SplitterWidth - this.SplitContainer3.Panel2MinSize);
10410 this.mySpDis3 = splitterDistance;
10411 this.MarkSettingLocalModified();
10414 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
10416 if (this.statuses.RemovedTab.Count == 0)
10418 this.UndoRemoveTabMenuItem.Enabled = false;
10422 this.UndoRemoveTabMenuItem.Enabled = true;
10425 if (this.CurrentTab.TabType == MyCommon.TabUsageType.PublicSearch)
10426 this.PublicSearchQueryMenuItem.Enabled = true;
10428 this.PublicSearchQueryMenuItem.Enabled = false;
10430 var post = this.CurrentPost;
10431 if (!this.ExistCurrentPost || post == null)
10433 this.CopySTOTMenuItem.Enabled = false;
10434 this.CopyURLMenuItem.Enabled = false;
10435 this.CopyUserIdStripMenuItem.Enabled = false;
10439 this.CopySTOTMenuItem.Enabled = true;
10440 this.CopyURLMenuItem.Enabled = true;
10441 this.CopyUserIdStripMenuItem.Enabled = true;
10443 if (post.IsDm) this.CopyURLMenuItem.Enabled = false;
10444 if (post.IsProtect) this.CopySTOTMenuItem.Enabled = false;
10448 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
10449 => this.SetNotifyIconText();
10451 private async void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
10452 => await this.ShowUserStatus(this.CurrentPost?.ScreenName ?? "");
10454 private async Task DoShowUserStatus(string id, bool showInputDialog)
10456 TwitterUser? user = null;
10458 if (showInputDialog)
10460 using var inputName = new InputTabName();
10461 inputName.FormTitle = "Show UserStatus";
10462 inputName.FormDescription = Properties.Resources.FRMessage1;
10463 inputName.TabName = id;
10465 if (inputName.ShowDialog(this) != DialogResult.OK)
10467 if (string.IsNullOrWhiteSpace(inputName.TabName))
10470 id = inputName.TabName.Trim();
10473 using (var dialog = new WaitingDialog(Properties.Resources.doShowUserStatusText1))
10475 var cancellationToken = dialog.EnableCancellation();
10479 var task = this.twitterApi.UsersShow(id);
10480 user = await dialog.WaitForAsync(this, task);
10482 catch (WebApiException ex)
10484 if (!cancellationToken.IsCancellationRequested)
10485 MessageBox.Show($"Err:{ex.Message}(UsersShow)");
10489 if (cancellationToken.IsCancellationRequested)
10493 await this.DoShowUserStatus(user);
10496 private async Task DoShowUserStatus(TwitterUser user)
10498 using var userDialog = new UserInfoDialog(this, this.twitterApi);
10499 var showUserTask = userDialog.ShowUserAsync(user);
10500 userDialog.ShowDialog(this);
10503 this.BringToFront();
10505 // ユーザー情報の表示が完了するまで userDialog を破棄しない
10506 await showUserTask;
10509 internal Task ShowUserStatus(string id, bool showInputDialog)
10510 => this.DoShowUserStatus(id, showInputDialog);
10512 internal Task ShowUserStatus(string id)
10513 => this.DoShowUserStatus(id, true);
10515 private async void AuthorShowProfileMenuItem_Click(object sender, EventArgs e)
10517 var post = this.CurrentPost;
10520 await this.ShowUserStatus(post.ScreenName, false);
10524 private async void RetweetedByShowProfileMenuItem_Click(object sender, EventArgs e)
10526 var retweetedBy = this.CurrentPost?.RetweetedBy;
10527 if (retweetedBy != null)
10529 await this.ShowUserStatus(retweetedBy, false);
10533 private async void RtCountMenuItem_Click(object sender, EventArgs e)
10535 var post = this.CurrentPost;
10536 if (!this.ExistCurrentPost || post == null)
10539 var statusId = post.RetweetedId ?? post.StatusId;
10540 TwitterStatus status;
10542 using (var dialog = new WaitingDialog(Properties.Resources.RtCountMenuItem_ClickText1))
10544 var cancellationToken = dialog.EnableCancellation();
10548 var task = this.twitterApi.StatusesShow(statusId);
10549 status = await dialog.WaitForAsync(this, task);
10551 catch (WebApiException ex)
10553 if (!cancellationToken.IsCancellationRequested)
10554 MessageBox.Show(Properties.Resources.RtCountText2 + Environment.NewLine + "Err:" + ex.Message);
10558 if (cancellationToken.IsCancellationRequested)
10562 MessageBox.Show(status.RetweetCount + Properties.Resources.RtCountText1);
10565 private readonly HookGlobalHotkey hookGlobalHotkey;
10569 this.hookGlobalHotkey = new HookGlobalHotkey(this);
10571 // この呼び出しは、Windows フォーム デザイナで必要です。
10572 this.InitializeComponent();
10574 // InitializeComponent() 呼び出しの後で初期化を追加します。
10576 if (!this.DesignMode)
10578 // デザイナでの編集時にレイアウトが縦方向に数pxずれる問題の対策
10579 this.StatusText.Dock = DockStyle.Fill;
10582 this.tweetDetailsView.Owner = this;
10584 this.hookGlobalHotkey.HotkeyPressed += this.HookGlobalHotkey_HotkeyPressed;
10585 this.gh.NotifyClicked += this.GrowlHelper_Callback;
10587 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
10588 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
10590 this.ImageSelector.Visible = false;
10591 this.ImageSelector.Enabled = false;
10592 this.ImageSelector.FilePickDialog = this.OpenFileDialog1;
10594 this.workerProgress = new Progress<string>(x => this.StatusLabel.Text = x);
10596 this.ReplaceAppName();
10597 this.InitializeShortcuts();
10600 private void HookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
10602 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
10605 this.Visible = false;
10607 else if (Form.ActiveForm == null)
10609 this.Visible = true;
10610 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
10612 this.BringToFront();
10613 this.StatusText.Focus();
10617 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
10618 => this.MultiLinePullDownMenuItem.PerformClick();
10621 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
10623 if (this.ImageSelector.Visible)
10624 this.ImageSelector.EndSelection();
10626 this.ImageSelector.BeginSelection();
10629 private void SelectMedia_DragEnter(DragEventArgs e)
10631 if (this.ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0], true))
10633 e.Effect = DragDropEffects.Copy;
10636 e.Effect = DragDropEffects.None;
10639 private void SelectMedia_DragDrop(DragEventArgs e)
10642 this.BringToFront();
10643 this.ImageSelector.BeginSelection((string[])e.Data.GetData(DataFormats.FileDrop, false));
10644 this.StatusText.Focus();
10647 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
10649 this.TimelinePanel.Visible = false;
10650 this.TimelinePanel.Enabled = false;
10653 private void ImageSelector_EndSelecting(object sender, EventArgs e)
10655 this.TimelinePanel.Visible = true;
10656 this.TimelinePanel.Enabled = true;
10657 this.CurrentListView.Focus();
10660 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
10661 => this.AllowDrop = false;
10663 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
10664 => this.AllowDrop = true;
10666 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
10668 if (this.ImageSelector.Visible)
10670 this.MarkSettingCommonModified();
10671 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
10675 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
10676 => this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
10679 /// StatusTextでCtrl+Vが押下された時の処理
10681 private void ProcClipboardFromStatusTextWhenCtrlPlusV()
10685 if (Clipboard.ContainsText())
10687 // clipboardにテキストがある場合は貼り付け処理
10688 this.StatusText.Paste(Clipboard.GetText());
10690 else if (Clipboard.ContainsImage())
10693 if (MessageBox.Show(Properties.Resources.PostPictureConfirm3,
10694 Properties.Resources.PostPictureWarn4,
10695 MessageBoxButtons.OKCancel,
10696 MessageBoxIcon.Question,
10697 MessageBoxDefaultButton.Button2)
10698 == DialogResult.OK)
10700 // clipboardから画像を取得
10701 using var image = Clipboard.GetImage();
10702 this.ImageSelector.BeginSelection(image);
10705 else if (Clipboard.ContainsFileDropList())
10707 var files = Clipboard.GetFileDropList().Cast<string>().ToArray();
10708 this.ImageSelector.BeginSelection(files);
10711 catch (ExternalException ex)
10713 MessageBox.Show(ex.Message);
10718 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
10720 using var form = new ListManage(this.tw);
10721 form.ShowDialog(this);
10724 private bool ModifySettingCommon { get; set; }
10726 private bool ModifySettingLocal { get; set; }
10728 private bool ModifySettingAtId { get; set; }
10730 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
10732 var post = this.CurrentPost;
10733 if (this.ExistCurrentPost && post != null && !post.IsDm)
10734 this.RtCountMenuItem.Enabled = true;
10736 this.RtCountMenuItem.Enabled = false;
10739 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
10740 => this.CopyUserId();
10742 private void CopyUserId()
10744 var post = this.CurrentPost;
10745 if (post == null) return;
10746 var clstr = post.ScreenName;
10749 Clipboard.SetDataObject(clstr, false, 5, 100);
10751 catch (Exception ex)
10753 MessageBox.Show(ex.Message);
10757 private async void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e)
10759 var post = this.CurrentPost;
10760 if (this.ExistCurrentPost && post != null && !post.IsDm)
10764 await this.OpenRelatedTab(post);
10766 catch (TabException ex)
10768 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
10774 /// 指定されたツイートに対する関連発言タブを開きます
10776 /// <param name="statusId">表示するツイートのID</param>
10777 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
10778 public async Task OpenRelatedTab(long statusId)
10780 var post = this.statuses[statusId];
10785 post = await this.tw.GetStatusApi(false, statusId);
10787 catch (WebApiException ex)
10789 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
10794 await this.OpenRelatedTab(post);
10798 /// 指定されたツイートに対する関連発言タブを開きます
10800 /// <param name="post">表示する対象となるツイート</param>
10801 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
10802 private async Task OpenRelatedTab(PostClass post)
10804 var tabRelated = this.statuses.GetTabByType<RelatedPostsTabModel>();
10805 if (tabRelated != null)
10807 this.RemoveSpecifiedTab(tabRelated.TabName, confirm: false);
10810 var tabName = this.statuses.MakeTabName("Related Tweets");
10812 tabRelated = new RelatedPostsTabModel(tabName, post)
10814 UnreadManage = false,
10818 this.statuses.AddTab(tabRelated);
10819 this.AddNewTab(tabRelated, startup: false);
10821 this.ListTab.SelectedIndex = this.statuses.Tabs.IndexOf(tabName);
10823 await this.RefreshTabAsync(tabRelated);
10825 var tabIndex = this.statuses.Tabs.IndexOf(tabRelated.TabName);
10827 if (tabIndex != -1)
10829 // TODO: 非同期更新中にタブが閉じられている場合を厳密に考慮したい
10831 var tabPage = this.ListTab.TabPages[tabIndex];
10832 var listView = (DetailsListView)tabPage.Tag;
10833 var targetPost = tabRelated.TargetPost;
10834 var index = tabRelated.IndexOf(targetPost.RetweetedId ?? targetPost.StatusId);
10836 if (index != -1 && index < listView.Items.Count)
10838 listView.SelectedIndices.Add(index);
10839 listView.Items[index].Focused = true;
10844 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
10846 var buf = new StringBuilder();
10847 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, this.iconCache.CacheCount);
10848 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, this.iconCache.CacheRemoveCount);
10849 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
10852 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
10854 MyCommon.EndingFlag = true;
10858 Application.Restart();
10862 MessageBox.Show("Failed to restart. Please run " + ApplicationSettings.ApplicationName + " manually.");
10866 private async void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
10867 => await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.tw.Username);
10869 private bool ExistCurrentPost
10873 var post = this.CurrentPost;
10874 return post != null && !post.IsDeleted;
10878 private async void AuthorShowUserTimelineMenuItem_Click(object sender, EventArgs e)
10879 => await this.ShowUserTimeline();
10881 private async void RetweetedByShowUserTimelineMenuItem_Click(object sender, EventArgs e)
10882 => await this.ShowRetweeterTimeline();
10884 private string GetUserIdFromCurPostOrInput(string caption)
10886 var id = this.CurrentPost?.ScreenName ?? "";
10888 using var inputName = new InputTabName();
10889 inputName.FormTitle = caption;
10890 inputName.FormDescription = Properties.Resources.FRMessage1;
10891 inputName.TabName = id;
10893 if (inputName.ShowDialog() == DialogResult.OK &&
10894 !MyCommon.IsNullOrEmpty(inputName.TabName.Trim()))
10896 id = inputName.TabName.Trim();
10905 private async void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
10907 var id = this.GetUserIdFromCurPostOrInput("Show UserTimeline");
10908 if (!MyCommon.IsNullOrEmpty(id))
10910 await this.AddNewTabForUserTimeline(id);
10914 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
10916 if (e.Mode == Microsoft.Win32.PowerModes.Resume)
10917 this.timelineScheduler.SystemResumed();
10920 private void SystemEvents_TimeChanged(object sender, EventArgs e)
10922 var prevTimeOffset = TimeZoneInfo.Local.BaseUtcOffset;
10924 TimeZoneInfo.ClearCachedData();
10926 var curTimeOffset = TimeZoneInfo.Local.BaseUtcOffset;
10928 if (curTimeOffset != prevTimeOffset)
10931 this.PurgeListViewItemCache();
10932 this.CurrentListView.Refresh();
10934 this.DispSelectedPost(forceupdate: true);
10937 this.timelineScheduler.Reset();
10940 private void TimelineRefreshEnableChange(bool isEnable)
10942 this.timelineScheduler.Enabled = isEnable;
10945 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
10946 => this.TimelineRefreshEnableChange(!this.StopRefreshAllMenuItem.Checked);
10948 private async Task OpenUserAppointUrl()
10950 if (SettingManager.Common.UserAppointUrl != null)
10952 if (SettingManager.Common.UserAppointUrl.Contains("{ID}") || SettingManager.Common.UserAppointUrl.Contains("{STATUS}"))
10954 var post = this.CurrentPost;
10957 var xUrl = SettingManager.Common.UserAppointUrl;
10958 xUrl = xUrl.Replace("{ID}", post.ScreenName);
10960 var statusId = post.RetweetedId ?? post.StatusId;
10961 xUrl = xUrl.Replace("{STATUS}", statusId.ToString());
10963 await MyCommon.OpenInBrowserAsync(this, xUrl);
10968 await MyCommon.OpenInBrowserAsync(this, SettingManager.Common.UserAppointUrl);
10973 private async void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
10974 => await this.OpenUserAppointUrl();
10976 private async void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
10978 if (Form.ActiveForm == null)
10980 await this.InvokeAsync(() =>
10982 this.Visible = true;
10983 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
10985 this.BringToFront();
10986 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
10988 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
10992 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
10998 private void ReplaceAppName()
11000 this.MatomeMenuItem.Text = MyCommon.ReplaceAppName(this.MatomeMenuItem.Text);
11001 this.AboutMenuItem.Text = MyCommon.ReplaceAppName(this.AboutMenuItem.Text);
11004 private void TweetThumbnail_ThumbnailLoading(object sender, EventArgs e)
11005 => this.SplitContainer3.Panel2Collapsed = false;
11007 private async void TweetThumbnail_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
11008 => await this.OpenThumbnailPicture(e.Thumbnail);
11010 private async void TweetThumbnail_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
11011 => await MyCommon.OpenInBrowserAsync(this, e.ImageUrl);
11013 private async Task OpenThumbnailPicture(ThumbnailInfo thumbnail)
11015 var url = thumbnail.FullSizeImageUrl ?? thumbnail.MediaPageUrl;
11017 await MyCommon.OpenInBrowserAsync(this, url);
11020 private async void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
11021 => await MyCommon.OpenInBrowserAsync(this, Twitter.ServiceAvailabilityStatusUrl);
11023 private void PostButton_KeyDown(object sender, KeyEventArgs e)
11025 if (e.KeyCode == Keys.Space)
11027 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
11029 e.SuppressKeyPress = true;
11033 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
11035 this.IconSizeNoneToolStripMenuItem.Checked = SettingManager.Common.IconSize == MyCommon.IconSizes.IconNone;
11036 this.IconSize16ToolStripMenuItem.Checked = SettingManager.Common.IconSize == MyCommon.IconSizes.Icon16;
11037 this.IconSize24ToolStripMenuItem.Checked = SettingManager.Common.IconSize == MyCommon.IconSizes.Icon24;
11038 this.IconSize48ToolStripMenuItem.Checked = SettingManager.Common.IconSize == MyCommon.IconSizes.Icon48;
11039 this.IconSize48_2ToolStripMenuItem.Checked = SettingManager.Common.IconSize == MyCommon.IconSizes.Icon48_2;
11041 this.LockListSortOrderToolStripMenuItem.Checked = SettingManager.Common.SortOrderLock;
11044 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
11045 => this.ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
11047 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
11048 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
11050 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
11051 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
11053 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
11054 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
11056 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
11057 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
11059 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
11061 if (SettingManager.Common.IconSize == iconSize) return;
11063 var oldIconCol = this.iconCol;
11065 SettingManager.Common.IconSize = iconSize;
11066 this.ApplyListViewIconSize(iconSize);
11068 if (this.iconCol != oldIconCol)
11070 foreach (TabPage tp in this.ListTab.TabPages)
11072 this.ResetColumns((DetailsListView)tp.Tag);
11076 this.CurrentListView.Refresh();
11077 this.MarkSettingCommonModified();
11080 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
11082 var state = this.LockListSortOrderToolStripMenuItem.Checked;
11083 if (SettingManager.Common.SortOrderLock == state) return;
11085 SettingManager.Common.SortOrderLock = state;
11086 this.MarkSettingCommonModified();
11089 private void TweetDetailsView_StatusChanged(object sender, TweetDetailsViewStatusChengedEventArgs e)
11091 if (!MyCommon.IsNullOrEmpty(e.StatusText))
11093 this.StatusLabelUrl.Text = e.StatusText;
11097 this.SetStatusLabelUrl();