diff options
| author | Martin Owens <doctormo@gmail.com> | 2017-06-15 01:20:41 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2017-06-15 01:20:41 +0000 |
| commit | 2aa30324422f2d53c191d0abc4e4243fd792e898 (patch) | |
| tree | a912674b1bd059ddac7bfd44ec2e1849eb06176c /src | |
| parent | Merge branch 'master' of gitlab.com:marcjeanmougin/inkscape (diff) | |
| download | inkscape-2aa30324422f2d53c191d0abc4e4243fd792e898.tar.gz inkscape-2aa30324422f2d53c191d0abc4e4243fd792e898.zip | |
Use user interface files for the user interface
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/resource.cpp | 36 | ||||
| -rw-r--r-- | src/io/resource.h | 2 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 20 |
3 files changed, 53 insertions, 5 deletions
diff --git a/src/io/resource.cpp b/src/io/resource.cpp index 501eab03b..52ac884b1 100644 --- a/src/io/resource.cpp +++ b/src/io/resource.cpp @@ -19,15 +19,18 @@ #include <glib.h> // g_assert() #include "path-prefix.h" #include "inkscape.h" +#include "io/sys.h" #include "io/resource.h" +using Inkscape::IO::file_test; + namespace Inkscape { namespace IO { namespace Resource { -Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) +gchar *_get_path(Domain domain, Type type, char const *filename) { gchar *path=NULL; switch (domain) { @@ -71,7 +74,8 @@ Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) case PALETTES: name = "palettes"; break; case PATTERNS: name = "patterns"; break; case TEMPLATES: name = "templates"; break; - default: return get_path(SYSTEM, type, filename); + case UI: name = "ui"; break; + default: return _get_path(SYSTEM, type, filename); } path = Inkscape::Application::profile_path(name); } break; @@ -83,11 +87,39 @@ Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) path = temp; } + return path; +} + +Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) +{ + char *path = _get_path(domain, type, filename); Util::ptr_shared<char> result=Util::share_string(path); g_free(path); return result; } +/* + * Same as get_path, but checks for file's existance and falls back + * from USER to SYSTEM modes. + */ +Util::ptr_shared<char> get_filename(Type type, char const *filename) +{ + Util::ptr_shared<char> result; + char *user_filename = _get_path(USER, type, filename); + char *sys_filename = _get_path(SYSTEM, type, filename); + + if (file_test(user_filename, G_FILE_TEST_EXISTS)) { + result = Util::share_string(user_filename); + } else if(file_test(sys_filename, G_FILE_TEST_EXISTS)) { + result = Util::share_string(sys_filename); + } else { + g_warning("Failed to load resource: %s", filename); + } + g_free(user_filename); + g_free(sys_filename); + return result; +} + } } diff --git a/src/io/resource.h b/src/io/resource.h index 36fe5f81e..fbf2111f4 100644 --- a/src/io/resource.h +++ b/src/io/resource.h @@ -48,6 +48,8 @@ enum Domain { Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename=NULL); +Util::ptr_shared<char> get_filename(Type type, char const *filename=NULL); + } } 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"; + /* "<ui>" " <toolbar name='ToolToolbar'>" " <!-- Basics -->" " <toolitem action='ToolSelector' />" + " <toolitem action='FooBar' />" " <toolitem action='ToolNode' />" " <toolitem action='ToolTweak' />" " <toolitem action='ToolZoom' />" @@ -1360,6 +1373,7 @@ void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) #endif " </toolbar>" "</ui>"; +*/ setupToolboxCommon( toolbox, desktop, descr, "/ui/ToolToolbar", |
