#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 lines
2.5 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project;
using System.Windows.Forms;
namespace ICSharpCode.GitAddIn
{
public class RegisterEventsCommand : AbstractCommand
{
public override void Run()
{
FileService.FileCreated += (sender, e) => {
AddFile(e.FileName);
};
FileService.FileCopied += (sender, e) => {
AddFile(e.TargetFile);
};
FileService.FileRemoved += (sender, e) => {
RemoveFile(e.FileName);
};
FileService.FileRenamed += (sender, e) => {
RenameFile(e.SourceFile, e.TargetFile);
};
FileUtility.FileSaved += (sender, e) => {
ClearStatusCacheAndEnqueueFile(e.FileName);
};
AbstractProjectBrowserTreeNode.OnNewNode += TreeNodeCreated;
}
void AddFile(string fileName)
{
Git.Add(fileName,
exitcode => SD.MainThread.InvokeAsync(() => ClearStatusCacheAndEnqueueFile(fileName)).FireAndForget()
);
}
void RemoveFile(string fileName)
{
if (GitStatusCache.GetFileStatus(fileName) == GitStatus.Added) {
Git.Remove(fileName, true,
exitcode => SD.MainThread.InvokeAsync(() => ClearStatusCacheAndEnqueueFile(fileName)).FireAndForget());
}
}
void RenameFile(string sourceFileName, string targetFileName)
{
Git.Add(targetFileName,
exitcode => SD.MainThread.InvokeAsync(() => RemoveFile(sourceFileName)).FireAndForget()
);
SD.MainThread.InvokeAsync(() => ClearStatusCacheAndEnqueueFile(targetFileName)).FireAndForget();
}
void TreeNodeCreated(object sender, TreeViewEventArgs e)
{
SolutionNode sn = e.Node as SolutionNode;
if (sn != null) {
GitStatusCache.ClearCachedStatus(sn.Solution.FileName);
OverlayIconManager.Enqueue(sn);
} else {
DirectoryNode dn = e.Node as DirectoryNode;
if (dn != null) {
OverlayIconManager.Enqueue(dn);
} else {
FileNode fn = e.Node as FileNode;
if (fn != null) {
OverlayIconManager.Enqueue(fn);
}
}
}
}
void ClearStatusCacheAndEnqueueFile(string fileName)
{
GitStatusCache.ClearCachedStatus(fileName);
ProjectBrowserPad pad = ProjectBrowserPad.Instance;
if (pad == null) return;
FileNode node = pad.ProjectBrowserControl.FindFileNode(fileName);
if (node == null) return;
OverlayIconManager.EnqueueParents(node);
}
}
}