summaryrefslogtreecommitdiffstats
path: root/src/inkscape.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-06-26 01:45:01 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-06-26 01:45:01 +0000
commitcdc7587062b42c39a23451e5c9ec7da06dd6fdb3 (patch)
treede3ce9585caf538af3cb215cf117a9e4521df936 /src/inkscape.cpp
parent2. connect signals (diff)
downloadinkscape-cdc7587062b42c39a23451e5c9ec7da06dd6fdb3.tar.gz
inkscape-cdc7587062b42c39a23451e5c9ec7da06dd6fdb3.zip
3. remove dead code, refactor existing code. Connect overlooked signals.
(bzr r13341.5.3)
Diffstat (limited to 'src/inkscape.cpp')
-rw-r--r--src/inkscape.cpp604
1 files changed, 185 insertions, 419 deletions
diff --git a/src/inkscape.cpp b/src/inkscape.cpp
index 4e8b06ef4..2181b2814 100644
--- a/src/inkscape.cpp
+++ b/src/inkscape.cpp
@@ -1,12 +1,13 @@
/**
* @file
- * Legacy interface to main application.
+ * Interface to main application.
*/
/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
+ * Liam P. White <inkscapebrony@gmail.com>
*
- * Copyright (C) 1999-2005 authors
+ * Copyright (C) 1999-2014 authors
* g++ port Copyright (C) 2003 Nathan Hurst
*
* Released under GNU GPL, read the file 'COPYING' for more information
@@ -50,109 +51,35 @@
#include <gtk/gtk.h>
#include <signal.h>
#include <string>
+
#include "desktop.h"
#include "desktop-handles.h"
#include "device-manager.h"
#include "document.h"
-#include "ui/tools/tool-base.h"
#include "extension/db.h"
#include "extension/init.h"
#include "extension/output.h"
#include "extension/system.h"
-#include "inkscape-private.h"
+#include "helper/action-context.h"
+#include "helper/sp-marshal.h"
+#include "inkscape.h"
#include "io/sys.h"
#include "layer-model.h"
#include "message-stack.h"
#include "preferences.h"
#include "resource-manager.h"
#include "selection.h"
+#include "ui/tools/tool-base.h"
#include "ui/dialog/debug.h"
#include "xml/repr.h"
-#include "helper/action-context.h"
-#include "helper/sp-marshal.h"
static Inkscape::Application *inkscape = NULL;
/* Backbones of configuration xml data */
#include "menus-skeleton.h"
-#if 0
-enum {
- MODIFY_SELECTION, // global: one of selections modified
- CHANGE_SELECTION, // global: one of selections changed
- CHANGE_SUBSELECTION, // global: one of subselections (text selection, gradient handle, etc) changed
- SET_SELECTION, // global: one of selections set
- SET_EVENTCONTEXT, // tool switched
- ACTIVATE_DESKTOP, // some desktop got focus
- DEACTIVATE_DESKTOP, // some desktop lost focus
- SHUTDOWN_SIGNAL, // inkscape is quitting
- DIALOGS_HIDE, // user pressed F12
- DIALOGS_UNHIDE, // user pressed F12
- EXTERNAL_CHANGE, // a document was changed by some external means (undo or XML editor); this
- // may not be reflected by a selection change and thus needs a separate signal
- LAST_SIGNAL
-};
-#endif
-
#define DESKTOP_IS_ACTIVE(d) (!inkscape->desktops->empty() && ((d) == inkscape->desktops->front()))
-
-/*################################
-# FORWARD DECLARATIONS
-################################*/
-
-//namespace Inkscape {
-//struct ApplicationClass;
-//}
-
-//static void inkscape_class_init (Inkscape::ApplicationClass *klass);
-//static void inkscape_init (SPObject *object);
-//static void inkscape_dispose (GObject *object);
-
-//static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
-//static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop);
-
-#if 0
-class AppSelectionModel {
- Inkscape::LayerModel _layer_model;
- Inkscape::Selection *_selection;
-
-public:
- AppSelectionModel(SPDocument *doc) {
- _layer_model.setDocument(doc);
- // TODO: is this really how we should manage the lifetime of the selection?
- // I just copied this from the initialization of the Selection in SPDesktop.
- // When and how is it actually released?
- _selection = Inkscape::GC::release(new Inkscape::Selection(&_layer_model, NULL));
- }
-
- Inkscape::Selection *getSelection() const { return _selection; }
-};
-#endif
-
-#if 0
-struct Inkscape::ApplicationClass {
- GObjectClass object_class;
-
- /* Signals */
- void (* change_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
- void (* change_subselection) (Inkscape::Application * inkscape, SPDesktop *desktop);
- void (* modify_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection, guint flags);
- void (* set_selection) (Inkscape::Application * inkscape, Inkscape::Selection * selection);
- void (* set_eventcontext) (Inkscape::Application * inkscape, Inkscape::UI::Tools::ToolBase * eventcontext);
- void (* activate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
- void (* deactivate_desktop) (Inkscape::Application * inkscape, SPDesktop * desktop);
- void (* destroy_document) (Inkscape::Application *inkscape, SPDocument *doc);
- void (* color_set) (Inkscape::Application *inkscape, SPColor *color, double opacity);
- void (* shut_down) (Inkscape::Application *inkscape);
- void (* dialogs_hide) (Inkscape::Application *inkscape);
- void (* dialogs_unhide) (Inkscape::Application *inkscape);
- void (* external_change) (Inkscape::Application *inkscape);
-};
-#endif
-
-// static guint inkscape_signals[LAST_SIGNAL] = {0};
-
static void (* segv_handler) (int) = SIG_DFL;
static void (* abrt_handler) (int) = SIG_DFL;
static void (* fpe_handler) (int) = SIG_DFL;
@@ -166,123 +93,39 @@ static void (* bus_handler) (int) = SIG_DFL;
#define INKSCAPE_LEGACY_PROFILE_DIR ".inkscape"
#define MENUS_FILE "menus.xml"
-
-/**
- * Initializes the inkscape class, registering all of its signal handlers
- * and virtual functions
- */
-
-#if 0
-static void
-inkscape_class_init (Inkscape::ApplicationClass * klass)
-{
- GObjectClass * object_class;
-
- object_class = (GObjectClass *) klass;
-
- parent_class = (GObjectClass *)g_type_class_peek_parent (klass);
-
- inkscape_signals[MODIFY_SELECTION] = g_signal_new ("modify_selection",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, modify_selection),
- NULL, NULL,
- sp_marshal_VOID__POINTER_UINT,
- G_TYPE_NONE, 2,
- G_TYPE_POINTER, G_TYPE_UINT);
- inkscape_signals[CHANGE_SELECTION] = g_signal_new ("change_selection",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_selection),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[CHANGE_SUBSELECTION] = g_signal_new ("change_subselection",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, change_subselection),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[SET_SELECTION] = g_signal_new ("set_selection",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_selection),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[SET_EVENTCONTEXT] = g_signal_new ("set_eventcontext",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, set_eventcontext),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[ACTIVATE_DESKTOP] = g_signal_new ("activate_desktop",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, activate_desktop),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[DEACTIVATE_DESKTOP] = g_signal_new ("deactivate_desktop",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, deactivate_desktop),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- inkscape_signals[SHUTDOWN_SIGNAL] = g_signal_new ("shut_down",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, shut_down),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- inkscape_signals[DIALOGS_HIDE] = g_signal_new ("dialogs_hide",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_hide),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- inkscape_signals[DIALOGS_UNHIDE] = g_signal_new ("dialogs_unhide",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, dialogs_unhide),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- inkscape_signals[EXTERNAL_CHANGE] = g_signal_new ("external_change",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (Inkscape::ApplicationClass, external_change),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- object_class->dispose = inkscape_dispose;
-
- klass->activate_desktop = inkscape_activate_desktop_private;
- klass->deactivate_desktop = inkscape_deactivate_desktop_private;
-}
-#endif
+#define SP_INDENT 8
#ifdef WIN32
typedef int uid_t;
#define getuid() 0
#endif
+class InkErrorHandler : public Inkscape::ErrorReporter {
+public:
+ InkErrorHandler(bool useGui) : Inkscape::ErrorReporter(),
+ _useGui(useGui)
+ {}
+ virtual ~InkErrorHandler() {}
+
+ virtual void handleError( Glib::ustring const& primary, Glib::ustring const& secondary ) const
+ {
+ if (_useGui) {
+ Gtk::MessageDialog err(primary, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
+ err.set_secondary_text(secondary);
+ err.run();
+ } else {
+ g_message("%s", primary.data());
+ g_message("%s", secondary.data());
+ }
+ }
+
+private:
+ bool _useGui;
+};
+
Inkscape::Application * inkscape_ref(Inkscape::Application * in)
{
g_return_val_if_fail(in != NULL, NULL);
- g_return_val_if_fail(dynamic_cast<Inkscape::Application *>(in) != NULL, NULL);
in->refCount++;
return in;
@@ -291,7 +134,6 @@ Inkscape::Application * inkscape_ref(Inkscape::Application * in)
Inkscape::Application * inkscape_unref(Inkscape::Application * in)
{
g_return_val_if_fail(in != NULL, NULL);
- g_return_val_if_fail(dynamic_cast<Inkscape::Application *>(in) != NULL, NULL);
in->refCount--;
@@ -302,6 +144,40 @@ Inkscape::Application * inkscape_unref(Inkscape::Application * in)
return NULL;
}
+int inkscape_autosave(gpointer) {
+ g_assert(inkscape != NULL);
+ return inkscape->autosave();
+}
+
+/**
+ * Returns the current Inkscape::Application global object
+ */
+Inkscape::Application *
+inkscape_get_instance()
+{
+ return inkscape;
+}
+
+/* fixme: This is EVIL, and belongs to main after all */
+
+static bool crashIsHappening = false;
+
+bool inkscapeIsCrashing()
+{
+ return crashIsHappening;
+}
+
+
+void
+inkscape_application_init (const gchar *argv0, gboolean use_gui)
+{
+ if (!inkscape) {
+ inkscape = new Inkscape::Application(argv0, use_gui);
+ } else {
+ g_assert_not_reached();
+ }
+}
+
namespace Inkscape {
/**
@@ -371,7 +247,6 @@ int Application::autosave()
++docnum;
Inkscape::XML::Node *repr = doc->getReprRoot();
- // g_debug("Document %d: \"%s\" %s", docnum, doc ? doc->getName() : "(null)", doc ? (doc->isModifiedSinceSave() ? "(dirty)" : "(clean)") : "(null)");
if (doc->isModifiedSinceSave()) {
gchar *oldest_autosave = 0;
@@ -402,8 +277,6 @@ int Application::autosave()
}
}
- // g_debug("%d previous autosaves exists. Max = %d", count, autosave_max);
-
// Have we reached the limit for number of autosaves?
if ( count >= autosave_max ){
// Remove the oldest file
@@ -425,8 +298,6 @@ int Application::autosave()
g_free(baseName);
baseName = 0;
- // g_debug("Filename: %s", full_path);
-
// Try to save the file
FILE *file = Inkscape::IO::fopen_utf8name(full_path, "w");
gchar *errortext = 0;
@@ -464,15 +335,6 @@ int Application::autosave()
return TRUE;
}
-} // namespace Inkscape
-
-int inkscape_autosave(gpointer) {
- g_assert(inkscape != NULL);
- return inkscape->autosave();
-}
-
-namespace Inkscape {
-
void Application::autosave_init()
{
static guint32 autosave_timeout_id = 0;
@@ -484,46 +346,114 @@ void Application::autosave_init()
autosave_timeout_id = 0;
}
- // g_debug("options.autosave.enable = %d", prefs->getBool("/options/autosave/enable", true));
// Is autosave enabled?
if (!prefs->getBool("/options/autosave/enable", true)){
autosave_timeout_id = 0;
} else {
// Turn on autosave
guint32 timeout = prefs->getInt("/options/autosave/interval", 10) * 60;
- // g_debug("options.autosave.interval = %d", prefs->getInt("/options/autosave/interval", 10));
autosave_timeout_id = g_timeout_add_seconds(timeout, inkscape_autosave, NULL);
}
}
+void Application::argv0(char const* argv)
+{
+ _argv0 = g_strdup(argv);
+}
+
-Application::Application()
+Application::Application(const char* argv, bool use_gui) :
+ refCount(1),
+ _dialogs_toggle(TRUE),
+ _mapalt(GDK_MOD1_MASK),
+ _trackalt(FALSE),
+ _use_gui(use_gui),
+ menus(NULL),
+ desktops(NULL)
{
- if (!inkscape) {
- inkscape = this;
- } else {
- g_assert_not_reached();
+ /* fixme: load application defaults */
+
+ segv_handler = signal (SIGSEGV, Application::crash_handler);
+ abrt_handler = signal (SIGABRT, Application::crash_handler);
+ fpe_handler = signal (SIGFPE, Application::crash_handler);
+ ill_handler = signal (SIGILL, Application::crash_handler);
+#ifndef WIN32
+ bus_handler = signal (SIGBUS, Application::crash_handler);
+#endif
+
+ _argv0 = g_strdup(argv);
+
+ /* Load the preferences and menus */
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ InkErrorHandler* handler = new InkErrorHandler(use_gui);
+ prefs->setErrorHandler(handler);
+ {
+ Glib::ustring msg;
+ Glib::ustring secondary;
+ if (prefs->getLastError( msg, secondary )) {
+ handler->handleError(msg, secondary);
+ }
}
- this->menus = NULL;
- this->desktops = NULL;
- this->_dialogs_toggle = TRUE;
- this->_mapalt = GDK_MOD1_MASK;
- this->_trackalt = FALSE;
+ if (use_gui) {
+ load_menus();
+ Inkscape::DeviceManager::getManager().loadConfig();
+ }
+ Inkscape::ResourceManager::getManager();
+
+ /* set language for user interface according setting in preferences */
+ Glib::ustring ui_language = prefs->getString("/ui/language");
+ if(!ui_language.empty())
+ {
+ setenv("LANGUAGE", ui_language, 1);
+ }
+
+ /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
+ * Use only if use_gui is enabled
+ */
+#ifdef WIN32
+#define DEFAULT_LOG_REDIRECT true
+#else
+#define DEFAULT_LOG_REDIRECT false
+#endif
+
+ if (use_gui == TRUE && prefs->getBool("/dialogs/debug/redirect", DEFAULT_LOG_REDIRECT))
+ {
+ Inkscape::UI::Dialog::DebugDialog::getInstance()->captureLogMessages();
+ }
+
+ /* Check for global remapping of Alt key */
+ if (use_gui)
+ {
+ mapalt(guint(prefs->getInt("/options/mapalt/value", 0)));
+ trackalt(guint(prefs->getInt("/options/trackalt/value", 0)));
+ }
+
+ /* Initialize the extensions */
+ Inkscape::Extension::init();
+
+ autosave_init();
}
Application::~Application()
{
- g_assert (!desktops);
+ if (desktops) {
+ g_error("FATAL: desktops still in list on application destruction!");
+ }
Inkscape::Preferences::unload();
if (menus) {
- /* fixme: This is not the best place */
Inkscape::GC::release(menus);
menus = NULL;
}
+ if (_argv0) {
+ g_free(_argv0);
+ _argv0 = NULL;
+ }
+
+ refCount = 0;
gtk_main_quit ();
}
@@ -537,36 +467,8 @@ void Application::mapalt(guint maskvalue)
}
}
-} // namespace Inkscape
-#if 0
-static void
-inkscape_activate_desktop_private (Inkscape::Application *, SPDesktop *desktop)
-{
- desktop->set_active (true);
-}
-
-
-static void
-inkscape_deactivate_desktop_private (Inkscape::Application *, SPDesktop *desktop)
-{
- desktop->set_active (false);
-}
-#endif
-
-/* fixme: This is EVIL, and belongs to main after all */
-
-#define SP_INDENT 8
-
-
-static bool crashIsHappening = false;
-
-bool inkscapeIsCrashing()
-{
- return crashIsHappening;
-}
-
-static void
-inkscape_crash_handler (int /*signum*/)
+void
+Application::crash_handler (int /*signum*/)
{
using Inkscape::Debug::SimpleEvent;
using Inkscape::Debug::EventTracker;
@@ -606,7 +508,7 @@ inkscape_crash_handler (int /*signum*/)
gint count = 0;
gchar *curdir = g_get_current_dir(); // This one needs to be freed explicitly
- gchar *inkscapedir = g_path_get_dirname(INKSCAPE->argv0); // Needs to be freed
+ gchar *inkscapedir = g_path_get_dirname(INKSCAPE->_argv0); // Needs to be freed
GSList *savednames = NULL;
GSList *failednames = NULL;
for (std::map<SPDocument*,int>::iterator iter = inkscape->document_set.begin();
@@ -771,117 +673,6 @@ inkscape_crash_handler (int /*signum*/)
/* on exit, allow restored signal handler to take over and crash us */
}
-
-class InkErrorHandler : public Inkscape::ErrorReporter {
-public:
- InkErrorHandler(bool useGui) : Inkscape::ErrorReporter(),
- _useGui(useGui)
- {}
- virtual ~InkErrorHandler() {}
-
- virtual void handleError( Glib::ustring const& primary, Glib::ustring const& secondary ) const
- {
- if (_useGui) {
- Gtk::MessageDialog err(primary, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK, true);
- err.set_secondary_text(secondary);
- err.run();
- } else {
- g_message("%s", primary.data());
- g_message("%s", secondary.data());
- }
- }
-
-private:
- bool _useGui;
-};
-
-void
-inkscape_application_init (const gchar *argv0, gboolean use_gui)
-{
- inkscape = new Inkscape::Application();
- /* fixme: load application defaults */
-
- segv_handler = signal (SIGSEGV, inkscape_crash_handler);
- abrt_handler = signal (SIGABRT, inkscape_crash_handler);
- fpe_handler = signal (SIGFPE, inkscape_crash_handler);
- ill_handler = signal (SIGILL, inkscape_crash_handler);
-#ifndef WIN32
- bus_handler = signal (SIGBUS, inkscape_crash_handler);
-#endif
-
- inkscape->use_gui(use_gui);
- inkscape->argv0 = g_strdup(argv0);
-
- /* Load the preferences and menus */
- Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- InkErrorHandler* handler = new InkErrorHandler(use_gui);
- prefs->setErrorHandler(handler);
- {
- Glib::ustring msg;
- Glib::ustring secondary;
- if (prefs->getLastError( msg, secondary )) {
- handler->handleError(msg, secondary);
- }
- }
-
- if (use_gui) {
- inkscape->load_menus();
- Inkscape::DeviceManager::getManager().loadConfig();
- }
- Inkscape::ResourceManager::getManager();
-
- /* set language for user interface according setting in preferences */
- Glib::ustring ui_language = prefs->getString("/ui/language");
- if(!ui_language.empty())
- {
- setenv("LANGUAGE", ui_language, 1);
- }
-
- /* DebugDialog redirection. On Linux, default to OFF, on Win32, default to ON.
- * Use only if use_gui is enabled
- */
-#ifdef WIN32
-#define DEFAULT_LOG_REDIRECT true
-#else
-#define DEFAULT_LOG_REDIRECT false
-#endif
-
- if (use_gui == TRUE && prefs->getBool("/dialogs/debug/redirect", DEFAULT_LOG_REDIRECT))
- {
- Inkscape::UI::Dialog::DebugDialog::getInstance()->captureLogMessages();
- }
-
- /* Check for global remapping of Alt key */
- if (use_gui)
- {
- inkscape->mapalt(guint(prefs->getInt("/options/mapalt/value", 0)));
- inkscape->trackalt(guint(prefs->getInt("/options/trackalt/value", 0)));
- }
-
- /* Initialize the extensions */
- Inkscape::Extension::init();
-
- inkscape->autosave_init();
-
- //return;
-}
-
-/**
- * Returns the current Inkscape::Application global object
- */
-Inkscape::Application *
-inkscape_get_instance()
-{
- return inkscape;
-}
-
-namespace Inkscape {
-
-//gboolean inkscape_use_gui()
-//{
-// return inkscape_get_instance()->use_gui;
-//}
-
/**
* Menus management
*
@@ -894,7 +685,7 @@ bool Application::load_menus()
if ( g_file_get_contents(fn, &menus_xml, &len, NULL) ) {
// load the menus_xml file
- inkscape->menus = sp_repr_read_mem(menus_xml, len, NULL);
+ menus = sp_repr_read_mem(menus_xml, len, NULL);
g_free(menus_xml);
menus_xml = 0;
@@ -906,7 +697,7 @@ bool Application::load_menus()
menus = sp_repr_read_mem(menus_skeleton, MENUS_SKELETON_SIZE, NULL);
}
- return (inkscape->menus != 0);
+ return (menus != 0);
}
@@ -917,7 +708,6 @@ Application::selection_modified (Inkscape::Selection *selection, guint flags)
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
signal_selection_modified.emit(this, selection, flags);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[MODIFY_SELECTION], 0, selection, flags);
}
}
@@ -929,7 +719,6 @@ Application::selection_changed (Inkscape::Selection * selection)
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
signal_selection_changed.emit(this, selection);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
}
}
@@ -940,7 +729,6 @@ Application::subselection_changed (SPDesktop *desktop)
if (DESKTOP_IS_ACTIVE (desktop)) {
signal_subselection_changed.emit(this, desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SUBSELECTION], 0, desktop);
}
}
@@ -953,8 +741,6 @@ Application::selection_set (Inkscape::Selection * selection)
if (DESKTOP_IS_ACTIVE (selection->desktop())) {
signal_selection_set.emit(this, selection);
signal_selection_changed.emit(this, selection);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, selection);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, selection);
}
}
@@ -967,7 +753,6 @@ Application::eventcontext_set (Inkscape::UI::Tools::ToolBase * eventcontext)
if (DESKTOP_IS_ACTIVE (eventcontext->desktop)) {
signal_eventcontext_set.emit(this, eventcontext);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, eventcontext);
}
}
@@ -977,23 +762,20 @@ Application::add_desktop (SPDesktop * desktop)
{
g_return_if_fail (desktop != NULL);
if (desktops == NULL) {
- desktops = new std::list<SPDesktop*>;
+ desktops = new std::vector<SPDesktop*>;
g_message("Creating new desktop list.");
}
- //g_return_if_fail (inkscape != NULL);
- g_assert (std::find(desktops->begin(), desktops->end(), desktop) == desktops->end());
+ if (std::find(desktops->begin(), desktops->end(), desktop) != desktops->end()) {
+ g_error("Attempted to add desktop already in list.");
+ }
- desktops->push_front(desktop);
+ desktops->insert(desktops->begin(), desktop);
signal_activate_desktop.emit(this, desktop);
signal_eventcontext_set.emit(this, desktop->getEventContext());
signal_selection_set.emit(this, sp_desktop_selection(desktop));
signal_selection_changed.emit(this, sp_desktop_selection(desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext());
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
}
@@ -1004,39 +786,36 @@ Application::remove_desktop (SPDesktop * desktop)
g_return_if_fail (desktop != NULL);
g_return_if_fail (inkscape != NULL);
- g_assert (std::find (desktops->begin(), desktops->end(), desktop) != desktops->end() );
+ if (std::find (desktops->begin(), desktops->end(), desktop) == desktops->end() ) {
+ g_error("Attempted to remove desktop not in list.");
+ }
if (DESKTOP_IS_ACTIVE (desktop)) {
signal_deactivate_desktop.emit(this, desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, desktop);
if (desktops->size() > 1) {
SPDesktop * new_desktop = *(++desktops->begin());
- desktops->remove(new_desktop);
- desktops->push_front(new_desktop);
+ desktops->erase(std::find(desktops->begin(), desktops->end(), new_desktop));
+ desktops->insert(desktops->begin(), new_desktop);
signal_activate_desktop.emit(this, new_desktop);
signal_eventcontext_set.emit(this, new_desktop->getEventContext());
signal_selection_set.emit(this, sp_desktop_selection(new_desktop));
signal_selection_changed.emit(this, sp_desktop_selection(new_desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, new_desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, new_desktop->getEventContext());
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (new_desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (new_desktop));
} else {
signal_eventcontext_set.emit(this, NULL);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, NULL);
if (sp_desktop_selection(desktop))
sp_desktop_selection(desktop)->clear();
}
}
- desktops->remove(desktop);
+ desktops->erase(std::find(desktops->begin(), desktops->end(), desktop));
// if this was the last desktop, shut down the program
if (desktops->empty()) {
g_message("Shutting down.");
this->exit();
delete desktops;
+ desktops = NULL;
}
}
@@ -1051,28 +830,23 @@ Application::activate_desktop (SPDesktop * desktop)
return;
}
- SPDesktop* oldDesktop = 0;
- std::list<SPDesktop*>::iterator i;
+ std::vector<SPDesktop*>::iterator i;
- g_assert ((i = std::find (desktops->begin(), desktops->end(), desktop)) != desktops->end());
+ if ((i = std::find (desktops->begin(), desktops->end(), desktop)) == desktops->end()) {
+ g_error("Tried to activate desktop not added to list.");
+ }
- oldDesktop = *i;
SPDesktop *current = desktops->front();
signal_deactivate_desktop.emit(this, current);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DEACTIVATE_DESKTOP], 0, current);
- desktops->remove (desktop);
- desktops->push_front (desktop);
+ desktops->erase (i);
+ desktops->insert (desktops->begin(), desktop);
signal_activate_desktop.emit(this, desktop);
signal_eventcontext_set.emit(this, desktop->getEventContext());
signal_selection_set(this, sp_desktop_selection(desktop));
signal_selection_changed(this, sp_desktop_selection(desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_EVENTCONTEXT], 0, desktop->getEventContext());
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[SET_SELECTION], 0, sp_desktop_selection (desktop));
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[CHANGE_SELECTION], 0, sp_desktop_selection (desktop));
}
@@ -1086,7 +860,6 @@ Application::reactivate_desktop (SPDesktop * desktop)
if (DESKTOP_IS_ACTIVE (desktop)) {
signal_activate_desktop.emit(this, desktop);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[ACTIVATE_DESKTOP], 0, desktop);
}
}
@@ -1095,7 +868,7 @@ Application::reactivate_desktop (SPDesktop * desktop)
SPDesktop *
Application::find_desktop_by_dkey (unsigned int dkey)
{
- for (std::list<SPDesktop*>::iterator r = desktops->begin(); r != desktops->end(); r++) {
+ for (std::vector<SPDesktop*>::iterator r = desktops->begin(), e = desktops->end(); r != e; ++r) {
if ((*r)->dkey == dkey){
return *r;
}
@@ -1109,7 +882,7 @@ Application::maximum_dkey()
{
unsigned int dkey = 0;
- for (std::list<SPDesktop*>::iterator r = desktops->begin(); r != desktops->end(); r++) {
+ for (std::vector<SPDesktop*>::iterator r = desktops->begin(), e = desktops->end(); r != e; ++r) {
if ((*r)->dkey > dkey){
dkey = (*r)->dkey;
}
@@ -1127,7 +900,7 @@ Application::next_desktop ()
if (dkey_current < maximum_dkey()) {
// find next existing
- for (unsigned int i = dkey_current + 1; i <= maximum_dkey(); i++) {
+ for (unsigned int i = dkey_current + 1; i <= maximum_dkey(); ++i) {
d = find_desktop_by_dkey (i);
if (d) {
break;
@@ -1135,7 +908,7 @@ Application::next_desktop ()
}
} else {
// find first existing
- for (unsigned int i = 0; i <= maximum_dkey(); i++) {
+ for (unsigned int i = 0; i <= maximum_dkey(); ++i) {
d = find_desktop_by_dkey (i);
if (d) {
break;
@@ -1157,7 +930,7 @@ Application::prev_desktop ()
if (dkey_current > 0) {
// find prev existing
- for (signed int i = dkey_current - 1; i >= 0; i--) {
+ for (signed int i = dkey_current - 1; i >= 0; --i) {
d = find_desktop_by_dkey (i);
if (d) {
break;
@@ -1191,7 +964,6 @@ void
Application::dialogs_hide()
{
signal_dialogs_hide.emit(this);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_HIDE], 0);
_dialogs_toggle = FALSE;
}
@@ -1201,7 +973,6 @@ void
Application::dialogs_unhide()
{
signal_dialogs_unhide.emit(this);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[DIALOGS_UNHIDE], 0);
_dialogs_toggle = TRUE;
}
@@ -1220,9 +991,7 @@ Application::dialogs_toggle()
void
Application::external_change()
{
- //g_return_if_fail (inkscape != NULL);
signal_external_change.emit(this);
- //g_signal_emit (G_OBJECT (inkscape), inkscape_signals[EXTERNAL_CHANGE], 0);
}
/**
@@ -1318,7 +1087,7 @@ Application::sole_desktop_for_document(SPDesktop const &desktop) {
if (!document) {
return false;
}
- for ( std::list<SPDesktop*>::iterator iter = desktops->begin() ; iter != desktops->end() ; iter++ ) {
+ for ( std::vector<SPDesktop*>::iterator iter = desktops->begin(), e = desktops->end() ; iter != e; ++iter ) {
SPDesktop *other_desktop = *iter;
SPDocument *other_document = other_desktop->doc();
if ( other_document == document && other_desktop != &desktop ) {
@@ -1357,7 +1126,7 @@ Inkscape::ActionContext
Application::action_context_for_document(SPDocument *doc)
{
// If there are desktops, check them first to see if the document is bound to one of them
- for (std::list<SPDesktop*>::iterator iter = desktops->begin() ; iter != desktops->end() ; iter++) {
+ for (std::vector<SPDesktop*>::iterator iter = desktops->begin(), e = desktops->end() ; iter != e ; ++iter) {
SPDesktop *desktop = *iter;
if (desktop->doc() == doc) {
return Inkscape::ActionContext(desktop);
@@ -1365,8 +1134,8 @@ Application::action_context_for_document(SPDocument *doc)
}
// Document is not associated with any desktops - maybe we're in command-line mode
- std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = inkscape->selection_models.find(doc);
- if (sel_iter == inkscape->selection_models.end()) {
+ std::map<SPDocument *, AppSelectionModel *>::iterator sel_iter = selection_models.find(doc);
+ if (sel_iter == selection_models.end()) {
return Inkscape::ActionContext();
}
return Inkscape::ActionContext(sel_iter->second->getSelection());
@@ -1380,7 +1149,7 @@ Application::action_context_for_document(SPDocument *doc)
void
Application::refresh_display ()
{
- for (std::list<SPDesktop*>::iterator l = desktops->begin(); l != desktops->end(); l++) {
+ for (std::vector<SPDesktop*>::iterator l = desktops->begin(), e = desktops->end(); l != e; ++l) {
(*l)->requestRedraw();
}
}
@@ -1393,11 +1162,8 @@ Application::refresh_display ()
void
Application::exit ()
{
- g_assert (INKSCAPE);
-
//emit shutdown signal so that dialogs could remember layout
signal_shut_down.emit(this);
- //g_signal_emit (G_OBJECT (INKSCAPE), inkscape_signals[SHUTDOWN_SIGNAL], 0);
Inkscape::Preferences::unload();
gtk_main_quit ();
@@ -1411,7 +1177,9 @@ Application::homedir_path(const char *filename)
homedir = g_get_home_dir();
}
if (!homedir) {
- homedir = g_path_get_dirname(INKSCAPE->argv0);
+ if (inkscape) {
+ homedir = g_path_get_dirname(inkscape->_argv0);
+ }
}
return g_build_filename(homedir, filename, NULL);
}
@@ -1544,9 +1312,7 @@ Application::get_menus()
void
Application::get_all_desktops(std::list< SPDesktop* >& listbuf)
{
- for (std::list<SPDesktop*>::iterator it = desktops->begin(); it != desktops->end(); it++) {
- listbuf.push_back(*it);
- }
+ listbuf.insert(listbuf.end(), desktops->begin(), desktops->end());
}
} // namespace Inkscape