-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from Haacked/settings
Settings UI and internals
- Loading branch information
Showing
14 changed files
with
422 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<appSettings> | ||
<!-- | ||
Option: AdornerCommitMessageVisibility | ||
Description: Sets the attached commit message visibility to Visible/Hidden/Hidden in Expanded. | ||
Options: Visible / Hidden / ExpandedHidden | ||
Default: "ExpandedHidden" (On) | ||
--> | ||
<add key="AdornerCommitMessageVisibility" value="ExpandedHidden"/> | ||
|
||
<!-- | ||
Option: DescriptionInExpander | ||
Description: Adds description in Expanded view. | ||
Default: "False" (Off) | ||
--> | ||
<add key="DescriptionInExpander" value="False"/> | ||
|
||
<!-- | ||
Option: SHALength | ||
Description: SHA Length used in commit titles | ||
Default: "8" (Short) | ||
--> | ||
<add key="SHALength" value="8"/> | ||
</appSettings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Configuration; | ||
using System.Linq; | ||
|
||
namespace SeeGit.Models | ||
{ | ||
public class Settings | ||
{ | ||
private readonly Configuration _config; | ||
public Settings() | ||
{ | ||
var fileMap = new ExeConfigurationFileMap(); | ||
fileMap.ExeConfigFilename = @"SeeGit.exe.config"; | ||
_config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); | ||
|
||
if (!_config.HasFile) | ||
throw new ConfigurationErrorsException("Config file not found."); | ||
} | ||
|
||
/// <summary> | ||
/// Changes configuration modifications to file | ||
/// </summary> | ||
public void Save() | ||
{ | ||
_config.Save(ConfigurationSaveMode.Full); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the value associated with the given key or | ||
/// returns the passed value if key does not exist. | ||
/// </summary> | ||
/// <typeparam name="T">Type of default value and return type</typeparam> | ||
/// <param name="key">Key</param> | ||
/// <param name="defaultVal">Return value if key does not exist</param> | ||
/// <param name="createVal">If the key does not exist, add the key-default value pair to configuration</param> | ||
/// <returns></returns> | ||
public T GetSetting<T>(string key, T defaultVal, bool createVal = false) | ||
{ | ||
var pair = _config.AppSettings.Settings[key]; | ||
if (pair == null) | ||
{ | ||
if (createVal) | ||
_config.AppSettings.Settings.Add( | ||
new KeyValueConfigurationElement(key, defaultVal.ToString())); | ||
|
||
return defaultVal; | ||
} | ||
|
||
return (T) Convert.ChangeType(pair.Value, typeof (T)); | ||
} | ||
|
||
/// <summary> | ||
/// Modifies the value of an existing key or creates a new one. | ||
/// </summary> | ||
/// <param name="key">Key</param> | ||
/// <param name="value">Value</param> | ||
public void SetSetting(string key, string value) | ||
{ | ||
if (_config.AppSettings.Settings.AllKeys.Contains(key)) | ||
_config.AppSettings.Settings[key].Value = value; | ||
else | ||
_config.AppSettings.Settings.Add(new KeyValueConfigurationElement(key, value)); | ||
} | ||
|
||
/// <summary> | ||
/// Removes a setting from the configuration. | ||
/// Does nothing if key does not exist. | ||
/// </summary> | ||
/// <param name="key">Key</param> | ||
public void RemoveSetting(string key) | ||
{ | ||
_config.AppSettings.Settings.Remove(key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.