diff options
| -rw-r--r-- | src/actions/actions-base.cpp | 6 | ||||
| -rw-r--r-- | src/actions/actions-base.h | 5 | ||||
| -rw-r--r-- | src/actions/actions-output.cpp | 9 | ||||
| -rw-r--r-- | src/actions/actions-output.h | 4 | ||||
| -rw-r--r-- | src/actions/actions-selection.cpp | 7 | ||||
| -rw-r--r-- | src/actions/actions-selection.h | 5 | ||||
| -rw-r--r-- | src/actions/actions-transform.cpp | 7 | ||||
| -rw-r--r-- | src/actions/actions-transform.h | 5 | ||||
| -rw-r--r-- | src/inkscape-application.cpp | 194 | ||||
| -rw-r--r-- | src/inkscape-application.h | 51 | ||||
| -rw-r--r-- | src/inkscape-main.cpp | 6 |
11 files changed, 189 insertions, 110 deletions
diff --git a/src/actions/actions-base.cpp b/src/actions/actions-base.cpp index b24602ca7..252eb956f 100644 --- a/src/actions/actions-base.cpp +++ b/src/actions/actions-base.cpp @@ -201,8 +201,9 @@ vacuum_defs(InkscapeApplication* app) document->vacuumDocument(); } +template<class T> void -add_actions_base(InkscapeApplication* app) +add_actions_base(ConcreteInkscapeApplication<T>* app) { // Note: "radio" actions are just an easy way to set type without using templating. app->add_action("inkscape-version", sigc::ptr_fun(&print_inkscape_version )); @@ -224,6 +225,9 @@ add_actions_base(InkscapeApplication* app) } +template void add_actions_base(ConcreteInkscapeApplication<Gio::Application>* app); +template void add_actions_base(ConcreteInkscapeApplication<Gtk::Application>* app); + /* Local Variables: mode:c++ diff --git a/src/actions/actions-base.h b/src/actions/actions-base.h index a52078881..cf43b8e02 100644 --- a/src/actions/actions-base.h +++ b/src/actions/actions-base.h @@ -11,8 +11,9 @@ #ifndef INK_ACTIONS_BASE_H #define INK_ACTIONS_BASE_H -class InkscapeApplication; +template<class T> class ConcreteInkscapeApplication; -void add_actions_base(InkscapeApplication* app); +template<class T> +void add_actions_base(ConcreteInkscapeApplication<T>* app); #endif // INK_ACTIONS_BASE_H diff --git a/src/actions/actions-output.cpp b/src/actions/actions-output.cpp index 0ea7f6dc4..1d6946553 100644 --- a/src/actions/actions-output.cpp +++ b/src/actions/actions-output.cpp @@ -210,8 +210,9 @@ export_do(InkscapeApplication *app) app->file_export()->do_export(document, filename); } +template <class T> void -add_actions_output(InkscapeApplication* app) +add_actions_output(ConcreteInkscapeApplication<T>* app) { Glib::VariantType Bool( Glib::VARIANT_TYPE_BOOL); Glib::VariantType Int( Glib::VARIANT_TYPE_INT32); @@ -255,6 +256,12 @@ add_actions_output(InkscapeApplication* app) #endif } + +template void add_actions_output(ConcreteInkscapeApplication<Gio::Application>* app); +template void add_actions_output(ConcreteInkscapeApplication<Gtk::Application>* app); + + + /* Local Variables: mode:c++ diff --git a/src/actions/actions-output.h b/src/actions/actions-output.h index fffe1842d..01ea455f7 100644 --- a/src/actions/actions-output.h +++ b/src/actions/actions-output.h @@ -12,8 +12,10 @@ #define INK_ACTIONS_OUTPUT_H class InkscapeApplication; +template<class T> class ConcreteInkscapeApplication; -void add_actions_output(InkscapeApplication* app); +template<class T> +void add_actions_output(ConcreteInkscapeApplication<T>* app); #endif // INK_ACTIONS_OUTPUT_H diff --git a/src/actions/actions-selection.cpp b/src/actions/actions-selection.cpp index 5687ebdd7..7a46f5398 100644 --- a/src/actions/actions-selection.cpp +++ b/src/actions/actions-selection.cpp @@ -100,8 +100,9 @@ select_all(InkscapeApplication* app) std::cerr << "select_all: Not implemented!" << std::endl; } +template<class T> void -add_actions_selection(InkscapeApplication* app) +add_actions_selection(ConcreteInkscapeApplication<T>* app) { app->add_action( "select-clear", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_clear), app) ); app->add_action_radio_string( "select", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_id), app), "null"); // Backwards compatible. @@ -111,6 +112,10 @@ add_actions_selection(InkscapeApplication* app) app->add_action_radio_string( "select-via-selector",sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&select_via_selector), app), "null"); } +template void add_actions_selection(ConcreteInkscapeApplication<Gio::Application>* app); +template void add_actions_selection(ConcreteInkscapeApplication<Gtk::Application>* app); + + diff --git a/src/actions/actions-selection.h b/src/actions/actions-selection.h index 1d5a31127..f792a5cb8 100644 --- a/src/actions/actions-selection.h +++ b/src/actions/actions-selection.h @@ -11,9 +11,10 @@ #ifndef INK_ACTIONS_SELECTION_H #define INK_ACTIONS_SELECTION_H -class InkscapeApplication; +template<class T> class ConcreteInkscapeApplication; -void add_actions_selection(InkscapeApplication* app); +template<class T> +void add_actions_selection(ConcreteInkscapeApplication<T>* app); #endif // INK_ACTIONS_SELECTION_H diff --git a/src/actions/actions-transform.cpp b/src/actions/actions-transform.cpp index 2480363fa..10dabd76a 100644 --- a/src/actions/actions-transform.cpp +++ b/src/actions/actions-transform.cpp @@ -27,8 +27,9 @@ transform_rotate(const Glib::VariantBase& value, InkscapeApplication *app) selection->rotate(d.get()); } +template<class T> void -add_actions_transform(InkscapeApplication* app) +add_actions_transform(ConcreteInkscapeApplication<T>* app) { Glib::VariantType Bool( Glib::VARIANT_TYPE_BOOL); Glib::VariantType Int( Glib::VARIANT_TYPE_INT32); @@ -45,6 +46,10 @@ add_actions_transform(InkscapeApplication* app) +template void add_actions_transform(ConcreteInkscapeApplication<Gio::Application>* app); +template void add_actions_transform(ConcreteInkscapeApplication<Gtk::Application>* app); + + /* Local Variables: diff --git a/src/actions/actions-transform.h b/src/actions/actions-transform.h index 9b1b0dc3d..03c2afd97 100644 --- a/src/actions/actions-transform.h +++ b/src/actions/actions-transform.h @@ -11,9 +11,10 @@ #ifndef INK_ACTIONS_TRANSFORM_H #define INK_ACTIONS_TRANSFORM_H -class InkscapeApplication; +template<class T> class ConcreteInkscapeApplication; -void add_actions_transform(InkscapeApplication* app); +template<class T> +void add_actions_transform(ConcreteInkscapeApplication<T>* app); #endif // INK_ACTIONS_TRANSFORM_H diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index cf442ecbc..a5bde2d25 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -43,12 +43,14 @@ using Inkscape::IO::Resource::UIS; // flags are set. If the open flag is set and the command line not, the all the remainng arguments // after calling on_handle_local_options() are assumed to be filenames. -InkscapeApplication::InkscapeApplication() - : Gtk::Application("org.inkscape.application.with_gui", +InkscapeApplication::InkscapeApplication() : _with_gui(true), _use_shell(false) {} + +template<class T> +ConcreteInkscapeApplication<T>::ConcreteInkscapeApplication() + : T("org.inkscape.application.with_gui", Gio::APPLICATION_HANDLES_OPEN | // Use default file opening. Gio::APPLICATION_NON_UNIQUE ) // Allows different instances of Inkscape to run at same time. - , _with_gui(true) - , _use_shell(false) + , InkscapeApplication() { // ==================== Initializations ===================== @@ -74,86 +76,81 @@ InkscapeApplication::InkscapeApplication() // Note: OPTION_TYPE_FILENAME => std::string, OPTION_TYPE_STRING => Glib::ustring. // Actions - add_main_option_entry(OPTION_TYPE_STRING, "actions", 'a', N_("Actions (with optional arguments), semi-colon separated."), N_("ACTION(:ARG)[;ACTION(:ARG)]*")); - add_main_option_entry(OPTION_TYPE_BOOL, "action-list", '\0', N_("Actions: List available actions."), ""); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "actions", 'a', N_("Actions (with optional arguments), semi-colon separated."), N_("ACTION(:ARG)[;ACTION(:ARG)]*")); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "action-list", '\0', N_("Actions: List available actions."), ""); // Query - add_main_option_entry(OPTION_TYPE_BOOL, "version", 'V', N_("Print: Inkscape version."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "extensions-directory",'x', N_("Print: Extensions directory."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "verb-list", '\0', N_("Print: List verbs."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "version", 'V', N_("Print: Inkscape version."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "extensions-directory",'x', N_("Print: Extensions directory."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "verb-list", '\0', N_("Print: List verbs."), ""); // Interface - add_main_option_entry(OPTION_TYPE_BOOL, "with-gui", 'g', N_("GUI: With graphical interface."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "without-gui", 'G', N_("GUI: Console only."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "with-gui", 'g', N_("GUI: With graphical interface."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "without-gui", 'G', N_("GUI: Console only."), ""); // Open/Import - add_main_option_entry(OPTION_TYPE_INT, "pdf-page", '\0', N_("Open: PDF page to import"), N_("PAGE")); - add_main_option_entry(OPTION_TYPE_STRING, "convert-dpi-method", '\0', N_("Open: Method used to convert pre-0.92 document dpi, if needed: [none|scale-viewbox|scale-document]."), "[...]"); - add_main_option_entry(OPTION_TYPE_BOOL, "no-convert-text-baseline-spacing", 0, N_("Open: Do not fix pre-0.92 document's text baseline spacing on opening."), ""); + this->add_main_option_entry(T::OPTION_TYPE_INT, "pdf-page", '\0', N_("Open: PDF page to import"), N_("PAGE")); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "convert-dpi-method", '\0', N_("Open: Method used to convert pre-0.92 document dpi, if needed: [none|scale-viewbox|scale-document]."), "[...]"); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "no-convert-text-baseline-spacing", 0, N_("Open: Do not fix pre-0.92 document's text baseline spacing on opening."), ""); // Query - Geometry - add_main_option_entry(OPTION_TYPE_STRING, "query-id", 'I', N_("Query: ID(s) of object(s) to be queried."), N_("OBJECT-ID[,OBJECT-ID]*")); - add_main_option_entry(OPTION_TYPE_BOOL, "query-all", 'S', N_("Query: Print bounding boxes of all objects."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "query-x", 'X', N_("Query: X coordinate of drawing or object (if specified by --query-id)."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "query-y", 'Y', N_("Query: Y coordinate of drawing or object (if specified by --query-id)."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "query-width", 'W', N_("Query: Width of drawing or object (if specified by --query-id)."), ""); - add_main_option_entry(OPTION_TYPE_BOOL, "query-height", 'H', N_("Query: Heightof drawing or object (if specified by --query-id)."), ""); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "query-id", 'I', N_("Query: ID(s) of object(s) to be queried."), N_("OBJECT-ID[,OBJECT-ID]*")); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "query-all", 'S', N_("Query: Print bounding boxes of all objects."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "query-x", 'X', N_("Query: X coordinate of drawing or object (if specified by --query-id)."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "query-y", 'Y', N_("Query: Y coordinate of drawing or object (if specified by --query-id)."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "query-width", 'W', N_("Query: Width of drawing or object (if specified by --query-id)."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "query-height", 'H', N_("Query: Heightof drawing or object (if specified by --query-id)."), ""); // Processing - add_main_option_entry(OPTION_TYPE_BOOL, "vacuum-defs", '\0', N_("Process: Remove unused definitions from the <defs> section(s) of document."), ""); - add_main_option_entry(OPTION_TYPE_STRING, "select", '\0', N_("Process: Select objects: comma separated list of IDs."), N_("OBJECT-ID[,OBJECT-ID]*")); - add_main_option_entry(OPTION_TYPE_STRING, "verb", '\0', N_("Process: Verb(s) to call when Inkscape opens."), N_("VERB-ID[;VERB-ID]*")); - add_main_option_entry(OPTION_TYPE_BOOL, "shell", '\0', N_("Process: Start Inkscape in interactive shell mode."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "vacuum-defs", '\0', N_("Process: Remove unused definitions from the <defs> section(s) of document."), ""); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "select", '\0', N_("Process: Select objects: comma separated list of IDs."), N_("OBJECT-ID[,OBJECT-ID]*")); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "verb", '\0', N_("Process: Verb(s) to call when Inkscape opens."), N_("VERB-ID[;VERB-ID]*")); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "shell", '\0', N_("Process: Start Inkscape in interactive shell mode."), ""); // Export - File and File Type - add_main_option_entry(OPTION_TYPE_STRING, "export-type", '\0', N_("Export: File type:[svg,png,ps,psf,tex,emf,wmf,xaml]"), "[...]"); - add_main_option_entry(OPTION_TYPE_FILENAME, "export-file", 'o', N_("Export: File name"), N_("EXPORT-FILENAME")); - add_main_option_entry(OPTION_TYPE_BOOL, "export-overwrite", '\0', N_("Export: Overwrite input file."), ""); // BSP + this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-type", '\0', N_("Export: File type:[svg,png,ps,psf,tex,emf,wmf,xaml]"), "[...]"); + this->add_main_option_entry(T::OPTION_TYPE_FILENAME, "export-file", 'o', N_("Export: File name"), N_("EXPORT-FILENAME")); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-overwrite", '\0', N_("Export: Overwrite input file."), ""); // BSP // B = PNG, S = SVG, P = PS/EPS/PDF // Export - Geometry - add_main_option_entry(OPTION_TYPE_STRING, "export-area", 'a', N_("Export: Area to export in SVG user units."), N_("x0:y0:x1:y1")); // BSP - add_main_option_entry(OPTION_TYPE_BOOL, "export-area-drawing", 'D', N_("Export: Area to export is drawing (not page)."), ""); // BSP - add_main_option_entry(OPTION_TYPE_BOOL, "export-area-page", 'C', N_("Export: Area to export is page."), ""); // BSP - add_main_option_entry(OPTION_TYPE_INT, "export-margin", '\0', N_("Export: Margin around export area: units of page size for SVG, mm for PS/EPS/PDF."), ""); // xSP - add_main_option_entry(OPTION_TYPE_BOOL, "export-area-snap", '\0', N_("Export: Snap the bitmap export area outwards to the nearest integer values."), ""); // Bxx - add_main_option_entry(OPTION_TYPE_INT, "export-width", 'w', N_("Export: Bitmap width in pixels (overrides --export-dpi)."), N_("WIDTH")); // Bxx - add_main_option_entry(OPTION_TYPE_INT, "export-height", 'h', N_("Export: Bitmap height in pixels (overrides --export-dpi)."), N_("HEIGHT")); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-area", 'a', N_("Export: Area to export in SVG user units."), N_("x0:y0:x1:y1")); // BSP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-area-drawing", 'D', N_("Export: Area to export is drawing (not page)."), ""); // BSP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-area-page", 'C', N_("Export: Area to export is page."), ""); // BSP + this->add_main_option_entry(T::OPTION_TYPE_INT, "export-margin", '\0', N_("Export: Margin around export area: units of page size for SVG, mm for PS/EPS/PDF."), ""); // xSP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-area-snap", '\0', N_("Export: Snap the bitmap export area outwards to the nearest integer values."), ""); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_INT, "export-width", 'w', N_("Export: Bitmap width in pixels (overrides --export-dpi)."), N_("WIDTH")); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_INT, "export-height", 'h', N_("Export: Bitmap height in pixels (overrides --export-dpi)."), N_("HEIGHT")); // Bxx // Export - Options - add_main_option_entry(OPTION_TYPE_STRING, "export-id", 'i', N_("Export: ID(s) of object(s) to export."), N_("OBJECT-ID[;OBJECT-ID]*")); // BSP - add_main_option_entry(OPTION_TYPE_BOOL, "export-id-only", 'j', N_("Export: Hide all objects except object with ID selected by export-id."), ""); // BSx - add_main_option_entry(OPTION_TYPE_BOOL, "export-plain-svg", 'l', N_("Export: Remove items in the Inkscape namespace."), ""); // xSx - add_main_option_entry(OPTION_TYPE_INT, "export-dpi", 'd', N_("Export: Resolution for rasterization bitmaps and filters (default is 96)."), N_("DPI")); // BxP - add_main_option_entry(OPTION_TYPE_BOOL, "export-ignore-filters", '\0', N_("Export: Render objects without filters instead of rasterizing. (PS/EPS/PDF)"), ""); // xxP - add_main_option_entry(OPTION_TYPE_BOOL, "export-text-to-path", 'T', N_("Export: Convert text to paths. (PS/EPS/PDF/SVG)."), ""); // xxP - add_main_option_entry(OPTION_TYPE_INT, "export-ps-level", '\0', N_("Export: Postscript level (2 or 3). Default is 3."), N_("PS-Level")); // xxP - add_main_option_entry(OPTION_TYPE_STRING, "export-pdf-level", '\0', N_("Export: PDF level (1.4 or 1.5)"), N_("PDF-Level")); // xxP - add_main_option_entry(OPTION_TYPE_BOOL, "export-latex", '\0', N_("Export: Export text separately to LaTeX file (PS/EPS/PDF). Include via \\input{file.tex}"), ""); // xxP - add_main_option_entry(OPTION_TYPE_BOOL, "export-use-hints", 't', N_("Export: Use stored filename and DPI hints when exporting object selected by --export-id."), ""); // Bxx - add_main_option_entry(OPTION_TYPE_STRING, "export-background", 'b', N_("Export: Background color for exported bitmaps (any SVG color string)."), N_("COLOR")); // Bxx - add_main_option_entry(OPTION_TYPE_DOUBLE, "export-background-opacity", 'y', N_("Export: Background opacity for exported bitmaps (either 0.0 to 1.0 or 1 to 255)."), N_("VALUE")); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-id", 'i', N_("Export: ID(s) of object(s) to export."), N_("OBJECT-ID[;OBJECT-ID]*")); // BSP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-id-only", 'j', N_("Export: Hide all objects except object with ID selected by export-id."), ""); // BSx + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-plain-svg", 'l', N_("Export: Remove items in the Inkscape namespace."), ""); // xSx + this->add_main_option_entry(T::OPTION_TYPE_INT, "export-dpi", 'd', N_("Export: Resolution for rasterization bitmaps and filters (default is 96)."), N_("DPI")); // BxP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-ignore-filters", '\0', N_("Export: Render objects without filters instead of rasterizing. (PS/EPS/PDF)"), ""); // xxP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-text-to-path", 'T', N_("Export: Convert text to paths. (PS/EPS/PDF/SVG)."), ""); // xxP + this->add_main_option_entry(T::OPTION_TYPE_INT, "export-ps-level", '\0', N_("Export: Postscript level (2 or 3). Default is 3."), N_("PS-Level")); // xxP + this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-pdf-level", '\0', N_("Export: PDF level (1.4 or 1.5)"), N_("PDF-Level")); // xxP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-latex", '\0', N_("Export: Export text separately to LaTeX file (PS/EPS/PDF). Include via \\input{file.tex}"), ""); // xxP + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "export-use-hints", 't', N_("Export: Use stored filename and DPI hints when exporting object selected by --export-id."), ""); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-background", 'b', N_("Export: Background color for exported bitmaps (any SVG color string)."), N_("COLOR")); // Bxx + this->add_main_option_entry(T::OPTION_TYPE_DOUBLE, "export-background-opacity", 'y', N_("Export: Background opacity for exported bitmaps (either 0.0 to 1.0 or 1 to 255)."), N_("VALUE")); // Bxx #ifdef WITH_YAML - add_main_option_entry(OPTION_TYPE_FILENAME, "xverbs", '\0', N_("Process: xverb command file."), N_("XVERBS-FILENAME")); + this->add_main_option_entry(T::OPTION_TYPE_FILENAME, "xverbs", '\0', N_("Process: xverb command file."), N_("XVERBS-FILENAME")); #endif // WITH_YAML #ifdef WITH_DBUS - add_main_option_entry(OPTION_TYPE_BOOL, "dbus-listen", '\0', N_("D-Bus: Enter a listening loop for D-Bus messages in console mode."), ""); - add_main_option_entry(OPTION_TYPE_STRING, "dbus-name", '\0', N_("D-Bus: Specify the D-Bus name (default is 'org.inkscape')."), N_("BUS-NAME")); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "dbus-listen", '\0', N_("D-Bus: Enter a listening loop for D-Bus messages in console mode."), ""); + this->add_main_option_entry(T::OPTION_TYPE_STRING, "dbus-name", '\0', N_("D-Bus: Specify the D-Bus name (default is 'org.inkscape')."), N_("BUS-NAME")); #endif // WITH_DBUS - signal_handle_local_options().connect(sigc::mem_fun(*this, &InkscapeApplication::on_handle_local_options)); + Gio::Application::signal_handle_local_options().connect(sigc::mem_fun(*this, &InkscapeApplication::on_handle_local_options)); // This is normally called for us... but after the "handle_local_options" signal is emitted. If // we want to rely on actions for handling options, we need to call it here. This appears to // have no unwanted side-effect. It will also trigger the call to on_startup(). - register_application(); -} - -Glib::RefPtr<InkscapeApplication> InkscapeApplication::create() -{ - return Glib::RefPtr<InkscapeApplication>(new InkscapeApplication()); + T::register_application(); } SPDocument* @@ -174,16 +171,23 @@ InkscapeApplication::get_active_selection() return context.getSelection(); } +template<class T> void -InkscapeApplication::on_startup() +ConcreteInkscapeApplication<T>::on_startup() { - Gtk::Application::on_startup(); + T::on_startup(); } // Here are things that should be in on_startup() but cannot be as we don't set _with_gui until // on_handle_local_options() is called. +template<> void ConcreteInkscapeApplication<Gio::Application>::on_startup2() +{ + Inkscape::Application::create(nullptr, false); +} + +template<> void -InkscapeApplication::on_startup2() +ConcreteInkscapeApplication<Gtk::Application>::on_startup2() { // This should be completely rewritten. Inkscape::Application::create(nullptr, _with_gui); // argv appears to not be used. @@ -224,8 +228,9 @@ InkscapeApplication::on_startup2() } // Open document window with default document. Either this or on_open() is called. +template<class T> void -InkscapeApplication::on_activate() +ConcreteInkscapeApplication<T>::on_activate() { on_startup2(); @@ -246,8 +251,9 @@ InkscapeApplication::on_activate() // Open document window for each file. Either this or on_activate() is called. // type_vec_files == std::vector<Glib::RefPtr<Gio::File> > +template<class T> void -InkscapeApplication::on_open(const Gio::Application::type_vec_files& files, const Glib::ustring& hint) +ConcreteInkscapeApplication<T>::on_open(const Gio::Application::type_vec_files& files, const Glib::ustring& hint) { on_startup2(); @@ -259,7 +265,7 @@ InkscapeApplication::on_open(const Gio::Application::type_vec_files& files, cons // Process each file. for (auto action: _command_line_actions) { - activate_action( action.first, action.second ); + Gio::Application::activate_action( action.first, action.second ); } } else { @@ -278,7 +284,7 @@ InkscapeApplication::on_open(const Gio::Application::type_vec_files& files, cons // process_file(file); for (auto action: _command_line_actions) { - activate_action( action.first, action.second ); + Gio::Application::activate_action( action.first, action.second ); } if (_use_shell) { @@ -301,8 +307,28 @@ InkscapeApplication::on_open(const Gio::Application::type_vec_files& files, cons // Gtk::Application::on_open(files, hint); } + + +template<class T> SPDesktop* -InkscapeApplication::create_window(const Glib::RefPtr<Gio::File>& file) +ConcreteInkscapeApplication<T>::create_window(const Glib::RefPtr<Gio::File>& file) +{ + SPDesktop* desktop = nullptr; + if (file) { + desktop = sp_file_new_default(); + sp_file_open(file->get_parse_name(), nullptr, false, true); + } else { + desktop = sp_file_new_default(); + } + _documents.push_back(desktop->getDocument()); + return (desktop); // Temp: Need to track desktop for shell mode. +} + + + +template<> +SPDesktop* +ConcreteInkscapeApplication<Gtk::Application>::create_window(const Glib::RefPtr<Gio::File>& file) { SPDesktop* desktop = nullptr; if (file) { @@ -320,9 +346,9 @@ InkscapeApplication::create_window(const Glib::RefPtr<Gio::File>& file) return (desktop); // Temp: Need to track desktop for shell mode. } - +template<class T> void -InkscapeApplication::parse_actions(const Glib::ustring& input, action_vector_t& action_vector) +ConcreteInkscapeApplication<T>::parse_actions(const Glib::ustring& input, action_vector_t& action_vector) { // Split action list std::vector<Glib::ustring> tokens = Glib::Regex::split_simple("\\s*;\\s*", input); @@ -337,7 +363,7 @@ InkscapeApplication::parse_actions(const Glib::ustring& input, action_vector_t& value = tokens2[1]; } - Glib::RefPtr<Gio::Action> action_ptr = lookup_action(action); + Glib::RefPtr<Gio::Action> action_ptr = Gio::Application::lookup_action(action); if (action_ptr) { // Doesn't seem to be a way to test this using the C++ binding without Glib-CRITICAL errors. const GVariantType* gtype = g_action_get_parameter_type(action_ptr->gobj()); @@ -384,8 +410,9 @@ InkscapeApplication::parse_actions(const Glib::ustring& input, action_vector_t& // Interactively trigger actions. This is a travesty! Due to most verbs requiring a desktop we must // create one even in shell mode! +template<class T> void -InkscapeApplication::shell() +ConcreteInkscapeApplication<T>::shell() { std::cout << "Inkscape interactive shell mode. Type 'quit' to quit." << std::endl; std::cout << " Input of the form:" << std::endl; @@ -424,7 +451,7 @@ InkscapeApplication::shell() action_vector_t action_vector; parse_actions(input_u, action_vector); for (auto action: action_vector) { - activate_action( action.first, action.second ); + Gio::Application::activate_action( action.first, action.second ); } if (desktop) { @@ -432,12 +459,13 @@ InkscapeApplication::shell() } } - quit(); // Must quit or segfault. + T::quit(); // Must quit or segfault. } // Once we don't need to create a window just to process verbs! +template<class T> void -InkscapeApplication::shell2() +ConcreteInkscapeApplication<T>::shell2() { std::cout << "Inkscape interactive shell mode. Type 'quit' to quit." << std::endl; std::cout << " Input of the form:" << std::endl; @@ -452,7 +480,7 @@ InkscapeApplication::shell2() action_vector_t action_vector; parse_actions(input, action_vector); for (auto action: action_vector) { - activate_action( action.first, action.second ); + T::activate_action( action.first, action.second ); } } } @@ -468,8 +496,9 @@ InkscapeApplication::shell2() * For each file without GUI: Open -> Query -> Process -> Export * More flexible processing can be done via actions or xverbs. */ +template<class T> int -InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDict>& options) +ConcreteInkscapeApplication<T>::on_handle_local_options(const Glib::RefPtr<Glib::VariantDict>& options) { if (!options) { std::cerr << "InkscapeApplication::on_handle_local_options: options is null!" << std::endl; @@ -479,22 +508,22 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDic // ===================== QUERY ===================== // These are processed first as they result in immediate program termination. if (options->contains("version")) { - activate_action("inkscape-version"); + T::activate_action("inkscape-version"); return EXIT_SUCCESS; } if (options->contains("extensions-directory")) { - activate_action("extensions-directory"); + T::activate_action("extensions-directory"); return EXIT_SUCCESS; } if (options->contains("verb-list")) { - activate_action("verb-list"); + T::activate_action("verb-list"); return EXIT_SUCCESS; } if (options->contains("action-list")) { - std::vector<Glib::ustring> actions = list_actions(); + std::vector<Glib::ustring> actions = T::list_actions(); std::sort(actions.begin(), actions.end()); for (auto action : actions) { std::cout << action << std::endl; @@ -688,14 +717,18 @@ InkscapeApplication::on_handle_local_options(const Glib::RefPtr<Glib::VariantDic // ======================== Actions ========================= +template<class T> void -InkscapeApplication::on_new() +ConcreteInkscapeApplication<T>::on_new() { create_window(); } +template<class T> void ConcreteInkscapeApplication<T>::on_quit(){ T::quit(); } + +template<> void -InkscapeApplication::on_quit() +ConcreteInkscapeApplication<Gtk::Application>::on_quit() { // Delete all windows (quit() doesn't do this). std::vector<Gtk::Window*> windows = get_windows(); @@ -706,6 +739,9 @@ InkscapeApplication::on_quit() quit(); } +template class ConcreteInkscapeApplication<Gio::Application>; +template class ConcreteInkscapeApplication<Gtk::Application>; + /* Local Variables: mode:c++ diff --git a/src/inkscape-application.h b/src/inkscape-application.h index 90553cd0d..c80110ac2 100644 --- a/src/inkscape-application.h +++ b/src/inkscape-application.h @@ -30,17 +30,42 @@ typedef std::vector<std::pair<std::string, Glib::VariantBase> > action_vector_t; -class InkscapeApplication : public Gtk::Application + +class InkscapeApplication { +public: + virtual void on_startup() = 0; + virtual void on_startup2() = 0; + virtual InkFileExportCmd* file_export() = 0; + virtual int on_handle_local_options(const Glib::RefPtr<Glib::VariantDict>& options) = 0; + virtual void on_new() = 0; + virtual void on_quit() = 0; + SPDocument* get_active_document(); + Inkscape::Selection* get_active_selection(); protected: + bool _with_gui; + bool _use_shell; InkscapeApplication(); + // Documents are owned by the application which is responsible for opening/saving/exporting. WIP + std::vector<SPDocument*> _documents; + InkFileExportCmd _file_export; + // Actions from the command line or file. + action_vector_t _command_line_actions; + + +}; + + + -public: - static Glib::RefPtr<InkscapeApplication> create(); - SPDocument* get_active_document(); - Inkscape::Selection* get_active_selection(); +template <class T> class ConcreteInkscapeApplication : public T, public InkscapeApplication +{ +public: + ConcreteInkscapeApplication(); + +public: InkFileExportCmd* file_export() { return &_file_export; } protected: @@ -48,12 +73,8 @@ protected: void on_startup2(); void on_activate() override; void on_open(const Gio::Application::type_vec_files& files, const Glib::ustring& hint) override; - -private: SPDesktop* create_window(const Glib::RefPtr<Gio::File>& file = Glib::RefPtr<Gio::File>()); void parse_actions(const Glib::ustring& input, action_vector_t& action_vector); - void shell(); - void shell2(); private: // Callbacks @@ -63,18 +84,12 @@ private: void on_new(); void on_quit(); void on_about(); + + void shell(); + void shell2(); Glib::RefPtr<Gtk::Builder> _builder; - bool _with_gui; - bool _use_shell; - InkFileExportCmd _file_export; - - // Documents are owned by the application which is responsible for opening/saving/exporting. WIP - std::vector<SPDocument*> _documents; - - // Actions from the command line or file. - action_vector_t _command_line_actions; }; #endif // INKSCAPE_APPLICATION_H diff --git a/src/inkscape-main.cpp b/src/inkscape-main.cpp index 52d3e7873..e1c0411e0 100644 --- a/src/inkscape-main.cpp +++ b/src/inkscape-main.cpp @@ -19,9 +19,11 @@ int main(int argc, char *argv[]) { - auto application = InkscapeApplication::create(); - return application->run(argc, argv); + if(gtk_init_check(NULL, NULL)) + return (new ConcreteInkscapeApplication<Gtk::Application>())->run(argc, argv); + else + return (new ConcreteInkscapeApplication<Gio::Application>())->run(argc, argv); } /* |
