public async Task <List <TaskRunnerInformation> > FindTasks( IWorkspaceFileObject workspaceFileObject, HashSet <FilePath> filesAdded) { List <TaskRunnerInformation> foundTasks = null; foreach (FilePath configFile in GetFiles(workspaceFileObject)) { if (!filesAdded.Contains(configFile)) { ITaskRunner runner = taskRunnerProvider.GetTaskRunner(configFile); if (runner != null) { ITaskRunnerConfig config = await runner.ParseConfig(null, configFile); var info = new TaskRunnerInformation(workspaceFileObject, config, runner.Options, configFile); if (foundTasks == null) { foundTasks = new List <TaskRunnerInformation> (); } foundTasks.Add(info); filesAdded.Add(configFile); } } } return(foundTasks); }
public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor) { object readObject = null; ProjectExtensionUtil.BeginLoadOperation(); try { string ext = Path.GetExtension(fileName).ToLower(); if (ext == ".mdp") { object project = ReadProjectFile(fileName, monitor); if (project is DotNetProject) { ((DotNetProject)project).SetItemHandler(new MD1DotNetProjectHandler((DotNetProject)project)); } readObject = project; } else if (ext == ".mds") { readObject = ReadCombineFile(fileName, monitor); } else if (ext == ".mdw") { readObject = ReadWorkspaceItemFile(fileName, monitor); } else { XmlTextReader reader = new XmlTextReader(new StreamReader(fileName)); try { monitor.BeginTask(string.Format(GettextCatalog.GetString("Loading solution item: {0}"), fileName), 1); reader.MoveToContent(); XmlDataSerializer ser = new XmlDataSerializer(MD1ProjectService.DataContext); ser.SerializationContext.BaseFile = fileName; ser.SerializationContext.ProgressMonitor = monitor; SolutionEntityItem entry = (SolutionEntityItem)ser.Deserialize(reader, typeof(SolutionEntityItem)); entry.FileName = fileName; MD1ProjectService.InitializeHandler(entry); readObject = entry; } catch (Exception ex) { monitor.ReportError(string.Format(GettextCatalog.GetString("Could not load solution item: {0}"), fileName), ex); throw; } finally { monitor.EndTask(); reader.Close(); } } } finally { ProjectExtensionUtil.EndLoadOperation(); } IWorkspaceFileObject fo = readObject as IWorkspaceFileObject; if (fo != null) { fo.ConvertToFormat(MD1ProjectService.FileFormat, false); } return(readObject); }
public object ReadFile(FilePath fileName, Type expectedType, IProgressMonitor monitor) { string ext = Path.GetExtension(fileName).ToLower(); if (ext != ".mdw") { throw new ArgumentException(); } object readObject = null; ProjectExtensionUtil.BeginLoadOperation(); try { readObject = ReadWorkspaceItemFile(fileName, monitor); } finally { ProjectExtensionUtil.EndLoadOperation(); } IWorkspaceFileObject fo = readObject as IWorkspaceFileObject; if (fo != null) { fo.ConvertToFormat(MD1ProjectService.FileFormat, false); } return(readObject); }
public SelectFileFormatDialog(IWorkspaceFileObject item) { this.Build(); string warning = ""; foreach (string msg in item.FileFormat.GetCompatibilityWarnings(item)) { warning += msg + "\n"; } if (warning.Length > 0) { warning = warning.Substring(0, warning.Length - 1); } labelWarnings.Text = warning; labelMessage.Text = string.Format(labelMessage.Text, item.Name); labelCurrentFormat.Text = item.FileFormat.Name; foreach (FileFormat format in Services.ProjectService.FileFormats.GetFileFormatsForObject(item)) { comboNewFormat.AppendText(format.Name); formats.Add(format); } comboNewFormat.Active = 0; }
public bool CanWrite (object obj) { IWorkspaceFileObject wfo = obj as IWorkspaceFileObject; if (wfo != null && !wfo.SupportsFormat (this)) return false; return format.CanWriteFile (obj); }
public GroupedTaskRunnerInformation( IWorkspaceFileObject workspaceFileObject, IEnumerable <TaskRunnerInformation> tasks) { WorkspaceFileObject = workspaceFileObject; this.tasks = tasks.ToList(); Name = GetName(workspaceFileObject); }
public static void RenameItem(IWorkspaceFileObject item, string newName) { if (newName == item.Name) { return; } if (!FileService.IsValidFileName(newName)) { MessageService.ShowError(GettextCatalog.GetString("Illegal project name.\nOnly use letters, digits, space, '.' or '_'.")); return; } FilePath oldFile = item.FileName; string oldName = item.Name; FilePath newFile = oldFile.ParentDirectory.Combine(newName + oldFile.Extension); // Rename the physical file first as changing the name of an IWorkspaceFileObject // can result in the filesystem being probed for a file with that name. if (!RenameItemFile(oldFile, newFile)) { return; } try { item.Name = newName; item.NeedsReload = false; // We renamed it to the wrong thing... if (item.FileName != newFile) { LoggingService.LogError("File {0} was renamed to {1} instead of {2}.", item.FileName, item.FileName.FileName, newFile.FileName); // File name changed, rename the project file if (!RenameItemFile(newFile, item.FileName)) { RenameItemFile(newFile, oldFile); item.Name = oldName; item.NeedsReload = false; return; } } } catch (Exception ex) { if (File.Exists(item.FileName)) { FileService.RenameFile(item.FileName, oldFile); } else if (File.Exists(newFile)) { FileService.RenameFile(newFile, oldFile); } item.Name = oldName; MessageService.ShowException(ex, GettextCatalog.GetString("The project could not be renamed.")); return; } item.NeedsReload = false; }
static string GetName(IWorkspaceFileObject workspaceFileObject) { if (workspaceFileObject is Solution solution) { return(GettextCatalog.GetString("Solution '{0}'", solution.Name)); } return(workspaceFileObject.Name); }
public FileStatusTracker(IWorkspaceFileObject item, Action <TEventArgs> onReloadRequired, TEventArgs eventArgs) { this.item = item; this.eventArgs = eventArgs; this.onReloadRequired = onReloadRequired; lastSaveTime = new Dictionary <string, DateTime> (); savingFlag = false; reloadRequired = null; }
public IEnumerable<string> GetCompatibilityWarnings (object obj) { IWorkspaceFileObject wfo = obj as IWorkspaceFileObject; if (wfo != null && !wfo.SupportsFormat (this)) { return new string[] {GettextCatalog.GetString ("The project '{0}' is not supported by {1}", wfo.Name, Name) }; } IEnumerable<string> res = format.GetCompatibilityWarnings (obj); return res ?? new string [0]; }
public static void RenameItem(IWorkspaceFileObject item, string newName) { if (newName == item.Name) { return; } if (!FileService.IsValidFileName(newName)) { MessageService.ShowError(GettextCatalog.GetString("Illegal project name.\nOnly use letters, digits, space, '.' or '_'.")); return; } FilePath oldFile = item.FileName; string oldName = item.Name; try { item.Name = newName; item.NeedsReload = false; if (oldFile != item.FileName) { // File name changed, rename the project file if (!RenameItemFile(oldFile, item.FileName)) { item.Name = oldName; item.NeedsReload = false; return; } } else if (oldFile.FileNameWithoutExtension == oldName) { FilePath newFile = oldFile.ParentDirectory.Combine(newName + oldFile.Extension); if (newFile != oldFile) { if (!RenameItemFile(oldFile, newFile)) { item.Name = oldName; item.NeedsReload = false; return; } item.FileName = newFile; } } } catch (Exception ex) { item.Name = oldName; MessageService.ShowException(ex, GettextCatalog.GetString("The project could not be renamed.")); return; } item.NeedsReload = false; }
public TaskRunnerInformation( IWorkspaceFileObject workspaceFileObject, ITaskRunnerConfig config, IEnumerable <ITaskRunnerOption> options, FilePath configFile) { WorkspaceFileObject = workspaceFileObject; Config = config; Options = options; ConfigFile = configFile; Name = GetName(); Bindings = new TaskRunnerBindings(Config, configFile); }
public void OnChanged(object obj) { // Don't use the CurrentNode property here since it may not be properly initialized when the event is fired. ITreeNavigator nav = Tree.GetNodeAtObject(obj); if (nav != null) { IWorkspaceFileObject ce = (IWorkspaceFileObject)nav.GetParentDataItem(typeof(IWorkspaceFileObject), true); if (ce != null) { IdeApp.ProjectOperations.Save(ce); return; } } }
public static void RenameItem (IWorkspaceFileObject item, string newName) { if (newName == item.Name) return; if (!NewProjectConfiguration.IsValidSolutionName (newName)) { MessageService.ShowError (GettextCatalog.GetString ("Illegal project name.\nOnly use letters, digits, space, '.' or '_'.")); return; } FilePath oldFile = item.FileName; string oldName = item.Name; FilePath newFile = oldFile.ParentDirectory.Combine (newName + oldFile.Extension); // Rename the physical file first as changing the name of an IWorkspaceFileObject // can result in the filesystem being probed for a file with that name. if (!RenameItemFile (oldFile, newFile)) return; try { item.Name = newName; item.NeedsReload = false; // We renamed it to the wrong thing... if (item.FileName != newFile) { LoggingService.LogError ("File {0} was renamed to {1} instead of {2}.", item.FileName, item.FileName.FileName, newFile.FileName); // File name changed, rename the project file if (!RenameItemFile (newFile, item.FileName)) { RenameItemFile (newFile, oldFile); item.Name = oldName; item.NeedsReload = false; return; } } } catch (Exception ex) { if (File.Exists (item.FileName)) FileService.RenameFile (item.FileName, oldFile); else if (File.Exists (newFile)) FileService.RenameFile (newFile, oldFile); item.Name = oldName; MessageService.ShowError (GettextCatalog.GetString ("The project could not be renamed."), ex); return; } item.NeedsReload = false; }
ProcessedTemplateResult ProcessTemplate(DefaultSolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder) { IEnumerable <IWorkspaceFileObject> newItems = null; ProjectCreateInformation cinfo = CreateProjectCreateInformation(config, parentFolder); if (parentFolder == null) { IWorkspaceFileObject newItem = template.Template.CreateWorkspaceItem(cinfo); if (newItem != null) { newItems = new [] { newItem }; } } else { newItems = template.Template.CreateProjects(parentFolder, cinfo); } return(new DefaultProcessedTemplateResult(template.Template, newItems, cinfo.ProjectBasePath)); }
bool CopyFiles(IProgressMonitor monitor, IWorkspaceFileObject obj, IEnumerable <FilePath> files, FilePath targetBasePath, bool ignoreExternalFiles) { FilePath baseDir = obj.BaseDirectory.FullPath; foreach (FilePath file in files) { if (!File.Exists(file)) { monitor.ReportWarning(GettextCatalog.GetString("File '{0}' not found.", file)); continue; } FilePath fname = file.FullPath; // Can't export files from outside the root solution directory if (!fname.IsChildPathOf(baseDir)) { if (ignoreExternalFiles) { continue; } if (obj is Solution) { monitor.ReportError("The solution '" + obj.Name + "' is referencing the file '" + Path.GetFileName(file) + "' which is located outside the root solution directory.", null); } else { monitor.ReportError("The project '" + obj.Name + "' is referencing the file '" + Path.GetFileName(file) + "' which is located outside the project directory.", null); } return(false); } FilePath rpath = fname.ToRelative(baseDir); rpath = rpath.ToAbsolute(targetBasePath); if (!Directory.Exists(rpath.ParentDirectory)) { Directory.CreateDirectory(rpath.ParentDirectory); } File.Copy(file, rpath, true); } return(true); }
public SelectFileFormatDialog (IWorkspaceFileObject item) { this.Build (); string warning = ""; foreach (string msg in item.FileFormat.GetCompatibilityWarnings (item)) warning += msg + "\n"; if (warning.Length > 0) warning = warning.Substring (0, warning.Length - 1); labelWarnings.Text = warning; labelMessage.Text = string.Format (labelMessage.Text, item.Name); labelCurrentFormat.Text = item.FileFormat.Name; foreach (FileFormat format in Services.ProjectService.FileFormats.GetFileFormatsForObject (item)) { comboNewFormat.AppendText (format.Name); formats.Add (format); } comboNewFormat.Active = 0; }
public static void RenameItem (IWorkspaceFileObject item, string newName) { if (newName == item.Name) return; if (!FileService.IsValidFileName (newName)) { MessageService.ShowError (GettextCatalog.GetString ("Illegal project name.\nOnly use letters, digits, space, '.' or '_'.")); return; } FilePath oldFile = item.FileName; string oldName = item.Name; try { item.Name = newName; item.NeedsReload = false; if (oldFile != item.FileName) { // File name changed, rename the project file if (!RenameItemFile (oldFile, item.FileName)) { item.Name = oldName; item.NeedsReload = false; return; } } else if (oldFile.FileNameWithoutExtension == oldName) { FilePath newFile = oldFile.ParentDirectory.Combine (newName + oldFile.Extension); if (newFile != oldFile) { if (!RenameItemFile (oldFile, newFile)) { item.Name = oldName; item.NeedsReload = false; return; } item.FileName = newFile; } } } catch (Exception ex) { item.Name = oldName; MessageService.ShowException (ex, GettextCatalog.GetString ("The project could not be renamed.")); return; } item.NeedsReload = false; }
void ExcludeEntries(IWorkspaceFileObject obj, string[] includedChildIds) { Solution sol = obj as Solution; if (sol != null && includedChildIds != null) { // Remove items not to be exported. Dictionary <string, string> childIds = new Dictionary <string, string> (); foreach (string it in includedChildIds) { childIds [it] = it; } foreach (SolutionItem item in sol.GetAllSolutionItems <SolutionItem> ()) { if (!childIds.ContainsKey(item.ItemId) && item.ParentFolder != null) { item.ParentFolder.Items.Remove(item); } } } }
IEnumerable <FilePath> GetFiles(IWorkspaceFileObject workspaceFileObject) { if (workspaceFileObject is Project project) { foreach (ProjectFile file in project.Files) { yield return(file.FilePath); } } if (workspaceFileObject is Solution solution) { foreach (FilePath file in GetSolutionFolderFiles(solution.RootFolder)) { yield return(file); } } foreach (FilePath configFile in Directory.EnumerateFiles(workspaceFileObject.BaseDirectory)) { yield return(configFile); } }
public ConfirmProjectDeleteDialog(IWorkspaceFileObject item) { this.Build(); this.item = item; store = new TreeStore(typeof(bool), typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); fileList.Model = store; TreeViewColumn col = new TreeViewColumn(); CellRendererToggle crt = new CellRendererToggle(); crt.Toggled += CrtToggled; col.PackStart(crt, false); col.AddAttribute(crt, "active", 0); CellRendererPixbuf crp = new CellRendererPixbuf(); col.PackStart(crp, false); col.AddAttribute(crp, "pixbuf", 1); CellRendererText cre = new CellRendererText(); col.PackStart(cre, true); col.AddAttribute(cre, "text", 2); col.AddAttribute(cre, "foreground", 4); fileList.AppendColumn(col); store.SetSortColumnId(2, SortType.Ascending); labelProjectDir.Text = item.BaseDirectory.FullPath; HashSet <string> itemFiles = new HashSet <string> (); HashSet <string> knownPaths = new HashSet <string> (); foreach (FilePath file in item.GetItemFiles(true)) { itemFiles.Add(file.FullPath); knownPaths.Add(file.FullPath + "~"); } foreach (string ext in knownExtensions) { knownPaths.Add(item.FileName.ChangeExtension(ext)); } FillDirRec(TreeIter.Zero, item, itemFiles, knownPaths, item.BaseDirectory, false); if (item.BaseDirectory != item.ItemDirectory) { // If the project has a custom base directory, make sure the project files // from the item directory are shown in the list foreach (FilePath f in item.GetItemFiles(false)) { if (!f.IsChildPathOf(item.BaseDirectory)) { Gdk.Pixbuf pix = DesktopService.GetPixbufForFile(f, IconSize.Menu); paths [f] = store.AppendValues(true, pix, f.FileName, f.ToString()); } } } if (item is SolutionItem) { var sol = ((SolutionItem)item).ParentSolution; var bdir = item.BaseDirectory; if (sol.GetItemFiles(false).Any(f => f.IsChildPathOf(bdir)) || sol.GetAllSolutionItems <SolutionEntityItem> ().Any(it => it != item && it.GetItemFiles(true).Any(f => f.IsChildPathOf(bdir)))) { radioDeleteAll.Sensitive = false; labelProjectDir.Text = GettextCatalog.GetString("Project directory can't be deleted since it contains files from other projects or solutions"); } } if (item.BaseDirectory.FileName == item.Name && radioDeleteAll.Sensitive) { radioDeleteAll.Active = true; fileList.Sensitive = false; } else { radioDeleteSel.Active = true; Focus = radioDeleteSel; } }
public RootDirectoriesChangedEventArgs(IWorkspaceFileObject sourceItem, bool isRemove, bool isAdd) { SourceItem = sourceItem; IsRemove = isRemove; IsAdd = isAdd; }
bool SelectValidFileFormat (IWorkspaceFileObject item) { var dlg = new SelectFileFormatDialog (item); try { if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok && dlg.Format != null) { item.ConvertToFormat (dlg.Format, true); return true; } return false; } finally { dlg.Destroy (); } }
bool HasChanged (IWorkspaceFileObject item) { if (item.ItemFilesChanged) return true; if (item is WorkspaceItem) { foreach (SolutionEntityItem eitem in ((WorkspaceItem)item).GetAllSolutionItems<SolutionEntityItem> ()) if (eitem.ItemFilesChanged) return true; } return false; }
public void Save (IWorkspaceFileObject item) { if (item is SolutionEntityItem) Save ((SolutionEntityItem) item); else if (item is Solution) Save ((Solution)item); if (!item.FileFormat.CanWrite (item)) { IWorkspaceFileObject ci = GetContainer (item); if (SelectValidFileFormat (ci)) Save (ci); return; } if (!AllowSave (item)) return; IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true); try { item.Save (monitor); monitor.ReportSuccess (GettextCatalog.GetString ("Item saved.")); } catch (Exception ex) { monitor.ReportError (GettextCatalog.GetString ("Save failed."), ex); } finally { monitor.Dispose (); } }
bool CopyFiles (IProgressMonitor monitor, IWorkspaceFileObject obj, IEnumerable<FilePath> files, FilePath targetBasePath, bool ignoreExternalFiles) { FilePath baseDir = obj.BaseDirectory.FullPath; foreach (FilePath file in files) { if (!File.Exists (file)) { monitor.ReportWarning (GettextCatalog.GetString ("File '{0}' not found.", file)); continue; } FilePath fname = file.FullPath; // Can't export files from outside the root solution directory if (!fname.IsChildPathOf (baseDir)) { if (ignoreExternalFiles) continue; if (obj is Solution) monitor.ReportError ("The solution '" + obj.Name + "' is referencing the file '" + Path.GetFileName (file) + "' which is located outside the root solution directory.", null); else monitor.ReportError ("The project '" + obj.Name + "' is referencing the file '" + Path.GetFileName (file) + "' which is located outside the project directory.", null); return false; } FilePath rpath = fname.ToRelative (baseDir); rpath = rpath.ToAbsolute (targetBasePath); if (!Directory.Exists (rpath.ParentDirectory)) Directory.CreateDirectory (rpath.ParentDirectory); File.Copy (file, rpath, true); } return true; }
public Task <List <TaskRunnerInformation> > FindTasks(IWorkspaceFileObject workspaceFileObject) { var filesAdded = new HashSet <FilePath> (); return(FindTasks(workspaceFileObject, filesAdded)); }
public GroupedTaskRunnerInformation GetGroupedTask(IWorkspaceFileObject workspaceFileObject) { return(groupedTasks.FirstOrDefault(task => task.WorkspaceFileObject == workspaceFileObject)); }
public ConfirmProjectDeleteDialog (IWorkspaceFileObject item) { this.Build (); this.item = item; store = new TreeStore (typeof(bool), typeof(Gdk.Pixbuf), typeof(string), typeof(string), typeof(string)); fileList.Model = store; TreeViewColumn col = new TreeViewColumn (); CellRendererToggle crt = new CellRendererToggle (); crt.Toggled += CrtToggled; col.PackStart (crt, false); col.AddAttribute (crt, "active", 0); CellRendererPixbuf crp = new CellRendererPixbuf (); col.PackStart (crp, false); col.AddAttribute (crp, "pixbuf", 1); CellRendererText cre = new CellRendererText (); col.PackStart (cre, true); col.AddAttribute (cre, "text", 2); col.AddAttribute (cre, "foreground", 4); fileList.AppendColumn (col); store.SetSortColumnId (2, SortType.Ascending); labelProjectDir.Text = item.BaseDirectory.FullPath; HashSet<string> itemFiles = new HashSet<string> (); HashSet<string> knownPaths = new HashSet<string> (); foreach (FilePath file in item.GetItemFiles (true)) { itemFiles.Add (file.FullPath); knownPaths.Add (file.FullPath + "~"); } foreach (string ext in knownExtensions) knownPaths.Add (item.FileName.ChangeExtension (ext)); FillDirRec (TreeIter.Zero, item, itemFiles, knownPaths, item.BaseDirectory, false); if (item.BaseDirectory != item.ItemDirectory) { // If the project has a custom base directory, make sure the project files // from the item directory are shown in the list foreach (FilePath f in item.GetItemFiles (false)) { if (!f.IsChildPathOf (item.BaseDirectory)) { Gdk.Pixbuf pix = DesktopService.GetPixbufForFile (f, IconSize.Menu); paths [f] = store.AppendValues (true, pix, f.FileName, f.ToString ()); } } } if (item is SolutionItem) { var sol = ((SolutionItem)item).ParentSolution; var bdir = item.BaseDirectory; if (sol.GetItemFiles (false).Any (f => f.IsChildPathOf (bdir)) || sol.GetAllSolutionItems<SolutionEntityItem> ().Any (it => it != item && it.GetItemFiles (true).Any (f => f.IsChildPathOf (bdir)))) { radioDeleteAll.Sensitive = false; labelProjectDir.Text = GettextCatalog.GetString ("Project directory can't be deleted since it contains files from other projects or solutions"); } } if (item.BaseDirectory.FileName == item.Name && radioDeleteAll.Sensitive) { radioDeleteAll.Active = true; fileList.Sensitive = false; } else { radioDeleteSel.Active = true; Focus = radioDeleteSel; } }
ChildInfo FillDirRec (Gtk.TreeIter iter, IWorkspaceFileObject item, HashSet<string> itemFiles, HashSet<string> knownPaths, FilePath dir, bool forceSet) { ChildInfo cinfo = ChildInfo.AllSelected; bool hasChildren = false; foreach (string sd in knownSubdirs) { if (dir == item.BaseDirectory.Combine (sd)) { forceSet = true; break; } } TreeIter dit; if (!iter.Equals (TreeIter.Zero)) { dit = store.AppendValues (iter, false, DesktopService.GetPixbufForFile (dir, IconSize.Menu), dir.FileName.ToString (), dir.ToString ()); fileList.ExpandRow (store.GetPath (iter), false); } else dit = store.AppendValues (false, DesktopService.GetPixbufForFile (dir, IconSize.Menu), dir.FileName.ToString (), dir.ToString ()); paths [dir] = dit; foreach (string file in Directory.GetFiles (dir)) { string path = System.IO.Path.GetFileName (file); Gdk.Pixbuf pix = DesktopService.GetPixbufForFile (file, IconSize.Menu); bool active = itemFiles.Contains (file); string color = null; if (!active) { pix = ImageService.MakeTransparent (pix, 0.5); color = "dimgrey"; } else cinfo |= ChildInfo.HasProjectFiles; active = active || forceSet || knownPaths.Contains (file); if (!active) cinfo &= ~ChildInfo.AllSelected; else cinfo |= ChildInfo.SomeSelected; paths [file] = store.AppendValues (dit, active, pix, path, file, color); if (!hasChildren) { hasChildren = true; fileList.ExpandRow (store.GetPath (dit), false); } } foreach (string cdir in Directory.GetDirectories (dir)) { hasChildren = true; ChildInfo ci = FillDirRec (dit, item, itemFiles, knownPaths, cdir, forceSet); if ((ci & ChildInfo.AllSelected) == 0) cinfo &= ~ChildInfo.AllSelected; cinfo |= ci & (ChildInfo.SomeSelected | ChildInfo.HasProjectFiles); } if ((cinfo & ChildInfo.AllSelected) != 0 && hasChildren) store.SetValue (dit, 0, true); if ((cinfo & ChildInfo.HasProjectFiles) == 0) { Gdk.Pixbuf pix = DesktopService.GetPixbufForFile (dir, IconSize.Menu); pix = ImageService.MakeTransparent (pix, 0.5); store.SetValue (dit, 1, pix); store.SetValue (dit, 4, "dimgrey"); } if ((cinfo & ChildInfo.SomeSelected) != 0 && (cinfo & ChildInfo.AllSelected) == 0) { fileList.ExpandRow (store.GetPath (dit), false); } else { fileList.CollapseRow (store.GetPath (dit)); } return cinfo; }
string Export (IProgressMonitor monitor, IWorkspaceFileObject obj, string[] includedChildIds, string targetPath, FileFormat format) { string rootSourceFile = obj.FileName; string sourcePath = Path.GetFullPath (Path.GetDirectoryName (rootSourceFile)); targetPath = Path.GetFullPath (targetPath); if (sourcePath != targetPath) { if (!CopyFiles (monitor, obj, obj.GetItemFiles (true), targetPath, true)) return null; string newFile = Path.Combine (targetPath, Path.GetFileName (rootSourceFile)); if (IsWorkspaceItemFile (rootSourceFile)) obj = ReadWorkspaceItem (monitor, newFile); else obj = (SolutionEntityItem) ReadSolutionItem (monitor, newFile); using (obj) { List<FilePath> oldFiles = obj.GetItemFiles (true); ExcludeEntries (obj, includedChildIds); if (format != null) obj.ConvertToFormat (format, true); obj.Save (monitor); List<FilePath> newFiles = obj.GetItemFiles (true); foreach (FilePath f in newFiles) { if (!f.IsChildPathOf (targetPath)) { if (obj is Solution) monitor.ReportError ("The solution '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the root solution directory.", null); else monitor.ReportError ("The project '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the project directory.", null); } oldFiles.Remove (f); } // Remove old files foreach (FilePath file in oldFiles) { if (File.Exists (file)) { File.Delete (file); // Exclude empty directories FilePath dir = file.ParentDirectory; if (Directory.GetFiles (dir).Length == 0 && Directory.GetDirectories (dir).Length == 0) { try { Directory.Delete (dir); } catch (Exception ex) { monitor.ReportError (null, ex); } } } } return obj.FileName; } } else { using (obj) { ExcludeEntries (obj, includedChildIds); if (format != null) obj.ConvertToFormat (format, true); obj.Save (monitor); return obj.FileName; } } }
bool CreateProject() { if (templateView.CurrentlySelected != null) { PropertyService.Set("Dialogs.NewProjectDialog.LastSelectedCategory", ((ProjectTemplate)templateView.CurrentlySelected).Category); recentIds.Remove(templateView.CurrentlySelected.Id); recentIds.Insert(0, templateView.CurrentlySelected.Id); if (recentIds.Count > 15) { recentIds.RemoveAt(recentIds.Count - 1); } string strRecent = string.Join(",", recentIds.ToArray()); PropertyService.Set("Dialogs.NewProjectDialog.RecentTemplates", strRecent); PropertyService.SaveProperties(); //PropertyService.Set("Dialogs.NewProjectDialog.LargeImages", ((RadioButton)ControlDictionary["largeIconsRadioButton"]).Checked); } string solution = txt_subdirectory.Text; string name = txt_name.Text; string location = ProjectLocation; if (solution.Equals("")) { solution = name; //This was empty when adding after first combine } if ( !FileService.IsValidPath(solution) || !FileService.IsValidFileName(name) || name.IndexOf(' ') >= 0 || !FileService.IsValidPath(location)) { MessageService.ShowError(GettextCatalog.GetString("Illegal project name.\nOnly use letters, digits, '.' or '_'.")); return(false); } if (parentFolder != null && parentFolder.ParentSolution.FindProjectByName(name) != null) { MessageService.ShowError(GettextCatalog.GetString("A Project with that name is already in your Project Space")); return(false); } PropertyService.Set( "MonoDevelop.Core.Gui.Dialogs.NewProjectDialog.AutoCreateProjectSubdir", CreateSolutionDirectory); if (templateView.CurrentlySelected == null || name.Length == 0) { return(false); } ProjectTemplate item = (ProjectTemplate)templateView.CurrentlySelected; try { if (Directory.Exists(ProjectLocation)) { var btn = MessageService.AskQuestion(GettextCatalog.GetString("Directory {0} already exists.\nDo you want to coninue the Project creation?", ProjectLocation), AlertButton.No, AlertButton.Yes); if (btn != AlertButton.Yes) { return(false); } } System.IO.Directory.CreateDirectory(location); } catch (IOException) { MessageService.ShowError(GettextCatalog.GetString("Could not create directory {0}. File already exists.", location)); return(false); } catch (UnauthorizedAccessException) { MessageService.ShowError(GettextCatalog.GetString("You do not have permission to create to {0}", location)); return(false); } try { ProjectCreateInformation cinfo = CreateProjectCreateInformation(); if (newSolution) { newItem = item.CreateWorkspaceItem(cinfo); } else { newItem = item.CreateProject(parentFolder, cinfo); } } catch (UserException ex) { MessageService.ShowError(ex.Message, ex.Details); return(false); } catch (Exception ex) { MessageService.ShowException(ex, GettextCatalog.GetString("The project could not be created")); return(false); } selectedItem = item; return(true); }
void ExcludeEntries (IWorkspaceFileObject obj, string[] includedChildIds) { Solution sol = obj as Solution; if (sol != null && includedChildIds != null) { // Remove items not to be exported. Dictionary<string,string> childIds = new Dictionary<string,string> (); foreach (string it in includedChildIds) childIds [it] = it; foreach (SolutionItem item in sol.GetAllSolutionItems<SolutionItem> ()) { if (!childIds.ContainsKey (item.ItemId) && item.ParentFolder != null) item.ParentFolder.Items.Remove (item); } } }
public async void RenameItem (IWorkspaceFileObject item, string newName) { ProjectOptionsDialog.RenameItem (item, newName); if (item is SolutionFolderItem) { await SaveAsync (((SolutionFolderItem)item).ParentSolution); } else { await IdeApp.Workspace.SaveAsync (); IdeApp.Workspace.SavePreferences (); } }
public void RenameItem (IWorkspaceFileObject item, string newName) { ProjectOptionsDialog.RenameItem (item, newName); if (item is SolutionItem) { Save (((SolutionItem)item).ParentSolution); } else { IdeApp.Workspace.Save (); IdeApp.Workspace.SavePreferences (); } }
async Task SaveAsync (IWorkspaceFileObject item) { if (item is SolutionItem) await SaveAsync ((SolutionItem) item); else if (item is Solution) await SaveAsync ((Solution)item); var msf = item as IMSBuildFileObject; if (msf != null && !msf.FileFormat.CanWriteFile (item)) { var ci = (IMSBuildFileObject) GetContainer (item); if (SelectValidFileFormat (ci)) await SaveAsync (ci); return; } if (!AllowSave (item)) return; ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true); try { await item.SaveAsync (monitor); monitor.ReportSuccess (GettextCatalog.GetString ("Item saved.")); } catch (Exception ex) { monitor.ReportError (GettextCatalog.GetString ("Save failed."), ex); } finally { monitor.Dispose (); } }
bool AllowSave (IWorkspaceFileObject item) { if (HasChanged (item)) return MessageService.Confirm ( GettextCatalog.GetString ("Some project files have been changed from outside MonoDevelop. Do you want to overwrite them?"), GettextCatalog.GetString ("Changes done in those files will be overwritten by MonoDevelop."), AlertButton.OverwriteFile); else return true; }
IWorkspaceFileObject GetContainer (IWorkspaceFileObject item) { SolutionItem si = item as SolutionItem; if (si != null && si.ParentSolution != null) return si.ParentSolution; else return item; }
IWorkspaceFileObject GetContainer (IWorkspaceFileObject item) { SolutionEntityItem si = item as SolutionEntityItem; if (si != null && si.ParentSolution != null && !si.ParentSolution.FileFormat.SupportsMixedFormats) return si.ParentSolution; else return item; }
bool AllowSave (IWorkspaceFileObject item) { if (HasChanged (item)) { return MessageService.Confirm ( GettextCatalog.GetString ( "Some project files have been changed from outside {0}. Do you want to overwrite them?", BrandingService.ApplicationName ), GettextCatalog.GetString ( "Changes done in those files will be overwritten by {0}.", BrandingService.ApplicationName ), AlertButton.OverwriteFile); } else { return true; } }
string Export(IProgressMonitor monitor, IWorkspaceFileObject obj, string[] includedChildIds, string targetPath, FileFormat format) { string rootSourceFile = obj.FileName; string sourcePath = Path.GetFullPath(Path.GetDirectoryName(rootSourceFile)); targetPath = Path.GetFullPath(targetPath); if (sourcePath != targetPath) { if (!CopyFiles(monitor, obj, obj.GetItemFiles(true), targetPath, true)) { return(null); } string newFile = Path.Combine(targetPath, Path.GetFileName(rootSourceFile)); if (IsWorkspaceItemFile(rootSourceFile)) { obj = ReadWorkspaceItem(monitor, newFile); } else { obj = (SolutionEntityItem)ReadSolutionItem(monitor, newFile); } using (obj) { List <FilePath> oldFiles = obj.GetItemFiles(true); ExcludeEntries(obj, includedChildIds); if (format != null) { obj.ConvertToFormat(format, true); } obj.Save(monitor); List <FilePath> newFiles = obj.GetItemFiles(true); foreach (FilePath f in newFiles) { if (!f.IsChildPathOf(targetPath)) { if (obj is Solution) { monitor.ReportError("The solution '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the root solution directory.", null); } else { monitor.ReportError("The project '" + obj.Name + "' is referencing the file '" + f.FileName + "' which is located outside the project directory.", null); } } oldFiles.Remove(f); } // Remove old files foreach (FilePath file in oldFiles) { if (File.Exists(file)) { File.Delete(file); // Exclude empty directories FilePath dir = file.ParentDirectory; if (Directory.GetFiles(dir).Length == 0 && Directory.GetDirectories(dir).Length == 0) { try { Directory.Delete(dir); } catch (Exception ex) { monitor.ReportError(null, ex); } } } } return(obj.FileName); } } else { using (obj) { ExcludeEntries(obj, includedChildIds); if (format != null) { obj.ConvertToFormat(format, true); } obj.Save(monitor); return(obj.FileName); } } }
ChildInfo FillDirRec(Gtk.TreeIter iter, IWorkspaceFileObject item, HashSet <string> itemFiles, HashSet <string> knownPaths, FilePath dir, bool forceSet) { ChildInfo cinfo = ChildInfo.AllSelected; bool hasChildren = false; foreach (string sd in knownSubdirs) { if (dir == item.BaseDirectory.Combine(sd)) { forceSet = true; break; } } TreeIter dit; if (!iter.Equals(TreeIter.Zero)) { dit = store.AppendValues(iter, false, DesktopService.GetPixbufForFile(dir, IconSize.Menu), dir.FileName.ToString(), dir.ToString()); fileList.ExpandRow(store.GetPath(iter), false); } else { dit = store.AppendValues(false, DesktopService.GetPixbufForFile(dir, IconSize.Menu), dir.FileName.ToString(), dir.ToString()); } paths [dir] = dit; foreach (string file in Directory.GetFiles(dir)) { string path = System.IO.Path.GetFileName(file); Gdk.Pixbuf pix = DesktopService.GetPixbufForFile(file, IconSize.Menu); bool active = itemFiles.Contains(file); string color = null; if (!active) { pix = ImageService.MakeTransparent(pix, 0.5); color = "dimgrey"; } else { cinfo |= ChildInfo.HasProjectFiles; } active = active || forceSet || knownPaths.Contains(file); if (!active) { cinfo &= ~ChildInfo.AllSelected; } else { cinfo |= ChildInfo.SomeSelected; } paths [file] = store.AppendValues(dit, active, pix, path, file, color); if (!hasChildren) { hasChildren = true; fileList.ExpandRow(store.GetPath(dit), false); } } foreach (string cdir in Directory.GetDirectories(dir)) { hasChildren = true; ChildInfo ci = FillDirRec(dit, item, itemFiles, knownPaths, cdir, forceSet); if ((ci & ChildInfo.AllSelected) == 0) { cinfo &= ~ChildInfo.AllSelected; } cinfo |= ci & (ChildInfo.SomeSelected | ChildInfo.HasProjectFiles); } if ((cinfo & ChildInfo.AllSelected) != 0 && hasChildren) { store.SetValue(dit, 0, true); } if ((cinfo & ChildInfo.HasProjectFiles) == 0) { Gdk.Pixbuf pix = DesktopService.GetPixbufForFile(dir, IconSize.Menu); pix = ImageService.MakeTransparent(pix, 0.5); store.SetValue(dit, 1, pix); store.SetValue(dit, 4, "dimgrey"); } if ((cinfo & ChildInfo.SomeSelected) != 0 && (cinfo & ChildInfo.AllSelected) == 0) { fileList.ExpandRow(store.GetPath(dit), false); } else { fileList.CollapseRow(store.GetPath(dit)); } return(cinfo); }
public GroupedTaskRunnerInformation(IWorkspaceFileObject workspaceFileObject) : this(workspaceFileObject, Enumerable.Empty <TaskRunnerInformation> ()) { }
internal void OnRootDirectoriesChanged(IWorkspaceFileObject sourceItem, bool isRemove, bool isAdd) { RootDirectoriesChanged?.Invoke(this, new RootDirectoriesChangedEventArgs(sourceItem, isRemove, isAdd)); }