index 33ac02a9b0df915c5dd9347bc771dd1a8ce5002c..c90cde490ba02dfd0812b1c57a19ddadfbe2934f 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
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* 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 "widgets/icon.h"
+#include "../widgets/sp-xmlview-attr-list.h"
+#include "../widgets/sp-xmlview-content.h"
+#include "../widgets/sp-xmlview-tree.h"
-#include "message-stack.h"
-#include "message-context.h"
+using Inkscape::DocumentUndo;
#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 +632,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)
{
if (current_document) {
document_uri_set_connection = current_document->connectURISet(sigc::bind(sigc::ptr_fun(&on_document_uri_set), current_document));
- on_document_uri_set(SP_DOCUMENT_URI(current_document), current_document);
- set_tree_repr(sp_document_repr_root(current_document));
-
+ on_document_uri_set( current_document->getURI(), current_document );
+ set_tree_repr(current_document->getReprRoot());
} else {
set_tree_repr(NULL);
}
if (GTK_CTREE_ROW(node)->parent == new_parent &&
GTK_CTREE_ROW(node)->sibling == new_sibling)
{
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Drag XML subtree"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Drag XML subtree"));
} else {
- sp_document_cancel(current_document);
+ DocumentUndo::cancel(current_document);
}
}
@@ -924,10 +910,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 +1144,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;
{
gchar title[500];
sp_ui_dialog_title_string(Inkscape::Verb::get(SP_VERB_DIALOG_XML_EDITOR), title);
- gchar *t = g_strdup_printf("%s: %s", SP_DOCUMENT_NAME(document), title);
+ gchar *t = g_strdup_printf("%s: %s", document->getName(), title);
gtk_window_set_title(GTK_WINDOW(dlg), t);
g_free(t);
}
gtk_main();
if (selected_repr != NULL && name.text) {
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_document);
+ Inkscape::XML::Document *xml_doc = current_document->getReprDoc();
Inkscape::XML::Node *new_repr;
new_repr = xml_doc->createElement(name.text);
+ Inkscape::GC::release(new_repr);
g_free(name.text);
selected_repr->appendChild(new_repr);
set_tree_select(new_repr);
set_dt_select(new_repr);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Create new element node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Create new element node"));
}
} // end of cmd_new_element_node()
{
g_assert(selected_repr != NULL);
- Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_document);
+ Inkscape::XML::Document *xml_doc = current_document->getReprDoc();
Inkscape::XML::Node *text = xml_doc->createTextNode("");
selected_repr->appendChild(text);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Create new text node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Create new text node"));
set_tree_select(text);
set_dt_select(text);
Inkscape::XML::Node *dup = selected_repr->duplicate(parent->document());
parent->addChild(dup, selected_repr);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Duplicate node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Duplicate node"));
GtkCTreeNode *node = sp_xmlview_tree_get_repr_node(SP_XMLVIEW_TREE(tree), dup);
g_assert(selected_repr != NULL);
sp_repr_unparent(selected_repr);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Delete node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ Q_("nodeAsInXMLinHistoryDialog|Delete node"));
}
updated->updateRepr();
}
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Delete attribute"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Delete attribute"));
}
updated->updateRepr();
}
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Change attribute"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Change attribute"));
/* TODO: actually, the row won't have been created yet. why? */
gint row = sp_xmlview_attr_list_find_row_from_key(GTK_CLIST(attributes),
parent->changeOrder(selected_repr, ref);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Raise node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Raise node"));
set_tree_select(selected_repr);
set_dt_select(selected_repr);
parent->changeOrder(selected_repr, selected_repr->next());
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Lower node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Lower node"));
set_tree_select(selected_repr);
set_dt_select(selected_repr);
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);
prev->addChild(repr, ref);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Indent node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Indent node"));
set_tree_select(repr);
set_dt_select(repr);
parent->removeChild(repr);
grandparent->addChild(repr, parent);
- sp_document_done(current_document, SP_VERB_DIALOG_XML_EDITOR,
- _("Unindent node"));
+ DocumentUndo::done(current_document, SP_VERB_DIALOG_XML_EDITOR,
+ _("Unindent node"));
set_tree_select(repr);
set_dt_select(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:
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :