9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/ListHolder/ListButtonHolder/ListButton.rb', line 9
def initialize(properties,caller,holder=nil)
@caller=caller
@properties=properties
@holder=holder
@show_icon=if gtk_attribute('show-mode') then gtk_attribute('show-mode') == 'icon only' || gtk_attribute('show-mode') == 'icon and text' || false else true end
@show_text=if gtk_attribute('show-mode') then gtk_attribute('show-mode') == 'text only' || gtk_attribute('show-mode') == 'icon and text' || false else true end
@column_of_sensitivity=nil
if gtk_attribute('column-of-sensitivity')
if @caller.list.list_model..has_key?(gtk_attribute('column-of-sensitivity'))
@column_of_sensitivity=@caller.list.list_model.[gtk_attribute('column-of-sensitivity')]["model_col"]
else
warn("You need to add \"#{gtk_attribute('column-of-sensitivity')}\" as Invisible String to #{@caller.list}")
end
end
super()
set_use_underline(true)
set_relief(Gtk::ReliefStyle::NONE)
case @properties['btfunct']
when 'add'
@properties['display']='add' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::ADD,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked') do |c|
if @properties['target_moditemid'].to_i >0
case @properties['moditem_render_mode']
when 'embedded' then @caller.list.changed if @caller.notebook
when 'newwindow'
begin
form=Myform::MyFormHolder.new("dialog",self,"add",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id)
ensure
form.destroy
end
end
else edebug("builtin add row on #{@caller.list}","list-button","info")
@caller.list.add_row(nil)
end
end
when 'modify'
@properties['display']='modify' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::EDIT,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked') { |c|
if @properties['target_moditemid'].to_i >0
case @properties['moditem_render_mode']
when 'embedded' then @caller.list.changed if @caller.notebook
when 'newwindow'
begin
form=Myform::MyFormHolder.new("dialog",self,"modify",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id, @caller.list.selected_ids)
ensure
form.destroy
end
end
end }
when 'wysiwygf'
@properties['display']='wysiwyg' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::PROPERTIES,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){|c|
if @caller.list.get_cursor_id
form=Myform::MyFormHolder.new("dialog",self,"wysiwygf",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id)
end
}
when 'info'
properties['display']='info' if properties['display'].empty?
set_label(properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::INFO,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked') do |c|
if properties['target_moditemid'].to_i >0
case properties['moditem_render_mode']
when 'embedded'
caller.list.changed if caller.notebook
when 'newwindow'
if @caller.list.get_cursor_id
form=Myform::MyFormHolder.new("dialog",self,"info",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id)
end
end
end end
when 'copy'
@properties['display']='copy' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::COPY,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){|c|
if @properties['target_moditemid'].to_i >0
case @properties['moditem_render_mode']
when 'embedded'
@caller.list.changed if @caller.notebook
when 'newwindow'
if @caller.list.get_cursor_id
form=Myform::MyFormHolder.new("dialog",self,"copy",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id)
end
end
else warner=Gtk::MessageDialog.new(get_ancestor(Gtk::Window),Gtk::Dialog::DESTROY_WITH_PARENT,Gtk::MessageDialog::QUESTION,Gtk::MessageDialog::BUTTONS_YES_NO,"#{@properties['display']}?")
warner.set_image(Gtk::Image.new(Gtk::Stock::COPY,Gtk::IconSize::DIALOG))
if warner.show_all.run == Gtk::Dialog::RESPONSE_YES
@caller.list.duplicate_selected(self)
end
warner.destroy
end
}
when 'remove'
@properties['display']='remove' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::REMOVE,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){|me|
ids=Array.new
@caller.list.selection.selected_each { |model, path, iter| ids.push(iter[@caller.list.list_model.column_of_id])}
ids.each{|id_to_lock| @caller.list.list_model.lock_iter(id_to_lock)}
warner=Gtk::MessageDialog.new(get_ancestor(Gtk::Window),Gtk::Dialog::DESTROY_WITH_PARENT,Gtk::MessageDialog::QUESTION,Gtk::MessageDialog::BUTTONS_YES_NO,"#{@properties['display']} #{ids.size}?")
warner.set_image(Gtk::Image.new(Gtk::Stock::REMOVE,Gtk::IconSize::DIALOG))
begin
if warner.show_all.run == Gtk::Dialog::RESPONSE_YES
if @properties['target_moditemid'].to_i >0
ids.each{|id_to_rm|
@caller.list.set_cursor_id(id_to_rm)
if @caller.list.get_cursor_id
form=Myform::MyFormHolder.new("dialog",self,"remove",target).set_parentM(@caller.list)
ret=form.run(@caller.list.get_cursor_id)
@caller.list.remove_selected(self) if ret>=0
end
}
else
@caller.list.remove_selected(self,ids)
end
end
ensure
ids.each{|id_to_unlock| @caller.list.list_model.unlock_iter(id_to_unlock)}
ids=nil
warner.close
end
}
when 'print'
@properties['display']='print' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::PRINT,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked') do |c|
if @properties['target_moditemid'].to_i >0
ids=Array.new
@caller.list.selection.selected_each { |model, path, iter| ids.push(iter[@caller.list.list_model.column_of_id])}
if printop=MyPrintOperation.new(@caller.list,@properties['target_moditemid'].to_i,ids.join(","))
printop.run(Gtk::PrintOperation::Action::PRINT_DIALOG)
end
ids=nil
else
@caller.list.gtkprint
end
end
when 'pwysiwyg'
@properties['display']='wysiwyg print editor' if @properties['display'].empty?
set_label(@properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::PRINT_PREVIEW,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){ |c|
WysiwygPrintEditor.new(self,@caller.list.get_cursor_id).run if @caller.list.get_cursor_id
}
when 'export'
properties['display']='export' if properties['display'].empty?
set_label(properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::CONVERT,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){|c|
filechooser=Gtk::FileChooserDialog.new("Export to file",
@caller.get_ancestor(Gtk::Window),
Gtk::FileChooser::ACTION_SAVE,
nil,
[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
[Gtk::Stock::CONVERT, Gtk::Dialog::RESPONSE_ACCEPT])
filechooser.set_filename(get_conf(@caller.list.list_id,0,"csvfilename")) unless get_conf(@caller.list.list_id,0,"csvfilename").nil?
filechooser.add_filter(csv=Gtk::FileFilter.new.add_pattern("*.csv").set_name('csv'))
filechooser.set_filter(csv)
if filechooser.run == Gtk::Dialog::RESPONSE_ACCEPT
set_conf(@caller.list.list_id,0,"csvfilename",filechooser.filename)
@caller.list.list_model.to_csv(filechooser.filename)
end
filechooser.destroy
}
when 'import'
properties['display']='import' if properties['display'].empty?
set_label(properties['display']) if show_text?
set_image(Gtk::Image.new(Gtk::Stock::CONVERT,Gtk::IconSize.from_name(get_conf(0,0,"button-size")))) if show_icon?
signal_connect('clicked'){|c|
filechooser=Gtk::FileChooserDialog.new("Import from file",
@caller.get_ancestor(Gtk::Window),
Gtk::FileChooser::ACTION_OPEN,
nil,
[Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
[Gtk::Stock::CONVERT, Gtk::Dialog::RESPONSE_ACCEPT])
filechooser.set_filename(get_conf(@caller.list.list_id,0,"csvfilename")) unless get_conf(@caller.list.list_id,0,"csvfilename").nil?
ftype=(@caller.list.gtk_attribute("file_filter") ? @caller.list.gtk_attribute("file_filter").split(",") : ["*.csv"])
ftt=nil
ftype.each{|ft|
filechooser.add_filter(ftt=Gtk::FileFilter.new.add_pattern(ft).set_name(ft))
}
filechooser.set_filter(ftt) if ftt
if filechooser.run == Gtk::Dialog::RESPONSE_ACCEPT
set_conf(@caller.list.list_id,0,"csvfilename",filechooser.filename)
@caller.list.list_model.from_csv(filechooser.filename)
end
filechooser.destroy
}
else
p "Unknown Button: "+@properties['btfunct']
end
modify_label_widget_font if show_text?
@caller.list.tip.set_tip(self,@properties['display'],nil)
end
|