Skip to content

Commit 617c129

Browse files
authored
LT-22182 Add "Find" to sketch and Try a Word (#480)
* LT-22182 Add "Find" to sketch and Try a Word Change-Id: I3daa53c57e08fc018b6334760dd3e9d057309726 * LT-22182 Use enum instead of integer Change-Id: Ia64bc9f3b01a596b2cdc346060a52a9c443f8fc0
1 parent 4bd20a8 commit 617c129

9 files changed

Lines changed: 543 additions & 369 deletions

File tree

Src/LexText/ParserUI/TryAWordDlg.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
using XCore;
2222
using SIL.FieldWorks.Common.FwUtils;
2323
using SIL.Utils;
24+
using SIL.FieldWorks.XWorks;
25+
using Gecko;
26+
using static SIL.FieldWorks.XWorks.GeneratedHtmlViewer;
2427

2528
namespace SIL.FieldWorks.LexText.Controls
2629
{
@@ -66,6 +69,8 @@ public class TryAWordDlg : Form, IMediatorProvider, IPropertyTableProvider
6669
private WebPageInteractor m_webPageInteractor;
6770
private IParserTrace m_trace;
6871

72+
private GeneratedHtmlViewer.FindDialog findDialog;
73+
6974
#endregion Data members
7075

7176
/// <summary>
@@ -153,6 +158,7 @@ private void InitHtmlControl()
153158
Size = new Size(m_resultsPanel.Width, m_resultsPanel.Height - (m_resultsLabel.Height + 1)),
154159
Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right
155160
};
161+
m_htmlControl.Browser.DomKeyPress += new EventHandler<DomKeyEventArgs>(OnDomKeyPress);
156162
// Setting the Dock to fill doesn't work, as we lose the top of the HtmlControl to the
157163
// label control at the top of the panel. See LT-7446 for the worst case scenario (120dpi).
158164
// So, set the location and size of the HTML control, and anchor it to all four sides of the
@@ -359,6 +365,30 @@ private void InitializeComponent()
359365
}
360366

361367
#endregion
368+
private void OnDomKeyPress(object sender, DomKeyEventArgs e)
369+
{
370+
var ctrl = e.CtrlKey;
371+
if (ctrl && (char)e.KeyChar == 'f')
372+
{
373+
findDialog = new FindDialog(m_htmlControl.Browser);
374+
findDialog.FormClosing += new FormClosingEventHandler(FindDialog_FormClosing);
375+
findDialog.Show(this);
376+
}
377+
else if (e.KeyCode == (uint)Keys.Escape)
378+
{
379+
// we use escape to close the find dialog
380+
findDialog?.Close();
381+
}
382+
}
383+
private void FindDialog_FormClosing(object sender, FormClosingEventArgs e)
384+
{
385+
using (var executor = new AutoJSContext(m_htmlControl.Browser.Window))
386+
{
387+
// Javascript query to execute in the browser
388+
var browserJsQuery = "cleanUpHighlights()";
389+
executor.EvaluateScript(browserJsQuery);
390+
}
391+
}
362392

363393
protected override void OnClosed(EventArgs ea)
364394
{

Src/LexText/ParserUI/WebPageInteractor.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015 SIL International
1+
// Copyright (c) 2015 SIL International
22
// This software is licensed under the LGPL, version 2.1 or later
33
// (http://www.gnu.org/licenses/lgpl-2.1.html)
44

@@ -9,6 +9,7 @@
99
using SIL.FieldWorks.FdoUi;
1010
using SIL.LCModel;
1111
using XCore;
12+
using static SIL.FieldWorks.XWorks.GeneratedHtmlViewer;
1213

1314
namespace SIL.FieldWorks.LexText.Controls
1415
{
@@ -78,6 +79,15 @@ protected void HandleDomClick(object sender, DomMouseEventArgs e)
7879
break;
7980
}
8081
}
82+
if (elem.TagName.Equals("IMG", StringComparison.InvariantCultureIgnoreCase)
83+
&& m_htmlControl.ParentForm != null && m_htmlControl.ParentForm.OwnedForms.Length > 0)
84+
{
85+
// Try a Word tracing items:
86+
// close any instance of the find dialog when a section is opened or closed because the matches are
87+
// no longer valid or needed.
88+
FindDialog findDlg = (FindDialog)m_htmlControl.ParentForm.OwnedForms[0];
89+
findDlg?.Close();
90+
}
8191
}
8292

8393
/// <summary>

Src/Transforms/Presentation/FormatHCTrace.xsl

Lines changed: 2 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
33
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" media-type="text/html; charset=utf-8"/>
44
<xsl:include href="FormatCommon.xsl"/>
5+
<xsl:include href="JSFunctions.xsl"/>
56
<!--
67
================================================================
78
Format the xml returned from XAmple parse for user display.
@@ -57,13 +58,7 @@ Main template
5758
<html>
5859
<head>
5960
<meta charset="UTF-8" />
60-
<xsl:call-template name="Script"/>
61-
<style type="text/css">
62-
.interblock {
63-
display: -moz-inline-box;
64-
display: inline-block;
65-
vertical-align: top;
66-
}</style>
61+
<xsl:call-template name="TraceScript"/>
6762
</head>
6863
<body style="font-family:Times New Roman">
6964
<h1>
@@ -420,178 +415,6 @@ ShowMsaInfo
420415
</span>
421416
</xsl:for-each>
422417
</xsl:template>
423-
<!--
424-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
425-
Script
426-
Output the JavaScript script to handle dynamic "tree"
427-
Parameters: none
428-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
429-
-->
430-
<xsl:template name="Script">
431-
<script language="JavaScript" id="clientEventHandlersJS">
432-
<xsl:text disable-output-escaping="yes">
433-
function ButtonShowDetails()
434-
{
435-
if (TraceSection.style.display == 'none')
436-
{
437-
TraceSection.style.display = 'block';
438-
ShowDetailsButton.value = "Hide Details";
439-
}
440-
else
441-
{
442-
TraceSection.style.display = 'none';
443-
ShowDetailsButton.value = "Show Details";
444-
}
445-
}
446-
// Center the mouse position in the browser
447-
function CenterNodeInBrowser(node)
448-
{
449-
var posx = 0;
450-
var posy = 0;
451-
if (!e) var e = window.event;
452-
if (e.pageX || e.pageY)
453-
{
454-
posx = e.pageX;
455-
posy = e.pageY;
456-
}
457-
else if (e.clientX || e.clientY)
458-
{
459-
posx = e.clientX + document.body.scrollLeft;
460-
posy = e.clientY + document.body.scrollTop;
461-
}
462-
// posx and posy contain the mouse position relative to the document
463-
curY = findPosY(node);
464-
offset = document.body.clientHeight/2;
465-
window.scrollTo(0, curY-offset); // scroll to about the middle if possible
466-
}
467-
// findPosX() and findPosY() are from http://www.quirksmode.org/js/findpos.html
468-
function findPosX(obj)
469-
{
470-
var curleft = 0;
471-
if (obj.offsetParent)
472-
{
473-
while (obj.offsetParent)
474-
{
475-
curleft += obj.offsetLeft
476-
obj = obj.offsetParent;
477-
}
478-
}
479-
else if (obj.x)
480-
curleft += obj.x;
481-
return curleft;
482-
}
483-
484-
function findPosY(obj)
485-
{
486-
var curtop = 0;
487-
if (obj.offsetParent)
488-
{
489-
while (obj.offsetParent)
490-
{
491-
curtop += obj.offsetTop
492-
obj = obj.offsetParent;
493-
}
494-
}
495-
else if (obj.y)
496-
curtop += obj.y;
497-
return curtop;
498-
}
499-
500-
// nextSibling function that skips over textNodes.
501-
function NextNonTextSibling(node)
502-
{
503-
while(node.nextSibling.nodeName == "#text")
504-
node = node.nextSibling;
505-
506-
return node.nextSibling;
507-
}
508-
509-
// This script based on the one given in http://www.codeproject.com/jscript/dhtml_treeview.asp.
510-
function Toggle(node, path, imgOffset)
511-
{
512-
513-
Images = new Array('beginminus.gif', 'beginplus.gif', 'lastminus.gif', 'lastplus.gif', 'minus.gif', 'plus.gif', 'singleminus.gif', 'singleplus.gif',
514-
'beginminusRTL.gif', 'beginplusRTL.gif', 'lastminusRTL.gif', 'lastplusRTL.gif', 'minusRTL.gif', 'plusRTL.gif', 'singleminusRTL.gif', 'singleplusRTL.gif');
515-
// Unfold the branch if it isn't visible
516-
517-
if (NextNonTextSibling(node).style.display == 'none')
518-
{
519-
// Change the image (if there is an image)
520-
if (node.childNodes.length > 0)
521-
{
522-
if (node.childNodes.item(0).nodeName == "IMG")
523-
{
524-
var str = node.childNodes.item(0).src;
525-
var pos = str.indexOf(Images[1 + imgOffset]); // beginplus.gif
526-
if (pos >= 0)
527-
{
528-
node.childNodes.item(0).src = path + Images[0 + imgOffset]; // "beginminus.gif";
529-
}
530-
else
531-
{
532-
pos = str.indexOf(Images[7 + imgOffset]); // "singleplus.gif");
533-
if (pos >= 0)
534-
{
535-
node.childNodes.item(0).src = path + Images[6 + imgOffset]; // "singleminus.gif";
536-
}
537-
else
538-
{
539-
pos = str.indexOf(Images[3 + imgOffset]); // "lastplus.gif");
540-
if (pos >= 0)
541-
{
542-
node.childNodes.item(0).src = path + Images[2 + imgOffset]; // "lastminus.gif";
543-
}
544-
else
545-
{
546-
node.childNodes.item(0).src = path + Images[4 + imgOffset]; // "minus.gif";
547-
}
548-
}
549-
}
550-
}
551-
}
552-
NextNonTextSibling(node).style.display = 'block';
553-
CenterNodeInBrowser(node);
554-
}
555-
// Collapse the branch if it IS visible
556-
else
557-
{
558-
// Change the image (if there is an image)
559-
if (node.childNodes.length > 0)
560-
{
561-
if (node.childNodes.item(0).nodeName == "IMG")
562-
var str = node.childNodes.item(0).src;
563-
var pos = str.indexOf(Images[0 + imgOffset]); // "beginminus.gif");
564-
if (pos >= 0)
565-
{
566-
node.childNodes.item(0).src = path + Images[1 + imgOffset]; // "beginplus.gif";
567-
}
568-
else
569-
{
570-
pos = str.indexOf(Images[6 + imgOffset]); // "singleminus.gif");
571-
if (pos >= 0)
572-
{
573-
node.childNodes.item(0).src = path + Images[7 + imgOffset]; // "singleplus.gif";
574-
}
575-
else
576-
{
577-
pos = str.indexOf(Images[2 + imgOffset]); // "lastminus.gif");
578-
if (pos >= 0)
579-
{
580-
node.childNodes.item(0).src = path + Images[3 + imgOffset]; // "lastplus.gif";
581-
}
582-
else
583-
{
584-
node.childNodes.item(0).src = path + Images[5 + imgOffset]; // "plus.gif";
585-
}
586-
}
587-
}
588-
}
589-
NextNonTextSibling(node).style.display = 'none';
590-
}
591-
}
592-
</xsl:text>
593-
</script>
594-
</xsl:template>
595418
<!--
596419
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
597420
ShowAnyFailure

Src/Transforms/Presentation/FormatXAmpleParse.xsl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
33
<xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes" media-type="text/html; charset=utf-8"/>
44
<xsl:include href="FormatCommon.xsl"/>
5+
<xsl:include href="JSFunctions.xsl"/>
56
<!--
67
================================================================
78
Format the xml returned from XAmple parse for user display.
@@ -51,14 +52,7 @@ Main template
5152
<html>
5253
<head>
5354
<meta charset="UTF-8" />
54-
<style type="text/css">
55-
.interblock {
56-
display: -moz-inline-box;
57-
display:
58-
inline-block;
59-
vertical-align: top;
60-
61-
}</style>
55+
<xsl:call-template name="FindScript"/>
6256
</head>
6357
<body style="font-family:Times New Roman">
6458
<h1>

0 commit comments

Comments
 (0)