void OnFolderRemoved(object sender, FileEventArgs e) { ITreeBuilder tb = Context.GetTreeBuilder(sender); if (tb != null) { if (!tb.HasChildren()) { tb.Remove(); } else { tb.UpdateAll(); } } }
public override void BuildNode(ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { base.BuildNode(treeBuilder, dataObject, ref label, ref icon, ref closedIcon); ProjectFolder folder = (ProjectFolder)dataObject; label = folder.Name; //show directory in red if doesn't exist and doesn't have virtual linked children if (!Directory.Exists(folder.Path) && !treeBuilder.HasChildren()) { label = "<span foreground='red'>" + label + "</span>"; } icon = folderOpenIcon; closedIcon = folderClosedIcon; }
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; } } }
public override void BuildNode (ITreeBuilder treeBuilder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon) { base.BuildNode (treeBuilder, dataObject, ref label, ref icon, ref closedIcon); ProjectFolder folder = (ProjectFolder) dataObject; label = folder.Name; //show directory in red if doesn't exist and doesn't have virtual linked children if (!Directory.Exists (folder.Path) && !treeBuilder.HasChildren ()) { label = "<span foreground='red'>" + label + "</span>"; } icon = folderOpenIcon; closedIcon = folderClosedIcon; }