Exemplo n.º 1
0
        /// <summary>
        /// Approves an analysis and moves the selection to the next wordform or the
        /// next Interlinear line. An Interlinear line is one of the configurable
        /// "lines" in the Tools->Configure->Interlinear Lines dialog, not a segement.
        /// The list of lines is collected in choices[] below.
        /// WordLevel is true for word or analysis lines. The non-word lines are translation and note lines.
        /// Normally, this is invoked as a result of pressing the <Enter> key in an analysis.
        /// </summary>
        /// <param name="undoRedoText"></param>
        /// <returns>true if IP moved on, false otherwise</returns>
        internal virtual bool ApproveAndMoveNextRecursive(ICommandUndoRedoText undoRedoText)
        {
            if (!SelectedOccurrence.IsValid)
            {
                // Can happen (at least) when the text we're analyzing got deleted in another window
                SelectedOccurrence = null;
                InterlinDoc.TryHideFocusBoxAndUninstall();
                return(false);
            }
            var navigator    = new SegmentServices.StTextAnnotationNavigator(SelectedOccurrence);
            var nextWordform = navigator.GetNextWordformOrDefault(SelectedOccurrence);

            if (nextWordform == null || nextWordform.Segment != SelectedOccurrence.Segment ||
                nextWordform == SelectedOccurrence)
            {
                // We're at the end of a segment...try to go to an annotation of SelectedOccurrence.Segment
                // or possibly (See LT-12229:If the nextWordform is the same as SelectedOccurrence)
                // at the end of the text.
                UpdateRealFromSandbox(undoRedoText, true, null);                 // save work done in sandbox
                // try to select the first configured annotation (not a null note) in this segment
                if (InterlinDoc.SelectFirstTranslationOrNote())
                {                   // IP should now be on an annotation line.
                    return(true);
                }
            }
            if (nextWordform != null)
            {
                bool dealtWith = false;
                if (nextWordform.Segment != SelectedOccurrence.Segment)
                {                   // Is there another segment before the next wordform?
                    // It would have no analyses or just punctuation.
                    // It could have "real" annotations.
                    AnalysisOccurrence realAnalysis;
                    ISegment           nextSeg = InterlinDoc.GetNextSegment
                                                     (SelectedOccurrence.Segment.Owner.IndexInOwner,
                                                     SelectedOccurrence.Segment.IndexInOwner, false, out realAnalysis); // downward move
                    if (nextSeg != null && nextSeg != nextWordform.Segment)
                    {                                                                                                   // This is a segment before the one contaning the next wordform.
                        if (nextSeg.AnalysesRS.Where(an => an.HasWordform).Count() > 0)
                        {                                                                                               // Set it as the current segment and recurse
                            SelectedOccurrence = new AnalysisOccurrence(nextSeg, 0);                                    // set to first analysis
                            dealtWith          = ApproveAndMoveNextRecursive(undoRedoText);
                        }
                        else
                        {                               // only has annotations: focus on it and set the IP there.
                            InterlinDoc.SelectFirstTranslationOrNote(nextSeg);
                            return(true);               // IP should now be on an annotation line.
                        }
                    }
                }
                if (!dealtWith)
                {                   // If not dealt with continue on to the next wordform.
                    UpdateRealFromSandbox(undoRedoText, true, nextWordform);
                    // do the move.
                    InterlinDoc.SelectOccurrence(nextWordform);
                }
            }
            return(true);
        }
        /// <summary>
        /// Move to the first bundle
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public bool OnFirstBundle(object arg)
        {
            var navigator = new SegmentServices.StTextAnnotationNavigator(SelectedOccurrence);
            IEnumerable <AnalysisOccurrence> options = navigator.GetWordformOccurrencesBackwardsIncludingStartingOccurrence();

            InterlinDoc.TriggerAnalysisSelected(options.Last(), true, true);
            return(true);
        }
        /// <summary>
        /// Using the current focus box content, approve it and apply it to all unanalyzed matching
        /// wordforms in the text.  See LT-8833.
        /// </summary>
        /// <returns></returns>
        public void ApproveGuessOrChangesForWholeTextAndMoveNext(Command cmd)
        {
            // Go through the entire text looking for matching analyses that can be set to the new
            // value.
            if (SelectedOccurrence == null)
            {
                return;
            }
            var oldWf  = SelectedOccurrence.Analysis.Wordform;
            var stText = SelectedOccurrence.Paragraph.Owner as IStText;

            if (stText == null || stText.ParagraphsOS.Count == 0)
            {
                return;                 // paranoia, we should be in one of its paragraphs.
            }
            // We don't need to discard existing guesses, even though we will modify Segment.Analyses,
            // since guesses for other wordforms will not be affected, and there will be no remaining
            // guesses for the word we're confirming everywhere. (This needs to be outside the block
            // for the UOW, since what we are suppressing happens at the completion of the UOW.)
            InterlinDoc.SuppressResettingGuesses(
                () =>
            {
                // Needs to include GetRealAnalysis, since it might create a new one.
                UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, Cache.ActionHandlerAccessor,
                                            () =>
                {
                    IWfiAnalysis obsoleteAna;
                    AnalysisTree newAnalysisTree = InterlinWordControl.GetRealAnalysis(true, out obsoleteAna);
                    var wf = newAnalysisTree.Wordform;
                    if (newAnalysisTree.Analysis == wf)
                    {
                        // nothing significant to confirm, so move on
                        // (return means get out of this lambda expression, not out of the method).
                        return;
                    }
                    SaveAnalysisForAnnotation(SelectedOccurrence, newAnalysisTree);
                    // determine if we confirmed on a sentence initial wordform to its lowercased form
                    bool fIsSentenceInitialCaseChange = oldWf != wf;
                    if (wf != null)
                    {
                        ApplyAnalysisToInstancesOfWordform(newAnalysisTree.Analysis, oldWf, wf);
                    }
                    // don't try to clean up the old analysis until we've finished walking through
                    // the text and applied all our changes, otherwise we could delete a wordform
                    // that is referenced by dummy annotations in the text, and thus cause the display
                    // to treat them like pronunciations, and just show an unanalyzable text (LT-9953)
                    FinishSettingAnalysis(newAnalysisTree, InitialAnalysis);
                    if (obsoleteAna != null)
                    {
                        obsoleteAna.Delete();
                    }
                });
            });
            // This should not make any data changes, since we're telling it not to save and anyway
            // we already saved the current annotation. And it can't correctly place the focus box
            // until the change we just did are completed and PropChanged sent. So keep this outside the UOW.
            OnNextBundle(cmd, false, false, false, true);
        }
        /// <summary>
        /// Move to the next bundle in the direction indicated by fForward. If fSaveGuess is true, save guesses in the current position,
        /// using Undo  text from the command. If skipFullyAnalyzedWords is true, move to the next item needing analysis, otherwise, the immediate next.
        /// If fMakeDefaultSelection is true, make the default selection within the moved focus box.
        /// </summary>
        public void OnNextBundle(ICommandUndoRedoText undoRedoText, bool fSaveGuess, bool skipFullyAnalyzedWords,
                                 bool fMakeDefaultSelection, bool fForward)
        {
            int currentLineIndex = -1;

            if (InterlinWordControl != null)
            {
                currentLineIndex = InterlinWordControl.GetLineOfCurrentSelection();
            }
            var nextOccurrence = GetNextOccurrenceToAnalyze(fForward, skipFullyAnalyzedWords);

            InterlinDoc.TriggerAnalysisSelected(nextOccurrence, fSaveGuess, fMakeDefaultSelection);
            if (!fMakeDefaultSelection && currentLineIndex >= 0 && InterlinWordControl != null)
            {
                InterlinWordControl.SelectOnOrBeyondLine(currentLineIndex, 1);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Note: Assume we are in the OnDisplayShowLinkWords is true context.
        /// </summary>
        public bool OnJoinWords(object arg)
        {
            var cmd = (ICommandUndoRedoText)arg;

            UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, Cache.ActionHandlerAccessor,
                                        () =>
            {
                SelectedOccurrence.MakePhraseWithNextWord();
                if (InterlinDoc != null)
                {
                    InterlinDoc.RecordGuessIfNotKnown(SelectedOccurrence);
                }
            });
            InterlinWordControl.SwitchWord(SelectedOccurrence);
            UpdateButtonState();
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="undoRedoText">Approving the state of the FocusBox can be associated with
        /// different user actions (ie. UOW)</param>
        /// <param name="fSaveGuess"></param>
        /// <param name="nextWordform"></param>
        internal void UpdateRealFromSandbox(ICommandUndoRedoText undoRedoText, bool fSaveGuess,
                                            AnalysisOccurrence nextWordform)
        {
            if (!ShouldCreateAnalysisFromSandbox(fSaveGuess))
            {
                return;
            }

            var origWordform = SelectedOccurrence;

            if (!origWordform.IsValid)
            {
                return;                 // something (editing elsewhere?) has put things in a bad state; cf LTB-1665.
            }
            var origWag     = new AnalysisTree(origWordform.Analysis);
            var undoText    = undoRedoText != null ? undoRedoText.UndoText : ITextStrings.ksUndoApproveAnalysis;
            var redoText    = undoRedoText != null ? undoRedoText.RedoText : ITextStrings.ksRedoApproveAnalysis;
            var oldAnalysis = SelectedOccurrence.Analysis;

            try
            {
                // Updating one of a segment's analyses would normally reset the analysis cache.
                // And we may have to: UpdatingOccurrence will figure out whether to do it or not.
                // But we don't want it to happen as an automatic side effect of the PropChanged.
                InterlinDoc.SuspendResettingAnalysisCache = true;
                UndoableUnitOfWorkHelper.Do(undoText, redoText,
                                            Cache.ActionHandlerAccessor, () => ApproveAnalysisAndMove(fSaveGuess, nextWordform));
            }
            finally
            {
                InterlinDoc.SuspendResettingAnalysisCache = false;
            }
            var newAnalysis = SelectedOccurrence.Analysis;

            InterlinDoc.UpdatingOccurrence(oldAnalysis, newAnalysis);
            var newWag    = new AnalysisTree(origWordform.Analysis);
            var wordforms = new HashSet <IWfiWordform> {
                origWag.Wordform, newWag.Wordform
            };

            InterlinDoc.UpdateGuesses(wordforms);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Change root of Sandbox or create it; Lay it out and figure its size;
        /// tell m_vc the size.
        /// </summary>
        /// <returns></returns>
        private void ChangeOrCreateSandbox(AnalysisOccurrence selected)
        {
            this.SuspendLayout();
            panelSandbox.SuspendLayout();
            if (InterlinDoc != null)
            {
                InterlinDoc.RecordGuessIfNotKnown(selected);
            }
            int color = (int)CmObjectUi.RGB(DefaultBackColor);

            //if this sandbox is presenting a wordform with multiple possible analyses then set the
            //bg color indicator
            if (selected.Analysis.Analysis == null && selected.Analysis.Wordform != null &&
                SandboxBase.GetHasMultipleRelevantAnalyses(selected.Analysis.Wordform))
            {
                color = InterlinVc.MultipleApprovedGuessColor;
            }

            if (m_sandbox == null)
            {
                m_sandbox = CreateNewSandbox(selected);
                m_sandbox.MultipleAnalysisColor = color;
            }
            else
            {
                //set the color before switching so that the color is correct when DisplayWordForm is called
                m_sandbox.MultipleAnalysisColor = color;
                m_sandbox.SwitchWord(selected);
            }
            UpdateButtonState();
            // add the sandbox plus some padding.
            panelSandbox.ResumeLayout();
            this.ResumeLayout();

            SetSandboxSize();
        }
Exemplo n.º 8
0
 private void btnConfirmChangesForWholeText_Click(object sender, EventArgs e)
 {
     InterlinDoc.ApproveGuessOrChangesForWholeTextAndMoveNext(m_sandbox.Mediator.CommandSet["CmdApproveForWholeTextAndMoveNext"] as Command);
 }
Exemplo n.º 9
0
 private void btnConfirmChanges_Click(object sender, EventArgs e)
 {
     InterlinDoc.ApproveGuessOrChangesAndMoveNext();
 }
Exemplo n.º 10
0
 private void btnBreakPhrase_Click(object sender, EventArgs e)
 {
     InterlinDoc.OnBreakPhrase(m_sandbox.Mediator.CommandSet["CmdBreakPhrase"] as Command);
 }
Exemplo n.º 11
0
 private void btnLinkNextWord_Click(object sender, EventArgs e)
 {
     InterlinDoc.OnJoinWords(m_sandbox.Mediator.CommandSet["CmdMakePhrase"] as Command);
 }