Class: Redcar::ApplicationSWT::Notebook
- Inherits:
-
Object
- Object
- Redcar::ApplicationSWT::Notebook
show all
- Includes:
- Observable
- Defined in:
- plugins/application_swt/lib/application_swt/notebook.rb,
plugins/application_swt/lib/application_swt/notebook/tab_transfer.rb,
plugins/application_swt/lib/application_swt/notebook/tab_drag_and_drop_listener.rb
Defined Under Namespace
Classes: CTabFolder2Listener, MiddleMouseListener, SelectionListener, TabDragAndDropListener, TabTransfer
Constant Summary
Constant Summary
Constants included
from Observable
Observable::ASPECTS
Instance Attribute Summary (collapse)
Instance Method Summary
(collapse)
Methods included from Observable
#add_listener, #notify_listeners, #remove_listener
Constructor Details
- (Notebook) initialize(model, sash)
A new instance of Notebook
73
74
75
76
77
78
79
80
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 73
def initialize(model, sash)
@model = model
@model.controller = self
create_tab_folder(sash)
style_tab_folder
attach_model_listeners
attach_view_listeners
end
|
Instance Attribute Details
Returns the value of attribute model
6
7
8
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 6
def model
@model
end
|
- (Object) tab_folder
Returns the value of attribute tab_folder
6
7
8
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 6
def tab_folder
@tab_folder
end
|
Instance Method Details
- (Object) attach_model_listeners
122
123
124
125
126
127
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 122
def attach_model_listeners
@model.add_listener(:tab_added) do |tab|
tab.controller = Redcar.gui.controller_for(tab).new(tab, self)
end
@model.add_listener(:tab_moved, &method(:model_event_tab_moved))
end
|
- (Object) attach_view_listeners
129
130
131
132
133
134
135
136
137
138
139
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 129
def attach_view_listeners
@tab_folder.add_ctab_folder2_listener(CTabFolder2Listener.new(self))
@tab_folder.add_selection_listener(SelectionListener.new(self))
@tab_folder.addMouseListener(MiddleMouseListener.new(self))
@tab_folder.add_listener(Swt::SWT::MenuDetect) do |event|
point = ApplicationSWT.display.map(nil, @tab_folder, Swt::Graphics::Point.new(event.x, event.y))
if item = @tab_folder.getItem(point)
@model.right_click_on_tab(tab_item_to_tab_model(item))
end
end
end
|
- (Object) create_tab_folder(sash)
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 82
def create_tab_folder(sash)
folder_style = Swt::SWT::CLOSE
@tab_folder = Swt::Custom::CTabFolder.new(sash, folder_style)
font_data = @tab_folder.font.font_data.first
font = Swt::Graphics::Font.new(
ApplicationSWT.display,
font_data.name,
Redcar::EditView.font_size - 1,
Swt::SWT::NORMAL)
@tab_folder.font = font
grid_data = Swt::Layout::GridData.new
grid_data.grabExcessHorizontalSpace = true
grid_data.horizontalAlignment = Swt::Layout::GridData::FILL
@tab_folder.set_layout_data(grid_data)
@tab_folder.pack
register_tab_dnd(@tab_folder)
end
|
163
164
165
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 163
def dispose
@tab_folder.dispose
end
|
- (Object) model_event_focus_tab(tab)
Called by the models when a tab is selected by Redcar.
142
143
144
145
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 142
def model_event_focus_tab(tab)
tab_folder.set_selection(tab.item)
@model.select_tab!(tab.model)
end
|
- (Object) model_event_tab_moved(from_notebook, to_notebook, tab_model)
147
148
149
150
151
152
153
154
155
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 147
def model_event_tab_moved(from_notebook, to_notebook, tab_model)
tab_controller = tab_model.controller
title = tab_model.title
tab_controller.set_notebook(to_notebook.controller)
tab_controller.create_item_widget
tab_controller.move_tab_widget_to_current_notebook
tab_controller.focus
tab_model.title = title
end
|
- (Object) recalculate_tab_order
157
158
159
160
161
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 157
def recalculate_tab_order
@model.sort_tabs! do |a,b|
tab_folder.index_of(a.controller.item) <=> tab_folder.index_of(b.controller.item)
end
end
|
- (Object) register_tab_dnd(tab_folder)
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 100
def register_tab_dnd(tab_folder)
dnd_listener = TabDragAndDropListener.new(self)
operations = (Swt::DND::DND::DROP_COPY | Swt::DND::DND::DROP_DEFAULT | Swt::DND::DND::DROP_MOVE)
transfer_types = [TabTransfer.get_instance].to_java(:org.eclipse.swt.dnd.ByteArrayTransfer")
drag_source = Swt::DND::DragSource.new(tab_folder, operations)
drag_source.set_transfer(transfer_types)
drag_source.add_drag_listener(dnd_listener)
drop_target = Swt::DND::DropTarget.new(tab_folder, operations)
drop_target.set_transfer(transfer_types)
drop_target.add_drop_listener(dnd_listener)
end
|
- (Object) style_tab_folder
114
115
116
117
118
119
120
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 114
def style_tab_folder
selected_tab_background = Redcar::ApplicationSWT.selected_tab_background
@tab_folder.set_selection_background(selected_tab_background.swt_colors, selected_tab_background.swt_stops, true)
unselected_tab_background = Redcar::ApplicationSWT.unselected_tab_background
@tab_folder.set_background(unselected_tab_background.swt_colors, unselected_tab_background.swt_stops, true)
end
|
167
168
169
|
# File 'plugins/application_swt/lib/application_swt/notebook.rb', line 167
def tab_widget_to_tab_model(tab_widget)
@model.tabs.detect {|tab| tab.controller.item == tab_widget }
end
|