Skip to content

Commit

Permalink
Merge pull request #46 from Haacked/settings
Browse files Browse the repository at this point in the history
Settings UI and internals
  • Loading branch information
haacked committed May 16, 2013
2 parents 1dafe0b + b43d8d7 commit 89881ed
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 15 deletions.
26 changes: 26 additions & 0 deletions SeeGitApp/App.config
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>
13 changes: 11 additions & 2 deletions SeeGitApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
<KeyBinding Key="F5"
Command="Refresh" />
</Window.InputBindings>

<Grid d:DataContext="{d:DesignInstance {x:Type local:DesignTimeMainWindowViewModel}, IsDesignTimeCreatable=True}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<StackPanel Orientation="Vertical" Grid.Row="0">
<StackPanel Orientation="Horizontal" Background="Black" HorizontalAlignment="Stretch" Margin="0">
<StackPanel Orientation="Horizontal" Background="Black" HorizontalAlignment="Stretch" Margin="0" FlowDirection="LeftToRight">
<Label VerticalAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="10"
FontFamily="Verdana" FontWeight="Bold" Margin="0,0,0,0" Content="Repository Path:" />
<Label VerticalAlignment="Center" VerticalContentAlignment="Center" Foreground="White" FontSize="10"
Expand All @@ -61,6 +61,15 @@
Command="Refresh">
Refresh
</Button>
<ToggleButton Name="settingsToggle" Background="Gray" Foreground="White" HorizontalAlignment="Right" Margin="10 2 0 2" Padding="3" Focusable="False"
Click="OnToggleSettings">
Settings
</ToggleButton>
</StackPanel>
<StackPanel Visibility="{Binding IsChecked, ElementName=settingsToggle, Converter={StaticResource BooleanToVisibilityConverter}}">
<view:SettingsView>

</view:SettingsView>
</StackPanel>
</StackPanel>

Expand Down
31 changes: 30 additions & 1 deletion SeeGitApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System;
using SeeGit.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Windows.Controls;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;

Expand All @@ -8,6 +13,7 @@ namespace SeeGit
public partial class MainWindow : Window
{
private readonly MainWindowViewModel _viewModel;
private static readonly Settings _configuration = new Settings();

public MainWindow()
{
Expand All @@ -17,6 +23,14 @@ public MainWindow()
_viewModel.MonitorRepository(Directory.GetCurrentDirectory());
}

/// <summary>
/// A reference to the configuration.
/// </summary>
public static Settings Configuration
{
get { return _configuration; }
}

private void OnChooseRepository(object sender, RoutedEventArgs args)
{
_viewModel.MonitorRepository(WindowsExtensions.BrowseForFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
Expand All @@ -26,5 +40,20 @@ private void OnRefresh(object sender, ExecutedRoutedEventArgs e)
{
_viewModel.MonitorRepository(_viewModel.RepositoryPath);
}

private void OnToggleSettings(object sender, RoutedEventArgs args)
{
if (!_viewModel.ToggleSettings())
{
foreach (CommitVertex vertex in _viewModel.Graph.Vertices)
{
vertex.AdornerMessageVisibilityType = _configuration.GetSetting("AdornerCommitMessageVisibility", "ExpandedHidden");
vertex.DescriptionShown = _configuration.GetSetting<bool>("DescriptionInExpander", false);
vertex.ShaLength = _configuration.GetSetting<int>("SHALength", 8);
}
_configuration.Save();
_viewModel.Refresh();
}
}
}
}
67 changes: 58 additions & 9 deletions SeeGitApp/Models/CommitVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,61 @@ public CommitVertex(string sha, string message)
Message = message;
Branches = new BranchCollection();
Branches.CollectionChanged += (o, e) => RaisePropertyChanged(() => HasBranches);
ShaLength = MainWindow.Configuration.GetSetting<int>("SHALength", 8);
DescriptionShown = MainWindow.Configuration.GetSetting<bool>("DescriptionInExpander", false);
AdornerMessageVisibilityType = MainWindow.Configuration.GetSetting<string>("AdornerCommitMessageVisibility", "ExpandedHidden");
Expanded = false;
}

// Settings
int _shaLength;
public int ShaLength
{
get
{
return _shaLength;
}
set
{
_shaLength = value;
RaisePropertyChanged(() => ShortSha);
}
}

bool _descriptionShown;
public bool DescriptionShown
{
get
{
return _descriptionShown;
}
set
{
_descriptionShown = value;
RaisePropertyChanged(() => DescriptionShown);
}
}

public bool AdornerMessageVisibility
{
get;
set;
}

private string _adornerMessageVisibilityType;
public string AdornerMessageVisibilityType
{
set
{
if (value.Equals("Visible"))
AdornerMessageVisibility = true;
else if (value.Equals("Hidden"))
AdornerMessageVisibility = false;
_adornerMessageVisibilityType = value;
RaisePropertyChanged(() => AdornerMessageVisibility);
}
}

public string Sha
{
get;
Expand All @@ -26,7 +78,7 @@ public string ShortSha
{
get
{
return Sha.AtMost(8);
return Sha.AtMost(ShaLength);
}
}

Expand Down Expand Up @@ -71,18 +123,15 @@ public bool OnCurrentBranch
}
}

private bool _expanded;

public bool Expanded
{
get
{
return _expanded;
}
set
{
_expanded = value;
RaisePropertyChanged(() => Expanded);
if (_adornerMessageVisibilityType.Equals("ExpandedHidden"))
{
AdornerMessageVisibility = !value;
RaisePropertyChanged(() => AdornerMessageVisibility);
}
}
}

Expand Down
75 changes: 75 additions & 0 deletions SeeGitApp/Models/Settings.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions SeeGitApp/SeeGitApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<HintPath>..\Lib\QuickGraph.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Reactive">
<HintPath>..\packages\Rx_Experimental-Main.1.1.11111\lib\Net4\System.Reactive.dll</HintPath>
Expand Down Expand Up @@ -114,11 +115,16 @@
<Compile Include="Models\ReachableHighlightAlgorithmFactory.cs" />
<Compile Include="Models\RepositoryGraphBuilder.cs" />
<Compile Include="Models\RepositoryGraphLayout.cs" />
<Compile Include="Models\Settings.cs" />
<Compile Include="Settings.cs" />
<Compile Include="ViewModels\DesignTimeMainWindowViewModel.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="Views\CommitVertexView.xaml.cs">
<DependentUpon>CommitVertexView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -138,6 +144,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
Expand All @@ -158,6 +168,7 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
7 changes: 7 additions & 0 deletions SeeGitApp/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class MainWindowViewModel : NotifyPropertyChanged
private string _layoutAlgorithmType = "Tree";
private readonly Dispatcher _uiDispatcher;
private readonly Func<string, IRepositoryGraphBuilder> _graphBuilderThunk;
private bool _settingsVisible;

public MainWindowViewModel(Dispatcher uiDispatcher, Func<string, IRepositoryGraphBuilder> graphBuilderThunk)
{
Expand Down Expand Up @@ -92,5 +93,11 @@ public void Refresh()
{
Graph = _graphBuilder.Graph();
}

public bool ToggleSettings()
{
_settingsVisible = !_settingsVisible;
return _settingsVisible;
}
}
}
4 changes: 2 additions & 2 deletions SeeGitApp/Views/CommitVertexView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<local:CommitAdornerBehavior.AdornerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Message}" Foreground="White" TextWrapping="Wrap" MaxWidth="250" Visibility="{Binding Path=Expanded, Converter={StaticResource InverseBooleanToVisibilityConverter}}" />
<TextBlock Text="{Binding Message}" Foreground="White" TextWrapping="Wrap" MaxWidth="250" Visibility="{Binding Path=AdornerMessageVisibility, Converter={StaticResource BooleanToVisibilityConverter}}" />
</StackPanel>
</DataTemplate>
</local:CommitAdornerBehavior.AdornerTemplate>
Expand Down Expand Up @@ -100,7 +100,7 @@
</Expander.Style>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Message}" Foreground="White" TextWrapping="Wrap" MaxWidth="100" />
<!-- <TextBlock Text="{Binding Description}" Foreground="White" TextWrapping="Wrap" /> -->
<TextBlock Text="{Binding Description}" Foreground="White" TextWrapping="Wrap" Visibility="{Binding DescriptionShown, Converter={StaticResource BooleanToVisibilityConverter}}" />
</StackPanel>
</Expander>
</Border>
Expand Down
Loading

0 comments on commit 89881ed

Please sign in to comment.