public partial class AppendSettingDialog : OTBaseForm
{
private static AppendSettingDialog _instance = new AppendSettingDialog();
- private Twitter tw;
+ internal Twitter tw;
private bool _ValidationError = false;
- public List<UserAccount> UserAccounts;
private long? InitialUserId;
public TwitterConfiguration TwitterConfiguration = TwitterConfiguration.DefaultConfiguration();
public void LoadConfig(SettingCommon settingCommon, SettingLocal settingLocal)
{
+ this.BasedPanel.LoadConfig(settingCommon);
this.GetPeriodPanel.LoadConfig(settingCommon);
this.StartupPanel.LoadConfig(settingCommon);
this.TweetPrvPanel.LoadConfig(settingCommon);
this.CooperatePanel.LoadConfig(settingCommon);
this.ConnectionPanel.LoadConfig(settingCommon);
this.NotifyPanel.LoadConfig(settingCommon);
+
+ var activeUser = settingCommon.UserAccounts.FirstOrDefault(x => x.UserId == this.tw.UserId);
+ if (activeUser != null)
+ {
+ this.BasedPanel.AuthUserCombo.SelectedItem = activeUser;
+ this.InitialUserId = activeUser.UserId;
+ }
}
public void SaveConfig(SettingCommon settingCommon, SettingLocal settingLocal)
{
+ this.BasedPanel.SaveConfig(settingCommon);
this.GetPeriodPanel.SaveConfig(settingCommon);
this.StartupPanel.SaveConfig(settingCommon);
this.TweetPrvPanel.SaveConfig(settingCommon);
this.CooperatePanel.SaveConfig(settingCommon);
this.ConnectionPanel.SaveConfig(settingCommon);
this.NotifyPanel.SaveConfig(settingCommon);
+
+ var userAccountIdx = this.BasedPanel.AuthUserCombo.SelectedIndex;
+ if (userAccountIdx != -1)
+ {
+ var u = settingCommon.UserAccounts[userAccountIdx];
+ this.tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
+
+ if (u.UserId == 0)
+ {
+ this.tw.VerifyCredentials();
+ u.UserId = this.tw.UserId;
+ }
+ }
+ else
+ {
+ this.tw.ClearAuthInfo();
+ this.tw.Initialize("", "", "", 0);
+ }
}
private void TreeViewSetting_BeforeSelect(object sender, TreeViewCancelEventArgs e)
_ValidationError = false;
}
- this.UserAccounts.Clear();
- foreach (object u in this.BasedPanel.AuthUserCombo.Items)
- {
- this.UserAccounts.Add((UserAccount)u);
- }
- if (this.BasedPanel.AuthUserCombo.SelectedIndex > -1)
- {
- foreach (UserAccount u in this.UserAccounts)
- {
- if (u.Username.ToLower() == ((UserAccount)this.BasedPanel.AuthUserCombo.SelectedItem).Username.ToLower())
- {
- tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
- if (u.UserId == 0)
- {
- tw.VerifyCredentials();
- u.UserId = tw.UserId;
- }
- break;
- }
- }
- }
- else
- {
- tw.ClearAuthInfo();
- tw.Initialize("", "", "", 0);
- }
-
#if UA
//フォロー
if (this.FollowCheckBox.Checked)
{
if (MyCommon._endingFlag) return;
- if (this.DialogResult == DialogResult.Cancel)
- {
- //キャンセル時は画面表示時のアカウントに戻す
- //キャンセル時でも認証済みアカウント情報は保存する
- this.UserAccounts.Clear();
- foreach (object u in this.BasedPanel.AuthUserCombo.Items)
- {
- this.UserAccounts.Add((UserAccount)u);
- }
- //アクティブユーザーを起動時のアカウントに戻す(起動時アカウントなければ何もしない)
- bool userSet = false;
- if (this.InitialUserId != null)
- {
- foreach (UserAccount u in this.UserAccounts)
- {
- if (u.UserId == this.InitialUserId)
- {
- tw.Initialize(u.Token, u.TokenSecret, u.Username, u.UserId);
- userSet = true;
- break;
- }
- }
- }
- //認証済みアカウントが削除されていた場合、もしくは起動時アカウントがなかった場合は、
- //アクティブユーザーなしとして初期化
- if (!userSet)
- {
- tw.ClearAuthInfo();
- tw.Initialize("", "", "", 0);
- }
- }
-
if (tw != null && string.IsNullOrEmpty(tw.Username) && e.CloseReason == CloseReason.None)
{
if (MessageBox.Show(Properties.Resources.Setting_FormClosing1, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
private void Setting_Load(object sender, EventArgs e)
{
- tw = ((TweenMain)this.Owner).TwitterInstance;
- //this.AuthStateLabel.Enabled = true;
- //this.AuthUserLabel.Enabled = true;
- this.BasedPanel.AuthClearButton.Enabled = true;
-
- //if (tw.Username == "")
- //{
- // //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click4
- // //this.AuthUserLabel.Text = ""
- // //this.Save.Enabled = false
- //}
- //else
- //{
- // //this.AuthStateLabel.Text = Properties.Resources.AuthorizeButton_Click3;
- // //if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWrite)
- // //{
- // // this.AuthStateLabel.Text += "(xAuth)";
- // //}
- // //else if (TwitterApiInfo.AccessLevel == ApiAccessLevel.ReadWriteAndDirectMessage)
- // //{
- // // this.AuthStateLabel.Text += "(OAuth)";
- // //}
- // //this.AuthUserLabel.Text = tw.Username;
- //}
-
- this.BasedPanel.AuthUserCombo.Items.Clear();
- if (this.UserAccounts.Count > 0)
- {
- this.BasedPanel.AuthUserCombo.Items.AddRange(this.UserAccounts.ToArray());
- foreach (UserAccount u in this.UserAccounts)
- {
- if (u.UserId == tw.UserId)
- {
- this.BasedPanel.AuthUserCombo.SelectedItem = u;
- this.InitialUserId = u.UserId;
- break;
- }
- }
- }
-
this.TreeViewSetting.Nodes["BasedNode"].Tag = BasedPanel;
this.TreeViewSetting.Nodes["BasedNode"].Nodes["PeriodNode"].Tag = GetPeriodPanel;
this.TreeViewSetting.Nodes["BasedNode"].Nodes["StartUpNode"].Tag = StartupPanel;
if (this._cfgCommon.CountApiReply < 20 || this._cfgCommon.CountApiReply > 200)
this._cfgCommon.CountApiReply = 40;
- //設定画面への反映
- this.SettingDialog.LoadConfig(this._cfgCommon, this._cfgLocal);
HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
//認証関連
if (string.IsNullOrEmpty(_cfgCommon.Token)) _cfgCommon.UserName = "";
tw.Initialize(_cfgCommon.Token, _cfgCommon.TokenSecret, _cfgCommon.UserName, _cfgCommon.UserId);
- SettingDialog.UserAccounts = _cfgCommon.UserAccounts;
+ //設定画面への反映
+ this.SettingDialog.tw = this.tw;
+ this.SettingDialog.LoadConfig(this._cfgCommon, this._cfgLocal);
//新着取得時のリストスクロールをするか。trueならスクロールしない
ListLockMenuItem.Checked = _cfgCommon.ListLock;
if (saveRequired) SaveConfigsAll(false);
if (tw.UserId == 0)
- {
tw.VerifyCredentials();
- foreach (UserAccount ua in _cfgCommon.UserAccounts)
- {
- if (ua.Username.ToLower() == tw.Username.ToLower())
- {
- ua.UserId = tw.UserId;
- break;
- }
- }
- }
- foreach (UserAccount ua in SettingDialog.UserAccounts)
+
+ foreach (var ua in this._cfgCommon.UserAccounts)
{
if (ua.UserId == 0 && ua.Username.ToLower() == tw.Username.ToLower())
{
private void SettingStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result;
- string uid = tw.Username.ToLower();
+
+ // 設定画面表示前のユーザー情報
+ var oldUser = new { tw.AccessToken, tw.AccessTokenSecret, tw.Username, tw.UserId };
try
{
_hookGlobalHotkey.RegisterOriginalHotkey(this._cfgCommon.HotkeyKey, this._cfgCommon.HotkeyValue, modKey);
}
- if (uid != tw.Username) this.doGetFollowersMenu();
+ if (tw.Username != oldUser.Username)
+ this.doGetFollowersMenu();
if (this._cfgCommon.IsUseNotifyGrowl) gh.RegisterGrowl();
try
}
}
}
+ else
+ {
+ // キャンセル時は Twitter クラスの認証情報を画面表示前の状態に戻す
+ this.tw.Initialize(oldUser.AccessToken, oldUser.AccessTokenSecret, oldUser.Username, oldUser.UserId);
+ }
Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
_cfgCommon.Password = tw.Password;
_cfgCommon.Token = tw.AccessToken;
_cfgCommon.TokenSecret = tw.AccessTokenSecret;
- _cfgCommon.UserAccounts = SettingDialog.UserAccounts;
if (IdeographicSpaceToSpaceToolStripMenuItem != null &&
IdeographicSpaceToSpaceToolStripMenuItem.IsDisposed == false)