}
}
}
+
+namespace OpenTween.Setting
+{
+ public class SettingManagerTest
+ {
+ public static SettingCommon Common
+ {
+ get { return SettingManager.Common; }
+ set { SettingManager.Common = value; }
+ }
+
+ public static SettingLocal Local
+ {
+ get { return SettingManager.Local; }
+ set { SettingManager.Local = value; }
+ }
+
+ public static SettingTabs Tabs
+ {
+ get { return SettingManager.Tabs; }
+ set { SettingManager.Tabs = value; }
+ }
+
+ public static SettingAtIdList AtIdList
+ {
+ get { return SettingManager.AtIdList; }
+ set { SettingManager.AtIdList = value; }
+ }
+ }
+}
using System.Text.RegularExpressions;
using OpenTween.Api.DataModel;
using OpenTween.Models;
+using OpenTween.Setting;
using Xunit;
using Xunit.Extensions;
[Fact]
public void GetApiResultCount_DefaultTest()
{
- var oldInstance = SettingCommon.Instance;
- SettingCommon.Instance = new SettingCommon();
+ var oldInstance = SettingManagerTest.Common;
+ SettingManagerTest.Common = new SettingCommon();
var timeline = SettingCommon.Instance.CountApi;
var reply = SettingCommon.Instance.CountApiReply;
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.PublicSearch, false, false));
Assert.Equal(timeline, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, false));
- SettingCommon.Instance = oldInstance;
+ SettingManagerTest.Common = oldInstance;
}
[Fact]
public void GetApiResultCount_AdditionalCountTest()
{
- var oldInstance = SettingCommon.Instance;
- SettingCommon.Instance = new SettingCommon();
+ var oldInstance = SettingManagerTest.Common;
+ SettingManagerTest.Common = new SettingCommon();
var timeline = SettingCommon.Instance.CountApi;
var reply = SettingCommon.Instance.CountApiReply;
Assert.Equal(more, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, true, false));
Assert.Equal(startup, Twitter.GetApiResultCount(MyCommon.WORKERTYPE.UserTimeline, false, true));
- SettingCommon.Instance = oldInstance;
+ SettingManagerTest.Common = oldInstance;
}
[Fact]
<Compile Include="SendErrorReportForm.Designer.cs">
<DependentUpon>SendErrorReportForm.cs</DependentUpon>
</Compile>
+ <Compile Include="Setting\SettingManager.cs" />
<Compile Include="ShortcutCommand.cs" />
<Compile Include="Thumbnail\Services\PbsTwimgCom.cs" />
<Compile Include="TweetDetailsView.cs">
using System.Collections.Generic;
using System.Windows.Forms;
using OpenTween.Thumbnail;
+using OpenTween.Setting;
namespace OpenTween
{
public class SettingCommon : SettingBase<SettingCommon>
{
- public static SettingCommon Instance { get; internal set; }
-
- static SettingCommon()
- {
- Instance = new SettingCommon();
- }
+ public static SettingCommon Instance => SettingManager.Common;
#region "Settingクラス基本"
public static SettingCommon Load()
--- /dev/null
+// OpenTween - Client of Twitter
+// Copyright (c) 2017 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenTween.Setting
+{
+ public static class SettingManager
+ {
+ public static SettingCommon Common { get; internal set; } = new SettingCommon();
+
+ public static SettingLocal Local { get; internal set; } = new SettingLocal();
+
+ public static SettingTabs Tabs { get; internal set; } = new SettingTabs();
+
+ public static SettingAtIdList AtIdList { get; internal set; } = new SettingAtIdList();
+
+ public static void LoadAll()
+ {
+ LoadCommon();
+ LoadLocal();
+ LoadTabs();
+ LoadAtIdList();
+ }
+
+ public static void LoadCommon()
+ {
+ var settings = SettingCommon.Load();
+
+ if (settings.UserAccounts == null || settings.UserAccounts.Count == 0)
+ {
+ settings.UserAccounts = new List<UserAccount>();
+ if (!string.IsNullOrEmpty(settings.UserName))
+ {
+ UserAccount account = new UserAccount();
+ account.Username = settings.UserName;
+ account.UserId = settings.UserId;
+ account.Token = settings.Token;
+ account.TokenSecret = settings.TokenSecret;
+
+ settings.UserAccounts.Add(account);
+ }
+ }
+
+ SettingManager.Common = settings;
+ }
+
+ public static void LoadLocal()
+ => SettingManager.Local = SettingLocal.Load();
+
+ public static void LoadTabs()
+ => SettingManager.Tabs = SettingTabs.Load();
+
+ public static void LoadAtIdList()
+ => SettingManager.AtIdList = SettingAtIdList.Load();
+
+ public static void SaveCommon()
+ => SettingManager.Common.Save();
+
+ public static void SaveLocal()
+ => SettingManager.Local.Save();
+
+ public static void SaveTabs()
+ => SettingManager.Tabs.Save();
+
+ public static void SaveAtIdList()
+ => SettingManager.AtIdList.Save();
+ }
+}
using OpenTween.Connection;
using OpenTween.Models;
using OpenTween.OpenTweenCustomControl;
+using OpenTween.Setting;
using OpenTween.Thumbnail;
namespace OpenTween
ImageSelector.Initialize(tw, this.tw.Configuration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
//ハッシュタグ/@id関連
- AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
+ AtIdSupl = new AtIdSupplement(SettingManager.AtIdList.AtIdList, "@");
HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
HashMgr = new HashtagManage(HashSupl,
_cfgCommon.HashTags.ToArray(),
private void LoadConfig()
{
- _cfgCommon = SettingCommon.Load();
- SettingCommon.Instance = this._cfgCommon;
- if (_cfgCommon.UserAccounts == null || _cfgCommon.UserAccounts.Count == 0)
- {
- _cfgCommon.UserAccounts = new List<UserAccount>();
- if (!string.IsNullOrEmpty(_cfgCommon.UserName))
- {
- UserAccount account = new UserAccount();
- account.Username = _cfgCommon.UserName;
- account.UserId = _cfgCommon.UserId;
- account.Token = _cfgCommon.Token;
- account.TokenSecret = _cfgCommon.TokenSecret;
-
- _cfgCommon.UserAccounts.Add(account);
- }
- }
+ SettingManager.LoadAll();
- _cfgLocal = SettingLocal.Load();
+ this._cfgCommon = SettingManager.Common;
+ this._cfgLocal = SettingManager.Local;
// v1.2.4 以前の設定には ScaleDimension の項目がないため、現在の DPI と同じとして扱う
if (_cfgLocal.ScaleDimension.IsEmpty)
_cfgLocal.ScaleDimension = this.CurrentAutoScaleDimensions;
- var tabsSetting = SettingTabs.Load().Tabs;
- foreach (var tabSetting in tabsSetting)
+ var tabSettings = SettingManager.Tabs;
+ foreach (var tabSetting in tabSettings.Tabs)
{
TabModel tab;
switch (tabSetting.TabType)
if (_ignoreConfigSave || !this._cfgCommon.UseAtIdSupplement && AtIdSupl == null) return;
ModifySettingAtId = false;
- SettingAtIdList cfgAtId = new SettingAtIdList(AtIdSupl.GetItemList());
- cfgAtId.Save();
+ SettingManager.AtIdList.AtIdList = this.AtIdSupl.GetItemList();
+ SettingManager.SaveAtIdList();
}
private void SaveConfigsCommon()
_cfgCommon.UseImageService = ImageSelector.ServiceIndex;
_cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
- _cfgCommon.Save();
+ SettingManager.SaveCommon();
}
}
_cfgLocal.FontInputFont = _fntInputFont;
if (_ignoreConfigSave) return;
- _cfgLocal.Save();
+ SettingManager.SaveLocal();
}
}
private void SaveConfigsTabs()
{
- var tabsSetting = new SettingTabs();
+ var tabSettingList = new List<SettingTabs.SettingTabItem>();
var tabs = this.ListTab.TabPages.Cast<TabPage>()
.Select(x => this._statuses.Tabs[x.Text])
if (listTab != null)
tabSetting.ListInfo = listTab.ListInfo;
- tabsSetting.Tabs.Add(tabSetting);
+ tabSettingList.Add(tabSetting);
}
- tabsSetting.Save();
+ SettingManager.Tabs.Tabs = tabSettingList;
+ SettingManager.SaveTabs();
}
private async void OpenURLFileMenuItem_Click(object sender, EventArgs e)