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;
}