public override void BuildNode(ITreeBuilder builder, object dataObject, NodeInfo nodeInfo)
        {
            string thisPath = GetFolderPath(dataObject);

            if ((dataObject is ProjectFolder) && builder.Options ["ShowAllFiles"] && Directory.Exists(thisPath))
            {
                ProjectFolder pf = (ProjectFolder)dataObject;
                if (pf.Project == null || !ProjectFolderCommandHandler.PathExistsInProject(pf.Project, thisPath))
                {
                    var gicon = Context.GetComposedIcon(nodeInfo.Icon, "fade");
                    if (gicon == null)
                    {
                        gicon = nodeInfo.Icon.WithAlpha(0.5);
                        Context.CacheComposedIcon(nodeInfo.Icon, "fade", gicon);
                    }
                    nodeInfo.Icon = gicon;
                    gicon         = Context.GetComposedIcon(nodeInfo.ClosedIcon, "fade");
                    if (gicon == null)
                    {
                        gicon = nodeInfo.ClosedIcon.WithAlpha(0.5);
                        Context.CacheComposedIcon(nodeInfo.ClosedIcon, "fade", gicon);
                    }
                    nodeInfo.ClosedIcon = gicon;
                }
            }
        }
        public override void BuildNode(ITreeBuilder builder, object dataObject, ref string label, ref Gdk.Pixbuf icon, ref Gdk.Pixbuf closedIcon)
        {
            string thisPath = GetFolderPath(dataObject);

            if ((dataObject is ProjectFolder) && builder.Options ["ShowAllFiles"] && Directory.Exists(thisPath))
            {
                ProjectFolder pf = (ProjectFolder)dataObject;
                if (pf.Project == null || !ProjectFolderCommandHandler.PathExistsInProject(pf.Project, thisPath))
                {
                    Gdk.Pixbuf gicon = Context.GetComposedIcon(icon, "fade");
                    if (gicon == null)
                    {
                        gicon = ImageService.MakeTransparent(icon, 0.5);
                        Context.CacheComposedIcon(icon, "fade", gicon);
                    }
                    icon  = gicon;
                    gicon = Context.GetComposedIcon(closedIcon, "fade");
                    if (gicon == null)
                    {
                        gicon = ImageService.MakeTransparent(closedIcon, 0.5);
                        Context.CacheComposedIcon(closedIcon, "fade", gicon);
                    }
                    closedIcon = gicon;
                }
            }
        }
        public override void RenameItem(string newName)
        {
            SystemFile file    = CurrentNode.DataItem as SystemFile;
            string     oldname = file.Path;

            string newname = Path.Combine(Path.GetDirectoryName(oldname), newName);

            if (newname != oldname)
            {
                try {
                    if (!FileService.IsValidPath(newname) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                    }
                    else if (File.Exists(newname) || Directory.Exists(newname))
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                    }
                    else
                    {
                        FileService.RenameFile(oldname, newname);
                    }
                } catch (System.ArgumentException) {                 // new file name with wildcard (*, ?) characters in it
                    MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                } catch (System.IO.IOException ex) {
                    MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
                }
            }
        }
 public static bool RenameFileWithConflictCheck(FilePath oldPath, string newName, out string newPath)
 {
     newPath = oldPath.ParentDirectory.Combine(newName);
     if (oldPath == newPath)
     {
         return(false);
     }
     try {
         if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
         {
             MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
         }
         else if (File.Exists(newPath) || Directory.Exists(newPath))
         {
             MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
         }
         else
         {
             FileService.RenameFile(oldPath, newPath);
             return(true);
         }
     } catch (ArgumentException) {             // new file name with wildcard (*, ?) characters in it
         MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
     } catch (IOException ex) {
         MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
     }
     return(false);
 }
示例#5
0
        public async override void RenameItem(string newName)
        {
            ProjectFile newProjectFile = null;
            var         file           = (ProjectFile)CurrentNode.DataItem;

            string oldFileName = file.FilePath;
            string newFileName = Path.Combine(Path.GetDirectoryName(oldFileName), newName);

            if (oldFileName == newFileName)
            {
                return;
            }

            FilePath newPath, newLink = FilePath.Null;

            if (file.IsLink)
            {
                var oldLink = file.ProjectVirtualPath;
                newLink = oldLink.ParentDirectory.Combine(newName);
                newPath = file.Project.BaseDirectory.Combine(newLink);
            }
            else
            {
                newPath = file.FilePath.ParentDirectory.Combine(newName);
            }

            try {
                if (file.Project != null)
                {
                    newProjectFile = file.Project.Files.GetFileWithVirtualPath(newPath.ToRelative(file.Project.BaseDirectory));
                }

                if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
                {
                    MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                }
                else if ((newProjectFile != null && newProjectFile != file) || File.Exists(file.FilePath.ParentDirectory.Combine(newName)))
                {
                    // If there is already a file under the newPath which is *different*, then throw an exception
                    MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                }
                else
                {
                    FileService.RenameFile(file.FilePath, newName);
                    if (file.Project != null)
                    {
                        await IdeApp.ProjectOperations.SaveAsync(file.Project);
                    }
                }
            } catch (ArgumentException) {             // new file name with wildcard (*, ?) characters in it
                MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
            } catch (IOException ex) {
                MessageService.ShowError(GettextCatalog.GetString("There was an error renaming the file."), ex);
            }
        }
        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);
                }
            }
        }
        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();
                    }
                }
            }
        }
示例#8
0
        static bool CanRenameFile(ProjectFile file, string newName)
        {
            ProjectFile newProjectFile = null;
            FilePath    newPath        = GetRenamedFilePath(file, newName);

            if (file.Project != null)
            {
                newProjectFile = file.Project.Files.GetFileWithVirtualPath(newPath.ToRelative(file.Project.BaseDirectory));
            }

            if (!FileService.IsValidPath(newPath) || ProjectFolderCommandHandler.ContainsDirectorySeparator(newName))
            {
                MessageService.ShowWarning(GettextCatalog.GetString("The name you have chosen contains illegal characters. Please choose a different name."));
                return(false);
            }
            else if ((newProjectFile != null && newProjectFile != file) || FileExistsCaseSensitive(file.FilePath.ParentDirectory, newName))
            {
                // If there is already a file under the newPath which is *different*, then throw an exception
                MessageService.ShowWarning(GettextCatalog.GetString("File or directory name is already in use. Please choose a different one."));
                return(false);
            }

            return(true);
        }
示例#9
0
 public override bool CanHandleDropFromChild(object [] dataObjects, DragOperation operation, DropPosition position)
 {
     return(ProjectFolderCommandHandler.CanHandleDropFromChild(dataObjects, position));
 }