From e8017634daeec325373b4c83101e0b47a67b1a31 Mon Sep 17 00:00:00 2001 From: Patrick Storz Date: Wed, 17 Jul 2019 21:21:00 +0200 Subject: Avoid code duplication in ConcreteInkscapeApplication::on_open() --- src/inkscape-application.cpp | 78 ++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 47 deletions(-) (limited to 'src/inkscape-application.cpp') diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index 6b0178e74..e32f31c03 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -903,6 +903,36 @@ ConcreteInkscapeApplication::process(SPDocument* document, std::string output INKSCAPE.remove_document(document); } +/** Process 'file' using GUI. + */ +template +void +ConcreteInkscapeApplication::process_file_with_gui(Glib::RefPtr file) +{ + // no-op in general case (we only have a GUI if our application instance is a a Gtk::Application, see below) +} + +template<> +void +ConcreteInkscapeApplication::process_file_with_gui(Glib::RefPtr file) +{ + // Create a window for each file. + SPDesktop* desktop = create_window(file); + + // Process each file. + for (auto action: _command_line_actions) { + Gio::Application::activate_action( action.first, action.second ); + } + + // Close window after we're done with file. This may not be the best way... + // but we need to rewrite most of the window handling code so do this for now. + if (_batch_process) { + std::vector windows = get_windows(); + remove_window(*windows[0]); // There should be only one window (added in InkscapeWindow constructor). + // Eventually create_window() should return a pointer to the window, not the desktop. + } +} + // Open document window with default document. Either this or on_open() is called. template void @@ -966,55 +996,9 @@ ConcreteInkscapeApplication::on_open(const Gio::Application::type_vec_files& return; } - for (auto file : files) { - // Open file - SPDocument *document = document_open (file); - if (!document) continue; - - process (document, file->get_path()); - document_close (document); - } -} - -// Open document window for each file. Either this or on_activate() is called. -// type_vec_files == std::vector > -template<> -void -ConcreteInkscapeApplication::on_open(const Gio::Application::type_vec_files& files, const Glib::ustring& hint) -{ - on_startup2(); - if(_pdf_poppler) - INKSCAPE.set_pdf_poppler(_pdf_poppler); - if(_pdf_page) - INKSCAPE.set_pdf_page(_pdf_page); - - if (files.size() > 1 && !_file_export.export_filename.empty()) { - std::cerr << "ConcreteInkscapeApplication::on_open: " - "Can't use '--export-file' with multiple input files " - "(output file would be overwritten for each input file). " - "Please use '--export-type' instead and rename manually." - << std::endl; - return; - } - for (auto file : files) { if (_with_gui) { - // Create a window for each file. - SPDesktop* desktop = create_window(file); - - // Process each file. - for (auto action: _command_line_actions) { - Gio::Application::activate_action( action.first, action.second ); - } - - // Close window after we're done with file. This may not be the best way... - // but we need to rewrite most of the window handling code so do this for now. - if (_batch_process) { - std::vector windows = get_windows(); - remove_window(*windows[0]); // There should be only one window (added in InkscapeWindow constructor). - // Eventually create_window() should return a pointer to the window, not the desktop. - } - + process_file_with_gui(file); } else { // Open file SPDocument *document = document_open (file); -- cgit v1.2.3