void
JXInputField::HandleKeyPress
	(
	const int				key,
	const JXKeyModifiers&	modifiers
	)
{
	if (itsTable != NULL && itsTable->WantsInputFieldKey(key, modifiers))
		{
		itsTable->HandleKeyPress(key, modifiers);
		return;
		}
	else if (itsTable != NULL)
		{
		JPoint cell;
		const JBoolean ok = itsTable->GetEditedCell(&cell);
		assert( ok );
		itsTable->TableScrollToCell(cell);
		}

	if (key == JXCtrl('K') && modifiers.control() && HasSelection())
		{
		Cut();
		}
	else if (key == JXCtrl('K') && modifiers.control())
		{
		JIndex i;
		const JBoolean ok = GetCaretLocation(&i);
		assert( ok );
		SetSelection(i, GetTextLength());
		Cut();
		}

	else
		{
		JXTEBase::HandleKeyPress(key, modifiers);
		}
}
void
JXSearchTextDialog::SetObjects
	(
	JXInputField*			searchInput,
	JXStringHistoryMenu*	prevSearchMenu,
	JXTextCheckbox*			ignoreCaseCB,
	JXTextCheckbox*			entireWordCB,
	JXTextCheckbox*			wrapSearchCB,
	JXTextCheckbox*			searchIsRegexCB,
	JXTextCheckbox*			singleLineCB,

	JXInputField*			replaceInput,
	JXStringHistoryMenu*	prevReplaceMenu,
	JXTextCheckbox*			replaceIsRegexCB,
	JXTextCheckbox*			preserveCaseCB,

	JXTextCheckbox*			stayOpenCB,
	JXTextCheckbox*			retainFocusCB,

	JXSearchTextButton*		findFwdButton,
	JXSearchTextButton*		findBackButton,
	JXTextButton*			replaceButton,
	JXSearchTextButton*		replaceFindFwdButton,
	JXSearchTextButton*		replaceFindBackButton,
	JXSearchTextButton*		replaceAllFwdButton,
	JXSearchTextButton*		replaceAllBackButton,
	JXTextButton*			replaceAllInSelButton,

	JXTextButton*			closeButton,
	JXTextButton*			helpButton,
	JXTextButton*			qRefButton
	)
{
	JXWindow* window = searchInput->GetWindow();
	window->SetTitle("Search text");
	window->SetCloseAction(JXWindow::kDeactivateDirector);
	window->PlaceAsDialogWindow();
	window->LockCurrentMinSize();
	window->ShouldFocusWhenShow(kJTrue);
	ListenTo(window);

	itsSearchInput     = searchInput;
	itsPrevSearchMenu  = prevSearchMenu;
	itsIgnoreCaseCB    = ignoreCaseCB;
	itsEntireWordCB    = entireWordCB;
	itsWrapSearchCB    = wrapSearchCB;
	itsSearchIsRegexCB = searchIsRegexCB;
	itsSingleLineCB    = singleLineCB;

	itsReplaceInput     = replaceInput;
	itsPrevReplaceMenu  = prevReplaceMenu;
	itsReplaceIsRegexCB = replaceIsRegexCB;
	itsPreserveCaseCB   = preserveCaseCB;

	itsStayOpenCB    = stayOpenCB;
	itsRetainFocusCB = retainFocusCB;

	itsFindFwdButton         = findFwdButton;
	itsFindBackButton        = findBackButton;
	itsReplaceButton         = replaceButton;
	itsReplaceFindFwdButton  = replaceFindFwdButton;
	itsReplaceFindBackButton = replaceFindBackButton;
	itsReplaceAllFwdButton   = replaceAllFwdButton;
	itsReplaceAllBackButton  = replaceAllBackButton;
	itsReplaceAllInSelButton = replaceAllInSelButton;

	itsCloseButton = closeButton;
	itsHelpButton  = helpButton;
	itsQRefButton  = qRefButton;

	SetFont(JGetMonospaceFontName(), kJDefaultMonoFontSize);

	// decor

	const JRect wFrame  = window->GetFrame();
	const JRect soFrame = itsStayOpenCB->GetFrame();

	JXDownRect* line =
		new JXDownRect(window, JXWidget::kFixedLeft, JXWidget::kFixedTop,
					   soFrame.left, soFrame.top-6,
					   wFrame.right-10-soFrame.left, 2);
	assert( line != NULL );
	line->SetBorderWidth(1);

	// shortcuts

    itsCloseButton->SetShortcuts("#W^[");
    itsIgnoreCaseCB->SetShortcuts("#I");
    itsWrapSearchCB->SetShortcuts("#S");
    itsEntireWordCB->SetShortcuts("#E");
    itsSearchIsRegexCB->SetShortcuts("#X");
    itsSingleLineCB->SetShortcuts("#T");
    itsPreserveCaseCB->SetShortcuts("#P");

	if (JXMenu::GetDefaultStyle() == JXMenu::kMacintoshStyle)
		{
		itsFindFwdButton->SetShortcuts("#G");
		itsFindFwdButton->SetHint("Return / Meta-G");

		itsFindBackButton->SetHint("Shift-Return / Meta-Shift-G");

	    itsReplaceButton->SetShortcuts("#R#=");
		itsReplaceButton->SetHint("Meta-R / Meta-=");

		itsReplaceFindFwdButton->SetShortcuts("#L");
		itsReplaceFindFwdButton->SetHint("Meta-L");

		itsReplaceFindBackButton->SetHint("Meta-Shift-L");
		}
	else
		{
		itsFindFwdButton->SetShortcuts("^G");
		itsFindFwdButton->SetHint("Return / Ctrl-G");

		itsFindBackButton->SetHint("Shift-Return / Ctrl-Shift-G");

	    itsReplaceButton->SetShortcuts("#R^=");
		itsReplaceButton->SetHint("Meta-R / Ctrl-=");

		itsReplaceFindFwdButton->SetShortcuts("^L");
		itsReplaceFindFwdButton->SetHint("Ctrl-L");

		itsReplaceFindBackButton->SetHint("Ctrl-Shift-L");
		}

	JXKeyModifiers modifiers(GetDisplay());
	window->InstallShortcut(itsFindFwdButton, JXCtrl('M'), modifiers);

	modifiers.SetState(kJXShiftKeyIndex, kJTrue);
	window->InstallShortcut(itsFindBackButton, JXCtrl('M'), modifiers);

	modifiers.SetState(kJXMetaKeyIndex, kJTrue);
    itsReplaceIsRegexCB->SetShortcuts("#X");		// trick to underline x
	window->ClearShortcuts(itsReplaceIsRegexCB);
	window->InstallShortcut(itsReplaceIsRegexCB, 'x', modifiers);
	window->InstallShortcut(itsReplaceIsRegexCB, 'X', modifiers);

	if (JXMenu::GetDefaultStyle() != JXMenu::kMacintoshStyle)
		{
		modifiers.SetState(kJXMetaKeyIndex, kJFalse);
		modifiers.SetState(kJXControlKeyIndex, kJTrue);
		}

	window->InstallShortcut(itsFindBackButton, 'g', modifiers);
	window->InstallShortcut(itsFindBackButton, 'G', modifiers);

	window->InstallShortcut(itsReplaceFindBackButton, 'l', modifiers);
	window->InstallShortcut(itsReplaceFindBackButton, 'L', modifiers);

	// broadcasters

	ListenTo(itsFindFwdButton);
	ListenTo(itsFindBackButton);
	ListenTo(itsReplaceButton);
	ListenTo(itsReplaceFindFwdButton);
	ListenTo(itsReplaceFindBackButton);
	ListenTo(itsReplaceAllFwdButton);
	ListenTo(itsReplaceAllBackButton);
	ListenTo(itsReplaceAllInSelButton);

	ListenTo(itsHelpButton);
	ListenTo(itsQRefButton);
	ListenTo(itsCloseButton);

	ListenTo(itsPrevSearchMenu);
	ListenTo(itsPrevReplaceMenu);

	itsIgnoreCaseCB->SetState(kJTrue);
	itsWrapSearchCB->SetState(kJTrue);

	itsStayOpenCB->SetState(kJTrue);
	itsRetainFocusCB->SetState(kJTrue);

	// listen after setting value

	ListenTo(itsStayOpenCB);

	// XSearch data

	itsSearchInput->ShouldBroadcastAllTextChanged(kJTrue);
	ListenTo(itsSearchInput);
	ListenTo(itsSearchIsRegexCB);
	ListenTo(itsSingleLineCB);

	itsReplaceInput->ShouldBroadcastAllTextChanged(kJTrue);
	ListenTo(itsReplaceInput);
	ListenTo(itsReplaceIsRegexCB);
	ListenTo(itsPreserveCaseCB);

	ListenTo(itsWrapSearchCB);
	ListenTo(itsEntireWordCB);
	ListenTo(itsIgnoreCaseCB);
}
void
CBShellEditor::HandleKeyPress
	(
	const int				key,
	const JXKeyModifiers&	modifiers
	)
{
	const JBoolean controlOn = modifiers.control();
	const JBoolean metaOn    = modifiers.meta();
	const JBoolean shiftOn   = modifiers.shift();
	if ((key == kJLeftArrow && metaOn && !controlOn && !shiftOn) ||
		(key == JXCtrl('A') && controlOn && !metaOn && !shiftOn))
		{
		const JIndex index            = GetInsertionIndex();
		const JRunArray<Font>& styles = GetStyles();
		if (index > 1 && styles.GetElement(index-1) == GetDefaultFont())
			{
			JIndex runIndex, firstIndexInRun;
			const JBoolean ok = styles.FindRun(index-1, &runIndex, &firstIndexInRun);
			SetCaretLocation(firstIndexInRun);
			return;
			}
		}

	if (key == kJReturnKey)
		{
		SetCurrentFont(itsInsertFont);
		}
	else
		{
		SetCurrentFont(GetDefaultFont());
		}

	JBoolean sentCmd = kJFalse;
	if (key == kJReturnKey && !modifiers.shift() && !HasSelection())
		{
		JIndex index;
		JBoolean ok = GetCaretLocation(&index);
		assert( ok );

		JString cmd;
		const JRunArray<Font>& styles = GetStyles();
		if (index > 1 && styles.GetElement(index-1) == GetDefaultFont())
			{
			JIndex runIndex, firstIndexInRun;
			ok = styles.FindRun(index-1, &runIndex, &firstIndexInRun);

			const JIndex endIndex = firstIndexInRun + styles.GetRunLength(runIndex);
			cmd = (GetText()).GetSubstring(firstIndexInRun, endIndex - 1);
			SetCaretLocation(endIndex);

			if (cmd.BeginsWith("man "))
				{
				cmd.ReplaceSubstring(1, 4, "jcc --man ");
				}
			else if (cmd.BeginsWith("apropos "))
				{
				cmd.ReplaceSubstring(1, 8, "jcc --apropos ");
				}
			else if (cmd.BeginsWith("vi "))
				{
				cmd.ReplaceSubstring(1, 3, "jcc ");
				}
			else if (cmd.BeginsWith("less ") || cmd.BeginsWith("more "))
				{
				cmd.ReplaceSubstring(1, 5, "jcc ");
				}
			else if (cmd == "more" || cmd == "less" || cmd == "vi")
				{
				cmd = "jcc";
				}
			}

		cmd += "\n";
		itsShellDoc->SendCommand(cmd);

		sentCmd = kJTrue;
		}

	CBTextEditor::HandleKeyPress(key, modifiers);

	if (sentCmd)
		{
		itsInsertIndex = GetInsertionIndex();
		}
}