index 89892aab48ed1d39aec805d67a468aa660f16de8..c8644fef962ef2b3af6adddb79be4791f2d50f19 100644 (file)
--- a/src/dialogs/xml-tree.cpp
+++ b/src/dialogs/xml-tree.cpp
-#define __SP_XMLVIEW_TREE_C__
-
-/**
- * \brief XML View
- *
- * Authors:
+/** @file
+ * @brief XML editor
+ */
+/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* MenTaLguY <mental@rydia.net>
* bulia byak <buliabyak@users.sf.net>
* Johan Engelen <goejendaagh@zonnet.nl>
+ * David Turner
*
* Copyright (C) 1999-2006 Authors
- * Copyright (C) 2004 David Turner
- *
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <gtk/gtkmain.h>
-#include <gtk/gtkhbox.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtkhpaned.h>
-#include <gtk/gtkvpaned.h>
-#include <gtk/gtkhseparator.h>
-#include <gtk/gtkhbbox.h>
-#include <gtk/gtktoolbar.h>
-#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkarrow.h>
-
+#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
+#include <gtk/gtk.h>
+
+#include "desktop.h"
+#include "../desktop-handles.h"
+#include "dialog-events.h"
+#include "../document.h"
+#include "../event-context.h"
#include "helper/window.h"
-#include "macros.h"
#include "../inkscape.h"
-#include "../document.h"
-#include "../desktop-handles.h"
-#include "desktop.h"
+#include "../interface.h"
+#include "macros.h"
+#include "message-context.h"
+#include "message-stack.h"
+#include "../preferences.h"
#include "../selection.h"
+#include "shortcuts.h"
+#include "../sp-root.h"
#include "../sp-string.h"
#include "../sp-tspan.h"
-#include "../sp-root.h"
-#include "../event-context.h"
-#include "in-dt-coordsys.h"
-
-
-#include "../widgets/sp-xmlview-tree.h"
-#include "../widgets/sp-xmlview-content.h"
-#include "../widgets/sp-xmlview-attr-list.h"
-
-#include "../inkscape-stock.h"
-#include "widgets/icon.h"
-
-#include "dialog-events.h"
-#include "../prefs-utils.h"
+#include "ui/icon-names.h"
#include "../verbs.h"
-#include "../interface.h"
-
-#include "shortcuts.h"
-#include <gdk/gdkkeysyms.h>
-
-#include "message-stack.h"
-#include "message-context.h"
+#include "widgets/icon.h"
+#include "../widgets/sp-xmlview-attr-list.h"
+#include "../widgets/sp-xmlview-content.h"
+#include "../widgets/sp-xmlview-tree.h"
#define MIN_ONSCREEN_DISTANCE 50
static win_data wd;
// impossible original values to make sure they are read from prefs
static gint x = -1000, y = -1000, w = 0, h = 0;
-static gchar const *const prefs_path = "dialogs.xml";
+static Glib::ustring const prefs_path = "/dialogs/xml/";
static GtkWidget *status = NULL;
static Inkscape::MessageStack *_message_stack = NULL;
static Inkscape::MessageContext *_message_context = NULL;
static gint selected_attr = 0;
static Inkscape::XML::Node *selected_repr = NULL;
-static void sp_xmltree_desktop_change( Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *dialog );
+static void sp_xmltree_desktop_activate( Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *dialog );
+static void sp_xmltree_desktop_deactivate( Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *dialog );
static void set_tree_desktop(SPDesktop *desktop);
static void set_tree_document(SPDocument *document);
static gboolean sp_xml_tree_key_press(GtkWidget *widget, GdkEventKey *event);
+static bool in_dt_coordsys(SPObject const &item);
/*
* \brief Sets the XML status bar when the tree is selected.
gtk_tooltips_enable(tooltips);
dlg = sp_window_new("", TRUE);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (x == -1000 || y == -1000) {
- x = prefs_get_int_attribute(prefs_path, "x", -1000);
- y = prefs_get_int_attribute(prefs_path, "y", -1000);
+ x = prefs->getInt(prefs_path + "x", -1000);
+ y = prefs->getInt(prefs_path + "y", -1000);
}
if (w ==0 || h == 0) {
- w = prefs_get_int_attribute(prefs_path, "w", 0);
- h = prefs_get_int_attribute(prefs_path, "h", 0);
+ w = prefs->getInt(prefs_path + "w", 0);
+ h = prefs->getInt(prefs_path + "h", 0);
}
// if (x<0) x=0;
_("New element node"),
NULL,
sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
- INKSCAPE_STOCK_ADD_XML_ELEMENT_NODE ),
+ INKSCAPE_ICON_XML_ELEMENT_NEW ),
G_CALLBACK(cmd_new_element_node),
NULL);
button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
NULL, _("New text node"), NULL,
sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
- INKSCAPE_STOCK_ADD_XML_TEXT_NODE ),
+ INKSCAPE_ICON_XML_TEXT_NEW ),
G_CALLBACK(cmd_new_text_node),
NULL);
button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
NULL, _("Duplicate node"), NULL,
sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
- INKSCAPE_STOCK_DUPLICATE_XML_NODE ),
+ INKSCAPE_ICON_XML_NODE_DUPLICATE ),
G_CALLBACK(cmd_duplicate_node),
NULL);
gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
- NULL, _("Delete node"), NULL,
+ NULL, Q_("nodeAsInXMLdialogTooltip|Delete node"), NULL,
sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
- INKSCAPE_STOCK_DELETE_XML_NODE ),
+ INKSCAPE_ICON_XML_NODE_DELETE ),
G_CALLBACK(cmd_delete_node), NULL );
gtk_signal_connect_while_alive(GTK_OBJECT(tree), "tree_select_row",
button = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
NULL, _("Delete attribute"), NULL,
sp_icon_new( Inkscape::ICON_SIZE_LARGE_TOOLBAR,
- INKSCAPE_STOCK_DELETE_XML_ATTRIBUTE ),
+ INKSCAPE_ICON_XML_ATTRIBUTE_DELETE ),
(GCallback) cmd_delete_attr, NULL);
gtk_signal_connect_while_alive(GTK_OBJECT(attributes), "select_row",
gtk_widget_hide(text_container);
g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop",
- G_CALLBACK(sp_xmltree_desktop_change), dlg);
+ G_CALLBACK(sp_xmltree_desktop_activate), dlg);
g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop",
- G_CALLBACK(sp_xmltree_desktop_change), dlg);
+ G_CALLBACK(sp_xmltree_desktop_deactivate), dlg);
g_signal_connect((GObject *) dlg, "key_press_event", (GCallback) sp_xml_tree_key_press, NULL);
@@ -649,16 +628,20 @@ static gboolean sp_xml_tree_key_press(GtkWidget */*widget*/, GdkEventKey *event)
}
-static void sp_xmltree_desktop_change(Inkscape::Application */*inkscape*/,
+static void sp_xmltree_desktop_activate(Inkscape::Application */*inkscape*/,
SPDesktop *desktop,
GtkWidget */*dialog*/ )
{
- if (!desktop) {
- return;
- }
set_tree_desktop(desktop);
}
+static void sp_xmltree_desktop_deactivate(Inkscape::Application */*inkscape*/,
+ SPDesktop */*desktop*/,
+ GtkWidget */*dialog*/ )
+{
+ set_tree_desktop(NULL);
+}
+
void set_tree_desktop(SPDesktop *desktop)
{
@@ -924,10 +907,11 @@ static gboolean on_delete(GtkObject */*object*/, GdkEvent */*event*/, gpointer /
if (x<0) x=0;
if (y<0) y=0;
- prefs_set_int_attribute(prefs_path, "x", x);
- prefs_set_int_attribute(prefs_path, "y", y);
- prefs_set_int_attribute(prefs_path, "w", w);
- prefs_set_int_attribute(prefs_path, "h", h);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ prefs->setInt(prefs_path + "x", x);
+ prefs->setInt(prefs_path + "y", y);
+ prefs->setInt(prefs_path + "w", w);
+ prefs->setInt(prefs_path + "h", h);
return FALSE; // which means, go ahead and destroy it
}
@@ -1157,7 +1141,7 @@ void on_tree_select_row_enable_if_indentable(GtkCTree *tree, GtkCTreeNode *node,
// skip to the child just before the current repr
for ( prev = parent->firstChild() ;
prev && prev->next() != repr ;
- prev = prev->next() );
+ prev = prev->next() ){};
if (prev && prev->type() == Inkscape::XML::ELEMENT_NODE) {
indentable = TRUE;
sp_repr_unparent(selected_repr);
sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Delete node"));
+ Q_("nodeAsInXMLinHistoryDialog|Delete node"));
}
Inkscape::XML::Node* ref = NULL;
if (prev->firstChild()) {
- for( ref = prev->firstChild() ; ref->next() ; ref = ref->next() );
+ for( ref = prev->firstChild() ; ref->next() ; ref = ref->next() ){};
}
parent->removeChild(repr);
} // end of cmd_unindent_node()
+/** Returns true iff \a item is suitable to be included in the selection, in particular
+ whether it has a bounding box in the desktop coordinate system for rendering resize handles.
+
+ Descendents of <defs> nodes (markers etc.) return false, for example.
+*/
+bool in_dt_coordsys(SPObject const &item)
+{
+ /* Definition based on sp_item_i2doc_affine. */
+ SPObject const *child = &item;
+ g_return_val_if_fail(child != NULL, false);
+ for(;;) {
+ if (!SP_IS_ITEM(child)) {
+ return false;
+ }
+ SPObject const * const parent = SP_OBJECT_PARENT(child);
+ if (parent == NULL) {
+ break;
+ }
+ child = parent;
+ }
+ g_assert(SP_IS_ROOT(child));
+ /* Relevance: Otherwise, I'm not sure whether to return true or false. */
+ return true;
+}
+
/*
Local Variables: