From 2aa30324422f2d53c191d0abc4e4243fd792e898 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 14 Jun 2017 21:20:41 -0400 Subject: Use user interface files for the user interface --- src/widgets/toolbox.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/widgets/toolbox.cpp') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 016eafdaa..3f595dd35 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -61,7 +61,7 @@ #include "../xml/attribute-record.h" #include "../xml/node-event-vector.h" #include "ui/uxmanager.h" - +#include "io/resource.h" #include "arc-toolbar.h" #include "box3d-toolbar.h" @@ -101,6 +101,9 @@ using Inkscape::UI::PrefPusher; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::Tools::ToolBase; +using Inkscape::IO::Resource::get_filename; +using Inkscape::IO::Resource::UI; + typedef void (*SetupFunction)(GtkWidget *toolbox, SPDesktop *desktop); typedef void (*UpdateFunction)(SPDesktop *desktop, ToolBase *eventcontext, GtkWidget *toolbox); @@ -1209,7 +1212,15 @@ static void setupToolboxCommon( GtkWidget *toolbox, GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - gtk_ui_manager_add_ui_from_string( mgr, descr, -1, &errVal ); + + // This isn't good, but it is flexible. + if(descr[0] == '<') { + gtk_ui_manager_add_ui_from_string( mgr, descr, -1, &errVal ); + } else { + char const *filename = get_filename(UI, descr); + gtk_ui_manager_add_ui_from_file( mgr, filename, &errVal ); + g_warning("RET CODE: %d", errVal); + } GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, toolbarName ); if ( prefs->getBool("/toolbox/icononly", true) ) { @@ -1313,12 +1324,14 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { - gchar const * descr = + gchar const * descr = "tool-toolbar.ui"; + /* "" " " " " " " + " " " " " " " " @@ -1360,6 +1373,7 @@ void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) #endif " " ""; +*/ setupToolboxCommon( toolbox, desktop, descr, "/ui/ToolToolbar", -- cgit v1.2.3 From 6ad9341631773d37617538bf0367400388dc807a Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 15 Jun 2017 13:15:06 -0400 Subject: Cleanup old xml --- src/widgets/toolbox.cpp | 59 ++++--------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) (limited to 'src/widgets/toolbox.cpp') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 3f595dd35..846321c71 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -1219,7 +1219,6 @@ static void setupToolboxCommon( GtkWidget *toolbox, } else { char const *filename = get_filename(UI, descr); gtk_ui_manager_add_ui_from_file( mgr, filename, &errVal ); - g_warning("RET CODE: %d", errVal); } GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, toolbarName ); @@ -1324,60 +1323,10 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { - gchar const * descr = "tool-toolbar.ui"; - /* - "" - " " - - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - - " " - " " - - " " - " " - " " - -#if HAVE_POTRACE - " " - " " -#endif - - " " -#ifdef WITH_MESH - " " -#endif - " " - - " " -#ifdef WITH_LPETOOL - " " -#endif - " " - ""; -*/ - - setupToolboxCommon( toolbox, desktop, descr, - "/ui/ToolToolbar", - "/toolbox/tools/small"); + setupToolboxCommon( toolbox, desktop, + "tool-toolbar.ui", + "/ui/ToolToolbar", + "/toolbox/tools/small"); } void update_tool_toolbox( SPDesktop *desktop, ToolBase *eventcontext, GtkWidget * /*toolbox*/ ) -- cgit v1.2.3 From efab230bdeb40f1e217a0e1b825cb38b685129ea Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 15 Jun 2017 22:08:04 -0400 Subject: Complete to move to using ui files instead of compiled in xml --- src/widgets/toolbox.cpp | 493 +++--------------------------------------------- 1 file changed, 23 insertions(+), 470 deletions(-) (limited to 'src/widgets/toolbox.cpp') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 846321c71..671689716 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -225,390 +225,6 @@ static struct { { NULL, NULL, NULL, NULL, NULL, SP_VERB_INVALID, NULL, NULL } }; -static gchar const * ui_descr = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - -#if HAVE_POTRACE - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " -#endif - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " -// " " -// " " -// " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - - "" -; static Glib::RefPtr create_or_fetch_actions( SPDesktop* desktop ); @@ -1199,7 +815,7 @@ void ToolboxFactory::setToolboxDesktop(GtkWidget *toolbox, SPDesktop *desktop) static void setupToolboxCommon( GtkWidget *toolbox, SPDesktop *desktop, - gchar const *descr, + gchar const *ui_file, gchar const* toolbarName, gchar const* sizePref ) { @@ -1207,18 +823,17 @@ static void setupToolboxCommon( GtkWidget *toolbox, Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkUIManager* mgr = gtk_ui_manager_new(); - GError* errVal = 0; + GError* err = 0; GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - // This isn't good, but it is flexible. - if(descr[0] == '<') { - gtk_ui_manager_add_ui_from_string( mgr, descr, -1, &errVal ); - } else { - char const *filename = get_filename(UI, descr); - gtk_ui_manager_add_ui_from_file( mgr, filename, &errVal ); + char const *filename = get_filename(UI, ui_file); + gtk_ui_manager_add_ui_from_file( mgr, filename, &err ); + if(err) { + g_warning("Failed to load %s: %s", filename, err->message); + return; } GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, toolbarName ); @@ -1354,9 +969,15 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) GtkSizeGroup* grouper = gtk_size_group_new( GTK_SIZE_GROUP_BOTH ); Glib::RefPtr mainActions = create_or_fetch_actions( desktop ); GtkUIManager* mgr = gtk_ui_manager_new(); - GError* errVal = 0; + GError *err = 0; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - gtk_ui_manager_add_ui_from_string( mgr, ui_descr, -1, &errVal ); + + char const *filename = get_filename(UI, "select-toolbar.ui"); + guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename, &err); + if(err) { + g_warning("Failed to load aux toolbar %s: %s", filename, err->message); + return; + } std::map dataHolders; @@ -1457,49 +1078,10 @@ void update_aux_toolbox(SPDesktop * /*desktop*/, ToolBase *eventcontext, GtkWidg void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { - gchar const * descr = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; - - setupToolboxCommon( toolbox, desktop, descr, - "/ui/CommandsToolbar", - "/toolbox/small" ); + setupToolboxCommon( toolbox, desktop, + "commands-toolbar.ui", + "/ui/CommandsToolbar", + "/toolbox/small" ); } void update_commands_toolbox(SPDesktop * /*desktop*/, ToolBase * /*eventcontext*/, GtkWidget * /*toolbox*/) @@ -1635,36 +1217,6 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { Glib::RefPtr mainActions = create_or_fetch_actions(desktop); - gchar const * descr = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - //" " - " " - ""; - Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); { @@ -1843,9 +1395,10 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox ); } - setupToolboxCommon( toolbox, desktop, descr, - "/ui/SnapToolbar", - "/toolbox/secondary" ); + setupToolboxCommon( toolbox, desktop, + "snap-toolbar.ui", + "/ui/SnapToolbar", + "/toolbox/secondary" ); } Glib::ustring ToolboxFactory::getToolboxName(GtkWidget* toolbox) -- cgit v1.2.3 From 26b5429dbb1921b2fc1efc89f22268b85afd9163 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 16 Jun 2017 07:18:39 -0400 Subject: Fix err leaking and cmake --- src/widgets/toolbox.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/widgets/toolbox.cpp') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 671689716..45f81ee81 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -833,6 +833,7 @@ static void setupToolboxCommon( GtkWidget *toolbox, gtk_ui_manager_add_ui_from_file( mgr, filename, &err ); if(err) { g_warning("Failed to load %s: %s", filename, err->message); + g_error_free(err); return; } @@ -976,6 +977,7 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename, &err); if(err) { g_warning("Failed to load aux toolbar %s: %s", filename, err->message); + g_error_free(err); return; } -- cgit v1.2.3 From bfc9d4824f8ffa3c3807c520f3dc20f25cc0a727 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 16 Jun 2017 10:29:04 -0400 Subject: Attempt to make paintbucket build option not cause errors for toolbar loading --- src/widgets/toolbox.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/widgets/toolbox.cpp') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 45f81ee81..65c54f0ce 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -156,6 +156,9 @@ static struct { { "/tools/eraser", "eraser_tool", SP_VERB_CONTEXT_ERASER, SP_VERB_CONTEXT_ERASER_PREFS }, #if HAVE_POTRACE { "/tools/paintbucket", "paintbucket_tool", SP_VERB_CONTEXT_PAINTBUCKET, SP_VERB_CONTEXT_PAINTBUCKET_PREFS }, +#else + // Replacement blank action for ToolPaintBucket to prevent loading errors in ui file + { "/tools/paintbucket", "ToolPaintBucket", SP_VERB_NONE, SP_VERB_NONE }, #endif { "/tools/text", "text_tool", SP_VERB_CONTEXT_TEXT, SP_VERB_CONTEXT_TEXT_PREFS }, { "/tools/connector","connector_tool", SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_CONNECTOR_PREFS }, @@ -221,6 +224,8 @@ static struct { #if HAVE_POTRACE { "/tools/paintbucket", "paintbucket_toolbox", 0, sp_paintbucket_toolbox_prep, "PaintbucketToolbar", SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "/tools/paintbucket", N_("Style of Paint Bucket fill objects")}, +#else + { "/tools/paintbucket", "paintbucket_toolbox", 0, NULL, "PaintbucketToolbar", SP_VERB_NONE, "/tools/paintbucket", N_("Disabled")}, #endif { NULL, NULL, NULL, NULL, NULL, SP_VERB_INVALID, NULL, NULL } }; @@ -614,6 +619,12 @@ static Glib::RefPtr create_or_fetch_actions( SPDesktop* deskto if ( i == 0 ) { va->set_active(true); } + } else { + // This creates a blank action using the data_name, this can replace + // tools that have been disabled by compile time options. + Glib::RefPtr act = Gtk::Action::create(Glib::ustring(tools[i].data_name)); + act->set_sensitive(false); + mainActions->add(act); } } } -- cgit v1.2.3