index 2d1b4c4b17e983baf1f8aea978e38af5dbc8e09e..934045b33119029a72eee8d3c5555e7c1c4624b1 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 <gtk/gtk.h>
#include <glibmm/i18n.h>
#include "helper/window.h"
#include "macros.h"
#include "widgets/icon.h"
#include "dialog-events.h"
-#include "../prefs-utils.h"
+#include "../preferences.h"
#include "../verbs.h"
#include "../interface.h"
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);
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;
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 +633,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 +912,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 +1146,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;
dest->text = gtk_editable_get_chars(dest->editable, 0, -1);
}
-
+gboolean
+quit_on_esc (GtkWidget *w, GdkEventKey *event, GObject */*tbl*/)
+{
+ switch (get_group0_keyval (event)) {
+ case GDK_Escape: // defocus
+ gtk_widget_destroy(w);
+ return TRUE;
+ }
+ return FALSE;
+}
void cmd_new_element_node(GtkObject */*object*/, gpointer /*data*/)
{
gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(dlg));
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
gtk_signal_connect(GTK_OBJECT(window), "destroy", gtk_main_quit, NULL);
+ gtk_signal_connect(GTK_OBJECT(window), "key-press-event", G_CALLBACK(quit_on_esc), window);
vbox = gtk_vbox_new(FALSE, 4);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, TRUE, 0);
cancel = gtk_button_new_with_label(_("Cancel"));
+ GTK_WIDGET_SET_FLAGS( GTK_WIDGET(cancel),
+ GTK_CAN_DEFAULT );
gtk_signal_connect_object( GTK_OBJECT(cancel), "clicked",
G_CALLBACK(gtk_widget_destroy),
GTK_OBJECT(window) );
gtk_main();
- g_assert(selected_repr != NULL);
-
- if (name.text) {
+ if (selected_repr != NULL && name.text) {
Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_document);
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);
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);