Permalink
Browse files

Merge pull request #79 from Haacked/code-cleanup

Code cleanup
  • Loading branch information...
Haacked committed Oct 8, 2015
2 parents 64a5be7 + d637fb7 commit f75707c7186f9fbbb6109e6d16e84c9e41b3ab71
@@ -66,23 +66,25 @@ public CommitAdornerBehavior()
if (null == adornerLayer)
throw new NullReferenceException(
string.Format("No adorner found in attached object: {0}", AssociatedObject));
$"No adorner found in attached object: {AssociatedObject}");
// Create adorner
_adornerControl = new ContentControl();
// Add to adorner
adornerLayer.Add(
_caTemplatedAdorner =
new CommitTemplatedAdorner(AssociatedObject as UIElement, _adornerControl));
new CommitTemplatedAdorner((UIElement)AssociatedObject, _adornerControl));
// Set related bindings
_adornerControl.Content = AdornerTemplate.LoadContent();
_adornerControl.Visibility = AdornerVisible;
// Bind internal dependency to external
var bindingMargin = new Binding("AdornerMargin");
bindingMargin.Source = this;
var bindingMargin = new Binding("AdornerMargin")
{
Source = this
};
BindingOperations.SetBinding(_caTemplatedAdorner, FrameworkElement.MarginProperty,
bindingMargin);
}
@@ -165,8 +167,8 @@ private void HideAdorner(object parameter)
{
if (_adornerControl.IsMouseOver)
{
_adornerControl.MouseLeave -= (s, e) => _adornerControl.Visibility = AdornerVisible;
_adornerControl.MouseLeave += (s, e) => _adornerControl.Visibility = AdornerVisible;
_adornerControl.MouseLeave -= SetVisibility;
_adornerControl.MouseLeave += SetVisibility;
}
else
{
@@ -175,6 +177,11 @@ private void HideAdorner(object parameter)
}
}
private void SetVisibility(object source, MouseEventArgs e)
{
_adornerControl.Visibility = AdornerVisible;
}
/// <summary>
/// ShowAdornerCommand
/// </summary>
@@ -195,11 +202,11 @@ private void HideAdorner(object parameter)
"AdornerTemplate",
typeof (DataTemplate),
typeof (CommitAdornerBehavior), new PropertyMetadata((d, o) =>
{
if (null != ((CommitAdornerBehavior)d)._adornerControl)
((CommitAdornerBehavior)d)._adornerControl.
ContentTemplate = (DataTemplate)o.NewValue;
}));
{
if (null != ((CommitAdornerBehavior)d)._adornerControl)
((CommitAdornerBehavior)d)._adornerControl.
ContentTemplate = (DataTemplate)o.NewValue;
}));
/// <summary>
/// Data template for the adroner. Used inside a ContentControl.
@@ -265,16 +272,13 @@ public Visibility AdornerVisible
{
var adorner = d as CommitAdornerBehavior;
if (d == null) return;
if (adorner != null) adorner.SetDelayedState((bool)o.NewValue);
adorner?.SetDelayedState((bool)o.NewValue);
}));
/// <summary>
/// Data template for the adroner. Used inside a ContentControl.
/// </summary>
public bool DelayConstruction
{
get { return (bool)GetValue(DelayConstructionProperty); }
}
public bool DelayConstruction => (bool)GetValue(DelayConstructionProperty);
/// <summary>
/// Data template for the adroner. Used inside a ContentControl.
@@ -302,7 +306,7 @@ public object DataContext
private static void OnDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var adorner = d as CommitAdornerBehavior;
if (adorner == null || adorner._adornerControl == null) return;
if (adorner?._adornerControl == null) return;
adorner._adornerControl.DataContext = adorner.DataContext;
}
@@ -10,12 +10,7 @@ public static class ModelExtensions
public static string AtMost(this string s, int characterCount)
{
if (s == null) return null;
if (s.Length <= characterCount)
{
return s;
}
return s.Substring(0, characterCount);
return s == null ? null : (s.Length <= characterCount ? s : s.Substring(0, characterCount));
}
public static string GetGitRepositoryPath(string path)
@@ -40,10 +35,7 @@ public static string GetGitRepositoryPath(string path)
{
return pathToTest;
}
else
{
checkIn = checkIn.Parent;
}
checkIn = checkIn.Parent;
}
// This is not good, it relies on the rest of the code being ok
@@ -55,16 +47,16 @@ public static IObservable<FileSystemEventArgs> CreateGitRepositoryCreationObserv
{
string expectedGitDirectory = Path.Combine(path, GitDirectoryName);
return new FileSystemWatcher(path)
{
IncludeSubdirectories = false,
EnableRaisingEvents = true,
NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName
}.ObserveFileSystemCreateEvents()
.Where(
e =>
e.ChangeType == WatcherChangeTypes.Created &&
e.FullPath.Equals(expectedGitDirectory, StringComparison.OrdinalIgnoreCase))
.Take(1);
{
IncludeSubdirectories = false,
EnableRaisingEvents = true,
NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.DirectoryName
}.ObserveFileSystemCreateEvents()
.Where(
e =>
e.ChangeType == WatcherChangeTypes.Created &&
e.FullPath.Equals(expectedGitDirectory, StringComparison.OrdinalIgnoreCase))
.Take(1);
}
public static IObservable<FileSystemEventArgs> CreateGitRepositoryChangesObservable(string path)
@@ -1,5 +1,4 @@
using System.IO;
using Microsoft.WindowsAPICodePack.Dialogs;
using Microsoft.WindowsAPICodePack.Dialogs;
namespace SeeGit
{
@@ -17,7 +16,7 @@ public static string BrowseForFolder(string startingPath)
var cfd = new CommonOpenFileDialog
{
InitialDirectory = initialDirectory,
IsFolderPicker = true,
IsFolderPicker = true
};
if (cfd.ShowDialog() == CommonFileDialogResult.Ok)
@@ -29,7 +28,7 @@ public static string BrowseForFolder(string startingPath)
{
var fd = new System.Windows.Forms.FolderBrowserDialog
{
SelectedPath = initialDirectory,
SelectedPath = initialDirectory
};
if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
@@ -4,8 +4,9 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls" xmlns:local="clr-namespace:SeeGit"
xmlns:zoom="clr-namespace:WPFExtensions.Controls;assembly=WPFExtensions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:view="clr-namespace:SeeGit.Views"
xmlns:extbehaviour="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions" x:Class="SeeGit.MainWindow"
xmlns:view="clr-namespace:SeeGit.Views"
xmlns:extbehaviour="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions"
x:Class="SeeGit.MainWindow"
Title="SeeGit" Height="465" Width="708" mc:Ignorable="d">
<Window.Resources>
@@ -9,9 +9,7 @@ public class BranchReference : GitObject<BranchReference>
public override bool Equals(BranchReference other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(other.Name, Name);
return !ReferenceEquals(null, other) && (ReferenceEquals(this, other) || Equals(other.Name, Name));
}
public override int GetHashCode()
@@ -36,7 +36,7 @@ public string Id
public override bool Equals(object obj)
{
return this.Equals(obj as CommitEdge);
return Equals(obj as CommitEdge);
}
public bool Equals(CommitEdge other)
@@ -60,9 +60,7 @@ public override int GetHashCode()
public static bool operator ==(CommitEdge edge, CommitEdge other)
{
if(ReferenceEquals(edge, null)) return ReferenceEquals(other, null);
return edge.Equals(other);
return ReferenceEquals(edge, null) ? ReferenceEquals(other, null) : edge.Equals(other);
}
public static bool operator !=(CommitEdge edge, CommitEdge other)
@@ -13,9 +13,9 @@ 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");
ShaLength = MainWindow.Configuration.GetSetting("SHALength", 8);
DescriptionShown = MainWindow.Configuration.GetSetting("DescriptionInExpander", false);
AdornerMessageVisibilityType = MainWindow.Configuration.GetSetting("AdornerCommitMessageVisibility", "ExpandedHidden");
Expanded = false;
}
@@ -121,21 +121,17 @@ public bool Expanded
public override bool Equals(object obj)
{
return this.Equals(obj as CommitVertex);
return Equals(obj as CommitVertex);
}
public override bool Equals(CommitVertex other)
{
if(ReferenceEquals(null, other))
return false;
if(ReferenceEquals(this, other))
return true;
return Equals(other.Sha, Sha);
return !ReferenceEquals(null, other) && (ReferenceEquals(this, other) || Equals(other.Sha, Sha));
}
public override string ToString()
{
return string.Format("{0}: {1}", ShortSha, Message);
return $"{ShortSha}: {Message}";
}
public override int GetHashCode()
@@ -151,9 +147,7 @@ public override int GetHashCode()
public static bool operator ==(CommitVertex commit, CommitVertex other)
{
if(ReferenceEquals(commit, null)) return ReferenceEquals(other, null);
return commit.Equals(other);
return ReferenceEquals(commit, null) ? ReferenceEquals(other, null) : commit.Equals(other);
}
public static bool operator !=(CommitVertex commit, CommitVertex other)
@@ -18,13 +18,13 @@ public class ReachableHighlightAlgorithm<TVertex, TEdge, TGraph> :
private void ClearAllHighlights()
{
ClearSemiHighlights();
foreach (TVertex local in Controller.HighlightedVertices)
foreach (var vertex in Controller.HighlightedVertices)
{
Controller.RemoveHighlightFromVertex(local);
Controller.RemoveHighlightFromVertex(vertex);
}
foreach (TEdge local2 in Controller.HighlightedEdges)
foreach (var edge in Controller.HighlightedEdges)
{
Controller.RemoveHighlightFromEdge(local2);
Controller.RemoveHighlightFromEdge(edge);
}
}
@@ -42,8 +42,8 @@ private void ClearSemiHighlights()
public override bool OnEdgeHighlighting(TEdge edge)
{
this.ClearAllHighlights();
if (!(!object.Equals(edge, default(TEdge)) && base.Controller.Graph.ContainsEdge(edge)))
ClearAllHighlights();
if (!(!Equals(edge, default(TEdge)) && Controller.Graph.ContainsEdge(edge)))
{
return false;
}
@@ -25,7 +25,7 @@ public RepositoryGraphBuilder(string gitRepositoryPath)
}
}
public string GitRepositoryPath { get; private set; }
public string GitRepositoryPath { get; }
public RepositoryGraph Graph()
{
@@ -84,22 +84,22 @@ void AddHeadReference()
headCommitVertex.Branches.Merge(headBranceReference);
AddCommitsToGraph(headCommit, null);
HighlightCommitsOnCurrentBranch(headCommit, headCommitVertex);
HighlightCommitsOnCurrentBranch(headCommit);
}
private bool HighlightCommit(Commit commit)
{
CommitVertex commitVertex = GetCommitVertex(commit);
var commitVertex = GetCommitVertex(commit);
if (commitVertex.OnCurrentBranch)
return false;
commitVertex.OnCurrentBranch = true;
return true;
}
private void HighlightCommitsOnCurrentBranch(Commit commit, CommitVertex commitVertex)
private void HighlightCommitsOnCurrentBranch(Commit commit)
{
Queue<Commit> queue = new Queue<Commit>();
var queue = new Queue<Commit>();
queue.Enqueue(commit);
while (queue.Count != 0)
@@ -135,7 +135,7 @@ private void AddCommitsToGraph(Commit commit, CommitVertex childVertex)
{
// KeyValuePair is faster than a Tuple in this case.
// We create as many instances as we pass to the AddCommitToGraph.
Queue<CommitWithChildVertex> queue = new Queue<CommitWithChildVertex>();
var queue = new Queue<CommitWithChildVertex>();
queue.Enqueue(new CommitWithChildVertex(commit, childVertex));
while (queue.Count != 0)
@@ -1,16 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SeeGit.Views
{
@@ -36,12 +25,12 @@ public CommitVertex Model
private void Expander_Expanded(object sender, RoutedEventArgs e)
{
((CommitVertex)Model).Expanded = true;
Model.Expanded = true;
}
private void Expander_Collapsed(object sender, RoutedEventArgs e)
{
((CommitVertex)Model).Expanded = false;
Model.Expanded = false;
}
}
}
@@ -2,8 +2,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:local="clr-namespace:SeeGit"
mc:Ignorable="d" x:Name="Settings" d:DesignWidth="700" d:DesignHeight="50" Visibility="{Binding IsChecked, ElementName=toggleButton, Converter={StaticResource BooleanToVisibilityConverter}}">
mc:Ignorable="d"
x:Name="Settings"
d:DesignWidth="700"
d:DesignHeight="50"
Visibility="{Binding IsChecked, ElementName=toggleButton, Converter={StaticResource BooleanToVisibilityConverter}}">
<AdornerDecorator>
<Border Background="Black">
<StackPanel Orientation="Horizontal" Width="700" Height="50">
Oops, something went wrong.

0 comments on commit f75707c

Please sign in to comment.