void AddFile (ProjectFile file, Project project) { ITreeBuilder tb = Context.GetTreeBuilder (); if (file.DependsOnFile != null) { if (!tb.MoveToObject (file.DependsOnFile)) { // The parent is not in the tree. Add it now, and it will add this file as a child. AddFile (file.DependsOnFile, project); } else tb.AddChild (file); return; } object data; if (file.Subtype == Subtype.Directory) data = new ProjectFolder (file.Name, project); else data = file; // Already there? if (tb.MoveToObject (data)) return; string filePath = file.IsLink ? project.BaseDirectory.Combine (file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; tb = GetFolder (project, filePath); if (tb != null) tb.AddChild (data); }
void AddFile(string fileName) { ITreeBuilder builder = Context.GetTreeBuilder(); string filePath = Path.GetDirectoryName(fileName); var file = new SystemFile(fileName, null, false); // Already there? if (builder.MoveToObject(file)) { return; } var folder = new WorkspaceFolder(filePath); if (builder.MoveToObject(folder) || MoveToWorkspace(builder, filePath)) { if (builder.Filled) { builder.AddChild(file); } } else { // Make sure there is a path to that folder EnsureReachable(fileName); } }
void RemoveFile (ProjectFile file, Project project) { ITreeBuilder tb = Context.GetTreeBuilder (); if (file.Subtype == Subtype.Directory) { if (!tb.MoveToObject (new ProjectFolder (file.Name, project))) return; tb.MoveToParent (); tb.UpdateAll (); return; } else { if (tb.MoveToObject (file)) { tb.Remove (true); } else { // We can't use IsExternalToProject here since the ProjectFile has // already been removed from the project string parentPath = file.IsLink ? project.BaseDirectory.Combine (file.Link.IsNullOrEmpty? file.FilePath.FileName : file.Link.ToString ()).ParentDirectory : file.FilePath.ParentDirectory; if (!tb.MoveToObject (new ProjectFolder (parentPath, project))) return; } } while (tb.DataItem is ProjectFolder) { ProjectFolder f = (ProjectFolder) tb.DataItem; if (!Directory.Exists (f.Path) && !project.Files.GetFilesInVirtualPath (f.Path.ToRelative (project.BaseDirectory)).Any ()) tb.Remove (true); else break; } }
ITreeBuilder GetFolder(Project project, FilePath filePath) { ITreeBuilder tb = Context.GetTreeBuilder(); if (filePath != project.BaseDirectory) { if (tb.MoveToObject(new ProjectFolder(filePath, project))) { return(tb); } else { // Make sure there is a path to that folder tb = FindParentFolderNode(filePath, project); if (tb != null) { tb.UpdateChildren(); return(null); } } } else { if (tb.MoveToObject(project)) { return(tb); } } return(null); }
void OnSystemFileDeleted(object sender, FileEventArgs args) { if (Context.Tree.IsDestroyed) { return; } foreach (FileEventInfo e in args) { try { Project project = GetProjectForFile(e.FileName); ITreeBuilder tb = Context.GetTreeBuilder(); if (e.IsDirectory) { if (tb.MoveToObject(new ProjectFolder(e.FileName, project))) { if (tb.Options ["ShowAllFiles"] && (project == null || !ProjectFolderCommandHandler.PathExistsInProject(project, e.FileName))) { tb.Remove(); return; } } } else { if (tb.MoveToObject(new SystemFile(e.FileName, project))) { tb.Remove(); return; } } // Find the parent folder, and update it's children count string parentPath = Path.GetDirectoryName(e.FileName); if (tb.MoveToObject(new ProjectFolder(parentPath, project))) { if (tb.Options ["ShowAllFiles"] && Directory.Exists(parentPath)) { tb.UpdateChildren(); } } } catch (Exception ex) { LoggingService.LogInternalError($"Error while updating project tree in OnSystemFileDeleted : {string.Join (", ", args.Select (x => x.FileName))}.", ex); } } }
private void OnConnectionRemoved(object sender, DatabaseConnectionContextEventArgs args) { if (builder.MoveToObject(args.ConnectionContext)) { builder.Remove(); builder.MoveToParent(); } }
void OnSystemFileDeleted(object sender, FileEventArgs args) { foreach (FileEventInfo e in args) { Project project = GetProjectForFile(e.FileName); if (project == null) { return; } ITreeBuilder tb = Context.GetTreeBuilder(); if (e.IsDirectory) { if (tb.MoveToObject(new ProjectFolder(e.FileName, project))) { if (tb.Options ["ShowAllFiles"] && !ProjectFolderCommandHandler.PathExistsInProject(project, e.FileName)) { tb.Remove(); return; } } } else { if (tb.MoveToObject(new SystemFile(e.FileName, project))) { tb.Remove(); return; } } // Find the parent folder, and update it's children count string parentPath = Path.GetDirectoryName(e.FileName); if (tb.MoveToObject(new ProjectFolder(parentPath, project))) { if (tb.Options ["ShowAllFiles"] && Directory.Exists(parentPath)) { tb.UpdateChildren(); } } } }
void AddClass(Project project, IType cls) { ITreeBuilder builder = Context.GetTreeBuilder(); if (!builder.MoveToObject(project)) { return; // The project is not there or may not yet be expanded } if (cls.Namespace == "") { builder.AddChild(new ClassData(project, cls)); } else { if (builder.Options ["NestedNamespaces"]) { string[] nsparts = cls.Namespace.Split('.'); string ns = ""; foreach (string nsp in nsparts) { if (builder.Filled) { if (ns.Length > 0) { ns += "."; } ns += nsp; if (!builder.MoveToChild(nsp, typeof(NamespaceData))) { builder.AddChild(new ProjectNamespaceData(project, ns), true); break; } } else { break; } } builder.AddChild(new ClassData(project, cls)); } else { if (builder.MoveToChild(cls.Namespace, typeof(NamespaceData))) { builder.AddChild(new ClassData(project, cls)); } else { builder.AddChild(new ProjectNamespaceData(project, cls.Namespace)); } } } }
void OnFileRemoved(object sender, FileEventArgs e) { foreach (FileEventInfo info in e) { ITreeBuilder treeBuilder = Context.GetTreeBuilder(); if (treeBuilder.MoveToObject(new WorkspaceFolder(info.FileName))) { treeBuilder.Remove(); } } }
private void OnConnectionRemoved(object sender, DatabaseConnectionContextEventArgs args) { ITreeBuilder builder = Context.GetTreeBuilder(args.ConnectionContext); if (builder.MoveToObject(args.ConnectionContext)) { builder.Remove(); builder.MoveToParent(); builder.UpdateAll(); } }
void AddFile(string file, Project project) { if (!file.StartsWith(project.BaseDirectory)) { return; } ITreeBuilder tb = Context.GetTreeBuilder(); string filePath = Path.GetDirectoryName(file); object data = new SystemFile(file, project); // Already there? if (tb.MoveToObject(data)) { return; } if (filePath != project.BaseDirectory) { if (tb.MoveToObject(new ProjectFolder(filePath, project))) { if (tb.Filled && tb.Options ["ShowAllFiles"]) { tb.AddChild(data); } } else { // Make sure there is a path to that folder EnsureReachable(project, file); } } else { if (tb.MoveToObject(project) && tb.Options ["ShowAllFiles"]) { tb.AddChild(data); } } }
void OnSystemFileCreated(object sender, FileEventArgs args) { if (!args.Any(f => f.IsDirectory)) { return; } // When a folder is created, we need to refresh the parent if the folder was created externally. ITreeBuilder tb = Context.GetTreeBuilder(); var dirs = args.Where(d => d.IsDirectory).Select(d => d.FileName).ToArray(); foreach (var p in IdeApp.Workspace.GetAllProjects()) { foreach (var dir in dirs) { if (tb.MoveToObject(new ProjectFolder(dir, p))) { if (tb.MoveToParent()) { tb.UpdateAll(); } } else if (tb.MoveToObject(new ProjectFolder(dir.ParentDirectory, p))) { tb.UpdateAll(); } else if (dir.ParentDirectory == p.BaseDirectory) { if (tb.MoveToObject(p)) { tb.UpdateAll(); } } } } }
bool MoveToWorkspace(ITreeBuilder builder, FilePath directoryPath) { Workspace workspace = builder.GetParentDataItem <Workspace> (true); if (workspace == null) { return(false); } if (!builder.MoveToObject(workspace)) { return(false); } return(workspace.BaseDirectory == directoryPath.CanonicalPath.ParentDirectory); }
// void OnClassInformationChanged (object sender, TypeUpdateInformationEventArgs e) // { //// DateTime t = DateTime.Now; // Dictionary<object,bool> oldStatus = new Dictionary<object,bool> (); // List<string> namespacesToClean = new List<string> (); // ITreeBuilder tb = Context.GetTreeBuilder (); // // foreach (IType cls in e.TypeUpdateInformation.Removed) { // if (tb.MoveToObject (new ClassData (e.Project, cls))) { // oldStatus [tb.DataItem] = tb.Expanded; // // ITreeNavigator np = tb.Clone (); // np.MoveToParent (); // oldStatus [np.DataItem] = np.Expanded; // // tb.Remove (true); // } // namespacesToClean.Add (cls.Namespace); // } // // foreach (IType cls in e.TypeUpdateInformation.Modified) { // ClassData ucd = new ClassData (e.Project, cls); // if (tb.MoveToObject (ucd)) { // ClassData cd = (ClassData) tb.DataItem; // cd.UpdateFrom (ucd); // tb.UpdateAll (); // } // } // // foreach (IType cls in e.TypeUpdateInformation.Added) { // AddClass (e.Project, cls); // } // // // Clean empty namespaces // // foreach (string ns in namespacesToClean) { // string subns = ns; // while (subns != null) { // bool found = tb.MoveToObject (new ProjectNamespaceData (e.Project, subns)); // if (!found) found = tb.MoveToObject (new ProjectNamespaceData (null, subns)); // if (found) { // while (tb.DataItem is NamespaceData && !tb.HasChildren()) // tb.Remove (true); // break; // } // int i = subns.LastIndexOf ('.'); // if (i != -1) subns = subns.Substring (0,i); // else subns = null; // } // } // // // Restore expand status // // foreach (KeyValuePair<object,bool> de in oldStatus) { // if (de.Value && tb.MoveToObject (de.Key)) { // tb.ExpandToNode (); // tb.Expanded = true; // } // } // } void AddClass(Project project, ITypeDefinition cls) { ITreeBuilder builder = Context.GetTreeBuilder(); if (!builder.MoveToObject(project)) { return; // The project is not there or may not yet be expanded } if (cls.Namespace == "") { builder.AddChild(new ClassData(project, cls)); } else { // TODO: Type system conversion. /* if (builder.Options ["NestedNamespaces"]) { * string[] nsparts = cls.Namespace.Split ('.'); * string ns = ""; * foreach (string nsp in nsparts) { * if (builder.Filled) { * if (ns.Length > 0) ns += "."; * ns += nsp; * if (!builder.MoveToChild (nsp, typeof(NamespaceData))) { * builder.AddChild (new ProjectNamespaceData (project, ns), true); * break; * } * } else * break; * } * builder.AddChild (new ClassData (project, cls)); * } else { * if (builder.MoveToChild (cls.Namespace, typeof(NamespaceData))) * builder.AddChild (new ClassData (project, cls)); * else * builder.AddChild (new ProjectNamespaceData (project, cls.Namespace)); * }*/ } }
void OnSystemFileDeleted(object sender, FileEventArgs args) { if (!args.Any(f => f.IsDirectory)) { return; } // When a folder is deleted, we need to remove all references in the tree, for all projects ITreeBuilder tb = Context.GetTreeBuilder(); var dirs = args.Where(d => d.IsDirectory).Select(d => d.FileName).ToArray(); foreach (var p in IdeApp.Workspace.GetAllProjects()) { foreach (var dir in dirs) { if (tb.MoveToObject(new ProjectFolder(dir, p)) && tb.MoveToParent()) { tb.UpdateAll(); } } } }
void OnClassInformationChanged(object sender, TypeUpdateInformationEventArgs e) { // DateTime t = DateTime.Now; Dictionary <object, bool> oldStatus = new Dictionary <object, bool> (); List <string> namespacesToClean = new List <string> (); ITreeBuilder tb = Context.GetTreeBuilder(); foreach (IType cls in e.TypeUpdateInformation.Removed) { if (tb.MoveToObject(new ClassData(e.Project, cls))) { oldStatus [tb.DataItem] = tb.Expanded; ITreeNavigator np = tb.Clone(); np.MoveToParent(); oldStatus [np.DataItem] = np.Expanded; tb.Remove(true); } namespacesToClean.Add(cls.Namespace); } foreach (IType cls in e.TypeUpdateInformation.Modified) { ClassData ucd = new ClassData(e.Project, cls); if (tb.MoveToObject(ucd)) { ClassData cd = (ClassData)tb.DataItem; cd.UpdateFrom(ucd); tb.UpdateAll(); } } foreach (IType cls in e.TypeUpdateInformation.Added) { AddClass(e.Project, cls); } // Clean empty namespaces foreach (string ns in namespacesToClean) { string subns = ns; while (subns != null) { bool found = tb.MoveToObject(new ProjectNamespaceData(e.Project, subns)); if (!found) { found = tb.MoveToObject(new ProjectNamespaceData(null, subns)); } if (found) { while (tb.DataItem is NamespaceData && !tb.HasChildren()) { tb.Remove(true); } break; } int i = subns.LastIndexOf('.'); if (i != -1) { subns = subns.Substring(0, i); } else { subns = null; } } } // Restore expand status foreach (KeyValuePair <object, bool> de in oldStatus) { if (de.Value && tb.MoveToObject(de.Key)) { tb.ExpandToNode(); tb.Expanded = true; } } }
void RemoveFile(ProjectFile file, Project project) { ITreeBuilder tb = Context.GetTreeBuilder(); if (file.Subtype == Subtype.Directory) { if (!tb.MoveToObject(new ProjectFolder(file.Name, project))) { return; } tb.MoveToParent(); tb.UpdateAll(); return; } else { if (tb.MoveToObject(file)) { tb.Remove(true); } else { // We can't use IsExternalToProject here since the ProjectFile has // already been removed from the project FilePath parentPath = file.IsLink ? project.BaseDirectory.Combine(file.Link.IsNullOrEmpty? file.FilePath.FileName : file.Link.ToString()).ParentDirectory : file.FilePath.ParentDirectory; if (!tb.MoveToObject(new ProjectFolder(parentPath, project))) { if (project.UseFileWatcher && parentPath.IsChildPathOf(project.BaseDirectory)) { // Keep looking for folder higher up the tree so any empty folders // can be removed. while (parentPath != project.BaseDirectory) { parentPath = parentPath.ParentDirectory; if (tb.MoveToObject(new ProjectFolder(parentPath, project))) { tb.UpdateAll(); break; } } } else { return; } } } } while (tb.DataItem is ProjectFolder) { ProjectFolder f = (ProjectFolder)tb.DataItem; if (!Directory.Exists(f.Path) && !project.Files.GetFilesInVirtualPath(f.Path.ToRelative(project.BaseDirectory)).Any()) { tb.Remove(true); } else if (project.UseFileWatcher) { // Ensure empty folders are removed if they are not part of the project. while (!tb.HasChildren() && tb.MoveToParent()) { tb.UpdateAll(); } break; } else { break; } } }
void AddFile(ProjectFile file, Project project) { ITreeBuilder tb = Context.GetTreeBuilder(); if (file.DependsOnFile != null) { if (!tb.MoveToObject(file.DependsOnFile)) { // The parent is not in the tree. Add it now, and it will add this file as a child. AddFile(file.DependsOnFile, project); } else { tb.AddChild(file); } return; } string filePath = file.IsLink ? project.BaseDirectory.Combine(file.ProjectVirtualPath).ParentDirectory : file.FilePath.ParentDirectory; object data; if (file.Subtype == Subtype.Directory) { data = new ProjectFolder(file.Name, project); } else { data = file; } // Already there? if (tb.MoveToObject(data)) { return; } if (filePath != project.BaseDirectory) { if (tb.MoveToObject(new ProjectFolder(filePath, project))) { tb.AddChild(data); } else { // Make sure there is a path to that folder tb = FindParentFolderNode(filePath, project); if (tb != null) { tb.UpdateChildren(); } } } else { if (tb.MoveToObject(project)) { tb.AddChild(data); } tb.UpdateChildren(); } }