This repository was archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 808
Expand file tree
/
Copy pathSubversionStateCondition.cs
More file actions
122 lines (118 loc) · 4.45 KB
/
Copy pathSubversionStateCondition.cs
File metadata and controls
122 lines (118 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.Svn.Commands;
using SharpSvn;
namespace ICSharpCode.Svn
{
/// <summary>
/// Gets if a folder is under version control
/// </summary>
public class SubversionIsControlledCondition : IConditionEvaluator
{
public bool IsValid(object caller, Condition condition)
{
FileNode node = ProjectBrowserPad.Instance.SelectedNode as FileNode;
if (node != null) {
return RegisterEventsCommand.CanBeVersionControlledFile(node.FileName);
}
DirectoryNode dir = ProjectBrowserPad.Instance.SelectedNode as DirectoryNode;
if (dir != null) {
return Commands.RegisterEventsCommand.CanBeVersionControlledDirectory(dir.Directory);
}
SolutionNode sol = ProjectBrowserPad.Instance.SelectedNode as SolutionNode;
if (sol != null) {
return Commands.RegisterEventsCommand.CanBeVersionControlledDirectory(sol.Solution.Directory);
}
return false;
}
}
public class SubversionStateCondition : IConditionEvaluator
{
public bool IsValid(object caller, Condition condition)
{
FileNode node = ProjectBrowserPad.Instance.SelectedNode as FileNode;
if (node != null) {
if (condition.Properties["item"] == "Folder") {
return false;
}
return Test(condition, node.FileName, false);
}
DirectoryNode dir = ProjectBrowserPad.Instance.SelectedNode as DirectoryNode;
if (dir != null) {
if (condition.Properties["item"] == "File") {
return false;
}
if (condition.Properties["state"].Contains("Modified")) {
// Directories are not checked recursively yet.
return true;
}
return Test(condition, dir.Directory, true);
}
SolutionNode sol = ProjectBrowserPad.Instance.SelectedNode as SolutionNode;
if (sol != null) {
if (condition.Properties["item"] == "File") {
return false;
}
if (condition.Properties["state"].Contains("Modified")) {
// Directories are not checked recursively yet.
return true;
}
return Test(condition, sol.Solution.Directory, true);
}
return false;
}
bool Test(Condition condition, string fileName, bool isDirectory)
{
string[] allowedStatus = condition.Properties["state"].Split(';');
if (allowedStatus.Length == 0 || (allowedStatus.Length == 1 && allowedStatus[0].Length == 0)) {
return true;
}
string status;
if (isDirectory ? RegisterEventsCommand.CanBeVersionControlledDirectory(fileName)
: RegisterEventsCommand.CanBeVersionControlledFile(fileName))
{
status = OverlayIconManager.GetStatus(fileName).ToString();
} else {
status = "Unversioned";
}
/*if (status == "Unversioned") {
PropertyDictionary pd = SvnClient.Instance.Client.PropGet("svn:ignore", Path.GetDirectoryName(fileName), Revision.Working, Recurse.None);
if (pd != null) {
string shortFileName = Path.GetFileName(fileName);
foreach (Property p in pd.Values) {
using (StreamReader r = new StreamReader(new MemoryStream(p.Data))) {
string line;
while ((line = r.ReadLine()) != null) {
if (string.Equals(line, shortFileName, StringComparison.OrdinalIgnoreCase)) {
status = "Ignored";
break;
}
}
}
}
}
}*/
//LoggingService.Debug("Status of " + fileName + " is " + status);
return Array.IndexOf(allowedStatus, status) >= 0;
}
}
}