//------------------------------------ // Handle copy events //------------------------------------ void EditHandler::ProcessCommandEvent(wxWindow *owner, wxCommandEvent &event) { wxUnusedVar(event); LEditor *editor = (LEditor*)owner; OptionsConfigPtr options = editor->GetOptions(); // hide completion box editor->HideCompletionBox(); bool isSelectionEmpty = editor->GetSelectedText().IsEmpty(); if (event.GetId() == wxID_COPY) { // reset the 'full line' copy/cut flag editor->SetFullLineCopyCut(false); if ( isSelectionEmpty && options->HasOption( OptionsConfig::Opt_CopyNothing) ) { // do nothing } else if ( isSelectionEmpty && options->HasOption( OptionsConfig::Opt_CopyLineIfLineNotEmpty ) ) { // Copy the line content only when the caret line is not empty int lineNumber = editor->GetCurrentLine(); wxString lineContent = editor->GetLine(lineNumber); if ( !lineContent.Trim().Trim(false).IsEmpty() ) { editor->CopyAllowLine(); editor->SetFullLineCopyCut(true); } } else if ( isSelectionEmpty ) { // default behavior editor->CopyAllowLine(); editor->SetFullLineCopyCut(true); } else { editor->Copy(); } } else if (event.GetId() == wxID_CUT) { // reset the 'full line' copy/cut flag editor->SetFullLineCopyCut(false); if ( isSelectionEmpty && options->HasOption( OptionsConfig::Opt_CopyNothing) ) { // do nothing } else if ( isSelectionEmpty && options->HasOption( OptionsConfig::Opt_CopyLineIfLineNotEmpty ) ) { // Copy the line content only when the caret line is not empty int lineNumber = editor->GetCurrentLine(); wxString lineContent = editor->GetLine(lineNumber); if ( !lineContent.Trim().Trim(false).IsEmpty() ) { editor->CopyAllowLine(); editor->LineDelete(); editor->SetFullLineCopyCut(true); } } else if ( isSelectionEmpty ) { // default behavior editor->CopyAllowLine(); editor->LineDelete(); editor->SetFullLineCopyCut(true); } else { editor->Cut(); } } else if (event.GetId() == wxID_PASTE) { if ( editor->IsFullLineCopyCut() ) { // paste one line above the caret editor->PasteLineAbove(); } else { // paste at caret position editor->Paste(); } } else if (event.GetId() == wxID_UNDO) { if (editor->GetCommandsProcessor().CanUndo()) { editor->Undo(); editor->GetCommandsProcessor().DecrementCurrentCommand(); } } else if (event.GetId() == wxID_REDO) { if (editor->GetCommandsProcessor().CanRedo()) { editor->Redo(); editor->GetCommandsProcessor().IncrementCurrentCommand(); } } else if (event.GetId() == XRCID("label_current_state")) { wxString label = wxGetTextFromUser("What would you like to call the current state?", "Label current state", "", editor); if (!label.empty()) { editor->GetCommandsProcessor().SetUserLabel(label); } } else if (event.GetId() == wxID_SELECTALL) { editor->SelectAll(); } else if (event.GetId() == wxID_DUPLICATE) { editor->SelectionDuplicate(); } else if (event.GetId() == XRCID("delete_line_end")) { editor->DelLineRight(); } else if (event.GetId() == XRCID("delete_line_start")) { editor->DelLineLeft(); } else if (event.GetId() == XRCID("delete_line")) { editor->LineDelete(); } else if (event.GetId() == XRCID("trim_trailing")) { editor->TrimText(true, false); } else if (event.GetId() == XRCID("to_lower")) { editor->ChangeCase(true); } else if (event.GetId() == XRCID("to_upper")) { editor->ChangeCase(false); } else if (event.GetId() == XRCID("transpose_lines")) { editor->LineTranspose(); } else if (event.GetId() == wxID_DELETE) { editor->DeleteBack(); } else if (event.GetId() == XRCID("move_line_down")) { int curline = editor->GetCurrentLine(); int lastline = editor->LineFromPosition(editor->GetLength()-1); if (editor->GetSelection().empty() || (editor->LineFromPos(editor->GetSelectionStart() == editor->LineFromPos(editor->GetSelectionEnd())))) { // No selection (or only a trivial 1-line one) if (curline != lastline) { editor->LineDown(); editor->LineTranspose(); } } else { editor->MoveSelectedLinesDown(); // There is a selection, so we can move it direct } } else if (event.GetId() == XRCID("move_line_up")) { if (editor->GetSelection().empty() || (editor->LineFromPos(editor->GetSelectionStart() == editor->LineFromPos(editor->GetSelectionEnd())))) { // No selection (or only a trivial 1-line one) editor->LineTranspose(); editor->LineUp(); } else { editor->MoveSelectedLinesUp(); // There is a selection, so we can move it direct } } else if (event.GetId() == XRCID("center_line")) { //editor->VerticalCentreCaret(); } else if (event.GetId() == XRCID("center_line_roll")) { int here = editor->GetCurrentLine(); int top = editor->GetFirstVisibleLine(); int count = editor->LinesOnScreen(); int center = top + (count / 2); if (here < center) { for (int lnIterator = 0; lnIterator < center - here; lnIterator++) editor->LineScrollUp(); //roll up until we get to center } else if (here > center) { for (int lnIterator = 0; lnIterator < here - center; lnIterator++) editor->LineScrollDown(); //roll down until we get to center } } }