TerminalWx icon indicating copy to clipboard operation
TerminalWx copied to clipboard

How do I add an Edit menu for copy/paste/select all?

Open rayarachelian opened this issue 5 years ago • 2 comments

The testapp doesn't seem to have an edit menu, but I do see some stuff here:

./taTelnet/wxterm.cpp around like 900 there's a mark selection method.

But when I click and drag in the terminal window on displayed text, it doesn't get selected, or at least the text doesn't get highlighted.

After adding a default Edit menu with default Copy/Paste items, they don't do anything, so I'd need to bridge those events to some of these methods.

I suppose Paste is easy enough to implement, can get a string from the clipboard and feed it to the SendBack method.

But not sure how I'd do copy and Select.

rayarachelian avatar Jan 13 '21 04:01 rayarachelian

This code worked for both OnCopy and OnSelect all Edit menu items, however, dragging in the window does not highlight the text, so there's no feedback of selection. (I allow multiple terminals, so I'm using arrays for Terminal, hence Terminal[portnum] - if your code only has one, edit accordingly to point to your TerminalWx object, etc.)

The select code in wxterm.cpp needs some way to redraw the selected test with inverted background/foreground colors during the MarkSelection method to indicate the selection, so that's one issue.

The next issue is that OnSelectAll followed by Copy, results in a block of text 80x25 in size, with excess spaces at the ends of the lines and all spaces on blank lines, so not as nice as can be. Looks like I'll have to add some code to trim the excess white space and empty lines.

Next, the usual double click to select a word, triple click to select a line semantics as in most terminal emulators don't exist.

void TerminalWxFrame::OnCopy(wxCommandEvent& event) {
    if (Terminal[portnum]->HasSelection()) {

        wxString Selection = Terminal[portnum]->GetSelection();
        if (wxTheClipboard->Open())
        {
            wxTheClipboard->SetData( new wxTextDataObject(Selection) );
            wxTheClipboard->Flush();
            wxTheClipboard->Close();
        }
    }

    event.Skip();
}

void TerminalWxFrame::OnSelectAll(wxCommandEvent& WXUNUSED(event)) { Terminal[portnum]->SelectAll(); }

rayarachelian avatar Dec 24 '21 04:12 rayarachelian

So, actually the selection does happen, however, the display isn't refreshed. If I switch windows away from the terminalwx window, OnLoseFocus is called, and then the selection appears, however, as I drag across some text to select it, it doesn't get highlighted. I've also noticed that a size event can also make it appear.

EDIT: It looks like the fix is to call Refresh() in OnMouseMove and OnSelectAll() to make the selection show uo.

rayarachelian avatar Jan 07 '22 19:01 rayarachelian