It looks like you're new here. If you want to get involved, click one of these buttons!
Hi all,
In the manual is written:
on_current_view_changed: This event is triggered when the current tab changes. The signal is available with an integer parameter: this is the index of the previous tab. The new tab is already the current tab when this event is triggered.
$mw = Application.instance.main_window
$code = proc { |last| puts "viewchanged #{last==nil}" }
$mw.on_current_view_changed=$code
worked but last is always nil.
When I substitute proc with lambda it is not working.
However you can work with a global variable saving $mw.current_view
In the end
$mw = Application.instance.main_window
$lastview=$mw.current_view
$mw.on_current_view_changed-=$code1_current_view_changed
$code1_current_view_changed = proc { puts "viewchanged #{$lastview}"; $lastview=$mw.current_view}
$mw.on_current_view_changed+=$code1_current_view_changed
worked fine for me.
(The line 3 can be obmitted, if the code is called only once.)
Best regards,
Frank
Comments
Hi Frank
you can also simple use a block instead of a proc:
But you're right about the nil. The documentation was incorrect - there is no such parameter The master is already updated.
But you do not need a global variable. This works for MainWindow as there is one one. But that's not a solution in other cases. One solution is to extend MainWindow to provide a new attribute you can use:
Another approach is a more object-oriented one which works with an observer object:
Kind regards,
Matthias