Пример #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>
		/// 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 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);
            }
        }
Пример #4
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);
        }
 /// <summary>
 /// Move to next bundle to the right, after approving changes (and guesses if fSaveGuess is true).
 /// </summary>
 public void OnMoveFocusBoxRight(ICommandUndoRedoText undoRedoText, bool fSaveGuess)
 {
     // Move in the literal direction (LT-3706)
     OnNextBundle(undoRedoText, fSaveGuess, false, true, !m_fRightToLeft);
 }
 /// <summary>
 /// Approves an analysis and moves the selection to the next wordform or the
 /// next Interlinear line.
 /// Normally, this is invoked as a result of pressing the <Enter> key
 /// or clicking the "Approve and Move Next" green check in an analysis.
 /// </summary>
 /// <param name="undoRedoText"></param>
 internal virtual void ApproveAndMoveNext(ICommandUndoRedoText undoRedoText)
 {
     ApproveAndMoveNextRecursive(undoRedoText);
 }
 internal void ApproveAndStayPut(ICommandUndoRedoText undoRedoText)
 {
     // don't navigate, just save.
     UpdateRealFromSandbox(undoRedoText, true, SelectedOccurrence);
 }
		/// <summary>
		/// Move to next bundle to the right, after approving changes (and guesses if fSaveGuess is true).
		/// </summary>
		public void OnMoveFocusBoxRight(ICommandUndoRedoText undoRedoText, bool fSaveGuess)
		{
			// Move in the literal direction (LT-3706)
			OnNextBundle(undoRedoText, fSaveGuess, false, true, !m_fRightToLeft);
		}
		/// <summary>
		/// Approves an analysis and moves the selection to the next wordform or the
		/// next Interlinear line.
		/// Normally, this is invoked as a result of pressing the <Enter> key
		/// or clicking the "Approve and Move Next" green check in an analysis.
		/// </summary>
		/// <param name="undoRedoText"></param>
		internal virtual void ApproveAndMoveNext(ICommandUndoRedoText undoRedoText)
		{
			ApproveAndMoveNextRecursive(undoRedoText);
		}
		/// <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);
		}
		internal void ApproveAndStayPut(ICommandUndoRedoText undoRedoText)
		{
			// don't navigate, just save.
			UpdateRealFromSandbox(undoRedoText, true, SelectedOccurrence);
		}
		/// <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);
		}