summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorKris De Gussem <kris.degussem@gmail.com>2012-01-19 19:45:06 +0000
committerKris <Kris.De.Gussem@hotmail.com>2012-01-19 19:45:06 +0000
commit28dcdf10f9fef7f4c7d7bf7664040aa3c26126fe (patch)
tree446c523f5a28f31ce6423086a293cdfff81f2b8f /src/ui
parentUpdate and documentation of sp-attribute-widget (diff)
downloadinkscape-28dcdf10f9fef7f4c7d7bf7664040aa3c26126fe.tar.gz
inkscape-28dcdf10f9fef7f4c7d7bf7664040aa3c26126fe.zip
Gtkmmification of object attributes dialog: image and link attributes now editable in dockable dialog (Bug #592323)
(bzr r10910)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/CMakeLists.txt4
-rw-r--r--src/ui/context-menu.cpp29
-rw-r--r--src/ui/dialog/dialog-manager.cpp7
-rw-r--r--src/ui/dialog/object-attributes.cpp211
-rw-r--r--src/ui/dialog/object-attributes.h124
5 files changed, 358 insertions, 17 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 3727cc661..f1cccc3fe 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -48,9 +48,10 @@ set(ui_SRC
dialog/layer-properties.cpp
dialog/layers.cpp
dialog/livepatheffect-editor.cpp
- dialog/object-properties.cpp
dialog/memory.cpp
dialog/messages.cpp
+ dialog/object-attributes.cpp
+ dialog/object-properties.cpp
dialog/ocaldialogs.cpp
dialog/print-colors-preview-dialog.cpp
dialog/print.cpp
@@ -155,6 +156,7 @@ set(ui_SRC
dialog/livepatheffect-editor.h
dialog/memory.h
dialog/messages.h
+ dialog/object-attributes.h
dialog/object-properties.h
dialog/ocaldialogs.h
dialog/panel-dialog.h
diff --git a/src/ui/context-menu.cpp b/src/ui/context-menu.cpp
index f8ec1eed1..e99a19e11 100644
--- a/src/ui/context-menu.cpp
+++ b/src/ui/context-menu.cpp
@@ -42,24 +42,22 @@ void sp_object_menu(SPObject *object, SPDesktop *desktop, GtkMenu *menu)
/* Implementation */
#include <gtk/gtk.h>
-
#include <glibmm/i18n.h>
+#include "selection.h"
+#include "selection-chemistry.h"
#include "sp-anchor.h"
+#include "sp-clippath.h"
#include "sp-image.h"
+#include "sp-mask.h"
+#include "sp-path.h"
#include "sp-text.h"
-
#include "desktop-handles.h"
-#include "selection.h"
-#include "selection-chemistry.h"
-#include "dialogs/object-attributes.h"
#include "dialogs/text-edit.h"
#include "dialogs/spellcheck.h"
+#include "ui/dialog/object-attributes.h"
#include "ui/dialog/object-properties.h"
-#include "sp-path.h"
-#include "sp-clippath.h"
-#include "sp-mask.h"
static void sp_item_menu(SPObject *object, SPDesktop *desktop, GtkMenu *menu);
@@ -284,9 +282,8 @@ static void sp_item_create_link(GtkMenuItem *menuitem, SPItem *item)
DocumentUndo::done(object->document, SP_VERB_NONE,
_("Create link"));
- sp_object_attributes_dialog(object, "SPAnchor");
-
sp_desktop_selection(desktop)->set(SP_ITEM(object));
+ desktop->_dlg_mgr->showDialog("ObjectAttributes");
}
/* SPGroup */
@@ -355,9 +352,11 @@ static void sp_anchor_menu(SPObject *object, SPDesktop *desktop, GtkMenu *m)
gtk_menu_shell_append(GTK_MENU_SHELL(m), w);
}
-static void sp_anchor_link_properties(GtkMenuItem */*menuitem*/, SPAnchor *anchor)
+static void sp_anchor_link_properties(GtkMenuItem *menuitem, SPAnchor */*anchor*/)
{
- sp_object_attributes_dialog(anchor, "Link");
+ SPDesktop *desktop = (SPDesktop*)g_object_get_data(G_OBJECT(menuitem), "desktop");
+ g_return_if_fail(desktop != NULL);
+ desktop->_dlg_mgr->showDialog("ObjectAttributes");
}
static void sp_anchor_link_follow(GtkMenuItem */*menuitem*/, SPAnchor *anchor)
@@ -410,9 +409,11 @@ static void sp_image_menu(SPObject *object, SPDesktop *desktop, GtkMenu *m)
}
}
-static void sp_image_image_properties(GtkMenuItem */*menuitem*/, SPAnchor *anchor)
+static void sp_image_image_properties(GtkMenuItem *menuitem, SPAnchor */*anchor*/)
{
- sp_object_attributes_dialog(anchor, "Image");
+ SPDesktop *desktop = (SPDesktop*)g_object_get_data(G_OBJECT(menuitem), "desktop");
+ g_return_if_fail(desktop != NULL);
+ desktop->_dlg_mgr->showDialog("ObjectAttributes");
}
static gchar* getImageEditorName() {
diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp
index 95486c5e3..4781e55ba 100644
--- a/src/ui/dialog/dialog-manager.cpp
+++ b/src/ui/dialog/dialog-manager.cpp
@@ -45,6 +45,7 @@
//#include "ui/dialog/print-colors-preview-dialog.h"
#include "util/ege-appear-time-tracker.h"
#include "preferences.h"
+#include "ui/dialog/object-attributes.h"
#include "ui/dialog/object-properties.h"
@@ -108,7 +109,8 @@ DialogManager::DialogManager() {
registerFactory("LivePathEffect", &create<LivePathEffectEditor, FloatingBehavior>);
registerFactory("Memory", &create<Memory, FloatingBehavior>);
registerFactory("Messages", &create<Messages, FloatingBehavior>);
- registerFactory("ObjectProperties", &create<ObjectProperties, FloatingBehavior>);
+ registerFactory("ObjectAttributes", &create<ObjectAttributes, FloatingBehavior>);
+ registerFactory("ObjectProperties", &create<ObjectProperties, FloatingBehavior>);
// registerFactory("PrintColorsPreviewDialog", &create<PrintColorsPreviewDialog, FloatingBehavior>);
registerFactory("Script", &create<ScriptDialog, FloatingBehavior>);
#ifdef ENABLE_SVG_FONTS
@@ -137,7 +139,8 @@ DialogManager::DialogManager() {
registerFactory("LivePathEffect", &create<LivePathEffectEditor, DockBehavior>);
registerFactory("Memory", &create<Memory, DockBehavior>);
registerFactory("Messages", &create<Messages, DockBehavior>);
- registerFactory("ObjectProperties", &create<ObjectProperties, DockBehavior>);
+ registerFactory("ObjectAttributes", &create<ObjectAttributes, DockBehavior>);
+ registerFactory("ObjectProperties", &create<ObjectProperties, DockBehavior>);
// registerFactory("PrintColorsPreviewDialog", &create<PrintColorsPreviewDialog, DockBehavior>);
registerFactory("Script", &create<ScriptDialog, DockBehavior>);
#ifdef ENABLE_SVG_FONTS
diff --git a/src/ui/dialog/object-attributes.cpp b/src/ui/dialog/object-attributes.cpp
new file mode 100644
index 000000000..1f55887f4
--- /dev/null
+++ b/src/ui/dialog/object-attributes.cpp
@@ -0,0 +1,211 @@
+/** @file
+ * Generic object attribute editor
+ */
+/* Authors:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * bulia byak <buliabyak@users.sf.net>
+ * Kris De Gussem <Kris.DeGussem@gmail.com>
+ *
+ * Copyright (C) 1999-2012 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <glibmm/i18n.h>
+
+#include "desktop-handles.h"
+#include "macros.h"
+#include "sp-anchor.h"
+#include "sp-image.h"
+#include "verbs.h"
+#include "xml/repr.h"
+#include "ui/dialog/dialog-manager.h"
+#include "ui/dialog/object-attributes.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Dialog {
+
+struct SPAttrDesc {
+ gchar const *label;
+ gchar const *attribute;
+};
+
+static const SPAttrDesc anchor_desc[] = {
+ { N_("Href:"), "xlink:href"},
+ { N_("Target:"), "target"},
+ { N_("Type:"), "xlink:type"},
+ // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkRoleAttribute
+ // Identifies the type of the related resource with an absolute URI
+ { N_("Role:"), "xlink:role"},
+ // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkArcRoleAttribute
+ // For situations where the nature/role alone isn't enough, this offers an additional URI defining the purpose of the link.
+ { N_("Arcrole:"), "xlink:arcrole"},
+ // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkTitleAttribute
+ { N_("Title:"), "xlink:title"},
+ { N_("Show:"), "xlink:show"},
+ // TRANSLATORS: for info, see http://www.w3.org/TR/2000/CR-SVG-20000802/linking.html#AElementXLinkActuateAttribute
+ { N_("Actuate:"), "xlink:actuate"},
+ { NULL, NULL}
+};
+
+static const SPAttrDesc image_desc[] = {
+ { N_("URL:"), "xlink:href"},
+ { N_("X:"), "x"},
+ { N_("Y:"), "y"},
+ { N_("Width:"), "width"},
+ { N_("Height:"), "height"},
+ { NULL, NULL}
+};
+
+static const SPAttrDesc image_nohref_desc[] = {
+ { N_("X:"), "x"},
+ { N_("Y:"), "y"},
+ { N_("Width:"), "width"},
+ { N_("Height:"), "height"},
+ { NULL, NULL}
+};
+
+ObjectAttributes::ObjectAttributes (void) :
+ UI::Widget::Panel ("", "/dialogs/objectattr/", SP_VERB_DIALOG_ATTR),
+ blocked (false),
+ CurrentItem(NULL),
+ attrTable(),
+ desktop(NULL),
+ deskTrack(),
+ selectChangedConn(),
+ subselChangedConn(),
+ selectModifiedConn()
+{
+ attrTable.show();
+ widget_setup();
+
+ desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &ObjectAttributes::setTargetDesktop) );
+ deskTrack.connect(GTK_WIDGET(gobj()));
+}
+
+ObjectAttributes::~ObjectAttributes (void)
+{
+ selectModifiedConn.disconnect();
+ subselChangedConn.disconnect();
+ selectChangedConn.disconnect();
+ desktopChangeConn.disconnect();
+ deskTrack.disconnect();
+}
+
+void ObjectAttributes::widget_setup (void)
+{
+ if (blocked)
+ {
+ return;
+ }
+
+ Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP);
+ SPItem *item = selection->singleItem();
+ if (!item)
+ {
+ set_sensitive (false);
+ CurrentItem = NULL;
+ //no selection anymore or multiple objects selected, means that we need
+ //to close the connections to the previously selected object
+ return;
+ }
+
+ blocked = true;
+ SPObject *obj = (SPObject*)item; //to get the selected item
+ GObjectClass *klass = G_OBJECT_GET_CLASS(obj); //to deduce the object's type
+ GType type = G_TYPE_FROM_CLASS(klass);
+ const SPAttrDesc *desc;
+
+ if (type == SP_TYPE_ANCHOR)
+ {
+ desc = anchor_desc;
+ }
+ else if (type == SP_TYPE_IMAGE)
+ {
+ Inkscape::XML::Node *ir = obj->getRepr();
+ const gchar *href = ir->attribute("xlink:href");
+ if ( (!href) || ((strncmp(href, "data:", 5) == 0)) )
+ {
+ desc = image_nohref_desc;
+ }
+ else
+ {
+ desc = image_desc;
+ }
+ }
+ else
+ {
+ blocked = false;
+ set_sensitive (false);
+ return;
+ }
+
+ int len = 0;
+ std::vector<Glib::ustring> labels;
+ std::vector<Glib::ustring> attrs;
+ if (CurrentItem != item)
+ {
+ while (desc[len].label)
+ {
+ labels.push_back(desc[len].label);
+ attrs.push_back (desc[len].attribute);
+ len += 1;
+ }
+ attrTable.set_object(obj, labels, attrs, (GtkWidget*)gobj());
+ CurrentItem = item;
+ }
+ else
+ {
+ attrTable.change_object(obj);
+ }
+
+ set_sensitive (true);
+ show_all();
+ blocked = false;
+}
+
+void ObjectAttributes::setTargetDesktop(SPDesktop *desktop)
+{
+ if (this->desktop != desktop) {
+ if (this->desktop) {
+ selectModifiedConn.disconnect();
+ subselChangedConn.disconnect();
+ selectChangedConn.disconnect();
+ }
+ this->desktop = desktop;
+ if (desktop && desktop->selection) {
+ selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup)));
+ subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &ObjectAttributes::widget_setup)));
+
+ // Must check flags, so can't call widget_setup() directly.
+ selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &ObjectAttributes::selectionModifiedCB)));
+ }
+ widget_setup();
+ }
+}
+
+void ObjectAttributes::selectionModifiedCB( guint flags )
+{
+ if (flags & ( SP_OBJECT_MODIFIED_FLAG |
+ SP_OBJECT_PARENT_MODIFIED_FLAG |
+ SP_OBJECT_STYLE_MODIFIED_FLAG) ) {
+ attrTable.reread_properties();
+ }
+}
+
+
+}
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/dialog/object-attributes.h b/src/ui/dialog/object-attributes.h
new file mode 100644
index 000000000..a5a361c25
--- /dev/null
+++ b/src/ui/dialog/object-attributes.h
@@ -0,0 +1,124 @@
+/** @file
+ * Generic object attribute editor
+ */
+/* Author:
+ * Lauris Kaplinski <lauris@ximian.com>
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Licensed under GNU GPL
+ */
+
+#ifndef SEEN_DIALOGS_OBJECT_ATTRIBUTES_H
+#define SEEN_DIALOGS_OBJECT_ATTRIBUTES_H
+
+#include <glib.h>
+
+#include "desktop.h"
+#include "ui/dialog/desktop-tracker.h"
+#include "ui/widget/panel.h"
+#include "widgets/sp-attribute-widget.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Dialog {
+
+/**
+ * A dialog widget to show object attributes (currently for images and links).
+ */
+class ObjectAttributes : public Widget::Panel {
+public:
+ ObjectAttributes ();
+ ~ObjectAttributes ();
+
+ /**
+ * Returns a new instance of the object attributes dialog.
+ *
+ * Auxiliary function needed by the DialogManager.
+ */
+ static ObjectAttributes &getInstance() { return *new ObjectAttributes(); }
+
+ /**
+ * Updates entries and other child widgets on selection change, object modification, etc.
+ */
+ void widget_setup(void);
+
+private:
+ /**
+ * Is UI update bloched?
+ */
+ bool blocked;
+
+ /**
+ * Contains a pointer to the currently selected item (NULL in case nothing is or multiple objects are selected).
+ */
+ SPItem *CurrentItem;
+
+ /**
+ * Child widget to show the object attributes.
+ *
+ * attrTable makes the labels and edit boxes for the attributes defined
+ * in the SPAttrDesc arrays at the top of the cpp-file. This widgets also
+ * ensures object attribute modifications by the user are set.
+ */
+ SPAttributeTable attrTable;
+
+ /**
+ * Stores the current desktop.
+ */
+ SPDesktop *desktop;
+
+ /**
+ * Auxiliary widget to keep track of desktop changes for the floating dialog.
+ */
+ DesktopTracker deskTrack;
+
+ /**
+ * Link to callback function for a change in desktop (window).
+ */
+ sigc::connection desktopChangeConn;
+
+ /**
+ * Link to callback function for a selection change.
+ */
+ sigc::connection selectChangedConn;
+ sigc::connection subselChangedConn;
+
+ /**
+ * Link to callback function for a modification of the selected object.
+ */
+ sigc::connection selectModifiedConn;
+
+ /**
+ * Callback function invoked by the desktop tracker in case of a modification of the selected object.
+ */
+ void selectionModifiedCB( guint flags );
+
+ /*
+ * Can be invoked for setting the desktop. Currently not used.
+ */
+ // void setDesktop(SPDesktop *desktop);
+
+ /**
+ * Is invoked by the desktop tracker when the desktop changes.
+ */
+ void setTargetDesktop(SPDesktop *desktop);
+
+};
+
+}
+}
+}
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :