Skip to content

Commit

Permalink
TweenMainのメニュー等からのコマンドを現在のタブに応じたアカウントで実行する
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed Feb 6, 2024
1 parent a28b66e commit d53e0e0
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions OpenTween/Tween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,15 @@ public partial class TweenMain : OTBaseForm
private readonly AccountCollection accounts;

#pragma warning disable SA1300
private Twitter tw => ((TwitterAccount)this.PrimaryAccount).Legacy; // AccountCollection への移行用
private Twitter tw => ((TwitterAccount)this.CurrentTabAccount).Legacy; // AccountCollection への移行用
#pragma warning restore SA1300

private ISocialAccount PrimaryAccount
=> this.accounts.Primary;

private ISocialAccount CurrentTabAccount
=> this.accounts.GetAccountForTab(this.CurrentTab) ?? throw new InvalidOperationException("Account not found");

// Growl呼び出し部
private readonly GrowlHelper gh = new(ApplicationSettings.ApplicationName);

Expand Down Expand Up @@ -2217,7 +2220,7 @@ private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)
this.StatusOpenMenuItem.Enabled = true;
this.ShowRelatedStatusesMenuItem.Enabled = true; // PublicSearchの時問題出るかも

if (!post.CanRetweetBy(this.PrimaryAccount.UserId))
if (!post.CanRetweetBy(this.CurrentTabAccount.UserId))
{
this.ReTweetStripMenuItem.Enabled = false;
this.ReTweetUnofficialStripMenuItem.Enabled = false;
Expand Down Expand Up @@ -2246,7 +2249,7 @@ private void ContextMenuOperate_Opening(object sender, CancelEventArgs e)

if (this.ExistCurrentPost && post != null)
{
var primaryUserId = this.PrimaryAccount.UserId;
var primaryUserId = this.CurrentTabAccount.UserId;
this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(primaryUserId);
if (post.RetweetedByUserId == primaryUserId)
this.DeleteStripMenuItem.Text = Properties.Resources.DeleteMenuText2;
Expand All @@ -2268,7 +2271,7 @@ private async Task DoStatusDelete()
return;

// 選択されたツイートの中に削除可能なものが一つでもあるか
var primaryUserId = this.PrimaryAccount.UserId;
var primaryUserId = this.CurrentTabAccount.UserId;
if (!posts.Any(x => x.CanDeleteBy(primaryUserId)))
return;

Expand Down Expand Up @@ -3495,7 +3498,7 @@ internal string FormatStatusText(string statusText, Keys modifierKeys)
disableFooter = true;

// 自分宛のリプライの場合は先頭の「@screen_name 」の部分を除去する (in_reply_to_status_id は維持される)
var primaryUserName = this.PrimaryAccount.UserName;
var primaryUserName = this.CurrentTabAccount.UserName;
if (this.inReplyTo != null && this.inReplyTo.Value.ScreenName == primaryUserName)
{
var mentionSelf = $"@{primaryUserName} ";
Expand Down Expand Up @@ -6018,7 +6021,7 @@ private void MakeReplyText(bool atAll = false)
this.inReplyTo = null;
}

var selfScreenName = this.PrimaryAccount.UserName;
var selfScreenName = this.CurrentTabAccount.UserName;
var targetScreenNames = new List<string>();
foreach (var post in selectedPosts)
{
Expand Down Expand Up @@ -6852,7 +6855,7 @@ private void SetMainWindowTitle()
}
}

if (this.settings.Common.DispUsername) ttl.Append(this.PrimaryAccount.UserName).Append(" - ");
if (this.settings.Common.DispUsername) ttl.Append(this.CurrentTabAccount.UserName).Append(" - ");
ttl.Append(ApplicationSettings.ApplicationName);
ttl.Append(" ");
switch (this.settings.Common.DispLatestPost)
Expand Down Expand Up @@ -7021,7 +7024,7 @@ private void SetNotifyIconText()
ur.Remove(0, ur.Length);
if (this.settings.Common.DispUsername)
{
ur.Append(this.PrimaryAccount.UserName);
ur.Append(this.CurrentTabAccount.UserName);
ur.Append(" - ");
}
ur.Append(ApplicationSettings.ApplicationName);
Expand Down Expand Up @@ -7990,7 +7993,7 @@ private async Task DoReTweetOfficial(bool isConfirm)
if (this.ExistCurrentPost)
{
var selectedPosts = this.CurrentTab.SelectedPosts;
var primaryUserId = this.PrimaryAccount.UserId;
var primaryUserId = this.CurrentTabAccount.UserId;

if (selectedPosts.Any(x => !x.CanRetweetBy(primaryUserId)))
{
Expand Down Expand Up @@ -8333,7 +8336,7 @@ internal async Task ShowFriendship(string id)

try
{
var task = this.tw.Api.FriendshipsShow(this.PrimaryAccount.UserName, id);
var task = this.tw.Api.FriendshipsShow(this.CurrentTabAccount.UserName, id);
var friendship = await dialog.WaitForAsync(this, task);

isFollowing = friendship.Relationship.Source.Following;
Expand Down Expand Up @@ -8383,7 +8386,7 @@ internal async Task ShowFriendship(string[] ids)

try
{
var task = this.tw.Api.FriendshipsShow(this.PrimaryAccount.UserName, id);
var task = this.tw.Api.FriendshipsShow(this.CurrentTabAccount.UserName, id);
var friendship = await dialog.WaitForAsync(this, task);

isFollowing = friendship.Relationship.Source.Following;
Expand Down Expand Up @@ -8443,7 +8446,7 @@ internal async Task ShowFriendship(string[] ids)
}

private async void OwnStatusMenuItem_Click(object sender, EventArgs e)
=> await this.DoShowUserStatus(this.PrimaryAccount.UserName, false);
=> await this.DoShowUserStatus(this.CurrentTabAccount.UserName, false);

// TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない)
// URLから切り出した文字列を渡す
Expand Down Expand Up @@ -8784,7 +8787,7 @@ private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)
this.OpenStatusOpMenuItem.Enabled = true;
this.ShowRelatedStatusesMenuItem2.Enabled = true; // PublicSearchの時問題出るかも

if (!post.CanRetweetBy(this.PrimaryAccount.UserId))
if (!post.CanRetweetBy(this.CurrentTabAccount.UserId))
{
this.RtOpMenuItem.Enabled = false;
this.RtUnOpMenuItem.Enabled = false;
Expand Down Expand Up @@ -8821,7 +8824,7 @@ private void MenuItemOperate_DropDownOpening(object sender, EventArgs e)

if (this.ExistCurrentPost && post != null)
{
this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.PrimaryAccount.UserId);
this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.CurrentTabAccount.UserId);
}
}

Expand Down Expand Up @@ -9208,7 +9211,7 @@ private async Task OpenRelatedTab(PostClass post)

var tabName = this.statuses.MakeTabName("Related Tweets");

tabRelated = new RelatedPostsTabModel(tabName, this.PrimaryAccount.UniqueKey, post)
tabRelated = new RelatedPostsTabModel(tabName, this.CurrentTabAccount.UniqueKey, post)
{
UnreadManage = false,
Notify = false,
Expand Down Expand Up @@ -9263,7 +9266,7 @@ private void TweenRestartMenuItem_Click(object sender, EventArgs e)
}

private async void OpenOwnHomeMenuItem_Click(object sender, EventArgs e)
=> await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.PrimaryAccount.UserName);
=> await MyCommon.OpenInBrowserAsync(this, MyCommon.TwitterUrl + this.CurrentTabAccount.UserName);

private bool ExistCurrentPost
{
Expand Down

0 comments on commit d53e0e0

Please sign in to comment.