Copy & paste event

hi. now I have problem about copy and paste text in my application I
make copy and paste button in toolbar and I have fuction of them but I
don’t know how to make it can copy only selection text and paste into
other textCtrl. see my picture for more info. thank you :slight_smile:

Hi

Pat K. wrote:

hi. now I have problem about copy and paste text in my application I
make copy and paste button in toolbar and I have fuction of them but I
don’t know how to make it can copy only selection text and paste into
other textCtrl. see my picture for more info. thank you :slight_smile:

If you just want ToolBar buttons that do the “normal” thing for
cut/copy/paste - i.e. do that action to the current selection in the
current active widget - just give the Tool the relevant standard id when
you create it. For example

toolbar.add_tool(Wx::ID_COPY, ‘Cut’, bitmap_1 …)

Or Wx::ID_CUT, Wx::ID_PASTE. No additional programming effort should be
needed

alex

I use

tb.add_tool(ID_COPY, “Copy”, ArtProvider::get_bitmap(ART_COPY))

but when I click it can’t copy some text
what’s wrong :’(

Pat K. wrote:

tb.add_tool(ID_COPY, “Copy”, ArtProvider::get_bitmap(ART_COPY))

but when I click it can’t copy some text
what’s wrong :’(

Add something like

evt_tool(Wx::ID_COPY) :on_copy

then create a method like:

def on_copy
text_box.copy
end

alex

:’(

tb.add_tool(ID_COPY, "Copy", ArtProvider::get_bitmap(ART_COPY))
evt_tool(ID_COPY){|event| on_copy()}

def on_copy()
  @textbox2.copy
end

then I copy it’s ok but it can copy only @textbox2 and and I have many
textbox. how can I use it to copy only selected text not dependent
textbox? I have @textbox1, @textbox2 and @textbox3

Pat K. wrote:

IMHO it seems a confusing UI design to have a toolbar button that can
interact with one of several different widgets depending on
circumstances. Anyway, it’s up to you to decide the logic by which one
of the text boxes is chosen to have its selection copied.

Perhaps, you could use evt_set_focus to track the most recently focussed
textbox, or perhaps you could test each textbox in turn with
get_selection to see if it has a selection.

Suggest you spend some time trying things out and working through the
wxruby samples and documentation to see what’s possible.

alex

Thank you I use it now!!
:smiley:

now I have problem with paste :frowning:
when I copy I use this

  a = @textbox1.get_selection()
  b = @textbox2.get_selection()
  c = @textbox3.get_selection()
  if a[1] - a[0] != 0
    @textbox1.copy
  elsif b[1] - b[0] != 0
    @textbox2.copy
  elsif c[1] - c[0] != 0
    @textbox3.copy
  end

to check where @textbox was selected but when I want to paste it can’t
use this I try to think but I don’t know how can I fix it please help me
:’(

Pat K. wrote:

to check where @textbox was selected but when I want to paste it can’t
use this I try to think but I don’t know how can I fix it please help me

http://wxruby.rubyforge.org/doc/textctrl.html#TextCtrl_paste

As for which TextCtrl to paste into, I have no idea because you haven’t
given us any idea of what your app is meant to do.

If you wanted to track the last-focussed TextCtrl, it might be something
like (untested):

evt_child_focus do | event |
if [ @textbox1, @textbox2, @textbox3 ].any?(event.window)
@focussed_textbox = event.window
end
end

When posting, it helps a lot if you write clearly what you want to do,
what you’ve tried, and what you expected to happen. Don’t expect other
people to guess or do your work for you.

alex

sorry, I will explain again :slight_smile:

I have three textbox like this picture, and I have copy, paste, cut on
toolbar and I want to make when user click at copy it will copy text
that selected (I can do it now) and then I want to paste text in other
textbox

example
first I copy ‘sssss’ on left textbox, it’s ok. then I want to paste it
in right textbox that I point into it (see picture)

if I use @textbox2.paste in function on_paste. it’s ok but it can paste
only right textbox when I point mouse at left textbox and paste it, it
will appear at riht textbox :’(