コード例 #1
0
        private void OnEditImageMetdata(DomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);

            if (imageElement == null)
            {
                return;
            }
            string fileName = imageElement.GetAttribute("src").Replace("%20", " ");

            var path = Path.Combine(_model.CurrentBook.FolderPath, fileName);

            using (var imageInfo = PalasoImage.FromFile(path))
            {
                bool looksOfficial = imageInfo.Metadata != null && !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri);
                if (looksOfficial)
                {
                    MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en"));
                    return;
                }
                Logger.WriteEvent("Showing Metadata Editor For Image");
                using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata))
                {
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        imageInfo.Metadata = dlg.Metadata;
                        imageInfo.SaveUpdatedMetadataIfItMakesSense();
                        imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image);
                        //update so any overlays on the image are brough up to data
                        var editor = new PageEditingModel();
                        editor.UpdateMetdataAttributesOnImgElement(imageElement, imageInfo);

                        var answer = MessageBox.Show(LocalizationManager.GetString("EditTab.copyImageIPMetdataQuestion", "Copy this information to all other pictures in this book?", "get this after you edit the metadata of an image"), LocalizationManager.GetString("EditTab.titleOfCopyIPToWholeBooksDialog", "Picture Intellectual Property Information"), MessageBoxButtons.YesNo);
                        if (answer == DialogResult.Yes)
                        {
                            Cursor = Cursors.WaitCursor;
                            try
                            {
                                _model.CopyImageMetadataToWholeBook(dlg.Metadata);
                                // There might be more than one image on this page. Update overlays.
                                _model.RefreshDisplayOfCurrentPage();
                            }
                            catch (Exception e)
                            {
                                ErrorReport.NotifyUserOfProblem(e, "There was a problem copying the metadata to all the images.");
                            }
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }

            //_model.SaveNow();
            //doesn't work: _browser1.WebBrowser.Reload();
        }
コード例 #2
0
 public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged()
 {
     var dom = new XmlDocument();
     dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");
     var model = new PageEditingModel();
     using (var src = new TemporaryFolder("bloom pictures test source"))
     using (var dest = new TemporaryFolder("bloom picture tests dest"))
     {
         var newImagePath = src.Combine("new.png");
         using (var original = MakeSamplePngImage(newImagePath))
         {
             model.ChangePicture(dest.Path, dom, "two", original);
             Assert.IsTrue(File.Exists(dest.Combine("new.png")));
             AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1);
         }
     }
 }
コード例 #3
0
 public void ChangePicture_PictureIsJpg_StaysJpg()
 {
     var dom = new XmlDocument();
     dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");
     var model = new PageEditingModel();
     using (var src = new TemporaryFolder("bloom pictures test source"))
     using (var dest = new TemporaryFolder("bloom picture tests dest"))
     using (var original = MakeSampleJpegImage(src.Combine("new.jpg")))
     {
         model.ChangePicture(dest.Path, dom, "two", original);
         Assert.IsTrue(File.Exists(dest.Combine("new.jpg")));
         AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.jpg']", 1);
         using (var converted = Image.FromFile(dest.Combine("new.jpg")))
         {
             Assert.AreEqual(ImageFormat.Jpeg.Guid, converted.RawFormat.Guid);
         }
     }
 }
コード例 #4
0
 public void ChangePicture_AlreadyHaveACopyInPublicationFolder_PictureUpdated()
 {
     var dom = new XmlDocument();
     dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");
     var model = new PageEditingModel();
     using (var src = new TemporaryFolder("bloom pictures test source"))
     using (var dest = new TemporaryFolder("bloom picture tests dest"))
     {
         var dogImagePath = src.Combine("dog.png");
         using (var original = MakeSamplePngImage(dogImagePath))
         {
             var destDogImagePath = dest.Combine("dog.png");
             File.WriteAllText(destDogImagePath, "old dog");
             model.ChangePicture(dest.Path, dom, "two", original);
             Assert.IsTrue(Image.FromFile(destDogImagePath).Width == kSampleImageDimension);
         }
     }
 }
コード例 #5
0
        public void ChangePicture(GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress)
        {
            try
            {
                Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName);
                var editor = new PageEditingModel();
                editor.ChangePicture(_bookSelection.CurrentSelection.FolderPath, img, imageInfo, progress);

                //we have to save so that when asked by the thumbnailer, the book will give the proper image
                SaveNow();
                //but then, we need the non-cleaned version back there
                _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection);

                _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection);
                Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName);
                Analytics.Track("Change Picture");
                Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName);
            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, "Could not change the picture");
            }
        }
コード例 #6
0
ファイル: EditingView.cs プロジェクト: jorik041/BloomDesktop
        private void OnEditImageMetdata(GeckoDomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);
            if (imageElement == null)
                return;
            string fileName = imageElement.GetAttribute("src").Replace("%20", " ");

            var path = Path.Combine(_model.CurrentBook.FolderPath, fileName);
            using (var imageInfo = PalasoImage.FromFile(path))
            {
                bool looksOfficial = imageInfo.Metadata!=null && !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri);
                if(looksOfficial)
                {
                    MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en"));
                    return;
                }
                Logger.WriteEvent("Showing Metadata Editor For Image");
                using (var dlg = new Palaso.UI.WindowsForms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata))
                {
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        imageInfo.Metadata = dlg.Metadata;
                        imageInfo.SaveUpdatedMetadataIfItMakesSense();
                        imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image);
                        //update so any overlays on the image are brough up to data
                        var editor = new PageEditingModel();
                        editor.UpdateMetdataAttributesOnImgElement(imageElement, imageInfo);

                        var answer = MessageBox.Show(LocalizationManager.GetString("EditTab.copyImageIPMetdataQuestion","Copy this information to all other pictures in this book?", "get this after you edit the metadata of an image"), LocalizationManager.GetString("EditTab.titleOfCopyIPToWholeBooksDialog","Picture Intellectual Property Information"), MessageBoxButtons.YesNo);
                        if(answer == DialogResult.Yes)
                        {
                            Cursor = Cursors.WaitCursor;
                            try
                            {
                                _model.CopyImageMetadataToWholeBook(dlg.Metadata);
                            }
                            catch (Exception e)
                            {
                                ErrorReport.NotifyUserOfProblem(e, "There was a problem copying the metadata to all the images.");
                            }
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }

            //_model.SaveNow();
            //doesn't work: _browser1.WebBrowser.Reload();
        }
コード例 #7
0
ファイル: EditingModel.cs プロジェクト: JohnThomson/testBloom
        public void ChangePicture(GeckoElement img, PalasoImage imageInfo, IProgress progress)
        {
            try
            {
                Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName);
                var editor = new PageEditingModel();
                editor.ChangePicture(_bookSelection.CurrentSelection.FolderPath, img, imageInfo, progress);

                //we have to save so that when asked by the thumbnailer, the book will give the proper image
                SaveNow();
                //but then, we need the non-cleaned version back there
                _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection);

                _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection);
                Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName);
                Analytics.Track("Change Picture");
                Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName);

            }
            catch (Exception e)
            {
                ErrorReport.NotifyUserOfProblem(e, "Could not change the picture");
            }
        }
コード例 #8
0
        public void ChangePicture(GeckoHtmlElement img, PalasoImage imageInfo, IProgress progress)
        {
            try
            {
                Logger.WriteMinorEvent("Starting ChangePicture {0}...", imageInfo.FileName);
                var editor = new PageEditingModel();
                editor.ChangePicture(CurrentBook.FolderPath, new ElementProxy(img), imageInfo, progress);

                // We need to save so that when asked by the thumbnailer, the book will give the proper image
                SaveNow();

                // BL-3717: if we cleanup unused image files whenever we change a picture then Cut can lose
                // all of an image's metadata (because the actual file is missing from the book folder when we go to
                // paste in the image that was copied onto the clipboard, which doesn't have metadata.)
                // Let's only do this on ExpensiveIntialization() when loading a book.
                //CurrentBook.Storage.CleanupUnusedImageFiles();

                // But after saving, we need the non-cleaned version back there
                _view.UpdateSingleDisplayedPage(_pageSelection.CurrentSelection);

                _view.UpdateThumbnailAsync(_pageSelection.CurrentSelection);
                Logger.WriteMinorEvent("Finished ChangePicture {0} (except for async thumbnail) ...", imageInfo.FileName);
                Analytics.Track("Change Picture");
                Logger.WriteEvent("ChangePicture {0}...", imageInfo.FileName);

            }
            catch (Exception e)
            {
                var msg = LocalizationManager.GetString("Errors.ProblemImportingPicture","Bloom had a problem importing this picture.");
                ErrorReport.NotifyUserOfProblem(e, msg+Environment.NewLine+e.Message);
            }
        }