35
35
using MonoDevelop.Ide.Commands;
36
36
using MonoDevelop.Ide.Gui;
37
37
using MonoDevelop.Components.Commands;
38
using MonoDevelop.Core.Gui;
39
38
using MonoDevelop.Core.Collections;
40
39
using MonoDevelop.Ide.Gui.Components;
42
42
namespace MonoDevelop.Ide.Gui.Pads.ProjectPad
54
54
public override string GetNodeName (ITreeNavigator thisNode, object dataObject)
56
return Path.GetFileName (((ProjectFile)dataObject).Name);
56
var file = (ProjectFile) dataObject;
57
return file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName;
59
60
public override void GetNodeAttributes (ITreeNavigator treeNavigator, object dataObject, ref NodeAttributes attributes)
73
74
ProjectFile file = (ProjectFile) dataObject;
75
label = Path.GetFileName (file.FilePath);
76
label = file.Link.IsNullOrEmpty ? file.FilePath.FileName : file.Link.FileName;
76
77
if (!File.Exists (file.FilePath)) {
77
78
label = "<span foreground='red'>" + label + "</span>";
80
81
icon = DesktopService.GetPixbufForFile (file.FilePath, Gtk.IconSize.Menu);
83
if (file.IsLink && icon != null) {
85
using (Gdk.Pixbuf overlay = Gdk.Pixbuf.LoadFromResource ("Icons.16x16.LinkOverlay.png")) {
86
overlay.Composite (icon,
88
icon.Width, icon.Width,
90
1, 1, Gdk.InterpType.Bilinear, 255);
83
95
public override object GetParentObject (object dataObject)
94
106
if (dir == file.Project.BaseDirectory)
95
107
return file.Project;
96
else if (file.IsExternalToProject)
97
return new LinkedFilesFolder (file.Project);
99
109
return new ProjectFolder (dir, file.Project, null);
130
140
public override void RenameItem (string newName)
132
142
ProjectFile file = (ProjectFile) CurrentNode.DataItem;
133
string oldPath = file.Name;
134
string newPath = Path.Combine (Path.GetDirectoryName (oldPath), newName);
144
FilePath oldPath, newPath, newLink = FilePath.Null, oldLink = FilePath.Null;
146
oldLink = file.ProjectVirtualPath;
147
newLink = oldLink.ParentDirectory.Combine (newName);
148
oldPath = file.Project.BaseDirectory.Combine (oldLink);
149
newPath = file.Project.BaseDirectory.Combine (newLink);
152
newPath = oldPath.ParentDirectory.Combine (newName);
136
155
if (oldPath != newPath) {
138
157
if (!FileService.IsValidPath (newPath)) {
139
158
MessageService.ShowWarning (GettextCatalog.GetString ("The name you have chosen contains illegal characters. Please choose a different name."));
140
} else if (File.Exists (newPath) || Directory.Exists (newPath)) {
159
} else if (File.Exists (newPath) || Directory.Exists (newPath) ||
160
(file.Project != null && file.Project.Files.GetFileWithVirtualPath (newPath.ToRelative (file.Project.BaseDirectory)) != null)) {
141
161
MessageService.ShowWarning (GettextCatalog.GetString ("File or directory name is already in use. Please choose a different one."));
143
FileService.RenameFile (oldPath, newName);
166
FileService.RenameFile (oldPath, newName);
144
168
if (file.Project != null)
145
169
IdeApp.ProjectOperations.Save (file.Project);
225
249
foreach (ProjectFile file in files) {
226
250
Project project = file.Project;
227
if (!file.IsExternalToProject) {
228
ProjectFile[] inFolder = project.Files.GetFilesInPath (Path.GetDirectoryName (file.Name));
229
if (inFolder.Length == 1 && inFolder [0] == file) {
230
// This is the last project file in the folder. Make sure we keep
231
// a reference to the folder, so it is not deleted from the tree.
232
ProjectFile folderFile = new ProjectFile (Path.GetDirectoryName (file.Name));
233
folderFile.Subtype = Subtype.Directory;
234
project.Files.Add (folderFile);
251
var inFolder = project.Files.GetFilesInVirtualPath (file.ProjectVirtualPath.ParentDirectory).ToList ();
252
if (inFolder.Count == 1 && inFolder [0] == file) {
253
// This is the last project file in the folder. Make sure we keep
254
// a reference to the folder, so it is not deleted from the tree.
255
ProjectFile folderFile = new ProjectFile (project.BaseDirectory.Combine (file.ProjectVirtualPath.ParentDirectory));
256
folderFile.Subtype = Subtype.Directory;
257
project.Files.Add (folderFile);
238
260
if (file.HasChildren) {