1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'observer_utils'
10 class MultiView < KDE::TabWidget
15 def initialize(parent, movelist_stack)
17 @movelist_stack = movelist_stack
20 tab_bar.visible = false
21 tab_bar.tabs_closable = true
22 on(:current_changed) {|i| self.index = i; fire :changed }
23 tab_bar.on(:tab_close_requested) {|i| delete_at(i) }
27 if value >= 0 and value < size and value != @index
29 self.current_index = value
30 @movelist_stack.current_index = value
40 def add(view, opts = { })
42 i = add_tab(view.main_widget, opts[:name] || "?")
44 raise "[bug] inconsistent MultiView index #{size - 1}, expected #{i}"
46 @movelist_stack.insert_widget(i, view.movelist)
47 if opts[:activate] || index == -1
50 tab_bar.visible = size > 1
55 raise "Cannot delete last view" if size <= 1
56 if index >= 0 and index < size
57 self.index -= 1 if index <= @index
59 v = @views.delete_at(index)
60 @movelist_stack.remove_widget(v.movelist)
61 tab_bar.visible = size > 1