Repository navigation
Expand file tree
/
Copy pathFileService.cs
More file actions
252 lines (225 loc) · 9.41 KB
/
Copy pathFileService.cs
File metadata and controls
252 lines (225 loc) · 9.41 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
// 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Parser;
using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Workbench;
namespace ICSharpCode.SharpDevelop
{
// TODO make obsolete, exists only for compatiblity with 4.x
public static class FileService
{
/// <summary>
/// Checks if the path is valid <b>and shows a MessageBox if it is not valid</b>.
/// Do not use in non-UI methods.
/// </summary>
public static bool CheckFileName(string path)
{
return SD.FileService.CheckFileName(path);
}
/// <summary>
/// Checks that a single directory entry (file or subdirectory) name is valid
/// <b>and shows a MessageBox if it is not valid</b>.
/// </summary>
/// <param name="name">A single file name not the full path</param>
public static bool CheckDirectoryEntryName(string name)
{
return SD.FileService.CheckDirectoryEntryName(name);
}
public static bool IsOpen(string fileName)
{
return SD.FileService.IsOpen(FileName.Create(fileName));
}
/// <summary>
/// Opens a view content for the specified file and switches to the opened view
/// or switches to and returns the existing view content for the file if it is already open.
/// </summary>
/// <param name="fileName">The name of the file to open.</param>
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
public static IViewContent OpenFile(string fileName)
{
return SD.FileService.OpenFile(FileName.Create(fileName));
}
/// <summary>
/// Opens a view content for the specified file
/// or returns the existing view content for the file if it is already open.
/// </summary>
/// <param name="fileName">The name of the file to open.</param>
/// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
/// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
public static IViewContent OpenFile(string fileName, bool switchToOpenedView)
{
return SD.FileService.OpenFile(FileName.Create(fileName), switchToOpenedView);
}
/// <summary>
/// Opens a new unsaved file.
/// </summary>
/// <param name="defaultName">The (unsaved) name of the to open</param>
/// <param name="content">Content of the file to create</param>
public static IViewContent NewFile(string defaultName, string content)
{
return SD.FileService.NewFile(defaultName, content);
}
/// <summary>
/// Opens a new unsaved file.
/// </summary>
/// <param name="defaultName">The (unsaved) name of the to open</param>
/// <param name="content">Content of the file to create</param>
public static IViewContent NewFile(string defaultName, byte[] content)
{
return SD.FileService.NewFile(defaultName, content);
}
/// <summary>
/// Gets a list of the names of the files that are open as primary files
/// in view contents.
/// </summary>
public static IList<FileName> GetOpenFiles()
{
return SD.FileService.OpenPrimaryFiles.ToArray();
}
/// <summary>
/// Gets the IViewContent for a fileName. Returns null if the file is not opened currently.
/// </summary>
public static IViewContent GetOpenFile(string fileName)
{
return SD.FileService.GetOpenFile(FileName.Create(fileName));
}
/// <summary>
/// Removes a file, raising the appropriate events. This method may show message boxes.
/// </summary>
public static void RemoveFile(string fileName, bool isDirectory)
{
SD.FileService.RemoveFile(fileName, isDirectory);
}
/// <summary>
/// Renames or moves a file, raising the appropriate events. This method may show message boxes.
/// </summary>
public static bool RenameFile(string oldName, string newName, bool isDirectory)
{
return SD.FileService.RenameFile(oldName, newName, isDirectory);
}
/// <summary>
/// Copies a file, raising the appropriate events. This method may show message boxes.
/// </summary>
public static bool CopyFile(string oldName, string newName, bool isDirectory, bool overwrite)
{
return SD.FileService.CopyFile(oldName, newName, isDirectory, overwrite);
}
/// <summary>
/// Opens the specified file and jumps to the specified file position.
/// Line and column start counting at 1.
/// </summary>
public static IViewContent JumpToFilePosition(string fileName, int line, int column)
{
return SD.FileService.JumpToFilePosition(FileName.Create(fileName), line, column);
}
/// <summary>
/// Creates a FolderBrowserDialog that will initially select the
/// specified folder. If the folder does not exist then the default
/// behaviour of the FolderBrowserDialog is used where it selects the
/// desktop folder.
/// </summary>
[Obsolete("Use SD.FileService.BrowseForFolder() instead.")]
public static FolderBrowserDialog CreateFolderBrowserDialog(string description, string selectedPath = null)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = StringParser.Parse(description);
if (selectedPath != null && selectedPath.Length > 0 && Directory.Exists(selectedPath)) {
dialog.RootFolder = Environment.SpecialFolder.MyComputer;
dialog.SelectedPath = selectedPath;
}
return dialog;
}
#region Static event firing methods
/// <summary>
/// Fires the event handlers for a file being created.
/// </summary>
/// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param>
/// <param name="isDirectory">Set to true if this is a directory</param>
public static bool FireFileReplacing(string fileName, bool isDirectory)
{
return SD.FileService.FireFileReplacing(fileName, isDirectory);
}
/// <summary>
/// Fires the event handlers for a file being replaced.
/// </summary>
/// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param>
/// <param name="isDirectory">Set to true if this is a directory</param>
public static void FireFileReplaced(string fileName, bool isDirectory)
{
SD.FileService.FireFileReplaced(fileName, isDirectory);
}
/// <summary>
/// Fires the event handlers for a file being created.
/// </summary>
/// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param>
/// <param name="isDirectory">Set to true if this is a directory</param>
public static void FireFileCreated(string fileName, bool isDirectory)
{
SD.FileService.FireFileCreated(fileName, isDirectory);
}
#endregion Static event firing methods
#region Events
public static event EventHandler<FileRenamingEventArgs> FileRenaming {
add { SD.FileService.FileRenaming += value; }
remove { SD.FileService.FileRenaming -= value; }
}
public static event EventHandler<FileRenameEventArgs> FileRenamed {
add { SD.FileService.FileRenamed += value; }
remove { SD.FileService.FileRenamed -= value; }
}
public static event EventHandler<FileRenamingEventArgs> FileCopying {
add { SD.FileService.FileCopying += value; }
remove { SD.FileService.FileCopying -= value; }
}
public static event EventHandler<FileRenameEventArgs> FileCopied {
add { SD.FileService.FileCopied += value; }
remove { SD.FileService.FileCopied -= value; }
}
public static event EventHandler<FileCancelEventArgs> FileRemoving {
add { SD.FileService.FileRemoving += value; }
remove { SD.FileService.FileRemoving -= value; }
}
public static event EventHandler<FileEventArgs> FileRemoved {
add { SD.FileService.FileRemoved += value; }
remove { SD.FileService.FileRemoved -= value; }
}
public static event EventHandler<FileEventArgs> FileCreated {
add { SD.FileService.FileCreated += value; }
remove { SD.FileService.FileCreated -= value; }
}
public static event EventHandler<FileCancelEventArgs> FileReplacing {
add { SD.FileService.FileReplacing += value; }
remove { SD.FileService.FileReplacing -= value; }
}
public static event EventHandler<FileEventArgs> FileReplaced {
add { SD.FileService.FileReplaced += value; }
remove { SD.FileService.FileReplaced -= value; }
}
#endregion Events
}
}