Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Status grid can now remove files.

  • Loading branch information...
commit b59b3bd5d3596d066859a891eb0b04e657600b7e 1 parent 7926540
@kaisellgren authored
View
4 DesignData/SampleApplication.xaml
@@ -1,6 +1,6 @@
<local:MainWindowViewModel xmlns:local="clr-namespace:GG" xmlns:sys="clr-namespace:System;assembly=mscorlib">
<local:MainWindowViewModel.RepositoryViewModels>
- <local:RepositoryViewModel Name="Sample" FullPath="Z:/www/git1">
+ <local:RepositoryViewModel Name="Sample" RepositoryFullPath="Z:/www/git1">
<local:RepositoryViewModel.Commits>
<local:Commit AuthorEmail="foo@email" AuthorName="Foo" Date="12.12.2012" FormattedDate="One minute ago" Description="Foo" Hash="123" Source="asdasd">
<local:Commit.DisplayTags>
@@ -22,6 +22,6 @@
</local:MainWindowViewModel.RepositoryViewModels>
<local:MainWindowViewModel.RecentRepositories>
- <local:RepositoryViewModel Name="Sample" FullPath="Z:/www/git1" />
+ <local:RepositoryViewModel Name="Sample" RepositoryFullPath="Z:/www/git1" />
</local:MainWindowViewModel.RecentRepositories>
</local:MainWindowViewModel>
View
3  Git-GUI.csproj
@@ -426,6 +426,9 @@
<FileType>Assembly</FileType>
</PublishFile>
</ItemGroup>
+ <ItemGroup>
+ <Resource Include="Resources\Icons\OpenIgnoreEditor.png" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
View
2  Libraries/ChangesetGraph.cs
@@ -67,7 +67,7 @@ public void Draw(ItemCollection commitList)
Console.WriteLine("Drawing graph.");
- LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(repositoryViewModel.FullPath);
+ LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(repositoryViewModel.RepositoryFullPath);
commitDotPositions.Clear();
SetBranchColors(repo.Branches);
View
BIN  Resources/Icons/OpenIgnoreEditor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
48 UserControls/StatusGridContextMenu.xaml
@@ -17,19 +17,19 @@
<Separator x:Name="StageSeparator" />
- <MenuItem Header="Annotate...">
+ <MenuItem Header="Annotate..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Annotate.png" Stretch="None" />
</MenuItem.Icon>
</MenuItem>
- <MenuItem Header="File history...">
+ <MenuItem Header="File history..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/History.png" Stretch="None" />
</MenuItem.Icon>
</MenuItem>
- <MenuItem Header="Visual diff...">
+ <MenuItem Header="Visual diff..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/VisualDiff.png" Stretch="None" />
</MenuItem.Icon>
@@ -37,13 +37,43 @@
<Separator />
- <MenuItem Header="Ignore" InputGestureText="Ctrl+I">
+ <MenuItem Header="Ignore" IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Ignore.png" Stretch="None" />
</MenuItem.Icon>
+
+ <MenuItem Header="Open the Ignore Editor...">
+ <MenuItem.Icon>
+ <Image Source="../Resources/Icons/OpenIgnoreEditor.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+ <MenuItem x:Name="IgnoreThisFile" Header="Ignore this file">
+ <MenuItem.Icon>
+ <Image Source="../Resources/Icons/Ignore.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+ <MenuItem Header="Ignore all *.xyz files">
+ <MenuItem.Icon>
+ <Image Source="../Resources/Icons/Ignore.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+ <MenuItem x:Name="IgnoreFilesUnderThisFolder" Header="Ignore files under this folder">
+ <MenuItem.Icon>
+ <Image Source="../Resources/Icons/Ignore.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
+
+ <MenuItem x:Name="IgnoreThisFolderEntirely" Header="Ignore this folder entirely">
+ <MenuItem.Icon>
+ <Image Source="../Resources/Icons/Ignore.png" Stretch="None" />
+ </MenuItem.Icon>
+ </MenuItem>
</MenuItem>
- <MenuItem Header="Revert...">
+ <MenuItem Header="Revert..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Backout.png" Stretch="None" />
</MenuItem.Icon>
@@ -51,7 +81,7 @@
<Separator />
- <MenuItem Header="Copy">
+ <MenuItem Header="Copy" IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Copy.png" Stretch="None" />
</MenuItem.Icon>
@@ -69,19 +99,19 @@
</MenuItem>
</MenuItem>
- <MenuItem Header="Delete..." InputGestureText="Delete">
+ <MenuItem x:Name="Delete" Header="Delete..." InputGestureText="Delete" Command="{Binding PlacementTarget.Tag.DeleteFileCommand, RelativeSource={RelativeSource AncestorType=ContextMenu}}">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Delete.png" Stretch="None" />
</MenuItem.Icon>
</MenuItem>
- <MenuItem Header="Edit...">
+ <MenuItem Header="Edit..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Edit.png" Stretch="None" />
</MenuItem.Icon>
</MenuItem>
- <MenuItem Header="Rename...">
+ <MenuItem Header="Rename..." IsEnabled="False">
<MenuItem.Icon>
<Image Source="../Resources/Icons/Rename.png" Stretch="None" />
</MenuItem.Icon>
View
26 UserControls/StatusGridContextMenu.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Windows;
using System.Collections;
using System.Linq;
@@ -26,6 +27,15 @@ public StatusGridContextMenu()
/// <param name="e"></param>
private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
{
+ HandleStageUnstageMenuItems();
+ HandleDeleteMenuItem();
+ }
+
+ /// <summary>
+ /// Shows and hides Stage and Unstage menu items accordingly to what has been selected.
+ /// </summary>
+ private void HandleStageUnstageMenuItems()
+ {
MenuItem stage = UIHelper.FindChild<MenuItem>(this, "Stage");
MenuItem unstage = UIHelper.FindChild<MenuItem>(this, "Unstage");
Separator stageSeparator = UIHelper.FindChild<Separator>(this, "StageSeparator");
@@ -50,5 +60,19 @@ private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
stageSeparator.Visibility = Visibility.Visible;
}
}
+
+ /// <summary>
+ /// Handles the disabling/enabling of the Delete menu item.
+ /// </summary>
+ private void HandleDeleteMenuItem()
+ {
+ MenuItem delete = UIHelper.FindChild<MenuItem>(this, "Delete");
+ DataGrid statusGrid = PlacementTarget as DataGrid;
+ string repositoryFullPath = ((RepositoryViewModel) statusGrid.DataContext).RepositoryFullPath;
+
+ bool hasPhysicallyExistingFiles = statusGrid.SelectedItems.OfType<StatusItem>().Any(i => File.Exists(repositoryFullPath + "/" + ((StatusItem) i).Filename));
+
+ delete.Visibility = hasPhysicallyExistingFiles ? Visibility.Visible : Visibility.Collapsed;
+ }
}
-}
+}
View
4 ViewModels/MainWindowViewModel.cs
@@ -26,10 +26,10 @@ public void Load()
// C:/Program Files (x86)/node
// Add some test repositories.
- RepositoryViewModel repo = new RepositoryViewModel { Name = "Git test repository", FullPath = "Z:/www/test-repo" };
+ RepositoryViewModel repo = new RepositoryViewModel { Name = "Git test repository", RepositoryFullPath = "Z:/www/test-repo" };
repo.Load();
- RepositoryViewModel repo2 = new RepositoryViewModel { Name = "New tab", FullPath = null, NotOpened = true };
+ RepositoryViewModel repo2 = new RepositoryViewModel { Name = "New tab", RepositoryFullPath = null, NotOpened = true };
repo2.Load();
RepositoryViewModels.Add(repo);
View
86 ViewModels/RepositoryViewModel.cs
@@ -18,7 +18,7 @@ namespace GG
public class RepositoryViewModel : BaseViewModel
{
public string Name { get; set; }
- public string FullPath { get; set; }
+ public string RepositoryFullPath { get; set; }
public bool NotOpened { get; set; }
public RangedObservableCollection<Commit> Commits { get; set; }
@@ -39,15 +39,6 @@ public class RepositoryViewModel : BaseViewModel
/// <param name="e"></param>
delegate void ReloadStatusDelegate(object sender, FileSystemEventArgs e);
- /// <summary>
- /// Commands.
- /// </summary>
- #region Commands
-
- public DelegateCommand StageUnstageCommand { get; private set; } // TODO
-
- #endregion
-
public RepositoryViewModel()
{
// Initialize empty collections.
@@ -68,9 +59,18 @@ public RepositoryViewModel()
// Initialize commands.
StageUnstageCommand = new DelegateCommand(StageUnstage);
+ DeleteFileCommand = new DelegateCommand(DeleteFile);
}
/// <summary>
+ /// Commands.
+ /// </summary>
+ #region Commands.
+
+ public DelegateCommand StageUnstageCommand { get; private set; }
+ public DelegateCommand DeleteFileCommand { get; private set; }
+
+ /// <summary>
/// Stages or unstages the selected item.
/// </summary>
/// <param name="action"></param>
@@ -79,19 +79,55 @@ private void StageUnstage(object action)
DataGrid statusGrid = UIHelper.FindChild<DataGrid>(Application.Current.MainWindow, "StatusGridElement");
StatusItem item = statusGrid.SelectedItem as StatusItem;
- LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(FullPath);
+ LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(RepositoryFullPath);
if (item.GenericStatus == "Staged")
- repo.Index.Unstage(FullPath + "/" + item.Filename);
+ repo.Index.Unstage(RepositoryFullPath + "/" + item.Filename);
else
- repo.Index.Stage(FullPath + "/" + item.Filename);
+ repo.Index.Stage(RepositoryFullPath + "/" + item.Filename);
+ }
+
+ /// <summary>
+ /// Deletes a file or many.
+ /// </summary>
+ /// <param name="action"></param>
+ private void DeleteFile(object action)
+ {
+ LibGit2Sharp.Repository repo = null;
+ DataGrid statusGrid = UIHelper.FindChild<DataGrid>(Application.Current.MainWindow, "StatusGridElement");
+
+ // Loop through all selected status items and remove the files physically (and in some cases also from the repository).
+ foreach (StatusItem item in statusGrid.SelectedItems)
+ {
+ // TODO: --cached ?
+
+ File.Delete(RepositoryFullPath + "/" + item.Filename);
+
+ if (!item.Status.HasFlag(LibGit2Sharp.FileStatus.Untracked))
+ {
+ if (!(repo is LibGit2Sharp.Repository))
+ repo = new LibGit2Sharp.Repository(RepositoryFullPath);
+
+ repo.Index.Stage(RepositoryFullPath + "/" + item.Filename);
+ }
+ }
+
+ if (repo is LibGit2Sharp.Repository)
+ repo.Dispose();
}
+ #endregion
+
+ #region Loading and construction.
+
+ /// <summary>
+ /// A method that loads the entire repository.
+ /// </summary>
public void Load()
{
if (NotOpened == false)
{
- Console.WriteLine("Loading and constructing repository data for \"" + FullPath + "\".");
+ Console.WriteLine("Loading and constructing repository data for \"" + RepositoryFullPath + "\".");
ConstructRepository();
LoadRepositoryStatus();
@@ -107,10 +143,10 @@ public void Load()
/// </summary>
private void ConstructRepository()
{
- LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(FullPath);
+ LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(RepositoryFullPath);
// Create tags.
- Console.WriteLine("Constructs repository tags for \"" + FullPath + "\".");
+ Console.WriteLine("Constructs repository tags for \"" + RepositoryFullPath + "\".");
foreach (LibGit2Sharp.Tag tag in repo.Tags)
{
Tag t = Tag.Create(repo, tag);
@@ -120,7 +156,7 @@ private void ConstructRepository()
}
// Create commits.
- Console.WriteLine("Constructs repository commits for \"" + FullPath + "\".");
+ Console.WriteLine("Constructs repository commits for \"" + RepositoryFullPath + "\".");
List<Commit> commitList = new List<Commit>();
foreach (LibGit2Sharp.Commit commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = repo.Refs }).Take(CommitsPerPage))
{
@@ -129,7 +165,7 @@ private void ConstructRepository()
Commits.AddRange(commitList);
// Create branches.
- Console.WriteLine("Constructs repository branches for \"" + FullPath + "\".");
+ Console.WriteLine("Constructs repository branches for \"" + RepositoryFullPath + "\".");
foreach (LibGit2Sharp.Branch branch in repo.Branches)
{
Branch b = Branch.Create(repo, branch, Commits, CommitsPerPage);
@@ -137,14 +173,14 @@ private void ConstructRepository()
}
// Post-process branches (tips and tracking branches).
- Console.WriteLine("Post-processing repository branches for \"" + FullPath + "\".");
+ Console.WriteLine("Post-processing repository branches for \"" + RepositoryFullPath + "\".");
foreach (Branch branch in Branches)
{
branch.PostProcess(Branches, Commits);
}
// Post-process commits (commit parents).
- Console.WriteLine("Post-processing repository commits for \"" + FullPath + "\".");
+ Console.WriteLine("Post-processing repository commits for \"" + RepositoryFullPath + "\".");
foreach (Commit commit in Commits)
{
commit.PostProcess(Commits, Branches);
@@ -158,9 +194,9 @@ private void ConstructRepository()
/// </summary>
private void LoadRepositoryStatus()
{
- Console.WriteLine("Loading status data for \"" + FullPath + "\".");
+ Console.WriteLine("Loading status data for \"" + RepositoryFullPath + "\".");
- LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(FullPath);
+ LibGit2Sharp.Repository repo = new LibGit2Sharp.Repository(RepositoryFullPath);
StatusItems.Clear();
@@ -177,7 +213,7 @@ private void LoadRepositoryStatus()
if (isSet == false || value.ToString() == "Unaltered" || value.ToString() == "Ignored")
continue;
- string fileFullPath = FullPath + "/" + fileStatus.FilePath;
+ string fileFullPath = RepositoryFullPath + "/" + fileStatus.FilePath;
// Only those enum statuses that were set will generate a row in the status grid (and those that are not ignored/unaltered).
StatusItem item = new StatusItem
@@ -197,6 +233,8 @@ private void LoadRepositoryStatus()
repo.Dispose();
}
+#endregion
+
/// <summary>
/// Refresh some data when the repository directory changes.
/// </summary>
@@ -219,7 +257,7 @@ private void ListenToDirectoryChanges()
watcher.Deleted += new FileSystemEventHandler(reloadStatusDelegate);
watcher.Renamed += new RenamedEventHandler(reloadStatusDelegate);
watcher.Created += new FileSystemEventHandler(reloadStatusDelegate);
- watcher.Path = FullPath;
+ watcher.Path = RepositoryFullPath;
watcher.EnableRaisingEvents = true;
}
}

0 comments on commit b59b3bd

Please sign in to comment.
Something went wrong with that request. Please try again.