diff options
| author | Kris De Gussem <kris.degussem@gmail.com> | 2012-01-08 18:44:57 +0000 |
|---|---|---|
| committer | Kris <Kris.De.Gussem@hotmail.com> | 2012-01-08 18:44:57 +0000 |
| commit | 76f22d76e691070e082914b61ff2b2f478350587 (patch) | |
| tree | aa28f63602107c3d4576acb08997e713f0a6233f /src/ui | |
| parent | Unweirdification of Preferences dialog's menu (Bug #259480). (diff) | |
| download | inkscape-76f22d76e691070e082914b61ff2b2f478350587.tar.gz inkscape-76f22d76e691070e082914b61ff2b2f478350587.zip | |
Object properties dialog now dockable (derived from Inkscape::UI:Widget::Panel as opposed to Gtk::Widget)
(bzr r10862)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/ui/context-menu.cpp | 5 | ||||
| -rw-r--r-- | src/ui/dialog/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/ui/dialog/dialog-manager.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/object-properties.cpp | 391 | ||||
| -rw-r--r-- | src/ui/dialog/object-properties.h | 110 |
6 files changed, 511 insertions, 2 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index e697fba99..74802cab3 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -48,6 +48,7 @@ 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/ocaldialogs.cpp diff --git a/src/ui/context-menu.cpp b/src/ui/context-menu.cpp index 331026aac..f8ec1eed1 100644 --- a/src/ui/context-menu.cpp +++ b/src/ui/context-menu.cpp @@ -52,10 +52,10 @@ void sp_object_menu(SPObject *object, SPDesktop *desktop, GtkMenu *menu) #include "desktop-handles.h" #include "selection.h" #include "selection-chemistry.h" -#include "dialogs/item-properties.h" #include "dialogs/object-attributes.h" #include "dialogs/text-edit.h" #include "dialogs/spellcheck.h" +#include "ui/dialog/object-properties.h" #include "sp-path.h" #include "sp-clippath.h" @@ -189,7 +189,8 @@ static void sp_item_properties(GtkMenuItem *menuitem, SPItem *item) sp_desktop_selection(desktop)->set(item); - sp_item_dialog(); + // sp_item_dialog(); + desktop->_dlg_mgr->showDialog("ObjectProperties"); } diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index 5d6592897..701066b20 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -64,6 +64,8 @@ ink_common_sources += \ ui/dialog/messages.h \ ui/dialog/ocaldialogs.cpp \ ui/dialog/ocaldialogs.h \ + ui/dialog/object-properties.cpp \ + ui/dialog/object-properties.h \ ui/dialog/panel-dialog.h \ ui/dialog/print.cpp \ ui/dialog/print.h \ diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index cba0cf508..95486c5e3 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -45,6 +45,8 @@ //#include "ui/dialog/print-colors-preview-dialog.h" #include "util/ege-appear-time-tracker.h" #include "preferences.h" +#include "ui/dialog/object-properties.h" + #ifdef ENABLE_SVG_FONTS #include "ui/dialog/svg-fonts-dialog.h" @@ -106,6 +108,7 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create<LivePathEffectEditor, FloatingBehavior>); registerFactory("Memory", &create<Memory, FloatingBehavior>); registerFactory("Messages", &create<Messages, FloatingBehavior>); + registerFactory("ObjectProperties", &create<ObjectProperties, FloatingBehavior>); // registerFactory("PrintColorsPreviewDialog", &create<PrintColorsPreviewDialog, FloatingBehavior>); registerFactory("Script", &create<ScriptDialog, FloatingBehavior>); #ifdef ENABLE_SVG_FONTS @@ -134,6 +137,7 @@ DialogManager::DialogManager() { registerFactory("LivePathEffect", &create<LivePathEffectEditor, DockBehavior>); registerFactory("Memory", &create<Memory, DockBehavior>); registerFactory("Messages", &create<Messages, 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-properties.cpp b/src/ui/dialog/object-properties.cpp new file mode 100644 index 000000000..773906174 --- /dev/null +++ b/src/ui/dialog/object-properties.cpp @@ -0,0 +1,391 @@ +/** + * @file + * Object properties dialog. + */ +/* Authors: + * Lauris Kaplinski <lauris@kaplinski.com> + * bulia byak <buliabyak@users.sf.net> + * Johan Engelen <goejendaagh@zonnet.nl> + * Abhishek Sharma + * Kris De Gussem <Kris.DeGussem@gmail.com> + * + * Copyright (C) 1999-2011 Authors + * Copyright (C) 2001 Ximian, Inc. + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "../desktop-handles.h" +#include "../document.h" +#include "object-properties.h" + + +namespace Inkscape { +namespace UI { +namespace Dialog { + +void on_selection_changed(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, ObjectProperties *dial); + +/** + * Create a new static instance of the object properties dialog. + */ +ObjectProperties::ObjectProperties (void) : + UI::Widget::Panel ("", "/dialogs/object/", SP_VERB_DIALOG_ITEM), + blocked (false), + TopTable (3, 4, false), + LabelID(_("_ID:"), 1), + LabelLabel(_("_Label:"), 1), + LabelTitle(_("_Title:"),1), + LabelDescription(_("_Description"),1), + HBoxCheck(FALSE, 0), + CheckTable(1, 2, TRUE), + CBHide(_("_Hide"), 1), + CBLock(_("L_ock"), 1), + BSet (_("_Set"), 1), + LabelInteractivity(_("_Interactivity"), 1), + attrTable(), + CurrentItem(0) +{ + //initialize labels for the table at the bottom of the dialog + int_labels.push_back("onclick"); + int_labels.push_back("onmouseover"); + int_labels.push_back("onmouseout"); + int_labels.push_back("onmousedown"); + int_labels.push_back("onmouseup"); + int_labels.push_back("onmousemove"); + int_labels.push_back("onfocusin"); + int_labels.push_back("onfocusout"); + int_labels.push_back("onfocusout"); + int_labels.push_back("onload"); + + MakeWidget(); +} + +ObjectProperties::~ObjectProperties (void) +{ +} + +void ObjectProperties::MakeWidget(void) +{ + // g_signal_connect (G_OBJECT (INKSCAPE), "modify_selection", G_CALLBACK (sp_item_widget_modify_selection), wd.win); + // g_signal_connect (G_OBJECT (INKSCAPE), "set_selection", G_CALLBACK (sp_item_widget_change_selection), wd.win); + g_signal_connect (G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (on_selection_changed), this); + + Gtk::Box *contents = _getContents(); + contents->set_spacing(0); + + TopTable.set_border_width(4); + TopTable.set_row_spacings(4); + TopTable.set_col_spacings(4); + contents->pack_start (TopTable, true, true, 0); + + /* Create the label for the object id */ + LabelID.set_alignment (1, 0.5); + TopTable.attach (LabelID, 0, 1, 0, 1, + Gtk::SHRINK | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + + /* Create the entry box for the object id */ + EntryID.set_tooltip_text (_("The id= attribute (only letters, digits, and the characters .-_: allowed)")); + EntryID.set_max_length (64); + TopTable.attach (EntryID, 1, 2, 0, 1, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + LabelID.set_mnemonic_widget (EntryID); + + // pressing enter in the id field is the same as clicking Set: + EntryID.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + // focus is in the id field initially: + EntryID.grab_focus(); + + /* Create the label for the object label */ + LabelLabel.set_alignment (1, 0.5); + TopTable.attach (LabelLabel, 0, 1, 1, 2, + Gtk::SHRINK | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + + /* Create the entry box for the object label */ + EntryLabel.set_tooltip_text (_("A freeform label for the object")); + EntryLabel.set_max_length (256); + TopTable.attach (EntryLabel, 1, 2, 1, 2, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + LabelLabel.set_mnemonic_widget (EntryLabel); + + // pressing enter in the label field is the same as clicking Set: + EntryLabel.signal_activate().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + + /* Create the label for the object title */ + LabelTitle.set_alignment (1, 0.5); + TopTable.attach (LabelTitle, 0, 1, 2, 3, + Gtk::SHRINK | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + + /* Create the entry box for the object title */ + EntryTitle.set_sensitive (FALSE); + EntryTitle.set_max_length (256); + TopTable.attach (EntryTitle, 1, 3, 2, 3, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + LabelTitle.set_mnemonic_widget (EntryTitle); + + /* Create the frame for the object description */ + FrameDescription.set_label_widget (LabelDescription); + TopTable.attach (FrameDescription, 0, 3, 3, 4, + Gtk::EXPAND | Gtk::FILL, + Gtk::EXPAND | Gtk::FILL, 0, 0 ); + + /* Create the text view box for the object description */ + FrameTextDescription.set_border_width(4); + FrameTextDescription.set_sensitive (FALSE); + FrameDescription.add (FrameTextDescription); + FrameTextDescription.set_shadow_type (Gtk::SHADOW_IN); + + TextViewDescription.set_wrap_mode(Gtk::WRAP_WORD); + TextViewDescription.get_buffer()->set_text(""); + FrameTextDescription.add (TextViewDescription); + TextViewDescription.add_mnemonic_label(LabelDescription); + + /* Check boxes */ + contents->pack_start (HBoxCheck, FALSE, FALSE, 0); + CheckTable.set_border_width(0); + HBoxCheck.pack_start (CheckTable, TRUE, TRUE, 10); + + /* Hide */ + CBHide.set_tooltip_text (_("Check to make the object invisible")); + CheckTable.attach (CBHide, 0, 1, 0, 1, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + CBHide.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::hidden_toggled)); + + /* Lock */ + // TRANSLATORS: "Lock" is a verb here + CBLock.set_tooltip_text (_("Check to make the object insensitive (not selectable by mouse)")); + CheckTable.attach (CBLock, 1, 2, 0, 1, + Gtk::EXPAND | Gtk::FILL, + Gtk::AttachOptions(), 0, 0 ); + CBLock.signal_toggled().connect(sigc::mem_fun(this, &ObjectProperties::sensitivity_toggled)); + + + /* Button for setting the object's id, label, title and description. */ + HBoxCheck.pack_start (BSet, TRUE, TRUE, 10); + BSet.signal_clicked().connect(sigc::mem_fun(this, &ObjectProperties::label_changed)); + + /* Create the frame for interactivity options */ + EInteractivity.set_label_widget (LabelInteractivity); + contents->pack_start (EInteractivity, FALSE, FALSE, 0); + show_all (); + widget_setup(); +} + +void ObjectProperties::widget_setup(void) +{ + if (blocked) + { + return; + } + + Inkscape::Selection *selection = sp_desktop_selection (SP_ACTIVE_DESKTOP); + Gtk::Box *contents = _getContents(); + + if (!selection->singleItem()) { + contents->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 + attrTable.clear(); + return; + } else { + contents->set_sensitive (true); + } + + SPItem *item = selection->singleItem(); + if (CurrentItem == item) + { + //otherwise we would end up wasting resources through the modify selection + //callback when moving an object (endlessly setting the labels and recreating attrTable) + return; + } + blocked = true; + + CBLock.set_active (item->isLocked()); /* Sensitive */ + CBHide.set_active (item->isExplicitlyHidden()); /* Hidden */ + + if (item->cloned) { + /* ID */ + EntryID.set_text (""); + EntryID.set_sensitive (FALSE); + LabelID.set_text (_("Ref")); + + /* Label */ + EntryLabel.set_text (""); + EntryLabel.set_sensitive (FALSE); + LabelLabel.set_text (_("Ref")); + + } else { + SPObject *obj = (SPObject*)item; + + /* ID */ + EntryID.set_text (obj->getId()); + EntryID.set_sensitive (TRUE); + LabelID.set_markup_with_mnemonic (_("_ID:")); + + /* Label */ + EntryLabel.set_text(obj->defaultLabel()); + EntryLabel.set_sensitive (TRUE); + + /* Title */ + gchar *title = obj->title(); + if (title) { + EntryTitle.set_text(title); + g_free(title); + } + else { + EntryTitle.set_text(""); + } + EntryTitle.set_sensitive(TRUE); + + /* Description */ + gchar *desc = obj->desc(); + if (desc) { + TextViewDescription.get_buffer()->set_text(desc); + g_free(desc); + } else { + TextViewDescription.get_buffer()->set_text(""); + } + FrameTextDescription.set_sensitive(TRUE); + + if (CurrentItem == NULL) + { + attrTable.set_object(obj, int_labels, int_labels, (GtkWidget*)EInteractivity.gobj()); + } + else + { + attrTable.change_object(obj); + } + attrTable.show_all(); + } + CurrentItem = item; + blocked = false; +} + +void ObjectProperties::label_changed(void) +{ + if (blocked) + { + return; + } + + SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + g_return_if_fail (item != NULL); + + blocked = true; + + /* Retrieve the label widget for the object's id */ + gchar *id = g_strdup(EntryID.get_text().c_str()); + g_strcanon (id, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.:", '_'); + if (!strcmp (id, item->getId())) { + LabelID.set_markup_with_mnemonic(_("_ID:")); + } else if (!*id || !isalnum (*id)) { + LabelID.set_text (_("Id invalid! ")); + } else if (SP_ACTIVE_DOCUMENT->getObjectById(id) != NULL) { + LabelID.set_text (_("Id exists! ")); + } else { + SPException ex; + LabelID.set_markup_with_mnemonic(_("_ID:")); + SP_EXCEPTION_INIT (&ex); + item->setAttribute("id", id, &ex); + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, _("Set object ID")); + } + g_free (id); + + /* Retrieve the label widget for the object's label */ + Glib::ustring label = EntryLabel.get_text(); + g_assert(!label.empty()); + + /* Give feedback on success of setting the drawing object's label + * using the widget's label text + */ + SPObject *obj = (SPObject*)item; + if (label.compare (obj->defaultLabel())) { + obj->setLabel(label.c_str()); + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, + _("Set object label")); + } + + /* Retrieve the title */ + if (obj->setTitle(EntryTitle.get_text().c_str())) + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, + _("Set object title")); + + /* Retrieve the description */ + Gtk::TextBuffer::iterator start, end; + TextViewDescription.get_buffer()->get_bounds(start, end); + Glib::ustring desc = TextViewDescription.get_buffer()->get_text(start, end, TRUE); + if (obj->setDesc(desc.c_str())) + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, + _("Set object description")); + + blocked = false; +} + +void ObjectProperties::sensitivity_toggled (void) +{ + if (blocked) + { + return; + } + + SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + g_return_if_fail (item != NULL); + + blocked = true; + item->setLocked(CBLock.get_active()); + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, + CBLock.get_active()? _("Lock object") : _("Unlock object")); + blocked = false; +} + +void ObjectProperties::hidden_toggled(void) +{ + if (blocked) + { + return; + } + + SPItem *item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + g_return_if_fail (item != NULL); + + blocked = true; + item->setExplicitlyHidden(CBHide.get_active()); + DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, + CBHide.get_active()? _("Hide object") : _("Unhide object")); + blocked = false; +} + +/** + * ObjectProperties callback for the selection of an other object. + */ +void on_selection_changed(Inkscape::Application */*inkscape*/, Inkscape::Selection */*selection*/, ObjectProperties *dial) +{ + dial->widget_setup(); +} + +} +} +} + +/* + 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-properties.h b/src/ui/dialog/object-properties.h new file mode 100644 index 000000000..2f64e9158 --- /dev/null +++ b/src/ui/dialog/object-properties.h @@ -0,0 +1,110 @@ +/** @file + * \brief Display settings dialog + */ +/* Author: + * Lauris Kaplinski <lauris@ximian.com> + * Kris De Gussem <Kris.DeGussem@gmail.com> + * + * Copyright (C) 2001 Ximian, Inc. + * Copyright (C) 2011 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_DIALOGS_ITEM_PROPERTIES_H +#define SEEN_DIALOGS_ITEM_PROPERTIES_H + +#include <gtk/gtk.h> +#include <gtkmm.h> +#include <glibmm/i18n.h> + +#include "ui/widget/panel.h" +#include "../widgets/sp-attribute-widget.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * A dialog widget to show object properties. + * + * A widget to enter an ID, label, title and description for an object. + * In addition it allows to edit the properties of an object. + */ +class ObjectProperties : public Widget::Panel { +public: + ObjectProperties (); + ~ObjectProperties (); + + static ObjectProperties &getInstance() { return *new ObjectProperties(); } + + /** + * Updates entries and other child widgets on selection change, object modification, etc. + */ + void widget_setup(void); + +private: + bool blocked; + SPItem *CurrentItem; //to store the current item, for not wasting resources + std::vector<Glib::ustring> int_labels; + + Gtk::Table TopTable; //the table with the object properties + Gtk::Label LabelID; //the label for the object ID + Gtk::Entry EntryID; //the entry for the object ID + Gtk::Label LabelLabel; //the label for the object label + Gtk::Entry EntryLabel; //the entry for the object label + Gtk::Label LabelTitle; //the label for the object title + Gtk::Entry EntryTitle; //the entry for the object title + + Gtk::Label LabelDescription; //the label for the object description + Gtk::Frame FrameDescription; //the frame for the object description + Gtk::Frame FrameTextDescription; //the frame for the text of the object description + Gtk::TextView TextViewDescription; //the text view object showing the object description + + Gtk::HBox HBoxCheck; // the HBox for the check boxes + Gtk::Table CheckTable; //the table for the check boxes + Gtk::CheckButton CBHide; //the check button hide + Gtk::CheckButton CBLock; //the check button lock + Gtk::Button BSet; //the button set + + Gtk::Label LabelInteractivity; //the label for interactivity + Gtk::Expander EInteractivity; //the label for interactivity + SPAttributeTable attrTable; //the widget for showing the on... names at the bottom + + + /** + * Constructor auxiliary function creating the child widgets. + */ + void MakeWidget(void); + + /** + * Sets object properties (ID, label, title, description) on user input. + */ + void label_changed(void); + + /** + * Callback for checkbox Lock. + */ + void sensitivity_toggled (void); + + /** + * Callback for checkbox Hide. + */ + void hidden_toggled(void); +}; + +} +} +} + +#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 : |
