Beispiel #1
0
    void StyledTextBox::OnKeyChar(wxKeyEvent& keyEvent) {
        // Process visible character input

        if (!keyEvent.HasModifiers()) {
            int keycode = keyEvent.GetRawKeyCode();

            if (keycode < 255 && isprint(keycode)) {
                if (HasSelectedText()) {
                    RemoveSelectedText();
                }

                char c = (wxChar)keycode;
                auto text = GetStdText();

                auto insertPosition = begin(text) + GetCursorPosition();

                text.insert(insertPosition, c);

                SetText(text);

                SetCursorPosition(GetCursorPosition() + 1);
            }
        }
    }
Beispiel #2
0
bool CBottomView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)
{
	if (!this->IsWindowVisible())
		return false;

	CMenu popup;
	if (popup.CreatePopupMenu())
	{
#define ID_USETHEIRBLOCK 1
#define ID_USEYOURBLOCK 2
#define ID_USETHEIRANDYOURBLOCK 3
#define ID_USEYOURANDTHEIRBLOCK 4
		UINT uEnabled = MF_ENABLED;
		if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
			uEnabled |= MF_DISABLED | MF_GRAYED;
		CString temp;

		bool bImportantBlock = true;
		switch (state)
		{
		case DIFFSTATE_UNKNOWN:
			bImportantBlock = false;
			break;
		}

		temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRBLOCK);
		popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USETHEIRBLOCK, temp);
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURBLOCK);
		popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEYOURBLOCK, temp);
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);
		popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USEYOURANDTHEIRBLOCK, temp);
		temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);
		popup.AppendMenu(MF_STRING | uEnabled | (bImportantBlock ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_USETHEIRANDYOURBLOCK, temp);

		popup.AppendMenu(MF_SEPARATOR, NULL);

		temp.LoadString(IDS_EDIT_COPY);
		popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_COPY, temp);
		if (!m_bCaretHidden)
		{
			temp.LoadString(IDS_EDIT_CUT);
			popup.AppendMenu(MF_STRING | (HasTextSelection() ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_CUT, temp);
			temp.LoadString(IDS_EDIT_PASTE);
			popup.AppendMenu(MF_STRING | (CAppUtils::HasClipboardFormat(CF_UNICODETEXT)||CAppUtils::HasClipboardFormat(CF_TEXT) ? MF_ENABLED : MF_DISABLED|MF_GRAYED), ID_EDIT_PASTE, temp);
		}

		// if the context menu is invoked through the keyboard, we have to use
		// a calculated position on where to anchor the menu on
		if ((point.x == -1) && (point.y == -1))
		{
			CRect rect;
			GetWindowRect(&rect);
			point = rect.CenterPoint();
		}

		int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
		viewstate rightstate;
		viewstate bottomstate;
		viewstate leftstate;
		switch (cmd)
		{
		case ID_USETHEIRBLOCK:
			UseTheirTextBlock();
			break;
		case ID_USEYOURBLOCK:
			UseMyTextBlock();
			break;
		case ID_USEYOURANDTHEIRBLOCK:
			UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
			CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
			break;
		case ID_USETHEIRANDYOURBLOCK:
			UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
			CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
			break;
		case ID_EDIT_COPY:
			OnEditCopy();
			return true;
		case ID_EDIT_CUT:
			OnEditCopy();
			RemoveSelectedText();
			break;
		case ID_EDIT_PASTE:
			PasteText();
			break;
		}
	}
	return false;
}
Beispiel #3
0
bool CRightView::OnContextMenu(CPoint point, int /*nLine*/, DiffStates state)
{
	if (!this->IsWindowVisible())
		return false;

	CMenu popup;
	if (!popup.CreatePopupMenu())
		return false;

#define ID_USEBLOCK 1
#define ID_USEFILE 2
#define ID_USETHEIRANDYOURBLOCK 3
#define ID_USEYOURANDTHEIRBLOCK 4
#define ID_USEBOTHTHISFIRST 5
#define ID_USEBOTHTHISLAST 6

	const UINT uFlags = GetMenuFlags( state );

	CString temp;

	if (m_pwndBottom->IsWindowVisible())
	{
		temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISBLOCK);
	}
	else		
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERBLOCK);
	popup.AppendMenu(uFlags, ID_USEBLOCK, temp);

	if (m_pwndBottom->IsWindowVisible())
	{
		temp.LoadString(IDS_VIEWCONTEXTMENU_USETHISFILE);
	}
	else
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEOTHERFILE);
	popup.AppendMenu(MF_STRING | MF_ENABLED, ID_USEFILE, temp);

	if (m_pwndBottom->IsWindowVisible())
	{
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEYOURANDTHEIRBLOCK);
		popup.AppendMenu(uFlags, ID_USEYOURANDTHEIRBLOCK, temp);
		temp.LoadString(IDS_VIEWCONTEXTMENU_USETHEIRANDYOURBLOCK);
		popup.AppendMenu(uFlags, ID_USETHEIRANDYOURBLOCK, temp);
	}
	else
	{
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISFIRST);
		popup.AppendMenu(uFlags, ID_USEBOTHTHISFIRST, temp);
		temp.LoadString(IDS_VIEWCONTEXTMENU_USEBOTHTHISLAST);
		popup.AppendMenu(uFlags, ID_USEBOTHTHISLAST, temp);
	}

	AddCutCopyAndPaste(popup);

	CompensateForKeyboard(point);

	int cmd = popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
	viewstate rightstate;
	viewstate bottomstate;
	viewstate leftstate;
	switch (cmd)
	{
	case ID_EDIT_COPY:
		OnEditCopy();
		return true;
	case ID_EDIT_CUT:
		OnEditCopy();
		RemoveSelectedText();
		return false;
	case ID_EDIT_PASTE:
		PasteText();
		return false;
	case ID_USEFILE:
		UseFile(false);
		break;
	case ID_USEBLOCK:
		UseBlock(false);
		break;
	case ID_USEYOURANDTHEIRBLOCK:
		UseYourAndTheirBlock(rightstate, bottomstate, leftstate);
		CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
		break;
	case ID_USETHEIRANDYOURBLOCK:
		UseTheirAndYourBlock(rightstate, bottomstate, leftstate);
		CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
		break;
	case ID_USEBOTHTHISFIRST:
		UseBothRightFirst(rightstate, leftstate);
		CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
		break;
	case ID_USEBOTHTHISLAST:
		UseBothLeftFirst(rightstate, leftstate);
		CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
		break;
	default:
		return false;
	} // switch (cmd) 
	return false;
}
Beispiel #4
0
    void StyledTextBox::OnKeyPressed(wxKeyEvent& keyEvent) {

        bool eventHandled = false;
        int keycode = keyEvent.GetKeyCode();
        int originalCursorPosition = GetCursorPosition();

        // Used to indicate there was a cursor navigation event
        bool navigationEvent = false;

        if (keyEvent.GetModifiers() & wxMOD_SHIFT) {
            EnsureSelectionStarted();
        }

        // Select All
        if (keyEvent.ControlDown() && keycode == 'A') {
            SetCursorPosition(GetText().Length());
            SetSelection(0, 0);
            SetSelectionEnd(GetCursorPosition());
            eventHandled = true;
        }

        // Copy
        if (keyEvent.ControlDown() && keycode == 'C') {
            if (wxTheClipboard->Open())
            {
                wxTheClipboard->SetData(new wxTextDataObject(GetSelectedText()));
                wxTheClipboard->Close();
            }
            eventHandled = true;
        }

        // Paste
        if (keyEvent.ControlDown() && keycode == 'V') {
            if (wxTheClipboard->Open())
            {
                if (wxTheClipboard->IsSupported(wxDF_TEXT))
                {
                    wxTextDataObject data;
                    wxTheClipboard->GetData(data);
                    if (HasSelectedText()) {
                        RemoveSelectedText();
                    }
                    auto text = GetText();
                    text.insert(GetCursorPosition(), data.GetText());
                    SetText(text);
                    SetCursorPosition(GetCursorPosition() + data.GetText().Length());
                }
                wxTheClipboard->Close();
            }
        }

        if (keycode == WXK_BACK) {
            if (HasSelectedText()) {
                RemoveSelectedText();
            } else if (GetCursorPosition() > 0) {
                auto text = GetStdText();

                auto eraseStart = begin(text) + GetCursorPosition() - 1;
                auto eraseEnd = eraseStart + 1;
                text.erase(eraseStart, eraseEnd);

                SetText(text);

                SetCursorPosition(GetCursorPosition() - 1);
            }
            eventHandled = true;
            navigationEvent = true;
        }

        if (keycode == WXK_DELETE) {
            if (HasSelectedText()) {
                RemoveSelectedText();
            } else if (GetCursorPosition() < GetText().Length()) {
                auto text = GetStdText();

                auto eraseStart = begin(text) + GetCursorPosition();
                auto eraseEnd = eraseStart + 1;
                text.erase(eraseStart, eraseEnd);

                SetText(text);
            }
            return;
        } 

        if (keycode == WXK_LEFT) {
            if (GetCursorPosition() > 0) {
                SetCursorPosition(GetCursorPosition() - 1);
            }
            eventHandled = true;
            navigationEvent = true;
        }

        if (keycode == WXK_RIGHT) {
            if (GetCursorPosition() < GetText().Length()) {
                SetCursorPosition(GetCursorPosition() + 1);
            }
            eventHandled = true;
            navigationEvent = true;
        }

        if (keycode == WXK_END) {
            SetCursorPosition(GetText().Length());
            eventHandled = true;
            navigationEvent = true;
        }

        if (keycode == WXK_HOME) {
            SetCursorPosition(0);
            eventHandled = true;
            navigationEvent = true;
        }

        if (keyEvent.GetModifiers() & wxMOD_SHIFT) {
            SetSelectionEnd(GetCursorPosition());
        } else {
            if (navigationEvent) {
                ClearSelection();
            }
        }

        if (!eventHandled) {
            keyEvent.Skip();
        }

        Refresh();
    }