From e1d0948cfb4187b72ec3b5f6264e546d7567cfb0 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Thu, 1 Feb 2024 06:32:15 +0900 Subject: [PATCH] =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E7=94=BB=E9=9D=A2=E3=81=AE?= =?UTF-8?q?=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E4=B8=80=E8=A6=A7?= =?UTF-8?q?=E3=82=92ComboBox=E3=81=8B=E3=82=89ListBox=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.txt | 1 + OpenTween/AppendSettingDialog.cs | 39 +---- OpenTween/Properties/Resources.Designer.cs | 11 +- OpenTween/Properties/Resources.en.resx | 3 +- OpenTween/Properties/Resources.resx | 3 +- .../Setting/Panel/BasedPanel.Designer.cs | 73 +++++---- OpenTween/Setting/Panel/BasedPanel.cs | 142 ++++++++++++++---- OpenTween/Setting/Panel/BasedPanel.en.resx | 10 +- OpenTween/Setting/Panel/BasedPanel.resx | 102 +++++++------ 9 files changed, 228 insertions(+), 156 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 116f9890b..ef29d2d0b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,7 @@ 更新履歴 ==== Unreleased + * CHG: 設定画面でのアカウント一覧の表示形式を変更 ==== Ver 3.13.0(2024/01/27) * NEW: Cookie使用時のReplyタブの更新に対応(/statuses/mentions_timeline.json 廃止に伴う対応) diff --git a/OpenTween/AppendSettingDialog.cs b/OpenTween/AppendSettingDialog.cs index 0f8dfeda0..092ecf23c 100644 --- a/OpenTween/AppendSettingDialog.cs +++ b/OpenTween/AppendSettingDialog.cs @@ -47,8 +47,7 @@ public AppendSettingDialog() { this.InitializeComponent(); - this.BasedPanel.StartAuthButton.Click += this.StartAuthButton_Click; - this.BasedPanel.CreateAccountButton.Click += this.CreateAccountButton_Click; + this.BasedPanel.AddAccountButton.Click += this.AddAccountButton_Click; this.GetPeriodPanel.CheckPostAndGet.CheckedChanged += this.CheckPostAndGet_CheckedChanged; this.ActionPanel.UReadMng.CheckedChanged += this.UReadMng_CheckedChanged; @@ -115,7 +114,8 @@ private void Setting_FormClosing(object sender, FormClosingEventArgs e) { if (MyCommon.EndingFlag) return; - if (this.BasedPanel.AuthUserCombo.SelectedIndex == -1 && e.CloseReason == CloseReason.None) + var primaryAccountExists = this.BasedPanel.AccountsList.Any(x => x.IsPrimary); + if (!primaryAccountExists && e.CloseReason == CloseReason.None) { if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { @@ -151,7 +151,7 @@ private void Setting_Load(object sender, EventArgs e) this.TreeViewSetting.SelectedNode = this.TreeViewSetting.Nodes[0]; this.TreeViewSetting.ExpandAll(); - this.ActiveControl = this.BasedPanel.StartAuthButton; + this.ActiveControl = this.BasedPanel.AddAccountButton; } private void UReadMng_CheckedChanged(object sender, EventArgs e) @@ -166,9 +166,9 @@ private void UReadMng_CheckedChanged(object sender, EventArgs e) } } - private async void StartAuthButton_Click(object sender, EventArgs e) + private async void AddAccountButton_Click(object sender, EventArgs e) { - using (ControlTransaction.Disabled(this.BasedPanel.StartAuthButton)) + using (ControlTransaction.Disabled(this.BasedPanel.AddAccountButton)) { try { @@ -201,23 +201,7 @@ private async void StartAuthButton_Click(object sender, EventArgs e) newAccount = account; } - var authUserCombo = this.BasedPanel.AuthUserCombo; - - var oldAccount = authUserCombo.Items.Cast() - .FirstOrDefault(x => x.UserId == newAccount.UserId); - - int idx; - if (oldAccount != null) - { - idx = authUserCombo.Items.IndexOf(oldAccount); - authUserCombo.Items[idx] = newAccount; - } - else - { - idx = authUserCombo.Items.Add(newAccount); - } - - authUserCombo.SelectedIndex = idx; + this.BasedPanel.AddAccount(newAccount); MessageBox.Show( this, @@ -318,15 +302,6 @@ private void Setting_Shown(object sender, EventArgs e) this.GetPeriodPanel.UpdateTabCounts(TabInformations.GetInstance()); } - private async Task OpenUrl(string url) - { - var browserPathWithArgs = this.ActionPanel.BrowserPathText.Text; - await MyCommon.OpenInBrowserAsync(this, browserPathWithArgs, url); - } - - private async void CreateAccountButton_Click(object sender, EventArgs e) - => await this.OpenUrl("https://twitter.com/signup"); - private void GetPeriodPanel_IntervalChanged(object sender, IntervalChangedEventArgs e) => this.IntervalChanged?.Invoke(sender, e); } diff --git a/OpenTween/Properties/Resources.Designer.cs b/OpenTween/Properties/Resources.Designer.cs index 4938614d8..668f76c64 100644 --- a/OpenTween/Properties/Resources.Designer.cs +++ b/OpenTween/Properties/Resources.Designer.cs @@ -60,6 +60,15 @@ internal Resources() { } } + /// + /// (メイン) に類似しているローカライズされた文字列を検索します。 + /// + internal static string AccountListBoxItem_Primary { + get { + return ResourceManager.GetString("AccountListBoxItem_Primary", resourceCulture); + } + } + /// /// 発言一覧 に類似しているローカライズされた文字列を検索します。 /// @@ -2594,7 +2603,7 @@ internal static string SetStatusLabelText4 { } /// - /// 「認証開始」ボタンを押すとブラウザが開きます。「連携アプリを認証」し、表示されたPINを画面上部に入力後、「Finish」ボタンを押してください。認証せずに終了してもよろしいですか? に類似しているローカライズされた文字列を検索します。 + /// メインのアカウントが設定されていません。このまま終了してもよろしいですか? に類似しているローカライズされた文字列を検索します。 /// internal static string Setting_FormClosing1 { get { diff --git a/OpenTween/Properties/Resources.en.resx b/OpenTween/Properties/Resources.en.resx index 62d612824..383e243ea 100644 --- a/OpenTween/Properties/Resources.en.resx +++ b/OpenTween/Properties/Resources.en.resx @@ -4,6 +4,7 @@ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + (Primary) PostsList (New Tab) Name @@ -258,7 +259,7 @@ Available service: {1} -] ] [Updates: {0:#,0}] - Press [Start Authentication] button and [Authorize App]. Key in PIN then press [Finish] button. Will you exit application without validating your account? + The primary account has not been set up. Are you sure you want to exit? Failed to write settings to {0}. Existing setting files are copied to {1}. diff --git a/OpenTween/Properties/Resources.resx b/OpenTween/Properties/Resources.resx index f9cab82d6..5fbf6339d 100644 --- a/OpenTween/Properties/Resources.resx +++ b/OpenTween/Properties/Resources.resx @@ -5,6 +5,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + (メイン) 発言一覧 (新規タブ) 名前 @@ -290,7 +291,7 @@ -] ] [更新: {0:#,0}] - 「認証開始」ボタンを押すとブラウザが開きます。「連携アプリを認証」し、表示されたPINを画面上部に入力後、「Finish」ボタンを押してください。認証せずに終了してもよろしいですか? + メインのアカウントが設定されていません。このまま終了してもよろしいですか? {0} での設定の書き込みに失敗しました。 既存の設定ファイルは {1} にコピーされます。 diff --git a/OpenTween/Setting/Panel/BasedPanel.Designer.cs b/OpenTween/Setting/Panel/BasedPanel.Designer.cs index 88c42afc9..a111e990f 100644 --- a/OpenTween/Setting/Panel/BasedPanel.Designer.cs +++ b/OpenTween/Setting/Panel/BasedPanel.Designer.cs @@ -29,53 +29,53 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BasedPanel)); - this.AuthUserCombo = new System.Windows.Forms.ComboBox(); - this.CreateAccountButton = new System.Windows.Forms.Button(); - this.StartAuthButton = new System.Windows.Forms.Button(); - this.AuthClearButton = new System.Windows.Forms.Button(); - this.Label4 = new System.Windows.Forms.Label(); + this.AccountListLabel = new System.Windows.Forms.Label(); + this.AccountsListBox = new System.Windows.Forms.ListBox(); + this.AddAccountButton = new System.Windows.Forms.Button(); + this.RemoveAccountButton = new System.Windows.Forms.Button(); + this.MakePrimaryButton = new System.Windows.Forms.Button(); this.panel1 = new System.Windows.Forms.Panel(); this.panel1.SuspendLayout(); this.SuspendLayout(); // - // AuthUserCombo + // AccountListLabel // - this.AuthUserCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.AuthUserCombo.FormattingEnabled = true; - resources.ApplyResources(this.AuthUserCombo, "AuthUserCombo"); - this.AuthUserCombo.Name = "AuthUserCombo"; + resources.ApplyResources(this.AccountListLabel, "AccountListLabel"); + this.AccountListLabel.Name = "AccountListLabel"; // - // CreateAccountButton + // AccountsListBox // - resources.ApplyResources(this.CreateAccountButton, "CreateAccountButton"); - this.CreateAccountButton.Name = "CreateAccountButton"; - this.CreateAccountButton.UseVisualStyleBackColor = true; + resources.ApplyResources(this.AccountsListBox, "AccountsListBox"); + this.AccountsListBox.FormattingEnabled = true; + this.AccountsListBox.Name = "AccountsListBox"; // - // StartAuthButton + // AddAccountButton // - resources.ApplyResources(this.StartAuthButton, "StartAuthButton"); - this.StartAuthButton.Name = "StartAuthButton"; - this.StartAuthButton.UseVisualStyleBackColor = true; + resources.ApplyResources(this.AddAccountButton, "AddAccountButton"); + this.AddAccountButton.Name = "AddAccountButton"; + this.AddAccountButton.UseVisualStyleBackColor = true; // - // AuthClearButton + // RemoveAccountButton // - resources.ApplyResources(this.AuthClearButton, "AuthClearButton"); - this.AuthClearButton.Name = "AuthClearButton"; - this.AuthClearButton.UseVisualStyleBackColor = true; - this.AuthClearButton.Click += new System.EventHandler(this.AuthClearButton_Click); + resources.ApplyResources(this.RemoveAccountButton, "RemoveAccountButton"); + this.RemoveAccountButton.Name = "RemoveAccountButton"; + this.RemoveAccountButton.UseVisualStyleBackColor = true; + this.RemoveAccountButton.Click += new System.EventHandler(this.RemoveAccountButton_Click); // - // Label4 + // MakePrimaryButton // - resources.ApplyResources(this.Label4, "Label4"); - this.Label4.Name = "Label4"; + resources.ApplyResources(this.MakePrimaryButton, "MakePrimaryButton"); + this.MakePrimaryButton.Name = "MakePrimaryButton"; + this.MakePrimaryButton.UseVisualStyleBackColor = true; + this.MakePrimaryButton.Click += new System.EventHandler(this.MakePrimaryButton_Click); // // panel1 // - this.panel1.Controls.Add(this.AuthUserCombo); - this.panel1.Controls.Add(this.CreateAccountButton); - this.panel1.Controls.Add(this.StartAuthButton); - this.panel1.Controls.Add(this.AuthClearButton); - this.panel1.Controls.Add(this.Label4); + this.panel1.Controls.Add(this.AccountListLabel); + this.panel1.Controls.Add(this.AccountsListBox); + this.panel1.Controls.Add(this.AddAccountButton); + this.panel1.Controls.Add(this.RemoveAccountButton); + this.panel1.Controls.Add(this.MakePrimaryButton); resources.ApplyResources(this.panel1, "panel1"); this.panel1.Name = "panel1"; // @@ -92,12 +92,11 @@ private void InitializeComponent() } #endregion - - internal System.Windows.Forms.ComboBox AuthUserCombo; - internal System.Windows.Forms.Button CreateAccountButton; - internal System.Windows.Forms.Button StartAuthButton; - internal System.Windows.Forms.Button AuthClearButton; - internal System.Windows.Forms.Label Label4; + internal System.Windows.Forms.Label AccountListLabel; + internal System.Windows.Forms.ListBox AccountsListBox; + internal System.Windows.Forms.Button AddAccountButton; + internal System.Windows.Forms.Button RemoveAccountButton; + internal System.Windows.Forms.Button MakePrimaryButton; private System.Windows.Forms.Panel panel1; } } diff --git a/OpenTween/Setting/Panel/BasedPanel.cs b/OpenTween/Setting/Panel/BasedPanel.cs index 8824c943f..b4b76c1f1 100644 --- a/OpenTween/Setting/Panel/BasedPanel.cs +++ b/OpenTween/Setting/Panel/BasedPanel.cs @@ -27,49 +27,78 @@ #nullable enable using System; -using System.Collections.Generic; using System.ComponentModel; using System.Data; -using System.Drawing; using System.Linq; -using System.Text; -using System.Windows.Forms; namespace OpenTween.Setting.Panel { public partial class BasedPanel : SettingPanelBase { + internal BindingList AccountsList { get; } = new(); + + internal record AccountListBoxItem(UserAccount AccountSettings, bool IsPrimary) + { + public string DisplayText + => this.ComposeDisplayText(); + + private string ComposeDisplayText() + { + var authTypeText = this.AccountSettings.TwitterAuthType switch + { + APIAuthType.OAuth1 => "Twitter / OAuth", + APIAuthType.TwitterComCookie => "Twitter / Cookie", + _ => "Twitter / unknown", + }; + var accountName = $"@{this.AccountSettings.Username}"; + var suffix = this.IsPrimary ? Properties.Resources.AccountListBoxItem_Primary : ""; + + return $"[{authTypeText}] {accountName} {suffix}"; + } + } + public BasedPanel() - => this.InitializeComponent(); + { + this.InitializeComponent(); + this.InitializeBinding(); + } + + private void InitializeBinding() + { + this.AccountsListBox.DataSource = this.AccountsList; + this.AccountsListBox.DisplayMember = nameof(AccountListBoxItem.DisplayText); + } public void LoadConfig(SettingCommon settingCommon) { - using (ControlTransaction.Update(this.AuthUserCombo)) + using (ControlTransaction.Update(this.AccountsListBox)) { - this.AuthUserCombo.Items.Clear(); - this.AuthUserCombo.Items.AddRange(settingCommon.UserAccounts.ToArray()); + this.AccountsList.Clear(); - var selectedAccountKey = settingCommon.SelectedAccountKey; - var selectedAccountIndex = settingCommon.UserAccounts.FindIndex(x => x.UniqueKey == selectedAccountKey); - if (selectedAccountIndex != -1) - this.AuthUserCombo.SelectedIndex = selectedAccountIndex; + var primaryAccountKey = settingCommon.SelectedAccountKey; + foreach (var accountSettings in settingCommon.UserAccounts) + { + var isPrimary = accountSettings.UniqueKey == primaryAccountKey; + var item = new AccountListBoxItem(accountSettings, isPrimary); + this.AccountsList.Add(item); + } } } public void SaveConfig(SettingCommon settingCommon) { - var accounts = this.AuthUserCombo.Items.Cast().ToList(); + var accounts = this.AccountsList.Select(x => x.AccountSettings).ToList(); settingCommon.UserAccounts = accounts; - var selectedIndex = this.AuthUserCombo.SelectedIndex; - if (selectedIndex != -1) + var primaryItem = this.AccountsList.FirstOrDefault(x => x.IsPrimary); + if (primaryItem != null) { - var selectedAccount = accounts[selectedIndex]; - settingCommon.UserId = selectedAccount.UserId; - settingCommon.UserName = selectedAccount.Username; - settingCommon.Token = selectedAccount.Token; - settingCommon.TokenSecret = selectedAccount.TokenSecret; - settingCommon.SelectedAccountKey = selectedAccount.UniqueKey; + var primaryAccountSettings = primaryItem.AccountSettings; + settingCommon.UserId = primaryAccountSettings.UserId; + settingCommon.UserName = primaryAccountSettings.Username; + settingCommon.Token = primaryAccountSettings.Token; + settingCommon.TokenSecret = primaryAccountSettings.TokenSecret; + settingCommon.SelectedAccountKey = primaryAccountSettings.UniqueKey; } else { @@ -81,20 +110,69 @@ public void SaveConfig(SettingCommon settingCommon) } } - private void AuthClearButton_Click(object sender, EventArgs e) + internal void AddAccount(UserAccount accountSettings) { - if (this.AuthUserCombo.SelectedIndex > -1) + var duplicatedAccountIndex = + this.AccountsList.FindIndex(x => x.AccountSettings.UserId == accountSettings.UserId); + + int addIndex; + if (duplicatedAccountIndex != -1) { - this.AuthUserCombo.Items.RemoveAt(this.AuthUserCombo.SelectedIndex); - if (this.AuthUserCombo.Items.Count > 0) - { - this.AuthUserCombo.SelectedIndex = 0; - } - else - { - this.AuthUserCombo.SelectedIndex = -1; - } + addIndex = duplicatedAccountIndex; + this.AccountsList[addIndex] = this.AccountsList[addIndex] with { AccountSettings = accountSettings }; + } + else + { + addIndex = this.AccountsList.Count; + this.AccountsList.Add(new(accountSettings, IsPrimary: addIndex == 0)); + } + + this.AccountsListBox.SelectedIndex = addIndex; + } + + private void RemoveAccountAt(int index) + { + var removingPrimaryAccount = this.AccountsList[index].IsPrimary; + this.AccountsList.RemoveAt(index); + + if (removingPrimaryAccount && this.AccountsList.Count >= 1) + this.MakeAccountPrimaryAt(0); + } + + private void MakeAccountPrimaryAt(int index) + { + var oldPrimaryIndex = this.AccountsList.FindIndex(x => x.IsPrimary); + if (oldPrimaryIndex != -1) + { + if (oldPrimaryIndex == index) + return; + + this.AccountsList[oldPrimaryIndex] = + this.AccountsList[oldPrimaryIndex] with { IsPrimary = false }; } + + this.AccountsList[index] = + this.AccountsList[index] with { IsPrimary = true }; + } + + private void RemoveAccountButton_Click(object sender, EventArgs e) + { + var selectedIndex = this.AccountsListBox.SelectedIndex; + if (selectedIndex == -1) + return; + + using (ControlTransaction.Update(this.AccountsListBox)) + this.RemoveAccountAt(selectedIndex); + } + + private void MakePrimaryButton_Click(object sender, EventArgs e) + { + var selectedIndex = this.AccountsListBox.SelectedIndex; + if (selectedIndex == -1) + return; + + using (ControlTransaction.Update(this.AccountsListBox)) + this.MakeAccountPrimaryAt(selectedIndex); } } } diff --git a/OpenTween/Setting/Panel/BasedPanel.en.resx b/OpenTween/Setting/Panel/BasedPanel.en.resx index 6eb8d1ac7..0dbaecb34 100644 --- a/OpenTween/Setting/Panel/BasedPanel.en.resx +++ b/OpenTween/Setting/Panel/BasedPanel.en.resx @@ -5,9 +5,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Remove - Sign up for Twitter account - 47, 12 - Account - Start Authentication + 53, 12 + Accounts + Add + Make Primary + Remove diff --git a/OpenTween/Setting/Panel/BasedPanel.resx b/OpenTween/Setting/Panel/BasedPanel.resx index 7d65746a2..d71e0c3ef 100644 --- a/OpenTween/Setting/Panel/BasedPanel.resx +++ b/OpenTween/Setting/Panel/BasedPanel.resx @@ -12,60 +12,68 @@ 0, 0, 0, 0 BasedPanel OpenTween.Setting.Panel.SettingPanelBase, OpenTween, Version=2.4.3.1, Culture=neutral, PublicKeyToken=null - AuthClearButton - panel1 - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 3 - AuthUserCombo - panel1 - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 0 - CreateAccountButton - panel1 - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 1 - Label4 - panel1 - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 4 + AccountListLabel + panel1 + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 0 + AccountsListBox + panel1 + System.Windows.Forms.ListBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 1 + AddAccountButton + panel1 + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 2 + MakePrimaryButton + panel1 + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 4 panel1 $this System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 0 - StartAuthButton - panel1 - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 2 - True - NoControl - 293, 20 - 75, 25 - 2 - 削除 - 111, 22 - 160, 20 - 1 - Bottom, Right - True - NoControl - 310, 320 - 186, 25 - 4 - Twitter アカウントを作成する - True - NoControl - 23, 25 - 49, 12 - 0 - アカウント + RemoveAccountButton + panel1 + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 3 + True + NoControl + 21, 20 + 49, 12 + 0 + アカウント + Top, Bottom, Left, Right + False + 12 + 30, 42 + 10, 10, 10, 10 + 346, 296 + 1 + Top, Right + True + NoControl + 396, 42 + 10, 3, 3, 3 + 100, 25 + 2 + 追加 + Top, Right + True + NoControl + 396, 104 + 100, 25 + 4 + メインに設定 Fill 0, 0 20, 20, 20, 20 519, 368 0 - NoControl - 98, 63 - 321, 45 - 3 - 認証開始 + Top, Right + True + NoControl + 396, 73 + 100, 25 + 3 + 削除