Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tag related functionality.

  • Loading branch information...
commit c0faec81140c8ba9f6d40f76a5552206551e2552 1 parent 9916947
Kai Sellgren authored
24 Converters/GetSelectedTreeViewItemConverter.cs
View
@@ -0,0 +1,24 @@
+using System;
+using System.Linq;
+using System.Globalization;
+using System.Windows.Controls;
+using System.Windows.Data;
+
+namespace GG.Converters
+{
+ /// <summary>
+ /// Returns the height of the body (data grid actual height - column header height).
+ /// </summary>
+ class GetSelectedTreeViewItemConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return ((TreeView) value).SelectedItem;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return null;
+ }
+ }
+}
8 Git-GUI.csproj
View
@@ -161,6 +161,7 @@
</ApplicationDefinition>
<Compile Include="Converters\GenericVisibilityConverter.cs" />
<Compile Include="Converters\GetDataGridContentHeightConverter.cs" />
+ <Compile Include="Converters\GetSelectedTreeViewItemConverter.cs" />
<Compile Include="Libraries\Observable.cs" />
<Compile Include="UserControls\CenterArea.xaml.cs">
<DependentUpon>CenterArea.xaml</DependentUpon>
@@ -168,6 +169,9 @@
<Compile Include="UserControls\Dialogs\ConfirmDialog.xaml.cs">
<DependentUpon>ConfirmDialog.xaml</DependentUpon>
</Compile>
+ <Compile Include="UserControls\LeftToolbarContextMenus\TagContextMenu.xaml.cs">
+ <DependentUpon>TagContextMenu.xaml</DependentUpon>
+ </Compile>
<Compile Include="Views\About.xaml.cs">
<DependentUpon>About.xaml</DependentUpon>
</Compile>
@@ -255,6 +259,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
+ <Page Include="UserControls\LeftToolbarContextMenus\TagContextMenu.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="Views\About.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
25 Models/Commit.cs
View
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
using GG.Libraries;
using System.Linq;
using System.Collections.ObjectModel;
@@ -16,7 +14,7 @@ public class Commit
public string Description { get; set; }
public string ShortDescription { get; set; }
public List<string> DisplayTags { get; set; }
- public List<string> Tags { get; set; }
+ public ObservableCollection<Tag> Tags { get; set; }
public string Hash { get; set; }
public List<Branch> Branches { get; set; }
public List<Branch> BranchesAround { get; set; }
@@ -79,34 +77,35 @@ public bool IsMergeCommit()
/// </summary>
/// <param name="repo"></param>
/// <param name="commit"></param>
+ /// <param name="tags"> </param>
/// <returns></returns>
public static Commit Create(LibGit2Sharp.Repository repo,
LibGit2Sharp.Commit commit,
ObservableCollection<Tag> tags)
{
- Commit c = new Commit();
+ var c = new Commit();
// Process Tags (Git tags to display next to the commit description).
- List<string> commitTags = new List<string>();
- foreach (Tag tag in tags)
+ var commitTags = new ObservableCollection<Tag>();
+ foreach (var tag in tags)
{
- if (tag.TargetSha == commit.Sha.ToString())
+ if (tag.TargetSha == commit.Sha)
{
- commitTags.Add(tag.Name);
+ commitTags.Add(tag);
tag.Target = c;
}
}
// Process display tags.
- List<string> displayTags = new List<string>();
+ var displayTags = new List<string>();
if (repo.Head.Tip == commit)
displayTags.Add("HEAD");
// Process ParentHashes.
- List<string> parentHashes = new List<string>();
- foreach (LibGit2Sharp.Commit parentCommit in commit.Parents)
+ var parentHashes = new List<string>();
+ foreach (var parentCommit in commit.Parents)
{
- parentHashes.Add(parentCommit.Sha.ToString());
+ parentHashes.Add(parentCommit.Sha);
}
// Set properties.
@@ -118,7 +117,7 @@ public bool IsMergeCommit()
c.DisplayTags = displayTags;
c.Branches = new List<Branch>();
c.Tags = commitTags;
- c.Hash = commit.Sha.ToString();
+ c.Hash = commit.Sha;
c.ParentHashes = parentHashes;
c.ParentCount = commit.ParentsCount;
c.Parents = new List<Commit>();
20 Styles/DataGrid.xaml
View
@@ -27,6 +27,14 @@
<GradientStop Color="#9fd3eb" Offset="1"/>
</LinearGradientBrush>
+ <LinearGradientBrush x:Key="DataGridHighlightBlurBrush" StartPoint="0,0" EndPoint="0,1">
+ <GradientStop Color="#fcfcfc" Offset="0"/>
+ <GradientStop Color="#e3e3e3" Offset="0.1"/>
+ <GradientStop Color="#d2d2d2" Offset="0.45"/>
+ <GradientStop Color="#c8c8c8" Offset="0.9"/>
+ <GradientStop Color="#ebebeb" Offset="1"/>
+ </LinearGradientBrush>
+
<Style TargetType="{x:Type DataGrid}">
<Setter Property="Background" Value="{StaticResource DefaultBackgroundBrush}" />
<Setter Property="BorderBrush" Value="#bbb" />
@@ -225,17 +233,7 @@
<Setter Property="BorderBrush" Value="#bebebe" />
<Setter Property="BorderBrush" Value="#bebebe" TargetName="OuterBorder" />
<Setter Property="Foreground" Value="#000" />
- <Setter Property="Background">
- <Setter.Value>
- <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
- <GradientStop Color="#fcfcfc" Offset="0"/>
- <GradientStop Color="#e3e3e3" Offset="0.1"/>
- <GradientStop Color="#d2d2d2" Offset="0.45"/>
- <GradientStop Color="#c8c8c8" Offset="0.9"/>
- <GradientStop Color="#ebebeb" Offset="1"/>
- </LinearGradientBrush>
- </Setter.Value>
- </Setter>
+ <Setter Property="Background" Value="{StaticResource DataGridHighlightBlurBrush}" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
142 Styles/TreeView.xaml
View
@@ -1,55 +1,113 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+ <Style x:Key="ExpandCollapseToggleStyle" TargetType="ToggleButton">
+ <Setter Property="Focusable" Value="False"/>
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="ToggleButton">
+ <Grid Width="15" Height="13" Background="Transparent">
+ <Path x:Name="ExpandPath" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="1,1,1,1" Fill="{StaticResource GlyphBrush}" Data="M 4 0 L 8 4 L 4 8 Z"/>
+ </Grid>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsChecked" Value="True">
+ <Setter Property="Data" TargetName="ExpandPath" Value="M 0 4 L 8 4 L 4 8 Z"/>
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+ <Style x:Key="TreeViewItemFocusVisual">
+ <Setter Property="Control.Template">
+ <Setter.Value>
+ <ControlTemplate>
+ <Border>
+ <Rectangle Margin="0,0,0,0" StrokeThickness="5" Stroke="Black" StrokeDashArray="1 2" Opacity="0"/>
+ </Border>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="4,1,0,1" />
- <Style.Triggers>
- <Trigger Property="IsSelected" Value="True">
- <Setter Property="Foreground" Value="White" />
- <Setter Property="BorderBrush" Value="#7ea3be"/>
- </Trigger>
- <MultiDataTrigger>
- <MultiDataTrigger.Conditions>
- <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True"/>
- <Condition Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="False"/>
- </MultiDataTrigger.Conditions>
- <Setter Property="BorderBrush" Value="LightGray"/>
- <Setter Property="Foreground" Value="Gray" />
- </MultiDataTrigger>
-
- <MultiDataTrigger>
- <MultiDataTrigger.Conditions>
- <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True"/>
- <Condition Binding="{Binding ContextMenu.IsOpen, RelativeSource={RelativeSource AncestorType=DataGrid}}" Value="True"/>
- </MultiDataTrigger.Conditions>
- <Setter Property="Foreground" Value="White" />
- <Setter Property="BorderBrush" Value="#7ea3be"/>
- </MultiDataTrigger>
- </Style.Triggers>
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="{x:Type TreeViewItem}">
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition MinWidth="19" Width="Auto"/>
+ <ColumnDefinition Width="Auto"/>
+ <ColumnDefinition Width="*"/>
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto"/>
+ <RowDefinition/>
+ </Grid.RowDefinitions>
+ <ToggleButton x:Name="Expander" Style="{StaticResource ExpandCollapseToggleStyle}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
+ <Border Name="Bd" Grid.Column="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
+ <ContentPresenter x:Name="PART_Header" ContentSource="Header" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>
+ </Border>
+ <ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"/>
+ </Grid>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsExpanded" Value="false">
+ <Setter TargetName="ItemsHost" Property="Visibility" Value="Collapsed"/>
+ </Trigger>
+ <Trigger Property="HasItems" Value="false">
+ <Setter TargetName="Expander" Property="Visibility" Value="Hidden"/>
+ </Trigger>
+ <MultiTrigger>
+ <MultiTrigger.Conditions>
+ <Condition Property="HasHeader" Value="false"/>
+ <Condition Property="Width" Value="Auto"/>
+ </MultiTrigger.Conditions>
+ <Setter TargetName="PART_Header" Property="MinWidth" Value="75"/>
+ </MultiTrigger>
+ <MultiTrigger>
+ <MultiTrigger.Conditions>
+ <Condition Property="HasHeader" Value="false"/>
+ <Condition Property="Height" Value="Auto"/>
+ </MultiTrigger.Conditions>
+ <Setter TargetName="PART_Header" Property="MinHeight" Value="19"/>
+ </MultiTrigger>
+ <Trigger Property="IsSelected" Value="true">
+ <Setter TargetName="Bd" Property="Background" Value="{StaticResource DataGridHighlightBrush}"/>
+ <Setter Property="Foreground" Value="#fff"/>
+ <Setter TargetName="Bd" Property="BorderBrush" Value="#7ea3be"/>
+ </Trigger>
+ <MultiTrigger>
+ <MultiTrigger.Conditions>
+ <Condition Property="IsSelected" Value="true"/>
+ <Condition Property="IsSelectionActive" Value="false"/>
+ </MultiTrigger.Conditions>
+ <Setter TargetName="Bd" Property="Background" Value="{StaticResource DataGridHighlightBlurBrush}"/>
+ <Setter TargetName="Bd" Property="BorderBrush" Value="#bebebe"/>
+ <Setter Property="Foreground" Value="#000"/>
+ </MultiTrigger>
+ <MultiDataTrigger>
+ <MultiDataTrigger.Conditions>
+ <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True"/>
+ <Condition Binding="{Binding ContextMenu.IsOpen, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" Value="True"/>
+ </MultiDataTrigger.Conditions>
+
+ <Setter TargetName="Bd" Property="Background" Value="{StaticResource DataGridHighlightBrush}"/>
+ <Setter Property="Foreground" Value="#fff"/>
+ <Setter TargetName="Bd" Property="BorderBrush" Value="#7ea3be"/>
+ </MultiDataTrigger>
+ <Trigger Property="IsEnabled" Value="false">
+ <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="2" />
</Style>
</Style.Resources>
</Style>
-
- <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" EndPoint="0,1" StartPoint="0,0" >
- <GradientStop Color="#b3e5fc" Offset="0"/>
- <GradientStop Color="#8cc8e3" Offset="0.1"/>
- <GradientStop Color="#83bad2" Offset="0.45"/>
- <GradientStop Color="#609fbb" Offset="0.9"/>
- <GradientStop Color="#9fd3eb" Offset="1"/>
- </LinearGradientBrush>
-
- <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" EndPoint="0,1" StartPoint="0,0">
- <GradientStop Color="#fcfcfc" Offset="0"/>
- <GradientStop Color="#e3e3e3" Offset="0.1"/>
- <GradientStop Color="#d2d2d2" Offset="0.45"/>
- <GradientStop Color="#c8c8c8" Offset="0.9"/>
- <GradientStop Color="#ebebeb" Offset="1"/>
- </LinearGradientBrush>
-
- <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="#eee" />
- <SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="#666" />
</ResourceDictionary>
2  UserControls/ChangesetHistory.xaml
View
@@ -59,7 +59,7 @@
<DataTemplate>
<WrapPanel>
<ListBox ItemsSource="{Binding DisplayTags}" Style="{StaticResource DisplayTagsBlueStyle}" IsHitTestVisible="False" />
- <ListBox ItemsSource="{Binding Tags}" Style="{StaticResource DisplayTagsOrangeStyle}" IsHitTestVisible="False" />
+ <ListBox ItemsSource="{Binding Tags}" DisplayMemberPath="Name" Style="{StaticResource DisplayTagsOrangeStyle}" IsHitTestVisible="False" />
<TextBlock Text="{Binding Path=ShortDescription}"
VerticalAlignment="Center"
FontWeight="{Binding IsHead, Converter={StaticResource isHeadToFontWeightConverter}}"
2  UserControls/ChangesetHistoryContextMenu.xaml
View
@@ -69,7 +69,7 @@
</MenuItem>
<MenuItem Header="Tag this commit..."
- Command="{Binding PlacementTarget.Tag.TagCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
+ Command="{Binding PlacementTarget.Tag.CreateTagCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
CommandParameter="{Binding PlacementTarget.SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Tag.png" Stretch="None" />
5 UserControls/ChangesetHistoryContextMenu.xaml.cs
View
@@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Linq;
using GG.Models;
-using System.Windows;
using GG.Libraries;
using System.Windows.Documents;
@@ -64,10 +63,10 @@ private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
// Add Checkout menu items. TODO: Add also non-branch-checkouts.
var numberOfCheckoutItems = 0;
- foreach (Branch branch in commit.Branches)
+ foreach (var branch in commit.Branches)
{
// Only if the right clicked commit is the tip of the branch, AND the branch is not already checkout out, continue.
- if (branch.Tip == commit && ((Branch) repositoryViewModel.Head) != branch && branch.IsRemote == false)
+ if (branch.Tip == commit && (repositoryViewModel.Head) != branch && branch.IsRemote == false)
{
var text = new TextBlock();
text.Inlines.AddRange(new Inline[]
3  UserControls/Dialogs/ConfirmDialog.xaml.cs
View
@@ -42,6 +42,9 @@ public ConfirmDialog() : base()
);
DataContext = this;
+
+ if (Buttons == null)
+ ButtonSet = ButtonsSet.OK_CANCEL;
}
/// <summary>
47 UserControls/LeftToolbar.xaml
View
@@ -4,19 +4,21 @@
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:userControls="clr-namespace:GG.UserControls"
+ xmlns:contextMenus="clr-namespace:GG.UserControls.LeftToolbarContextMenus"
mc:Ignorable="d">
+
+ <UserControl.Resources>
+ <contextMenus:TagContextMenu x:Key="tagContextMenu" />
+ </UserControl.Resources>
<Border BorderBrush="#bbb" BorderThickness="1,1,1,0">
<Grid>
<Grid VerticalAlignment="Stretch" Style="{StaticResource LeftToolbarStyle}" HorizontalAlignment="Left" Width="160">
<Grid Margin="8" d:DataContext="{d:DesignData Source=../DesignData/Branches.xaml}">
<TreeView Background="{x:Null}" BorderThickness="0" Padding="0">
- <TreeView.InputBindings>
- <!--<KeyBinding Command="{Binding DeleteBranchCommand}" Gesture="Delete" />-->
- </TreeView.InputBindings>
-
- <TreeViewItem ItemsSource="{Binding Branches}" PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown">
+ <TreeViewItem ItemsSource="{Binding Branches}"
+ PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown"
+ Tag="{Binding}">
<TreeViewItem.Header>
<WrapPanel>
<Image Source="../Resources/Icons/Branch.png" Stretch="None" Style="{StaticResource LeftToolbarTitleImageStyle}" />
@@ -26,38 +28,27 @@
<TreeViewItem.ItemTemplate>
<DataTemplate>
- <TextBlock Text="{Binding Name}" Style="{StaticResource LeftToolbarTitleStyle}" Tag="{Binding ElementName=LeftToolbarUserControl}">
- <TextBlock.ContextMenu>
- <ContextMenu>
- <MenuItem Header="Checkout">
- <MenuItem.Icon>
- <Image Source="../Resources/Icons/Checkout.png" Stretch="None" />
- </MenuItem.Icon>
- </MenuItem>
- <MenuItem Header="Delete" CommandParameter="{Binding}" Command="{Binding PlacementTarget.Tag.DeleteBranchCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}}" InputGestureText="Delete">
- <MenuItem.Icon>
- <Image Source="../Resources/Icons/Delete.png" Stretch="None" />
- </MenuItem.Icon>
- </MenuItem>
- <MenuItem Header="Merge with X">
- <MenuItem.Icon>
- <Image Source="../Resources/Icons/Merge.png" Stretch="None" />
- </MenuItem.Icon>
- </MenuItem>
- </ContextMenu>
- </TextBlock.ContextMenu>
- </TextBlock>
+ <TextBlock Text="{Binding Name}" Style="{StaticResource LeftToolbarTitleStyle}" Tag="{Binding ElementName=LeftToolbarUserControl}" />
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
- <TreeViewItem ItemsSource="{Binding Tags}">
+ <TreeViewItem ItemsSource="{Binding Tags}"
+ PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown"
+ ContextMenu="{StaticResource tagContextMenu}"
+ Tag="{Binding}">
<TreeViewItem.Header>
<WrapPanel>
<Image Source="../Resources/Icons/Tag.png" Stretch="None" Style="{StaticResource LeftToolbarTitleImageStyle}" />
<TextBlock Style="{StaticResource LeftToolbarTitleStyle}">TAGS</TextBlock>
</WrapPanel>
</TreeViewItem.Header>
+
+ <TreeViewItem.ItemTemplate>
+ <DataTemplate>
+ <TextBlock Text="{Binding Name}" Style="{StaticResource LeftToolbarTitleStyle}" Tag="{Binding ElementName=LeftToolbarUserControl}" />
+ </DataTemplate>
+ </TreeViewItem.ItemTemplate>
</TreeViewItem>
<TreeViewItem ItemsSource="{Binding Remotes}">
31 UserControls/LeftToolbar.xaml.cs
View
@@ -1,18 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-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.Models;
namespace GG.UserControls
{
@@ -21,30 +10,14 @@ namespace GG.UserControls
/// </summary>
public partial class LeftToolbar : UserControl
{
- public DelegateCommand DeleteBranchCommand { get; private set; }
-
public LeftToolbar()
{
InitializeComponent();
-
- DeleteBranchCommand = new DelegateCommand(DeleteBranch);
- }
-
- /// <summary>
- /// Deletes a branch.
- /// </summary>
- /// <param name="action"></param>
- private void DeleteBranch(object action)
- {
- Branch branch = action as Branch;
-
- // TODO: Needs confirmation.
- branch.Delete();
}
private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
- TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);
+ var treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject);
if (treeViewItem != null)
{
28 UserControls/LeftToolbarContextMenus/TagContextMenu.xaml
View
@@ -0,0 +1,28 @@
+<ContextMenu x:Class="GG.UserControls.LeftToolbarContextMenus.TagContextMenu"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:converters="clr-namespace:GG.Converters"
+ Opened="OnOpened"
+ ContextMenuOpening="OnContextMenuOpening">
+
+ <ContextMenu.Resources>
+ <converters:GetSelectedTreeViewItemConverter x:Key="getSelectedTreeViewItemConverter" />
+ </ContextMenu.Resources>
+
+ <MenuItem Header="Checkout"
+ CommandParameter="{Binding PlacementTarget.Parent, RelativeSource={RelativeSource AncestorType=ContextMenu}, Converter={StaticResource getSelectedTreeViewItemConverter}}"
+ Command="{Binding PlacementTarget.Tag.CheckoutCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}}">
+ <MenuItem.Icon>
+ <Image Source="../../Resources/Icons/Checkout.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+ <MenuItem Header="Delete"
+ CommandParameter="{Binding PlacementTarget.Parent, RelativeSource={RelativeSource AncestorType=ContextMenu}, Converter={StaticResource getSelectedTreeViewItemConverter}}"
+ Command="{Binding PlacementTarget.Tag.DeleteTagCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ContextMenu}}">
+ <MenuItem.Icon>
+ <Image Source="../../Resources/Icons/Delete.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+</ContextMenu>
38 UserControls/LeftToolbarContextMenus/TagContextMenu.xaml.cs
View
@@ -0,0 +1,38 @@
+using System.Windows.Controls;
+using GG.Models;
+
+namespace GG.UserControls.LeftToolbarContextMenus
+{
+ /// <summary>
+ /// Interaction logic for ChangesetHistoryContextMenu.xaml
+ /// </summary>
+ public partial class TagContextMenu : ContextMenu
+ {
+ public TagContextMenu()
+ {
+ InitializeComponent();
+ }
+
+ /// <summary>
+ /// Returns the current repository view model instance being used.
+ /// </summary>
+ /// <returns></returns>
+ private RepositoryViewModel GetRepositoryViewModel()
+ {
+ return ((DataGrid) PlacementTarget).DataContext as RepositoryViewModel;
+ }
+
+ /// <summary>
+ /// Preprocessing prior to menu opening.
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
+ {
+ }
+
+ private void OnContextMenuOpening(object sender, ContextMenuEventArgs e)
+ {
+ }
+ }
+}
90 ViewModels/RepositoryViewModel.cs
View
@@ -98,18 +98,20 @@ public RepositoryViewModel()
RecentCommitMessageCount = 10;
// Initialize commands.
- ExportPatchCommand = new DelegateCommand(ExportPatch);
- CopyPatchCommand = new DelegateCommand(CopyPatch);
AddNoteCommand = new DelegateCommand(AddNote);
- CopyHashCommand = new DelegateCommand(CopyHash);
- TagCommand = new DelegateCommand(CreateTag);
+ CheckoutCommand = new DelegateCommand(Checkout);
CreateBranchCommand = new DelegateCommand(CreateBranch);
+ CreateTagCommand = new DelegateCommand(CreateTag);
+ CommitCommand = new DelegateCommand(CommitChanges, CommitChanges_CanExecute);
+ CopyHashCommand = new DelegateCommand(CopyHash);
+ CopyPatchCommand = new DelegateCommand(CopyPatch);
+ DeleteFileCommand = new DelegateCommand(DeleteFile);
+ DeleteTagCommand = new DelegateCommand(DeleteTag);
+ ExportPatchCommand = new DelegateCommand(ExportPatch);
+ OpenAboutCommand = new DelegateCommand(OpenAbout);
ResetSoftCommand = new DelegateCommand(ResetSoft);
ResetMixedCommand = new DelegateCommand(ResetMixed);
- OpenAboutCommand = new DelegateCommand(OpenAbout);
StageUnstageCommand = new DelegateCommand(StageUnstage);
- DeleteFileCommand = new DelegateCommand(DeleteFile);
- CommitCommand = new DelegateCommand(CommitChanges, CommitChanges_CanExecute);
// Diff panel.
StatusItemDiff = "";
@@ -117,18 +119,20 @@ public RepositoryViewModel()
#region Commands.
- public DelegateCommand ExportPatchCommand { get; private set; }
- public DelegateCommand CopyPatchCommand { get; private set; }
- public DelegateCommand AddNoteCommand { get; private set; }
- public DelegateCommand CopyHashCommand { get; private set; }
- public DelegateCommand TagCommand { get; private set; }
+ public DelegateCommand AddNoteCommand { get; private set; }
+ public DelegateCommand CheckoutCommand { get; private set; }
public DelegateCommand CreateBranchCommand { get; private set; }
- public DelegateCommand ResetSoftCommand { get; private set; }
- public DelegateCommand ResetMixedCommand { get; private set; }
+ public DelegateCommand CreateTagCommand { get; private set; }
+ public DelegateCommand CommitCommand { get; private set; }
+ public DelegateCommand CopyHashCommand { get; private set; }
+ public DelegateCommand CopyPatchCommand { get; private set; }
+ public DelegateCommand DeleteFileCommand { get; private set; }
+ public DelegateCommand DeleteTagCommand { get; private set; }
+ public DelegateCommand ExportPatchCommand { get; private set; }
public DelegateCommand OpenAboutCommand { get; private set; }
+ public DelegateCommand ResetSoftCommand { get; private set; }
+ public DelegateCommand ResetMixedCommand { get; private set; }
public DelegateCommand StageUnstageCommand { get; private set; }
- public DelegateCommand DeleteFileCommand { get; private set; }
- public DelegateCommand CommitCommand { get; private set; }
/// <summary>
/// Exports the given changeset as a patch to a file.
@@ -180,6 +184,22 @@ public void CopyPatch(object action)
}
/// <summary>
+ /// Checkouts a commit/branch/tag.
+ /// </summary>
+ /// <param name="action"></param>
+ public void Checkout(object action)
+ {
+ Task.Run(() =>
+ {
+ using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
+ {
+ if (action is Tag)
+ repo.Checkout(((Tag) action).CanonicalName);
+ }
+ });
+ }
+
+ /// <summary>
/// Adds a new note for the given commit.
/// </summary>
/// <param name="action"></param>
@@ -255,6 +275,44 @@ public void CreateTag(object action)
}
/// <summary>
+ /// Deletes a tag.
+ /// </summary>
+ /// <param name="action"></param>
+ public void DeleteTag(object action)
+ {
+ var tag = (Tag) action;
+
+ var dialog = new ConfirmDialog
+ {
+ Title = "Deleting a tag",
+ Message = String.Format("Are you sure you want to delete this tag ({0})?", tag.Name)
+ };
+
+ dialog.ShowDialog();
+
+ var pressedButton = dialog.PressedButton;
+ if (pressedButton == null || ((string) pressedButton.Content) != "OK")
+ return;
+
+ Task.Run(() =>
+ {
+ using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
+ {
+ // Remove the tag from the Git repository.
+ repo.Tags.Delete(tag.CanonicalName);
+
+ // Reload all tags.
+ LoadTags();
+
+ Application.Current.Dispatcher.BeginInvoke(
+ DispatcherPriority.Normal,
+ (Action) (() => tag.Target.Tags.Remove(tag))
+ );
+ }
+ });
+ }
+
+ /// <summary>
/// Resets (reset --mixed) the repository to the given changeset.
/// </summary>
/// <param name="action"></param>
Please sign in to comment.
Something went wrong with that request. Please try again.