public void CreateCustomLibrary(Guid libraryId, string libraryName) { if (string.IsNullOrEmpty(libraryName)) { throw new ArgumentException("libraryName cannot be empty"); } var doc = ServiceLocator.Current.GetInstance <IDocumentService>(); try { var iloadLibrary = doc.LibraryManager.GetLibrary(libraryId); if (iloadLibrary != null && !this.WidgetExpands.Any(e => e.LibraryGID == libraryId)) { var path = System.IO.Path.Combine( this.CreateLibraryFolder(libraryId), string.Format("{0}.libpn", libraryName)); iloadLibrary.Save(path); var expand = new WidgetExpand { LibraryGID = iloadLibrary.Guid, Header = iloadLibrary.Title, FileName = iloadLibrary.Name, IsCustomWidget = true, IsExpand = true, ExpandCache = true }; foreach (var customObject in iloadLibrary.CustomObjects) { var bytes = default(byte[]); if (customObject.Icon != null) { bytes = new byte[customObject.Icon.Length]; customObject.Icon.Read(bytes, 0, bytes.Length); } var widgetModel = new WidgetModel { Id = customObject.Guid, Name = customObject.Name, Icon = bytes != null?Convert.ToBase64String(bytes) : null, LbrType = "custom" }; expand.WidgetModels.Insert(0, widgetModel); } this.WidgetExpands.Insert(1, expand); var _ListEventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>(); _ListEventAggregator.GetEvent <CustomWidgetChangedEvent>().Publish(expand); } } catch (Exception ex) { NLogger.Warn("Failed to create custom library. ex:{0}", ex.ToString()); MessageBox.Show(ex.ToString()); } }
private void FixStatusOfExpand(WidgetExpand expand) { if (string.IsNullOrEmpty(_textSearch)) { /// normal condition expand.IsExpand = expand.ExpandCache; expand.IsVisible = true; if (expand.TabType != null && expand.Header.StartsWith(expand.TabType)) { expand.Header = expand.Header.Substring(expand.TabType.Length); } } else { /// search condition if (expand.WidgetModels.Any(wm => wm.IsVisible)) { if (string.IsNullOrEmpty(_lastSearchText)) { expand.ExpandCache = expand.IsExpand; } expand.IsExpand = true; expand.IsVisible = true; if (expand.TabType != null && !expand.Header.StartsWith(expand.TabType)) { expand.Header = expand.TabType + expand.Header; } } else { expand.IsVisible = false; } } if (expand.WidgetModels.Any(wm => wm.IsVisible)) { expand.IsFavoriteHintVisible = false; expand.IsLibraryHintVisible = false; } else { if (expand.Header == FavouriteExpandHeader) { expand.IsFavoriteHintVisible = true; } else { expand.IsLibraryHintVisible = true; } } }
private void InsertLibrary(ILibrary library, int insertIndex) { var expand = new WidgetExpand { LibraryGID = library.Guid, Header = library.Title, FileName = library.Name, IsCustomWidget = true, IsExpand = true, ExpandCache = true }; foreach (var customObject in library.CustomObjects) { var bytes = default(byte[]); if (customObject.Icon != null) { bytes = new byte[customObject.Icon.Length]; customObject.Icon.Read(bytes, 0, bytes.Length); } var widgetModel = new WidgetModel { Id = customObject.Guid, Name = customObject.Name, Icon = bytes != null?Convert.ToBase64String(bytes) : null, LbrType = "custom" }; expand.WidgetModels.Add(widgetModel); } this.WidgetExpands.Insert(insertIndex, expand); var _ListEventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>(); _ListEventAggregator.GetEvent <CustomWidgetChangedEvent>().Publish(expand); }
private DataObject GetItemInfo(WidgetModel widgetModel) { if (widgetModel.LbrType.StartsWith("lbw")) { // XamlWriter.Save() has limitations in exactly what is serialized, // see SDK documentation; short term solution only; return(new DataObject("DESIGNER_ITEM", widgetModel.LbrType)); } else if (widgetModel.EnumType == WidgetModelType.svg) { string szURl = widgetModel.SvgIcon; try { Uri uri = new Uri(@"pack://application:,,,/Naver.Compass.Module.WidgetLibrary;component/Resources/" + szURl, UriKind.RelativeOrAbsolute); if (szURl.EndsWith(".svg")) { return(new DataObject("SVG_ITEM", uri)); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); return(null); } } else if (widgetModel.LbrType == "custom") { try { var parantToolbox = Naver.Compass.Module.VisualTreeEx.GetAncestor <Toolbox>(this); if (parantToolbox.DataContext is WidgetExpand) { WidgetExpand parentLibrary = null; if ((this.DataContext as WidgetModel).IsFavourite) { //widget which is custom and is favourite var gallery = Naver.Compass.Module.VisualTreeEx.GetAncestor <WidgetGallery>(this); //get parent expand in UI tab. var uiExpands = (gallery.DataContext as WidgetGalleryViewModel).UIWidgetLibraryTab.WidgetExpands; foreach (var expand in uiExpands) { if (expand.WidgetModels.Contains(widgetModel)) { parentLibrary = expand; } } } else {//common custom widget parentLibrary = parantToolbox.DataContext as WidgetExpand; } if (parentLibrary == null) { return(null); } if (!File.Exists(parentLibrary.Raw_FileName)) { MessageBox.Show(GlobalData.FindResource("Error_LibFile_Not_Exit")); return(null); } return(new DataObject( "CUSTOM_ITEM", new Tuple <Guid, string, Guid, string>( parentLibrary.LibraryGID, parentLibrary.Raw_FileName, widgetModel.Id, parentLibrary.Header))); } } catch { return(null); } } return(null); }