/// <summary> /// Adds the provided project item to the Altaxo project, for instance a table or a graph, to the project. If another project item with the same name already exists, /// a new unique name for the item is found, based on the given name. /// For <see cref="T:Altaxo.Main.Properties.ProjectFolderPropertyDocument"/>s, if a document with the same name is already present, the properties are merged. /// </summary> /// <param name="item">The item to add.</param> /// <exception cref="System.ArgumentNullException">item</exception> /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception> public void AddItemWithThisOrModifiedName(IProjectItem item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } if (item is Altaxo.Main.Properties.ProjectFolderPropertyDocument propertyDoc) { if (!ProjectFolderProperties.ContainsAnyName(propertyDoc.Name)) { ProjectFolderProperties.Add(propertyDoc); // if not existing, then add the new property document } else { ProjectFolderProperties[propertyDoc.Name].PropertyBagNotNull.MergePropertiesFrom(propertyDoc.PropertyBag, true); // if existing, then merge the properties into the existing bag } } else // normal case { var coll = GetCollectionForProjectItemType(item.GetType()); if (item.Name == null || item.Name == string.Empty) { item.Name = coll.FindNewItemName(); } else if (coll.ContainsAnyName(item.Name)) { item.Name = coll.FindNewItemName(item.Name); } coll.Add(item); } }
/// <summary> /// Gets the document path for project item, using its type and name. It is not neccessary that the item is part of the project yet. /// </summary> /// <param name="item">The item.</param> /// <returns>The document part for the project item, deduces from its type and its name.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public AbsoluteDocumentPath GetDocumentPathForProjectItem(IProjectItem item) { if (null == item) { throw new ArgumentNullException("item"); } return(GetRootPathForProjectItemType(item.GetType()).Append(item.Name)); }
/// <summary> /// Removes the provided project item to the Altaxo project, for instance a table or a graph, to the project. /// </summary> /// <param name="item">The item to remove.</param> /// <exception cref="System.ArgumentNullException">item</exception> /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception> public bool RemoveItem(IProjectItem item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } var coll = GetCollectionForProjectItemType(item.GetType()); return(coll.Remove(item)); }
/// <summary> /// Tests if the project item given in the argument is already contained in this document. /// </summary> /// <param name="item">The item to test.</param> /// <returns>True if the item is already contained in the document, otherwise false.</returns> /// <exception cref="System.ArgumentNullException">item</exception> /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception> public bool ContainsItem(IProjectItem item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } var coll = GetCollectionForProjectItemType(item.GetType()); return(coll.TryGetValue(item.Name, out var foundItem) && object.ReferenceEquals(foundItem, item)); }
public override void VisitProjectItem(IProjectItem projectItem) { switch (projectItem.Kind) { case ProjectItemKind.PHYSICAL_FILE: this.TextWriter.WriteLine($"{projectItem.Name,-30} {projectItem.GetType()}"); break; } base.VisitProjectItem(projectItem); }
public static bool SetObject <T>(this IProjectItem notifier, IProjectItem container, string propertyName, ref T newValue, string propertyNotifierName) where T : class { var propertyInfo = container.GetType().GetProperty(propertyName); var oldValue = (T)propertyInfo.GetValue(container, null); propertyInfo.SetValue(container, newValue, null); var result = notifier.SetObject(ref oldValue, ref newValue, propertyNotifierName); return(result); }
/// <summary> /// Shows a dialog to rename the table. /// </summary> /// <param name="projectItem">The project item to rename.</param> public static void ShowRenameDialog(IProjectItem projectItem) { string projectItemTypeName = projectItem.GetType().Name; var tvctrl = new TextValueInputController(projectItem.Name, string.Format("Enter a name for the {0}:", projectItem)) { Validator = new RenameValidator(projectItem, projectItemTypeName) }; if (Current.Gui.ShowDialog(tvctrl, string.Format("Rename {0}", projectItemTypeName), false)) { projectItem.Name = tvctrl.InputText.Trim(); } }
public RenameValidator(IProjectItem projectItem, string projectItemTypeName) : base(string.Format("The {0} name must not be empty! Please enter a valid name.", projectItemTypeName)) { if (null == projectItem) { throw new ArgumentNullException(nameof(projectItem)); } _projectItem = projectItem; _projectItemTypeName = projectItemTypeName; if (null == projectItemTypeName) { _projectItemTypeName = _projectItem.GetType().Name; } }
/// <summary> /// Tries to get an existring project item with the same type and name as the provided item. /// </summary> /// <param name="item">The item to test for.</param> /// <returns>True an item with the same type and name as the provided item exists in the project, that existing item is returned; otherwise, the return value is null.</returns> /// <exception cref="System.ArgumentNullException">item</exception> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public IProjectItem TryGetExistingItemWithSameTypeAndName(IProjectItem item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } var coll = GetCollectionForProjectItemType(item.GetType()); if (coll.Contains(item.Name)) { return(coll[item.Name]); } return(null); }
/// <summary> /// Gets an exporter that can be used to export an image of the provided project item. /// </summary> /// <param name="item">The item to export, for instance an item of type <see cref="Altaxo.Graph.Gdi.GraphDocument"/> or <see cref="Altaxo.Graph.Graph3D.GraphDocument"/>.</param> /// <returns>The image exporter class that can be used to export the item in graphical form, or null if no exporter could be found.</returns> public IProjectItemImageExporter GetProjectItemImageExporter(IProjectItem item) { IProjectItemImageExporter result = null; foreach (IProjectItemExportBindingDescriptor descriptor in AddInTree.BuildItems <IProjectItemExportBindingDescriptor>("/Altaxo/Workbench/ProjectItemExportBindings", this, false)) { if (descriptor.ProjectItemType == item.GetType()) { System.Reflection.ConstructorInfo cinfo; if (null != (cinfo = descriptor.GraphicalExporterType.GetConstructor(new Type[0]))) { result = cinfo.Invoke(new object[0]) as IProjectItemImageExporter; if (null != result) { break; } } } } return(result); }
public static BrowserListItem GetBrowserListItem(IProjectItem t, bool showFullName) { var name = showFullName ? t.Name : ProjectFolder.GetNamePart(t.Name); if (t is Altaxo.Main.Properties.ProjectFolderPropertyDocument) { name += "FolderProperties"; } else if (t is Altaxo.Text.TextDocument && Altaxo.Main.ProjectFolder.IsValidFolderName(name)) { name += "FolderNotes"; } if (!_projectItemTypesToImage.TryGetValue(t.GetType(), out var image)) { image = ProjectBrowseItemImage.OpenFolder; } return(new BrowserListItem(name, showFullName, t, false) { Image = image, CreationDate = t.CreationTimeUtc }); }
/// <summary> /// Adds the provided project item to the Altaxo project, for instance a table or a graph, to the project. For <see cref="T:Altaxo.Main.Properties.ProjectFolderPropertyDocument"/>s, /// if a document with the same name is already present, the properties are merged. /// </summary> /// <param name="item">The item to add.</param> /// <exception cref="System.ArgumentNullException">item</exception> /// <exception cref="System.ArgumentOutOfRangeException">The type of item is not yet considered here.</exception> public void AddItem(IProjectItem item) { if (null == item) { throw new ArgumentNullException(nameof(item)); } if (item is Altaxo.Main.Properties.ProjectFolderPropertyDocument propDoc) { if (!ProjectFolderProperties.Contains(propDoc.Name)) { ProjectFolderProperties.Add(propDoc); // if not existing, then add the new property document } else { ProjectFolderProperties[propDoc.Name].PropertyBagNotNull.MergePropertiesFrom(propDoc.PropertyBag, true); // if existing, then merge the properties into the existing bag } } else { var coll = GetCollectionForProjectItemType(item.GetType()); coll.Add(item); } }
private IMVCController CreateNewViewContent_Unsynchronized(IProjectItem document) { if (document == null) { throw new ArgumentNullException(nameof(document)); } // make sure that the item is already contained in the project if (!Current.Project.ContainsItem(document)) { Current.Project.AddItemWithThisOrModifiedName(document); } var types = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(AbstractViewContent)); System.Reflection.ConstructorInfo cinfo = null; object viewContent = null; foreach (Type type in types) { if (null != (cinfo = type.GetConstructor(new Type[] { document.GetType() }))) { var par = cinfo.GetParameters()[0]; if (par.ParameterType != typeof(object)) // ignore view content which takes the most generic type { viewContent = cinfo.Invoke(new object[] { document }); break; } } } if (null == viewContent) { foreach (IProjectItemDisplayBindingDescriptor descriptor in AddInTree.BuildItems <IProjectItemDisplayBindingDescriptor>("/Altaxo/Workbench/ProjectItemDisplayBindings", this, false)) { if (descriptor.ProjectItemType == document.GetType()) { if (null != (cinfo = descriptor.ViewContentType.GetConstructor(new Type[] { document.GetType() }))) { var par = cinfo.GetParameters()[0]; if (par.ParameterType != typeof(object)) // ignore view content which takes the most generic type { viewContent = cinfo.Invoke(new object[] { document }); break; } } } } } var controller = viewContent as IMVCController; if (controller.ViewObject == null) { Current.Gui.FindAndAttachControlTo(controller); } if (null != Current.Workbench) { Current.Workbench.ShowView(viewContent, true); } return(controller); }
/// <summary> /// Shows a dialog to rename the table. /// </summary> /// <param name="projectItem">The project item to rename.</param> public static void ShowRenameDialog(IProjectItem projectItem) { string projectItemTypeName = projectItem.GetType().Name; TextValueInputController tvctrl = new TextValueInputController(projectItem.Name, string.Format("Enter a name for the {0}:", projectItem)); tvctrl.Validator = new RenameValidator(projectItem, projectItemTypeName); if (Current.Gui.ShowDialog(tvctrl, string.Format("Rename {0}", projectItemTypeName), false)) projectItem.Name = tvctrl.InputText.Trim(); }
private IMVCController CreateNewViewContent_Unsynchronized(IProjectItem document) { if (document == null) throw new ArgumentNullException(nameof(document)); // make sure that the item is already contained in the project if (!Current.Project.ContainsItem(document)) Current.Project.AddItemWithThisOrModifiedName(document); var types = Altaxo.Main.Services.ReflectionService.GetNonAbstractSubclassesOf(typeof(ICSharpCode.SharpDevelop.Gui.AbstractViewContent)); System.Reflection.ConstructorInfo cinfo = null; object viewContent = null; foreach (Type type in types) { if (null != (cinfo = type.GetConstructor(new Type[] { document.GetType() }))) { var par = cinfo.GetParameters()[0]; if (par.ParameterType != typeof(object)) // ignore view content which takes the most generic type { viewContent = cinfo.Invoke(new object[] { document }); break; } } } if (null == viewContent) { foreach (IProjectItemDisplayBindingDescriptor descriptor in AddInTree.BuildItems<IProjectItemDisplayBindingDescriptor>("/Altaxo/Workbench/ProjectItemDisplayBindings", this, false)) { if (descriptor.ProjectItemType == document.GetType()) { if (null != (cinfo = descriptor.ViewContentType.GetConstructor(new Type[] { document.GetType() }))) { var par = cinfo.GetParameters()[0]; if (par.ParameterType != typeof(object)) // ignore view content which takes the most generic type { viewContent = cinfo.Invoke(new object[] { document }); break; } } } } } var viewContentAsControllerWrapper = viewContent as Altaxo.Gui.IMVCControllerWrapper; if (null == viewContentAsControllerWrapper) throw new InvalidOperationException("All Altaxo classes implementing SDGraphViewContent have to implement IMVCControllerWrapper, too!"); if (viewContentAsControllerWrapper.MVCController.ViewObject == null) { Current.Gui.FindAndAttachControlTo(viewContentAsControllerWrapper.MVCController); } if (null != Current.Workbench) Current.Workbench.ShowView(viewContent); return viewContentAsControllerWrapper.MVCController; }
/// <summary> /// Gets an exporter that can be used to export an image of the provided project item. /// </summary> /// <param name="item">The item to export, for instance an item of type <see cref="Altaxo.Graph.Gdi.GraphDocument"/> or <see cref="Altaxo.Graph.Graph3D.GraphDocument"/>.</param> /// <returns>The image exporter class that can be used to export the item in graphical form, or null if no exporter could be found.</returns> public IProjectItemImageExporter GetProjectItemImageExporter(IProjectItem item) { IProjectItemImageExporter result = null; foreach (IProjectItemExportBindingDescriptor descriptor in AddInTree.BuildItems<IProjectItemExportBindingDescriptor>("/Altaxo/Workbench/ProjectItemExportBindings", this, false)) { if (descriptor.ProjectItemType == item.GetType()) { System.Reflection.ConstructorInfo cinfo; if (null != (cinfo = descriptor.GraphicalExporterType.GetConstructor(new Type[0]))) { result = cinfo.Invoke(new object[0]) as IProjectItemImageExporter; if (null != result) break; } } } return result; }
public RenameValidator(IProjectItem projectItem, string projectItemTypeName) : base(string.Format("The {0} name must not be empty! Please enter a valid name.", projectItemTypeName)) { if (null == projectItem) throw new ArgumentNullException(nameof(projectItem)); _projectItem = projectItem; _projectItemTypeName = projectItemTypeName; if (null == projectItemTypeName) _projectItemTypeName = _projectItem.GetType().Name; }