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.Api.TwitterV2;
56 using OpenTween.Connection;
57 using OpenTween.MediaUploadServices;
58 using OpenTween.Models;
59 using OpenTween.OpenTweenCustomControl;
60 using OpenTween.Setting;
61 using OpenTween.Thumbnail;
65 public partial class TweenMain : OTBaseForm
69 /// <summary>画面サイズ</summary>
72 /// <summary>画面位置</summary>
75 /// <summary>区切り位置</summary>
78 /// <summary>発言欄区切り位置</summary>
81 /// <summary>プレビュー区切り位置</summary>
85 private bool initial; // true:起動時処理中
86 private bool initialLayout = true;
87 private bool ignoreConfigSave; // true:起動時処理中
89 /// <summary>タブドラッグ中フラグ(DoDragDropを実行するかの判定用)</summary>
92 private TabPage? beforeSelectedTab; // タブが削除されたときに前回選択されていたときのタブを選択する為に保持
93 private Point tabMouseDownPoint;
95 /// <summary>右クリックしたタブの名前(Tabコントロール機能不足対応)</summary>
96 private string? rclickTabName;
98 private readonly object syncObject = new(); // ロック用
100 private const string DetailHtmlFormatHead =
101 "<head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\">"
102 + "<style type=\"text/css\"><!-- "
103 + "body, p, pre {margin: 0;} "
104 + "body {font-family: \"%FONT_FAMILY%\", \"Segoe UI Emoji\", sans-serif; font-size: %FONT_SIZE%pt; background-color:rgb(%BG_COLOR%); word-wrap: break-word; color:rgb(%FONT_COLOR%);} "
105 + "pre {font-family: inherit;} "
106 + "a:link, a:visited, a:active, a:hover {color:rgb(%LINK_COLOR%); } "
107 + "img.emoji {width: 1em; height: 1em; margin: 0 .05em 0 .1em; vertical-align: -0.1em; border: none;} "
108 + ".quote-tweet {border: 1px solid #ccc; margin: 1em; padding: 0.5em;} "
109 + ".quote-tweet.reply {border-color: rgb(%BG_REPLY_COLOR%);} "
110 + ".quote-tweet-link {color: inherit !important; text-decoration: none;}"
114 private const string DetailHtmlFormatTemplateMono =
115 $"<html>{DetailHtmlFormatHead}<body><pre>%CONTENT_HTML%</pre></body></html>";
117 private const string DetailHtmlFormatTemplateNormal =
118 $"<html>{DetailHtmlFormatHead}<body><p>%CONTENT_HTML%</p></body></html>";
120 private string detailHtmlFormatPreparedTemplate = null!;
122 private bool myStatusError = false;
123 private bool myStatusOnline = false;
124 private bool soundfileListup = false;
125 private FormWindowState formWindowState = FormWindowState.Normal; // フォームの状態保存用 通知領域からアイコンをクリックして復帰した際に使用する
128 private readonly SettingManager settings;
131 private readonly Twitter tw;
134 private readonly GrowlHelper gh = new(ApplicationSettings.ApplicationName);
138 /// <summary>検索画面インスタンス</summary>
139 internal SearchWordDialog SearchDialog = new();
141 private readonly OpenURL urlDialog = new();
143 /// <summary>@id補助</summary>
144 public AtIdSupplement AtIdSupl = null!;
146 /// <summary>Hashtag補助</summary>
147 public AtIdSupplement HashSupl = null!;
149 public HashtagManage HashMgr = null!;
152 private ThemeManager themeManager;
154 /// <summary>アイコン画像リスト</summary>
155 private readonly ImageCache iconCache;
157 private readonly IconAssetsManager iconAssets;
159 private readonly ThumbnailGenerator thumbGenerator;
161 /// <summary>発言履歴</summary>
162 private readonly List<StatusTextHistory> history = new();
164 /// <summary>発言履歴カレントインデックス</summary>
167 // 発言投稿時のAPI引数(発言編集時に設定。手書きreplyでは設定されない)
169 /// <summary>リプライ先のステータスID・スクリーン名</summary>
170 private (long StatusId, string ScreenName)? inReplyTo = null;
173 private readonly List<DateTimeUtc> postTimestamps = new();
174 private readonly List<DateTimeUtc> favTimestamps = new();
177 private readonly StringFormat sfTab = new();
179 //////////////////////////////////////////////////////////////////////////////////////////////////////////
181 /// <summary>発言保持クラス</summary>
182 private readonly TabInformations statuses;
184 private TimelineListViewCache? listCache;
185 private TimelineListViewDrawer? listDrawer;
186 private readonly Dictionary<string, TimelineListViewState> listViewState = new();
188 private bool isColumnChanged = false;
190 private const int MaxWorderThreads = 20;
191 private readonly SemaphoreSlim workerSemaphore = new(MaxWorderThreads);
192 private readonly CancellationTokenSource workerCts = new();
193 private readonly IProgress<string> workerProgress = null!;
195 private int unreadCounter = -1;
196 private int unreadAtCounter = -1;
198 private readonly string[] columnOrgText = new string[9];
199 private readonly string[] columnText = new string[9];
201 private bool doFavRetweetFlags = false;
203 //////////////////////////////////////////////////////////////////////////////////////////////////////////
205 private readonly TimelineScheduler timelineScheduler = new();
206 private readonly DebounceTimer selectionDebouncer;
207 private readonly DebounceTimer saveConfigDebouncer;
209 private readonly string recommendedStatusFooter;
210 private bool urlMultibyteSplit = false;
211 private bool preventSmsCommand = true;
214 private readonly record struct UrlUndo(
219 private List<UrlUndo>? urlUndoBuffer = null;
221 private readonly record struct ReplyChain(
227 /// <summary>[, ]でのリプライ移動の履歴</summary>
228 private Stack<ReplyChain>? replyChains;
230 /// <summary>ポスト選択履歴</summary>
231 private readonly Stack<(TabModel, PostClass?)> selectPostChains = new();
233 public TabModel CurrentTab
234 => this.statuses.SelectedTab;
236 public string CurrentTabName
237 => this.statuses.SelectedTabName;
239 public TabPage CurrentTabPage
240 => this.ListTab.TabPages[this.statuses.Tabs.IndexOf(this.CurrentTabName)];
242 public DetailsListView CurrentListView
243 => (DetailsListView)this.CurrentTabPage.Tag;
245 public PostClass? CurrentPost
246 => this.CurrentTab.SelectedPost;
248 public bool Use2ColumnsMode
249 => this.settings.Common.IconSize == MyCommon.IconSizes.Icon48_2;
251 /// <summary>検索処理タイプ</summary>
252 internal enum SEARCHTYPE
259 private readonly record struct StatusTextHistory(
261 (long StatusId, string ScreenName)? InReplyTo = null
264 private readonly HookGlobalHotkey hookGlobalHotkey;
266 private void TweenMain_Activated(object sender, EventArgs e)
268 // 画面がアクティブになったら、発言欄の背景色戻す
269 if (this.StatusText.Focused)
271 this.StatusText_Enter(this.StatusText, System.EventArgs.Empty);
275 private bool disposed = false;
278 /// 使用中のリソースをすべてクリーンアップします。
280 /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
281 protected override void Dispose(bool disposing)
283 base.Dispose(disposing);
290 this.components?.Dispose();
293 this.SearchDialog.Dispose();
294 this.urlDialog.Dispose();
295 this.themeManager.Dispose();
296 this.sfTab.Dispose();
298 this.timelineScheduler.Dispose();
299 this.workerCts.Cancel();
300 this.thumbnailTokenSource?.Dispose();
302 this.hookGlobalHotkey.Dispose();
305 // 終了時にRemoveHandlerしておかないとメモリリークする
306 // http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
307 Microsoft.Win32.SystemEvents.PowerModeChanged -= this.SystemEvents_PowerModeChanged;
308 Microsoft.Win32.SystemEvents.TimeChanged -= this.SystemEvents_TimeChanged;
310 this.disposed = true;
313 private void InitColumns(ListView list, bool startup)
315 this.InitColumnText();
317 ColumnHeader[]? columns = null;
320 if (this.Use2ColumnsMode)
324 new ColumnHeader(), // アイコン
325 new ColumnHeader(), // 本文
328 columns[0].Text = this.columnText[0];
329 columns[1].Text = this.columnText[2];
333 var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / this.settings.Local.ScaleDimension.Width;
335 columns[0].Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[0]);
336 columns[1].Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[2]);
337 columns[0].DisplayIndex = 0;
338 columns[1].DisplayIndex = 1;
343 foreach (var curListColumn in this.CurrentListView.Columns.Cast<ColumnHeader>())
345 columns[idx].Width = curListColumn.Width;
346 columns[idx].DisplayIndex = curListColumn.DisplayIndex;
355 new ColumnHeader(), // アイコン
356 new ColumnHeader(), // ニックネーム
357 new ColumnHeader(), // 本文
358 new ColumnHeader(), // 日付
359 new ColumnHeader(), // ユーザID
360 new ColumnHeader(), // 未読
361 new ColumnHeader(), // マーク&プロテクト
362 new ColumnHeader(), // ソース
365 foreach (var i in Enumerable.Range(0, columns.Length))
366 columns[i].Text = this.columnText[i];
370 var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / this.settings.Local.ScaleDimension.Width;
372 foreach (var (column, index) in columns.WithIndex())
374 column.Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[index]);
375 column.DisplayIndex = this.settings.Local.ColumnsOrder[index];
381 foreach (var curListColumn in this.CurrentListView.Columns.Cast<ColumnHeader>())
383 columns[idx].Width = curListColumn.Width;
384 columns[idx].DisplayIndex = curListColumn.DisplayIndex;
390 list.Columns.AddRange(columns);
398 foreach (var column in columns)
404 private void InitColumnText()
406 this.columnText[0] = "";
407 this.columnText[1] = Properties.Resources.AddNewTabText2;
408 this.columnText[2] = Properties.Resources.AddNewTabText3;
409 this.columnText[3] = Properties.Resources.AddNewTabText4_2;
410 this.columnText[4] = Properties.Resources.AddNewTabText5;
411 this.columnText[5] = "";
412 this.columnText[6] = "";
413 this.columnText[7] = "Source";
415 this.columnOrgText[0] = "";
416 this.columnOrgText[1] = Properties.Resources.AddNewTabText2;
417 this.columnOrgText[2] = Properties.Resources.AddNewTabText3;
418 this.columnOrgText[3] = Properties.Resources.AddNewTabText4_2;
419 this.columnOrgText[4] = Properties.Resources.AddNewTabText5;
420 this.columnOrgText[5] = "";
421 this.columnOrgText[6] = "";
422 this.columnOrgText[7] = "Source";
424 var c = this.statuses.SortMode switch
426 ComparerMode.Nickname => 1, // ニックネーム
427 ComparerMode.Data => 2, // 本文
428 ComparerMode.Id => 3, // 時刻=発言Id
429 ComparerMode.Name => 4, // 名前
430 ComparerMode.Source => 7, // Source
434 if (this.Use2ColumnsMode)
436 if (this.statuses.SortOrder == SortOrder.Descending)
438 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
439 this.columnText[2] = this.columnOrgText[2] + "▾";
443 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
444 this.columnText[2] = this.columnOrgText[2] + "▴";
449 if (this.statuses.SortOrder == SortOrder.Descending)
451 // U+25BE BLACK DOWN-POINTING SMALL TRIANGLE
452 this.columnText[c] = this.columnOrgText[c] + "▾";
456 // U+25B4 BLACK UP-POINTING SMALL TRIANGLE
457 this.columnText[c] = this.columnOrgText[c] + "▴";
463 SettingManager settingManager,
464 TabInformations tabInfo,
466 ImageCache imageCache,
467 IconAssetsManager iconAssets,
468 ThumbnailGenerator thumbGenerator
471 this.settings = settingManager;
472 this.statuses = tabInfo;
474 this.iconCache = imageCache;
475 this.iconAssets = iconAssets;
476 this.thumbGenerator = thumbGenerator;
478 this.InitializeComponent();
480 if (!this.DesignMode)
482 // デザイナでの編集時にレイアウトが縦方向に数pxずれる問題の対策
483 this.StatusText.Dock = DockStyle.Fill;
486 this.hookGlobalHotkey = new HookGlobalHotkey(this);
488 this.hookGlobalHotkey.HotkeyPressed += this.HookGlobalHotkey_HotkeyPressed;
489 this.gh.NotifyClicked += this.GrowlHelper_Callback;
491 // メイリオフォント指定時にタブの最小幅が広くなる問題の対策
492 this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
494 this.ImageSelector.Visible = false;
495 this.ImageSelector.Enabled = false;
496 this.ImageSelector.FilePickDialog = this.OpenFileDialog1;
498 this.workerProgress = new Progress<string>(x => this.StatusLabel.Text = x);
500 this.ReplaceAppName();
501 this.InitializeShortcuts();
503 this.ignoreConfigSave = true;
504 this.Visible = false;
506 this.TraceOutToolStripMenuItem.Checked = MyCommon.TraceFlag;
508 Microsoft.Win32.SystemEvents.PowerModeChanged += this.SystemEvents_PowerModeChanged;
510 Regex.CacheSize = 100;
513 this.Icon = this.iconAssets.IconMain; // メインフォーム(TweenMain)
514 this.NotifyIcon1.Icon = this.iconAssets.IconTray; // タスクトレイ
515 this.TabImage.Images.Add(this.iconAssets.IconTab); // タブ見出し
517 // <<<<<<<<<設定関連>>>>>>>>>
521 // 現在の DPI と設定保存時の DPI との比を取得する
522 var configScaleFactor = this.settings.Local.GetConfigScaleFactor(this.CurrentAutoScaleDimensions);
525 this.tw.Initialize(this.settings.Common.Token, this.settings.Common.TokenSecret, this.settings.Common.UserName, this.settings.Common.UserId);
529 this.tw.RestrictFavCheck = this.settings.Common.RestrictFavCheck;
530 this.tw.ReadOwnPost = this.settings.Common.ReadOwnPost;
532 // アクセストークンが有効であるか確認する
533 // ここが Twitter API への最初のアクセスになるようにすること
536 this.tw.VerifyCredentials();
538 catch (WebApiException ex)
542 string.Format(Properties.Resources.StartupAuthError_Text, ex.Message),
543 ApplicationSettings.ApplicationName,
544 MessageBoxButtons.OK,
545 MessageBoxIcon.Warning);
549 // プロキシ設定等の通信まわりの初期化が済んでから処理する
550 var imgazyobizinet = this.thumbGenerator.ImgAzyobuziNet;
551 imgazyobizinet.Enabled = this.settings.Common.EnableImgAzyobuziNet;
552 imgazyobizinet.DisabledInDM = this.settings.Common.ImgAzyobuziNetDisabledInDM;
553 imgazyobizinet.AutoUpdate = true;
555 Thumbnail.Services.TonTwitterCom.GetApiConnection = () => this.tw.Api.Connection;
558 this.ImageSelector.Model.InitializeServices(this.tw, this.tw.Configuration);
559 this.ImageSelector.Model.SelectMediaService(this.settings.Common.UseImageServiceName, this.settings.Common.UseImageService);
561 this.tweetThumbnail1.Initialize(this.thumbGenerator);
564 this.AtIdSupl = new AtIdSupplement(this.settings.AtIdList.AtIdList, "@");
565 this.HashSupl = new AtIdSupplement(this.settings.Common.HashTags, "#");
566 this.HashMgr = new HashtagManage(this.HashSupl,
567 this.settings.Common.HashTags.ToArray(),
568 this.settings.Common.HashSelected,
569 this.settings.Common.HashIsPermanent,
570 this.settings.Common.HashIsHead,
571 this.settings.Common.HashIsNotAddToAtReply);
572 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash) && this.HashMgr.IsPermanent) this.HashStripSplitButton.Text = this.HashMgr.UseHash;
575 this.themeManager = new(this.settings.Local);
576 this.tweetDetailsView.Initialize(this, this.iconCache, this.themeManager);
578 // StringFormatオブジェクトへの事前設定
579 this.sfTab.Alignment = StringAlignment.Center;
580 this.sfTab.LineAlignment = StringAlignment.Center;
582 this.InitDetailHtmlFormat();
583 this.tweetDetailsView.ClearPostBrowser();
585 this.recommendedStatusFooter = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
587 this.history.Add(new StatusTextHistory(""));
589 this.inReplyTo = null;
592 this.SearchDialog.Owner = this;
593 this.urlDialog.Owner = this;
596 this.NewPostPopMenuItem.Checked = this.settings.Common.NewAllPop;
597 this.NotifyFileMenuItem.Checked = this.NewPostPopMenuItem.Checked;
599 // 新着取得時のリストスクロールをするか。trueならスクロールしない
600 this.ListLockMenuItem.Checked = this.settings.Common.ListLock;
601 this.LockListFileMenuItem.Checked = this.settings.Common.ListLock;
603 this.PlaySoundMenuItem.Checked = this.settings.Common.PlaySound;
604 this.PlaySoundFileMenuItem.Checked = this.settings.Common.PlaySound;
607 this.ClientSize = ScaleBy(configScaleFactor, this.settings.Local.FormSize);
608 this.mySize = this.ClientSize; // サイズ保持(最小化・最大化されたまま終了した場合の対応用)
609 this.myLoc = this.settings.Local.FormLocation;
611 if (this.WindowState != FormWindowState.Minimized)
613 var tbarRect = new Rectangle(this.myLoc, new Size(this.mySize.Width, SystemInformation.CaptionHeight));
614 var outOfScreen = true;
615 if (Screen.AllScreens.Length == 1) // ハングするとの報告
617 foreach (var scr in Screen.AllScreens)
619 if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
627 this.myLoc = new Point(0, 0);
629 this.DesktopLocation = this.myLoc;
631 this.TopMost = this.settings.Common.AlwaysTop;
632 this.mySpDis = ScaleBy(configScaleFactor.Height, this.settings.Local.SplitterDistance);
633 this.mySpDis2 = ScaleBy(configScaleFactor.Height, this.settings.Local.StatusTextHeight);
634 this.mySpDis3 = ScaleBy(configScaleFactor.Width, this.settings.Local.PreviewDistance);
636 this.PlaySoundMenuItem.Checked = this.settings.Common.PlaySound;
637 this.PlaySoundFileMenuItem.Checked = this.settings.Common.PlaySound;
639 this.StatusText.Font = this.themeManager.FontInputFont;
640 this.StatusText.ForeColor = this.themeManager.ColorInputFont;
642 // SplitContainer2.Panel2MinSize を一行表示の入力欄の高さに合わせる (MS UI Gothic 12pt (96dpi) の場合は 19px)
643 this.StatusText.Multiline = false; // this.settings.Local.StatusMultiline の設定は後で反映される
644 this.SplitContainer2.Panel2MinSize = this.StatusText.Height;
646 // 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
647 this.SplitContainer1.IsPanelInverted = !this.settings.Common.StatusAreaAtBottom;
649 // 全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
650 if (this.settings.Common.UnreadManage == false)
652 this.ReadedStripMenuItem.Enabled = false;
653 this.UnreadStripMenuItem.Enabled = false;
656 // リンク先URL表示部の初期化(画面左下)
657 this.StatusLabelUrl.Text = "";
659 this.StatusLabel.Text = "";
660 this.StatusLabel.AutoToolTip = false;
661 this.StatusLabel.ToolTipText = "";
663 this.lblLen.Text = this.GetRestStatusCount(this.FormatStatusTextExtended("")).ToString();
665 this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
666 this.CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
667 this.CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
668 this.CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
670 // SourceLinkLabel のテキストが SplitContainer2.Panel2.AccessibleName にセットされるのを防ぐ
671 // (タブオーダー順で SourceLinkLabel の次にある PostBrowser が TabStop = false となっているため、
672 // さらに次のコントロールである SplitContainer2.Panel2 の AccessibleName がデフォルトで SourceLinkLabel のテキストになってしまう)
673 this.SplitContainer2.Panel2.AccessibleName = "";
675 ////////////////////////////////////////////////////////////////////////////////
676 var sortOrder = (SortOrder)this.settings.Common.SortOrder;
677 var mode = this.settings.Common.SortColumn switch
679 // 0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
680 0 or 5 or 6 => ComparerMode.Id, // Idソートに読み替え
681 1 => ComparerMode.Nickname, // ニックネーム
682 2 => ComparerMode.Data, // 本文
683 3 => ComparerMode.Id, // 時刻=発言Id
684 4 => ComparerMode.Name, // 名前
685 7 => ComparerMode.Source, // Source
686 _ => ComparerMode.Id,
688 this.statuses.SetSortMode(mode, sortOrder);
689 ////////////////////////////////////////////////////////////////////////////////
691 this.ApplyListViewIconSize(this.settings.Common.IconSize);
693 // <<<<<<<<タブ関連>>>>>>>
694 foreach (var tab in this.statuses.Tabs)
696 if (!this.AddNewTab(tab, startup: true))
697 throw new TabException(Properties.Resources.TweenMain_LoadText1);
700 this.ListTabSelect(this.ListTab.SelectedTab);
703 this.SetTabAlignment();
705 MyCommon.TwitterApiInfo.AccessLimitUpdated += this.TwitterApiStatus_AccessLimitUpdated;
706 Microsoft.Win32.SystemEvents.TimeChanged += this.SystemEvents_TimeChanged;
708 if (this.settings.Common.TabIconDisp)
710 this.ListTab.DrawMode = TabDrawMode.Normal;
714 this.ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
715 this.ListTab.DrawItem += this.ListTab_DrawItem;
716 this.ListTab.ImageList = null;
719 if (this.settings.Common.HotkeyEnabled)
722 var modKey = HookGlobalHotkey.ModKeys.None;
723 if ((this.settings.Common.HotkeyModifier & Keys.Alt) == Keys.Alt)
724 modKey |= HookGlobalHotkey.ModKeys.Alt;
725 if ((this.settings.Common.HotkeyModifier & Keys.Control) == Keys.Control)
726 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
727 if ((this.settings.Common.HotkeyModifier & Keys.Shift) == Keys.Shift)
728 modKey |= HookGlobalHotkey.ModKeys.Shift;
729 if ((this.settings.Common.HotkeyModifier & Keys.LWin) == Keys.LWin)
730 modKey |= HookGlobalHotkey.ModKeys.Win;
732 this.hookGlobalHotkey.RegisterOriginalHotkey(this.settings.Common.HotkeyKey, this.settings.Common.HotkeyValue, modKey);
735 if (this.settings.Common.IsUseNotifyGrowl)
736 this.gh.RegisterGrowl();
738 this.StatusLabel.Text = Properties.Resources.Form1_LoadText1; // 画面右下の状態表示を変更
740 this.SetMainWindowTitle();
741 this.SetNotifyIconText();
743 if (!this.settings.Common.MinimizeToTray || this.WindowState != FormWindowState.Minimized)
750 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Home] = () => this.InvokeAsync(() => this.RefreshTabAsync<HomeTabModel>());
751 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Mention] = () => this.InvokeAsync(() => this.RefreshTabAsync<MentionsTabModel>());
752 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Dm] = () => this.InvokeAsync(() => this.RefreshTabAsync<DirectMessagesTabModel>());
753 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.PublicSearch] = () => this.InvokeAsync(() => this.RefreshTabAsync<PublicSearchTabModel>());
754 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.User] = () => this.InvokeAsync(() => this.RefreshTabAsync<UserTimelineTabModel>());
755 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.List] = () => this.InvokeAsync(() => this.RefreshTabAsync<ListTimelineTabModel>());
756 this.timelineScheduler.UpdateFunc[TimelineSchedulerTaskType.Config] = () => this.InvokeAsync(() => Task.WhenAll(new[]
758 this.DoGetFollowersMenu(),
759 this.RefreshBlockIdsAsync(),
760 this.RefreshMuteUserIdsAsync(),
761 this.RefreshNoRetweetIdsAsync(),
762 this.RefreshTwitterConfigurationAsync(),
764 this.RefreshTimelineScheduler();
766 this.selectionDebouncer = DebounceTimer.Create(() => this.InvokeAsync(() => this.UpdateSelectedPost()), TimeSpan.FromMilliseconds(100), leading: true);
767 this.saveConfigDebouncer = DebounceTimer.Create(() => this.InvokeAsync(() => this.SaveConfigsAll(ifModified: true)), TimeSpan.FromSeconds(1));
770 this.TimerRefreshIcon.Interval = 200;
771 this.TimerRefreshIcon.Enabled = false;
773 this.ignoreConfigSave = false;
774 this.TweenMain_Resize(this, EventArgs.Empty);
776 if (this.settings.IsFirstRun)
778 // 初回起動時だけ右下のメニューを目立たせる
779 this.HashStripSplitButton.ShowDropDown();
783 private void InitDetailHtmlFormat()
785 var htmlTemplate = this.settings.Common.IsMonospace ? DetailHtmlFormatTemplateMono : DetailHtmlFormatTemplateNormal;
787 static string ColorToRGBString(Color color)
788 => $"{color.R},{color.G},{color.B}";
790 this.detailHtmlFormatPreparedTemplate = htmlTemplate
791 .Replace("%FONT_FAMILY%", this.themeManager.FontDetail.Name)
792 .Replace("%FONT_SIZE%", this.themeManager.FontDetail.Size.ToString())
793 .Replace("%FONT_COLOR%", ColorToRGBString(this.themeManager.ColorDetail))
794 .Replace("%LINK_COLOR%", ColorToRGBString(this.themeManager.ColorDetailLink))
795 .Replace("%BG_COLOR%", ColorToRGBString(this.themeManager.ColorDetailBackcolor))
796 .Replace("%BG_REPLY_COLOR%", ColorToRGBString(this.themeManager.ColorAtTo));
799 private void ListTab_DrawItem(object sender, DrawItemEventArgs e)
804 txt = this.statuses.Tabs[e.Index].TabName;
811 e.Graphics.FillRectangle(System.Drawing.SystemBrushes.Control, e.Bounds);
812 if (e.State == DrawItemState.Selected)
814 e.DrawFocusRectangle();
819 if (this.statuses.Tabs[txt].UnreadCount > 0)
822 fore = System.Drawing.SystemBrushes.ControlText;
826 fore = System.Drawing.SystemBrushes.ControlText;
828 e.Graphics.DrawString(txt, e.Font, fore, e.Bounds, this.sfTab);
831 private void LoadConfig()
833 this.statuses.LoadTabsFromSettings(this.settings.Tabs);
834 this.statuses.AddDefaultTabs();
837 private void TimerInterval_Changed(object sender, IntervalChangedEventArgs e)
839 this.RefreshTimelineScheduler();
842 private void RefreshTimelineScheduler()
844 static TimeSpan IntervalSecondsOrDisabled(int seconds)
845 => seconds == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(seconds);
847 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Home] = IntervalSecondsOrDisabled(this.settings.Common.TimelinePeriod);
848 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Mention] = IntervalSecondsOrDisabled(this.settings.Common.ReplyPeriod);
849 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Dm] = IntervalSecondsOrDisabled(this.settings.Common.DMPeriod);
850 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.PublicSearch] = IntervalSecondsOrDisabled(this.settings.Common.PubSearchPeriod);
851 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.User] = IntervalSecondsOrDisabled(this.settings.Common.UserTimelinePeriod);
852 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.List] = IntervalSecondsOrDisabled(this.settings.Common.ListsPeriod);
853 this.timelineScheduler.UpdateInterval[TimelineSchedulerTaskType.Config] = TimeSpan.FromHours(6);
854 this.timelineScheduler.UpdateAfterSystemResume = TimeSpan.FromSeconds(30);
856 this.timelineScheduler.RefreshSchedule();
859 private void MarkSettingCommonModified()
861 if (this.saveConfigDebouncer == null)
864 this.ModifySettingCommon = true;
865 _ = this.saveConfigDebouncer.Call();
868 private void MarkSettingLocalModified()
870 if (this.saveConfigDebouncer == null)
873 this.ModifySettingLocal = true;
874 _ = this.saveConfigDebouncer.Call();
877 internal void MarkSettingAtIdModified()
879 if (this.saveConfigDebouncer == null)
882 this.ModifySettingAtId = true;
883 _ = this.saveConfigDebouncer.Call();
886 private void RefreshTimeline()
888 var curListView = this.CurrentListView;
890 // 現在表示中のタブのスクロール位置を退避
891 var currentListViewState = this.listViewState[this.CurrentTabName];
892 currentListViewState.Save(this.ListLockMenuItem.Checked);
896 addCount = this.statuses.SubmitUpdate(
899 out var newMentionOrDm,
902 if (MyCommon.EndingFlag) return;
905 if (this.listCache != null && (this.listCache.IsListSizeMismatched || isDelete))
907 using (ControlTransaction.Update(curListView))
909 this.listCache.PurgeCache();
910 this.listCache.UpdateListSize();
913 currentListViewState.RestoreSelection();
919 if (this.settings.Common.TabIconDisp)
921 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
923 var tabPage = this.ListTab.TabPages[index];
924 if (tab.UnreadCount > 0 && tabPage.ImageIndex != 0)
925 tabPage.ImageIndex = 0; // 未読アイコン
930 this.ListTab.Refresh();
935 currentListViewState.RestoreScroll();
938 this.NotifyNewPosts(notifyPosts, soundFile, addCount, newMentionOrDm);
940 this.SetMainWindowTitle();
941 if (!this.StatusLabelUrl.Text.StartsWith("http", StringComparison.Ordinal)) this.SetStatusLabelUrl();
943 this.HashSupl.AddRangeItem(this.tw.GetHashList());
946 private bool BalloonRequired()
951 if (NativeMethods.IsScreenSaverRunning())
955 if (!this.NewPostPopMenuItem.Checked)
958 // 「画面最小化・アイコン時のみバルーンを表示する」が有効
959 if (this.settings.Common.LimitBalloon)
961 if (this.WindowState != FormWindowState.Minimized && this.Visible && Form.ActiveForm != null)
968 private void NotifyNewPosts(PostClass[] notifyPosts, string soundFile, int addCount, bool newMentions)
970 if (this.settings.Common.ReadOwnPost)
972 if (notifyPosts != null && notifyPosts.Length > 0 && notifyPosts.All(x => x.UserId == this.tw.UserId))
977 if (this.BalloonRequired())
979 if (notifyPosts != null && notifyPosts.Length > 0)
981 // Growlは一個ずつばらして通知。ただし、3ポスト以上あるときはまとめる
982 if (this.settings.Common.IsUseNotifyGrowl)
984 var sb = new StringBuilder();
988 foreach (var post in notifyPosts)
990 if (!(notifyPosts.Length > 3))
996 if (post.IsReply && !post.IsExcludeReply) reply = true;
997 if (post.IsDm) dm = true;
998 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
999 switch (this.settings.Common.NameBalloon)
1001 case MyCommon.NameBalloonEnum.UserID:
1002 sb.Append(post.ScreenName).Append(" : ");
1004 case MyCommon.NameBalloonEnum.NickName:
1005 sb.Append(post.Nickname).Append(" : ");
1008 sb.Append(post.TextFromApi);
1009 if (notifyPosts.Length > 3)
1011 if (notifyPosts.Last() != post) continue;
1014 var title = new StringBuilder();
1015 GrowlHelper.NotifyType nt;
1016 if (this.settings.Common.DispUsername)
1018 title.Append(this.tw.Username);
1019 title.Append(" - ");
1024 title.Append(ApplicationSettings.ApplicationName);
1025 title.Append(" [DM] ");
1026 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1027 nt = GrowlHelper.NotifyType.DirectMessage;
1031 title.Append(ApplicationSettings.ApplicationName);
1032 title.Append(" [Reply!] ");
1033 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1034 nt = GrowlHelper.NotifyType.Reply;
1038 title.Append(ApplicationSettings.ApplicationName);
1040 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1041 nt = GrowlHelper.NotifyType.Notify;
1043 var bText = sb.ToString();
1044 if (MyCommon.IsNullOrEmpty(bText)) return;
1046 var image = this.iconCache.TryGetFromCache(post.ImageUrl);
1047 this.gh.Notify(nt, post.StatusId.ToString(), title.ToString(), bText, image?.Image, post.ImageUrl);
1052 var sb = new StringBuilder();
1055 foreach (var post in notifyPosts)
1057 if (post.IsReply && !post.IsExcludeReply) reply = true;
1058 if (post.IsDm) dm = true;
1059 if (sb.Length > 0) sb.Append(System.Environment.NewLine);
1060 switch (this.settings.Common.NameBalloon)
1062 case MyCommon.NameBalloonEnum.UserID:
1063 sb.Append(post.ScreenName).Append(" : ");
1065 case MyCommon.NameBalloonEnum.NickName:
1066 sb.Append(post.Nickname).Append(" : ");
1069 sb.Append(post.TextFromApi);
1072 var title = new StringBuilder();
1074 if (this.settings.Common.DispUsername)
1076 title.Append(this.tw.Username);
1077 title.Append(" - ");
1082 ntIcon = ToolTipIcon.Warning;
1083 title.Append(ApplicationSettings.ApplicationName);
1084 title.Append(" [DM] ");
1085 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1089 ntIcon = ToolTipIcon.Warning;
1090 title.Append(ApplicationSettings.ApplicationName);
1091 title.Append(" [Reply!] ");
1092 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1096 ntIcon = ToolTipIcon.Info;
1097 title.Append(ApplicationSettings.ApplicationName);
1099 title.AppendFormat(Properties.Resources.RefreshTimeline_NotifyText, addCount);
1101 var bText = sb.ToString();
1102 if (MyCommon.IsNullOrEmpty(bText)) return;
1104 this.NotifyIcon1.BalloonTipTitle = title.ToString();
1105 this.NotifyIcon1.BalloonTipText = bText;
1106 this.NotifyIcon1.BalloonTipIcon = ntIcon;
1107 this.NotifyIcon1.ShowBalloonTip(500);
1113 if (!this.initial && this.settings.Common.PlaySound && !MyCommon.IsNullOrEmpty(soundFile))
1117 var dir = Application.StartupPath;
1118 if (Directory.Exists(Path.Combine(dir, "Sounds")))
1120 dir = Path.Combine(dir, "Sounds");
1122 using var player = new SoundPlayer(Path.Combine(dir, soundFile));
1130 // mentions新着時に画面ブリンク
1131 if (!this.initial && this.settings.Common.BlinkNewMentions && newMentions && Form.ActiveForm == null)
1133 NativeMethods.FlashMyWindow(this.Handle, 3);
1137 private async void MyList_SelectedIndexChanged(object sender, EventArgs e)
1139 var listView = this.CurrentListView;
1140 if (listView != sender)
1143 var indices = listView.SelectedIndices.Cast<int>().ToArray();
1144 this.CurrentTab.SelectPosts(indices);
1146 if (indices.Length != 1)
1149 var index = indices[0];
1150 if (index > listView.VirtualListSize - 1) return;
1152 this.PushSelectPostChain();
1154 var post = this.CurrentPost!;
1155 this.statuses.SetReadAllTab(post.StatusId, read: true);
1157 this.listCache?.RefreshStyle();
1158 await this.selectionDebouncer.Call();
1161 private void StatusTextHistoryBack()
1163 if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
1164 this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
1167 if (this.hisIdx < 0)
1170 var historyItem = this.history[this.hisIdx];
1171 this.inReplyTo = historyItem.InReplyTo;
1172 this.StatusText.Text = historyItem.Status;
1173 this.StatusText.SelectionStart = this.StatusText.Text.Length;
1176 private void StatusTextHistoryForward()
1178 if (!string.IsNullOrWhiteSpace(this.StatusText.Text))
1179 this.history[this.hisIdx] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
1182 if (this.hisIdx > this.history.Count - 1)
1183 this.hisIdx = this.history.Count - 1;
1185 var historyItem = this.history[this.hisIdx];
1186 this.inReplyTo = historyItem.InReplyTo;
1187 this.StatusText.Text = historyItem.Status;
1188 this.StatusText.SelectionStart = this.StatusText.Text.Length;
1191 private async void PostButton_Click(object sender, EventArgs e)
1193 if (this.StatusText.Text.Trim().Length == 0)
1195 if (!this.ImageSelector.Enabled)
1197 await this.DoRefresh();
1202 var currentPost = this.CurrentPost;
1203 if (this.ExistCurrentPost && currentPost != null && this.StatusText.Text.Trim() == string.Format("RT @{0}: {1}", currentPost.ScreenName, currentPost.TextFromApi))
1205 var rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
1207 MessageBoxButtons.YesNoCancel,
1208 MessageBoxIcon.Question);
1211 case DialogResult.Yes:
1212 this.StatusText.Text = "";
1213 await this.DoReTweetOfficial(false);
1215 case DialogResult.Cancel:
1220 if (TextContainsOnlyMentions(this.StatusText.Text))
1222 var message = string.Format(Properties.Resources.PostConfirmText, this.StatusText.Text);
1223 var ret = MessageBox.Show(message, ApplicationSettings.ApplicationName, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
1225 if (ret != DialogResult.OK)
1229 this.history[this.history.Count - 1] = new StatusTextHistory(this.StatusText.Text, this.inReplyTo);
1231 if (this.settings.Common.Nicoms)
1233 this.StatusText.SelectionStart = this.StatusText.Text.Length;
1234 await this.UrlConvertAsync(MyCommon.UrlConverter.Nicoms);
1237 this.StatusText.SelectionStart = this.StatusText.Text.Length;
1238 this.CheckReplyTo(this.StatusText.Text);
1240 var status = new PostStatusParams();
1242 var statusTextCompat = this.FormatStatusText(this.StatusText.Text);
1243 if (this.GetRestStatusCount(statusTextCompat) >= 0)
1245 // auto_populate_reply_metadata や attachment_url を使用しなくても 140 字以内に
1246 // 収まる場合はこれらのオプションを使用せずに投稿する
1247 status.Text = statusTextCompat;
1248 status.InReplyToStatusId = this.inReplyTo?.StatusId;
1252 status.Text = this.FormatStatusTextExtended(this.StatusText.Text, out var autoPopulatedUserIds, out var attachmentUrl);
1253 status.InReplyToStatusId = this.inReplyTo?.StatusId;
1255 status.AttachmentUrl = attachmentUrl;
1257 // リプライ先がセットされていても autoPopulatedUserIds が空の場合は auto_populate_reply_metadata を有効にしない
1259 var replyToPost = this.inReplyTo != null ? this.statuses[this.inReplyTo.Value.StatusId] : null;
1260 if (replyToPost != null && autoPopulatedUserIds.Length != 0)
1262 status.AutoPopulateReplyMetadata = true;
1264 // ReplyToList のうち autoPopulatedUserIds に含まれていないユーザー ID を抽出
1265 status.ExcludeReplyUserIds = replyToPost.ReplyToList.Select(x => x.UserId).Except(autoPopulatedUserIds)
1270 if (this.GetRestStatusCount(status.Text) < 0)
1272 // 文字数制限を超えているが強制的に投稿するか
1273 var ret = MessageBox.Show(Properties.Resources.PostLengthOverMessage1, Properties.Resources.PostLengthOverMessage2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
1274 if (ret != DialogResult.OK)
1278 IMediaUploadService? uploadService = null;
1279 IMediaItem[]? uploadItems = null;
1280 if (this.ImageSelector.Visible)
1283 if (!this.ImageSelector.TryGetSelectedMedia(out var serviceName, out uploadItems))
1286 this.ImageSelector.EndSelection();
1287 uploadService = this.ImageSelector.Model.GetService(serviceName);
1290 this.inReplyTo = null;
1291 this.StatusText.Text = "";
1292 this.history.Add(new StatusTextHistory(""));
1293 this.hisIdx = this.history.Count - 1;
1294 if (!this.settings.Common.FocusLockToStatusText)
1295 this.CurrentListView.Focus();
1296 this.urlUndoBuffer = null;
1297 this.UrlUndoToolStripMenuItem.Enabled = false; // Undoをできないように設定
1300 if (this.StatusText.Text.StartsWith("Google:", StringComparison.OrdinalIgnoreCase) && this.StatusText.Text.Trim().Length > 7)
1302 var tmp = string.Format(Properties.Resources.SearchItem2Url, Uri.EscapeDataString(this.StatusText.Text.Substring(7)));
1303 await MyCommon.OpenInBrowserAsync(this, tmp);
1306 await this.PostMessageAsync(status, uploadService, uploadItems);
1309 private void EndToolStripMenuItem_Click(object sender, EventArgs e)
1311 MyCommon.EndingFlag = true;
1315 private void TweenMain_FormClosing(object sender, FormClosingEventArgs e)
1317 if (!this.settings.Common.CloseToExit && e.CloseReason == CloseReason.UserClosing && MyCommon.EndingFlag == false)
1319 // _endingFlag=false:フォームの×ボタン
1321 this.Visible = false;
1325 this.hookGlobalHotkey.UnregisterAllOriginalHotkey();
1326 this.ignoreConfigSave = true;
1327 MyCommon.EndingFlag = true;
1328 this.timelineScheduler.Enabled = false;
1329 this.TimerRefreshIcon.Enabled = false;
1333 private void NotifyIcon1_BalloonTipClicked(object sender, EventArgs e)
1335 this.Visible = true;
1336 if (this.WindowState == FormWindowState.Minimized)
1338 this.WindowState = FormWindowState.Normal;
1341 this.BringToFront();
1344 private static int errorCount = 0;
1346 private static bool CheckAccountValid()
1348 if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
1354 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
1363 /// <summary>指定された型 <typeparamref name="T"/> に合致する全てのタブを更新します</summary>
1364 private Task RefreshTabAsync<T>()
1366 => this.RefreshTabAsync<T>(backward: false);
1368 /// <summary>指定された型 <typeparamref name="T"/> に合致する全てのタブを更新します</summary>
1369 private Task RefreshTabAsync<T>(bool backward)
1373 from tab in this.statuses.GetTabsByType<T>()
1374 select this.RefreshTabAsync(tab, backward);
1376 return Task.WhenAll(loadTasks);
1379 /// <summary>指定されたタブ <paramref name="tab"/> を更新します</summary>
1380 private Task RefreshTabAsync(TabModel tab)
1381 => this.RefreshTabAsync(tab, backward: false);
1383 /// <summary>指定されたタブ <paramref name="tab"/> を更新します</summary>
1384 private async Task RefreshTabAsync(TabModel tab, bool backward)
1386 await this.workerSemaphore.WaitAsync();
1390 this.RefreshTasktrayIcon();
1391 await Task.Run(() => tab.RefreshAsync(this.tw, backward, this.initial, this.workerProgress));
1393 catch (WebApiException ex)
1395 this.myStatusError = true;
1396 var tabType = tab switch
1398 HomeTabModel => "GetTimeline",
1399 MentionsTabModel => "GetTimeline",
1400 DirectMessagesTabModel => "GetDirectMessage",
1401 FavoritesTabModel => "GetFavorites",
1402 PublicSearchTabModel => "GetSearch",
1403 UserTimelineTabModel => "GetUserTimeline",
1404 ListTimelineTabModel => "GetListStatus",
1405 RelatedPostsTabModel => "GetRelatedTweets",
1406 _ => tab.GetType().Name.Replace("Model", ""),
1408 this.StatusLabel.Text = $"Err:{ex.Message}({tabType})";
1412 this.RefreshTimeline();
1413 this.workerSemaphore.Release();
1417 private async Task FavAddAsync(long statusId, TabModel tab)
1419 await this.workerSemaphore.WaitAsync();
1423 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
1425 this.RefreshTasktrayIcon();
1426 await this.FavAddAsyncInternal(progress, this.workerCts.Token, statusId, tab);
1428 catch (WebApiException ex)
1430 this.myStatusError = true;
1431 this.StatusLabel.Text = $"Err:{ex.Message}(PostFavAdd)";
1435 this.workerSemaphore.Release();
1439 private async Task FavAddAsyncInternal(IProgress<string> p, CancellationToken ct, long statusId, TabModel tab)
1441 if (ct.IsCancellationRequested)
1444 if (!CheckAccountValid())
1445 throw new WebApiException("Auth error. Check your account");
1447 if (!tab.Posts.TryGetValue(statusId, out var post))
1453 await Task.Run(async () =>
1455 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 0, 1, 0));
1461 await this.tw.Api.FavoritesCreate(post.RetweetedId ?? post.StatusId)
1463 .ConfigureAwait(false);
1465 catch (TwitterApiException ex)
1466 when (ex.Errors.All(x => x.Code == TwitterErrorCode.AlreadyFavorited))
1468 // エラーコード 139 のみの場合は成功と見なす
1471 if (this.settings.Common.RestrictFavCheck)
1473 var status = await this.tw.Api.StatusesShow(post.RetweetedId ?? post.StatusId)
1474 .ConfigureAwait(false);
1476 if (status.Favorited != true)
1477 throw new WebApiException("NG(Restricted?)");
1480 this.favTimestamps.Add(DateTimeUtc.Now);
1483 if (this.statuses.Posts.TryGetValue(statusId, out var postTl))
1485 postTl.IsFav = true;
1487 var favTab = this.statuses.FavoriteTab;
1488 favTab.AddPostQueue(postTl);
1491 // 検索,リスト,UserTimeline,Relatedの各タブに反映
1492 foreach (var tb in this.statuses.GetTabsInnerStorageType())
1494 if (tb.Contains(statusId))
1495 tb.Posts[statusId].IsFav = true;
1498 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 1, 1, 0));
1500 catch (WebApiException)
1502 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText15, 1, 1, 1));
1507 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
1508 foreach (var i in MyCommon.CountDown(this.favTimestamps.Count - 1, 0))
1510 if (this.favTimestamps[i] < oneHour)
1511 this.favTimestamps.RemoveAt(i);
1514 this.statuses.DistributePosts();
1517 if (ct.IsCancellationRequested)
1520 this.RefreshTimeline();
1522 if (this.CurrentTabName == tab.TabName)
1524 using (ControlTransaction.Update(this.CurrentListView))
1526 var idx = tab.IndexOf(statusId);
1528 this.listCache?.RefreshStyle(idx);
1531 var currentPost = this.CurrentPost;
1532 if (currentPost != null && statusId == currentPost.StatusId)
1533 this.DispSelectedPost(true); // 選択アイテム再表示
1537 private async Task FavRemoveAsync(IReadOnlyList<long> statusIds, TabModel tab)
1539 await this.workerSemaphore.WaitAsync();
1543 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
1545 this.RefreshTasktrayIcon();
1546 await this.FavRemoveAsyncInternal(progress, this.workerCts.Token, statusIds, tab);
1548 catch (WebApiException ex)
1550 this.myStatusError = true;
1551 this.StatusLabel.Text = $"Err:{ex.Message}(PostFavRemove)";
1555 this.workerSemaphore.Release();
1559 private async Task FavRemoveAsyncInternal(IProgress<string> p, CancellationToken ct, IReadOnlyList<long> statusIds, TabModel tab)
1561 if (ct.IsCancellationRequested)
1564 if (!CheckAccountValid())
1565 throw new WebApiException("Auth error. Check your account");
1567 var successIds = new List<long>();
1569 await Task.Run(async () =>
1573 var failedCount = 0;
1574 foreach (var statusId in statusIds)
1578 var post = tab.Posts[statusId];
1580 p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17, allCount, statusIds.Count, failedCount));
1587 await this.tw.Api.FavoritesDestroy(post.RetweetedId ?? post.StatusId)
1589 .ConfigureAwait(false);
1591 catch (WebApiException)
1597 successIds.Add(statusId);
1598 post.IsFav = false; // リスト再描画必要
1600 if (this.statuses.Posts.TryGetValue(statusId, out var tabinfoPost))
1601 tabinfoPost.IsFav = false;
1603 // 検索,リスト,UserTimeline,Relatedの各タブに反映
1604 foreach (var tb in this.statuses.GetTabsInnerStorageType())
1606 if (tb.Contains(statusId))
1607 tb.Posts[statusId].IsFav = false;
1612 if (ct.IsCancellationRequested)
1615 var favTab = this.statuses.FavoriteTab;
1616 foreach (var statusId in successIds)
1618 // ツイートが削除された訳ではないので IsDeleted はセットしない
1619 favTab.EnqueueRemovePost(statusId, setIsDeleted: false);
1622 this.RefreshTimeline();
1624 if (this.CurrentTabName == tab.TabName)
1626 if (tab.TabType == MyCommon.TabUsageType.Favorites)
1632 using (ControlTransaction.Update(this.CurrentListView))
1634 foreach (var statusId in successIds)
1636 var idx = tab.IndexOf(statusId);
1638 this.listCache?.RefreshStyle(idx);
1642 var currentPost = this.CurrentPost;
1643 if (currentPost != null && successIds.Contains(currentPost.StatusId))
1644 this.DispSelectedPost(true); // 選択アイテム再表示
1649 private async Task PostMessageAsync(PostStatusParams postParams, IMediaUploadService? uploadService, IMediaItem[]? uploadItems)
1651 await this.workerSemaphore.WaitAsync();
1655 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
1657 this.RefreshTasktrayIcon();
1658 await this.PostMessageAsyncInternal(progress, this.workerCts.Token, postParams, uploadService, uploadItems);
1660 catch (WebApiException ex)
1662 this.myStatusError = true;
1663 this.StatusLabel.Text = $"Err:{ex.Message}(PostMessage)";
1667 this.workerSemaphore.Release();
1671 private async Task PostMessageAsyncInternal(
1672 IProgress<string> p,
1673 CancellationToken ct,
1674 PostStatusParams postParams,
1675 IMediaUploadService? uploadService,
1676 IMediaItem[]? uploadItems)
1678 if (ct.IsCancellationRequested)
1681 if (!CheckAccountValid())
1682 throw new WebApiException("Auth error. Check your account");
1684 p.Report("Posting...");
1686 PostClass? post = null;
1691 await Task.Run(async () =>
1693 var postParamsWithMedia = postParams;
1695 if (uploadService != null && uploadItems != null && uploadItems.Length > 0)
1697 postParamsWithMedia = await uploadService.UploadAsync(uploadItems, postParamsWithMedia)
1698 .ConfigureAwait(false);
1701 post = await this.tw.PostStatus(postParamsWithMedia)
1702 .ConfigureAwait(false);
1705 p.Report(Properties.Resources.PostWorker_RunWorkerCompletedText4);
1707 catch (WebApiException ex)
1709 // 処理は中断せずエラーの表示のみ行う
1710 errMsg = $"Err:{ex.Message}(PostMessage)";
1712 this.myStatusError = true;
1714 catch (UnauthorizedAccessException ex)
1716 // アップロード対象のファイルが開けなかった場合など
1717 errMsg = $"Err:{ex.Message}(PostMessage)";
1719 this.myStatusError = true;
1723 // 使い終わった MediaItem は破棄する
1724 if (uploadItems != null)
1726 foreach (var disposableItem in uploadItems.OfType<IDisposable>())
1728 disposableItem.Dispose();
1733 if (ct.IsCancellationRequested)
1736 if (!MyCommon.IsNullOrEmpty(errMsg) &&
1737 !errMsg.StartsWith("OK:", StringComparison.Ordinal) &&
1738 !errMsg.StartsWith("Warn:", StringComparison.Ordinal))
1740 var message = string.Format(Properties.Resources.StatusUpdateFailed, errMsg, postParams.Text);
1742 var ret = MessageBox.Show(
1744 "Failed to update status",
1745 MessageBoxButtons.RetryCancel,
1746 MessageBoxIcon.Question);
1748 if (ret == DialogResult.Retry)
1750 await this.PostMessageAsync(postParams, uploadService, uploadItems);
1754 this.StatusTextHistoryBack();
1755 this.StatusText.Focus();
1757 // 連投モードのときだけEnterイベントが起きないので強制的に背景色を戻す
1758 if (this.settings.Common.FocusLockToStatusText)
1759 this.StatusText_Enter(this.StatusText, EventArgs.Empty);
1764 this.postTimestamps.Add(DateTimeUtc.Now);
1766 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
1767 foreach (var i in MyCommon.CountDown(this.postTimestamps.Count - 1, 0))
1769 if (this.postTimestamps[i] < oneHour)
1770 this.postTimestamps.RemoveAt(i);
1773 if (!this.HashMgr.IsPermanent && !MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
1775 this.HashMgr.ClearHashtag();
1776 this.HashStripSplitButton.Text = "#[-]";
1777 this.HashTogglePullDownMenuItem.Checked = false;
1778 this.HashToggleMenuItem.Checked = false;
1781 this.SetMainWindowTitle();
1786 this.statuses.AddPost(post);
1787 this.statuses.DistributePosts();
1788 this.RefreshTimeline();
1791 if (this.settings.Common.PostAndGet)
1792 await this.RefreshTabAsync<HomeTabModel>();
1795 private async Task RetweetAsync(IReadOnlyList<long> statusIds)
1797 await this.workerSemaphore.WaitAsync();
1801 var progress = new Progress<string>(x => this.StatusLabel.Text = x);
1803 this.RefreshTasktrayIcon();
1804 await this.RetweetAsyncInternal(progress, this.workerCts.Token, statusIds);
1806 catch (WebApiException ex)
1808 this.myStatusError = true;
1809 this.StatusLabel.Text = $"Err:{ex.Message}(PostRetweet)";
1813 this.workerSemaphore.Release();
1817 private async Task RetweetAsyncInternal(IProgress<string> p, CancellationToken ct, IReadOnlyList<long> statusIds)
1819 if (ct.IsCancellationRequested)
1822 if (!CheckAccountValid())
1823 throw new WebApiException("Auth error. Check your account");
1826 if (!this.settings.Common.UnreadManage)
1829 read = this.initial && this.settings.Common.Read;
1831 p.Report("Posting...");
1833 var posts = new List<PostClass>();
1835 await Task.Run(async () =>
1837 foreach (var statusId in statusIds)
1839 var post = await this.tw.PostRetweet(statusId, read).ConfigureAwait(false);
1840 if (post != null) posts.Add(post);
1844 if (ct.IsCancellationRequested)
1847 p.Report(Properties.Resources.PostWorker_RunWorkerCompletedText4);
1849 this.postTimestamps.Add(DateTimeUtc.Now);
1851 var oneHour = DateTimeUtc.Now - TimeSpan.FromHours(1);
1852 foreach (var i in MyCommon.CountDown(this.postTimestamps.Count - 1, 0))
1854 if (this.postTimestamps[i] < oneHour)
1855 this.postTimestamps.RemoveAt(i);
1858 // 自分のRTはTLの更新では取得できない場合があるので、
1859 // 投稿時取得の有無に関わらず追加しておく
1860 posts.ForEach(post => this.statuses.AddPost(post));
1862 if (this.settings.Common.PostAndGet)
1864 await this.RefreshTabAsync<HomeTabModel>();
1868 this.statuses.DistributePosts();
1869 this.RefreshTimeline();
1873 private async Task RefreshFollowerIdsAsync()
1875 await this.workerSemaphore.WaitAsync();
1879 this.RefreshTasktrayIcon();
1880 this.StatusLabel.Text = Properties.Resources.UpdateFollowersMenuItem1_ClickText1;
1882 await this.tw.RefreshFollowerIds();
1884 this.StatusLabel.Text = Properties.Resources.UpdateFollowersMenuItem1_ClickText3;
1886 this.RefreshTimeline();
1887 this.listCache?.PurgeCache();
1888 this.CurrentListView.Refresh();
1890 catch (WebApiException ex)
1892 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshFollowersIds)";
1896 this.workerSemaphore.Release();
1900 private async Task RefreshNoRetweetIdsAsync()
1902 await this.workerSemaphore.WaitAsync();
1906 this.RefreshTasktrayIcon();
1907 await this.tw.RefreshNoRetweetIds();
1909 this.StatusLabel.Text = "NoRetweetIds refreshed";
1911 catch (WebApiException ex)
1913 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshNoRetweetIds)";
1917 this.workerSemaphore.Release();
1921 private async Task RefreshBlockIdsAsync()
1923 await this.workerSemaphore.WaitAsync();
1927 this.RefreshTasktrayIcon();
1928 this.StatusLabel.Text = Properties.Resources.UpdateBlockUserText1;
1930 await this.tw.RefreshBlockIds();
1932 this.StatusLabel.Text = Properties.Resources.UpdateBlockUserText3;
1934 catch (WebApiException ex)
1936 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshBlockIds)";
1940 this.workerSemaphore.Release();
1944 private async Task RefreshTwitterConfigurationAsync()
1946 await this.workerSemaphore.WaitAsync();
1950 this.RefreshTasktrayIcon();
1951 await this.tw.RefreshConfiguration();
1953 if (this.tw.Configuration.PhotoSizeLimit != 0)
1955 foreach (var (_, service) in this.ImageSelector.Model.MediaServices)
1957 service.UpdateTwitterConfiguration(this.tw.Configuration);
1961 this.listCache?.PurgeCache();
1962 this.CurrentListView.Refresh();
1964 catch (WebApiException ex)
1966 this.StatusLabel.Text = $"Err:{ex.Message}(RefreshConfiguration)";
1970 this.workerSemaphore.Release();
1974 private async Task RefreshMuteUserIdsAsync()
1976 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Start;
1980 await this.tw.RefreshMuteUserIdsAsync();
1982 catch (WebApiException ex)
1984 this.StatusLabel.Text = string.Format(Properties.Resources.UpdateMuteUserIds_Error, ex.Message);
1988 this.StatusLabel.Text = Properties.Resources.UpdateMuteUserIds_Finish;
1991 private void NotifyIcon1_MouseClick(object sender, MouseEventArgs e)
1993 if (e.Button == MouseButtons.Left)
1995 this.Visible = true;
1996 if (this.WindowState == FormWindowState.Minimized)
1998 this.WindowState = this.formWindowState;
2001 this.BringToFront();
2005 private async void MyList_MouseDoubleClick(object sender, MouseEventArgs e)
2006 => await this.ListItemDoubleClickAction();
2008 private async Task ListItemDoubleClickAction()
2010 switch (this.settings.Common.ListDoubleClickAction)
2012 case MyCommon.ListItemDoubleClickActionType.Reply:
2013 this.MakeReplyText();
2015 case MyCommon.ListItemDoubleClickActionType.ReplyAll:
2016 this.MakeReplyText(atAll: true);
2018 case MyCommon.ListItemDoubleClickActionType.Favorite:
2019 await this.FavoriteChange(true);
2021 case MyCommon.ListItemDoubleClickActionType.ShowProfile:
2022 var post = this.CurrentPost;
2024 await this.ShowUserStatus(post.ScreenName, false);
2026 case MyCommon.ListItemDoubleClickActionType.ShowTimeline:
2027 await this.ShowUserTimeline();
2029 case MyCommon.ListItemDoubleClickActionType.ShowRelated:
2030 this.ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty);
2032 case MyCommon.ListItemDoubleClickActionType.OpenHomeInBrowser:
2033 this.AuthorOpenInBrowserMenuItem_Click(this.AuthorOpenInBrowserContextMenuItem, EventArgs.Empty);
2035 case MyCommon.ListItemDoubleClickActionType.OpenStatusInBrowser:
2036 this.StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty);
2038 case MyCommon.ListItemDoubleClickActionType.None:
2045 private async void FavAddToolStripMenuItem_Click(object sender, EventArgs e)
2046 => await this.FavoriteChange(true);
2048 private async void FavRemoveToolStripMenuItem_Click(object sender, EventArgs e)
2049 => await this.FavoriteChange(false);
2051 private async void FavoriteRetweetMenuItem_Click(object sender, EventArgs e)
2052 => await this.FavoritesRetweetOfficial();
2054 private async void FavoriteRetweetUnofficialMenuItem_Click(object sender, EventArgs e)
2055 => await this.FavoritesRetweetUnofficial();
2057 private async Task FavoriteChange(bool favAdd, bool multiFavoriteChangeDialogEnable = true)
2059 var tab = this.CurrentTab;
2060 var posts = tab.SelectedPosts;
2062 // trueでFavAdd,falseでFavRemove
2063 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || posts.Length == 0
2064 || !this.ExistCurrentPost) return;
2066 if (posts.Length > 1)
2071 // https://support.twitter.com/articles/76915#favoriting
2072 MessageBox.Show(string.Format(Properties.Resources.FavoriteLimitCountText, 1));
2073 this.doFavRetweetFlags = false;
2078 if (multiFavoriteChangeDialogEnable)
2080 var confirm = MessageBox.Show(
2081 Properties.Resources.FavRemoveToolStripMenuItem_ClickText1,
2082 Properties.Resources.FavRemoveToolStripMenuItem_ClickText2,
2083 MessageBoxButtons.OKCancel,
2084 MessageBoxIcon.Question);
2086 if (confirm == DialogResult.Cancel)
2094 var selectedPost = posts.Single();
2095 if (selectedPost.IsFav)
2097 this.StatusLabel.Text = Properties.Resources.FavAddToolStripMenuItem_ClickText4;
2101 await this.FavAddAsync(selectedPost.StatusId, tab);
2105 var selectedPosts = posts.Where(x => x.IsFav);
2106 var statusIds = selectedPosts.Select(x => x.StatusId).ToArray();
2107 if (statusIds.Length == 0)
2109 this.StatusLabel.Text = Properties.Resources.FavRemoveToolStripMenuItem_ClickText4;
2113 await this.FavRemoveAsync(statusIds, tab);
2117 private async void AuthorOpenInBrowserMenuItem_Click(object sender, EventArgs e)
2119 var post = this.CurrentPost;
2121 await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + post.ScreenName);
2123 await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl);
2126 private void TweenMain_ClientSizeChanged(object sender, EventArgs e)
2128 if ((!this.initialLayout) && this.Visible)
2130 if (this.WindowState == FormWindowState.Normal)
2132 this.mySize = this.ClientSize;
2133 this.mySpDis = this.SplitContainer1.SplitterDistance;
2134 this.mySpDis3 = this.SplitContainer3.SplitterDistance;
2135 if (this.StatusText.Multiline) this.mySpDis2 = this.StatusText.Height;
2136 this.MarkSettingLocalModified();
2141 private void MyList_ColumnClick(object sender, ColumnClickEventArgs e)
2143 var comparerMode = this.GetComparerModeByColumnIndex(e.Column);
2144 if (comparerMode == null)
2147 this.SetSortColumn(comparerMode.Value);
2151 /// 列インデックスからソートを行う ComparerMode を求める
2153 /// <param name="columnIndex">ソートを行うカラムのインデックス (表示上の順序とは異なる)</param>
2154 /// <returns>ソートを行う ComparerMode。null であればソートを行わない</returns>
2155 private ComparerMode? GetComparerModeByColumnIndex(int columnIndex)
2157 if (this.Use2ColumnsMode)
2158 return ComparerMode.Id;
2160 return columnIndex switch
2162 1 => ComparerMode.Nickname, // ニックネーム
2163 2 => ComparerMode.Data, // 本文
2164 3 => ComparerMode.Id, // 時刻=発言Id
2165 4 => ComparerMode.Name, // 名前
2166 7 => ComparerMode.Source, // Source
2167 _ => (ComparerMode?)null, // 0:アイコン, 5:未読マーク, 6:プロテクト・フィルターマーク
2172 /// 発言一覧の指定した位置の列でソートする
2174 /// <param name="columnIndex">ソートする列の位置 (表示上の順序で指定)</param>
2175 private void SetSortColumnByDisplayIndex(int columnIndex)
2177 // 表示上の列の位置から ColumnHeader を求める
2178 var col = this.CurrentListView.Columns.Cast<ColumnHeader>()
2179 .FirstOrDefault(x => x.DisplayIndex == columnIndex);
2184 var comparerMode = this.GetComparerModeByColumnIndex(col.Index);
2185 if (comparerMode == null)
2188 this.SetSortColumn(comparerMode.Value);
2192 /// 発言一覧の最後列の項目でソートする
2194 private void SetSortLastColumn()
2196 // 表示上の最後列にある ColumnHeader を求める
2197 var col = this.CurrentListView.Columns.Cast<ColumnHeader>()
2198 .OrderByDescending(x => x.DisplayIndex)
2201 var comparerMode = this.GetComparerModeByColumnIndex(col.Index);
2202 if (comparerMode == null)
2205 this.SetSortColumn(comparerMode.Value);
2209 /// 発言一覧を指定された ComparerMode に基づいてソートする
2211 private void SetSortColumn(ComparerMode sortColumn)
2213 if (this.settings.Common.SortOrderLock)
2216 this.statuses.ToggleSortOrder(sortColumn);
2217 this.InitColumnText();
2219 var list = this.CurrentListView;
2220 if (this.Use2ColumnsMode)
2222 list.Columns[0].Text = this.columnText[0];
2223 list.Columns[1].Text = this.columnText[2];
2227 for (var i = 0; i <= 7; i++)
2229 list.Columns[i].Text = this.columnText[i];
2233 this.listCache?.PurgeCache();
2235 var tab = this.CurrentTab;
2236 var post = this.CurrentPost;
2237 if (tab.AllCount > 0 && post != null)
2239 var idx = tab.IndexOf(post.StatusId);
2242 this.SelectListItem(list, idx);
2243 list.EnsureVisible(idx);
2248 this.MarkSettingCommonModified();
2251 private void TweenMain_LocationChanged(object sender, EventArgs e)
2253 if (this.WindowState == FormWindowState.Normal && !this.initialLayout)
2255 this.myLoc = this.DesktopLocation;
2256 this.MarkSettingLocalModified();
2260 private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
2262 var post = this.CurrentPost;
2263 if (!this.ExistCurrentPost)
2265 this.ReplyStripMenuItem.Enabled = false;
2266 this.ReplyAllStripMenuItem.Enabled = false;
2267 this.DMStripMenuItem.Enabled = false;
2268 this.TabMenuItem.Enabled = false;
2269 this.IDRuleMenuItem.Enabled = false;
2270 this.SourceRuleMenuItem.Enabled = false;
2271 this.ReadedStripMenuItem.Enabled = false;
2272 this.UnreadStripMenuItem.Enabled = false;
2273 this.AuthorContextMenuItem.Visible = false;
2274 this.RetweetedByContextMenuItem.Visible = false;
2278 this.ReplyStripMenuItem.Enabled = true;
2279 this.ReplyAllStripMenuItem.Enabled = true;
2280 this.DMStripMenuItem.Enabled = true;
2281 this.TabMenuItem.Enabled = true;
2282 this.IDRuleMenuItem.Enabled = true;
2283 this.SourceRuleMenuItem.Enabled = true;
2284 this.ReadedStripMenuItem.Enabled = true;
2285 this.UnreadStripMenuItem.Enabled = true;
2286 this.AuthorContextMenuItem.Visible = true;
2287 this.AuthorContextMenuItem.Text = $"@{post!.ScreenName}";
2288 this.RetweetedByContextMenuItem.Visible = post.RetweetedByUserId != null;
2289 this.RetweetedByContextMenuItem.Text = $"@{post.RetweetedBy}";
2291 var tab = this.CurrentTab;
2292 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
2294 this.FavAddToolStripMenuItem.Enabled = false;
2295 this.FavRemoveToolStripMenuItem.Enabled = false;
2296 this.StatusOpenMenuItem.Enabled = false;
2297 this.ShowRelatedStatusesMenuItem.Enabled = false;
2299 this.ReTweetStripMenuItem.Enabled = false;
2300 this.ReTweetUnofficialStripMenuItem.Enabled = false;
2301 this.QuoteStripMenuItem.Enabled = false;
2302 this.FavoriteRetweetContextMenu.Enabled = false;
2303 this.FavoriteRetweetUnofficialContextMenu.Enabled = false;
2307 this.FavAddToolStripMenuItem.Enabled = true;
2308 this.FavRemoveToolStripMenuItem.Enabled = true;
2309 this.StatusOpenMenuItem.Enabled = true;
2310 this.ShowRelatedStatusesMenuItem.Enabled = true; // PublicSearchの時問題出るかも
2312 if (!post.CanRetweetBy(this.tw.UserId))
2314 this.ReTweetStripMenuItem.Enabled = false;
2315 this.ReTweetUnofficialStripMenuItem.Enabled = false;
2316 this.QuoteStripMenuItem.Enabled = false;
2317 this.FavoriteRetweetContextMenu.Enabled = false;
2318 this.FavoriteRetweetUnofficialContextMenu.Enabled = false;
2322 this.ReTweetStripMenuItem.Enabled = true;
2323 this.ReTweetUnofficialStripMenuItem.Enabled = true;
2324 this.QuoteStripMenuItem.Enabled = true;
2325 this.FavoriteRetweetContextMenu.Enabled = true;
2326 this.FavoriteRetweetUnofficialContextMenu.Enabled = true;
2330 if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
2332 this.RepliedStatusOpenMenuItem.Enabled = false;
2336 this.RepliedStatusOpenMenuItem.Enabled = true;
2339 if (this.ExistCurrentPost && post != null)
2341 this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
2342 if (post.RetweetedByUserId == this.tw.UserId)
2343 this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
2345 this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText1;
2349 private void ReplyStripMenuItem_Click(object sender, EventArgs e)
2350 => this.MakeReplyText();
2352 private void DMStripMenuItem_Click(object sender, EventArgs e)
2353 => this.MakeDirectMessageText();
2355 private async Task DoStatusDelete()
2357 var posts = this.CurrentTab.SelectedPosts;
2358 if (posts.Length == 0)
2361 // 選択されたツイートの中に削除可能なものが一つでもあるか
2362 if (!posts.Any(x => x.CanDeleteBy(this.tw.UserId)))
2365 var ret = MessageBox.Show(
2367 string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine),
2368 Properties.Resources.DeleteStripMenuItem_ClickText2,
2369 MessageBoxButtons.OKCancel,
2370 MessageBoxIcon.Question);
2372 if (ret != DialogResult.OK)
2375 var currentListView = this.CurrentListView;
2376 var focusedIndex = currentListView.FocusedItem?.Index ?? currentListView.TopItem?.Index ?? 0;
2378 using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
2380 Exception? lastException = null;
2381 foreach (var post in posts)
2383 if (!post.CanDeleteBy(this.tw.UserId))
2390 await this.tw.Api.DirectMessagesEventsDestroy(post.StatusId.ToString(CultureInfo.InvariantCulture));
2394 if (post.RetweetedByUserId == this.tw.UserId)
2396 // 自分が RT したツイート (自分が RT した自分のツイートも含む)
2398 await this.tw.Api.StatusesDestroy(post.StatusId)
2403 if (post.UserId == this.tw.UserId)
2405 if (post.RetweetedId != null)
2407 // 他人に RT された自分のツイート
2408 // => RT 元の自分のツイートを削除
2409 await this.tw.Api.StatusesDestroy(post.RetweetedId.Value)
2416 await this.tw.Api.StatusesDestroy(post.StatusId)
2423 catch (WebApiException ex)
2429 this.statuses.RemovePostFromAllTabs(post.StatusId, setIsDeleted: true);
2432 if (lastException == null)
2433 this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; // 成功
2435 this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; // 失敗
2437 using (ControlTransaction.Update(currentListView))
2439 this.listCache?.PurgeCache();
2440 this.listCache?.UpdateListSize();
2442 currentListView.SelectedIndices.Clear();
2444 var currentTab = this.CurrentTab;
2445 if (currentTab.AllCount != 0)
2448 if (currentTab.AllCount - 1 > focusedIndex && focusedIndex > -1)
2449 selectedIndex = focusedIndex;
2451 selectedIndex = currentTab.AllCount - 1;
2453 currentListView.SelectedIndices.Add(selectedIndex);
2454 currentListView.EnsureVisible(selectedIndex);
2455 currentListView.FocusedItem = currentListView.Items[selectedIndex];
2459 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
2461 var tabPage = this.ListTab.TabPages[index];
2462 if (this.settings.Common.TabIconDisp && tab.UnreadCount == 0)
2464 if (tabPage.ImageIndex == 0)
2465 tabPage.ImageIndex = -1; // タブアイコン
2469 if (!this.settings.Common.TabIconDisp)
2470 this.ListTab.Refresh();
2474 private async void DeleteStripMenuItem_Click(object sender, EventArgs e)
2475 => await this.DoStatusDelete();
2477 private void ReadedStripMenuItem_Click(object sender, EventArgs e)
2479 using (ControlTransaction.Update(this.CurrentListView))
2481 var tab = this.CurrentTab;
2482 foreach (var statusId in tab.SelectedStatusIds)
2484 this.statuses.SetReadAllTab(statusId, read: true);
2485 var idx = tab.IndexOf(statusId);
2486 this.listCache?.RefreshStyle(idx);
2489 if (this.settings.Common.TabIconDisp)
2491 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
2493 if (tab.UnreadCount == 0)
2495 var tabPage = this.ListTab.TabPages[index];
2496 if (tabPage.ImageIndex == 0)
2497 tabPage.ImageIndex = -1; // タブアイコン
2501 if (!this.settings.Common.TabIconDisp) this.ListTab.Refresh();
2504 private void UnreadStripMenuItem_Click(object sender, EventArgs e)
2506 using (ControlTransaction.Update(this.CurrentListView))
2508 var tab = this.CurrentTab;
2509 foreach (var statusId in tab.SelectedStatusIds)
2511 this.statuses.SetReadAllTab(statusId, read: false);
2512 var idx = tab.IndexOf(statusId);
2513 this.listCache?.RefreshStyle(idx);
2516 if (this.settings.Common.TabIconDisp)
2518 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
2520 if (tab.UnreadCount > 0)
2522 var tabPage = this.ListTab.TabPages[index];
2523 if (tabPage.ImageIndex == -1)
2524 tabPage.ImageIndex = 0; // タブアイコン
2528 if (!this.settings.Common.TabIconDisp) this.ListTab.Refresh();
2531 private async void RefreshStripMenuItem_Click(object sender, EventArgs e)
2532 => await this.DoRefresh();
2534 private async Task DoRefresh()
2535 => await this.RefreshTabAsync(this.CurrentTab);
2537 private async Task DoRefreshMore()
2538 => await this.RefreshTabAsync(this.CurrentTab, backward: true);
2540 private DialogResult ShowSettingDialog()
2542 using var settingDialog = new AppendSettingDialog();
2543 settingDialog.Icon = this.iconAssets.IconMain;
2544 settingDialog.IntervalChanged += this.TimerInterval_Changed;
2546 settingDialog.LoadConfig(this.settings.Common, this.settings.Local);
2548 DialogResult result;
2551 result = settingDialog.ShowDialog(this);
2555 return DialogResult.Abort;
2558 if (result == DialogResult.OK)
2560 lock (this.syncObject)
2562 settingDialog.SaveConfig(this.settings.Common, this.settings.Local);
2569 private async void SettingStripMenuItem_Click(object sender, EventArgs e)
2572 var previousUserId = this.settings.Common.UserId;
2573 var oldIconCol = this.Use2ColumnsMode;
2575 if (this.ShowSettingDialog() == DialogResult.OK)
2577 lock (this.syncObject)
2579 this.settings.ApplySettings();
2581 if (MyCommon.IsNullOrEmpty(this.settings.Common.Token))
2582 this.tw.ClearAuthInfo();
2584 this.tw.Initialize(this.settings.Common.Token, this.settings.Common.TokenSecret, this.settings.Common.UserName, this.settings.Common.UserId);
2585 this.tw.RestrictFavCheck = this.settings.Common.RestrictFavCheck;
2586 this.tw.ReadOwnPost = this.settings.Common.ReadOwnPost;
2588 this.ImageSelector.Model.InitializeServices(this.tw, this.tw.Configuration);
2592 if (this.settings.Common.TabIconDisp)
2594 this.ListTab.DrawItem -= this.ListTab_DrawItem;
2595 this.ListTab.DrawMode = TabDrawMode.Normal;
2596 this.ListTab.ImageList = this.TabImage;
2600 this.ListTab.DrawItem -= this.ListTab_DrawItem;
2601 this.ListTab.DrawItem += this.ListTab_DrawItem;
2602 this.ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
2603 this.ListTab.ImageList = null;
2606 catch (Exception ex)
2608 ex.Data["Instance"] = "ListTab(TabIconDisp)";
2609 ex.Data["IsTerminatePermission"] = false;
2615 if (!this.settings.Common.UnreadManage)
2617 this.ReadedStripMenuItem.Enabled = false;
2618 this.UnreadStripMenuItem.Enabled = false;
2619 if (this.settings.Common.TabIconDisp)
2621 foreach (TabPage myTab in this.ListTab.TabPages)
2623 myTab.ImageIndex = -1;
2629 this.ReadedStripMenuItem.Enabled = true;
2630 this.UnreadStripMenuItem.Enabled = true;
2633 catch (Exception ex)
2635 ex.Data["Instance"] = "ListTab(UnreadManage)";
2636 ex.Data["IsTerminatePermission"] = false;
2641 this.SetTabAlignment();
2643 this.SplitContainer1.IsPanelInverted = !this.settings.Common.StatusAreaAtBottom;
2645 var imgazyobizinet = this.thumbGenerator.ImgAzyobuziNet;
2646 imgazyobizinet.Enabled = this.settings.Common.EnableImgAzyobuziNet;
2647 imgazyobizinet.DisabledInDM = this.settings.Common.ImgAzyobuziNetDisabledInDM;
2649 this.NewPostPopMenuItem.Checked = this.settings.Common.NewAllPop;
2650 this.NotifyFileMenuItem.Checked = this.settings.Common.NewAllPop;
2651 this.PlaySoundMenuItem.Checked = this.settings.Common.PlaySound;
2652 this.PlaySoundFileMenuItem.Checked = this.settings.Common.PlaySound;
2654 var newTheme = new ThemeManager(this.settings.Local);
2655 (var oldTheme, this.themeManager) = (this.themeManager, newTheme);
2656 this.tweetDetailsView.Theme = this.themeManager;
2657 if (this.listDrawer != null)
2658 this.listDrawer.Theme = this.themeManager;
2663 if (this.StatusText.Focused)
2664 this.StatusText.BackColor = this.themeManager.ColorInputBackcolor;
2666 this.StatusText.Font = this.themeManager.FontInputFont;
2667 this.StatusText.ForeColor = this.themeManager.ColorInputFont;
2669 catch (Exception ex)
2671 MessageBox.Show(ex.Message);
2676 this.InitDetailHtmlFormat();
2678 catch (Exception ex)
2680 ex.Data["Instance"] = "Font";
2681 ex.Data["IsTerminatePermission"] = false;
2687 if (this.settings.Common.TabIconDisp)
2689 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
2691 var tabPage = this.ListTab.TabPages[index];
2692 if (tab.UnreadCount == 0)
2693 tabPage.ImageIndex = -1;
2695 tabPage.ImageIndex = 0;
2699 catch (Exception ex)
2701 ex.Data["Instance"] = "ListTab(TabIconDisp no2)";
2702 ex.Data["IsTerminatePermission"] = false;
2708 this.ApplyListViewIconSize(this.settings.Common.IconSize);
2710 foreach (TabPage tp in this.ListTab.TabPages)
2712 var lst = (DetailsListView)tp.Tag;
2714 using (ControlTransaction.Update(lst))
2716 lst.GridLines = this.settings.Common.ShowGrid;
2718 if (this.Use2ColumnsMode != oldIconCol)
2719 this.ResetColumns(lst);
2723 catch (Exception ex)
2725 ex.Data["Instance"] = "ListView(IconSize)";
2726 ex.Data["IsTerminatePermission"] = false;
2730 this.SetMainWindowTitle();
2731 this.SetNotifyIconText();
2733 this.listCache?.PurgeCache();
2734 this.CurrentListView.Refresh();
2735 this.ListTab.Refresh();
2737 this.hookGlobalHotkey.UnregisterAllOriginalHotkey();
2738 if (this.settings.Common.HotkeyEnabled)
2740 // グローバルホットキーの登録。設定で変更可能にするかも
2741 var modKey = HookGlobalHotkey.ModKeys.None;
2742 if ((this.settings.Common.HotkeyModifier & Keys.Alt) == Keys.Alt)
2743 modKey |= HookGlobalHotkey.ModKeys.Alt;
2744 if ((this.settings.Common.HotkeyModifier & Keys.Control) == Keys.Control)
2745 modKey |= HookGlobalHotkey.ModKeys.Ctrl;
2746 if ((this.settings.Common.HotkeyModifier & Keys.Shift) == Keys.Shift)
2747 modKey |= HookGlobalHotkey.ModKeys.Shift;
2748 if ((this.settings.Common.HotkeyModifier & Keys.LWin) == Keys.LWin)
2749 modKey |= HookGlobalHotkey.ModKeys.Win;
2751 this.hookGlobalHotkey.RegisterOriginalHotkey(this.settings.Common.HotkeyKey, this.settings.Common.HotkeyValue, modKey);
2754 if (this.settings.Common.IsUseNotifyGrowl) this.gh.RegisterGrowl();
2757 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
2765 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
2767 this.TopMost = this.settings.Common.AlwaysTop;
2768 this.SaveConfigsAll(false);
2770 if (this.tw.UserId != previousUserId)
2771 await this.DoGetFollowersMenu();
2777 private void SetTabAlignment()
2779 var newAlignment = this.settings.Common.ViewTabBottom ? TabAlignment.Bottom : TabAlignment.Top;
2780 if (this.ListTab.Alignment == newAlignment) return;
2783 var currentListViewState = this.listViewState[this.CurrentTabName];
2784 currentListViewState.Save(this.ListLockMenuItem.Checked);
2786 this.ListTab.Alignment = newAlignment;
2788 currentListViewState.Restore(forceScroll: true);
2791 private void ApplyListViewIconSize(MyCommon.IconSizes iconSz)
2794 if (this.listDrawer != null)
2796 this.listDrawer.IconSize = iconSz;
2797 this.listDrawer.UpdateItemHeight();
2800 this.listCache?.PurgeCache();
2803 private void ResetColumns(DetailsListView list)
2805 using (ControlTransaction.Update(list))
2806 using (ControlTransaction.Layout(list, false))
2809 list.ColumnClick -= this.MyList_ColumnClick;
2810 list.DrawColumnHeader -= this.MyList_DrawColumnHeader;
2811 list.ColumnReordered -= this.MyList_ColumnReordered;
2812 list.ColumnWidthChanged -= this.MyList_ColumnWidthChanged;
2814 var cols = list.Columns.Cast<ColumnHeader>().ToList();
2815 list.Columns.Clear();
2816 cols.ForEach(col => col.Dispose());
2819 this.InitColumns(list, true);
2821 list.ColumnClick += this.MyList_ColumnClick;
2822 list.DrawColumnHeader += this.MyList_DrawColumnHeader;
2823 list.ColumnReordered += this.MyList_ColumnReordered;
2824 list.ColumnWidthChanged += this.MyList_ColumnWidthChanged;
2828 public void AddNewTabForSearch(string searchWord)
2830 // 同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
2831 foreach (var tb in this.statuses.GetTabsByType<PublicSearchTabModel>())
2833 if (tb.SearchWords == searchWord && MyCommon.IsNullOrEmpty(tb.SearchLang))
2835 var tabIndex = this.statuses.Tabs.IndexOf(tb);
2836 this.ListTab.SelectedIndex = tabIndex;
2841 var tabName = searchWord;
2842 for (var i = 0; i <= 100; i++)
2844 if (this.statuses.ContainsTab(tabName))
2850 var tab = new PublicSearchTabModel(tabName);
2851 this.statuses.AddTab(tab);
2852 this.AddNewTab(tab, startup: false);
2854 this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1;
2856 var tabPage = this.CurrentTabPage;
2857 var cmb = (ComboBox)tabPage.Controls["panelSearch"].Controls["comboSearch"];
2858 cmb.Items.Add(searchWord);
2859 cmb.Text = searchWord;
2860 this.SaveConfigsTabs();
2862 this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
2865 private async Task ShowUserTimeline()
2867 var post = this.CurrentPost;
2868 if (post == null || !this.ExistCurrentPost) return;
2869 await this.AddNewTabForUserTimeline(post.ScreenName);
2872 private async Task ShowRetweeterTimeline()
2874 var retweetedBy = this.CurrentPost?.RetweetedBy;
2875 if (retweetedBy == null || !this.ExistCurrentPost) return;
2876 await this.AddNewTabForUserTimeline(retweetedBy);
2879 private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
2881 if (e.KeyCode == Keys.Escape)
2883 this.RemoveSpecifiedTab(this.CurrentTabName, false);
2884 this.SaveConfigsTabs();
2885 e.SuppressKeyPress = true;
2889 public async Task AddNewTabForUserTimeline(string user)
2891 // 同一検索条件のタブが既に存在すれば、そのタブアクティブにして終了
2892 foreach (var tb in this.statuses.GetTabsByType<UserTimelineTabModel>())
2894 if (tb.ScreenName == user)
2896 var tabIndex = this.statuses.Tabs.IndexOf(tb);
2897 this.ListTab.SelectedIndex = tabIndex;
2902 var tabName = "user:" + user;
2903 while (this.statuses.ContainsTab(tabName))
2908 var tab = new UserTimelineTabModel(tabName, user);
2909 this.statuses.AddTab(tab);
2910 this.AddNewTab(tab, startup: false);
2912 this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1;
2913 this.SaveConfigsTabs();
2915 await this.RefreshTabAsync(tab);
2918 public bool AddNewTab(TabModel tab, bool startup)
2921 if (this.ListTab.TabPages.Cast<TabPage>().Any(x => x.Text == tab.TabName))
2925 if (tab.TabName == Properties.Resources.AddNewTabText1) return false;
2927 var tabPage = new TabPage();
2928 var listCustom = new DetailsListView();
2930 var cnt = this.statuses.Tabs.Count;
2932 // ToDo:Create and set controls follow tabtypes
2934 using (ControlTransaction.Update(listCustom))
2935 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
2936 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
2937 using (ControlTransaction.Layout(this.SplitContainer1, false))
2938 using (ControlTransaction.Layout(this.ListTab, false))
2939 using (ControlTransaction.Layout(this))
2940 using (ControlTransaction.Layout(tabPage, false))
2942 tabPage.Controls.Add(listCustom);
2945 var userTab = tab as UserTimelineTabModel;
2946 var listTab = tab as ListTimelineTabModel;
2947 var searchTab = tab as PublicSearchTabModel;
2949 if (userTab != null || listTab != null)
2951 var label = new Label
2953 Dock = DockStyle.Top,
2958 if (listTab != null)
2960 label.Text = listTab.ListInfo.ToString();
2962 else if (userTab != null)
2964 label.Text = userTab.ScreenName + "'s Timeline";
2966 label.TextAlign = ContentAlignment.MiddleLeft;
2967 using (var tmpComboBox = new ComboBox())
2969 label.Height = tmpComboBox.Height;
2971 tabPage.Controls.Add(label);
2974 else if (searchTab != null)
2976 var pnl = new Panel();
2978 var lbl = new Label();
2979 var cmb = new ComboBox();
2980 var btn = new Button();
2981 var cmbLang = new ComboBox();
2983 using (ControlTransaction.Layout(pnl, false))
2985 pnl.Controls.Add(cmb);
2986 pnl.Controls.Add(cmbLang);
2987 pnl.Controls.Add(btn);
2988 pnl.Controls.Add(lbl);
2989 pnl.Name = "panelSearch";
2991 pnl.Dock = DockStyle.Top;
2992 pnl.Height = cmb.Height;
2993 pnl.Enter += this.SearchControls_Enter;
2994 pnl.Leave += this.SearchControls_Leave;
2997 cmb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
2998 cmb.Dock = DockStyle.Fill;
2999 cmb.Name = "comboSearch";
3000 cmb.DropDownStyle = ComboBoxStyle.DropDown;
3001 cmb.ImeMode = ImeMode.NoControl;
3002 cmb.TabStop = false;
3004 cmb.AutoCompleteMode = AutoCompleteMode.None;
3005 cmb.KeyDown += this.SearchComboBox_KeyDown;
3008 cmbLang.Anchor = AnchorStyles.Left | AnchorStyles.Right;
3009 cmbLang.Dock = DockStyle.Right;
3011 cmbLang.Name = "comboLang";
3012 cmbLang.DropDownStyle = ComboBoxStyle.DropDownList;
3013 cmbLang.TabStop = false;
3014 cmbLang.TabIndex = 2;
3015 cmbLang.Items.Add("");
3016 cmbLang.Items.Add("ja");
3017 cmbLang.Items.Add("en");
3018 cmbLang.Items.Add("ar");
3019 cmbLang.Items.Add("da");
3020 cmbLang.Items.Add("nl");
3021 cmbLang.Items.Add("fa");
3022 cmbLang.Items.Add("fi");
3023 cmbLang.Items.Add("fr");
3024 cmbLang.Items.Add("de");
3025 cmbLang.Items.Add("hu");
3026 cmbLang.Items.Add("is");
3027 cmbLang.Items.Add("it");
3028 cmbLang.Items.Add("no");
3029 cmbLang.Items.Add("pl");
3030 cmbLang.Items.Add("pt");
3031 cmbLang.Items.Add("ru");
3032 cmbLang.Items.Add("es");
3033 cmbLang.Items.Add("sv");
3034 cmbLang.Items.Add("th");
3036 lbl.Text = "Search(C-S-f)";
3037 lbl.Name = "label1";
3038 lbl.Dock = DockStyle.Left;
3040 lbl.Height = cmb.Height;
3041 lbl.TextAlign = ContentAlignment.MiddleLeft;
3044 btn.Text = "Search";
3045 btn.Name = "buttonSearch";
3046 btn.UseVisualStyleBackColor = true;
3047 btn.Dock = DockStyle.Right;
3048 btn.TabStop = false;
3050 btn.Click += this.SearchButton_Click;
3052 if (!MyCommon.IsNullOrEmpty(searchTab.SearchWords))
3054 cmb.Items.Add(searchTab.SearchWords);
3055 cmb.Text = searchTab.SearchWords;
3058 cmbLang.Text = searchTab.SearchLang;
3060 tabPage.Controls.Add(pnl);
3064 tabPage.Tag = listCustom;
3065 this.ListTab.Controls.Add(tabPage);
3067 tabPage.Location = new Point(4, 4);
3068 tabPage.Name = "CTab" + cnt;
3069 tabPage.Size = new Size(380, 260);
3070 tabPage.TabIndex = 2 + cnt;
3071 tabPage.Text = tab.TabName;
3072 tabPage.UseVisualStyleBackColor = true;
3073 tabPage.AccessibleRole = AccessibleRole.PageTab;
3075 listCustom.AccessibleName = Properties.Resources.AddNewTab_ListView_AccessibleName;
3076 listCustom.TabIndex = 1;
3077 listCustom.AllowColumnReorder = true;
3078 listCustom.ContextMenuStrip = this.ContextMenuOperate;
3079 listCustom.ColumnHeaderContextMenuStrip = this.ContextMenuColumnHeader;
3080 listCustom.Dock = DockStyle.Fill;
3081 listCustom.FullRowSelect = true;
3082 listCustom.HideSelection = false;
3083 listCustom.Location = new Point(0, 0);
3084 listCustom.Margin = new Padding(0);
3085 listCustom.Name = "CList" + Environment.TickCount;
3086 listCustom.ShowItemToolTips = true;
3087 listCustom.Size = new Size(380, 260);
3088 listCustom.UseCompatibleStateImageBehavior = false;
3089 listCustom.View = View.Details;
3090 listCustom.OwnerDraw = true;
3091 listCustom.VirtualMode = true;
3093 listCustom.GridLines = this.settings.Common.ShowGrid;
3094 listCustom.AllowDrop = true;
3096 this.InitColumns(listCustom, startup);
3098 listCustom.SelectedIndexChanged += this.MyList_SelectedIndexChanged;
3099 listCustom.MouseDoubleClick += this.MyList_MouseDoubleClick;
3100 listCustom.ColumnClick += this.MyList_ColumnClick;
3101 listCustom.DrawColumnHeader += this.MyList_DrawColumnHeader;
3102 listCustom.DragDrop += this.TweenMain_DragDrop;
3103 listCustom.DragEnter += this.TweenMain_DragEnter;
3104 listCustom.DragOver += this.TweenMain_DragOver;
3105 listCustom.MouseClick += this.MyList_MouseClick;
3106 listCustom.ColumnReordered += this.MyList_ColumnReordered;
3107 listCustom.ColumnWidthChanged += this.MyList_ColumnWidthChanged;
3108 listCustom.HScrolled += this.MyList_HScrolled;
3111 var state = new TimelineListViewState(listCustom, tab);
3112 this.listViewState[tab.TabName] = state;
3117 public bool RemoveSpecifiedTab(string tabName, bool confirm)
3119 var tabInfo = this.statuses.GetTabByName(tabName);
3120 if (tabInfo == null || tabInfo.IsDefaultTabType || tabInfo.Protected)
3125 var tmp = string.Format(Properties.Resources.RemoveSpecifiedTabText1, Environment.NewLine);
3126 var result = MessageBox.Show(
3128 tabName + " " + Properties.Resources.RemoveSpecifiedTabText2,
3129 MessageBoxButtons.OKCancel,
3130 MessageBoxIcon.Question,
3131 MessageBoxDefaultButton.Button2);
3132 if (result == DialogResult.Cancel)
3138 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
3142 var tabPage = this.ListTab.TabPages[tabIndex];
3144 this.SetListProperty(); // 他のタブに列幅等を反映
3146 this.listViewState.Remove(tabName);
3149 var listCustom = (DetailsListView)tabPage.Tag;
3152 using (ControlTransaction.Layout(this.SplitContainer1.Panel1, false))
3153 using (ControlTransaction.Layout(this.SplitContainer1.Panel2, false))
3154 using (ControlTransaction.Layout(this.SplitContainer1, false))
3155 using (ControlTransaction.Layout(this.ListTab, false))
3156 using (ControlTransaction.Layout(this))
3157 using (ControlTransaction.Layout(tabPage, false))
3159 if (this.CurrentTabName == tabName)
3161 this.ListTab.SelectTab((this.beforeSelectedTab != null && this.ListTab.TabPages.Contains(this.beforeSelectedTab)) ? this.beforeSelectedTab : this.ListTab.TabPages[0]);
3162 this.beforeSelectedTab = null;
3164 this.ListTab.Controls.Remove(tabPage);
3167 if (tabInfo.TabType == MyCommon.TabUsageType.UserTimeline || tabInfo.TabType == MyCommon.TabUsageType.Lists)
3169 using var label = tabPage.Controls["labelUser"];
3170 tabPage.Controls.Remove(label);
3172 else if (tabInfo.TabType == MyCommon.TabUsageType.PublicSearch)
3174 using var pnl = tabPage.Controls["panelSearch"];
3176 pnl.Enter -= this.SearchControls_Enter;
3177 pnl.Leave -= this.SearchControls_Leave;
3178 tabPage.Controls.Remove(pnl);
3180 foreach (Control ctrl in pnl.Controls)
3182 if (ctrl.Name == "buttonSearch")
3184 ctrl.Click -= this.SearchButton_Click;
3186 else if (ctrl.Name == "comboSearch")
3188 ctrl.KeyDown -= this.SearchComboBox_KeyDown;
3190 pnl.Controls.Remove(ctrl);
3195 tabPage.Controls.Remove(listCustom);
3197 listCustom.SelectedIndexChanged -= this.MyList_SelectedIndexChanged;
3198 listCustom.MouseDoubleClick -= this.MyList_MouseDoubleClick;
3199 listCustom.ColumnClick -= this.MyList_ColumnClick;
3200 listCustom.DrawColumnHeader -= this.MyList_DrawColumnHeader;
3201 listCustom.DragDrop -= this.TweenMain_DragDrop;
3202 listCustom.DragEnter -= this.TweenMain_DragEnter;
3203 listCustom.DragOver -= this.TweenMain_DragOver;
3204 listCustom.MouseClick -= this.MyList_MouseClick;
3205 listCustom.ColumnReordered -= this.MyList_ColumnReordered;
3206 listCustom.ColumnWidthChanged -= this.MyList_ColumnWidthChanged;
3207 listCustom.HScrolled -= this.MyList_HScrolled;
3209 var cols = listCustom.Columns.Cast<ColumnHeader>().ToList<ColumnHeader>();
3210 listCustom.Columns.Clear();
3211 cols.ForEach(col => col.Dispose());
3214 listCustom.ContextMenuStrip = null;
3215 listCustom.ColumnHeaderContextMenuStrip = null;
3216 listCustom.Font = null;
3218 listCustom.SmallImageList = null;
3219 listCustom.ListViewItemSorter = null;
3222 this.listCache?.PurgeCache();
3226 listCustom.Dispose();
3227 this.statuses.RemoveTab(tabName);
3232 private void ListTab_Deselected(object sender, TabControlEventArgs e)
3234 this.listCache?.PurgeCache();
3235 this.beforeSelectedTab = e.TabPage;
3238 private void ListTab_MouseMove(object sender, MouseEventArgs e)
3242 if (!this.settings.Common.TabMouseLock && e.Button == MouseButtons.Left && this.tabDrag)
3245 var dragEnableRectangle = new Rectangle(this.tabMouseDownPoint.X - (SystemInformation.DragSize.Width / 2), this.tabMouseDownPoint.Y - (SystemInformation.DragSize.Height / 2), SystemInformation.DragSize.Width, SystemInformation.DragSize.Height);
3246 if (!dragEnableRectangle.Contains(e.Location))
3248 // タブが多段の場合にはMouseDownの前の段階で選択されたタブの段が変わっているので、このタイミングでカーソルの位置からタブを判定出来ない。
3249 tn = this.CurrentTabName;
3252 if (MyCommon.IsNullOrEmpty(tn)) return;
3254 var tabIndex = this.statuses.Tabs.IndexOf(tn);
3257 var tabPage = this.ListTab.TabPages[tabIndex];
3258 this.ListTab.DoDragDrop(tabPage, DragDropEffects.All);
3263 this.tabDrag = false;
3266 var cpos = new Point(e.X, e.Y);
3267 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3269 var rect = this.ListTab.GetTabRect(index);
3270 if (rect.Contains(cpos))
3272 this.rclickTabName = tab.TabName;
3278 private void ListTab_SelectedIndexChanged(object sender, EventArgs e)
3280 this.SetMainWindowTitle();
3281 this.SetStatusLabelUrl();
3282 this.SetApiStatusLabel();
3283 if (this.ListTab.Focused || ((Control)this.CurrentTabPage.Tag).Focused)
3284 this.Tag = this.ListTab.Tag;
3285 this.TabMenuControl(this.CurrentTabName);
3286 this.PushSelectPostChain();
3287 this.DispSelectedPost();
3290 private void SetListProperty()
3292 if (!this.isColumnChanged) return;
3294 var currentListView = this.CurrentListView;
3296 var dispOrder = new int[currentListView.Columns.Count];
3297 for (var i = 0; i < currentListView.Columns.Count; i++)
3299 for (var j = 0; j < currentListView.Columns.Count; j++)
3301 if (currentListView.Columns[j].DisplayIndex == i)
3310 foreach (TabPage tb in this.ListTab.TabPages)
3312 if (tb.Text == this.CurrentTabName)
3315 if (tb.Tag != null && tb.Controls.Count > 0)
3317 var lst = (DetailsListView)tb.Tag;
3318 for (var i = 0; i < lst.Columns.Count; i++)
3320 lst.Columns[dispOrder[i]].DisplayIndex = i;
3321 lst.Columns[i].Width = currentListView.Columns[i].Width;
3326 this.isColumnChanged = false;
3329 private void StatusText_KeyPress(object sender, KeyPressEventArgs e)
3331 if (e.KeyChar == '@')
3333 if (!this.settings.Common.UseAtIdSupplement) return;
3335 var cnt = this.AtIdSupl.ItemCount;
3336 this.ShowSuplDialog(this.StatusText, this.AtIdSupl);
3337 if (cnt != this.AtIdSupl.ItemCount)
3338 this.MarkSettingAtIdModified();
3341 else if (e.KeyChar == '#')
3343 if (!this.settings.Common.UseHashSupplement) return;
3344 this.ShowSuplDialog(this.StatusText, this.HashSupl);
3349 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog)
3350 => this.ShowSuplDialog(owner, dialog, 0, "");
3352 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset)
3353 => this.ShowSuplDialog(owner, dialog, offset, "");
3355 public void ShowSuplDialog(TextBox owner, AtIdSupplement dialog, int offset, string startswith)
3357 dialog.StartsWith = startswith;
3364 dialog.ShowDialog();
3366 this.TopMost = this.settings.Common.AlwaysTop;
3367 var selStart = owner.SelectionStart;
3370 if (dialog.DialogResult == DialogResult.OK)
3372 if (!MyCommon.IsNullOrEmpty(dialog.InputText))
3376 fHalf = owner.Text.Substring(0, selStart - offset);
3378 if (selStart < owner.Text.Length)
3380 eHalf = owner.Text.Substring(selStart);
3382 owner.Text = fHalf + dialog.InputText + eHalf;
3383 owner.SelectionStart = selStart + dialog.InputText.Length;
3390 fHalf = owner.Text.Substring(0, selStart);
3392 if (selStart < owner.Text.Length)
3394 eHalf = owner.Text.Substring(selStart);
3396 owner.Text = fHalf + eHalf;
3399 owner.SelectionStart = selStart;
3405 private void StatusText_KeyUp(object sender, KeyEventArgs e)
3408 if (!e.Alt && !e.Control && !e.Shift)
3410 if (e.KeyCode == Keys.Space || e.KeyCode == Keys.ProcessKey)
3412 var isSpace = false;
3413 foreach (var c in this.StatusText.Text)
3415 if (c == ' ' || c == ' ')
3428 this.StatusText.Text = "";
3429 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
3433 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
3436 private void StatusText_TextChanged(object sender, EventArgs e)
3439 var pLen = this.GetRestStatusCount(this.FormatStatusTextExtended(this.StatusText.Text));
3440 this.lblLen.Text = pLen.ToString();
3443 this.StatusText.ForeColor = Color.Red;
3447 this.StatusText.ForeColor = this.themeManager.ColorInputFont;
3450 this.StatusText.AccessibleDescription = string.Format(Properties.Resources.StatusText_AccessibleDescription, pLen);
3452 if (MyCommon.IsNullOrEmpty(this.StatusText.Text))
3454 this.inReplyTo = null;
3459 /// メンション以外の文字列が含まれていないテキストであるか判定します
3461 internal static bool TextContainsOnlyMentions(string text)
3463 var mentions = TweetExtractor.ExtractMentionEntities(text).OrderBy(x => x.Indices[0]);
3466 foreach (var mention in mentions)
3468 var textPart = text.Substring(startIndex, mention.Indices[0] - startIndex);
3470 if (!string.IsNullOrWhiteSpace(textPart))
3473 startIndex = mention.Indices[1];
3476 var textPartLast = text.Substring(startIndex);
3478 if (!string.IsNullOrWhiteSpace(textPartLast))
3485 /// 投稿時に auto_populate_reply_metadata オプションによって自動で追加されるメンションを除去します
3487 private string RemoveAutoPopuratedMentions(string statusText, out long[] autoPopulatedUserIds)
3489 var autoPopulatedUserIdList = new List<long>();
3491 var replyToPost = this.inReplyTo != null ? this.statuses[this.inReplyTo.Value.StatusId] : null;
3492 if (replyToPost != null)
3494 if (statusText.StartsWith($"@{replyToPost.ScreenName} ", StringComparison.Ordinal))
3496 statusText = statusText.Substring(replyToPost.ScreenName.Length + 2);
3497 autoPopulatedUserIdList.Add(replyToPost.UserId);
3499 foreach (var (userId, screenName) in replyToPost.ReplyToList)
3501 if (statusText.StartsWith($"@{screenName} ", StringComparison.Ordinal))
3503 statusText = statusText.Substring(screenName.Length + 2);
3504 autoPopulatedUserIdList.Add(userId);
3510 autoPopulatedUserIds = autoPopulatedUserIdList.ToArray();
3516 /// attachment_url に指定可能な URL が含まれていれば除去
3518 private string RemoveAttachmentUrl(string statusText, out string? attachmentUrl)
3520 attachmentUrl = null;
3522 // attachment_url は media_id と同時に使用できない
3523 if (this.ImageSelector.Visible && this.ImageSelector.Model.SelectedMediaService is TwitterPhoto)
3526 var match = Twitter.AttachmentUrlRegex.Match(statusText);
3530 attachmentUrl = match.Value;
3533 statusText = statusText.Substring(0, match.Index);
3535 // テキストと URL の間にスペースが含まれていれば除去
3536 return statusText.TrimEnd(' ');
3539 private string FormatStatusTextExtended(string statusText)
3540 => this.FormatStatusTextExtended(statusText, out _, out _);
3543 /// <see cref="FormatStatusText"/> に加えて、拡張モードで140字にカウントされない文字列の除去を行います
3545 private string FormatStatusTextExtended(string statusText, out long[] autoPopulatedUserIds, out string? attachmentUrl)
3547 statusText = this.RemoveAutoPopuratedMentions(statusText, out autoPopulatedUserIds);
3549 statusText = this.RemoveAttachmentUrl(statusText, out attachmentUrl);
3551 return this.FormatStatusText(statusText);
3555 /// ツイート投稿前のフッター付与などの前処理を行います
3557 private string FormatStatusText(string statusText)
3559 statusText = statusText.Replace("\r\n", "\n");
3561 if (this.urlMultibyteSplit)
3564 statusText = Regex.Replace(statusText, @"https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#^]+", "$& ");
3567 if (this.settings.Common.WideSpaceConvert)
3569 // 文中の全角スペースを半角スペース1個にする
3570 statusText = statusText.Replace(" ", " ");
3573 // DM の場合はこれ以降の処理を行わない
3574 if (statusText.StartsWith("D ", StringComparison.OrdinalIgnoreCase))
3578 if (this.settings.Common.PostShiftEnter)
3580 disableFooter = MyCommon.IsKeyDown(Keys.Control);
3584 if (this.StatusText.Multiline && !this.settings.Common.PostCtrlEnter)
3585 disableFooter = MyCommon.IsKeyDown(Keys.Control);
3587 disableFooter = MyCommon.IsKeyDown(Keys.Shift);
3590 if (statusText.Contains("RT @"))
3591 disableFooter = true;
3593 // 自分宛のリプライの場合は先頭の「@screen_name 」の部分を除去する (in_reply_to_status_id は維持される)
3594 if (this.inReplyTo != null && this.inReplyTo.Value.ScreenName == this.tw.Username)
3596 var mentionSelf = $"@{this.tw.Username} ";
3597 if (statusText.StartsWith(mentionSelf, StringComparison.OrdinalIgnoreCase))
3599 if (statusText.Length > mentionSelf.Length || this.GetSelectedImageService() != null)
3600 statusText = statusText.Substring(mentionSelf.Length);
3607 var hashtag = this.HashMgr.UseHash;
3608 if (!MyCommon.IsNullOrEmpty(hashtag) && !(this.HashMgr.IsNotAddToAtReply && this.inReplyTo != null))
3610 if (this.HashMgr.IsHead)
3611 header = this.HashMgr.UseHash + " ";
3613 footer = " " + this.HashMgr.UseHash;
3618 if (this.settings.Local.UseRecommendStatus)
3621 footer += this.recommendedStatusFooter;
3623 else if (!MyCommon.IsNullOrEmpty(this.settings.Local.StatusText))
3625 // テキストボックスに入力されている文字列を使用する
3626 footer += " " + this.settings.Local.StatusText.Trim();
3630 statusText = header + statusText + footer;
3632 if (this.preventSmsCommand)
3634 // ツイートが意図せず SMS コマンドとして解釈されることを回避 (D, DM, M のみ)
3635 // 参照: https://support.twitter.com/articles/14020
3637 if (Regex.IsMatch(statusText, @"^[+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]*(d|dm|m)([+\-\[\]\s\\.,*/(){}^~|='&%$#""<>?]+|$)", RegexOptions.IgnoreCase)
3638 && !Twitter.DMSendTextRegex.IsMatch(statusText))
3640 // U+200B (ZERO WIDTH SPACE) を先頭に加えて回避
3641 statusText = '\u200b' + statusText;
3649 /// 投稿欄に表示する入力可能な文字数を計算します
3651 private int GetRestStatusCount(string statusText)
3653 var remainCount = this.tw.GetTextLengthRemain(statusText);
3655 var uploadService = this.GetSelectedImageService();
3656 if (uploadService != null)
3658 // TODO: ImageSelector で選択中の画像の枚数が mediaCount 引数に渡るようにする
3659 remainCount -= uploadService.GetReservedTextLength(1);
3665 private IMediaUploadService? GetSelectedImageService()
3666 => this.ImageSelector.Visible ? this.ImageSelector.Model.SelectedMediaService : null;
3669 /// 全てのタブの振り分けルールを反映し直します
3671 private void ApplyPostFilters()
3673 using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
3675 this.statuses.FilterAll();
3677 var listView = this.CurrentListView;
3678 using (ControlTransaction.Update(listView))
3680 this.listCache?.PurgeCache();
3681 this.listCache?.UpdateListSize();
3684 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
3686 var tabPage = this.ListTab.TabPages[index];
3688 if (this.settings.Common.TabIconDisp)
3690 if (tab.UnreadCount > 0)
3691 tabPage.ImageIndex = 0;
3693 tabPage.ImageIndex = -1;
3697 if (!this.settings.Common.TabIconDisp)
3698 this.ListTab.Refresh();
3700 this.SetMainWindowTitle();
3701 this.SetStatusLabelUrl();
3705 private void MyList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
3706 => e.DrawDefault = true;
3708 private void MyList_HScrolled(object sender, EventArgs e)
3709 => ((DetailsListView)sender).Refresh();
3711 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
3713 base.ScaleControl(factor, specified);
3715 ScaleChildControl(this.TabImage, factor);
3717 var tabpages = this.ListTab.TabPages.Cast<TabPage>();
3718 var listviews = tabpages.Select(x => x.Tag).Cast<ListView>();
3720 foreach (var listview in listviews)
3722 ScaleChildControl(listview, factor);
3726 internal void DoTabSearch(string searchWord, bool caseSensitive, bool useRegex, SEARCHTYPE searchType)
3728 var tab = this.CurrentTab;
3730 if (tab.AllCount == 0)
3732 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
3736 var selectedIndex = tab.SelectedIndex;
3741 case SEARCHTYPE.NextSearch: // 次を検索
3742 if (selectedIndex != -1)
3743 startIndex = Math.Min(selectedIndex + 1, tab.AllCount - 1);
3747 case SEARCHTYPE.PrevSearch: // 前を検索
3748 if (selectedIndex != -1)
3749 startIndex = Math.Max(selectedIndex - 1, 0);
3751 startIndex = tab.AllCount - 1;
3753 case SEARCHTYPE.DialogSearch: // ダイアログからの検索
3755 if (selectedIndex != -1)
3756 startIndex = selectedIndex;
3762 Func<string, bool> stringComparer;
3765 stringComparer = this.CreateSearchComparer(searchWord, useRegex, caseSensitive);
3767 catch (ArgumentException)
3769 MessageBox.Show(Properties.Resources.DoTabSearchText1, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Error);
3773 var reverse = searchType == SEARCHTYPE.PrevSearch;
3774 var foundIndex = tab.SearchPostsAll(stringComparer, startIndex, reverse)
3775 .DefaultIfEmpty(-1).First();
3777 if (foundIndex == -1)
3779 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
3783 var listView = this.CurrentListView;
3784 this.SelectListItem(listView, foundIndex);
3785 listView.EnsureVisible(foundIndex);
3788 private void MenuItemSubSearch_Click(object sender, EventArgs e)
3789 => this.ShowSearchDialog(); // 検索メニュー
3791 private void MenuItemSearchNext_Click(object sender, EventArgs e)
3793 var previousSearch = this.SearchDialog.ResultOptions;
3794 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
3796 this.SearchDialog.Reset();
3797 this.ShowSearchDialog();
3803 previousSearch.Query,
3804 previousSearch.CaseSensitive,
3805 previousSearch.UseRegex,
3806 SEARCHTYPE.NextSearch);
3809 private void MenuItemSearchPrev_Click(object sender, EventArgs e)
3811 var previousSearch = this.SearchDialog.ResultOptions;
3812 if (previousSearch == null || previousSearch.Type != SearchWordDialog.SearchType.Timeline)
3814 this.SearchDialog.Reset();
3815 this.ShowSearchDialog();
3821 previousSearch.Query,
3822 previousSearch.CaseSensitive,
3823 previousSearch.UseRegex,
3824 SEARCHTYPE.PrevSearch);
3828 /// 検索ダイアログを表示し、検索を実行します
3830 private void ShowSearchDialog()
3832 if (this.SearchDialog.ShowDialog(this) != DialogResult.OK)
3834 this.TopMost = this.settings.Common.AlwaysTop;
3837 this.TopMost = this.settings.Common.AlwaysTop;
3839 var searchOptions = this.SearchDialog.ResultOptions!;
3840 if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
3842 if (searchOptions.NewTab)
3844 var tabName = Properties.Resources.SearchResults_TabName;
3848 tabName = this.statuses.MakeTabName(tabName);
3850 catch (TabException ex)
3852 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
3855 var resultTab = new LocalSearchTabModel(tabName);
3856 this.AddNewTab(resultTab, startup: false);
3857 this.statuses.AddTab(resultTab);
3859 var targetTab = this.CurrentTab;
3861 Func<string, bool> stringComparer;
3864 stringComparer = this.CreateSearchComparer(searchOptions.Query, searchOptions.UseRegex, searchOptions.CaseSensitive);
3866 catch (ArgumentException)
3868 MessageBox.Show(Properties.Resources.DoTabSearchText1, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Error);
3872 var foundIndices = targetTab.SearchPostsAll(stringComparer).ToArray();
3873 if (foundIndices.Length == 0)
3875 MessageBox.Show(Properties.Resources.DoTabSearchText2, Properties.Resources.DoTabSearchText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
3879 var foundPosts = foundIndices.Select(x => targetTab[x]);
3880 foreach (var post in foundPosts)
3882 resultTab.AddPostQueue(post);
3885 this.statuses.DistributePosts();
3886 this.RefreshTimeline();
3888 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
3889 this.ListTab.SelectedIndex = tabIndex;
3894 searchOptions.Query,
3895 searchOptions.CaseSensitive,
3896 searchOptions.UseRegex,
3897 SEARCHTYPE.DialogSearch);
3900 else if (searchOptions.Type == SearchWordDialog.SearchType.Public)
3902 this.AddNewTabForSearch(searchOptions.Query);
3906 /// <summary>発言検索に使用するメソッドを生成します</summary>
3907 /// <exception cref="ArgumentException">
3908 /// <paramref name="useRegex"/> が true かつ、<paramref name="query"/> が不正な正規表現な場合
3910 private Func<string, bool> CreateSearchComparer(string query, bool useRegex, bool caseSensitive)
3914 var regexOption = caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;
3915 var regex = new Regex(query, regexOption);
3917 return x => regex.IsMatch(x);
3921 var comparisonType = caseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
3923 return x => x.IndexOf(query, comparisonType) != -1;
3927 private void AboutMenuItem_Click(object sender, EventArgs e)
3929 using (var about = new TweenAboutBox())
3931 about.ShowDialog(this);
3933 this.TopMost = this.settings.Common.AlwaysTop;
3936 private void JumpUnreadMenuItem_Click(object sender, EventArgs e)
3938 var bgnIdx = this.statuses.SelectedTabIndex;
3940 if (this.ImageSelector.Enabled)
3943 TabModel? foundTab = null;
3947 foreach (var (tab, index) in this.statuses.Tabs.WithIndex().Skip(bgnIdx))
3949 var unreadIndex = tab.NextUnreadIndex;
3950 if (unreadIndex != -1)
3952 this.ListTab.SelectedIndex = index;
3954 foundIndex = unreadIndex;
3959 // 未読みつからず&現在タブが先頭ではなかったら、先頭タブから現在タブの手前まで探索
3960 if (foundTab == null && bgnIdx > 0)
3962 foreach (var (tab, index) in this.statuses.Tabs.WithIndex().Take(bgnIdx))
3964 var unreadIndex = tab.NextUnreadIndex;
3965 if (unreadIndex != -1)
3967 this.ListTab.SelectedIndex = index;
3969 foundIndex = unreadIndex;
3975 DetailsListView lst;
3977 if (foundTab == null)
3979 // 全部調べたが未読見つからず→先頭タブの最新発言へ
3980 this.ListTab.SelectedIndex = 0;
3981 var tabPage = this.ListTab.TabPages[0];
3982 var tab = this.statuses.Tabs[0];
3984 if (tab.AllCount == 0)
3987 if (this.statuses.SortOrder == SortOrder.Ascending)
3988 foundIndex = tab.AllCount - 1;
3992 lst = (DetailsListView)tabPage.Tag;
3996 var foundTabIndex = this.statuses.Tabs.IndexOf(foundTab);
3997 lst = (DetailsListView)this.ListTab.TabPages[foundTabIndex].Tag;
4000 this.SelectListItem(lst, foundIndex);
4002 if (this.statuses.SortMode == ComparerMode.Id)
4004 var rowHeight = lst.SmallImageList.ImageSize.Height;
4005 if (this.statuses.SortOrder == SortOrder.Ascending && lst.Items[foundIndex].Position.Y > lst.ClientSize.Height - rowHeight - 10 ||
4006 this.statuses.SortOrder == SortOrder.Descending && lst.Items[foundIndex].Position.Y < rowHeight + 10)
4012 lst.EnsureVisible(foundIndex);
4017 lst.EnsureVisible(foundIndex);
4023 private async void StatusOpenMenuItem_Click(object sender, EventArgs e)
4025 var tab = this.CurrentTab;
4026 var post = this.CurrentPost;
4027 if (post != null && tab.TabType != MyCommon.TabUsageType.DirectMessage)
4028 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(post));
4031 private async void VerUpMenuItem_Click(object sender, EventArgs e)
4032 => await this.CheckNewVersion(false);
4034 private void RunTweenUp()
4036 var pinfo = new ProcessStartInfo
4038 UseShellExecute = true,
4039 WorkingDirectory = this.settings.SettingsPath,
4040 FileName = Path.Combine(this.settings.SettingsPath, "TweenUp3.exe"),
4041 Arguments = "\"" + Application.StartupPath + "\"",
4046 Process.Start(pinfo);
4050 MessageBox.Show("Failed to execute TweenUp3.exe.");
4054 public readonly record struct VersionInfo(
4061 /// OpenTween の最新バージョンの情報を取得します
4063 public async Task<VersionInfo> GetVersionInfoAsync()
4065 var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
4066 DateTimeUtc.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
4068 var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
4069 .ConfigureAwait(false);
4071 // 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
4072 var msgPart = responseText.Split(new[] { "\n\n", "\r\n\r\n" }, 2, StringSplitOptions.None);
4074 var msgHeader = msgPart[0].Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
4075 var msgBody = msgPart.Length == 2 ? msgPart[1] : "";
4077 msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
4079 return new VersionInfo
4081 Version = Version.Parse(msgHeader[0]),
4082 DownloadUri = new Uri(msgHeader[1]),
4083 ReleaseNote = msgBody,
4087 private async Task CheckNewVersion(bool startup = false)
4089 if (ApplicationSettings.VersionInfoUrl == null)
4090 return; // 更新チェック無効化
4094 var versionInfo = await this.GetVersionInfoAsync();
4096 if (versionInfo.Version <= Version.Parse(MyCommon.FileVersion))
4101 var msgtext = string.Format(
4102 Properties.Resources.CheckNewVersionText7,
4103 MyCommon.GetReadableVersion(),
4104 MyCommon.GetReadableVersion(versionInfo.Version));
4105 msgtext = MyCommon.ReplaceAppName(msgtext);
4109 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
4110 MessageBoxButtons.OK,
4111 MessageBoxIcon.Information);
4116 if (startup && versionInfo.Version <= this.settings.Common.SkipUpdateVersion)
4119 using var dialog = new UpdateDialog();
4121 dialog.SummaryText = string.Format(Properties.Resources.CheckNewVersionText3,
4122 MyCommon.GetReadableVersion(versionInfo.Version));
4123 dialog.DetailsText = versionInfo.ReleaseNote;
4125 if (dialog.ShowDialog(this) == DialogResult.Yes)
4127 await MyCommon.OpenInBrowserAsync(this, versionInfo.DownloadUri.OriginalString);
4129 else if (dialog.SkipButtonPressed)
4131 this.settings.Common.SkipUpdateVersion = versionInfo.Version;
4132 this.MarkSettingCommonModified();
4137 this.StatusLabel.Text = Properties.Resources.CheckNewVersionText9;
4141 Properties.Resources.CheckNewVersionText10,
4142 MyCommon.ReplaceAppName(Properties.Resources.CheckNewVersionText2),
4143 MessageBoxButtons.OK,
4144 MessageBoxIcon.Exclamation,
4145 MessageBoxDefaultButton.Button2);
4150 private void UpdateSelectedPost()
4152 // 件数関連の場合、タイトル即時書き換え
4153 if (this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.None &&
4154 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.Post &&
4155 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
4156 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
4158 this.SetMainWindowTitle();
4160 if (!this.StatusLabelUrl.Text.StartsWith("http", StringComparison.OrdinalIgnoreCase))
4161 this.SetStatusLabelUrl();
4163 if (this.settings.Common.TabIconDisp)
4165 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
4167 if (tab.UnreadCount == 0)
4169 var tabPage = this.ListTab.TabPages[index];
4170 if (tabPage.ImageIndex == 0)
4171 tabPage.ImageIndex = -1;
4177 this.ListTab.Refresh();
4180 this.DispSelectedPost();
4183 public string CreateDetailHtml(string orgdata)
4184 => this.detailHtmlFormatPreparedTemplate.Replace("%CONTENT_HTML%", orgdata);
4186 private void DispSelectedPost()
4187 => this.DispSelectedPost(false);
4189 private PostClass displayPost = new();
4192 /// サムネイル表示に使用する CancellationToken の生成元
4194 private CancellationTokenSource? thumbnailTokenSource = null;
4196 private void DispSelectedPost(bool forceupdate)
4198 var currentPost = this.CurrentPost;
4199 if (currentPost == null)
4202 var oldDisplayPost = this.displayPost;
4203 this.displayPost = currentPost;
4205 if (!forceupdate && currentPost.Equals(oldDisplayPost))
4208 var loadTasks = new List<Task>
4210 this.tweetDetailsView.ShowPostDetails(currentPost),
4213 this.SplitContainer3.Panel2Collapsed = true;
4215 if (this.settings.Common.PreviewEnable)
4217 var oldTokenSource = Interlocked.Exchange(ref this.thumbnailTokenSource, new CancellationTokenSource());
4218 oldTokenSource?.Cancel();
4220 var token = this.thumbnailTokenSource!.Token;
4221 loadTasks.Add(this.tweetThumbnail1.ShowThumbnailAsync(currentPost, token));
4224 async Task DelayedTasks()
4228 await Task.WhenAll(loadTasks);
4230 catch (OperationCanceledException)
4235 // サムネイルの読み込みを待たずに次に選択されたツイートを表示するため await しない
4239 private async void MatomeMenuItem_Click(object sender, EventArgs e)
4240 => await this.OpenApplicationWebsite();
4242 private async Task OpenApplicationWebsite()
4243 => await MyCommon.OpenInBrowserAsync(this, ApplicationSettings.WebsiteUrl);
4245 private async void ShortcutKeyListMenuItem_Click(object sender, EventArgs e)
4246 => await MyCommon.OpenInBrowserAsync(this, ApplicationSettings.ShortcutKeyUrl);
4248 private async void ListTab_KeyDown(object sender, KeyEventArgs e)
4250 var tab = this.CurrentTab;
4251 if (tab.TabType == MyCommon.TabUsageType.PublicSearch)
4253 var pnl = this.CurrentTabPage.Controls["panelSearch"];
4254 if (pnl.Controls["comboSearch"].Focused ||
4255 pnl.Controls["comboLang"].Focused ||
4256 pnl.Controls["buttonSearch"].Focused) return;
4259 if (e.Control || e.Shift || e.Alt)
4262 if (this.CommonKeyDown(e.KeyData, FocusedControl.ListTab, out var asyncTask))
4265 e.SuppressKeyPress = true;
4268 if (asyncTask != null)
4272 private ShortcutCommand[] shortcutCommands = Array.Empty<ShortcutCommand>();
4274 private void InitializeShortcuts()
4276 this.shortcutCommands = new[]
4278 // リストのカーソル移動関係(上下キー、PageUp/Downに該当)
4279 ShortcutCommand.Create(Keys.J, Keys.Control | Keys.J, Keys.Shift | Keys.J, Keys.Control | Keys.Shift | Keys.J)
4280 .FocusedOn(FocusedControl.ListTab)
4281 .Do(() => SendKeys.Send("{DOWN}")),
4283 ShortcutCommand.Create(Keys.K, Keys.Control | Keys.K, Keys.Shift | Keys.K, Keys.Control | Keys.Shift | Keys.K)
4284 .FocusedOn(FocusedControl.ListTab)
4285 .Do(() => SendKeys.Send("{UP}")),
4287 ShortcutCommand.Create(Keys.F, Keys.Shift | Keys.F)
4288 .FocusedOn(FocusedControl.ListTab)
4289 .Do(() => SendKeys.Send("{PGDN}")),
4291 ShortcutCommand.Create(Keys.B, Keys.Shift | Keys.B)
4292 .FocusedOn(FocusedControl.ListTab)
4293 .Do(() => SendKeys.Send("{PGUP}")),
4295 ShortcutCommand.Create(Keys.F1)
4296 .Do(() => this.OpenApplicationWebsite()),
4298 ShortcutCommand.Create(Keys.F3)
4299 .Do(() => this.MenuItemSearchNext_Click(this.MenuItemSearchNext, EventArgs.Empty)),
4301 ShortcutCommand.Create(Keys.F5)
4302 .Do(() => this.DoRefresh()),
4304 ShortcutCommand.Create(Keys.F6)
4305 .Do(() => this.RefreshTabAsync<MentionsTabModel>()),
4307 ShortcutCommand.Create(Keys.F7)
4308 .Do(() => this.RefreshTabAsync<DirectMessagesTabModel>()),
4310 ShortcutCommand.Create(Keys.Space, Keys.ProcessKey)
4311 .NotFocusedOn(FocusedControl.StatusText)
4314 this.CurrentTab.ClearAnchor();
4315 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
4318 ShortcutCommand.Create(Keys.G)
4319 .NotFocusedOn(FocusedControl.StatusText)
4322 this.CurrentTab.ClearAnchor();
4323 this.ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty);
4326 ShortcutCommand.Create(Keys.Right, Keys.N)
4327 .FocusedOn(FocusedControl.ListTab)
4328 .Do(() => this.GoRelPost(forward: true)),
4330 ShortcutCommand.Create(Keys.Left, Keys.P)
4331 .FocusedOn(FocusedControl.ListTab)
4332 .Do(() => this.GoRelPost(forward: false)),
4334 ShortcutCommand.Create(Keys.OemPeriod)
4335 .FocusedOn(FocusedControl.ListTab)
4336 .Do(() => this.GoAnchor()),
4338 ShortcutCommand.Create(Keys.I)
4339 .FocusedOn(FocusedControl.ListTab)
4340 .OnlyWhen(() => this.StatusText.Enabled)
4341 .Do(() => this.StatusText.Focus()),
4343 ShortcutCommand.Create(Keys.Enter)
4344 .FocusedOn(FocusedControl.ListTab)
4345 .Do(() => this.ListItemDoubleClickAction()),
4347 ShortcutCommand.Create(Keys.R)
4348 .FocusedOn(FocusedControl.ListTab)
4349 .Do(() => this.DoRefresh()),
4351 ShortcutCommand.Create(Keys.L)
4352 .FocusedOn(FocusedControl.ListTab)
4355 this.CurrentTab.ClearAnchor();
4356 this.GoPost(forward: true);
4359 ShortcutCommand.Create(Keys.H)
4360 .FocusedOn(FocusedControl.ListTab)
4363 this.CurrentTab.ClearAnchor();
4364 this.GoPost(forward: false);
4367 ShortcutCommand.Create(Keys.Z, Keys.Oemcomma)
4368 .FocusedOn(FocusedControl.ListTab)
4371 this.CurrentTab.ClearAnchor();
4375 ShortcutCommand.Create(Keys.S)
4376 .FocusedOn(FocusedControl.ListTab)
4379 this.CurrentTab.ClearAnchor();
4380 this.GoNextTab(forward: true);
4383 ShortcutCommand.Create(Keys.A)
4384 .FocusedOn(FocusedControl.ListTab)
4387 this.CurrentTab.ClearAnchor();
4388 this.GoNextTab(forward: false);
4391 // ] in_reply_to参照元へ戻る
4392 ShortcutCommand.Create(Keys.Oem4)
4393 .FocusedOn(FocusedControl.ListTab)
4396 this.CurrentTab.ClearAnchor();
4397 return this.GoInReplyToPostTree();
4400 // [ in_reply_toへジャンプ
4401 ShortcutCommand.Create(Keys.Oem6)
4402 .FocusedOn(FocusedControl.ListTab)
4405 this.CurrentTab.ClearAnchor();
4406 this.GoBackInReplyToPostTree();
4409 ShortcutCommand.Create(Keys.Escape)
4410 .FocusedOn(FocusedControl.ListTab)
4413 this.CurrentTab.ClearAnchor();
4414 var tab = this.CurrentTab;
4415 var tabtype = tab.TabType;
4416 if (tabtype == MyCommon.TabUsageType.Related || tabtype == MyCommon.TabUsageType.UserTimeline || tabtype == MyCommon.TabUsageType.PublicSearch || tabtype == MyCommon.TabUsageType.SearchResults)
4418 this.RemoveSpecifiedTab(tab.TabName, false);
4419 this.SaveConfigsTabs();
4423 // 上下キー, PageUp/Downキー, Home/Endキー は既定の動作を残しつつアンカー初期化
4424 ShortcutCommand.Create(Keys.Up, Keys.Down, Keys.PageUp, Keys.PageDown, Keys.Home, Keys.End)
4425 .FocusedOn(FocusedControl.ListTab)
4426 .Do(() => this.CurrentTab.ClearAnchor(), preventDefault: false),
4428 // PreviewKeyDownEventArgs.IsInputKey を true にしてスクロールを発生させる
4429 ShortcutCommand.Create(Keys.Up, Keys.Down)
4430 .FocusedOn(FocusedControl.PostBrowser)
4433 ShortcutCommand.Create(Keys.Control | Keys.R)
4434 .Do(() => this.MakeReplyText()),
4436 ShortcutCommand.Create(Keys.Control | Keys.D)
4437 .Do(() => this.DoStatusDelete()),
4439 ShortcutCommand.Create(Keys.Control | Keys.M)
4440 .Do(() => this.MakeDirectMessageText()),
4442 ShortcutCommand.Create(Keys.Control | Keys.S)
4443 .Do(() => this.FavoriteChange(favAdd: true)),
4445 ShortcutCommand.Create(Keys.Control | Keys.I)
4446 .Do(() => this.DoRepliedStatusOpen()),
4448 ShortcutCommand.Create(Keys.Control | Keys.Q)
4449 .Do(() => this.DoQuoteOfficial()),
4451 ShortcutCommand.Create(Keys.Control | Keys.B)
4452 .Do(() => this.ReadedStripMenuItem_Click(this.ReadedStripMenuItem, EventArgs.Empty)),
4454 ShortcutCommand.Create(Keys.Control | Keys.T)
4455 .Do(() => this.HashManageMenuItem_Click(this.HashManageMenuItem, EventArgs.Empty)),
4457 ShortcutCommand.Create(Keys.Control | Keys.L)
4458 .Do(() => this.UrlConvertAutoToolStripMenuItem_Click(this.UrlConvertAutoToolStripMenuItem, EventArgs.Empty)),
4460 ShortcutCommand.Create(Keys.Control | Keys.Y)
4461 .NotFocusedOn(FocusedControl.PostBrowser)
4462 .Do(() => this.MultiLineMenuItem_Click(this.MultiLineMenuItem, EventArgs.Empty)),
4464 ShortcutCommand.Create(Keys.Control | Keys.F)
4465 .Do(() => this.MenuItemSubSearch_Click(this.MenuItemSubSearch, EventArgs.Empty)),
4467 ShortcutCommand.Create(Keys.Control | Keys.U)
4468 .Do(() => this.ShowUserTimeline()),
4470 ShortcutCommand.Create(Keys.Control | Keys.H)
4471 .Do(() => this.AuthorOpenInBrowserMenuItem_Click(this.AuthorOpenInBrowserContextMenuItem, EventArgs.Empty)),
4473 ShortcutCommand.Create(Keys.Control | Keys.O)
4474 .Do(() => this.StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty)),
4476 ShortcutCommand.Create(Keys.Control | Keys.E)
4477 .Do(() => this.OpenURLMenuItem_Click(this.OpenURLMenuItem, EventArgs.Empty)),
4479 ShortcutCommand.Create(Keys.Control | Keys.Home, Keys.Control | Keys.End)
4480 .FocusedOn(FocusedControl.ListTab)
4481 .Do(() => this.selectionDebouncer.Call(), preventDefault: false),
4483 ShortcutCommand.Create(Keys.Control | Keys.N)
4484 .FocusedOn(FocusedControl.ListTab)
4485 .Do(() => this.GoNextTab(forward: true)),
4487 ShortcutCommand.Create(Keys.Control | Keys.P)
4488 .FocusedOn(FocusedControl.ListTab)
4489 .Do(() => this.GoNextTab(forward: false)),
4491 ShortcutCommand.Create(Keys.Control | Keys.C, Keys.Control | Keys.Insert)
4492 .FocusedOn(FocusedControl.ListTab)
4493 .Do(() => this.CopyStot()),
4495 // タブダイレクト選択(Ctrl+1~8,Ctrl+9)
4496 ShortcutCommand.Create(Keys.Control | Keys.D1)
4497 .FocusedOn(FocusedControl.ListTab)
4498 .OnlyWhen(() => this.statuses.Tabs.Count >= 1)
4499 .Do(() => this.ListTab.SelectedIndex = 0),
4501 ShortcutCommand.Create(Keys.Control | Keys.D2)
4502 .FocusedOn(FocusedControl.ListTab)
4503 .OnlyWhen(() => this.statuses.Tabs.Count >= 2)
4504 .Do(() => this.ListTab.SelectedIndex = 1),
4506 ShortcutCommand.Create(Keys.Control | Keys.D3)
4507 .FocusedOn(FocusedControl.ListTab)
4508 .OnlyWhen(() => this.statuses.Tabs.Count >= 3)
4509 .Do(() => this.ListTab.SelectedIndex = 2),
4511 ShortcutCommand.Create(Keys.Control | Keys.D4)
4512 .FocusedOn(FocusedControl.ListTab)
4513 .OnlyWhen(() => this.statuses.Tabs.Count >= 4)
4514 .Do(() => this.ListTab.SelectedIndex = 3),
4516 ShortcutCommand.Create(Keys.Control | Keys.D5)
4517 .FocusedOn(FocusedControl.ListTab)
4518 .OnlyWhen(() => this.statuses.Tabs.Count >= 5)
4519 .Do(() => this.ListTab.SelectedIndex = 4),
4521 ShortcutCommand.Create(Keys.Control | Keys.D6)
4522 .FocusedOn(FocusedControl.ListTab)
4523 .OnlyWhen(() => this.statuses.Tabs.Count >= 6)
4524 .Do(() => this.ListTab.SelectedIndex = 5),
4526 ShortcutCommand.Create(Keys.Control | Keys.D7)
4527 .FocusedOn(FocusedControl.ListTab)
4528 .OnlyWhen(() => this.statuses.Tabs.Count >= 7)
4529 .Do(() => this.ListTab.SelectedIndex = 6),
4531 ShortcutCommand.Create(Keys.Control | Keys.D8)
4532 .FocusedOn(FocusedControl.ListTab)
4533 .OnlyWhen(() => this.statuses.Tabs.Count >= 8)
4534 .Do(() => this.ListTab.SelectedIndex = 7),
4536 ShortcutCommand.Create(Keys.Control | Keys.D9)
4537 .FocusedOn(FocusedControl.ListTab)
4538 .Do(() => this.ListTab.SelectedIndex = this.statuses.Tabs.Count - 1),
4540 ShortcutCommand.Create(Keys.Control | Keys.A)
4541 .FocusedOn(FocusedControl.StatusText)
4542 .Do(() => this.StatusText.SelectAll()),
4544 ShortcutCommand.Create(Keys.Control | Keys.V)
4545 .FocusedOn(FocusedControl.StatusText)
4546 .Do(() => this.ProcClipboardFromStatusTextWhenCtrlPlusV()),
4548 ShortcutCommand.Create(Keys.Control | Keys.Up)
4549 .FocusedOn(FocusedControl.StatusText)
4550 .Do(() => this.StatusTextHistoryBack()),
4552 ShortcutCommand.Create(Keys.Control | Keys.Down)
4553 .FocusedOn(FocusedControl.StatusText)
4554 .Do(() => this.StatusTextHistoryForward()),
4556 ShortcutCommand.Create(Keys.Control | Keys.PageUp, Keys.Control | Keys.P)
4557 .FocusedOn(FocusedControl.StatusText)
4560 if (this.ListTab.SelectedIndex == 0)
4562 this.ListTab.SelectedIndex = this.ListTab.TabCount - 1;
4566 this.ListTab.SelectedIndex -= 1;
4568 this.StatusText.Focus();
4571 ShortcutCommand.Create(Keys.Control | Keys.PageDown, Keys.Control | Keys.N)
4572 .FocusedOn(FocusedControl.StatusText)
4575 if (this.ListTab.SelectedIndex == this.ListTab.TabCount - 1)
4577 this.ListTab.SelectedIndex = 0;
4581 this.ListTab.SelectedIndex += 1;
4583 this.StatusText.Focus();
4586 ShortcutCommand.Create(Keys.Control | Keys.Y)
4587 .FocusedOn(FocusedControl.PostBrowser)
4590 var multiline = !this.settings.Local.StatusMultiline;
4591 this.settings.Local.StatusMultiline = multiline;
4592 this.MultiLineMenuItem.Checked = multiline;
4593 this.MultiLineMenuItem_Click(this.MultiLineMenuItem, EventArgs.Empty);
4596 ShortcutCommand.Create(Keys.Shift | Keys.F3)
4597 .Do(() => this.MenuItemSearchPrev_Click(this.MenuItemSearchPrev, EventArgs.Empty)),
4599 ShortcutCommand.Create(Keys.Shift | Keys.F5)
4600 .Do(() => this.DoRefreshMore()),
4602 ShortcutCommand.Create(Keys.Shift | Keys.F6)
4603 .Do(() => this.RefreshTabAsync<MentionsTabModel>(backward: true)),
4605 ShortcutCommand.Create(Keys.Shift | Keys.F7)
4606 .Do(() => this.RefreshTabAsync<DirectMessagesTabModel>(backward: true)),
4608 ShortcutCommand.Create(Keys.Shift | Keys.R)
4609 .NotFocusedOn(FocusedControl.StatusText)
4610 .Do(() => this.DoRefreshMore()),
4612 ShortcutCommand.Create(Keys.Shift | Keys.H)
4613 .FocusedOn(FocusedControl.ListTab)
4614 .Do(() => this.GoTopEnd(goTop: true)),
4616 ShortcutCommand.Create(Keys.Shift | Keys.L)
4617 .FocusedOn(FocusedControl.ListTab)
4618 .Do(() => this.GoTopEnd(goTop: false)),
4620 ShortcutCommand.Create(Keys.Shift | Keys.M)
4621 .FocusedOn(FocusedControl.ListTab)
4622 .Do(() => this.GoMiddle()),
4624 ShortcutCommand.Create(Keys.Shift | Keys.G)
4625 .FocusedOn(FocusedControl.ListTab)
4626 .Do(() => this.GoLast()),
4628 ShortcutCommand.Create(Keys.Shift | Keys.Z)
4629 .FocusedOn(FocusedControl.ListTab)
4630 .Do(() => this.MoveMiddle()),
4632 ShortcutCommand.Create(Keys.Shift | Keys.Oem4)
4633 .FocusedOn(FocusedControl.ListTab)
4634 .Do(() => this.GoBackInReplyToPostTree(parallel: true, isForward: false)),
4636 ShortcutCommand.Create(Keys.Shift | Keys.Oem6)
4637 .FocusedOn(FocusedControl.ListTab)
4638 .Do(() => this.GoBackInReplyToPostTree(parallel: true, isForward: true)),
4640 // お気に入り前後ジャンプ(SHIFT+N←/P→)
4641 ShortcutCommand.Create(Keys.Shift | Keys.Right, Keys.Shift | Keys.N)
4642 .FocusedOn(FocusedControl.ListTab)
4643 .Do(() => this.GoFav(forward: true)),
4645 // お気に入り前後ジャンプ(SHIFT+N←/P→)
4646 ShortcutCommand.Create(Keys.Shift | Keys.Left, Keys.Shift | Keys.P)
4647 .FocusedOn(FocusedControl.ListTab)
4648 .Do(() => this.GoFav(forward: false)),
4650 ShortcutCommand.Create(Keys.Shift | Keys.Space)
4651 .FocusedOn(FocusedControl.ListTab)
4652 .Do(() => this.GoBackSelectPostChain()),
4654 ShortcutCommand.Create(Keys.Alt | Keys.R)
4655 .Do(() => this.DoReTweetOfficial(isConfirm: true)),
4657 ShortcutCommand.Create(Keys.Alt | Keys.P)
4658 .OnlyWhen(() => this.CurrentPost != null)
4659 .Do(() => this.DoShowUserStatus(this.CurrentPost!.ScreenName, showInputDialog: false)),
4661 ShortcutCommand.Create(Keys.Alt | Keys.Up)
4662 .Do(() => this.tweetDetailsView.ScrollDownPostBrowser(forward: false)),
4664 ShortcutCommand.Create(Keys.Alt | Keys.Down)
4665 .Do(() => this.tweetDetailsView.ScrollDownPostBrowser(forward: true)),
4667 ShortcutCommand.Create(Keys.Alt | Keys.PageUp)
4668 .Do(() => this.tweetDetailsView.PageDownPostBrowser(forward: false)),
4670 ShortcutCommand.Create(Keys.Alt | Keys.PageDown)
4671 .Do(() => this.tweetDetailsView.PageDownPostBrowser(forward: true)),
4673 // 別タブの同じ書き込みへ(ALT+←/→)
4674 ShortcutCommand.Create(Keys.Alt | Keys.Right)
4675 .FocusedOn(FocusedControl.ListTab)
4676 .Do(() => this.GoSamePostToAnotherTab(left: false)),
4678 ShortcutCommand.Create(Keys.Alt | Keys.Left)
4679 .FocusedOn(FocusedControl.ListTab)
4680 .Do(() => this.GoSamePostToAnotherTab(left: true)),
4682 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.R)
4683 .Do(() => this.MakeReplyText(atAll: true)),
4685 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.C, Keys.Control | Keys.Shift | Keys.Insert)
4686 .Do(() => this.CopyIdUri()),
4688 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.F)
4689 .OnlyWhen(() => this.CurrentTab.TabType == MyCommon.TabUsageType.PublicSearch)
4690 .Do(() => this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus()),
4692 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.L)
4693 .Do(() => this.DoQuoteOfficial()),
4695 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.S)
4696 .Do(() => this.FavoriteChange(favAdd: false)),
4698 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.B)
4699 .Do(() => this.UnreadStripMenuItem_Click(this.UnreadStripMenuItem, EventArgs.Empty)),
4701 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.T)
4702 .Do(() => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty)),
4704 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.P)
4705 .Do(() => this.ImageSelectMenuItem_Click(this.ImageSelectMenuItem, EventArgs.Empty)),
4707 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.H)
4708 .Do(() => this.DoMoveToRTHome()),
4710 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Up)
4711 .FocusedOn(FocusedControl.StatusText)
4714 var tab = this.CurrentTab;
4715 var selectedIndex = tab.SelectedIndex;
4716 if (selectedIndex != -1 && selectedIndex > 0)
4718 var listView = this.CurrentListView;
4719 var idx = selectedIndex - 1;
4720 this.SelectListItem(listView, idx);
4721 listView.EnsureVisible(idx);
4725 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Down)
4726 .FocusedOn(FocusedControl.StatusText)
4729 var tab = this.CurrentTab;
4730 var selectedIndex = tab.SelectedIndex;
4731 if (selectedIndex != -1 && selectedIndex < tab.AllCount - 1)
4733 var listView = this.CurrentListView;
4734 var idx = selectedIndex + 1;
4735 this.SelectListItem(listView, idx);
4736 listView.EnsureVisible(idx);
4740 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.Space)
4741 .FocusedOn(FocusedControl.StatusText)
4744 if (this.StatusText.SelectionStart > 0)
4746 var endidx = this.StatusText.SelectionStart - 1;
4748 for (var i = this.StatusText.SelectionStart - 1; i >= 0; i--)
4750 var c = this.StatusText.Text[i];
4751 if (char.IsLetterOrDigit(c) || c == '_')
4757 startstr = this.StatusText.Text.Substring(i + 1, endidx - i);
4758 var cnt = this.AtIdSupl.ItemCount;
4759 this.ShowSuplDialog(this.StatusText, this.AtIdSupl, startstr.Length + 1, startstr);
4760 if (this.AtIdSupl.ItemCount != cnt)
4761 this.MarkSettingAtIdModified();
4765 startstr = this.StatusText.Text.Substring(i + 1, endidx - i);
4766 this.ShowSuplDialog(this.StatusText, this.HashSupl, startstr.Length + 1, startstr);
4776 // ソートダイレクト選択(Ctrl+Shift+1~8,Ctrl+Shift+9)
4777 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D1)
4778 .FocusedOn(FocusedControl.ListTab)
4779 .Do(() => this.SetSortColumnByDisplayIndex(0)),
4781 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D2)
4782 .FocusedOn(FocusedControl.ListTab)
4783 .Do(() => this.SetSortColumnByDisplayIndex(1)),
4785 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D3)
4786 .FocusedOn(FocusedControl.ListTab)
4787 .Do(() => this.SetSortColumnByDisplayIndex(2)),
4789 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D4)
4790 .FocusedOn(FocusedControl.ListTab)
4791 .Do(() => this.SetSortColumnByDisplayIndex(3)),
4793 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D5)
4794 .FocusedOn(FocusedControl.ListTab)
4795 .Do(() => this.SetSortColumnByDisplayIndex(4)),
4797 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D6)
4798 .FocusedOn(FocusedControl.ListTab)
4799 .Do(() => this.SetSortColumnByDisplayIndex(5)),
4801 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D7)
4802 .FocusedOn(FocusedControl.ListTab)
4803 .Do(() => this.SetSortColumnByDisplayIndex(6)),
4805 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D8)
4806 .FocusedOn(FocusedControl.ListTab)
4807 .Do(() => this.SetSortColumnByDisplayIndex(7)),
4809 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.D9)
4810 .FocusedOn(FocusedControl.ListTab)
4811 .Do(() => this.SetSortLastColumn()),
4813 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.S)
4814 .FocusedOn(FocusedControl.ListTab)
4815 .Do(() => this.FavoritesRetweetOfficial()),
4817 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.R)
4818 .FocusedOn(FocusedControl.ListTab)
4819 .Do(() => this.FavoritesRetweetUnofficial()),
4821 ShortcutCommand.Create(Keys.Control | Keys.Alt | Keys.H)
4822 .FocusedOn(FocusedControl.ListTab)
4823 .Do(() => this.OpenUserAppointUrl()),
4825 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.R)
4826 .FocusedOn(FocusedControl.PostBrowser)
4827 .Do(() => this.DoReTweetUnofficial()),
4829 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.T)
4830 .OnlyWhen(() => this.ExistCurrentPost)
4831 .Do(() => this.tweetDetailsView.DoTranslation()),
4833 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.R)
4834 .Do(() => this.DoReTweetUnofficial()),
4836 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.C, Keys.Alt | Keys.Shift | Keys.Insert)
4837 .Do(() => this.CopyUserId()),
4839 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Up)
4840 .Do(() => this.tweetThumbnail1.ScrollUp()),
4842 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Down)
4843 .Do(() => this.tweetThumbnail1.ScrollDown()),
4845 ShortcutCommand.Create(Keys.Alt | Keys.Shift | Keys.Enter)
4846 .FocusedOn(FocusedControl.ListTab)
4847 .OnlyWhen(() => !this.SplitContainer3.Panel2Collapsed)
4848 .Do(() => this.OpenThumbnailPicture(this.tweetThumbnail1.Thumbnail)),
4852 internal bool CommonKeyDown(Keys keyData, FocusedControl focusedOn, out Task? asyncTask)
4854 // Task を返す非同期処理があれば asyncTask に代入する
4857 // ShortcutCommand に対応しているコマンドはここで処理される
4858 foreach (var command in this.shortcutCommands)
4860 if (command.IsMatch(keyData, focusedOn))
4862 asyncTask = command.RunCommand();
4863 return command.PreventDefault;
4870 private void GoNextTab(bool forward)
4872 var idx = this.statuses.SelectedTabIndex;
4873 var tabCount = this.statuses.Tabs.Count;
4877 if (idx > tabCount - 1) idx = 0;
4882 if (idx < 0) idx = tabCount - 1;
4884 this.ListTab.SelectedIndex = idx;
4887 private void CopyStot()
4889 var sb = new StringBuilder();
4890 var tab = this.CurrentTab;
4891 var isProtected = false;
4892 var isDm = tab.TabType == MyCommon.TabUsageType.DirectMessage;
4893 foreach (var post in tab.SelectedPosts)
4895 if (post.IsDeleted) continue;
4898 if (post.RetweetedId != null)
4899 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.RetweetedId, Environment.NewLine);
4901 sb.AppendFormat("{0}:{1} [https://twitter.com/{0}/status/{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
4905 sb.AppendFormat("{0}:{1} [{2}]{3}", post.ScreenName, post.TextSingleLine, post.StatusId, Environment.NewLine);
4910 MessageBox.Show(Properties.Resources.CopyStotText1);
4914 var clstr = sb.ToString();
4917 Clipboard.SetDataObject(clstr, false, 5, 100);
4919 catch (Exception ex)
4921 MessageBox.Show(ex.Message);
4926 private void CopyIdUri()
4928 var tab = this.CurrentTab;
4929 if (tab == null || tab is DirectMessagesTabModel)
4932 var copyUrls = new List<string>();
4933 foreach (var post in tab.SelectedPosts)
4934 copyUrls.Add(MyCommon.GetStatusUrl(post));
4936 if (copyUrls.Count == 0)
4941 Clipboard.SetDataObject(string.Join(Environment.NewLine, copyUrls), false, 5, 100);
4943 catch (ExternalException ex)
4945 MessageBox.Show(ex.Message);
4949 private void GoFav(bool forward)
4951 var tab = this.CurrentTab;
4952 if (tab.AllCount == 0)
4955 var selectedIndex = tab.SelectedIndex;
4963 if (selectedIndex == -1)
4969 fIdx = selectedIndex + 1;
4970 if (fIdx > tab.AllCount - 1)
4973 toIdx = tab.AllCount;
4978 if (selectedIndex == -1)
4980 fIdx = tab.AllCount - 1;
4984 fIdx = selectedIndex - 1;
4992 for (var idx = fIdx; idx != toIdx; idx += stp)
4996 var listView = this.CurrentListView;
4997 this.SelectListItem(listView, idx);
4998 listView.EnsureVisible(idx);
5004 private void GoSamePostToAnotherTab(bool left)
5006 var tab = this.CurrentTab;
5008 // Directタブは対象外(見つかるはずがない)
5009 if (tab.TabType == MyCommon.TabUsageType.DirectMessage)
5012 var selectedStatusId = tab.SelectedStatusId;
5013 if (selectedStatusId == -1)
5016 int fIdx, toIdx, stp;
5021 if (this.ListTab.SelectedIndex == 0)
5027 fIdx = this.ListTab.SelectedIndex - 1;
5035 if (this.ListTab.SelectedIndex == this.ListTab.TabCount - 1)
5041 fIdx = this.ListTab.SelectedIndex + 1;
5043 toIdx = this.ListTab.TabCount;
5047 for (var tabidx = fIdx; tabidx != toIdx; tabidx += stp)
5049 var targetTab = this.statuses.Tabs[tabidx];
5052 if (targetTab.TabType == MyCommon.TabUsageType.DirectMessage)
5055 var foundIndex = targetTab.IndexOf(selectedStatusId);
5056 if (foundIndex != -1)
5058 this.ListTab.SelectedIndex = tabidx;
5059 var listView = this.CurrentListView;
5060 this.SelectListItem(listView, foundIndex);
5061 listView.EnsureVisible(foundIndex);
5067 private void GoPost(bool forward)
5069 var tab = this.CurrentTab;
5070 var currentPost = this.CurrentPost;
5072 if (currentPost == null)
5075 var selectedIndex = tab.SelectedIndex;
5077 int fIdx, toIdx, stp;
5081 fIdx = selectedIndex + 1;
5082 if (fIdx > tab.AllCount - 1) return;
5083 toIdx = tab.AllCount;
5088 fIdx = selectedIndex - 1;
5089 if (fIdx < 0) return;
5095 if (currentPost.RetweetedBy == null)
5097 name = currentPost.ScreenName;
5101 name = currentPost.RetweetedBy;
5103 for (var idx = fIdx; idx != toIdx; idx += stp)
5105 var post = tab[idx];
5106 if (post.RetweetedId == null)
5108 if (post.ScreenName == name)
5110 var listView = this.CurrentListView;
5111 this.SelectListItem(listView, idx);
5112 listView.EnsureVisible(idx);
5118 if (post.RetweetedBy == name)
5120 var listView = this.CurrentListView;
5121 this.SelectListItem(listView, idx);
5122 listView.EnsureVisible(idx);
5129 private void GoRelPost(bool forward)
5131 var tab = this.CurrentTab;
5132 var selectedIndex = tab.SelectedIndex;
5134 if (selectedIndex == -1)
5137 int fIdx, toIdx, stp;
5141 fIdx = selectedIndex + 1;
5142 if (fIdx > tab.AllCount - 1) return;
5143 toIdx = tab.AllCount;
5148 fIdx = selectedIndex - 1;
5149 if (fIdx < 0) return;
5154 var anchorPost = tab.AnchorPost;
5155 if (anchorPost == null)
5157 var currentPost = this.CurrentPost;
5158 if (currentPost == null)
5161 anchorPost = currentPost;
5162 tab.AnchorPost = currentPost;
5165 for (var idx = fIdx; idx != toIdx; idx += stp)
5167 var post = tab[idx];
5168 if (post.ScreenName == anchorPost.ScreenName ||
5169 post.RetweetedBy == anchorPost.ScreenName ||
5170 post.ScreenName == anchorPost.RetweetedBy ||
5171 (!MyCommon.IsNullOrEmpty(post.RetweetedBy) && post.RetweetedBy == anchorPost.RetweetedBy) ||
5172 anchorPost.ReplyToList.Any(x => x.UserId == post.UserId) ||
5173 anchorPost.ReplyToList.Any(x => x.UserId == post.RetweetedByUserId) ||
5174 post.ReplyToList.Any(x => x.UserId == anchorPost.UserId) ||
5175 post.ReplyToList.Any(x => x.UserId == anchorPost.RetweetedByUserId))
5177 var listView = this.CurrentListView;
5178 this.SelectListItem(listView, idx);
5179 listView.EnsureVisible(idx);
5185 private void GoAnchor()
5187 var anchorStatusId = this.CurrentTab.AnchorStatusId;
5188 if (anchorStatusId == null)
5191 var idx = this.CurrentTab.IndexOf(anchorStatusId.Value);
5195 var listView = this.CurrentListView;
5196 this.SelectListItem(listView, idx);
5197 listView.EnsureVisible(idx);
5200 private void GoTopEnd(bool goTop)
5202 var listView = this.CurrentListView;
5203 if (listView.VirtualListSize == 0)
5211 item = listView.GetItemAt(0, 25);
5219 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
5221 idx = listView.VirtualListSize - 1;
5225 this.SelectListItem(listView, idx);
5228 private void GoMiddle()
5230 var listView = this.CurrentListView;
5231 if (listView.VirtualListSize == 0)
5239 item = listView.GetItemAt(0, 0);
5249 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
5252 idx2 = listView.VirtualListSize - 1;
5258 idx3 = (idx1 + idx2) / 2;
5260 this.SelectListItem(listView, idx3);
5263 private void GoLast()
5265 var listView = this.CurrentListView;
5266 if (listView.VirtualListSize == 0) return;
5268 if (this.statuses.SortOrder == SortOrder.Ascending)
5270 this.SelectListItem(listView, listView.VirtualListSize - 1);
5271 listView.EnsureVisible(listView.VirtualListSize - 1);
5275 this.SelectListItem(listView, 0);
5276 listView.EnsureVisible(0);
5280 private void MoveTop()
5282 var listView = this.CurrentListView;
5283 if (listView.SelectedIndices.Count == 0) return;
5284 var idx = listView.SelectedIndices[0];
5285 if (this.statuses.SortOrder == SortOrder.Ascending)
5287 listView.EnsureVisible(listView.VirtualListSize - 1);
5291 listView.EnsureVisible(0);
5293 listView.EnsureVisible(idx);
5296 private async Task GoInReplyToPostTree()
5298 var curTabClass = this.CurrentTab;
5299 var currentPost = this.CurrentPost;
5301 if (currentPost == null)
5304 if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && currentPost.InReplyToStatusId == null && currentPost.TextFromApi.Contains("@"))
5308 var post = await this.tw.GetStatusApi(false, currentPost.StatusId);
5310 currentPost.InReplyToStatusId = post.InReplyToStatusId;
5311 currentPost.InReplyToUser = post.InReplyToUser;
5312 currentPost.IsReply = post.IsReply;
5313 this.listCache?.PurgeCache();
5315 var index = curTabClass.SelectedIndex;
5316 this.CurrentListView.RedrawItems(index, index, false);
5318 catch (WebApiException ex)
5320 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
5324 if (!(this.ExistCurrentPost && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)) return;
5326 if (this.replyChains == null || (this.replyChains.Count > 0 && this.replyChains.Peek().InReplyToId != currentPost.StatusId))
5328 this.replyChains = new Stack<ReplyChain>();
5330 this.replyChains.Push(new ReplyChain(currentPost.StatusId, currentPost.InReplyToStatusId.Value, curTabClass));
5333 string inReplyToTabName;
5334 var inReplyToId = currentPost.InReplyToStatusId.Value;
5335 var inReplyToUser = currentPost.InReplyToUser;
5337 var inReplyToPosts = from tab in this.statuses.Tabs
5338 orderby tab != curTabClass
5339 from post in tab.Posts.Values
5340 where post.StatusId == inReplyToId
5341 let index = tab.IndexOf(post.StatusId)
5343 select new { Tab = tab, Index = index };
5345 var inReplyPost = inReplyToPosts.FirstOrDefault();
5346 if (inReplyPost == null)
5350 await Task.Run(async () =>
5352 var post = await this.tw.GetStatusApi(false, currentPost.InReplyToStatusId.Value)
5353 .ConfigureAwait(false);
5356 this.statuses.AddPost(post);
5357 this.statuses.DistributePosts();
5360 catch (WebApiException ex)
5362 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
5363 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
5367 this.RefreshTimeline();
5369 inReplyPost = inReplyToPosts.FirstOrDefault();
5370 if (inReplyPost == null)
5372 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
5376 inReplyToTabName = inReplyPost.Tab.TabName;
5377 inReplyToIndex = inReplyPost.Index;
5379 var tabIndex = this.statuses.Tabs.IndexOf(inReplyToTabName);
5380 var tabPage = this.ListTab.TabPages[tabIndex];
5381 var listView = (DetailsListView)tabPage.Tag;
5383 if (this.CurrentTabName != inReplyToTabName)
5385 this.ListTab.SelectedIndex = tabIndex;
5388 this.SelectListItem(listView, inReplyToIndex);
5389 listView.EnsureVisible(inReplyToIndex);
5392 private void GoBackInReplyToPostTree(bool parallel = false, bool isForward = true)
5394 var curTabClass = this.CurrentTab;
5395 var currentPost = this.CurrentPost;
5397 if (currentPost == null)
5402 if (currentPost.InReplyToStatusId != null)
5404 var posts = from t in this.statuses.Tabs
5406 where p.Value.StatusId != currentPost.StatusId && p.Value.InReplyToStatusId == currentPost.InReplyToStatusId
5407 let indexOf = t.IndexOf(p.Value.StatusId)
5409 orderby isForward ? indexOf : indexOf * -1
5410 orderby t != curTabClass
5411 select new { Tab = t, Post = p.Value, Index = indexOf };
5414 var postList = posts.ToList();
5415 for (var i = postList.Count - 1; i >= 0; i--)
5418 if (postList.FindIndex(pst => pst.Post.StatusId == postList[index].Post.StatusId) != index)
5420 postList.RemoveAt(index);
5423 var currentIndex = this.CurrentTab.SelectedIndex;
5424 var post = postList.FirstOrDefault(pst => pst.Tab == curTabClass && isForward ? pst.Index > currentIndex : pst.Index < currentIndex);
5425 if (post == null) post = postList.FirstOrDefault(pst => pst.Tab != curTabClass);
5426 if (post == null) post = postList.First();
5427 var tabIndex = this.statuses.Tabs.IndexOf(post.Tab);
5428 this.ListTab.SelectedIndex = tabIndex;
5429 var listView = this.CurrentListView;
5430 this.SelectListItem(listView, post.Index);
5431 listView.EnsureVisible(post.Index);
5433 catch (InvalidOperationException)
5441 if (this.replyChains == null || this.replyChains.Count < 1)
5443 var posts = from t in this.statuses.Tabs
5445 where p.Value.InReplyToStatusId == currentPost.StatusId
5446 let indexOf = t.IndexOf(p.Value.StatusId)
5449 orderby t != curTabClass
5450 select new { Tab = t, Index = indexOf };
5453 var post = posts.First();
5454 var tabIndex = this.statuses.Tabs.IndexOf(post.Tab);
5455 this.ListTab.SelectedIndex = tabIndex;
5456 var listView = this.CurrentListView;
5457 this.SelectListItem(listView, post.Index);
5458 listView.EnsureVisible(post.Index);
5460 catch (InvalidOperationException)
5467 var chainHead = this.replyChains.Pop();
5468 if (chainHead.InReplyToId == currentPost.StatusId)
5470 var tab = chainHead.OriginalTab;
5471 if (!this.statuses.Tabs.Contains(tab))
5473 this.replyChains = null;
5477 var idx = tab.IndexOf(chainHead.OriginalId);
5480 this.replyChains = null;
5484 var tabIndex = this.statuses.Tabs.IndexOf(tab);
5487 this.ListTab.SelectedIndex = tabIndex;
5491 this.replyChains = null;
5493 var listView = this.CurrentListView;
5494 this.SelectListItem(listView, idx);
5495 listView.EnsureVisible(idx);
5501 this.replyChains = null;
5502 this.GoBackInReplyToPostTree(parallel);
5508 private void GoBackSelectPostChain()
5510 if (this.selectPostChains.Count > 1)
5513 TabModel? foundTab = null;
5519 this.selectPostChains.Pop();
5520 var (tab, post) = this.selectPostChains.Peek();
5522 if (!this.statuses.Tabs.Contains(tab))
5523 continue; // 該当タブが存在しないので無視
5527 idx = tab.IndexOf(post.StatusId);
5528 if (idx == -1) continue; // 該当ポストが存在しないので無視
5533 this.selectPostChains.Pop();
5535 catch (InvalidOperationException)
5541 while (this.selectPostChains.Count > 1);
5543 if (foundTab == null)
5546 // 履歴が残り1つであればクリアしておく
5547 if (this.selectPostChains.Count == 1)
5548 this.selectPostChains.Clear();
5552 var tabIndex = this.statuses.Tabs.IndexOf(foundTab);
5553 var tabPage = this.ListTab.TabPages[tabIndex];
5554 var lst = (DetailsListView)tabPage.Tag;
5555 this.ListTab.SelectedIndex = tabIndex;
5559 this.SelectListItem(lst, idx);
5560 lst.EnsureVisible(idx);
5566 private void PushSelectPostChain()
5568 var currentTab = this.CurrentTab;
5569 var currentPost = this.CurrentPost;
5571 var count = this.selectPostChains.Count;
5574 var (tab, post) = this.selectPostChains.Peek();
5575 if (tab == currentTab)
5577 if (post == currentPost) return; // 最新の履歴と同一
5578 if (post == null) this.selectPostChains.Pop(); // 置き換えるため削除
5581 if (count >= 2500) this.TrimPostChain();
5582 this.selectPostChains.Push((currentTab, currentPost));
5585 private void TrimPostChain()
5587 if (this.selectPostChains.Count <= 2000) return;
5588 var p = new Stack<(TabModel, PostClass?)>(2000);
5589 for (var i = 0; i < 2000; i++)
5591 p.Push(this.selectPostChains.Pop());
5593 this.selectPostChains.Clear();
5594 for (var i = 0; i < 2000; i++)
5596 this.selectPostChains.Push(p.Pop());
5600 private bool GoStatus(long statusId)
5602 if (statusId == 0) return false;
5604 var tab = this.statuses.Tabs
5605 .Where(x => x.TabType != MyCommon.TabUsageType.DirectMessage)
5606 .Where(x => x.Contains(statusId))
5612 var index = tab.IndexOf(statusId);
5614 var tabIndex = this.statuses.Tabs.IndexOf(tab);
5615 this.ListTab.SelectedIndex = tabIndex;
5617 var listView = this.CurrentListView;
5618 this.SelectListItem(listView, index);
5619 listView.EnsureVisible(index);
5624 private bool GoDirectMessage(long statusId)
5626 if (statusId == 0) return false;
5628 var tab = this.statuses.DirectMessageTab;
5629 var index = tab.IndexOf(statusId);
5634 var tabIndex = this.statuses.Tabs.IndexOf(tab);
5635 this.ListTab.SelectedIndex = tabIndex;
5637 var listView = this.CurrentListView;
5638 this.SelectListItem(listView, index);
5639 listView.EnsureVisible(index);
5644 private void MyList_MouseClick(object sender, MouseEventArgs e)
5645 => this.CurrentTab.ClearAnchor();
5647 private void StatusText_Enter(object sender, EventArgs e)
5649 // フォーカスの戻り先を StatusText に設定
5650 this.Tag = this.StatusText;
5651 this.StatusText.BackColor = this.themeManager.ColorInputBackcolor;
5654 public Color InputBackColor
5655 => this.themeManager.ColorInputBackcolor;
5657 private void StatusText_Leave(object sender, EventArgs e)
5659 // フォーカスがメニューに遷移しないならばフォーカスはタブに移ることを期待
5660 if (this.ListTab.SelectedTab != null && this.MenuStrip1.Tag == null) this.Tag = this.ListTab.SelectedTab.Tag;
5661 this.StatusText.BackColor = Color.FromKnownColor(KnownColor.Window);
5664 private async void StatusText_KeyDown(object sender, KeyEventArgs e)
5666 if (this.CommonKeyDown(e.KeyData, FocusedControl.StatusText, out var asyncTask))
5669 e.SuppressKeyPress = true;
5672 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
5674 if (asyncTask != null)
5678 private void SaveConfigsAll(bool ifModified)
5682 this.SaveConfigsCommon();
5683 this.SaveConfigsLocal();
5684 this.SaveConfigsTabs();
5685 this.SaveConfigsAtId();
5689 if (this.ModifySettingCommon) this.SaveConfigsCommon();
5690 if (this.ModifySettingLocal) this.SaveConfigsLocal();
5691 if (this.ModifySettingAtId) this.SaveConfigsAtId();
5695 private void SaveConfigsAtId()
5697 if (this.ignoreConfigSave || !this.settings.Common.UseAtIdSupplement && this.AtIdSupl == null) return;
5699 this.ModifySettingAtId = false;
5700 this.settings.AtIdList.AtIdList = this.AtIdSupl.GetItemList();
5701 this.settings.SaveAtIdList();
5704 private void SaveConfigsCommon()
5706 if (this.ignoreConfigSave) return;
5708 this.ModifySettingCommon = false;
5709 lock (this.syncObject)
5711 this.settings.Common.UserName = this.tw.Username;
5712 this.settings.Common.UserId = this.tw.UserId;
5713 this.settings.Common.Token = this.tw.AccessToken;
5714 this.settings.Common.TokenSecret = this.tw.AccessTokenSecret;
5715 this.settings.Common.SortOrder = (int)this.statuses.SortOrder;
5716 this.settings.Common.SortColumn = this.statuses.SortMode switch
5718 ComparerMode.Nickname => 1, // ニックネーム
5719 ComparerMode.Data => 2, // 本文
5720 ComparerMode.Id => 3, // 時刻=発言Id
5721 ComparerMode.Name => 4, // 名前
5722 ComparerMode.Source => 7, // Source
5723 _ => throw new InvalidOperationException($"Invalid sort mode: {this.statuses.SortMode}"),
5725 this.settings.Common.HashTags = this.HashMgr.HashHistories;
5726 if (this.HashMgr.IsPermanent)
5728 this.settings.Common.HashSelected = this.HashMgr.UseHash;
5732 this.settings.Common.HashSelected = "";
5734 this.settings.Common.HashIsHead = this.HashMgr.IsHead;
5735 this.settings.Common.HashIsPermanent = this.HashMgr.IsPermanent;
5736 this.settings.Common.HashIsNotAddToAtReply = this.HashMgr.IsNotAddToAtReply;
5737 this.settings.Common.UseImageService = this.ImageSelector.Model.SelectedMediaServiceIndex;
5738 this.settings.Common.UseImageServiceName = this.ImageSelector.Model.SelectedMediaServiceName;
5740 this.settings.SaveCommon();
5744 private void SaveConfigsLocal()
5746 if (this.ignoreConfigSave) return;
5747 lock (this.syncObject)
5749 this.ModifySettingLocal = false;
5750 this.settings.Local.ScaleDimension = this.CurrentAutoScaleDimensions;
5751 this.settings.Local.FormSize = this.mySize;
5752 this.settings.Local.FormLocation = this.myLoc;
5753 this.settings.Local.SplitterDistance = this.mySpDis;
5754 this.settings.Local.PreviewDistance = this.mySpDis3;
5755 this.settings.Local.StatusMultiline = this.StatusText.Multiline;
5756 this.settings.Local.StatusTextHeight = this.mySpDis2;
5758 if (this.ignoreConfigSave) return;
5759 this.settings.SaveLocal();
5763 private void SaveConfigsTabs()
5765 var tabSettingList = new List<SettingTabs.SettingTabItem>();
5767 var tabs = this.statuses.Tabs.Append(this.statuses.MuteTab);
5769 foreach (var tab in tabs)
5771 if (!tab.IsPermanentTabType)
5774 var tabSetting = new SettingTabs.SettingTabItem
5776 TabName = tab.TabName,
5777 TabType = tab.TabType,
5778 UnreadManage = tab.UnreadManage,
5779 Protected = tab.Protected,
5780 Notify = tab.Notify,
5781 SoundFile = tab.SoundFile,
5786 case FilterTabModel filterTab:
5787 tabSetting.FilterArray = filterTab.FilterArray;
5789 case UserTimelineTabModel userTab:
5790 tabSetting.User = userTab.ScreenName;
5792 case PublicSearchTabModel searchTab:
5793 tabSetting.SearchWords = searchTab.SearchWords;
5794 tabSetting.SearchLang = searchTab.SearchLang;
5796 case ListTimelineTabModel listTab:
5797 tabSetting.ListInfo = listTab.ListInfo;
5801 tabSettingList.Add(tabSetting);
5804 this.settings.Tabs.Tabs = tabSettingList;
5805 this.settings.SaveTabs();
5808 private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)
5810 static void ShowFormatErrorDialog(IWin32Window owner)
5814 Properties.Resources.OpenURL_InvalidFormat,
5815 Properties.Resources.OpenURL_Caption,
5816 MessageBoxButtons.OK,
5817 MessageBoxIcon.Error
5821 var ret = InputDialog.Show(this, Properties.Resources.OpenURL_InputText, Properties.Resources.OpenURL_Caption, out var inputText);
5822 if (ret != DialogResult.OK)
5825 var match = Twitter.StatusUrlRegex.Match(inputText);
5828 ShowFormatErrorDialog(this);
5834 var statusId = long.Parse(match.Groups["StatusId"].Value);
5835 await this.OpenRelatedTab(statusId);
5837 catch (OverflowException)
5839 ShowFormatErrorDialog(this);
5841 catch (TabException ex)
5843 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
5847 private void SaveLogMenuItem_Click(object sender, EventArgs e)
5849 var tab = this.CurrentTab;
5851 var rslt = MessageBox.Show(
5852 string.Format(Properties.Resources.SaveLogMenuItem_ClickText1, Environment.NewLine),
5853 Properties.Resources.SaveLogMenuItem_ClickText2,
5854 MessageBoxButtons.YesNoCancel,
5855 MessageBoxIcon.Question);
5856 if (rslt == DialogResult.Cancel) return;
5858 this.SaveFileDialog1.FileName = $"{ApplicationSettings.AssemblyName}Posts{DateTimeUtc.Now.ToLocalTime():yyMMdd-HHmmss}.tsv";
5859 this.SaveFileDialog1.InitialDirectory = Application.ExecutablePath;
5860 this.SaveFileDialog1.Filter = Properties.Resources.SaveLogMenuItem_ClickText3;
5861 this.SaveFileDialog1.FilterIndex = 0;
5862 this.SaveFileDialog1.Title = Properties.Resources.SaveLogMenuItem_ClickText4;
5863 this.SaveFileDialog1.RestoreDirectory = true;
5865 if (this.SaveFileDialog1.ShowDialog() == DialogResult.OK)
5867 if (!this.SaveFileDialog1.ValidateNames) return;
5868 using var sw = new StreamWriter(this.SaveFileDialog1.FileName, false, Encoding.UTF8);
5869 if (rslt == DialogResult.Yes)
5872 for (var idx = 0; idx < tab.AllCount; idx++)
5874 var post = tab[idx];
5877 protect = "Protect";
5878 sw.WriteLine(post.Nickname + "\t" +
5879 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
5880 post.CreatedAt.ToLocalTimeString() + "\t" +
5881 post.ScreenName + "\t" +
5882 post.StatusId + "\t" +
5883 post.ImageUrl + "\t" +
5884 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
5890 foreach (var post in this.CurrentTab.SelectedPosts)
5894 protect = "Protect";
5895 sw.WriteLine(post.Nickname + "\t" +
5896 "\"" + post.TextFromApi.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
5897 post.CreatedAt.ToLocalTimeString() + "\t" +
5898 post.ScreenName + "\t" +
5899 post.StatusId + "\t" +
5900 post.ImageUrl + "\t" +
5901 "\"" + post.Text.Replace("\n", "").Replace("\"", "\"\"") + "\"" + "\t" +
5906 this.TopMost = this.settings.Common.AlwaysTop;
5909 public bool TabRename(string origTabName, [NotNullWhen(true)] out string? newTabName)
5913 using (var inputName = new InputTabName())
5915 inputName.TabName = origTabName;
5916 inputName.ShowDialog();
5917 if (inputName.DialogResult == DialogResult.Cancel) return false;
5918 newTabName = inputName.TabName;
5920 this.TopMost = this.settings.Common.AlwaysTop;
5921 if (!MyCommon.IsNullOrEmpty(newTabName))
5924 if (this.statuses.ContainsTab(newTabName))
5926 var tmp = string.Format(Properties.Resources.Tabs_DoubleClickText1, newTabName);
5927 MessageBox.Show(tmp, Properties.Resources.Tabs_DoubleClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
5931 var tabIndex = this.statuses.Tabs.IndexOf(origTabName);
5932 var tabPage = this.ListTab.TabPages[tabIndex];
5935 if (tabPage != null)
5936 tabPage.Text = newTabName;
5938 this.statuses.RenameTab(origTabName, newTabName);
5940 var state = this.listViewState[origTabName];
5941 this.listViewState.Remove(origTabName);
5942 this.listViewState[newTabName] = state;
5944 this.SaveConfigsCommon();
5945 this.SaveConfigsTabs();
5946 this.rclickTabName = newTabName;
5955 private void ListTab_MouseClick(object sender, MouseEventArgs e)
5957 if (e.Button == MouseButtons.Middle)
5959 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
5961 if (this.ListTab.GetTabRect(index).Contains(e.Location))
5963 this.RemoveSpecifiedTab(tab.TabName, true);
5964 this.SaveConfigsTabs();
5971 private void ListTab_DoubleClick(object sender, MouseEventArgs e)
5972 => this.TabRename(this.CurrentTabName, out _);
5974 private void ListTab_MouseDown(object sender, MouseEventArgs e)
5976 if (this.settings.Common.TabMouseLock) return;
5977 if (e.Button == MouseButtons.Left)
5979 foreach (var i in Enumerable.Range(0, this.statuses.Tabs.Count))
5981 if (this.ListTab.GetTabRect(i).Contains(e.Location))
5983 this.tabDrag = true;
5984 this.tabMouseDownPoint = e.Location;
5991 this.tabDrag = false;
5995 private void ListTab_DragEnter(object sender, DragEventArgs e)
5997 if (e.Data.GetDataPresent(typeof(TabPage)))
5998 e.Effect = DragDropEffects.Move;
6000 e.Effect = DragDropEffects.None;
6003 private void ListTab_DragDrop(object sender, DragEventArgs e)
6005 if (!e.Data.GetDataPresent(typeof(TabPage))) return;
6007 this.tabDrag = false;
6010 var cpos = new Point(e.X, e.Y);
6011 var spos = this.ListTab.PointToClient(cpos);
6012 foreach (var (tab, index) in this.statuses.Tabs.WithIndex())
6014 var rect = this.ListTab.GetTabRect(index);
6015 if (rect.Contains(spos))
6018 if (spos.X <= (rect.Left + rect.Right) / 2)
6027 // タブのないところにドロップ->最後尾へ移動
6028 if (MyCommon.IsNullOrEmpty(tn))
6030 var lastTab = this.statuses.Tabs.Last();
6031 tn = lastTab.TabName;
6035 var tp = (TabPage)e.Data.GetData(typeof(TabPage));
6036 if (tp.Text == tn) return;
6038 this.ReOrderTab(tp.Text, tn, bef);
6041 public void ReOrderTab(string targetTabText, string baseTabText, bool isBeforeBaseTab)
6043 var baseIndex = this.GetTabPageIndex(baseTabText);
6044 if (baseIndex == -1)
6047 var targetIndex = this.GetTabPageIndex(targetTabText);
6048 if (targetIndex == -1)
6051 using (ControlTransaction.Layout(this.ListTab))
6053 // 選択中のタブを Remove メソッドで取り外すと選択状態が変化して Selecting イベントが発生するが、
6054 // この時 TabInformations と TabControl の並び順が不一致なままで ListTabSelect メソッドが呼ばれてしまう。
6055 // これを防ぐために、Remove メソッドを呼ぶ前に選択中のタブを切り替えておく必要がある
6056 this.ListTab.SelectedIndex = targetIndex == 0 ? 1 : 0;
6058 var tab = this.statuses.Tabs[targetIndex];
6059 var tabPage = this.ListTab.TabPages[targetIndex];
6061 this.ListTab.TabPages.Remove(tabPage);
6063 if (targetIndex < baseIndex)
6066 if (!isBeforeBaseTab)
6069 this.statuses.MoveTab(baseIndex, tab);
6071 this.ListTab.TabPages.Insert(baseIndex, tabPage);
6074 this.SaveConfigsTabs();
6077 private void MakeDirectMessageText()
6079 var selectedPosts = this.CurrentTab.SelectedPosts;
6080 if (selectedPosts.Length > 1)
6083 var post = selectedPosts.Single();
6084 var text = $"D {post.ScreenName} {this.StatusText.Text}";
6086 this.inReplyTo = null;
6087 this.StatusText.Text = text;
6088 this.StatusText.SelectionStart = text.Length;
6089 this.StatusText.Focus();
6092 private void MakeReplyText(bool atAll = false)
6094 var selectedPosts = this.CurrentTab.SelectedPosts;
6095 if (selectedPosts.Any(x => x.IsDm))
6097 this.MakeDirectMessageText();
6101 if (selectedPosts.Length == 1)
6103 var post = selectedPosts.Single();
6104 var inReplyToStatusId = post.RetweetedId ?? post.StatusId;
6105 var inReplyToScreenName = post.ScreenName;
6106 this.inReplyTo = (inReplyToStatusId, inReplyToScreenName);
6110 this.inReplyTo = null;
6113 var selfScreenName = this.tw.Username;
6114 var targetScreenNames = new List<string>();
6115 foreach (var post in selectedPosts)
6117 if (post.ScreenName != selfScreenName)
6118 targetScreenNames.Add(post.ScreenName);
6122 foreach (var (_, screenName) in post.ReplyToList)
6124 if (screenName != selfScreenName)
6125 targetScreenNames.Add(screenName);
6130 if (this.inReplyTo != null)
6132 var (_, screenName) = this.inReplyTo.Value;
6133 if (screenName == selfScreenName)
6134 targetScreenNames.Insert(0, screenName);
6137 var text = this.StatusText.Text;
6138 foreach (var screenName in targetScreenNames.AsEnumerable().Reverse())
6140 var atText = $"@{screenName} ";
6141 if (!text.Contains(atText))
6142 text = atText + text;
6145 this.StatusText.Text = text;
6146 this.StatusText.SelectionStart = text.Length;
6147 this.StatusText.Focus();
6150 private void ListTab_MouseUp(object sender, MouseEventArgs e)
6151 => this.tabDrag = false;
6153 private int iconCnt = 0;
6154 private int blinkCnt = 0;
6155 private bool blink = false;
6157 private void RefreshTasktrayIcon()
6159 void EnableTasktrayAnimation()
6160 => this.TimerRefreshIcon.Enabled = true;
6162 void DisableTasktrayAnimation()
6163 => this.TimerRefreshIcon.Enabled = false;
6165 var busyTasks = this.workerSemaphore.CurrentCount != MaxWorderThreads;
6169 if (this.iconCnt >= this.iconAssets.IconTrayRefresh.Length)
6172 this.NotifyIcon1.Icon = this.iconAssets.IconTrayRefresh[this.iconCnt];
6173 this.myStatusError = false;
6174 EnableTasktrayAnimation();
6178 var replyIconType = this.settings.Common.ReplyIconState;
6180 if (replyIconType != MyCommon.REPLY_ICONSTATE.None)
6182 var replyTab = this.statuses.GetTabByType<MentionsTabModel>();
6183 if (replyTab != null && replyTab.UnreadCount > 0)
6187 if (replyIconType == MyCommon.REPLY_ICONSTATE.BlinkIcon && reply)
6190 if (this.blinkCnt > 10)
6193 if (this.blinkCnt == 0)
6194 this.blink = !this.blink;
6196 this.NotifyIcon1.Icon = this.blink ? this.iconAssets.IconTrayReplyBlink : this.iconAssets.IconTrayReply;
6197 EnableTasktrayAnimation();
6201 DisableTasktrayAnimation();
6207 // 優先度:リプライ→エラー→オフライン→アイドル
6208 // エラーは更新アイコンでクリアされる
6209 if (replyIconType == MyCommon.REPLY_ICONSTATE.StaticIcon && reply)
6210 this.NotifyIcon1.Icon = this.iconAssets.IconTrayReply;
6211 else if (this.myStatusError)
6212 this.NotifyIcon1.Icon = this.iconAssets.IconTrayError;
6213 else if (this.myStatusOnline)
6214 this.NotifyIcon1.Icon = this.iconAssets.IconTray;
6216 this.NotifyIcon1.Icon = this.iconAssets.IconTrayOffline;
6219 private void TimerRefreshIcon_Tick(object sender, EventArgs e)
6220 => this.RefreshTasktrayIcon(); // 200ms
6222 private void ContextMenuTabProperty_Opening(object sender, CancelEventArgs e)
6224 // 右クリックの場合はタブ名が設定済。アプリケーションキーの場合は現在のタブを対象とする
6225 if (MyCommon.IsNullOrEmpty(this.rclickTabName) || sender != this.ContextMenuTabProperty)
6226 this.rclickTabName = this.CurrentTabName;
6228 if (this.statuses == null) return;
6229 if (this.statuses.Tabs == null) return;
6231 if (!this.statuses.Tabs.TryGetValue(this.rclickTabName, out var tb))
6234 this.NotifyDispMenuItem.Checked = tb.Notify;
6235 this.NotifyTbMenuItem.Checked = tb.Notify;
6237 this.soundfileListup = true;
6238 this.SoundFileComboBox.Items.Clear();
6239 this.SoundFileTbComboBox.Items.Clear();
6240 this.SoundFileComboBox.Items.Add("");
6241 this.SoundFileTbComboBox.Items.Add("");
6242 var oDir = new DirectoryInfo(Application.StartupPath + Path.DirectorySeparatorChar);
6243 if (Directory.Exists(Path.Combine(Application.StartupPath, "Sounds")))
6245 oDir = oDir.GetDirectories("Sounds")[0];
6247 foreach (var oFile in oDir.GetFiles("*.wav"))
6249 this.SoundFileComboBox.Items.Add(oFile.Name);
6250 this.SoundFileTbComboBox.Items.Add(oFile.Name);
6252 var idx = this.SoundFileComboBox.Items.IndexOf(tb.SoundFile);
6253 if (idx == -1) idx = 0;
6254 this.SoundFileComboBox.SelectedIndex = idx;
6255 this.SoundFileTbComboBox.SelectedIndex = idx;
6256 this.soundfileListup = false;
6257 this.UreadManageMenuItem.Checked = tb.UnreadManage;
6258 this.UnreadMngTbMenuItem.Checked = tb.UnreadManage;
6260 this.TabMenuControl(this.rclickTabName);
6263 private void TabMenuControl(string tabName)
6265 var tabInfo = this.statuses.GetTabByName(tabName)!;
6267 this.FilterEditMenuItem.Enabled = true;
6268 this.EditRuleTbMenuItem.Enabled = true;
6270 if (tabInfo.IsDefaultTabType)
6272 this.ProtectTabMenuItem.Enabled = false;
6273 this.ProtectTbMenuItem.Enabled = false;
6277 this.ProtectTabMenuItem.Enabled = true;
6278 this.ProtectTbMenuItem.Enabled = true;
6281 if (tabInfo.IsDefaultTabType || tabInfo.Protected)
6283 this.ProtectTabMenuItem.Checked = true;
6284 this.ProtectTbMenuItem.Checked = true;
6285 this.DeleteTabMenuItem.Enabled = false;
6286 this.DeleteTbMenuItem.Enabled = false;
6290 this.ProtectTabMenuItem.Checked = false;
6291 this.ProtectTbMenuItem.Checked = false;
6292 this.DeleteTabMenuItem.Enabled = true;
6293 this.DeleteTbMenuItem.Enabled = true;
6297 private void ProtectTabMenuItem_Click(object sender, EventArgs e)
6299 var checkState = ((ToolStripMenuItem)sender).Checked;
6302 this.ProtectTbMenuItem.Checked = checkState;
6303 this.ProtectTabMenuItem.Checked = checkState;
6306 this.DeleteTabMenuItem.Enabled = !checkState;
6307 this.DeleteTbMenuItem.Enabled = !checkState;
6309 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
6310 this.statuses.Tabs[this.rclickTabName].Protected = checkState;
6312 this.SaveConfigsTabs();
6315 private void UreadManageMenuItem_Click(object sender, EventArgs e)
6317 this.UreadManageMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
6318 this.UnreadMngTbMenuItem.Checked = this.UreadManageMenuItem.Checked;
6320 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
6321 this.ChangeTabUnreadManage(this.rclickTabName, this.UreadManageMenuItem.Checked);
6323 this.SaveConfigsTabs();
6326 public void ChangeTabUnreadManage(string tabName, bool isManage)
6328 var idx = this.GetTabPageIndex(tabName);
6332 var tab = this.statuses.Tabs[tabName];
6333 tab.UnreadManage = isManage;
6335 if (this.settings.Common.TabIconDisp)
6337 var tabPage = this.ListTab.TabPages[idx];
6338 if (tab.UnreadCount > 0)
6339 tabPage.ImageIndex = 0;
6341 tabPage.ImageIndex = -1;
6344 if (this.CurrentTabName == tabName)
6346 this.listCache?.PurgeCache();
6347 this.CurrentListView.Refresh();
6350 this.SetMainWindowTitle();
6351 this.SetStatusLabelUrl();
6352 if (!this.settings.Common.TabIconDisp) this.ListTab.Refresh();
6355 private void NotifyDispMenuItem_Click(object sender, EventArgs e)
6357 this.NotifyDispMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
6358 this.NotifyTbMenuItem.Checked = this.NotifyDispMenuItem.Checked;
6360 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
6362 this.statuses.Tabs[this.rclickTabName].Notify = this.NotifyDispMenuItem.Checked;
6364 this.SaveConfigsTabs();
6367 private void SoundFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
6369 if (this.soundfileListup || MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
6371 this.statuses.Tabs[this.rclickTabName].SoundFile = (string)((ToolStripComboBox)sender).SelectedItem;
6373 this.SaveConfigsTabs();
6376 private void DeleteTabMenuItem_Click(object sender, EventArgs e)
6378 if (MyCommon.IsNullOrEmpty(this.rclickTabName) || sender == this.DeleteTbMenuItem)
6379 this.rclickTabName = this.CurrentTabName;
6381 this.RemoveSpecifiedTab(this.rclickTabName, true);
6382 this.SaveConfigsTabs();
6385 private void FilterEditMenuItem_Click(object sender, EventArgs e)
6387 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) this.rclickTabName = this.statuses.HomeTab.TabName;
6389 using (var fltDialog = new FilterDialog())
6391 fltDialog.Owner = this;
6392 fltDialog.SetCurrent(this.rclickTabName);
6393 fltDialog.ShowDialog(this);
6395 this.TopMost = this.settings.Common.AlwaysTop;
6397 this.ApplyPostFilters();
6398 this.SaveConfigsTabs();
6401 private async void AddTabMenuItem_Click(object sender, EventArgs e)
6403 string? tabName = null;
6404 MyCommon.TabUsageType tabUsage;
6405 using (var inputName = new InputTabName())
6407 inputName.TabName = this.statuses.MakeTabName("MyTab");
6408 inputName.IsShowUsage = true;
6409 inputName.ShowDialog();
6410 if (inputName.DialogResult == DialogResult.Cancel) return;
6411 tabName = inputName.TabName;
6412 tabUsage = inputName.Usage;
6414 this.TopMost = this.settings.Common.AlwaysTop;
6415 if (!MyCommon.IsNullOrEmpty(tabName))
6418 ListElement? list = null;
6419 if (tabUsage == MyCommon.TabUsageType.Lists)
6421 using var listAvail = new ListAvailable();
6422 if (listAvail.ShowDialog(this) == DialogResult.Cancel)
6424 if (listAvail.SelectedList == null)
6426 list = listAvail.SelectedList;
6432 case MyCommon.TabUsageType.UserDefined:
6433 tab = new FilterTabModel(tabName);
6435 case MyCommon.TabUsageType.PublicSearch:
6436 tab = new PublicSearchTabModel(tabName);
6438 case MyCommon.TabUsageType.Lists:
6439 tab = new ListTimelineTabModel(tabName, list!);
6445 if (!this.statuses.AddTab(tab) || !this.AddNewTab(tab, startup: false))
6447 var tmp = string.Format(Properties.Resources.AddTabMenuItem_ClickText1, tabName);
6448 MessageBox.Show(tmp, Properties.Resources.AddTabMenuItem_ClickText2, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
6453 this.SaveConfigsTabs();
6455 var tabIndex = this.statuses.Tabs.Count - 1;
6457 if (tabUsage == MyCommon.TabUsageType.PublicSearch)
6459 this.ListTab.SelectedIndex = tabIndex;
6460 this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus();
6462 if (tabUsage == MyCommon.TabUsageType.Lists)
6464 this.ListTab.SelectedIndex = tabIndex;
6465 await this.RefreshTabAsync(this.CurrentTab);
6471 private void TabMenuItem_Click(object sender, EventArgs e)
6474 foreach (var post in this.CurrentTab.SelectedPosts)
6477 if (!this.SelectTab(out var tab))
6480 using (var fltDialog = new FilterDialog())
6482 fltDialog.Owner = this;
6483 fltDialog.SetCurrent(tab.TabName);
6485 if (post.RetweetedBy == null)
6487 fltDialog.AddNewFilter(post.ScreenName, post.TextFromApi);
6491 fltDialog.AddNewFilter(post.RetweetedBy, post.TextFromApi);
6493 fltDialog.ShowDialog(this);
6496 this.TopMost = this.settings.Common.AlwaysTop;
6499 this.ApplyPostFilters();
6500 this.SaveConfigsTabs();
6503 protected override bool ProcessDialogKey(Keys keyData)
6505 // TextBox1でEnterを押してもビープ音が鳴らないようにする
6506 if ((keyData & Keys.KeyCode) == Keys.Enter)
6508 if (this.StatusText.Focused)
6510 var newLine = false;
6513 if (this.settings.Common.PostCtrlEnter) // Ctrl+Enter投稿時
6515 if (this.StatusText.Multiline)
6517 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) newLine = true;
6519 if ((keyData & Keys.Control) == Keys.Control) post = true;
6523 if ((keyData & Keys.Control) == Keys.Control) post = true;
6526 else if (this.settings.Common.PostShiftEnter) // SHift+Enter投稿時
6528 if (this.StatusText.Multiline)
6530 if ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) != Keys.Shift) newLine = true;
6532 if ((keyData & Keys.Shift) == Keys.Shift) post = true;
6536 if ((keyData & Keys.Shift) == Keys.Shift) post = true;
6541 if (this.StatusText.Multiline)
6543 if ((keyData & Keys.Shift) == Keys.Shift && (keyData & Keys.Control) != Keys.Control) newLine = true;
6545 if (((keyData & Keys.Control) != Keys.Control && (keyData & Keys.Shift) != Keys.Shift) ||
6546 ((keyData & Keys.Control) == Keys.Control && (keyData & Keys.Shift) == Keys.Shift)) post = true;
6550 if (((keyData & Keys.Shift) == Keys.Shift) ||
6551 (((keyData & Keys.Control) != Keys.Control) &&
6552 ((keyData & Keys.Shift) != Keys.Shift))) post = true;
6558 var pos1 = this.StatusText.SelectionStart;
6559 if (this.StatusText.SelectionLength > 0)
6561 this.StatusText.Text = this.StatusText.Text.Remove(pos1, this.StatusText.SelectionLength); // 選択状態文字列削除
6563 this.StatusText.Text = this.StatusText.Text.Insert(pos1, Environment.NewLine); // 改行挿入
6564 this.StatusText.SelectionStart = pos1 + Environment.NewLine.Length; // カーソルを改行の次の文字へ移動
6569 this.PostButton_Click(this.PostButton, EventArgs.Empty);
6575 var tab = this.CurrentTab;
6576 if (tab.TabType == MyCommon.TabUsageType.PublicSearch)
6578 var tabPage = this.CurrentTabPage;
6579 if (tabPage.Controls["panelSearch"].Controls["comboSearch"].Focused ||
6580 tabPage.Controls["panelSearch"].Controls["comboLang"].Focused)
6582 this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
6589 return base.ProcessDialogKey(keyData);
6592 private void ReplyAllStripMenuItem_Click(object sender, EventArgs e)
6593 => this.MakeReplyText(atAll: true);
6595 private void IDRuleMenuItem_Click(object sender, EventArgs e)
6597 var tab = this.CurrentTab;
6598 var selectedPosts = tab.SelectedPosts;
6601 if (selectedPosts.Length == 0)
6604 var screenNameArray = selectedPosts
6605 .Select(x => x.RetweetedBy ?? x.ScreenName)
6608 this.AddFilterRuleByScreenName(screenNameArray);
6610 if (screenNameArray.Length != 0)
6612 var atids = new List<string>();
6613 foreach (var screenName in screenNameArray)
6615 atids.Add("@" + screenName);
6617 var cnt = this.AtIdSupl.ItemCount;
6618 this.AtIdSupl.AddRangeItem(atids.ToArray());
6619 if (this.AtIdSupl.ItemCount != cnt)
6620 this.MarkSettingAtIdModified();
6624 private void SourceRuleMenuItem_Click(object sender, EventArgs e)
6626 var tab = this.CurrentTab;
6627 var selectedPosts = tab.SelectedPosts;
6629 if (selectedPosts.Length == 0)
6632 var sourceArray = selectedPosts.Select(x => x.Source).ToArray();
6634 this.AddFilterRuleBySource(sourceArray);
6637 public void AddFilterRuleByScreenName(params string[] screenNameArray)
6640 if (!this.SelectTab(out var tab)) return;
6644 if (tab.TabType != MyCommon.TabUsageType.Mute)
6646 this.MoveOrCopy(out mv, out mk);
6650 // ミュートタブでは常に MoveMatches を true にする
6655 foreach (var screenName in screenNameArray)
6657 tab.AddFilter(new PostFilterRule
6659 FilterName = screenName,
6660 UseNameField = true,
6664 FilterByUrl = false,
6668 this.ApplyPostFilters();
6669 this.SaveConfigsTabs();
6672 public void AddFilterRuleBySource(params string[] sourceArray)
6674 // タブ選択ダイアログを表示(or追加)
6675 if (!this.SelectTab(out var filterTab))
6680 if (filterTab.TabType != MyCommon.TabUsageType.Mute)
6682 // フィルタ動作選択ダイアログを表示(移動/コピー, マーク有無)
6683 this.MoveOrCopy(out mv, out mk);
6687 // ミュートタブでは常に MoveMatches を true にする
6692 // 振り分けルールに追加するSource
6693 foreach (var source in sourceArray)
6695 filterTab.AddFilter(new PostFilterRule
6697 FilterSource = source,
6701 FilterByUrl = false,
6705 this.ApplyPostFilters();
6706 this.SaveConfigsTabs();
6709 private bool SelectTab([NotNullWhen(true)] out FilterTabModel? tab)
6716 using (var dialog = new TabsDialog(this.statuses))
6718 if (dialog.ShowDialog(this) == DialogResult.Cancel) return false;
6720 tab = dialog.SelectedTab;
6723 this.CurrentTabPage.Focus();
6728 using (var inputName = new InputTabName())
6730 inputName.TabName = this.statuses.MakeTabName("MyTab");
6731 inputName.ShowDialog();
6732 if (inputName.DialogResult == DialogResult.Cancel) return false;
6733 tabName = inputName.TabName;
6735 this.TopMost = this.settings.Common.AlwaysTop;
6736 if (!MyCommon.IsNullOrEmpty(tabName))
6738 var newTab = new FilterTabModel(tabName);
6739 if (!this.statuses.AddTab(newTab) || !this.AddNewTab(newTab, startup: false))
6741 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText2, tabName);
6742 MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText3, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
6761 private void MoveOrCopy(out bool move, out bool mark)
6765 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText4, Environment.NewLine);
6766 if (MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText5, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
6774 var tmp = string.Format(Properties.Resources.IDRuleMenuItem_ClickText6, Environment.NewLine);
6775 if (MessageBox.Show(tmp, Properties.Resources.IDRuleMenuItem_ClickText7, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
6786 private void CopySTOTMenuItem_Click(object sender, EventArgs e)
6789 private void CopyURLMenuItem_Click(object sender, EventArgs e)
6790 => this.CopyIdUri();
6792 private void SelectAllMenuItem_Click(object sender, EventArgs e)
6794 if (this.StatusText.Focused)
6797 this.StatusText.SelectAll();
6801 // ListView上でのCtrl+A
6802 NativeMethods.SelectAllItems(this.CurrentListView);
6806 private void MoveMiddle()
6812 var listView = this.CurrentListView;
6813 if (listView.SelectedIndices.Count == 0) return;
6815 var idx = listView.SelectedIndices[0];
6817 item = listView.GetItemAt(0, 25);
6823 item = listView.GetItemAt(0, listView.ClientSize.Height - 1);
6825 idx2 = listView.VirtualListSize - 1;
6829 idx -= Math.Abs(idx1 - idx2) / 2;
6830 if (idx < 0) idx = 0;
6832 listView.EnsureVisible(listView.VirtualListSize - 1);
6833 listView.EnsureVisible(idx);
6836 private async void OpenURLMenuItem_Click(object sender, EventArgs e)
6838 var linkElements = this.tweetDetailsView.GetLinkElements();
6840 if (linkElements.Length == 0)
6843 var links = new List<OpenUrlItem>(linkElements.Length);
6845 foreach (var linkElm in linkElements)
6847 var displayUrl = linkElm.GetAttribute("title");
6848 var href = linkElm.GetAttribute("href");
6849 var linkedText = linkElm.InnerText;
6851 if (MyCommon.IsNullOrEmpty(displayUrl))
6854 links.Add(new OpenUrlItem(linkedText, displayUrl, href));
6858 bool isReverseSettings;
6860 if (links.Count == 1)
6862 // ツイートに含まれる URL が 1 つのみの場合
6863 // => OpenURL ダイアログを表示せずにリンクを開く
6864 selectedUrl = links[0].Href;
6866 // Ctrl+E で呼ばれた場合を考慮し isReverseSettings の判定を行わない
6867 isReverseSettings = false;
6871 // ツイートに含まれる URL が複数ある場合
6872 // => OpenURL を表示しユーザーが選択したリンクを開く
6873 this.urlDialog.ClearUrl();
6875 foreach (var link in links)
6876 this.urlDialog.AddUrl(link);
6878 if (this.urlDialog.ShowDialog(this) != DialogResult.OK)
6881 this.TopMost = this.settings.Common.AlwaysTop;
6883 selectedUrl = this.urlDialog.SelectedUrl;
6885 // Ctrlを押しながらリンクを開いた場合は、設定と逆の動作をするフラグを true としておく
6886 isReverseSettings = MyCommon.IsKeyDown(Keys.Control);
6889 await this.OpenUriAsync(new Uri(selectedUrl), isReverseSettings);
6892 private void ClearTabMenuItem_Click(object sender, EventArgs e)
6894 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
6895 this.ClearTab(this.rclickTabName, true);
6898 private void ClearTab(string tabName, bool showWarning)
6902 var tmp = string.Format(Properties.Resources.ClearTabMenuItem_ClickText1, Environment.NewLine);
6903 if (MessageBox.Show(tmp, tabName + " " + Properties.Resources.ClearTabMenuItem_ClickText2, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
6909 this.statuses.ClearTabIds(tabName);
6910 if (this.CurrentTabName == tabName)
6912 this.CurrentTab.ClearAnchor();
6913 this.listCache?.PurgeCache();
6914 this.listCache?.UpdateListSize();
6917 var tabIndex = this.statuses.Tabs.IndexOf(tabName);
6918 var tabPage = this.ListTab.TabPages[tabIndex];
6919 tabPage.ImageIndex = -1;
6921 if (!this.settings.Common.TabIconDisp) this.ListTab.Refresh();
6923 this.SetMainWindowTitle();
6924 this.SetStatusLabelUrl();
6927 private static long followers = 0;
6929 private void SetMainWindowTitle()
6931 // メインウインドウタイトルの書き換え
6932 var ttl = new StringBuilder(256);
6935 if (this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.None &&
6936 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.Post &&
6937 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.Ver &&
6938 this.settings.Common.DispLatestPost != MyCommon.DispTitleEnum.OwnStatus)
6940 foreach (var tab in this.statuses.Tabs)
6942 ur += tab.UnreadCount;
6947 if (this.settings.Common.DispUsername) ttl.Append(this.tw.Username).Append(" - ");
6948 ttl.Append(ApplicationSettings.ApplicationName);
6950 switch (this.settings.Common.DispLatestPost)
6952 case MyCommon.DispTitleEnum.Ver:
6953 ttl.Append("Ver:").Append(MyCommon.GetReadableVersion());
6955 case MyCommon.DispTitleEnum.Post:
6956 if (this.history != null && this.history.Count > 1)
6957 ttl.Append(this.history[this.history.Count - 2].Status.Replace("\r\n", " "));
6959 case MyCommon.DispTitleEnum.UnreadRepCount:
6960 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, this.statuses.MentionTab.UnreadCount + this.statuses.DirectMessageTab.UnreadCount);
6962 case MyCommon.DispTitleEnum.UnreadAllCount:
6963 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
6965 case MyCommon.DispTitleEnum.UnreadAllRepCount:
6966 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, this.statuses.MentionTab.UnreadCount + this.statuses.DirectMessageTab.UnreadCount);
6968 case MyCommon.DispTitleEnum.UnreadCountAllCount:
6969 ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
6971 case MyCommon.DispTitleEnum.OwnStatus:
6972 if (followers == 0 && this.tw.FollowersCount > 0) followers = this.tw.FollowersCount;
6973 ttl.AppendFormat(Properties.Resources.OwnStatusTitle, this.tw.StatusesCount, this.tw.FriendsCount, this.tw.FollowersCount, this.tw.FollowersCount - followers);
6979 this.Text = ttl.ToString();
6981 catch (AccessViolationException)
6983 // 原因不明。ポスト内容に依存か?たまーに発生するが再現せず。
6987 private string GetStatusLabelText()
6990 // タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
6991 if (this.statuses == null) return "";
6992 var tbRep = this.statuses.MentionTab;
6993 var tbDm = this.statuses.DirectMessageTab;
6994 if (tbRep == null || tbDm == null) return "";
6995 var urat = tbRep.UnreadCount + tbDm.UnreadCount;
7000 var slbl = new StringBuilder(256);
7003 foreach (var tab in this.statuses.Tabs)
7005 ur += tab.UnreadCount;
7007 if (tab.TabName == this.CurrentTabName)
7009 tur = tab.UnreadCount;
7019 this.unreadCounter = ur;
7020 this.unreadAtCounter = urat;
7022 var homeTab = this.statuses.HomeTab;
7024 slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, this.postTimestamps.Count, this.favTimestamps.Count, homeTab.TweetsPerHour);
7025 if (this.settings.Common.TimelinePeriod == 0)
7027 slbl.Append(Properties.Resources.SetStatusLabelText2);
7031 slbl.Append(this.settings.Common.TimelinePeriod + Properties.Resources.SetStatusLabelText3);
7033 return slbl.ToString();
7036 private async void TwitterApiStatus_AccessLimitUpdated(object sender, EventArgs e)
7040 if (this.InvokeRequired && !this.IsDisposed)
7042 await this.InvokeAsync(() => this.TwitterApiStatus_AccessLimitUpdated(sender, e));
7046 var endpointName = ((TwitterApiStatus.AccessLimitUpdatedEventArgs)e).EndpointName;
7047 this.SetApiStatusLabel(endpointName);
7050 catch (ObjectDisposedException)
7054 catch (InvalidOperationException)
7060 private void SetApiStatusLabel(string? endpointName = null)
7062 var tabType = this.CurrentTab.TabType;
7064 if (endpointName == null)
7067 endpointName = tabType switch
7069 MyCommon.TabUsageType.Home => GetTimelineRequest.EndpointName,
7070 MyCommon.TabUsageType.UserDefined => "/statuses/home_timeline",
7071 MyCommon.TabUsageType.Mentions => "/statuses/mentions_timeline",
7072 MyCommon.TabUsageType.Favorites => "/favorites/list",
7073 MyCommon.TabUsageType.DirectMessage => "/direct_messages/events/list",
7074 MyCommon.TabUsageType.UserTimeline => "/statuses/user_timeline",
7075 MyCommon.TabUsageType.Lists => "/lists/statuses",
7076 MyCommon.TabUsageType.PublicSearch => "/search/tweets",
7077 MyCommon.TabUsageType.Related => "/statuses/show/:id",
7080 this.toolStripApiGauge.ApiEndpoint = endpointName;
7084 // 表示中のタブに関連する endpoint であれば更新
7086 if (endpointName == GetTimelineRequest.EndpointName)
7088 update = tabType == MyCommon.TabUsageType.Home || tabType == MyCommon.TabUsageType.UserDefined;
7092 update = endpointName switch
7094 "/statuses/mentions_timeline" => tabType == MyCommon.TabUsageType.Mentions,
7095 "/favorites/list" => tabType == MyCommon.TabUsageType.Favorites,
7096 "/direct_messages/events/list" => tabType == MyCommon.TabUsageType.DirectMessage,
7097 "/statuses/user_timeline" => tabType == MyCommon.TabUsageType.UserTimeline,
7098 "/lists/statuses" => tabType == MyCommon.TabUsageType.Lists,
7099 "/search/tweets" => tabType == MyCommon.TabUsageType.PublicSearch,
7100 "/statuses/show/:id" => tabType == MyCommon.TabUsageType.Related,
7107 this.toolStripApiGauge.ApiEndpoint = endpointName;
7112 private void SetStatusLabelUrl()
7113 => this.StatusLabelUrl.Text = this.GetStatusLabelText();
7115 public void SetStatusLabel(string text)
7116 => this.StatusLabel.Text = text;
7118 private void SetNotifyIconText()
7120 var ur = new StringBuilder(64);
7122 // タスクトレイアイコンのツールチップテキスト書き換え
7124 ur.Remove(0, ur.Length);
7125 if (this.settings.Common.DispUsername)
7127 ur.Append(this.tw.Username);
7130 ur.Append(ApplicationSettings.ApplicationName);
7132 ur.Append("(Debug Build)");
7134 if (this.unreadCounter != -1 && this.unreadAtCounter != -1)
7137 ur.Append(this.unreadCounter);
7139 ur.Append(this.unreadAtCounter);
7142 this.NotifyIcon1.Text = ur.ToString();
7145 internal void CheckReplyTo(string statusText)
7149 m = Regex.Matches(statusText, Twitter.Hashtag, RegexOptions.IgnoreCase);
7151 foreach (Match hm in m)
7153 if (!hstr.Contains("#" + hm.Result("$3") + " "))
7155 hstr += "#" + hm.Result("$3") + " ";
7156 this.HashSupl.AddItem("#" + hm.Result("$3"));
7159 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash) && !hstr.Contains(this.HashMgr.UseHash + " "))
7161 hstr += this.HashMgr.UseHash;
7163 if (!MyCommon.IsNullOrEmpty(hstr)) this.HashMgr.AddHashToHistory(hstr.Trim(), false);
7165 // 本当にリプライ先指定すべきかどうかの判定
7166 m = Regex.Matches(statusText, "(^|[ -/:-@[-^`{-~])(?<id>@[a-zA-Z0-9_]+)");
7168 if (this.settings.Common.UseAtIdSupplement)
7170 var bCnt = this.AtIdSupl.ItemCount;
7171 foreach (Match mid in m)
7173 this.AtIdSupl.AddItem(mid.Result("${id}"));
7175 if (bCnt != this.AtIdSupl.ItemCount)
7176 this.MarkSettingAtIdModified();
7179 // リプライ先ステータスIDの指定がない場合は指定しない
7180 if (this.inReplyTo == null)
7184 // 次の条件を満たす場合に in_reply_to_status_id 指定
7185 // 1. Twitterによりリンクと判定される @idが文中に1つ含まれる (2009/5/28 リンク化される@IDのみカウントするように修正)
7186 // 2. リプライ先ステータスIDが設定されている(リストをダブルクリックで返信している)
7187 // 3. 文中に含まれた@idがリプライ先のポスト者のIDと一致する
7191 var inReplyToScreenName = this.inReplyTo.Value.ScreenName;
7192 if (statusText.StartsWith("@", StringComparison.Ordinal))
7194 if (statusText.StartsWith("@" + inReplyToScreenName, StringComparison.Ordinal)) return;
7198 foreach (Match mid in m)
7200 if (statusText.Contains("RT " + mid.Result("${id}") + ":") && mid.Result("${id}") == "@" + inReplyToScreenName) return;
7205 this.inReplyTo = null;
7208 private void TweenMain_Resize(object sender, EventArgs e)
7210 if (!this.initialLayout && this.settings.Common.MinimizeToTray && this.WindowState == FormWindowState.Minimized)
7212 this.Visible = false;
7214 if (this.initialLayout && this.settings.Local != null && this.WindowState == FormWindowState.Normal && this.Visible)
7216 // 現在の DPI と設定保存時の DPI との比を取得する
7217 var configScaleFactor = this.settings.Local.GetConfigScaleFactor(this.CurrentAutoScaleDimensions);
7219 this.ClientSize = ScaleBy(configScaleFactor, this.settings.Local.FormSize);
7222 var splitterDistance = ScaleBy(configScaleFactor.Height, this.settings.Local.SplitterDistance);
7223 if (splitterDistance > this.SplitContainer1.Panel1MinSize &&
7224 splitterDistance < this.SplitContainer1.Height - this.SplitContainer1.Panel2MinSize - this.SplitContainer1.SplitterWidth)
7226 this.SplitContainer1.SplitterDistance = splitterDistance;
7230 this.StatusText.Multiline = this.settings.Local.StatusMultiline;
7231 if (this.StatusText.Multiline)
7233 var statusTextHeight = ScaleBy(configScaleFactor.Height, this.settings.Local.StatusTextHeight);
7234 var dis = this.SplitContainer2.Height - statusTextHeight - this.SplitContainer2.SplitterWidth;
7235 if (dis > this.SplitContainer2.Panel1MinSize && dis < this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth)
7237 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - statusTextHeight - this.SplitContainer2.SplitterWidth;
7239 this.StatusText.Height = statusTextHeight;
7243 if (this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth > 0)
7245 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth;
7249 var previewDistance = ScaleBy(configScaleFactor.Width, this.settings.Local.PreviewDistance);
7250 if (previewDistance > this.SplitContainer3.Panel1MinSize && previewDistance < this.SplitContainer3.Width - this.SplitContainer3.Panel2MinSize - this.SplitContainer3.SplitterWidth)
7252 this.SplitContainer3.SplitterDistance = previewDistance;
7255 // Panel2Collapsed は SplitterDistance の設定を終えるまで true にしない
7256 this.SplitContainer3.Panel2Collapsed = true;
7258 this.initialLayout = false;
7260 if (this.WindowState != FormWindowState.Minimized)
7262 this.formWindowState = this.WindowState;
7266 private void PlaySoundMenuItem_CheckedChanged(object sender, EventArgs e)
7268 this.PlaySoundMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
7269 this.PlaySoundFileMenuItem.Checked = this.PlaySoundMenuItem.Checked;
7270 if (this.PlaySoundMenuItem.Checked)
7272 this.settings.Common.PlaySound = true;
7276 this.settings.Common.PlaySound = false;
7278 this.MarkSettingCommonModified();
7281 private void SplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
7283 if (this.initialLayout)
7286 int splitterDistance;
7287 switch (this.WindowState)
7289 case FormWindowState.Normal:
7290 splitterDistance = this.SplitContainer1.SplitterDistance;
7292 case FormWindowState.Maximized:
7293 // 最大化時は、通常時のウィンドウサイズに換算した SplitterDistance を算出する
7294 var normalContainerHeight = this.mySize.Height - this.ToolStripContainer1.TopToolStripPanel.Height - this.ToolStripContainer1.BottomToolStripPanel.Height;
7295 splitterDistance = this.SplitContainer1.SplitterDistance - (this.SplitContainer1.Height - normalContainerHeight);
7296 splitterDistance = Math.Min(splitterDistance, normalContainerHeight - this.SplitContainer1.SplitterWidth - this.SplitContainer1.Panel2MinSize);
7302 this.mySpDis = splitterDistance;
7303 this.MarkSettingLocalModified();
7306 private async Task DoRepliedStatusOpen()
7308 var currentPost = this.CurrentPost;
7309 if (this.ExistCurrentPost && currentPost != null && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)
7311 if (MyCommon.IsKeyDown(Keys.Shift))
7313 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.Value));
7316 if (this.statuses.Posts.TryGetValue(currentPost.InReplyToStatusId.Value, out var repPost))
7318 MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname} ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
7322 foreach (var tb in this.statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
7324 if (tb == null || !tb.Contains(currentPost.InReplyToStatusId.Value)) break;
7325 repPost = tb.Posts[currentPost.InReplyToStatusId.Value];
7326 MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname} ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
7329 await MyCommon.OpenInBrowserAsync(this, MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.Value));
7334 private async void RepliedStatusOpenMenuItem_Click(object sender, EventArgs e)
7335 => await this.DoRepliedStatusOpen();
7337 private void SplitContainer2_Panel2_Resize(object sender, EventArgs e)
7339 if (this.initialLayout)
7340 return; // SettingLocal の反映が完了するまで multiline の判定を行わない
7342 var multiline = this.SplitContainer2.Panel2.Height > this.SplitContainer2.Panel2MinSize + 2;
7343 if (multiline != this.StatusText.Multiline)
7345 this.StatusText.Multiline = multiline;
7346 this.settings.Local.StatusMultiline = multiline;
7347 this.MarkSettingLocalModified();
7351 private void StatusText_MultilineChanged(object sender, EventArgs e)
7353 if (this.StatusText.Multiline)
7354 this.StatusText.ScrollBars = ScrollBars.Vertical;
7356 this.StatusText.ScrollBars = ScrollBars.None;
7358 if (!this.initialLayout)
7359 this.MarkSettingLocalModified();
7362 private void MultiLineMenuItem_Click(object sender, EventArgs e)
7365 var menuItemChecked = ((ToolStripMenuItem)sender).Checked;
7366 this.StatusText.Multiline = menuItemChecked;
7367 this.settings.Local.StatusMultiline = menuItemChecked;
7368 if (menuItemChecked)
7370 if (this.SplitContainer2.Height - this.mySpDis2 - this.SplitContainer2.SplitterWidth < 0)
7371 this.SplitContainer2.SplitterDistance = 0;
7373 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.mySpDis2 - this.SplitContainer2.SplitterWidth;
7377 this.SplitContainer2.SplitterDistance = this.SplitContainer2.Height - this.SplitContainer2.Panel2MinSize - this.SplitContainer2.SplitterWidth;
7379 this.MarkSettingLocalModified();
7382 private async Task<bool> UrlConvertAsync(MyCommon.UrlConverter converterType)
7384 if (converterType == MyCommon.UrlConverter.Bitly || converterType == MyCommon.UrlConverter.Jmp)
7386 // OAuth2 アクセストークンまたは API キー (旧方式) のいずれも設定されていなければ短縮しない
7387 if (MyCommon.IsNullOrEmpty(this.settings.Common.BitlyAccessToken) &&
7388 (MyCommon.IsNullOrEmpty(this.settings.Common.BilyUser) || MyCommon.IsNullOrEmpty(this.settings.Common.BitlyPwd)))
7390 MessageBox.Show(this, Properties.Resources.UrlConvert_BitlyAuthRequired, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
7395 // Converter_Type=Nicomsの場合は、nicovideoのみ短縮する
7396 // 参考資料 RFC3986 Uniform Resource Identifier (URI): Generic Syntax
7397 // Appendix A. Collected ABNF for URI
7398 // http://www.ietf.org/rfc/rfc3986.txt
7400 const string nico = @"^https?://[a-z]+\.(nicovideo|niconicommons|nicolive)\.jp/[a-z]+/[a-z0-9]+$";
7403 if (this.StatusText.SelectionLength > 0)
7405 var tmp = this.StatusText.SelectedText;
7406 // httpから始まらない場合、ExcludeStringで指定された文字列で始まる場合は対象としない
7407 if (tmp.StartsWith("http", StringComparison.OrdinalIgnoreCase))
7409 // 文字列が選択されている場合はその文字列について処理
7411 // nico.ms使用、nicovideoにマッチしたら変換
7412 if (this.settings.Common.Nicoms && Regex.IsMatch(tmp, nico))
7414 result = Nicoms.Shorten(tmp);
7416 else if (converterType != MyCommon.UrlConverter.Nicoms)
7421 var srcUri = new Uri(tmp);
7422 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(converterType, srcUri);
7423 result = resultUri.AbsoluteUri;
7425 catch (WebApiException e)
7427 this.StatusLabel.Text = converterType + ":" + e.Message;
7430 catch (UriFormatException e)
7432 this.StatusLabel.Text = converterType + ":" + e.Message;
7441 if (!MyCommon.IsNullOrEmpty(result))
7443 // 短縮 URL が生成されるまでの間に投稿欄から元の URL が削除されていたら中断する
7444 var origUrlIndex = this.StatusText.Text.IndexOf(tmp, StringComparison.Ordinal);
7445 if (origUrlIndex == -1)
7448 this.StatusText.Select(origUrlIndex, tmp.Length);
7449 this.StatusText.SelectedText = result;
7452 var undo = new UrlUndo
7458 if (this.urlUndoBuffer == null)
7460 this.urlUndoBuffer = new List<UrlUndo>();
7461 this.UrlUndoToolStripMenuItem.Enabled = true;
7464 this.urlUndoBuffer.Add(undo);
7470 const string url = @"(?<before>(?:[^\""':!=]|^|\:))" +
7471 @"(?<url>(?<protocol>https?://)" +
7472 @"(?<domain>(?:[\.-]|[^\p{P}\s])+\.[a-z]{2,}(?::[0-9]+)?)" +
7473 @"(?<path>/[a-z0-9!*//();:&=+$/%#\-_.,~@]*[a-z0-9)=#/]?)?" +
7474 @"(?<query>\?[a-z0-9!*//();:&=+$/%#\-_.,~@?]*[a-z0-9_&=#/])?)";
7475 // 正規表現にマッチしたURL文字列をtinyurl化
7476 foreach (Match mt in Regex.Matches(this.StatusText.Text, url, RegexOptions.IgnoreCase))
7478 if (this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal) == -1)
7480 var tmp = mt.Result("${url}");
7481 if (tmp.StartsWith("w", StringComparison.OrdinalIgnoreCase))
7482 tmp = "http://" + tmp;
7485 this.StatusText.Select(this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal), mt.Result("${url}").Length);
7487 // nico.ms使用、nicovideoにマッチしたら変換
7488 if (this.settings.Common.Nicoms && Regex.IsMatch(tmp, nico))
7490 result = Nicoms.Shorten(tmp);
7492 else if (converterType != MyCommon.UrlConverter.Nicoms)
7497 var srcUri = new Uri(tmp);
7498 var resultUri = await ShortUrl.Instance.ShortenUrlAsync(converterType, srcUri);
7499 result = resultUri.AbsoluteUri;
7501 catch (HttpRequestException e)
7503 // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
7504 // のように長いので「:」が含まれていればそれ以降のみを抽出する
7505 var message = e.Message.Split(new[] { ':' }, count: 2).Last();
7507 this.StatusLabel.Text = converterType + ":" + message;
7510 catch (WebApiException e)
7512 this.StatusLabel.Text = converterType + ":" + e.Message;
7515 catch (UriFormatException e)
7517 this.StatusLabel.Text = converterType + ":" + e.Message;
7526 if (!MyCommon.IsNullOrEmpty(result))
7528 // 短縮 URL が生成されるまでの間に投稿欄から元の URL が削除されていたら中断する
7529 var origUrlIndex = this.StatusText.Text.IndexOf(mt.Result("${url}"), StringComparison.Ordinal);
7530 if (origUrlIndex == -1)
7533 this.StatusText.Select(origUrlIndex, mt.Result("${url}").Length);
7534 this.StatusText.SelectedText = result;
7536 var undo = new UrlUndo
7538 Before = mt.Result("${url}"),
7542 if (this.urlUndoBuffer == null)
7544 this.urlUndoBuffer = new List<UrlUndo>();
7545 this.UrlUndoToolStripMenuItem.Enabled = true;
7548 this.urlUndoBuffer.Add(undo);
7556 private void DoUrlUndo()
7558 if (this.urlUndoBuffer != null)
7560 var tmp = this.StatusText.Text;
7561 foreach (var data in this.urlUndoBuffer)
7563 tmp = tmp.Replace(data.After, data.Before);
7565 this.StatusText.Text = tmp;
7566 this.urlUndoBuffer = null;
7567 this.UrlUndoToolStripMenuItem.Enabled = false;
7568 this.StatusText.SelectionStart = 0;
7569 this.StatusText.SelectionLength = 0;
7573 private async void TinyURLToolStripMenuItem_Click(object sender, EventArgs e)
7574 => await this.UrlConvertAsync(MyCommon.UrlConverter.TinyUrl);
7576 private async void IsgdToolStripMenuItem_Click(object sender, EventArgs e)
7577 => await this.UrlConvertAsync(MyCommon.UrlConverter.Isgd);
7579 private async void UxnuMenuItem_Click(object sender, EventArgs e)
7580 => await this.UrlConvertAsync(MyCommon.UrlConverter.Uxnu);
7582 private async void UrlConvertAutoToolStripMenuItem_Click(object sender, EventArgs e)
7584 if (!await this.UrlConvertAsync(this.settings.Common.AutoShortUrlFirst))
7586 var rnd = new Random();
7588 MyCommon.UrlConverter svc;
7589 // 前回使用した短縮URLサービス以外を選択する
7592 svc = (MyCommon.UrlConverter)rnd.Next(System.Enum.GetNames(typeof(MyCommon.UrlConverter)).Length);
7594 while (svc == this.settings.Common.AutoShortUrlFirst || svc == MyCommon.UrlConverter.Nicoms || svc == MyCommon.UrlConverter.Unu);
7595 await this.UrlConvertAsync(svc);
7599 private void UrlUndoToolStripMenuItem_Click(object sender, EventArgs e)
7600 => this.DoUrlUndo();
7602 private void NewPostPopMenuItem_CheckStateChanged(object sender, EventArgs e)
7604 this.NotifyFileMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
7605 this.NewPostPopMenuItem.Checked = this.NotifyFileMenuItem.Checked;
7606 this.settings.Common.NewAllPop = this.NewPostPopMenuItem.Checked;
7607 this.MarkSettingCommonModified();
7610 private void ListLockMenuItem_CheckStateChanged(object sender, EventArgs e)
7612 this.ListLockMenuItem.Checked = ((ToolStripMenuItem)sender).Checked;
7613 this.LockListFileMenuItem.Checked = this.ListLockMenuItem.Checked;
7614 this.settings.Common.ListLock = this.ListLockMenuItem.Checked;
7615 this.MarkSettingCommonModified();
7618 private void MenuStrip1_MenuActivate(object sender, EventArgs e)
7620 // フォーカスがメニューに移る (MenuStrip1.Tag フラグを立てる)
7621 this.MenuStrip1.Tag = new object();
7622 this.MenuStrip1.Select(); // StatusText がフォーカスを持っている場合 Leave が発生
7625 private void MenuStrip1_MenuDeactivate(object sender, EventArgs e)
7627 var currentTabPage = this.CurrentTabPage;
7628 if (this.Tag != null) // 設定された戻り先へ遷移
7630 if (this.Tag == currentTabPage)
7631 ((Control)currentTabPage.Tag).Select();
7633 ((Control)this.Tag).Select();
7635 else // 戻り先が指定されていない (初期状態) 場合はタブに遷移
7637 this.Tag = currentTabPage.Tag;
7638 ((Control)this.Tag).Select();
7640 // フォーカスがメニューに遷移したかどうかを表すフラグを降ろす
7641 this.MenuStrip1.Tag = null;
7644 private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
7646 if (this.Use2ColumnsMode)
7652 var lst = (DetailsListView)sender;
7653 var columnsCount = lst.Columns.Count;
7655 var darr = new int[columnsCount];
7656 for (var i = 0; i < columnsCount; i++)
7657 darr[lst.Columns[i].DisplayIndex] = i;
7659 MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
7661 for (var i = 0; i < columnsCount; i++)
7662 this.settings.Local.ColumnsOrder[darr[i]] = i;
7664 this.MarkSettingLocalModified();
7665 this.isColumnChanged = true;
7668 private void MyList_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
7670 var lst = (DetailsListView)sender;
7671 if (this.settings.Local == null) return;
7673 var modified = false;
7674 if (this.Use2ColumnsMode)
7676 if (this.settings.Local.ColumnsWidth[0] != lst.Columns[0].Width)
7678 this.settings.Local.ColumnsWidth[0] = lst.Columns[0].Width;
7681 if (this.settings.Local.ColumnsWidth[2] != lst.Columns[1].Width)
7683 this.settings.Local.ColumnsWidth[2] = lst.Columns[1].Width;
7689 var columnsCount = lst.Columns.Count;
7690 for (var i = 0; i < columnsCount; i++)
7692 if (this.settings.Local.ColumnsWidth[i] == lst.Columns[i].Width)
7695 this.settings.Local.ColumnsWidth[i] = lst.Columns[i].Width;
7701 this.MarkSettingLocalModified();
7702 this.isColumnChanged = true;
7706 private void SplitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
7708 if (this.StatusText.Multiline) this.mySpDis2 = this.StatusText.Height;
7709 this.MarkSettingLocalModified();
7712 private void TweenMain_DragDrop(object sender, DragEventArgs e)
7714 if (e.Data.GetDataPresent(DataFormats.FileDrop))
7716 if (!e.Data.GetDataPresent(DataFormats.Html, false)) // WebBrowserコントロールからの絵文字画像Drag&Dropは弾く
7718 this.SelectMedia_DragDrop(e);
7721 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
7723 var (url, title) = GetUrlFromDataObject(e.Data);
7729 appendText = title + " " + url;
7731 if (this.StatusText.TextLength == 0)
7732 this.StatusText.Text = appendText;
7734 this.StatusText.Text += " " + appendText;
7736 else if (e.Data.GetDataPresent(DataFormats.UnicodeText))
7738 var text = (string)e.Data.GetData(DataFormats.UnicodeText);
7740 this.StatusText.Text += text;
7742 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
7744 var data = (string)e.Data.GetData(DataFormats.StringFormat, true);
7745 if (data != null) this.StatusText.Text += data;
7750 /// IDataObject から URL とタイトルの対を取得します
7753 /// タイトルのみ取得できなかった場合は Value2 が null のタプルを返すことがあります。
7755 /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
7756 /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
7757 internal static (string Url, string? Title) GetUrlFromDataObject(IDataObject data)
7759 if (data.GetDataPresent("text/x-moz-url"))
7761 // Firefox, Google Chrome で利用可能
7762 // 参照: https://developer.mozilla.org/ja/docs/DragDrop/Recommended_Drag_Types
7764 using var stream = (MemoryStream)data.GetData("text/x-moz-url");
7765 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\n');
7766 if (lines.Length < 2)
7767 throw new ArgumentException("不正な text/x-moz-url フォーマットです", nameof(data));
7769 return (lines[0], lines[1]);
7771 else if (data.GetDataPresent("IESiteModeToUrl"))
7773 // Internet Exproler 用
7774 // 保護モードが有効なデフォルトの IE では DragDrop イベントが発火しないため使えない
7776 using var stream = (MemoryStream)data.GetData("IESiteModeToUrl");
7777 var lines = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0').Split('\0');
7778 if (lines.Length < 2)
7779 throw new ArgumentException("不正な IESiteModeToUrl フォーマットです", nameof(data));
7781 return (lines[0], lines[1]);
7783 else if (data.GetDataPresent("UniformResourceLocatorW"))
7787 using var stream = (MemoryStream)data.GetData("UniformResourceLocatorW");
7788 var url = Encoding.Unicode.GetString(stream.ToArray()).TrimEnd('\0');
7792 throw new NotSupportedException("サポートされていないデータ形式です: " + data.GetFormats()[0]);
7795 private void TweenMain_DragEnter(object sender, DragEventArgs e)
7797 if (e.Data.GetDataPresent(DataFormats.FileDrop))
7799 if (!e.Data.GetDataPresent(DataFormats.Html, false)) // WebBrowserコントロールからの絵文字画像Drag&Dropは弾く
7801 this.SelectMedia_DragEnter(e);
7805 else if (e.Data.GetDataPresent("UniformResourceLocatorW"))
7807 e.Effect = DragDropEffects.Copy;
7810 else if (e.Data.GetDataPresent(DataFormats.UnicodeText))
7812 e.Effect = DragDropEffects.Copy;
7815 else if (e.Data.GetDataPresent(DataFormats.StringFormat))
7817 e.Effect = DragDropEffects.Copy;
7821 e.Effect = DragDropEffects.None;
7824 private void TweenMain_DragOver(object sender, DragEventArgs e)
7828 public bool IsNetworkAvailable()
7830 var nw = MyCommon.IsNetworkAvailable();
7831 this.myStatusOnline = nw;
7835 public async Task OpenUriAsync(Uri uri, bool isReverseSettings = false)
7837 var uriStr = uri.AbsoluteUri;
7839 // OpenTween 内部で使用する URL
7840 if (uri.Authority == "opentween")
7842 await this.OpenInternalUriAsync(uri);
7846 // ハッシュタグを含む Twitter 検索
7847 if (uri.Host == "twitter.com" && uri.AbsolutePath == "/search" && uri.Query.Contains("q=%23"))
7850 var unescapedQuery = Uri.UnescapeDataString(uri.Query);
7851 var pos = unescapedQuery.IndexOf('#');
7852 if (pos == -1) return;
7854 var hash = unescapedQuery.Substring(pos);
7855 this.HashSupl.AddItem(hash);
7856 this.HashMgr.AddHashToHistory(hash.Trim(), false);
7857 this.AddNewTabForSearch(hash);
7862 // フラグが立っている場合は設定と逆の動作をする
7863 if (this.settings.Common.OpenUserTimeline && !isReverseSettings ||
7864 !this.settings.Common.OpenUserTimeline && isReverseSettings)
7866 var userUriMatch = Regex.Match(uriStr, "^https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)$");
7867 if (userUriMatch.Success)
7869 var screenName = userUriMatch.Groups["ScreenName"].Value;
7870 if (this.IsTwitterId(screenName))
7872 await this.AddNewTabForUserTimeline(screenName);
7879 await MyCommon.OpenInBrowserAsync(this, uriStr);
7883 /// OpenTween 内部の機能を呼び出すための URL を開きます
7885 private async Task OpenInternalUriAsync(Uri uri)
7887 // ツイートを開く (//opentween/status/:status_id)
7888 var match = Regex.Match(uri.AbsolutePath, @"^/status/(\d+)$");
7891 var statusId = long.Parse(match.Groups[1].Value);
7892 await this.OpenRelatedTab(statusId);
7897 private void ListTabSelect(TabPage tabPage)
7899 this.SetListProperty();
7901 var previousTabName = this.CurrentTabName;
7902 if (this.listViewState.TryGetValue(previousTabName, out var previousListViewState))
7903 previousListViewState.Save(this.ListLockMenuItem.Checked);
7905 this.listCache?.PurgeCache();
7907 this.statuses.SelectTab(tabPage.Text);
7909 this.InitializeTimelineListView();
7911 var tab = this.CurrentTab;
7914 var listView = this.CurrentListView;
7916 var currentListViewState = this.listViewState[tab.TabName];
7917 currentListViewState.Restore(forceScroll: true);
7919 if (this.Use2ColumnsMode)
7921 listView.Columns[1].Text = this.columnText[2];
7925 for (var i = 0; i < listView.Columns.Count; i++)
7927 listView.Columns[i].Text = this.columnText[i];
7932 private void InitializeTimelineListView()
7934 var listView = this.CurrentListView;
7935 var tab = this.CurrentTab;
7937 var newCache = new TimelineListViewCache(listView, tab, this.settings.Common);
7938 (this.listCache, var oldCache) = (newCache, this.listCache);
7939 oldCache?.Dispose();
7941 var newDrawer = new TimelineListViewDrawer(listView, tab, this.listCache, this.iconCache, this.themeManager);
7942 (this.listDrawer, var oldDrawer) = (newDrawer, this.listDrawer);
7943 oldDrawer?.Dispose();
7945 newDrawer.IconSize = this.settings.Common.IconSize;
7946 newDrawer.UpdateItemHeight();
7949 private void ListTab_Selecting(object sender, TabControlCancelEventArgs e)
7950 => this.ListTabSelect(e.TabPage);
7952 private void SelectListItem(DetailsListView lView, int index)
7955 var bnd = new Rectangle();
7957 var item = lView.FocusedItem;
7966 lView.SelectedIndices.Clear();
7968 while (lView.SelectedIndices.Count > 0);
7969 item = lView.Items[index];
7970 item.Selected = true;
7971 item.Focused = true;
7973 if (flg) lView.Invalidate(bnd);
7976 private async void TweenMain_Shown(object sender, EventArgs e)
7978 this.NotifyIcon1.Visible = true;
7980 if (this.IsNetworkAvailable())
7982 var loadTasks = new List<Task>
7984 this.RefreshMuteUserIdsAsync(),
7985 this.RefreshBlockIdsAsync(),
7986 this.RefreshNoRetweetIdsAsync(),
7987 this.RefreshTwitterConfigurationAsync(),
7988 this.RefreshTabAsync<HomeTabModel>(),
7989 this.RefreshTabAsync<MentionsTabModel>(),
7990 this.RefreshTabAsync<DirectMessagesTabModel>(),
7991 this.RefreshTabAsync<PublicSearchTabModel>(),
7992 this.RefreshTabAsync<UserTimelineTabModel>(),
7993 this.RefreshTabAsync<ListTimelineTabModel>(),
7996 if (this.settings.Common.StartupFollowers)
7997 loadTasks.Add(this.RefreshFollowerIdsAsync());
7999 if (this.settings.Common.GetFav)
8000 loadTasks.Add(this.RefreshTabAsync<FavoritesTabModel>());
8002 var allTasks = Task.WhenAll(loadTasks);
8007 var timeout = Task.Delay(5000);
8008 if (await Task.WhenAny(allTasks, timeout) != timeout)
8012 if (i > 24) break; // 120秒間初期処理が終了しなかったら強制的に打ち切る
8014 if (MyCommon.EndingFlag)
8018 if (MyCommon.EndingFlag) return;
8020 if (ApplicationSettings.VersionInfoUrl != null)
8022 // バージョンチェック(引数:起動時チェックの場合はtrue・・・チェック結果のメッセージを表示しない)
8023 if (this.settings.Common.StartupVersion)
8024 await this.CheckNewVersion(true);
8028 // ApplicationSetting.cs の設定により更新チェックが無効化されている場合
8029 this.VerUpMenuItem.Enabled = false;
8030 this.VerUpMenuItem.Available = false;
8031 this.ToolStripSeparator16.Available = false; // VerUpMenuItem の一つ上にあるセパレータ
8034 // 権限チェック read/write権限(xAuthで取得したトークン)の場合は再認証を促す
8035 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
8037 MessageBox.Show(Properties.Resources.ReAuthorizeText);
8038 this.SettingStripMenuItem_Click(this.SettingStripMenuItem, EventArgs.Empty);
8042 var reloadTasks = new List<Task>();
8044 if (!this.tw.GetFollowersSuccess && this.settings.Common.StartupFollowers)
8045 reloadTasks.Add(this.RefreshFollowerIdsAsync());
8047 if (!this.tw.GetNoRetweetSuccess)
8048 reloadTasks.Add(this.RefreshNoRetweetIdsAsync());
8050 if (this.tw.Configuration.PhotoSizeLimit == 0)
8051 reloadTasks.Add(this.RefreshTwitterConfigurationAsync());
8053 await Task.WhenAll(reloadTasks);
8056 this.initial = false;
8058 this.timelineScheduler.Enabled = true;
8061 private async Task DoGetFollowersMenu()
8063 await this.RefreshFollowerIdsAsync();
8064 this.DispSelectedPost(true);
8067 private async void GetFollowersAllToolStripMenuItem_Click(object sender, EventArgs e)
8068 => await this.DoGetFollowersMenu();
8070 private void ReTweetUnofficialStripMenuItem_Click(object sender, EventArgs e)
8071 => this.DoReTweetUnofficial();
8073 private async Task DoReTweetOfficial(bool isConfirm)
8076 if (this.ExistCurrentPost)
8078 var selectedPosts = this.CurrentTab.SelectedPosts;
8080 if (selectedPosts.Any(x => !x.CanRetweetBy(this.tw.UserId)))
8082 if (selectedPosts.Any(x => x.IsProtect))
8083 MessageBox.Show("Protected.");
8085 this.doFavRetweetFlags = false;
8089 if (selectedPosts.Length > 15)
8091 MessageBox.Show(Properties.Resources.RetweetLimitText);
8092 this.doFavRetweetFlags = false;
8095 else if (selectedPosts.Length > 1)
8097 var questionText = Properties.Resources.RetweetQuestion2;
8098 if (this.doFavRetweetFlags) questionText = Properties.Resources.FavoriteRetweetQuestionText1;
8099 switch (MessageBox.Show(questionText, "Retweet", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
8101 case DialogResult.Cancel:
8102 case DialogResult.No:
8103 this.doFavRetweetFlags = false;
8109 if (!this.settings.Common.RetweetNoConfirm)
8111 var questiontext = Properties.Resources.RetweetQuestion1;
8112 if (this.doFavRetweetFlags) questiontext = Properties.Resources.FavoritesRetweetQuestionText2;
8113 if (isConfirm && MessageBox.Show(questiontext, "Retweet", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
8115 this.doFavRetweetFlags = false;
8121 var statusIds = selectedPosts.Select(x => x.StatusId).ToList();
8123 await this.RetweetAsync(statusIds);
8127 private async void ReTweetStripMenuItem_Click(object sender, EventArgs e)
8128 => await this.DoReTweetOfficial(true);
8130 private async Task FavoritesRetweetOfficial()
8132 if (!this.ExistCurrentPost) return;
8133 this.doFavRetweetFlags = true;
8134 var retweetTask = this.DoReTweetOfficial(true);
8135 if (this.doFavRetweetFlags)
8137 this.doFavRetweetFlags = false;
8138 var favoriteTask = this.FavoriteChange(true, false);
8140 await Task.WhenAll(retweetTask, favoriteTask);
8148 private async Task FavoritesRetweetUnofficial()
8150 var post = this.CurrentPost;
8151 if (this.ExistCurrentPost && post != null && !post.IsDm)
8153 this.doFavRetweetFlags = true;
8154 var favoriteTask = this.FavoriteChange(true);
8155 if (!post.IsProtect && this.doFavRetweetFlags)
8157 this.doFavRetweetFlags = false;
8158 this.DoReTweetUnofficial();
8166 /// TweetFormatterクラスによって整形された状態のHTMLを、非公式RT用に元のツイートに復元します
8168 /// <param name="statusHtml">TweetFormatterによって整形された状態のHTML</param>
8169 /// <param name="multiline">trueであればBRタグを改行に、falseであればスペースに変換します</param>
8170 /// <returns>復元されたツイート本文</returns>
8171 internal static string CreateRetweetUnofficial(string statusHtml, bool multiline)
8173 // TweetFormatterクラスによって整形された状態のHTMLを元のツイートに復元します
8176 statusHtml = Regex.Replace(statusHtml, "<a href=\"(?<href>.+?)\" title=\"(?<title>.+?)\">(?<text>.+?)</a>", "${title}");
8178 statusHtml = Regex.Replace(statusHtml, "<a class=\"mention\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
8180 statusHtml = Regex.Replace(statusHtml, "<a class=\"hashtag\" href=\"(?<href>.+?)\">(?<text>.+?)</a>", "${text}");
8182 statusHtml = Regex.Replace(statusHtml, "<img class=\"emoji\" src=\".+?\" alt=\"(?<text>.+?)\" />", "${text}");
8186 statusHtml = statusHtml.Replace("<br>", Environment.NewLine);
8188 statusHtml = statusHtml.Replace("<br>", " ");
8190 // は本来であれば U+00A0 (NON-BREAK SPACE) に置換すべきですが、
8191 // 現状では半角スペースの代用として を使用しているため U+0020 に置換します
8192 statusHtml = statusHtml.Replace(" ", " ");
8194 return WebUtility.HtmlDecode(statusHtml);
8197 private void DumpPostClassToolStripMenuItem_Click(object sender, EventArgs e)
8199 this.tweetDetailsView.DumpPostClass = this.DumpPostClassToolStripMenuItem.Checked;
8201 if (this.CurrentPost != null)
8202 this.DispSelectedPost(true);
8205 private void MenuItemHelp_DropDownOpening(object sender, EventArgs e)
8207 if (MyCommon.DebugBuild || MyCommon.IsKeyDown(Keys.CapsLock, Keys.Control, Keys.Shift))
8208 this.DebugModeToolStripMenuItem.Visible = true;
8210 this.DebugModeToolStripMenuItem.Visible = false;
8213 private void UrlMultibyteSplitMenuItem_CheckedChanged(object sender, EventArgs e)
8214 => this.urlMultibyteSplit = ((ToolStripMenuItem)sender).Checked;
8216 private void PreventSmsCommandMenuItem_CheckedChanged(object sender, EventArgs e)
8217 => this.preventSmsCommand = ((ToolStripMenuItem)sender).Checked;
8219 private void UrlAutoShortenMenuItem_CheckedChanged(object sender, EventArgs e)
8220 => this.settings.Common.UrlConvertAuto = ((ToolStripMenuItem)sender).Checked;
8222 private void IdeographicSpaceToSpaceMenuItem_Click(object sender, EventArgs e)
8224 this.settings.Common.WideSpaceConvert = ((ToolStripMenuItem)sender).Checked;
8225 this.MarkSettingCommonModified();
8228 private void FocusLockMenuItem_CheckedChanged(object sender, EventArgs e)
8230 this.settings.Common.FocusLockToStatusText = ((ToolStripMenuItem)sender).Checked;
8231 this.MarkSettingCommonModified();
8234 private void PostModeMenuItem_DropDownOpening(object sender, EventArgs e)
8236 this.UrlMultibyteSplitMenuItem.Checked = this.urlMultibyteSplit;
8237 this.PreventSmsCommandMenuItem.Checked = this.preventSmsCommand;
8238 this.UrlAutoShortenMenuItem.Checked = this.settings.Common.UrlConvertAuto;
8239 this.IdeographicSpaceToSpaceMenuItem.Checked = this.settings.Common.WideSpaceConvert;
8240 this.MultiLineMenuItem.Checked = this.settings.Local.StatusMultiline;
8241 this.FocusLockMenuItem.Checked = this.settings.Common.FocusLockToStatusText;
8244 private void ContextMenuPostMode_Opening(object sender, CancelEventArgs e)
8246 this.UrlMultibyteSplitPullDownMenuItem.Checked = this.urlMultibyteSplit;
8247 this.PreventSmsCommandPullDownMenuItem.Checked = this.preventSmsCommand;
8248 this.UrlAutoShortenPullDownMenuItem.Checked = this.settings.Common.UrlConvertAuto;
8249 this.IdeographicSpaceToSpacePullDownMenuItem.Checked = this.settings.Common.WideSpaceConvert;
8250 this.MultiLinePullDownMenuItem.Checked = this.settings.Local.StatusMultiline;
8251 this.FocusLockPullDownMenuItem.Checked = this.settings.Common.FocusLockToStatusText;
8254 private void TraceOutToolStripMenuItem_Click(object sender, EventArgs e)
8256 if (this.TraceOutToolStripMenuItem.Checked)
8257 MyCommon.TraceFlag = true;
8259 MyCommon.TraceFlag = false;
8262 private void TweenMain_Deactivate(object sender, EventArgs e)
8263 => this.StatusText_Leave(this.StatusText, EventArgs.Empty); // 画面が非アクティブになったら、発言欄の背景色をデフォルトへ
8265 private void TabRenameMenuItem_Click(object sender, EventArgs e)
8267 if (MyCommon.IsNullOrEmpty(this.rclickTabName)) return;
8269 _ = this.TabRename(this.rclickTabName, out _);
8272 private async void BitlyToolStripMenuItem_Click(object sender, EventArgs e)
8273 => await this.UrlConvertAsync(MyCommon.UrlConverter.Bitly);
8275 private async void JmpToolStripMenuItem_Click(object sender, EventArgs e)
8276 => await this.UrlConvertAsync(MyCommon.UrlConverter.Jmp);
8278 private async void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
8280 TwitterApiStatus? apiStatus;
8282 using (var dialog = new WaitingDialog(Properties.Resources.ApiInfo6))
8284 var cancellationToken = dialog.EnableCancellation();
8288 var task = this.tw.GetInfoApi();
8289 apiStatus = await dialog.WaitForAsync(this, task);
8291 catch (WebApiException)
8296 if (cancellationToken.IsCancellationRequested)
8299 if (apiStatus == null)
8301 MessageBox.Show(Properties.Resources.ApiInfo5, Properties.Resources.ApiInfo4, MessageBoxButtons.OK, MessageBoxIcon.Information);
8306 using var apiDlg = new ApiInfoDialog();
8307 apiDlg.ShowDialog(this);
8310 private async void FollowCommandMenuItem_Click(object sender, EventArgs e)
8312 var id = this.CurrentPost?.ScreenName ?? "";
8314 await this.FollowCommand(id);
8317 internal async Task FollowCommand(string id)
8319 using (var inputName = new InputTabName())
8321 inputName.FormTitle = "Follow";
8322 inputName.FormDescription = Properties.Resources.FRMessage1;
8323 inputName.TabName = id;
8325 if (inputName.ShowDialog(this) != DialogResult.OK)
8327 if (string.IsNullOrWhiteSpace(inputName.TabName))
8330 id = inputName.TabName.Trim();
8333 using (var dialog = new WaitingDialog(Properties.Resources.FollowCommandText1))
8337 var task = this.tw.Api.FriendshipsCreate(id).IgnoreResponse();
8338 await dialog.WaitForAsync(this, task);
8340 catch (WebApiException ex)
8342 MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
8347 MessageBox.Show(Properties.Resources.FRMessage3);
8350 private async void RemoveCommandMenuItem_Click(object sender, EventArgs e)
8352 var id = this.CurrentPost?.ScreenName ?? "";
8354 await this.RemoveCommand(id, false);
8357 internal async Task RemoveCommand(string id, bool skipInput)
8361 using var inputName = new InputTabName();
8362 inputName.FormTitle = "Unfollow";
8363 inputName.FormDescription = Properties.Resources.FRMessage1;
8364 inputName.TabName = id;
8366 if (inputName.ShowDialog(this) != DialogResult.OK)
8368 if (string.IsNullOrWhiteSpace(inputName.TabName))
8371 id = inputName.TabName.Trim();
8374 using (var dialog = new WaitingDialog(Properties.Resources.RemoveCommandText1))
8378 var task = this.tw.Api.FriendshipsDestroy(id).IgnoreResponse();
8379 await dialog.WaitForAsync(this, task);
8381 catch (WebApiException ex)
8383 MessageBox.Show(Properties.Resources.FRMessage2 + ex.Message);
8388 MessageBox.Show(Properties.Resources.FRMessage3);
8391 private async void FriendshipMenuItem_Click(object sender, EventArgs e)
8393 var id = this.CurrentPost?.ScreenName ?? "";
8395 await this.ShowFriendship(id);
8398 internal async Task ShowFriendship(string id)
8400 using (var inputName = new InputTabName())
8402 inputName.FormTitle = "Show Friendships";
8403 inputName.FormDescription = Properties.Resources.FRMessage1;
8404 inputName.TabName = id;
8406 if (inputName.ShowDialog(this) != DialogResult.OK)
8408 if (string.IsNullOrWhiteSpace(inputName.TabName))
8411 id = inputName.TabName.Trim();
8414 bool isFollowing, isFollowed;
8416 using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
8418 var cancellationToken = dialog.EnableCancellation();
8422 var task = this.tw.Api.FriendshipsShow(this.tw.Username, id);
8423 var friendship = await dialog.WaitForAsync(this, task);
8425 isFollowing = friendship.Relationship.Source.Following;
8426 isFollowed = friendship.Relationship.Source.FollowedBy;
8428 catch (WebApiException ex)
8430 if (!cancellationToken.IsCancellationRequested)
8431 MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
8435 if (cancellationToken.IsCancellationRequested)
8442 result = Properties.Resources.GetFriendshipInfo1 + System.Environment.NewLine;
8446 result = Properties.Resources.GetFriendshipInfo2 + System.Environment.NewLine;
8450 result += Properties.Resources.GetFriendshipInfo3;
8454 result += Properties.Resources.GetFriendshipInfo4;
8456 result = id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + result;
8457 MessageBox.Show(result);
8460 internal async Task ShowFriendship(string[] ids)
8462 foreach (var id in ids)
8464 bool isFollowing, isFollowed;
8466 using (var dialog = new WaitingDialog(Properties.Resources.ShowFriendshipText1))
8468 var cancellationToken = dialog.EnableCancellation();
8472 var task = this.tw.Api.FriendshipsShow(this.tw.Username, id);
8473 var friendship = await dialog.WaitForAsync(this, task);
8475 isFollowing = friendship.Relationship.Source.Following;
8476 isFollowed = friendship.Relationship.Source.FollowedBy;
8478 catch (WebApiException ex)
8480 if (!cancellationToken.IsCancellationRequested)
8481 MessageBox.Show($"Err:{ex.Message}(FriendshipsShow)");
8485 if (cancellationToken.IsCancellationRequested)
8495 ff += Properties.Resources.GetFriendshipInfo1;
8499 ff += Properties.Resources.GetFriendshipInfo2;
8502 ff += System.Environment.NewLine + " ";
8505 ff += Properties.Resources.GetFriendshipInfo3;
8509 ff += Properties.Resources.GetFriendshipInfo4;
8511 result += id + Properties.Resources.GetFriendshipInfo5 + System.Environment.NewLine + ff;
8514 if (MessageBox.Show(
8515 Properties.Resources.GetFriendshipInfo7 + System.Environment.NewLine + result,
8516 Properties.Resources.GetFriendshipInfo8,
8517 MessageBoxButtons.YesNo,
8518 MessageBoxIcon.Question,
8519 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
8521 await this.RemoveCommand(id, true);
8526 MessageBox.Show(result);
8531 private async void OwnStatusMenuItem_Click(object sender, EventArgs e)
8532 => await this.DoShowUserStatus(this.tw.Username, false);
8534 // TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
8537 public bool IsTwitterId(string name)
8539 if (this.tw.Configuration.NonUsernamePaths == null || this.tw.Configuration.NonUsernamePaths.Length == 0)
8540 return !Regex.Match(name, @"^(about|jobs|tos|privacy|who_to_follow|download|messages)$", RegexOptions.IgnoreCase).Success;
8542 return !this.tw.Configuration.NonUsernamePaths.Contains(name, StringComparer.InvariantCultureIgnoreCase);
8545 private void DoQuoteOfficial()
8547 var post = this.CurrentPost;
8548 if (this.ExistCurrentPost && post != null)
8550 if (post.IsDm || !this.StatusText.Enabled)
8555 MessageBox.Show("Protected.");
8559 var selection = (this.StatusText.SelectionStart, this.StatusText.SelectionLength);
8561 this.inReplyTo = null;
8563 this.StatusText.Text += " " + MyCommon.GetStatusUrl(post);
8565 (this.StatusText.SelectionStart, this.StatusText.SelectionLength) = selection;
8566 this.StatusText.Focus();
8570 private void DoReTweetUnofficial()
8573 var post = this.CurrentPost;
8574 if (this.ExistCurrentPost && post != null)
8576 if (post.IsDm || !this.StatusText.Enabled)
8581 MessageBox.Show("Protected.");
8584 var rtdata = post.Text;
8585 rtdata = CreateRetweetUnofficial(rtdata, this.StatusText.Multiline);
8587 var selection = (this.StatusText.SelectionStart, this.StatusText.SelectionLength);
8589 // 投稿時に in_reply_to_status_id を付加する
8590 var inReplyToStatusId = post.RetweetedId ?? post.StatusId;
8591 var inReplyToScreenName = post.ScreenName;
8592 this.inReplyTo = (inReplyToStatusId, inReplyToScreenName);
8594 this.StatusText.Text += " RT @" + post.ScreenName + ": " + rtdata;
8596 (this.StatusText.SelectionStart, this.StatusText.SelectionLength) = selection;
8597 this.StatusText.Focus();
8601 private void QuoteStripMenuItem_Click(object sender, EventArgs e)
8602 => this.DoQuoteOfficial();
8604 private async void SearchButton_Click(object sender, EventArgs e)
8607 var pnl = ((Control)sender).Parent;
8608 if (pnl == null) return;
8609 var tbName = pnl.Parent.Text;
8610 var tb = (PublicSearchTabModel)this.statuses.Tabs[tbName];
8611 var cmb = (ComboBox)pnl.Controls["comboSearch"];
8612 var cmbLang = (ComboBox)pnl.Controls["comboLang"];
8613 cmb.Text = cmb.Text.Trim();
8614 // 検索式演算子 OR についてのみ大文字しか認識しないので強制的に大文字とする
8616 var buf = new StringBuilder();
8617 var c = cmb.Text.ToCharArray();
8618 for (var cnt = 0; cnt < cmb.Text.Length; cnt++)
8620 if (cnt > cmb.Text.Length - 4)
8622 buf.Append(cmb.Text.Substring(cnt));
8631 if (!quote && cmb.Text.Substring(cnt, 4).Equals(" or ", StringComparison.OrdinalIgnoreCase))
8640 cmb.Text = buf.ToString();
8642 var listView = (DetailsListView)pnl.Parent.Tag;
8644 var queryChanged = tb.SearchWords != cmb.Text || tb.SearchLang != cmbLang.Text;
8646 tb.SearchWords = cmb.Text;
8647 tb.SearchLang = cmbLang.Text;
8648 if (MyCommon.IsNullOrEmpty(cmb.Text))
8651 this.SaveConfigsTabs();
8656 var idx = cmb.Items.IndexOf(tb.SearchWords);
8657 if (idx > -1) cmb.Items.RemoveAt(idx);
8658 cmb.Items.Insert(0, tb.SearchWords);
8659 cmb.Text = tb.SearchWords;
8661 this.statuses.ClearTabIds(tbName);
8662 this.listCache?.PurgeCache();
8663 this.listCache?.UpdateListSize();
8664 this.SaveConfigsTabs(); // 検索条件の保存
8668 await this.RefreshTabAsync(tb);
8671 private async void RefreshMoreStripMenuItem_Click(object sender, EventArgs e)
8672 => await this.DoRefreshMore(); // もっと前を取得
8675 /// 指定されたタブのListTabにおける位置を返します
8678 /// 非表示のタブについて -1 が返ることを常に考慮して下さい
8680 public int GetTabPageIndex(string tabName)
8681 => this.statuses.Tabs.IndexOf(tabName);
8683 private void UndoRemoveTabMenuItem_Click(object sender, EventArgs e)
8685 if (this.statuses.RemovedTab.Count == 0)
8687 MessageBox.Show("There isn't removed tab.", "Undo", MessageBoxButtons.OK, MessageBoxIcon.Information);
8692 var tb = this.statuses.RemovedTab.Pop();
8693 if (tb.TabType == MyCommon.TabUsageType.Related)
8695 var relatedTab = this.statuses.GetTabByType(MyCommon.TabUsageType.Related);
8696 if (relatedTab != null)
8698 // 関連発言なら既存のタブを置き換える
8699 tb.TabName = relatedTab.TabName;
8700 this.ClearTab(tb.TabName, false);
8702 this.statuses.ReplaceTab(tb);
8704 var tabIndex = this.statuses.Tabs.IndexOf(tb);
8705 this.ListTab.SelectedIndex = tabIndex;
8709 const string TabName = "Related Tweets";
8710 var renamed = TabName;
8711 for (var i = 2; i <= 100; i++)
8713 if (!this.statuses.ContainsTab(renamed))
8715 renamed = TabName + i;
8717 tb.TabName = renamed;
8719 this.statuses.AddTab(tb);
8720 this.AddNewTab(tb, startup: false);
8722 var tabIndex = this.statuses.Tabs.Count - 1;
8723 this.ListTab.SelectedIndex = tabIndex;
8728 var renamed = tb.TabName;
8729 for (var i = 1; i < int.MaxValue; i++)
8731 if (!this.statuses.ContainsTab(renamed))
8733 renamed = tb.TabName + "(" + i + ")";
8735 tb.TabName = renamed;
8737 this.statuses.AddTab(tb);
8738 this.AddNewTab(tb, startup: false);
8740 var tabIndex = this.statuses.Tabs.Count - 1;
8741 this.ListTab.SelectedIndex = tabIndex;
8743 this.SaveConfigsTabs();
8747 private async Task DoMoveToRTHome()
8749 var post = this.CurrentPost;
8750 if (post != null && post.RetweetedId != null)
8751 await MyCommon.OpenInBrowserAsync(this, "https://twitter.com/" + post.RetweetedBy);
8754 private async void RetweetedByOpenInBrowserMenuItem_Click(object sender, EventArgs e)
8755 => await this.DoMoveToRTHome();
8757 private void AuthorListManageMenuItem_Click(object sender, EventArgs e)
8759 var screenName = this.CurrentPost?.ScreenName;
8760 if (screenName != null)
8761 this.ListManageUserContext(screenName);
8764 private void RetweetedByListManageMenuItem_Click(object sender, EventArgs e)
8766 var screenName = this.CurrentPost?.RetweetedBy;
8767 if (screenName != null)
8768 this.ListManageUserContext(screenName);
8771 public void ListManageUserContext(string screenName)
8773 using var listSelectForm = new MyLists(screenName, this.tw.Api);
8774 listSelectForm.ShowDialog(this);
8777 private void SearchControls_Enter(object sender, EventArgs e)
8779 var pnl = (Control)sender;
8780 foreach (Control ctl in pnl.Controls)
8786 private void SearchControls_Leave(object sender, EventArgs e)
8788 var pnl = (Control)sender;
8789 foreach (Control ctl in pnl.Controls)
8791 ctl.TabStop = false;
8795 private void PublicSearchQueryMenuItem_Click(object sender, EventArgs e)
8797 var tab = this.CurrentTab;
8798 if (tab.TabType != MyCommon.TabUsageType.PublicSearch) return;
8799 this.CurrentTabPage.Controls["panelSearch"].Controls["comboSearch"].Focus();
8802 private void StatusLabel_DoubleClick(object sender, EventArgs e)
8803 => MessageBox.Show(this.StatusLabel.TextHistory, "Logs", MessageBoxButtons.OK, MessageBoxIcon.None);
8805 private void HashManageMenuItem_Click(object sender, EventArgs e)
8810 rslt = this.HashMgr.ShowDialog();
8816 this.TopMost = this.settings.Common.AlwaysTop;
8817 if (rslt == DialogResult.Cancel) return;
8818 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
8820 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
8821 this.HashTogglePullDownMenuItem.Checked = true;
8822 this.HashToggleMenuItem.Checked = true;
8826 this.HashStripSplitButton.Text = "#[-]";
8827 this.HashTogglePullDownMenuItem.Checked = false;
8828 this.HashToggleMenuItem.Checked = false;
8831 this.MarkSettingCommonModified();
8832 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
8835 private void HashToggleMenuItem_Click(object sender, EventArgs e)
8837 this.HashMgr.ToggleHash();
8838 if (!MyCommon.IsNullOrEmpty(this.HashMgr.UseHash))
8840 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
8841 this.HashToggleMenuItem.Checked = true;
8842 this.HashTogglePullDownMenuItem.Checked = true;
8846 this.HashStripSplitButton.Text = "#[-]";
8847 this.HashToggleMenuItem.Checked = false;
8848 this.HashTogglePullDownMenuItem.Checked = false;
8850 this.MarkSettingCommonModified();
8851 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
8854 private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
8855 => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty);
8857 public void SetPermanentHashtag(string hashtag)
8859 this.HashMgr.SetPermanentHash("#" + hashtag);
8860 this.HashStripSplitButton.Text = this.HashMgr.UseHash;
8861 this.HashTogglePullDownMenuItem.Checked = true;
8862 this.HashToggleMenuItem.Checked = true;
8864 this.MarkSettingCommonModified();
8867 private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
8869 var tab = this.CurrentTab;
8870 var post = this.CurrentPost;
8871 if (!this.ExistCurrentPost)
8873 this.ReplyOpMenuItem.Enabled = false;
8874 this.ReplyAllOpMenuItem.Enabled = false;
8875 this.DmOpMenuItem.Enabled = false;
8876 this.CreateTabRuleOpMenuItem.Enabled = false;
8877 this.CreateIdRuleOpMenuItem.Enabled = false;
8878 this.CreateSourceRuleOpMenuItem.Enabled = false;
8879 this.ReadOpMenuItem.Enabled = false;
8880 this.UnreadOpMenuItem.Enabled = false;
8881 this.AuthorMenuItem.Visible = false;
8882 this.RetweetedByMenuItem.Visible = false;
8886 this.ReplyOpMenuItem.Enabled = true;
8887 this.ReplyAllOpMenuItem.Enabled = true;
8888 this.DmOpMenuItem.Enabled = true;
8889 this.CreateTabRuleOpMenuItem.Enabled = true;
8890 this.CreateIdRuleOpMenuItem.Enabled = true;
8891 this.CreateSourceRuleOpMenuItem.Enabled = true;
8892 this.ReadOpMenuItem.Enabled = true;
8893 this.UnreadOpMenuItem.Enabled = true;
8894 this.AuthorMenuItem.Visible = true;
8895 this.AuthorMenuItem.Text = $"@{post!.ScreenName}";
8896 this.RetweetedByMenuItem.Visible = post.RetweetedByUserId != null;
8897 this.RetweetedByMenuItem.Text = $"@{post.RetweetedBy}";
8900 if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
8902 this.FavOpMenuItem.Enabled = false;
8903 this.UnFavOpMenuItem.Enabled = false;
8904 this.OpenStatusOpMenuItem.Enabled = false;
8905 this.ShowRelatedStatusesMenuItem2.Enabled = false;
8906 this.RtOpMenuItem.Enabled = false;
8907 this.RtUnOpMenuItem.Enabled = false;
8908 this.QtOpMenuItem.Enabled = false;
8909 this.FavoriteRetweetMenuItem.Enabled = false;
8910 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
8914 this.FavOpMenuItem.Enabled = true;
8915 this.UnFavOpMenuItem.Enabled = true;
8916 this.OpenStatusOpMenuItem.Enabled = true;
8917 this.ShowRelatedStatusesMenuItem2.Enabled = true; // PublicSearchの時問題出るかも
8919 if (!post.CanRetweetBy(this.tw.UserId))
8921 this.RtOpMenuItem.Enabled = false;
8922 this.RtUnOpMenuItem.Enabled = false;
8923 this.QtOpMenuItem.Enabled = false;
8924 this.FavoriteRetweetMenuItem.Enabled = false;
8925 this.FavoriteRetweetUnofficialMenuItem.Enabled = false;
8929 this.RtOpMenuItem.Enabled = true;
8930 this.RtUnOpMenuItem.Enabled = true;
8931 this.QtOpMenuItem.Enabled = true;
8932 this.FavoriteRetweetMenuItem.Enabled = true;
8933 this.FavoriteRetweetUnofficialMenuItem.Enabled = true;
8937 if (tab.TabType != MyCommon.TabUsageType.Favorites)
8939 this.RefreshPrevOpMenuItem.Enabled = true;
8943 this.RefreshPrevOpMenuItem.Enabled = false;
8945 if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
8947 this.OpenRepSourceOpMenuItem.Enabled = false;
8951 this.OpenRepSourceOpMenuItem.Enabled = true;
8954 if (this.ExistCurrentPost && post != null)
8956 this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
8960 private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
8961 => this.ContextMenuTabProperty_Opening(sender, null!);
8963 public Twitter TwitterInstance
8966 private void SplitContainer3_SplitterMoved(object sender, SplitterEventArgs e)
8968 if (this.initialLayout)
8971 int splitterDistance;
8972 switch (this.WindowState)
8974 case FormWindowState.Normal:
8975 splitterDistance = this.SplitContainer3.SplitterDistance;
8977 case FormWindowState.Maximized:
8978 // 最大化時は、通常時のウィンドウサイズに換算した SplitterDistance を算出する
8979 var normalContainerWidth = this.mySize.Width - SystemInformation.Border3DSize.Width * 2;
8980 splitterDistance = this.SplitContainer3.SplitterDistance - (this.SplitContainer3.Width - normalContainerWidth);
8981 splitterDistance = Math.Min(splitterDistance, normalContainerWidth - this.SplitContainer3.SplitterWidth - this.SplitContainer3.Panel2MinSize);
8987 this.mySpDis3 = splitterDistance;
8988 this.MarkSettingLocalModified();
8991 private void MenuItemEdit_DropDownOpening(object sender, EventArgs e)
8993 if (this.statuses.RemovedTab.Count == 0)
8995 this.UndoRemoveTabMenuItem.Enabled = false;
8999 this.UndoRemoveTabMenuItem.Enabled = true;
9002 if (this.CurrentTab.TabType == MyCommon.TabUsageType.PublicSearch)
9003 this.PublicSearchQueryMenuItem.Enabled = true;
9005 this.PublicSearchQueryMenuItem.Enabled = false;
9007 var post = this.CurrentPost;
9008 if (!this.ExistCurrentPost || post == null)
9010 this.CopySTOTMenuItem.Enabled = false;
9011 this.CopyURLMenuItem.Enabled = false;
9012 this.CopyUserIdStripMenuItem.Enabled = false;
9016 this.CopySTOTMenuItem.Enabled = true;
9017 this.CopyURLMenuItem.Enabled = true;
9018 this.CopyUserIdStripMenuItem.Enabled = true;
9020 if (post.IsDm) this.CopyURLMenuItem.Enabled = false;
9021 if (post.IsProtect) this.CopySTOTMenuItem.Enabled = false;
9025 private void NotifyIcon1_MouseMove(object sender, MouseEventArgs e)
9026 => this.SetNotifyIconText();
9028 private async void UserStatusToolStripMenuItem_Click(object sender, EventArgs e)
9029 => await this.ShowUserStatus(this.CurrentPost?.ScreenName ?? "");
9031 private async Task DoShowUserStatus(string id, bool showInputDialog)
9033 TwitterUser? user = null;
9035 if (showInputDialog)
9037 using var inputName = new InputTabName();
9038 inputName.FormTitle = "Show UserStatus";
9039 inputName.FormDescription = Properties.Resources.FRMessage1;
9040 inputName.TabName = id;
9042 if (inputName.ShowDialog(this) != DialogResult.OK)
9044 if (string.IsNullOrWhiteSpace(inputName.TabName))
9047 id = inputName.TabName.Trim();
9050 using (var dialog = new WaitingDialog(Properties.Resources.doShowUserStatusText1))
9052 var cancellationToken = dialog.EnableCancellation();
9056 var task = this.tw.Api.UsersShow(id);
9057 user = await dialog.WaitForAsync(this, task);
9059 catch (WebApiException ex)
9061 if (!cancellationToken.IsCancellationRequested)
9062 MessageBox.Show($"Err:{ex.Message}(UsersShow)");
9066 if (cancellationToken.IsCancellationRequested)
9070 await this.DoShowUserStatus(user);
9073 private async Task DoShowUserStatus(TwitterUser user)
9075 using var userDialog = new UserInfoDialog(this, this.tw.Api);
9076 var showUserTask = userDialog.ShowUserAsync(user);
9077 userDialog.ShowDialog(this);
9080 this.BringToFront();
9082 // ユーザー情報の表示が完了するまで userDialog を破棄しない
9086 internal Task ShowUserStatus(string id, bool showInputDialog)
9087 => this.DoShowUserStatus(id, showInputDialog);
9089 internal Task ShowUserStatus(string id)
9090 => this.DoShowUserStatus(id, true);
9092 private async void AuthorShowProfileMenuItem_Click(object sender, EventArgs e)
9094 var post = this.CurrentPost;
9097 await this.ShowUserStatus(post.ScreenName, false);
9101 private async void RetweetedByShowProfileMenuItem_Click(object sender, EventArgs e)
9103 var retweetedBy = this.CurrentPost?.RetweetedBy;
9104 if (retweetedBy != null)
9106 await this.ShowUserStatus(retweetedBy, false);
9110 private async void RtCountMenuItem_Click(object sender, EventArgs e)
9112 var post = this.CurrentPost;
9113 if (!this.ExistCurrentPost || post == null)
9116 var statusId = post.RetweetedId ?? post.StatusId;
9117 TwitterStatus status;
9119 using (var dialog = new WaitingDialog(Properties.Resources.RtCountMenuItem_ClickText1))
9121 var cancellationToken = dialog.EnableCancellation();
9125 var task = this.tw.Api.StatusesShow(statusId);
9126 status = await dialog.WaitForAsync(this, task);
9128 catch (WebApiException ex)
9130 if (!cancellationToken.IsCancellationRequested)
9131 MessageBox.Show(Properties.Resources.RtCountText2 + Environment.NewLine + "Err:" + ex.Message);
9135 if (cancellationToken.IsCancellationRequested)
9139 MessageBox.Show(status.RetweetCount + Properties.Resources.RtCountText1);
9142 private void HookGlobalHotkey_HotkeyPressed(object sender, KeyEventArgs e)
9144 if ((this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized) && this.Visible && Form.ActiveForm == this)
9147 this.Visible = false;
9149 else if (Form.ActiveForm == null)
9151 this.Visible = true;
9152 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
9154 this.BringToFront();
9155 this.StatusText.Focus();
9159 private void SplitContainer2_MouseDoubleClick(object sender, MouseEventArgs e)
9160 => this.MultiLinePullDownMenuItem.PerformClick();
9163 private void ImageSelectMenuItem_Click(object sender, EventArgs e)
9165 if (this.ImageSelector.Visible)
9166 this.ImageSelector.EndSelection();
9168 this.ImageSelector.BeginSelection();
9171 private void SelectMedia_DragEnter(DragEventArgs e)
9173 if (this.ImageSelector.Model.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0], true))
9175 e.Effect = DragDropEffects.Copy;
9178 e.Effect = DragDropEffects.None;
9181 private void SelectMedia_DragDrop(DragEventArgs e)
9184 this.BringToFront();
9186 var filePathArray = (string[])e.Data.GetData(DataFormats.FileDrop, false);
9187 this.ImageSelector.BeginSelection();
9188 this.ImageSelector.Model.AddMediaItemFromFilePath(filePathArray);
9189 this.StatusText.Focus();
9192 private void ImageSelector_BeginSelecting(object sender, EventArgs e)
9194 this.TimelinePanel.Visible = false;
9195 this.TimelinePanel.Enabled = false;
9198 private void ImageSelector_EndSelecting(object sender, EventArgs e)
9200 this.TimelinePanel.Visible = true;
9201 this.TimelinePanel.Enabled = true;
9202 this.CurrentListView.Focus();
9205 private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
9206 => this.AllowDrop = false;
9208 private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
9209 => this.AllowDrop = true;
9211 private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
9213 if (this.ImageSelector.Visible)
9215 this.MarkSettingCommonModified();
9216 this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
9220 private void ImageSelector_VisibleChanged(object sender, EventArgs e)
9221 => this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
9224 /// StatusTextでCtrl+Vが押下された時の処理
9226 private void ProcClipboardFromStatusTextWhenCtrlPlusV()
9230 if (Clipboard.ContainsText())
9232 // clipboardにテキストがある場合は貼り付け処理
9233 this.StatusText.Paste(Clipboard.GetText());
9235 else if (Clipboard.ContainsImage())
9238 using var image = Clipboard.GetImage();
9239 this.ImageSelector.BeginSelection();
9240 this.ImageSelector.Model.AddMediaItemFromImage(image);
9242 else if (Clipboard.ContainsFileDropList())
9244 var files = Clipboard.GetFileDropList().Cast<string>().ToArray();
9245 this.ImageSelector.BeginSelection();
9246 this.ImageSelector.Model.AddMediaItemFromFilePath(files);
9249 catch (ExternalException ex)
9251 MessageBox.Show(ex.Message);
9256 private void ListManageToolStripMenuItem_Click(object sender, EventArgs e)
9258 using var form = new ListManage(this.tw);
9259 form.ShowDialog(this);
9262 private bool ModifySettingCommon { get; set; }
9264 private bool ModifySettingLocal { get; set; }
9266 private bool ModifySettingAtId { get; set; }
9268 private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
9270 var post = this.CurrentPost;
9271 if (this.ExistCurrentPost && post != null && !post.IsDm)
9272 this.RtCountMenuItem.Enabled = true;
9274 this.RtCountMenuItem.Enabled = false;
9277 private void CopyUserIdStripMenuItem_Click(object sender, EventArgs e)
9278 => this.CopyUserId();
9280 private void CopyUserId()
9282 var post = this.CurrentPost;
9283 if (post == null) return;
9284 var clstr = post.ScreenName;
9287 Clipboard.SetDataObject(clstr, false, 5, 100);
9289 catch (Exception ex)
9291 MessageBox.Show(ex.Message);
9295 private async void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e)
9297 var post = this.CurrentPost;
9298 if (this.ExistCurrentPost && post != null && !post.IsDm)
9302 await this.OpenRelatedTab(post);
9304 catch (TabException ex)
9306 MessageBox.Show(this, ex.Message, ApplicationSettings.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
9312 /// 指定されたツイートに対する関連発言タブを開きます
9314 /// <param name="statusId">表示するツイートのID</param>
9315 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
9316 public async Task OpenRelatedTab(long statusId)
9318 var post = this.statuses[statusId];
9323 post = await this.tw.GetStatusApi(false, statusId);
9325 catch (WebApiException ex)
9327 this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
9332 await this.OpenRelatedTab(post);
9336 /// 指定されたツイートに対する関連発言タブを開きます
9338 /// <param name="post">表示する対象となるツイート</param>
9339 /// <exception cref="TabException">名前の重複が多すぎてタブを作成できない場合</exception>
9340 private async Task OpenRelatedTab(PostClass post)
9342 var tabRelated = this.statuses.GetTabByType<RelatedPostsTabModel>();
9343 if (tabRelated != null)
9345 this.RemoveSpecifiedTab(tabRelated.TabName, confirm: false);
9348 var tabName = this.statuses.MakeTabName("Related Tweets");
9350 tabRelated = new RelatedPostsTabModel(tabName, post)
9352 UnreadManage = false,
9356 this.statuses.AddTab(tabRelated);
9357 this.AddNewTab(tabRelated, startup: false);
9359 this.ListTab.SelectedIndex = this.statuses.Tabs.IndexOf(tabName);
9361 await this.RefreshTabAsync(tabRelated);
9363 var tabIndex = this.statuses.Tabs.IndexOf(tabRelated.TabName);
9367 // TODO: 非同期更新中にタブが閉じられている場合を厳密に考慮したい
9369 var tabPage = this.ListTab.TabPages[tabIndex];
9370 var listView = (DetailsListView)tabPage.Tag;
9371 var targetPost = tabRelated.TargetPost;
9372 var index = tabRelated.IndexOf(targetPost.RetweetedId ?? targetPost.StatusId);
9374 if (index != -1 && index < listView.Items.Count)
9376 listView.SelectedIndices.Add(index);
9377 listView.Items[index].Focused = true;
9382 private void CacheInfoMenuItem_Click(object sender, EventArgs e)
9384 var buf = new StringBuilder();
9385 buf.AppendFormat("キャッシュエントリ保持数 : {0}" + Environment.NewLine, this.iconCache.CacheCount);
9386 buf.AppendFormat("キャッシュエントリ破棄数 : {0}" + Environment.NewLine, this.iconCache.CacheRemoveCount);
9387 MessageBox.Show(buf.ToString(), "アイコンキャッシュ使用状況");
9390 private void TweenRestartMenuItem_Click(object sender, EventArgs e)
9392 MyCommon.EndingFlag = true;
9396 Application.Restart();
9400 MessageBox.Show("Failed to restart. Please run " + ApplicationSettings.ApplicationName + " manually.");
9404 private async void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
9405 => await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.tw.Username);
9407 private bool ExistCurrentPost
9411 var post = this.CurrentPost;
9412 return post != null && !post.IsDeleted;
9416 private async void AuthorShowUserTimelineMenuItem_Click(object sender, EventArgs e)
9417 => await this.ShowUserTimeline();
9419 private async void RetweetedByShowUserTimelineMenuItem_Click(object sender, EventArgs e)
9420 => await this.ShowRetweeterTimeline();
9422 private string GetUserIdFromCurPostOrInput(string caption)
9424 var id = this.CurrentPost?.ScreenName ?? "";
9426 using var inputName = new InputTabName();
9427 inputName.FormTitle = caption;
9428 inputName.FormDescription = Properties.Resources.FRMessage1;
9429 inputName.TabName = id;
9431 if (inputName.ShowDialog() == DialogResult.OK &&
9432 !MyCommon.IsNullOrEmpty(inputName.TabName.Trim()))
9434 id = inputName.TabName.Trim();
9443 private async void UserTimelineToolStripMenuItem_Click(object sender, EventArgs e)
9445 var id = this.GetUserIdFromCurPostOrInput("Show UserTimeline");
9446 if (!MyCommon.IsNullOrEmpty(id))
9448 await this.AddNewTabForUserTimeline(id);
9452 private void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
9454 if (e.Mode == Microsoft.Win32.PowerModes.Resume)
9455 this.timelineScheduler.SystemResumed();
9458 private void SystemEvents_TimeChanged(object sender, EventArgs e)
9460 var prevTimeOffset = TimeZoneInfo.Local.BaseUtcOffset;
9462 TimeZoneInfo.ClearCachedData();
9464 var curTimeOffset = TimeZoneInfo.Local.BaseUtcOffset;
9466 if (curTimeOffset != prevTimeOffset)
9469 this.listCache?.PurgeCache();
9470 this.CurrentListView.Refresh();
9472 this.DispSelectedPost(forceupdate: true);
9475 this.timelineScheduler.Reset();
9478 private void TimelineRefreshEnableChange(bool isEnable)
9480 this.timelineScheduler.Enabled = isEnable;
9483 private void StopRefreshAllMenuItem_CheckedChanged(object sender, EventArgs e)
9484 => this.TimelineRefreshEnableChange(!this.StopRefreshAllMenuItem.Checked);
9486 private async Task OpenUserAppointUrl()
9488 if (this.settings.Common.UserAppointUrl != null)
9490 if (this.settings.Common.UserAppointUrl.Contains("{ID}") || this.settings.Common.UserAppointUrl.Contains("{STATUS}"))
9492 var post = this.CurrentPost;
9495 var xUrl = this.settings.Common.UserAppointUrl;
9496 xUrl = xUrl.Replace("{ID}", post.ScreenName);
9498 var statusId = post.RetweetedId ?? post.StatusId;
9499 xUrl = xUrl.Replace("{STATUS}", statusId.ToString());
9501 await MyCommon.OpenInBrowserAsync(this, xUrl);
9506 await MyCommon.OpenInBrowserAsync(this, this.settings.Common.UserAppointUrl);
9511 private async void OpenUserSpecifiedUrlMenuItem_Click(object sender, EventArgs e)
9512 => await this.OpenUserAppointUrl();
9514 private async void GrowlHelper_Callback(object sender, GrowlHelper.NotifyCallbackEventArgs e)
9516 if (Form.ActiveForm == null)
9518 await this.InvokeAsync(() =>
9520 this.Visible = true;
9521 if (this.WindowState == FormWindowState.Minimized) this.WindowState = FormWindowState.Normal;
9523 this.BringToFront();
9524 if (e.NotifyType == GrowlHelper.NotifyType.DirectMessage)
9526 if (!this.GoDirectMessage(e.StatusId)) this.StatusText.Focus();
9530 if (!this.GoStatus(e.StatusId)) this.StatusText.Focus();
9536 private void ReplaceAppName()
9538 this.MatomeMenuItem.Text = MyCommon.ReplaceAppName(this.MatomeMenuItem.Text);
9539 this.AboutMenuItem.Text = MyCommon.ReplaceAppName(this.AboutMenuItem.Text);
9542 private void TweetThumbnail_ThumbnailLoading(object sender, EventArgs e)
9543 => this.SplitContainer3.Panel2Collapsed = false;
9545 private async void TweetThumbnail_ThumbnailDoubleClick(object sender, ThumbnailDoubleClickEventArgs e)
9546 => await this.OpenThumbnailPicture(e.Thumbnail);
9548 private async void TweetThumbnail_ThumbnailImageSearchClick(object sender, ThumbnailImageSearchEventArgs e)
9549 => await MyCommon.OpenInBrowserAsync(this, e.ImageUrl);
9551 private async Task OpenThumbnailPicture(ThumbnailInfo thumbnail)
9553 var url = thumbnail.FullSizeImageUrl ?? thumbnail.MediaPageUrl;
9555 await MyCommon.OpenInBrowserAsync(this, url);
9558 private async void TwitterApiStatusToolStripMenuItem_Click(object sender, EventArgs e)
9559 => await MyCommon.OpenInBrowserAsync(this, Twitter.ServiceAvailabilityStatusUrl);
9561 private void PostButton_KeyDown(object sender, KeyEventArgs e)
9563 if (e.KeyCode == Keys.Space)
9565 this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
9567 e.SuppressKeyPress = true;
9571 private void ContextMenuColumnHeader_Opening(object sender, CancelEventArgs e)
9573 this.IconSizeNoneToolStripMenuItem.Checked = this.settings.Common.IconSize == MyCommon.IconSizes.IconNone;
9574 this.IconSize16ToolStripMenuItem.Checked = this.settings.Common.IconSize == MyCommon.IconSizes.Icon16;
9575 this.IconSize24ToolStripMenuItem.Checked = this.settings.Common.IconSize == MyCommon.IconSizes.Icon24;
9576 this.IconSize48ToolStripMenuItem.Checked = this.settings.Common.IconSize == MyCommon.IconSizes.Icon48;
9577 this.IconSize48_2ToolStripMenuItem.Checked = this.settings.Common.IconSize == MyCommon.IconSizes.Icon48_2;
9579 this.LockListSortOrderToolStripMenuItem.Checked = this.settings.Common.SortOrderLock;
9582 private void IconSizeNoneToolStripMenuItem_Click(object sender, EventArgs e)
9583 => this.ChangeListViewIconSize(MyCommon.IconSizes.IconNone);
9585 private void IconSize16ToolStripMenuItem_Click(object sender, EventArgs e)
9586 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon16);
9588 private void IconSize24ToolStripMenuItem_Click(object sender, EventArgs e)
9589 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon24);
9591 private void IconSize48ToolStripMenuItem_Click(object sender, EventArgs e)
9592 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon48);
9594 private void IconSize48_2ToolStripMenuItem_Click(object sender, EventArgs e)
9595 => this.ChangeListViewIconSize(MyCommon.IconSizes.Icon48_2);
9597 private void ChangeListViewIconSize(MyCommon.IconSizes iconSize)
9599 if (this.settings.Common.IconSize == iconSize) return;
9601 var oldIconCol = this.Use2ColumnsMode;
9603 this.settings.Common.IconSize = iconSize;
9604 this.ApplyListViewIconSize(iconSize);
9606 if (this.Use2ColumnsMode != oldIconCol)
9608 foreach (TabPage tp in this.ListTab.TabPages)
9610 this.ResetColumns((DetailsListView)tp.Tag);
9614 this.CurrentListView.Refresh();
9615 this.MarkSettingCommonModified();
9618 private void LockListSortToolStripMenuItem_Click(object sender, EventArgs e)
9620 var state = this.LockListSortOrderToolStripMenuItem.Checked;
9621 if (this.settings.Common.SortOrderLock == state) return;
9623 this.settings.Common.SortOrderLock = state;
9624 this.MarkSettingCommonModified();
9627 private void TweetDetailsView_StatusChanged(object sender, TweetDetailsViewStatusChengedEventArgs e)
9629 if (!MyCommon.IsNullOrEmpty(e.StatusText))
9631 this.StatusLabelUrl.Text = e.StatusText;
9635 this.SetStatusLabelUrl();