diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2019-06-19 08:49:04 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2019-06-19 08:49:04 +0000 |
| commit | 2892b301b3c9aab0e251759ee2b8a3edba18dc99 (patch) | |
| tree | c9204a8db5ef4f7fde26a3e353ebb533e94ead41 /src/inkscape-application.cpp | |
| parent | fix horizontal palette scrolling for macOS (diff) | |
| download | inkscape-2892b301b3c9aab0e251759ee2b8a3edba18dc99.tar.gz inkscape-2892b301b3c9aab0e251759ee2b8a3edba18dc99.zip | |
Restore ability to pipe a file into Inkscape.
Diffstat (limited to 'src/inkscape-application.cpp')
| -rw-r--r-- | src/inkscape-application.cpp | 74 |
1 files changed, 70 insertions, 4 deletions
diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index 6ea03779f..ee882cbba 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -67,6 +67,7 @@ InkscapeApplication::InkscapeApplication() : _with_gui(true) , _batch_process(false) , _use_shell(false) + , _use_pipe(false) , _active_document(nullptr) , _active_selection(nullptr) , _active_view(nullptr) @@ -127,7 +128,26 @@ InkscapeApplication::document_open(const Glib::RefPtr<Gio::File>& file) document_add (document); } else { - std::cerr << "InkscapeApplication::open_document: Failed to open: " << file->get_parse_name() << std::endl; + std::cerr << "InkscapeApplication::document_open: Failed to open: " << file->get_parse_name() << std::endl; + } + + return document; +} + + +// Open a document, add it to app. +SPDocument* +InkscapeApplication::document_open(const std::string& data) +{ + // Open file + SPDocument *document = ink_file_open(data); + + if (document) { + document->setVirgin(false); // Prevents replacing document in same window during file open. + + document_add (document); + } else { + std::cerr << "InkscapeApplication::document_open: Failed to open memory document." << std::endl; } return document; @@ -512,7 +532,8 @@ ConcreteInkscapeApplication<T>::ConcreteInkscapeApplication() 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."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "shell", '\0', N_("Process: Start Inkscape in interactive shell mode."), ""); + this->add_main_option_entry(T::OPTION_TYPE_BOOL, "pipe", 'p', N_("Process: Read file from pipe."), ""); // Export - File and File Type this->add_main_option_entry(T::OPTION_TYPE_STRING, "export-type", '\0', N_("Export: File type:[svg,png,ps,psf,tex,emf,wmf,xaml]"), "[...]"); @@ -806,7 +827,6 @@ ConcreteInkscapeApplication<Gtk::Application>::destroy_all() } } - // Open document window with default document. Either this or on_open() is called. template<class T> void @@ -814,6 +834,52 @@ ConcreteInkscapeApplication<T>::on_activate() { on_startup2(); + if (_use_pipe) { + + if (_with_gui) { + std::cerr << "Must use --without-gui with --pipe!" << std::endl; + return; + } + + // Create document from pipe in. + std::istreambuf_iterator<char> begin(std::cin), end; + std::string s(begin, end); + SPDocument *document = document_open (s); + if (!document) return; + + // Add to Inkscape::Application... + INKSCAPE.add_document(document); + // ActionContext should be removed once verbs are gone but we use it for now. + Inkscape::ActionContext context = INKSCAPE.action_context_for_document(document); + _active_document = document; + _active_selection = context.getSelection(); + _active_view = context.getView(); + + if (_active_selection == nullptr) { + std::cerr << "ConcreteInkscapeApplication<T>::on_activate:_active_selection is null!" << std::endl; + std::cerr << " Must use --without_gui with --pipe!" << std::endl; + return; // Avoid segfault + + } + + document->ensureUpToDate(); // Or queries don't work! + + // process_file(file); + for (auto action: _command_line_actions) { + Gio::Application::activate_action( action.first, action.second ); + } + + _active_document = nullptr; + _active_selection = nullptr; + _active_view = nullptr; + + // Close file + INKSCAPE.remove_document(document); + + document_close (document); + return; + } + if (_with_gui) { if (_use_shell) { shell(); // Shell will create its own windows. @@ -910,7 +976,6 @@ ConcreteInkscapeApplication<Gtk::Application>::on_open(const Gio::Application::t } } else { - // Open file SPDocument *document = document_open (file); if (!document) continue; @@ -1142,6 +1207,7 @@ ConcreteInkscapeApplication<T>::on_handle_local_options(const Glib::RefPtr<Glib: if (options->contains("with-gui")) _with_gui = true; if (options->contains("batch-process")) _batch_process = true; if (options->contains("shell")) _use_shell = true; + if (options->contains("pipe")) _use_pipe = true; // Some options should preclude using gui! if (options->contains("query-id") || |
