142 |
sigc::mem_fun(*this, &ScriptEditor::onWindowHide) |
sigc::mem_fun(*this, &ScriptEditor::onWindowHide) |
143 |
); |
); |
144 |
|
|
145 |
|
signal_delete_event().connect( |
146 |
|
sigc::mem_fun(*this, &ScriptEditor::onWindowDelete) |
147 |
|
); |
148 |
|
|
149 |
show_all_children(); |
show_all_children(); |
150 |
|
|
151 |
resize(460,300); |
resize(460,300); |
368 |
return ManagedWindow::on_motion_notify_event(e); |
return ManagedWindow::on_motion_notify_event(e); |
369 |
} |
} |
370 |
|
|
371 |
|
bool ScriptEditor::onWindowDelete(GdkEventAny* e) { |
372 |
|
//printf("onWindowDelete\n"); |
373 |
|
|
374 |
|
if (!isModified()) return false; // propagate event further (which will close this window) |
375 |
|
|
376 |
|
gchar* msg = g_strdup_printf(_("Apply changes to instrument script \"%s\" before closing?"), |
377 |
|
m_script->Name.c_str()); |
378 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
379 |
|
g_free(msg); |
380 |
|
dialog.set_secondary_text(_("If you close without applying, your changes will be lost.")); |
381 |
|
dialog.add_button(_("Close _Without Applying"), Gtk::RESPONSE_NO); |
382 |
|
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
383 |
|
dialog.add_button(_("_Apply"), Gtk::RESPONSE_YES); |
384 |
|
dialog.set_default_response(Gtk::RESPONSE_YES); |
385 |
|
int response = dialog.run(); |
386 |
|
dialog.hide(); |
387 |
|
|
388 |
|
// user decided to close script editor without saving |
389 |
|
if (response == Gtk::RESPONSE_NO) |
390 |
|
return false; // propagate event further (which will close this window) |
391 |
|
|
392 |
|
// user cancelled dialog, thus don't close script editor |
393 |
|
if (response == Gtk::RESPONSE_CANCEL) { |
394 |
|
show(); |
395 |
|
return true; // drop event (prevents closing this window) |
396 |
|
} |
397 |
|
|
398 |
|
// user wants to apply the changes, afterwards close window |
399 |
|
if (response == Gtk::RESPONSE_YES) { |
400 |
|
onButtonApply(); |
401 |
|
return false; // propagate event further (which will close this window) |
402 |
|
} |
403 |
|
|
404 |
|
// should never ever make it to this point actually |
405 |
|
return false; |
406 |
|
} |
407 |
|
|
408 |
|
bool ScriptEditor::isModified() const { |
409 |
|
return m_textBuffer->get_modified(); |
410 |
|
} |
411 |
|
|
412 |
void ScriptEditor::onModifiedChanged() { |
void ScriptEditor::onModifiedChanged() { |
413 |
m_applyButton.set_sensitive( m_textBuffer->get_modified() ); |
m_applyButton.set_sensitive(isModified()); |
414 |
} |
} |
415 |
|
|
416 |
void ScriptEditor::onButtonCancel() { |
void ScriptEditor::onButtonCancel() { |
417 |
|
bool dropEvent = onWindowDelete(NULL); |
418 |
|
if (dropEvent) return; |
419 |
hide(); |
hide(); |
420 |
} |
} |
421 |
|
|