Open a context menu with actions in TextView widget

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?

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 H. ([email protected]):

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 - [email protected] che bisogno ci
    sarebbe
    •           di parlare tanto di amore e di rettitudine? 
      

(Chuang-Tzu)