~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlFileSystemExtension.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
using MonoDevelop.Core.ProgressMonitoring;
5
5
using MonoDevelop.Core.FileSystem;
6
6
using MonoDevelop.Ide;
 
7
using System.Collections.Generic;
 
8
using System.Linq;
7
9
 
8
10
namespace MonoDevelop.VersionControl
9
11
{
10
12
        internal class VersionControlFileSystemExtension: FileSystemExtension
11
13
        {
12
 
                public override bool CanHandlePath (string path, bool isDirectory)
 
14
                public override bool CanHandlePath (FilePath path, bool isDirectory)
13
15
                {
14
16
                        // FIXME: don't load this extension if the ide is not loaded.
15
17
                        if (IdeApp.ProjectOperations == null || !IdeApp.Workspace.IsOpen)
18
20
                                return GetRepository (path) != null;
19
21
                }
20
22
                
21
 
                Repository GetRepository (string path)
 
23
                Repository GetRepository (FilePath path)
22
24
                {
23
 
                        // FIXME: Optimize
 
25
                        path = path.FullPath;
 
26
                        
 
27
                        Project p = IdeApp.Workspace.GetProjectContainingFile (path);
 
28
                        if (p != null)
 
29
                                return VersionControlService.GetRepository (p);
 
30
                        
24
31
                        foreach (Project prj in IdeApp.Workspace.GetAllProjects ()) {
25
 
                                if (path.StartsWith (prj.BaseDirectory)) {
 
32
                                if (path == prj.BaseDirectory || path.IsChildPathOf (prj.BaseDirectory))
26
33
                                        return VersionControlService.GetRepository (prj);
27
 
                                }
28
34
                        }
29
35
                        return null;
30
36
                }
31
37
                
32
 
                public override void CopyFile (string source, string dest, bool overwrite)
 
38
                public override void CopyFile (FilePath source, FilePath dest, bool overwrite)
33
39
                {
34
40
                        Repository repo = GetRepository (dest);
35
41
                        if (repo.RequestFileWritePermission (dest)) {
40
46
                                throw new System.IO.IOException ("Write permission denied");
41
47
                }
42
48
                
43
 
                public override void MoveFile (string source, string dest)
 
49
                public override void MoveFile (FilePath source, FilePath dest)
44
50
                {
45
51
                        IProgressMonitor monitor = new NullProgressMonitor ();
46
52
                        
55
61
                        }
56
62
                }
57
63
                
58
 
                public override void DeleteFile (string file)
 
64
                public override void DeleteFile (FilePath file)
59
65
                {
60
66
                        Repository repo = GetRepository (file);
61
67
                        repo.DeleteFile (file, true, new NullProgressMonitor ());
62
68
                }
63
69
                
64
 
                public override void CreateDirectory (string path)
 
70
                public override void CreateDirectory (FilePath path)
65
71
                {
66
72
                        Repository repo = GetRepository (path);
67
73
                        repo.CreateLocalDirectory (path);
68
74
                }
69
75
                
70
 
                public override void MoveDirectory (string sourcePath, string destPath)
 
76
                public override void MoveDirectory (FilePath sourcePath, FilePath destPath)
71
77
                {
72
78
                        IProgressMonitor monitor = new NullProgressMonitor ();
73
79
                        
82
88
                        }
83
89
                }
84
90
                
85
 
                public override void DeleteDirectory (string path)
 
91
                public override void DeleteDirectory (FilePath path)
86
92
                {
87
93
                        Repository repo = GetRepository (path);
88
94
                        repo.DeleteDirectory (path, true, new NullProgressMonitor ());
89
95
                }
90
96
                
91
 
                public override bool RequestFileEdit (string file)
 
97
                public override bool RequestFileEdit (FilePath file)
92
98
                {
93
99
                        Repository repo = GetRepository (file);
94
100
                        return repo.RequestFileWritePermission (file);
95
101
                }
96
102
                
97
 
                public override void NotifyFileChanged (string file)
 
103
                public override void NotifyFilesChanged (IEnumerable<FilePath> files)
98
104
                {
99
 
                        Repository repo = GetRepository (file);
100
 
                        VersionControlService.NotifyFileStatusChanged (repo, file, false);
 
105
                        FileUpdateEventArgs args = new FileUpdateEventArgs ();
 
106
                        args.AddRange (files.Select (f => new FileUpdateEventInfo (GetRepository (f), f, false)));
 
107
                        VersionControlService.NotifyFileStatusChanged (args);
101
108
                }
102
109
        }
103
110
}