Forum: Ruby-Gnome 2 Open a context menu with actions in TextView widget

4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2013-08-24 02:30
Hi.

I have a question.

I have a window with three things - ScrolledWindow, TextBuffer and
TextView.

I can select text just fine with my mouse.

Now I would like to press right mouse click on selection and popup a
small context menu, with entries that I wish to define on my own. I.e.
increase font size would be nice for the selection.

Does one of you have an idea how to get such a popup widget on right
click?
3853dd5371ac1e094fc45d6c2aa0e459?d=identicon&s=25 Carlo E. Prelz (Guest)
on 2013-08-24 08:06
(Received via mailing list)
Subject: [ruby-gnome2-devel-en] Open a context menu with actions in
TextView widget
  Date: sab 24 ago 13 02:30:37 +0200

Quoting Marc Heiler (ruby-forum-incoming@andreas-s.net):

> click?
You can trap signals for your textview: signal 'button-press-event' is
emitted when a mouse button is pressed, and 'button-release-event' is
emitted when the button is released.

So, if you have something like this:

ebfr=Gtk::TextBuffer::new
ebfr.text=<<-EOF
...
...
...
EOF

et=Gtk::TextView::new(ebfr)

you can add this:

et.signal_connect('button-press-event') do |tv,eb|
  ...
  ...
end
et.signal_connect('button-release-event') do |tv,eb|
  ...
  ...
end

This specific processing only takes place when the focus of the mouse
is within the textview.

The second parameter you receive when the signal is triggered is an
EventButton instance. Check if eb.button==3, and do whatever you need
to do.

Remember that the return value from the signal_connect block has
meaning. If you return true, it means you have made use of the signal,
and it does not need further processing. If you return false, the
signal is passed downwards.

So, if you want to do something on release of the third mouse button,
first avoid the window manager processing of the click as follows:

et.signal_connect('button-press-event') do |tv,eb|
  eb.button==3 ? true : false
end

Then do what you need to do at release

et.signal_connect('button-release-event') do |tv,eb|
  return false unless(eb.button==3)
  do_what_you_need()
  true
end

...
...

def do_what_you_need
  dialog=Gtk::Dialog::new(:title=>'my
title',:flags=>Gtk::Dialog::Flags::MODAL)
  ...
  ...
end

Hope this helps

Carlo

--
  *         Se la Strada e la sua Virtu' non fossero state messe da
parte,
* K * Carlo E. Prelz - fluido@fluido.as             che bisogno ci
sarebbe
  *               di parlare tanto di amore e di rettitudine?
(Chuang-Tzu)
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.