From 66f214e9dae0e808ba48165f31ffecd92239f291 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 28 Nov 2008 00:41:01 +0000 Subject: Add File->Draw to render patch to graphviz (which can then be used to draw to PDF or SVG or PNG or whatever). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1810 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/PatchWindow.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/gui/PatchWindow.hpp | 2 ++ src/gui/ingen_gui.glade | 16 ++++++++++++++++ 3 files changed, 64 insertions(+) (limited to 'src/gui') diff --git a/src/gui/PatchWindow.cpp b/src/gui/PatchWindow.cpp index 30806c7c..7d9980df 100644 --- a/src/gui/PatchWindow.cpp +++ b/src/gui/PatchWindow.cpp @@ -69,6 +69,7 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, const Glib::RefPtrget_widget("patch_save_menuitem", _menu_save); xml->get_widget("patch_save_as_menuitem", _menu_save_as); xml->get_widget("patch_upload_menuitem", _menu_upload); + xml->get_widget("patch_draw_menuitem", _menu_draw); xml->get_widget("patch_edit_controls_menuitem", _menu_edit_controls); xml->get_widget("patch_cut_menuitem", _menu_cut); xml->get_widget("patch_copy_menuitem", _menu_copy); @@ -106,6 +107,8 @@ PatchWindow::PatchWindow(BaseObjectType* cobject, const Glib::RefPtrsignal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_upload)); + _menu_draw->signal_activate().connect( + sigc::mem_fun(this, &PatchWindow::event_draw)); _menu_edit_controls->signal_activate().connect( sigc::mem_fun(this, &PatchWindow::event_edit_controls)); _menu_copy->signal_activate().connect( @@ -459,6 +462,49 @@ PatchWindow::event_upload() } +void +PatchWindow::event_draw() +{ + Gtk::FileChooserDialog dialog(*this, "Draw to DOT", Gtk::FILE_CHOOSER_ACTION_SAVE); + + dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + Gtk::Button* save_button = dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + save_button->property_has_default() = true; + + int result = dialog.run(); + + if (result == Gtk::RESPONSE_OK) { + string filename = dialog.get_filename(); + if (filename.find(".") == string::npos) + filename += ".dot"; + + bool confirm = false; + std::fstream fin; + fin.open(filename.c_str(), std::ios::in); + if (fin.is_open()) { // File exists + const string msg = string("File exists!\n") + + "Are you sure you want to overwrite " + filename + "?"; + Gtk::MessageDialog confirm_dialog(*this, + msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_YES_NO, true); + if (confirm_dialog.run() == Gtk::RESPONSE_YES) + confirm = true; + else + confirm = false; + } else { // File doesn't exist + confirm = true; + } + fin.close(); + + if (confirm) { + _view->canvas()->render_to_dot(filename); + _status_bar->push( + (boost::format("Rendered %1% to %2%") % _patch->path() % filename).str(), + STATUS_CONTEXT_PATCH); + } + } +} + + void PatchWindow::event_edit_controls() { diff --git a/src/gui/PatchWindow.hpp b/src/gui/PatchWindow.hpp index 5cfa2936..007d51b7 100644 --- a/src/gui/PatchWindow.hpp +++ b/src/gui/PatchWindow.hpp @@ -85,6 +85,7 @@ private: void event_save(); void event_save_as(); void event_upload(); + void event_draw(); void event_edit_controls(); void event_copy(); void event_paste(); @@ -119,6 +120,7 @@ private: Gtk::MenuItem* _menu_save; Gtk::MenuItem* _menu_save_as; Gtk::MenuItem* _menu_upload; + Gtk::MenuItem* _menu_draw; Gtk::CheckMenuItem* _menu_edit_controls; Gtk::MenuItem* _menu_cut; Gtk::MenuItem* _menu_copy; diff --git a/src/gui/ingen_gui.glade b/src/gui/ingen_gui.glade index 402e5466..b10e0425 100644 --- a/src/gui/ingen_gui.glade +++ b/src/gui/ingen_gui.glade @@ -102,6 +102,22 @@ + + + True + _Draw... + True + + + + + True + gtk-print + 1 + + + + True -- cgit v1.2.1