SIL.FieldWorks.IText.InterlinDocForAnalysis.HandleArrowKeys C# (CSharp) Метод

HandleArrowKeys() приватный Метод

Performs a change in IP when arrow keys should take the IP from a translation or note to an analysis. Also handles right and left arrow for empty translation lines via the output enum. two directions of concern for Left to Right(LTR) and Right To Left(RTL): 1: up from the first translation or note in a paragraph after a word line possibly in another paragraph via up arrow or a left (right if RTL) arrow from the first (last) character of the annotaton 2: down from the last translation or note in a paragraph before a word line possibly in another paragraph via down arrow or a right (left if RTL) arrow from the last (right) character of the annotaton The following logic accounts for the configured position of notes and whether the user added them. The idea here is to eliminate as many default cases as possible as early as possible to be handled by the old annotation OnKeyDown() method.
private HandleArrowKeys ( KeyEventArgs e ) : ArrowChange
e System.Windows.Forms.KeyEventArgs The keyboard event
Результат ArrowChange
		private ArrowChange HandleArrowKeys(KeyEventArgs e)
		{
			if (SelectedOccurrence == null &&
				(e.KeyCode == Keys.Down || e.KeyCode == Keys.Up ||
				 e.KeyCode == Keys.Right || e.KeyCode == Keys.Left) &&
				((e.KeyCode & Keys.Shift) != Keys.Shift) && ((e.KeyCode & Keys.Control) != Keys.Control))
			{
				//MessageBox.Show("Processing arrow keys!", "What's Going On Here??");
				// It's an arrow key, but is it in a translation line or note?
				// Get the current selection so we can obtain the actual translation or note objects
				SelLevInfo[] rgvsli;
				int clev, tag, ichAnchor, ichEnd, ws;
				bool haveSelection = GetCurrentSelection(out clev, out rgvsli, out tag, out ichAnchor, out ichEnd, out ws);
				if (!haveSelection)
					return ArrowChange.None;

				// get the text, paragraph, segment and note, if there is one
				int curSegIndex, curParaIndex, curNoteIndex;
				ISegment curSeg;
				INote curNote;
				GetCurrentTextObjects(clev, rgvsli, tag,
					out curParaIndex, out curSegIndex, out curNoteIndex, out curSeg, out curNote);

				// what kind of line is it and where is the selection (ie., IP) in the text?
				int id, lineNum;
				WhichEnd where;
				bool isRightToLeft;
				bool hasPrompt;
				bool haveLineInfo = GetLineInfo(curSeg, curNote, tag, ichAnchor, ichEnd, ws,
					out id, out lineNum, out where, out isRightToLeft, out hasPrompt);
				if (!haveLineInfo)
					return ArrowChange.None;

				var lines = LineChoices.m_specs as IEnumerable<InterlinLineSpec>; // so we can use linq
				Debug.Assert(lines != null, "Interlinear line configurations not enumerable");
				bool isUpNewSeg;
				bool isUpMove = DetectUpMove(e, lines, lineNum, curSeg, curNoteIndex, where, isRightToLeft, out isUpNewSeg);

				bool isDownNewSeg = false;
				if (!isUpMove)
				{   // might be a downward move
					isDownNewSeg = DetectDownMove(e, lines, lineNum, curSeg, curNoteIndex, isRightToLeft, where);
					// Should = isDownMove since hasFollowingAnalysis should be false
				}
				if (isUpNewSeg || isDownNewSeg)
				{	// Get the next segment in direction with a real analysis or a real translation or note
					if (IsTranslationOrNoteNext(curParaIndex, curSeg, isUpNewSeg))
						if (hasPrompt && (id == InterlinLineChoices.kflidFreeTrans ||
										  id == InterlinLineChoices.kflidLitTrans))
						{   // moving from an empty translation line to another translation line
							return isUpNewSeg ? ArrowChange.Up : ArrowChange.Down;
						}
						else return ArrowChange.None; // let default handle it
					// a real analysis is next or no more segments
					var occurrence = MoveVerticallyToNextAnalysis(curParaIndex, curSegIndex, isUpNewSeg);
					if (occurrence == null)
						return ArrowChange.None; // only a real translation or note, or it couldn't find a suitable segment
					SelectOccurrence(occurrence); // only works for analyses, not annotations
					return ArrowChange.Handled;
				}
				if (isUpMove)
				{   // Need to move up to a real analysis in the same segment
					IAnalysis nextAnalysis = null;
					int index = 0;
					foreach (var an in curSeg.AnalysesRS.Reverse())
					{	// need to count because an.IndexInOwner == 0 for all an - go figure
						index++;
						if (!an.HasWordform) continue;
						break; // found the last real analysis
					}
					SelectOccurrence(new AnalysisOccurrence(curSeg, curSeg.AnalysesRS.Count - index));
					return ArrowChange.Handled;
				}
				if (hasPrompt && (id == InterlinLineChoices.kflidFreeTrans ||
								  id == InterlinLineChoices.kflidLitTrans)
							  && (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right))
				{   // moving from an empty translation line to right or left
					if (TextIsRightToLeft ? e.KeyCode == Keys.Right : e.KeyCode == Keys.Left)
						return ArrowChange.Up;
					return ArrowChange.Down;
				}
			}
			return ArrowChange.None;
		}
InterlinDocForAnalysis