public void CleanUp() { if (Designer != null) { Designer.CleanUp(); } ImageSelectionList.RemoveAt(0); StoragePath.Save(ImageSelectionList); }
/// <summary> /// Add image by downloading /// </summary> /// <param name="downloadLink"></param> /// <param name="contentSlide"></param> /// <param name="slideWidth"></param> /// <param name="slideHeight"></param> public void AddImageSelectionListItem(string downloadLink, Slide contentSlide, float slideWidth, float slideHeight) { if (StringUtil.IsEmpty(downloadLink) || !UrlUtil.IsUrlValid(downloadLink)) // Case 1: If url not valid { View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorUrlLinkIncorrect); return; } var item = new ImageItem { ImageFile = StoragePath.LoadingImgPath, ContextLink = downloadLink }; UrlUtil.GetMetaInfo(ref downloadLink, item); ImageSelectionList.Add(item); IsActiveDownloadProgressRing.Flag = true; var imagePath = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); ImageDownloader .Get(downloadLink, imagePath) .After(() => { try { VerifyIsProperImage(imagePath); // Case 2: not a proper image item.UpdateDownloadedImage(imagePath); if (ImageSelectionListSelectedItem.ImageItem != null && imagePath == ImageSelectionListSelectedItem.ImageItem.ImageFile) { UpdatePreviewImages(ImageSelectionListSelectedItem.ImageItem, contentSlide, slideWidth, slideHeight); } } catch { View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorImageDownloadCorrupted); ImageSelectionList.Remove(item); } finally { IsActiveDownloadProgressRing.Flag = false; } }) // Case 3: Possibly network timeout .OnError(e => { IsActiveDownloadProgressRing.Flag = false; ImageSelectionList.Remove(item); View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorFailedToLoad + e.Message); }) .Start(); }
public void CleanUp() { if (Designer != null) { Designer.CleanUp(); } ImageSelectionList.RemoveAt(0); StoragePath.Save(ImageSelectionList); StoragePath.Save(Settings); Logger.Log("ViewModel clean up done"); }
private List <ImageItem> GetLast8Pictures(int selectedIdOfVariationList) { if (!IsInPictureVariation()) { return(new List <ImageItem>()); } try { var subPictureList = ImageSelectionList.Skip(Math.Max(1, ImageSelectionList.Count - 8)); var result = new List <ImageItem>(subPictureList); while (result.Count < 8) { result.Add(View.CreateDefaultPictureItem()); } if (ImageSelectionListSelectedItem.ImageItem != null && !result.Contains(ImageSelectionListSelectedItem.ImageItem)) { result[selectedIdOfVariationList] = ImageSelectionListSelectedItem.ImageItem; } else if (ImageSelectionListSelectedItem.ImageItem == null) { for (var i = 0; i < result.Count; i++) { if (result[i].ImageFile == StoragePath.NoPicturePlaceholderImgPath) { result[i] = result[selectedIdOfVariationList]; break; } } result[selectedIdOfVariationList] = View.CreateDefaultPictureItem(); } else if (selectedIdOfVariationList >= 0) // contains selected item, need swap to selected index { var indexToSwap = result.IndexOf(ImageSelectionListSelectedItem.ImageItem); var tempItem = result[selectedIdOfVariationList]; result[selectedIdOfVariationList] = ImageSelectionListSelectedItem.ImageItem; result[indexToSwap] = tempItem; } return(result); } catch (Exception e) { View.ShowErrorMessageBox("Failed when generating picture aspect.", e); Logger.LogException(e, "GetLast8Pictures"); return(new List <ImageItem>()); } }
public void UpdatePictureInPictureVariationWhenDeleteSome() { Logger.Log("Check for update picture in picture aspect when deleted some"); Logger.Log("is in picture aspect: " + IsInPictureVariation()); if (!IsInPictureVariation()) { return; } for (var i = 0; i < _8PicturesInPictureVariation.Count; i++) { var imageItem = _8PicturesInPictureVariation[i]; if (ImageSelectionList.IndexOf(imageItem) == -1) { _8PicturesInPictureVariation[i] = View.CreateDefaultPictureItem(); } } }
public void ApplyStyleInVariationStage(Slide contentSlide, float slideWidth, float slideHeight) { Logger.Log("Apply style in variation stage begins"); var copiedPicture = LoadClipboardPicture(); try { Designer.ApplyStyle( IsInPictureVariation() ? GetSelectedPictureInPictureVariation( StylesVariationListSelectedId.Number) : ImageSelectionListSelectedItem.ImageItem, contentSlide, slideWidth, slideHeight); if (IsInPictureVariation()) { // select the picture if possible var targetPicture = GetSelectedPictureInPictureVariation( StylesVariationListSelectedId.Number); if (targetPicture.ImageFile != StoragePath.NoPicturePlaceholderImgPath) { var indexForTargetPicture = ImageSelectionList.IndexOf(targetPicture); if (indexForTargetPicture == -1) { ImageSelectionList.Add(targetPicture); ImageSelectionListSelectedId.Number = ImageSelectionList.Count - 1; } else { ImageSelectionListSelectedId.Number = indexForTargetPicture; } } } View.ShowSuccessfullyAppliedDialog(); } catch (Exception e) { View.ShowErrorMessageBox(PictureSlidesLabText.ErrorNoSelectedSlide); Logger.LogException(e, "ApplyStyleInVariationStage"); } SaveClipboardPicture(copiedPicture); Logger.Log("Apply style in variation stage done"); }
/// <summary> /// Add image from local files /// </summary> /// <param name="filenames"></param> /// <param name="contentSlide"></param> /// <param name="slideWidth"></param> /// <param name="slideHeight"></param> public void AddImageSelectionListItem(string[] filenames, Slide contentSlide, float slideWidth, float slideHeight) { try { Logger.Log("Add local picture begins"); var isToSelectPicture = ImageSelectionList.Count == 1; foreach (var filename in filenames) { VerifyIsProperImage(filename); var fromFileItem = new ImageItem { ImageFile = ImageUtil.GetThumbnailFromFullSizeImg(filename), FullSizeImageFile = filename, ContextLink = filename, Source = "local drive", Tooltip = ImageUtil.GetWidthAndHeight(filename) }; //add it ImageSelectionList.Add(fromFileItem); UpdatePictureInPictureVariationWhenAddedNewOne(fromFileItem); } if (IsInPictureVariation() && filenames.Length > 0) { UpdatePreviewImages( ImageSelectionListSelectedItem.ImageItem ?? View.CreateDefaultPictureItem(), contentSlide, slideWidth, slideHeight); } if (isToSelectPicture) { ImageSelectionListSelectedId.Number = 1; } Logger.Log("Add local picture done"); } catch (Exception e) { // not an image or image is corrupted View.ShowErrorMessageBox(PictureSlidesLabText.ErrorImageCorrupted); Logger.LogException(e, "AddImageSelectionListItem"); } }
/// <summary> /// Add images from local files /// </summary> /// <param name="filenames"></param> public void AddImageSelectionListItem(string[] filenames) { try { foreach (var filename in filenames) { VerifyIsProperImage(filename); var fromFileItem = new ImageItem { ImageFile = ImageUtil.GetThumbnailFromFullSizeImg(filename), FullSizeImageFile = filename, ContextLink = filename, Tooltip = ImageUtil.GetWidthAndHeight(filename) }; //add it ImageSelectionList.Add(fromFileItem); } } catch { // not an image or image is corrupted View.ShowErrorMessageBox(TextCollection.PictureSlidesLabText.ErrorImageCorrupted); } }
/// <summary> /// This method implements the way to guide the user step by step to customize /// style /// </summary> public void UpdateStepByStepStylesVariationImages(ImageItem source, Slide contentSlide, float slideWidth, float slideHeight) { Logger.Log("Check for step by step preview"); Logger.Log("current variation list selected id is " + StylesVariationListSelectedId.Number); Logger.Log("variants category count is " + VariantsCategory.Count); if (StylesVariationListSelectedId.Number < 0 || VariantsCategory.Count == 0) { return; } Logger.Log("Step by step preview begins"); var targetVariationSelectedIndex = StylesVariationListSelectedId.Number; var targetVariant = _styleVariants[_previousVariantsCategory][targetVariationSelectedIndex]; foreach (var option in _styleOptions) { targetVariant.Apply(option); } var currentVariantsCategory = CurrentVariantCategory.Text; if (currentVariantsCategory != PictureSlidesLabText.VariantCategoryFontColor && _previousVariantsCategory != PictureSlidesLabText.VariantCategoryFontColor) { // apply font color variant, // because default styles may contain special font color settings, but not in variants var fontColorVariant = new StyleVariant(new Dictionary <string, object> { { "FontColor", _styleOptions[targetVariationSelectedIndex].FontColor } }); foreach (var option in _styleOptions) { fontColorVariant.Apply(option); } } var nextCategoryVariants = _styleVariants[currentVariantsCategory]; if (currentVariantsCategory == PictureSlidesLabText.VariantCategoryFontFamily) { var isFontInVariation = false; var currentFontFamily = _styleOptions[targetVariationSelectedIndex].FontFamily; foreach (var variant in nextCategoryVariants) { if (currentFontFamily == (string)variant.Get("FontFamily")) { isFontInVariation = true; } } if (!isFontInVariation && targetVariationSelectedIndex >= 0 && targetVariationSelectedIndex < nextCategoryVariants.Count) { nextCategoryVariants[targetVariationSelectedIndex] .Set("FontFamily", currentFontFamily); nextCategoryVariants[targetVariationSelectedIndex] .Set("OptionName", currentFontFamily); } } int pictureIndexToSelect = -1; // Enter picture variation for the first time if (CurrentVariantCategory.Text == PictureSlidesLabText.VariantCategoryPicture && !_isPictureVariationInit) { _8PicturesInPictureVariation = GetLast8Pictures(targetVariationSelectedIndex); _isPictureVariationInit = true; } // Enter picture variation again else if (CurrentVariantCategory.Text == PictureSlidesLabText.VariantCategoryPicture && _isPictureVariationInit) { var isPictureSwapped = false; for (var i = 0; i < _8PicturesInPictureVariation.Count; i++) { // swap the picture to the current selected id in // variation list var picture = _8PicturesInPictureVariation[i]; if ((ImageSelectionListSelectedItem.ImageItem == null && picture.ImageFile == StoragePath.NoPicturePlaceholderImgPath) || (ImageSelectionListSelectedItem.ImageItem != null && picture.ImageFile == ImageSelectionListSelectedItem.ImageItem.ImageFile)) { var tempPic = _8PicturesInPictureVariation[targetVariationSelectedIndex]; _8PicturesInPictureVariation[targetVariationSelectedIndex] = picture; _8PicturesInPictureVariation[i] = tempPic; isPictureSwapped = true; break; } } if (!isPictureSwapped) { // if the current picture doesn't exist in the _8PicturesInPictureVariation // directly overwrite the existing one at the selected id UpdateSelectedPictureInPictureVariation(); } } // Exit picture variation else if (_previousVariantsCategory == PictureSlidesLabText.VariantCategoryPicture) { // use the selected picture in the picture variation to preview var targetPicture = _8PicturesInPictureVariation[targetVariationSelectedIndex]; if (targetPicture.ImageFile != StoragePath.NoPicturePlaceholderImgPath) { var indexForTargetPicture = ImageSelectionList.IndexOf(targetPicture); if (indexForTargetPicture == -1) { ImageSelectionList.Add(targetPicture); pictureIndexToSelect = ImageSelectionList.Count - 1; } else { pictureIndexToSelect = indexForTargetPicture; } } else // target picture is the default picture { // enter default picture mode View.EnterDefaultPictureMode(); source = View.CreateDefaultPictureItem(); } } var variantIndexWithoutEffect = -1; for (var i = 0; i < nextCategoryVariants.Count; i++) { if (nextCategoryVariants[i].IsNoEffect(_styleOptions[targetVariationSelectedIndex])) { variantIndexWithoutEffect = i; break; } } // swap the no-effect variant with the current selected style's corresponding variant // so that to achieve an effect: jumpt between different category wont change the // selected style if (variantIndexWithoutEffect != -1) { var temp = nextCategoryVariants[variantIndexWithoutEffect]; nextCategoryVariants[variantIndexWithoutEffect] = nextCategoryVariants[targetVariationSelectedIndex]; nextCategoryVariants[targetVariationSelectedIndex] = temp; } for (var i = 0; i < nextCategoryVariants.Count && i < _styleOptions.Count; i++) { nextCategoryVariants[i].Apply(_styleOptions[i]); } _previousVariantsCategory = currentVariantsCategory; Logger.Log("picture index to select is " + pictureIndexToSelect); if (pictureIndexToSelect == -1 || pictureIndexToSelect == ImageSelectionListSelectedId.Number) { UpdateStylesVariationImagesAfterOpenFlyout(source, contentSlide, slideWidth, slideHeight); } else { ImageSelectionListSelectedId.Number = pictureIndexToSelect; } Logger.Log("Step by step preview done"); }
/// <summary> /// Add image by downloading /// </summary> /// <param name="downloadLink"></param> /// <param name="contentSlide"></param> /// <param name="slideWidth"></param> /// <param name="slideHeight"></param> public void AddImageSelectionListItem(string downloadLink, Slide contentSlide, float slideWidth, float slideHeight) { if (StringUtil.IsEmpty(downloadLink) || !UrlUtil.IsUrlValid(downloadLink)) // Case 1: If url not valid { View.ShowErrorMessageBox(PictureSlidesLabText.ErrorUrlLinkIncorrect); Logger.Log("Url link error when add internet image"); return; } var item = new ImageItem { ImageFile = StoragePath.LoadingImgPath, ContextLink = downloadLink, Source = downloadLink }; UrlUtil.GetMetaInfo(ref downloadLink, item); ImageSelectionList.Add(item); IsActiveDownloadProgressRing.Flag = true; var imagePath = StoragePath.GetPath("img-" + DateTime.Now.GetHashCode() + "-" + Guid.NewGuid().ToString().Substring(0, 7)); ImageDownloader .Get(downloadLink, imagePath) .After((AutoUpdate.Downloader.AfterDownloadEventDelegate)(() => { try { Logger.Log("Add internet picture begins"); VerifyIsProperImage(imagePath); // Case 2: not a proper image item.UpdateDownloadedImage(imagePath); UpdatePictureInPictureVariationWhenAddedNewOne(item); if (ImageSelectionListSelectedItem.ImageItem != null && imagePath == ImageSelectionListSelectedItem.ImageItem.FullSizeImageFile) { UpdatePreviewImages(ImageSelectionListSelectedItem.ImageItem, contentSlide, slideWidth, slideHeight); } else if (IsInPictureVariation()) { UpdatePreviewImages( ImageSelectionListSelectedItem.ImageItem ?? View.CreateDefaultPictureItem(), contentSlide, slideWidth, slideHeight); } Logger.Log("Add internet picture ends"); } catch (Exception e) { View.ShowErrorMessageBox(PictureSlidesLabText.ErrorImageDownloadCorrupted); ImageSelectionList.Remove(item); Logger.LogException(e, "AddImageSelectionListItem (download)"); } finally { IsActiveDownloadProgressRing.Flag = false; } })) // Case 3: Possibly network timeout .OnError((AutoUpdate.Downloader.ErrorEventDelegate)(e => { IsActiveDownloadProgressRing.Flag = false; ImageSelectionList.Remove(item); View.ShowErrorMessageBox(PictureSlidesLabText.ErrorFailedToLoad + e.Message); })) .Start(); }
public void RemoveAllImageSelectionListItems() { ImageSelectionList.Clear(); ImageSelectionList.Add(CreateChoosePicturesItem()); Logger.Log("Clear all images done"); }
public void RemoveAllImageSelectionListItems() { ImageSelectionList.Clear(); ImageSelectionList.Add(CreateChoosePicturesItem()); }