migrate Settings codebase from MBS.Framework.UserInterface to MBS.Framework
This commit is contained in:
parent
2c9d62ac37
commit
a594833143
30
MBS.Framework/CommandStylePreset.cs
Normal file
30
MBS.Framework/CommandStylePreset.cs
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// CommandStylePresets.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public enum CommandStylePreset
|
||||
{
|
||||
None = 0,
|
||||
Destructive,
|
||||
Suggested
|
||||
}
|
||||
}
|
||||
@ -96,6 +96,20 @@
|
||||
<Compile Include="Collections\Generic\ExtensionMethods.cs" />
|
||||
<Compile Include="ISupportsExtraData.cs" />
|
||||
<Compile Include="InstallationStatus.cs" />
|
||||
<Compile Include="Setting.cs" />
|
||||
<Compile Include="SettingsGroup.cs" />
|
||||
<Compile Include="SettingsProfile.cs" />
|
||||
<Compile Include="SettingsProvider.cs" />
|
||||
<Compile Include="SettingsValue.cs" />
|
||||
<Compile Include="Settings\CommandSetting.cs" />
|
||||
<Compile Include="Settings\RangeSetting.cs" />
|
||||
<Compile Include="Settings\GroupSetting.cs" />
|
||||
<Compile Include="Settings\BooleanSetting.cs" />
|
||||
<Compile Include="Settings\ChoiceSetting.cs" />
|
||||
<Compile Include="Settings\TextSetting.cs" />
|
||||
<Compile Include="Settings\CollectionSetting.cs" />
|
||||
<Compile Include="Settings\FileSetting.cs" />
|
||||
<Compile Include="CommandStylePreset.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Logic\" />
|
||||
@ -104,6 +118,7 @@
|
||||
<Folder Include="IO\" />
|
||||
<Folder Include="Scripting\" />
|
||||
<Folder Include="Scripting\Strings\" />
|
||||
<Folder Include="Settings\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
||||
147
MBS.Framework/Setting.cs
Normal file
147
MBS.Framework/Setting.cs
Normal file
@ -0,0 +1,147 @@
|
||||
//
|
||||
// Option.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public abstract class Setting
|
||||
{
|
||||
public Setting(string name, string title, object defaultValue = null)
|
||||
{
|
||||
Name = name;
|
||||
Title = title;
|
||||
DefaultValue = defaultValue;
|
||||
mvarValue = defaultValue;
|
||||
}
|
||||
|
||||
public Guid ID { get; set; } = Guid.Empty;
|
||||
|
||||
[Obsolete("This is no longer implemented. Please set a proper ID in order for your setting to be saved.")]
|
||||
public string Name { get; set; } = String.Empty;
|
||||
|
||||
public string Title { get; set; } = String.Empty;
|
||||
public string Description { get; set; } = String.Empty;
|
||||
|
||||
public class SettingCollection
|
||||
: System.Collections.ObjectModel.Collection<Setting>
|
||||
{
|
||||
|
||||
public Setting this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (Setting item in this)
|
||||
{
|
||||
if (item.Title.Replace("_", String.Empty).Replace(' ', '_').Equals(name))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<Guid, Setting> _itemsByID = new Dictionary<Guid, Setting>();
|
||||
protected override void ClearItems()
|
||||
{
|
||||
base.ClearItems();
|
||||
_itemsByID.Clear();
|
||||
}
|
||||
protected override void InsertItem(int index, Setting item)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
_itemsByID[item.ID] = item;
|
||||
}
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
_itemsByID.Remove(this[index].ID);
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
public bool Contains(Guid id)
|
||||
{
|
||||
return _itemsByID.ContainsKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
protected Setting()
|
||||
{
|
||||
}
|
||||
|
||||
public object DefaultValue { get; set; } = null;
|
||||
public SettingsValue.SettingsValueCollection ScopedValues { get; } = new SettingsValue.SettingsValueCollection();
|
||||
|
||||
private object mvarValue = null;
|
||||
|
||||
public virtual object GetValue(Guid? scopeId = null)
|
||||
{
|
||||
if (scopeId != null)
|
||||
{
|
||||
if (ScopedValues.Contains(scopeId.Value))
|
||||
{
|
||||
return ScopedValues[scopeId.Value].Value;
|
||||
}
|
||||
}
|
||||
return mvarValue;
|
||||
}
|
||||
public virtual void SetValue(object value, Guid? scopeId = null)
|
||||
{
|
||||
if (scopeId != null)
|
||||
{
|
||||
if (ScopedValues.Contains(scopeId.Value))
|
||||
{
|
||||
ScopedValues[scopeId.Value].Value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
ScopedValues.Add(scopeId.Value, value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mvarValue = value;
|
||||
}
|
||||
}
|
||||
public T GetValue<T>(T defaultValue = default(T), Guid? scopeId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
object val = GetValue(scopeId);
|
||||
if (val is T)
|
||||
return (T)val;
|
||||
if (val is string)
|
||||
{
|
||||
return (val as string).Parse<T>();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
public void SetValue<T>(T value)
|
||||
{
|
||||
mvarValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
40
MBS.Framework/Settings/BooleanSetting.cs
Normal file
40
MBS.Framework/Settings/BooleanSetting.cs
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// BooleanSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class BooleanSetting : Setting
|
||||
{
|
||||
public BooleanSetting(string name, string title, bool defaultValue = false) : base(name, title, defaultValue)
|
||||
{
|
||||
}
|
||||
|
||||
public override void SetValue(object value, Guid? scopeId = null)
|
||||
{
|
||||
bool val = false;
|
||||
if (value != null)
|
||||
{
|
||||
val = (value.ToString().ToLower().Equals("true"));
|
||||
}
|
||||
base.SetValue(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
74
MBS.Framework/Settings/ChoiceSetting.cs
Normal file
74
MBS.Framework/Settings/ChoiceSetting.cs
Normal file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// ChoiceSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class ChoiceSetting : Setting
|
||||
{
|
||||
public ChoiceSetting(string name, string title, ChoiceSettingValue defaultValue = null, ChoiceSettingValue[] values = null) : base(name, title, null)
|
||||
{
|
||||
if (values == null)
|
||||
{
|
||||
values = new ChoiceSettingValue[0];
|
||||
}
|
||||
if (defaultValue != null)
|
||||
{
|
||||
if (defaultValue.Value != null)
|
||||
{
|
||||
base.DefaultValue = defaultValue.Value.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
base.DefaultValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ChoiceSettingValue value in values)
|
||||
{
|
||||
ValidValues.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
public class ChoiceSettingValue
|
||||
{
|
||||
public class ChoiceSettingValueCollection
|
||||
: System.Collections.ObjectModel.Collection<ChoiceSettingValue>
|
||||
{
|
||||
}
|
||||
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Title { get; set; } = String.Empty;
|
||||
public object Value { get; set; } = null;
|
||||
|
||||
public ChoiceSettingValue(string name, string title, object value)
|
||||
{
|
||||
Name = name;
|
||||
Title = title;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ChoiceSettingValue.ChoiceSettingValueCollection ValidValues { get; } = new ChoiceSettingValue.ChoiceSettingValueCollection();
|
||||
public ChoiceSettingValue SelectedValue { get; set; } = null;
|
||||
|
||||
public bool RequireSelectionFromList { get; set; } = true;
|
||||
}
|
||||
}
|
||||
37
MBS.Framework/Settings/CollectionSetting.cs
Normal file
37
MBS.Framework/Settings/CollectionSetting.cs
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// CollectionSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class CollectionSetting : Setting
|
||||
{
|
||||
public Setting.SettingCollection Settings { get; } = new Setting.SettingCollection();
|
||||
public SettingsGroup.SettingsGroupCollection Items { get; } = new SettingsGroup.SettingsGroupCollection();
|
||||
|
||||
public CollectionSetting(string name, string title, SettingsGroup group) : base(name, title, null)
|
||||
{
|
||||
for (int i = 0; i < group.Settings.Count; i++)
|
||||
{
|
||||
Settings.Add(group.Settings[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
MBS.Framework/Settings/CommandSetting.cs
Normal file
34
MBS.Framework/Settings/CommandSetting.cs
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// CommandSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class CommandSetting : Setting
|
||||
{
|
||||
public string CommandID { get; set; } = null;
|
||||
public CommandStylePreset StylePreset { get; set; } = CommandStylePreset.None;
|
||||
|
||||
public CommandSetting(string name, string title, string commandID) : base(name, title)
|
||||
{
|
||||
CommandID = commandID;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
MBS.Framework/Settings/FileSetting.cs
Normal file
41
MBS.Framework/Settings/FileSetting.cs
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// FileSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public enum FileSettingMode
|
||||
{
|
||||
Open,
|
||||
Save,
|
||||
SelectFolder,
|
||||
CreateFolder
|
||||
}
|
||||
public class FileSetting : TextSetting
|
||||
{
|
||||
public bool RequireExistingFile { get; set; } = true;
|
||||
public FileSettingMode Mode { get; set; } = FileSettingMode.Open;
|
||||
|
||||
public FileSetting(string name, string title, string defaultValue = "", bool requireExistingFile = true) : base(name, title, defaultValue)
|
||||
{
|
||||
RequireExistingFile = requireExistingFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
40
MBS.Framework/Settings/GroupSetting.cs
Normal file
40
MBS.Framework/Settings/GroupSetting.cs
Normal file
@ -0,0 +1,40 @@
|
||||
//
|
||||
// GroupSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class GroupSetting : Setting
|
||||
{
|
||||
public Setting.SettingCollection Options { get; } = new Setting.SettingCollection();
|
||||
public Setting.SettingCollection HeaderSettings { get; } = new Setting.SettingCollection();
|
||||
|
||||
public GroupSetting(string name, string title, Setting[] options = null) : base(name, title)
|
||||
{
|
||||
if (options != null)
|
||||
{
|
||||
foreach (Setting option in options)
|
||||
{
|
||||
Options.Add(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
MBS.Framework/Settings/RangeSetting.cs
Normal file
35
MBS.Framework/Settings/RangeSetting.cs
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// RangeSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class RangeSetting : Setting
|
||||
{
|
||||
public decimal? MinimumValue { get; set; } = null;
|
||||
public decimal? MaximumValue { get; set; } = null;
|
||||
|
||||
public RangeSetting(string name, string title, decimal defaultValue = 0.0M, decimal? minimumValue = null, decimal? maximumValue = null) : base(name, title, defaultValue)
|
||||
{
|
||||
MinimumValue = minimumValue;
|
||||
MaximumValue = maximumValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
MBS.Framework/Settings/TextSetting.cs
Normal file
30
MBS.Framework/Settings/TextSetting.cs
Normal file
@ -0,0 +1,30 @@
|
||||
//
|
||||
// TextSetting.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2021 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework.Settings
|
||||
{
|
||||
public class TextSetting : Setting
|
||||
{
|
||||
public TextSetting(string name, string title, string defaultValue = "") : base(name, title, defaultValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
146
MBS.Framework/SettingsGroup.cs
Normal file
146
MBS.Framework/SettingsGroup.cs
Normal file
@ -0,0 +1,146 @@
|
||||
//
|
||||
// OptionPanel.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public class SettingsGroup : IComparable<SettingsGroup>
|
||||
{
|
||||
public class SettingsGroupCollection
|
||||
: System.Collections.ObjectModel.Collection<SettingsGroup>
|
||||
{
|
||||
public SettingsGroup Add(string path, Setting[] options)
|
||||
{
|
||||
string[] paths = new string[0];
|
||||
if (!String.IsNullOrEmpty (path)) {
|
||||
paths = path.Split (new char[] { ':' });
|
||||
}
|
||||
return Add (paths, options);
|
||||
}
|
||||
public SettingsGroup Add(string[] path, Setting[] options)
|
||||
{
|
||||
SettingsGroup grp = new SettingsGroup();
|
||||
grp.Path = path;
|
||||
if (options != null) {
|
||||
foreach (Setting option in options) {
|
||||
grp.Settings.Add (option);
|
||||
}
|
||||
}
|
||||
Add (grp);
|
||||
return grp;
|
||||
}
|
||||
|
||||
private Dictionary<Guid, SettingsGroup> _itemsByID = new Dictionary<Guid, SettingsGroup>();
|
||||
protected override void ClearItems()
|
||||
{
|
||||
base.ClearItems();
|
||||
_itemsByID.Clear();
|
||||
}
|
||||
protected override void InsertItem(int index, SettingsGroup item)
|
||||
{
|
||||
base.InsertItem(index, item);
|
||||
_itemsByID[item.ID] = item;
|
||||
}
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
_itemsByID.Remove(this[index].ID);
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
public bool Contains(Guid id)
|
||||
{
|
||||
return _itemsByID.ContainsKey(id);
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsGroup()
|
||||
{
|
||||
}
|
||||
public SettingsGroup(string path, Setting[] options = null)
|
||||
{
|
||||
string[] paths = new string[0];
|
||||
if (!String.IsNullOrEmpty (path)) {
|
||||
paths = path.Split (new char[] { ':' });
|
||||
}
|
||||
Path = paths;
|
||||
if (options != null)
|
||||
{
|
||||
foreach (Setting option in options)
|
||||
{
|
||||
Settings.Add(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
public SettingsGroup(string[] paths, Setting[] options = null)
|
||||
{
|
||||
Path = paths;
|
||||
if (options != null)
|
||||
{
|
||||
foreach (Setting option in options)
|
||||
{
|
||||
Settings.Add(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo(SettingsGroup other)
|
||||
{
|
||||
int xprior = this.Priority;
|
||||
int yprior = other.Priority;
|
||||
if (xprior == -1 && yprior == -1)
|
||||
{
|
||||
string xpath = String.Join(":", this.GetPath());
|
||||
string ypath = String.Join(":", other.GetPath());
|
||||
return xpath.CompareTo(ypath);
|
||||
}
|
||||
else
|
||||
{
|
||||
return yprior.CompareTo(xprior);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ID { get; set; } = Guid.Empty;
|
||||
|
||||
public string[] GetPath()
|
||||
{
|
||||
if (Path == null) return new string[0];
|
||||
return Path;
|
||||
}
|
||||
|
||||
public string[] Path { get; set; } = null;
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Path.Length > 0) return Path[Path.Length - 1];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Setting.SettingCollection Settings { get; } = new Setting.SettingCollection();
|
||||
public int Priority { get; set; } = -1;
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return String.Join (":", Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
MBS.Framework/SettingsProfile.cs
Normal file
38
MBS.Framework/SettingsProfile.cs
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// SettingsProfile.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2020 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public class SettingsProfile
|
||||
{
|
||||
public class SettingsProfileCollection
|
||||
: System.Collections.ObjectModel.Collection<SettingsProfile>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static readonly Guid AllUsersGUID = new Guid("{6c1e84c6-7cb8-4798-b000-349dba816114}");
|
||||
public static readonly Guid ThisUserGUID = new Guid("{a550229d-05e1-4a93-96a6-98ae1c69b847}");
|
||||
|
||||
public Guid ID { get; set; } = Guid.Empty;
|
||||
public string Title { get; set; } = null;
|
||||
}
|
||||
}
|
||||
81
MBS.Framework/SettingsProvider.cs
Normal file
81
MBS.Framework/SettingsProvider.cs
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// OptionProvider.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2019 Mike Becker
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public abstract class SettingsProvider
|
||||
{
|
||||
public class SettingsProviderCollection
|
||||
: System.Collections.ObjectModel.Collection<SettingsProvider>
|
||||
{
|
||||
private System.Collections.Generic.Dictionary<Guid, SettingsProvider> _itemsByID = new System.Collections.Generic.Dictionary<Guid, SettingsProvider>();
|
||||
public bool Contains(Guid id)
|
||||
{
|
||||
return _itemsByID.ContainsKey(id);
|
||||
}
|
||||
protected override void ClearItems()
|
||||
{
|
||||
base.ClearItems();
|
||||
_itemsByID.Clear();
|
||||
}
|
||||
protected override void InsertItem(int index, SettingsProvider item)
|
||||
{
|
||||
_itemsByID[item.ID] = item;
|
||||
base.InsertItem(index, item);
|
||||
}
|
||||
protected override void RemoveItem(int index)
|
||||
{
|
||||
_itemsByID.Remove(this[index].ID);
|
||||
base.RemoveItem(index);
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ID { get; set; } = Guid.Empty;
|
||||
|
||||
public SettingsGroup.SettingsGroupCollection SettingsGroups { get; } = new SettingsGroup.SettingsGroupCollection();
|
||||
|
||||
protected virtual void InitializeInternal()
|
||||
{
|
||||
}
|
||||
public void Initialize()
|
||||
{
|
||||
InitializeInternal();
|
||||
}
|
||||
|
||||
protected virtual void LoadSettingsInternal()
|
||||
{
|
||||
}
|
||||
public void LoadSettings()
|
||||
{
|
||||
LoadSettingsInternal ();
|
||||
}
|
||||
|
||||
protected virtual void SaveSettingsInternal()
|
||||
{
|
||||
}
|
||||
public void SaveSettings()
|
||||
{
|
||||
SaveSettingsInternal ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
61
MBS.Framework/SettingsValue.cs
Normal file
61
MBS.Framework/SettingsValue.cs
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// SettingValue.cs
|
||||
//
|
||||
// Author:
|
||||
// Michael Becker <alcexhim@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2020 Mike Becker's Software
|
||||
//
|
||||
// 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/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MBS.Framework
|
||||
{
|
||||
public class SettingsValue
|
||||
{
|
||||
public class SettingsValueCollection : System.Collections.ObjectModel.Collection<SettingsValue>
|
||||
{
|
||||
Dictionary<Guid, SettingsValue> _itemsByGuid = new Dictionary<Guid, SettingsValue>();
|
||||
|
||||
public int Count { get { return _itemsByGuid.Count; } }
|
||||
|
||||
public bool Contains(Guid scopeId)
|
||||
{
|
||||
return _itemsByGuid.ContainsKey(scopeId);
|
||||
}
|
||||
|
||||
public void Add(Guid scopeId, object value)
|
||||
{
|
||||
SettingsValue item = new SettingsValue();
|
||||
item.ScopeId = scopeId;
|
||||
item.Value = value;
|
||||
Add(item);
|
||||
}
|
||||
public SettingsValue this[Guid scopeId]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_itemsByGuid.ContainsKey(scopeId))
|
||||
return _itemsByGuid[scopeId];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Guid ScopeId { get; set; }
|
||||
public object Value { get; set; } = null;
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user