Permalink
Browse files

Panel refactorings.

  • Loading branch information...
1 parent 22337bd commit 8d21c6bdb2d5af874a3a1001bfdde82034c5bb3d @kaisellgren committed Jul 5, 2012
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.ObjectModel;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace GG.Converters
+{
+ public class GenericVisibilityConverter : IValueConverter
+ {
+ #region Implementation of IValueConverter
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ // Whether to invert the visibility.
+ var invert = (string) parameter == "not" ? true : false;
+
+ // int 0
+ if (value is int && (int) value == 0)
+ return invert ? Visibility.Visible : Visibility.Collapsed;
+
+ // int > 0
+ if (value is int && (int) value > 0)
+ return invert ? Visibility.Collapsed : Visibility.Visible;
+
+ // null || bool == false
+ if (value == null || (value is bool && (bool) value == false))
+ return invert ? Visibility.Visible : Visibility.Collapsed;
+
+ // bool == true
+ if (value is bool && (bool) value == true)
+ return invert ? Visibility.Collapsed : Visibility.Visible;
+
+ // Fall back to "visible".
+ return invert ? Visibility.Collapsed : Visibility.Visible;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+ }
+}
@@ -27,10 +27,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (value == null)
return COLOR_RED;
- LibGit2Sharp.FileStatus status = (LibGit2Sharp.FileStatus) value;
+ var status = (LibGit2Sharp.FileStatus) value;
// Whether to use darker colors (for text).
- bool darkerColors = (string) parameter == "dark";
+ var darkerColors = (string) parameter == "dark";
// Removed & Missing = red.
if (status.HasFlag(LibGit2Sharp.FileStatus.Removed) || status.HasFlag(LibGit2Sharp.FileStatus.Missing))
@@ -48,7 +48,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (status.HasFlag(LibGit2Sharp.FileStatus.Untracked))
return darkerColors ? COLOR_DARK_GRAY : COLOR_GRAY;
- throw new Exception("Could not convert status " + status.ToString() + " to a SolidColorBrush!");
+ throw new Exception("Could not convert status " + status + " to a SolidColorBrush!");
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
View
@@ -156,8 +156,12 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Compile Include="Converters\GenericVisibilityConverter.cs" />
<Compile Include="Converters\GetDataGridContentHeightConverter.cs" />
<Compile Include="Libraries\Observable.cs" />
+ <Compile Include="UserControls\CenterArea.xaml.cs">
+ <DependentUpon>CenterArea.xaml</DependentUpon>
+ </Compile>
<Compile Include="UserControls\Dialogs\ConfirmDialog.xaml.cs">
<DependentUpon>ConfirmDialog.xaml</DependentUpon>
</Compile>
@@ -240,6 +244,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="UserControls\CenterArea.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="UserControls\Dialogs\ConfirmDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -63,6 +63,14 @@ public void AddRange(IEnumerable<T> collection)
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
+ /// <summary>
+ /// Returns true if the collection is empty.
+ /// </summary>
+ public bool IsEmpty
+ {
+ get { return Count == 0; }
+ }
+
/// <summary>
/// Initializes a new instance of the System.Collections.ObjectModel.ObservableCollection(Of T) class.
/// </summary>
@@ -3,20 +3,74 @@
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:controls="clr-namespace:GG.UserControls"
+ xmlns:userControls="clr-namespace:GG.UserControls"
+ xmlns:converters="clr-namespace:GG.Converters"
mc:Ignorable="d"
d:DesignHeight="480" d:DesignWidth="640">
+
+ <UserControl.Resources>
+ <converters:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
+
+ <DataTemplate x:Key="Test">
+ <TextBlock x:Name="FooBarBaz">Foo bar baz</TextBlock>
+ </DataTemplate>
+ </UserControl.Resources>
+
<DockPanel>
- <!-- TODO: Panel should be a reusable component... I've only made the title to be reusable, the rest is hard-coded as Commit Panel stuff in Panel XAML... move it in here... -->
- <controls:Panel>
- <controls:Panel.Header>
+ <userControls:Panel Header="{StaticResource Test}">
+ <!--<userControls:Panel.Header>
<WrapPanel>
<TextBlock Text="Parent: (" />
<TextBlock Text="{Binding Head.Tip.HashShort}" />
<TextBlock Text=") " />
<TextBlock Text="{Binding Head.Tip.ShortDescription}" />
</WrapPanel>
- </controls:Panel.Header>
- </controls:Panel>
+ </userControls:Panel.Header>-->
+
+ <userControls:Panel.HeaderButtons>
+ <WrapPanel HorizontalAlignment="Right">
+ <Grid>
+ <ComboBox ToolTip="Copy a previous commit message. The entire message will be copied."
+ ItemsSource="{Binding RecentCommitMessages}"
+ DisplayMemberPath="CroppedMessage"
+ Loaded="ComboBoxLoaded"
+ SelectionChanged="OnRecentCommitMessagesSelectionChanged"
+ Width="135" Margin="0,4,4,4">
+ </ComboBox>
+ <WrapPanel Margin="8,9,0,0" Visibility="{Binding SelectedItem, ElementName=RecentCommitMessages, Converter={StaticResource nullToVisibilityConverter}}">
+ <Image Source="../Resources/Icons/MessageWrite.png" Stretch="None" Margin="0,0,4,0" />
+ <TextBlock IsHitTestVisible="False" Text="Copy a message" Foreground="#333" />
+ </WrapPanel>
+ </Grid>
+ <Button Margin="0,3,3,3" Command="{Binding CommitCommand}" CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}">
+ <WrapPanel>
+ <Image Source="../Resources/Icons/RepositoryWrite.png" Width="16" Margin="0,0,4,0" />
+ <TextBlock>Commit</TextBlock>
+ </WrapPanel>
+ </Button>
+ </WrapPanel>
+ </userControls:Panel.HeaderButtons>
+
+ <userControls:Panel.Body>
+ <StackPanel Margin="4">
+ <TextBox Loaded="TextBoxLoaded"
+ ToolTip="Enter your commit message."
+ FontSize="12"
+ FontFamily="Courier New"
+ Height="38pt">
+
+ <TextBox.InputBindings>
+ <KeyBinding Key="Enter"
+ Modifiers="Control"
+ Command="{Binding CommitCommand}"
+ CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}" />
+ </TextBox.InputBindings>
+ </TextBox>
+
+ <userControls:DiffPanel DockPanel.Dock="Bottom" Margin="0,4,0,0" />
+ </StackPanel>
+ </userControls:Panel.Body>
+
+ </userControls:Panel>
</DockPanel>
</UserControl>
@@ -1,16 +1,7 @@
-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;
+using GG.Libraries;
+using GG.Models;
namespace GG.UserControls
{
@@ -23,5 +14,33 @@ public CommitPanel()
{
InitializeComponent();
}
+
+ private void TextBoxLoaded(object sender, RoutedEventArgs e)
+ {
+ ((TextBox) sender).Name = "CommitMessageTextBox";
+ }
+
+ private void OnRecentCommitMessagesSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ // Retrieve elements.
+ var recentCommitMessages = UIHelper.FindChild<ComboBox>(this, "RecentCommitMessages");
+ var commitMessageBox = UIHelper.FindChild<TextBox>(this, "CommitMessageTextBox");
+
+ var selectedRecentCommitMessage = recentCommitMessages.SelectedItem as RecentCommitMessage;
+
+ if (selectedRecentCommitMessage == null)
+ return;
+
+ // Set the commit text box value.
+ commitMessageBox.Text = selectedRecentCommitMessage.FullMessage;
+
+ // Reset the drop down menu.
+ recentCommitMessages.SelectedIndex = -1;
+ }
+
+ private void ComboBoxLoaded(object sender, RoutedEventArgs e)
+ {
+ ((ComboBox) sender).Name = "RecentCommitMessages";
+ }
}
}
@@ -8,7 +8,6 @@
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
- Margin="4"
Padding="4,6"
Background="White"
BorderThickness="0"
View
@@ -2,66 +2,24 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:GG"
xmlns:userControls="clr-namespace:GG.UserControls"
- xmlns:converters="clr-namespace:GG.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="600">
- <UserControl.Resources>
- <converters:NullToVisibilityConverter x:Key="nullToVisibilityConverter" />
- </UserControl.Resources>
-
<UserControl.Template>
<ControlTemplate>
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<Border BorderBrush="#7ea3be" BorderThickness="1">
<DockPanel Style="{StaticResource PanelHeaderStyle}">
<ContentPresenter DockPanel.Dock="Left" Style="{StaticResource PanelHeaderTitleStyle}" Content="{TemplateBinding userControls:Panel.Header}" />
- <WrapPanel DockPanel.Dock="Right" HorizontalAlignment="Right">
- <Grid>
- <ComboBox ToolTip="Copy a previous commit message. The entire message will be copied."
- ItemsSource="{Binding RecentCommitMessages}"
- DisplayMemberPath="CroppedMessage"
- Name="RecentCommitMessages"
- SelectionChanged="OnRecentCommitMessagesSelectionChanged"
- Width="135" Margin="0,4,4,4">
- </ComboBox>
- <WrapPanel Margin="8,9,0,0" Visibility="{Binding SelectedItem, ElementName=RecentCommitMessages, Converter={StaticResource nullToVisibilityConverter}}">
- <Image Source="../Resources/Icons/MessageWrite.png" Stretch="None" Margin="0,0,4,0" />
- <TextBlock IsHitTestVisible="False" Text="Copy a message" Foreground="#333" />
- </WrapPanel>
- </Grid>
- <Button Margin="0,3,3,3"
- Command="{Binding CommitCommand}" CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}">
- <WrapPanel>
- <Image Source="../Resources/Icons/RepositoryWrite.png" Width="16" Margin="0,0,4,0" />
- <TextBlock>Commit</TextBlock>
- </WrapPanel>
- </Button>
- </WrapPanel>
+ <ContentPresenter DockPanel.Dock="Right" Content="{TemplateBinding userControls:Panel.HeaderButtons}" />
</DockPanel>
</Border>
- <Grid>
- <StackPanel Margin="4">
- <TextBox Name="CommitMessageTextBox"
- ToolTip="Enter your commit message."
- FontSize="12"
- FontFamily="Courier New"
- Height="38pt">
- <TextBox.InputBindings>
- <KeyBinding Key="Enter"
- Modifiers="Control"
- Command="{Binding CommitCommand}"
- CommandParameter="{Binding Text, ElementName=CommitMessageTextBox}" />
- </TextBox.InputBindings>
- </TextBox>
- </StackPanel>
- </Grid>
</StackPanel>
- <userControls:DiffPanel DockPanel.Dock="Bottom" />
+
+ <ContentPresenter DockPanel.Dock="Bottom" Content="{TemplateBinding userControls:Panel.Body}" />
</DockPanel>
</ControlTemplate>
</UserControl.Template>
Oops, something went wrong.

0 comments on commit 8d21c6b

Please sign in to comment.