summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2019-01-13 13:45:12 +0000
committerTavmjong Bah <tavmjong@free.fr>2019-01-13 13:45:12 +0000
commitf0e5746fa4170875c5d432b7a636ec36452f1add (patch)
treef71d85a6be1c6778777b1c155ba1a660d73c9c3c /src
parentsimplify translated default.svg (diff)
downloadinkscape-f0e5746fa4170875c5d432b7a636ec36452f1add.tar.gz
inkscape-f0e5746fa4170875c5d432b7a636ec36452f1add.zip
Another baby step in creating InkscapeWindow.
Diffstat (limited to 'src')
-rw-r--r--src/inkscape-application.cpp32
-rw-r--r--src/inkscape-application.h14
-rw-r--r--src/inkscape-window.cpp17
-rw-r--r--src/inkscape-window.h7
-rw-r--r--src/ui/interface.cpp12
5 files changed, 49 insertions, 33 deletions
diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp
index 0310d0af3..2e4c690cf 100644
--- a/src/inkscape-application.cpp
+++ b/src/inkscape-application.cpp
@@ -154,21 +154,10 @@ ConcreteInkscapeApplication<T>::ConcreteInkscapeApplication()
T::register_application();
}
-SPDocument*
-InkscapeApplication::get_active_document()
-{
- // This should change based on last document window in focus if with GUI. But for now we're
- // only using it for command line mode so return last document (the one currently be read in).
- return _documents.back();
-}
-
Inkscape::Selection*
InkscapeApplication::get_active_selection()
{
- // This should change based on last document window in focus if with GUI. But for now we're
- // only using it for command line mode so return last document (the one currently be read in).
- SPDocument* document = _documents.back();
- Inkscape::ActionContext context = INKSCAPE.action_context_for_document(document);
+ Inkscape::ActionContext context = INKSCAPE.action_context_for_document(_active_document);
return context.getSelection();
}
@@ -263,7 +252,6 @@ ConcreteInkscapeApplication<T>::on_open(const Gio::Application::type_vec_files&
for (auto file : files) {
if (_with_gui) {
// Create a window for each file.
-
SPDesktop* desktop = create_window(file);
// Process each file.
@@ -278,7 +266,6 @@ ConcreteInkscapeApplication<T>::on_open(const Gio::Application::type_vec_files&
}
} else {
-
// Open file
SPDocument *doc = ink_file_open(file);
if (!doc) continue;
@@ -289,7 +276,7 @@ ConcreteInkscapeApplication<T>::on_open(const Gio::Application::type_vec_files&
doc->ensureUpToDate(); // Or queries don't work!
// Add to our application
- _documents.push_back(doc);
+ _active_document = doc;
// process_file(file);
for (auto action: _command_line_actions) {
@@ -303,8 +290,7 @@ ConcreteInkscapeApplication<T>::on_open(const Gio::Application::type_vec_files&
_file_export.do_export(doc, file->get_path());
}
- // Remove from our application... we only have one in command-line mode.
- _documents.pop_back();
+ _active_document = nullptr;
// Close file
INKSCAPE.remove_document(doc);
@@ -324,12 +310,15 @@ ConcreteInkscapeApplication<T>::create_window(const Glib::RefPtr<Gio::File>& fil
{
SPDesktop* desktop = nullptr;
if (file) {
- desktop = sp_file_new_default();
sp_file_open(file->get_parse_name(), nullptr, false, true);
+ desktop = SP_ACTIVE_DESKTOP;
} else {
desktop = sp_file_new_default();
}
- _documents.push_back(desktop->getDocument());
+
+ _active_document = desktop->getDocument();
+ // _documents.push_back(desktop->getDocument());
+
return (desktop); // Temp: Need to track desktop for shell mode.
}
@@ -347,9 +336,10 @@ ConcreteInkscapeApplication<Gtk::Application>::create_window(const Glib::RefPtr<
desktop = sp_file_new_default();
}
- _documents.push_back(desktop->getDocument());
+ _active_document = desktop->getDocument();
+ // _documents.push_back(desktop->getDocument());
- // Add to Gtk::Window to app window list.
+ // Add Gtk::Window to app window list.
add_window(*desktop->getToplevel());
return (desktop); // Temp: Need to track desktop for shell mode.
diff --git a/src/inkscape-application.h b/src/inkscape-application.h
index 4ce290030..f9a982207 100644
--- a/src/inkscape-application.h
+++ b/src/inkscape-application.h
@@ -30,6 +30,9 @@
typedef std::vector<std::pair<std::string, Glib::VariantBase> > action_vector_t;
+class InkscapeWindow;
+class SPDocument;
+class SPDesktop;
class InkscapeApplication
{
@@ -40,8 +43,8 @@ public:
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();
+ SPDocument* get_active_document() { return _active_document; };
+ Inkscape::Selection* get_active_selection(); // { return _active_selection; };
protected:
bool _with_gui;
@@ -50,7 +53,12 @@ protected:
InkscapeApplication();
// Documents are owned by the application which is responsible for opening/saving/exporting. WIP
- std::vector<SPDocument*> _documents;
+ // std::vector<SPDocument*> _documents; For a true headless version
+ std::map<SPDocument*, std::vector<InkscapeWindow*> > _documents;
+
+ // We keep track of these things so we don't need a window to find them (for headless operation).
+ SPDocument* _active_document;
+ Inkscape::Selection* active_selection; // This should be a view once view doesn't depend on GUI.
InkFileExportCmd _file_export;
diff --git a/src/inkscape-window.cpp b/src/inkscape-window.cpp
index 097ae214b..7227993cf 100644
--- a/src/inkscape-window.cpp
+++ b/src/inkscape-window.cpp
@@ -19,8 +19,12 @@
#include "inkscape.h" // SP_ACTIVE_DESKTOP
#include "shortcuts.h"
-InkscapeWindow::InkscapeWindow()
+#include "widgets/desktop-widget.h"
+
+InkscapeWindow::InkscapeWindow(SPDocument* document)
+ : _document(document)
{
+ set_resizable(true);
// Callbacks
signal_key_press_event().connect(sigc::mem_fun(*this, &InkscapeWindow::key_press));
@@ -28,11 +32,20 @@ InkscapeWindow::InkscapeWindow()
// Actions
}
+// TEMP: We should be creating the desktop widget and desktop in constructor.
+void
+InkscapeWindow::set_desktop_widget(SPDesktopWidget* desktop_widget)
+{
+ gtk_container_add(GTK_CONTAINER(gobj()), GTK_WIDGET(desktop_widget));
+ gtk_widget_show(GTK_WIDGET(desktop_widget));
+ _desktop = desktop_widget->desktop;
+}
+
bool
InkscapeWindow::key_press(GdkEventKey* event)
{
unsigned shortcut = sp_shortcut_get_for_event(event);
- return sp_shortcut_invoke (shortcut, SP_ACTIVE_DESKTOP); // We should own desktop.
+ return sp_shortcut_invoke (shortcut, _desktop);
}
/*
diff --git a/src/inkscape-window.h b/src/inkscape-window.h
index ecf4fd553..1389a6f32 100644
--- a/src/inkscape-window.h
+++ b/src/inkscape-window.h
@@ -20,6 +20,8 @@
#include <gtkmm.h>
class SPDocument;
+class SPDesktop;
+class SPDesktopWidget;
namespace Inkscape {
namespace UI {
@@ -33,9 +35,12 @@ namespace View {
class InkscapeWindow : public Gtk::ApplicationWindow {
public:
- InkscapeWindow();
+ InkscapeWindow(SPDocument* document);
+ void set_desktop_widget(SPDesktopWidget* desktop_widget); // Temp: We should be creating desktop in constructor!
private:
+ SPDocument* _document;
+ SPDesktop* _desktop;
// Callbacks
bool key_press(GdkEventKey* event);
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index c68ee0d2d..dfec59237 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -147,16 +147,16 @@ sp_create_window(SPViewWidget *vw, bool editable)
g_return_if_fail(vw != nullptr);
g_return_if_fail(SP_IS_VIEW_WIDGET(vw));
- InkscapeWindow* win = new InkscapeWindow();
- win->set_resizable(true);
- gtk_container_add(GTK_CONTAINER(win->gobj()), GTK_WIDGET(vw));
- gtk_widget_show(GTK_WIDGET(vw));
+ SPDesktopWidget *desktop_widget = reinterpret_cast<SPDesktopWidget*>(vw);
+ SPDesktop* desktop = desktop_widget->desktop;
+ SPDocument* document = desktop->getDocument();
+
+ InkscapeWindow* win = new InkscapeWindow(document);
+ win->set_desktop_widget(desktop_widget);
if (editable) {
g_object_set_data(G_OBJECT(vw), "window", win);
- SPDesktopWidget *desktop_widget = reinterpret_cast<SPDesktopWidget*>(vw);
- SPDesktop* desktop = desktop_widget->desktop;
desktop_widget->window = win;