Example #1
0
		protected void HandleDomClick(object sender, GeckoDomEventArgs e)
		{
			if (sender == null || e == null || e.Target == null)
				return;

			GeckoNode onClick = null;
			GeckoElement parentTable = GetParentTable(e.Target);
			if (parentTable != null)
				onClick = parentTable.Attributes["onclick"];
			if (onClick == null)
				onClick = e.Target.Attributes["onclick"];
			if (onClick == null)
				return;

			var js = onClick.TextContent;
			if (js.Contains("JumpToToolBasedOnHvo"))
			{
				JumpToToolBasedOnHvo(Int32.Parse(GetParameterFromJavaScriptFunctionCall(js)));
			}
			if (js.Contains("ShowWordGrammarDetail") || js.Contains("ButtonShowWGDetails"))
			{
				ShowWordGrammarDetail(GetParameterFromJavaScriptFunctionCall(js));
			}
			if (js.Contains("TryWordGrammarAgain") || js.Contains("ButtonTryNextPass"))
			{
				TryWordGrammarAgain(GetParameterFromJavaScriptFunctionCall(js));
			}
			if (js.Contains("GoToPreviousWordGrammarPage") || js.Contains("ButtonGoBack()"))
			{
				GoToPreviousWordGrammarPage();
			}
		}
Example #2
0
 void OnBrowserFocusChanged(object sender, GeckoDomEventArgs e)
 {
     //prevent recursion
     _browser1.WebBrowser.DomFocus -= new EventHandler <GeckoDomEventArgs>(OnBrowserFocusChanged);
     _model.BrowserFocusChanged();
     _browser1.WebBrowser.DomFocus += new EventHandler <GeckoDomEventArgs>(OnBrowserFocusChanged);
 }
Example #3
0
        private void HtmlComboBox_HtmlEvent(object o, GeckoDomEventArgs htmlEventArgs)
        {
#if PORT
            if (htmlEventArgs.Event.SrcElement == null || (htmlEventArgs.Event.SrcElement.id != "displayvalue" && htmlEventArgs.Event.SrcElement.id != "selectcontrol"))
            {
                ((IHTMLElement2)GetDisplayTextBoxElement()).Focus();
            }
#endif
        }
Example #4
0
 void browser_DomClick(object sender, GeckoDomEventArgs e)
 {
     GeckoHtmlElement element = e.Target;
     if (element.Id == Name)
     {
         if (Clicked != null)
         {
             Clicked(this, new EventArgs());
         }
     }
 }
Example #5
0
        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();
        }
Example #6
0
        void OnBrowser_DomClick(object sender, GeckoDomEventArgs e)
        {
            //this helps with a weird condition: make a new page, click in the text box, go over to another program, click in the box again.
            //it loses its focus.
            _browser.WebBrowserFocus.Activate();            //trying to help the disappearing cursor problem

            EventHandler handler = OnBrowserClick;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Example #7
0
        /// <summary>
        /// An example event handler for the DomClick event.
        /// Prevents a link click from navigating.
        /// </summary>
        void StopLinksNavigating(object sender, GeckoDomEventArgs e)
        {
            if (sender != null && e != null && e.Target != null && e.Target.TagName != null)
            {
                GeckoElement clicked = e.Target;

                // prevent clicking on Links from navigation to the
                if (clicked.TagName == "A")
                {
                    e.Handled = true;
                    MessageBox.Show(sender as IWin32Window, String.Format("You clicked on Link {0}", clicked.GetAttribute("href")));
                }
            }
        }
Example #8
0
        private void OnBrowser_DomClick(object sender, GeckoDomEventArgs e)
        {
            if (this.DesignModeAtAll())
                return;

              var ge = e as GeckoDomEventArgs;
            if (ge.Target == null)
                return;
            if (ge.Target.TagName=="A")
            {
                var url = ge.Target.GetAttribute("href");
                System.Diagnostics.Process.Start(url);
                e.Handled = true; //don't let the browser navigate itself
            }
        }
        protected void HandleDomClick(object sender, GeckoDomEventArgs e)
        {
            if (sender == null || e == null || e.Target == null)
            {
                return;
            }

            GeckoElement parentTable = GetParentTable(e.Target);

            if (parentTable == null)
            {
                return;
            }

            GeckoNode onClick = parentTable.Attributes["onclick"];

            // The next two lines are needed to fix FWNX-725, but if they're not commented out, the
            // program silently disappears shortly after the TryAWordDlg dialog is closed *if this
            // method is ever invoked by clicking on the HTML control anywhere*.  Somehow, either
            // e.Target.Attributes["onclick"] or onClick.TextContent must set some state in the browser
            // that causes this horrendous behavior.
            //if (onClick == null)
            //	onClick = e.Target.Attributes["onclick"];
            if (onClick == null)
            {
                return;
            }

            var js = onClick.TextContent;

            if (js.Contains("JumpToToolBasedOnHvo"))
            {
                JumpToToolBasedOnHvo(Int32.Parse(GetParameterFromJavaScriptFunctionCall(js)));
            }
            if (js.Contains("ShowWordGrammarDetail") || js.Contains("ButtonShowWGDetails"))
            {
                ShowWordGrammarDetail(GetParameterFromJavaScriptFunctionCall(js));
            }
            if (js.Contains("TryWordGrammarAgain"))
            {
                TryWordGrammarAgain(GetParameterFromJavaScriptFunctionCall(js));
            }
            if (js.Contains("GoToPreviousWordGrammarPage"))
            {
                GoToPreviousWordGrammarPage();
            }
        }
Example #10
0
        private void OnBrowser_DomClick(object sender, GeckoDomEventArgs e)
        {
            if (this.DesignModeAtAll())
            {
                return;
            }

            var ge = e as GeckoDomEventArgs;

            if (ge.Target == null)
            {
                return;
            }
            if (ge.Target.TagName == "A")
            {
                var url = ge.Target.GetAttribute("href");
                System.Diagnostics.Process.Start(url);
                e.Handled = true;                 //don't let the browser navigate itself
            }
        }
Example #11
0
        private static GeckoElement GetImageNode(GeckoDomEventArgs ge)
        {
            GeckoElement imageElement = null;

            foreach (var n in ge.Target.Parent.ChildNodes)
            {
                if (n is GeckoElement && ((GeckoElement)n).TagName.ToLower() == "img")
                {
                    imageElement = (GeckoElement)n;
                    break;
                }
            }

            if (imageElement == null)
            {
                Debug.Fail("Could not find image element");
                return(null);
            }
            return(imageElement);
        }
Example #12
0
        void OnBrowser_DomClick(object sender, GeckoDomEventArgs e)
        {
            //this helps with a weird condition: make a new page, click in the text box, go over to another program, click in the box again.
            //it loses its focus.
            _browser.WebBrowserFocus.Activate();//trying to help the disappearing cursor problem

            EventHandler handler = OnBrowserClick;
            if (handler != null)
                handler(this, e);
        }
Example #13
0
 void OnBrowserFocusChanged(object sender, GeckoDomEventArgs e)
 {
     //prevent recursion
     _browser1.WebBrowser.DomFocus -= new EventHandler<GeckoDomEventArgs>(OnBrowserFocusChanged);
     _model.BrowserFocusChanged();
     _browser1.WebBrowser.DomFocus += new EventHandler<GeckoDomEventArgs>(OnBrowserFocusChanged);
 }
Example #14
0
        private void OnPasteImage(GeckoDomEventArgs ge)
        {
            if (!_model.CanChangeImages())
            {
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked","Sorry, this book is locked down so that images cannot be changed."));
                return;
            }

            Image clipboardImage = null;
            try
            {
                clipboardImage = GetImageFromClipboard();
                if (clipboardImage == null)
                {
                    MessageBox.Show(
                        LocalizationManager.GetString("EditTab.NoImageFoundOnClipboard","Before you can paste an image, copy one onto your 'clipboard', from another program."));
                    return;
                }

                if (ge.Target.ClassName.Contains("licenseImage"))
                    return;

                var imageElement = GetImageNode(ge);
                if (imageElement == null)
                    return;
                Cursor = Cursors.WaitCursor;

                //nb: later, code closer to the the actual book folder will
                //improve this file name
                using (var temp = new TempFile())
                {
                    clipboardImage.Save(temp.Path, ImageFormat.Png);
            //                    using (var progressDialog = new ProgressDialogBackground())
            //                    {
            //                        progressDialog.ShowAndDoWork((progress, args) =>
            //                                                         {
            //                                                             ImageUpdater.CompressImage(temp.Path, progress);
            //                                                         });
            //                    }
                    using (var palasoImage = PalasoImage.FromFile(temp.Path))
                    {
                        _model.ChangePicture(imageElement, palasoImage, new NullProgress());
                    }
                }
            }
            catch (Exception error)
            {
                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "The program had trouble getting an image from the clipboard.");
            }
            finally
            {
                if (clipboardImage != null)
                    clipboardImage.Dispose();
            }
            Cursor = Cursors.Default;
        }
Example #15
0
        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();
        }
Example #16
0
        private void OnChangeImage(GeckoDomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);
            if (imageElement == null)
                return;
             string currentPath = imageElement.GetAttribute("src").Replace("%20", " ");

            //TODO: this would let them set it once without us bugging them, but after that if they
            //go to change it, we would bug them because we don't have a way of knowing that it was a placeholder before.
            if (!currentPath.ToLower().Contains("placeholder")  //always allow them to put in something over a placeholder
                && !_model.CanChangeImages())
            {
                if(DialogResult.Cancel== MessageBox.Show(LocalizationManager.GetString("EditTab.ImageChangeWarning","This book is locked down as shell. Are you sure you want to change the picture?"),LocalizationManager.GetString("EditTab.ChangeImage","Change Image"),MessageBoxButtons.OKCancel))
                {
                    return;
                }
            }
            if (ge.Target.ClassName.Contains("licenseImage"))
                return;

            Cursor = Cursors.WaitCursor;

            var imageInfo = new PalasoImage();
            var existingImagePath = Path.Combine(_model.CurrentBook.FolderPath, currentPath);

            //don't send the placeholder to the imagetoolbox... we get a better user experience if we admit we don't have an image yet.
            if (!currentPath.ToLower().Contains("placeholder") && File.Exists(existingImagePath))
            {
                try
                {
                    imageInfo = PalasoImage.FromFile(existingImagePath);
                }
                catch (Exception)
                {
                    //todo: log this
                }
            };
            Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog");
            using(var dlg = new ImageToolboxDialog(imageInfo, null))
            {
                if(DialogResult.OK== dlg.ShowDialog())
                {
                    // var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image);
                    try
                    {
                         _model.ChangePicture(imageElement, dlg.ImageInfo, new NullProgress());
                    }
                    catch(System.IO.IOException error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message);
                    }
                    catch (ApplicationException error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message);
                    }
                    catch (Exception error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error,"Bloom had a problem including that image");
                    }
                }
            }
            Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog");
            Cursor = Cursors.Default;
        }
Example #17
0
        private static GeckoElement GetImageNode(GeckoDomEventArgs ge)
        {
            GeckoElement imageElement = null;
            foreach (var n in ge.Target.Parent.ChildNodes)
            {
                if (n is GeckoElement && ((GeckoElement) n).TagName.ToLower() == "img")
                {
                    imageElement = (GeckoElement) n;
                    break;
                }
            }

            if (imageElement == null)
            {
                Debug.Fail("Could not find image element");
                return null;
            }
            return imageElement;
        }
Example #18
0
        private void OnChangeImage(GeckoDomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);

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

            //TODO: this would let them set it once without us bugging them, but after that if they
            //go to change it, we would bug them because we don't have a way of knowing that it was a placeholder before.
            if (!currentPath.ToLower().Contains("placeholder") &&           //always alow them to put in something over a placeholder
                !_model.CanChangeImages())
            {
                if (DialogResult.Cancel == MessageBox.Show(LocalizationManager.GetString("EditTab.ImageChangeWarning", "This book is locked down as shell. Are you sure you want to change the picture?"), LocalizationManager.GetString("EditTab.ChangeImage", "Change Image"), MessageBoxButtons.OKCancel))
                {
                    return;
                }
            }
            if (ge.Target.ClassName.Contains("licenseImage"))
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            var imageInfo         = new PalasoImage();
            var existingImagePath = Path.Combine(_model.CurrentBook.FolderPath, currentPath);

            //don't send the placeholder to the imagetoolbox... we get a better user experience if we admit we don't have an image yet.
            if (!currentPath.ToLower().Contains("placeholder") && File.Exists(existingImagePath))
            {
                try
                {
                    imageInfo = PalasoImage.FromFile(existingImagePath);
                }
                catch (Exception)
                {
                    //todo: log this
                }
            }
            ;
            Logger.WriteEvent("Showing ImageToolboxDialog Editor Dialog");
            using (var dlg = new ImageToolboxDialog(imageInfo, null))
            {
                if (DialogResult.OK == dlg.ShowDialog())
                {
                    // var path = MakePngOrJpgTempFileForImage(dlg.ImageInfo.Image);
                    try
                    {
                        _model.ChangePicture(imageElement, dlg.ImageInfo, new NullProgress());
                    }
                    catch (System.IO.IOException error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message);
                    }
                    catch (ApplicationException error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, error.Message);
                    }
                    catch (Exception error)
                    {
                        Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Bloom had a problem including that image");
                    }
                }
            }
            Logger.WriteMinorEvent("Emerged from ImageToolboxDialog Editor Dialog");
            Cursor = Cursors.Default;
        }
Example #19
0
        private void OnPasteImage(GeckoDomEventArgs ge)
        {
            if (!_model.CanChangeImages())
            {
                MessageBox.Show(
                    LocalizationManager.GetString("EditTab.CantPasteImageLocked", "Sorry, this book is locked down so that images cannot be changed."));
                return;
            }

            Image clipboardImage = null;

            try
            {
                clipboardImage = GetImageFromClipboard();
                if (clipboardImage == null)
                {
                    MessageBox.Show(
                        LocalizationManager.GetString("EditTab.NoImageFoundOnClipboard", "Before you can paste an image, copy one onto your 'clipboard', from another program."));
                    return;
                }

                if (ge.Target.ClassName.Contains("licenseImage"))
                {
                    return;
                }

                var imageElement = GetImageNode(ge);
                if (imageElement == null)
                {
                    return;
                }
                Cursor = Cursors.WaitCursor;

                //nb: later, code closer to the the actual book folder will
                //improve this file name
                using (var temp = new TempFile())
                {
                    clipboardImage.Save(temp.Path, ImageFormat.Png);
//                    using (var progressDialog = new ProgressDialogBackground())
//                    {
//                        progressDialog.ShowAndDoWork((progress, args) =>
//                                                         {
//                                                             ImageUpdater.CompressImage(temp.Path, progress);
//                                                         });
//                    }
                    using (var palasoImage = PalasoImage.FromFile(temp.Path))
                    {
                        _model.ChangePicture(imageElement, palasoImage, new NullProgress());
                    }
                }
            }
            catch (Exception error)
            {
                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "The program had trouble getting an image from the clipboard.");
            }
            finally
            {
                if (clipboardImage != null)
                {
                    clipboardImage.Dispose();
                }
            }
            Cursor = Cursors.Default;
        }