~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/VersionControl/SubversionAddIn/Src/Gui/SvnGuiWrapper.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Diagnostics;
 
6
using System.Text;
 
7
using System.Windows.Forms;
 
8
using ICSharpCode.Core;
 
9
using ICSharpCode.SharpDevelop.Gui;
 
10
using Microsoft.Win32;
 
11
 
 
12
namespace ICSharpCode.Svn
 
13
{
 
14
        /// <summary>
 
15
        /// Wraps commands opening a dialog window.
 
16
        /// The current implementation launches TortoiseSVN.
 
17
        /// </summary>
 
18
        public static class SvnGuiWrapper
 
19
        {
 
20
                static string GetPathFromRegistry(RegistryHive hive, string valueName)
 
21
                {
 
22
                        RegistryView view = Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default;
 
23
                        using (RegistryKey baseKey = RegistryKey.OpenBaseKey(hive, view)) {
 
24
                                using (RegistryKey key = baseKey.OpenSubKey("SOFTWARE\\TortoiseSVN")) {
 
25
                                        if (key != null)
 
26
                                                return key.GetValue(valueName) as string;
 
27
                                        else
 
28
                                                return null;
 
29
                                }
 
30
                        }
 
31
                }
 
32
                
 
33
                static string GetPathFromRegistry(string valueName)
 
34
                {
 
35
                        return GetPathFromRegistry(RegistryHive.CurrentUser, valueName)
 
36
                                ?? GetPathFromRegistry(RegistryHive.LocalMachine, valueName);
 
37
                }
 
38
                
 
39
                static void Proc(string command, string fileName, MethodInvoker callback)
 
40
                {
 
41
                        Proc(command, fileName, callback, null);
 
42
                }
 
43
                
 
44
                static void Proc(string command, string fileName, MethodInvoker callback, string argument)
 
45
                {
 
46
                        string path = GetPathFromRegistry("ProcPath");
 
47
                        if (path == null) {
 
48
                                using (TortoiseSvnNotFoundForm form = new TortoiseSvnNotFoundForm()) {
 
49
                                        form.ShowDialog(WorkbenchSingleton.MainWin32Window);
 
50
                                }
 
51
                        } else {
 
52
                                try {
 
53
                                        StringBuilder arguments = new StringBuilder();
 
54
                                        arguments.Append("/command:");
 
55
                                        arguments.Append(command);
 
56
                                        if (fileName != null) {
 
57
                                                arguments.Append(" /notempfile ");
 
58
                                                arguments.Append(" /path:\"");
 
59
                                                arguments.Append(fileName);
 
60
                                                arguments.Append('"');
 
61
                                        }
 
62
                                        if (argument != null) {
 
63
                                                arguments.Append(' ');
 
64
                                                arguments.Append(argument);
 
65
                                        }
 
66
                                        Process p = new Process();
 
67
                                        p.StartInfo.FileName = path;
 
68
                                        p.StartInfo.Arguments = arguments.ToString();
 
69
                                        //p.StartInfo.RedirectStandardError = true;
 
70
                                        //p.StartInfo.RedirectStandardOutput = true;
 
71
                                        p.StartInfo.UseShellExecute = false;
 
72
                                        p.EnableRaisingEvents = true;
 
73
                                        p.Exited += delegate {
 
74
                                                p.Dispose();
 
75
                                                if (callback != null) { callback(); }
 
76
                                        };
 
77
//                                      p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
 
78
//                                              SvnClient.Instance.SvnCategory.AppendText(e.Data);
 
79
//                                      };
 
80
//                                      p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
 
81
//                                              SvnClient.Instance.SvnCategory.AppendText(e.Data);
 
82
//                                      };
 
83
                                        p.Start();
 
84
                                } catch (Exception ex) {
 
85
                                        MessageService.ShowError(ex.Message);
 
86
                                }
 
87
                        }
 
88
                }
 
89
                
 
90
                public static void ShowCheckoutDialog(MethodInvoker callback)
 
91
                {
 
92
                        Proc("checkout", null, callback);
 
93
                }
 
94
                
 
95
                public static void ShowExportDialog(MethodInvoker callback)
 
96
                {
 
97
                        Proc("export", null, callback);
 
98
                }
 
99
                
 
100
                public static void Update(string fileName, MethodInvoker callback)
 
101
                {
 
102
                        Proc("update", fileName, callback);
 
103
                }
 
104
                
 
105
                public static void ApplyPatch(string fileName, MethodInvoker callback)
 
106
                {
 
107
                        //Proc("applypatch", fileName, callback);
 
108
                        // TODO: Applying patches is not implemented.
 
109
                        MessageService.ShowMessage("Applying patches is not implemented.");
 
110
                }
 
111
                
 
112
                public static void CreatePatch(string fileName, MethodInvoker callback)
 
113
                {
 
114
                        Proc("createpatch", fileName, callback);
 
115
                }
 
116
                
 
117
                public static void Revert(string fileName, MethodInvoker callback)
 
118
                {
 
119
                        Proc("revert", fileName, callback);
 
120
                }
 
121
                
 
122
                public static void Commit(string fileName, MethodInvoker callback)
 
123
                {
 
124
                        Proc("commit", fileName, callback);
 
125
                }
 
126
                
 
127
                public static void Add(string fileName, MethodInvoker callback)
 
128
                {
 
129
                        Proc("add", fileName, callback);
 
130
                }
 
131
                
 
132
                public static void Ignore(string fileName, MethodInvoker callback)
 
133
                {
 
134
                        Proc("ignore", fileName, callback);
 
135
                }
 
136
                
 
137
                public static void ShowSvnHelp()
 
138
                {
 
139
                        Proc("help", null, null);
 
140
                }
 
141
                
 
142
                public static void ShowSvnSettings()
 
143
                {
 
144
                        Proc("settings", null, null);
 
145
                }
 
146
                
 
147
                public static void ShowSvnAbout()
 
148
                {
 
149
                        Proc("about", null, null);
 
150
                }
 
151
                
 
152
                public static void Diff(string fileName, MethodInvoker callback)
 
153
                {
 
154
                        Proc("diff", fileName, callback);
 
155
                }
 
156
                
 
157
                public static void ConflictEditor(string fileName, MethodInvoker callback)
 
158
                {
 
159
                        Proc("conflicteditor", fileName, callback);
 
160
                }
 
161
                
 
162
                public static void ResolveConflict(string fileName, MethodInvoker callback)
 
163
                {
 
164
                        Proc("resolve", fileName, callback);
 
165
                }
 
166
                
 
167
                public static void ShowLog(string fileName, MethodInvoker callback)
 
168
                {
 
169
                        Proc("log", fileName, callback);
 
170
                }
 
171
                
 
172
                public static void Cleanup(string fileName, MethodInvoker callback)
 
173
                {
 
174
                        Proc("cleanup", fileName, callback);
 
175
                }
 
176
                
 
177
                public static void RevisionGraph(string fileName, MethodInvoker callback)
 
178
                {
 
179
                        Proc("revisiongraph", fileName, callback);
 
180
                }
 
181
                
 
182
                public static void RepoStatus(string fileName, MethodInvoker callback)
 
183
                {
 
184
                        Proc("repostatus", fileName, callback);
 
185
                }
 
186
                
 
187
                public static void RepoBrowser(string fileName, MethodInvoker callback)
 
188
                {
 
189
                        Proc("repobrowser", fileName, callback);
 
190
                }
 
191
                
 
192
                public static void UpdateToRevision(string fileName, MethodInvoker callback)
 
193
                {
 
194
                        Proc("update", fileName, callback, "/rev");
 
195
                }
 
196
                
 
197
                public static void Export(string fileName, MethodInvoker callback)
 
198
                {
 
199
                        Proc("export", fileName, callback);
 
200
                }
 
201
                
 
202
                public static void Branch(string fileName, MethodInvoker callback)
 
203
                {
 
204
                        Proc("copy", fileName, callback);
 
205
                }
 
206
                
 
207
                public static void Lock(string fileName, MethodInvoker callback)
 
208
                {
 
209
                        Proc("lock", fileName, callback);
 
210
                }
 
211
                
 
212
                public static void Blame(string fileName, MethodInvoker callback)
 
213
                {
 
214
                        Proc("blame", fileName, callback);
 
215
                }
 
216
                
 
217
                public static void Switch(string fileName, MethodInvoker callback)
 
218
                {
 
219
                        Proc("switch", fileName, callback);
 
220
                }
 
221
                
 
222
                public static void Merge(string fileName, MethodInvoker callback)
 
223
                {
 
224
                        Proc("merge", fileName, callback);
 
225
                }
 
226
                
 
227
                public static void Relocate(string fileName, MethodInvoker callback)
 
228
                {
 
229
                        Proc("relocate", fileName, callback);
 
230
                }
 
231
        }
 
232
}