public void CreateLibrary() { try { RenameWindow win = new RenameWindow(); win.NewName = CommonDefine.Untitled; win.Owner = Application.Current.MainWindow; win.ShowDialog(); if (win.Result.HasValue && win.Result.Value) { string libraryName = win.NewName; string objectName = CommonDefine.Untitled; ISerializeWriter writer = GetSerializeWriter(ref objectName); if (writer == null) { return; } //Create a new Library. Thumbnail is empty now, and waiting for a improvement IDocumentService DocService = ServiceLocator.Current.GetInstance <IDocumentService>(); ILibrary newLibrary = DocService.LibraryManager.CreateLibrary(writer, objectName, CreateIconImage(false), null); if (newLibrary != null) { ICustomLibraryService customLibraryService = ServiceLocator.Current.GetInstance <ICustomLibraryService>(); customLibraryService.GetMyLibrary().CreateCustomLibrary(newLibrary.Guid, libraryName); } } } catch (Exception ex) { NLogger.Warn("Add Library failed. ex:{0}", ex.ToString()); MessageBox.Show(GlobalData.FindResource("Error_Create_Library") + ex.Message); } }
private void AddLibrary2Menu(ContextMenu contextMenu) { if (_document == null) { return; } ContextMenuItem addToLibrary = new ContextMenuItem(GlobalData.FindResource("ContextMenu_AddToLibrary")); addToLibrary.Style = Application.Current.TryFindResource("librarymenu") as Style; ICustomLibraryService customLibraryService = ServiceLocator.Current.GetInstance <ICustomLibraryService>(); foreach (ICustomLibrary item in customLibraryService.GetAllCustomLibraies()) { //don't add current library to library list. if (_document.DocumentType == DocumentType.Library && item.LibraryGID == _document.Guid) { continue; } string itemHeader = item.Header; if (item.TabType != null && item.Header.StartsWith(item.TabType)) { itemHeader = item.Header.Substring(item.TabType.Length); } addToLibrary.Items.Add(new ContextMenuItem(itemHeader, AddToLibraryCommand, item)); addToLibrary.Tag = "limit"; } addToLibrary.Items.Add(new ContextMenuItem(GlobalData.FindResource("ContextMenu_AddLibrary"), AddLibraryCommand)); contextMenu.Items.Add(addToLibrary); contextMenu.Items.Add(new ContextMenuItem(GlobalData.FindResource("ContextMenu_ExportToLibrary"), ExportToLibraryCommand)); contextMenu.Items.Add(new Separator()); }
/// <summary> /// Создаёт новый экземпляр <see cref="CustomLibraryController"/> /// </summary> public CustomLibraryController(ICurrentObjectContextProvider currentObjectContextProvider, ICustomLibraryService customLibraryService) { this.currentObjectContextProvider = currentObjectContextProvider; this.customLibraryService = customLibraryService; }