From 283d25ef6f35973282e27af10e4075c66c9c8a8e Mon Sep 17 00:00:00 2001 From: JucaBlues Date: Mon, 24 Nov 2008 00:20:25 +0000 Subject: [PATCH] adding "remove" context menu in the embedded color profiles box --- src/ui/dialog/document-properties.cpp | 145 +++++++++++++++++++------- src/ui/dialog/document-properties.h | 26 +++++ src/verbs.cpp | 10 ++ src/verbs.h | 7 +- 4 files changed, 146 insertions(+), 42 deletions(-) diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index acf4dbb54..e47630615 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -19,30 +19,25 @@ # include #endif - - +#include "display/canvas-grid.h" +#include "document-properties.h" +#include "document.h" +#include "desktop-handles.h" +#include "desktop.h" #include -#include "ui/widget/color-picker.h" -#include "ui/widget/scalar-unit.h" - -#include "xml/node-event-vector.h" -#include "xml/repr.h" #include "helper/units.h" -#include "preferences.h" - #include "inkscape.h" #include "io/sys.h" -#include "verbs.h" -#include "document.h" -#include "desktop-handles.h" -#include "desktop.h" +#include "preferences.h" #include "sp-namedview.h" #include "sp-object-repr.h" #include "sp-root.h" +#include "ui/widget/color-picker.h" +#include "ui/widget/scalar-unit.h" +#include "verbs.h" #include "widgets/icon.h" -#include "document-properties.h" - -#include "display/canvas-grid.h" +#include "xml/node-event-vector.h" +#include "xml/repr.h" #if ENABLE_LCMS #include @@ -391,6 +386,42 @@ DocumentProperties::build_snap_dtls() attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array)); } +// Very simple observer that just emits a signal if anything happens to a node +DocumentProperties::SignalObserver::SignalObserver() + : _oldsel(0) +{} + +// Add this observer to the SPObject and remove it from any previous object +void +DocumentProperties::SignalObserver::set(SPObject* o) +{ + if(_oldsel && _oldsel->repr) + _oldsel->repr->removeObserver(*this); + if(o && o->repr) + o->repr->addObserver(*this); + _oldsel = o; +} + +void DocumentProperties::SignalObserver::notifyChildAdded(XML::Node&, XML::Node&, XML::Node*) +{ signal_changed()(); } + +void DocumentProperties::SignalObserver::notifyChildRemoved(XML::Node&, XML::Node&, XML::Node*) +{ signal_changed()(); } + +void DocumentProperties::SignalObserver::notifyChildOrderChanged(XML::Node&, XML::Node&, XML::Node*, XML::Node*) +{ signal_changed()(); } + +void DocumentProperties::SignalObserver::notifyContentChanged(XML::Node&, Util::ptr_shared, Util::ptr_shared) +{} + +void DocumentProperties::SignalObserver::notifyAttributeChanged(XML::Node&, GQuark, Util::ptr_shared, Util::ptr_shared) +{ signal_changed()(); } + +sigc::signal& DocumentProperties::SignalObserver::signal_changed() +{ + return _signal_changed; +} + #if ENABLE_LCMS static void lcms_profile_get_name (cmsHPROFILE profile, const gchar **name) @@ -414,26 +445,6 @@ lcms_profile_get_name (cmsHPROFILE profile, const gchar **name) void DocumentProperties::populate_available_profiles(){ - // add "None" -/* Gtk::MenuItem *i = new Gtk::MenuItem(); - i->show(); - - i->set_data("filepath", NULL); - i->set_data("name", _("None")); - - Gtk::HBox *hb = new Gtk::HBox(false, 0); - hb->show(); - - Gtk::Label *l = new Gtk::Label( _("None") ); - l->show(); - l->set_alignment(0.0, 0.5); - - hb->pack_start(*l, true, true, 0); - - hb->show(); - i->add(*hb); - _menu.append(*i); -*/ std::list sources; sources.push_back( profile_path("color/icc") ); //sources.push_back( g_strdup(INKSCAPE_COLORPROFILESDIR) ); @@ -519,7 +530,7 @@ DocumentProperties::onEmbedProfile() Inkscape::GC::release(defsRepr); // inform the document, so we can undo - sp_document_done(desktop->doc(), SP_VERB_EMBED_COLOR_PROFILE, _("Embed Color Profile")); + sp_document_done(desktop->doc(), SP_VERB_EDIT_EMBED_COLOR_PROFILE, _("Embed Color Profile")); populate_embedded_profiles_box(); } @@ -529,6 +540,7 @@ DocumentProperties::populate_embedded_profiles_box() { _EmbeddedProfilesListStore->clear(); const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" ); + if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent); while ( current ) { SPObject* obj = SP_OBJECT(current->data); Inkscape::ColorProfile* prof = reinterpret_cast(obj); @@ -539,6 +551,47 @@ DocumentProperties::populate_embedded_profiles_box() } } +void DocumentProperties::embedded_profiles_list_button_release(GdkEventButton* event) +{ + if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) { + _EmbProfContextMenu.popup(event->button, event->time); + } +} + +void DocumentProperties::create_popup_menu(Gtk::Widget& parent, sigc::slot rem) +{ + Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE)); + _EmbProfContextMenu.append(*mi); + mi->signal_activate().connect(rem); + mi->show(); + _EmbProfContextMenu.accelerate(parent); +} + +void DocumentProperties::remove_profile(){ + Glib::ustring name; + if(_EmbeddedProfilesList.get_selection()) { + Gtk::TreeModel::iterator i = _EmbeddedProfilesList.get_selection()->get_selected(); + + if(i){ + name = (*i)[_EmbeddedProfilesListColumns.nameColumn]; + } else { + return; + } + } + + const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" ); + while ( current ) { + SPObject* obj = SP_OBJECT(current->data); + Inkscape::ColorProfile* prof = reinterpret_cast(obj); + if (!name.compare(prof->name)){ + sp_repr_unparent(obj->repr); + sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove embedded color profile")); + } + current = g_slist_next(current); + } + + populate_embedded_profiles_box(); +} void DocumentProperties::build_cms() @@ -584,6 +637,13 @@ DocumentProperties::build_cms() _EmbeddedProfilesListScroller.set_size_request(-1, 90); _embed_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onEmbedProfile)); + + _EmbeddedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::embedded_profiles_list_button_release)); + create_popup_menu(_EmbeddedProfilesList, sigc::mem_fun(*this, &DocumentProperties::remove_profile)); + + const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "defs" ); + if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent); + _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_embedded_profiles_box)); } #endif // ENABLE_LCMS @@ -695,12 +755,13 @@ DocumentProperties::update() double const doc_h_px = sp_document_height(sp_desktop_document(dt)); _page_sizer.setDim (doc_w_px, doc_h_px); - //-----------------------------------------------------------guide + //-----------------------------------------------------------guide page + _rcb_sgui.setActive (nv->showguides); _rcp_gui.setRgba32 (nv->guidecolor); _rcp_hgui.setRgba32 (nv->guidehicolor); - //-----------------------------------------------------------snap + //-----------------------------------------------------------snap page _rcbsnbb.setActive (nv->snap_manager.snapprefs.getSnapModeBBox()); _rcbsnn.setActive (nv->snap_manager.snapprefs.getSnapModeNode()); @@ -721,10 +782,16 @@ DocumentProperties::update() _rsu_gusn.setValue (nv->guidetolerance); _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally()); + //-----------------------------------------------------------grids page update_gridspage(); + //------------------------------------------------Color Management page + + populate_embedded_profiles_box(); + populate_available_profiles(); + _wr.setUpdating (false); } diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index ff4739bfb..162618c05 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -26,6 +26,8 @@ #include "ui/widget/tolerance-slider.h" #include "ui/widget/panel.h" +#include "xml/node-observer.h" + using namespace Inkscape::UI::Widget; namespace Inkscape { @@ -59,11 +61,34 @@ protected: void populate_embedded_profiles_box(); virtual void on_response (int); void onEmbedProfile(); + void remove_profile(); + void embedded_profiles_list_button_release(GdkEventButton* event); + void create_popup_menu(Gtk::Widget& parent, sigc::slot rem); void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); void _handleActivateDesktop(Inkscape::Application *application, SPDesktop *desktop); void _handleDeactivateDesktop(Inkscape::Application *application, SPDesktop *desktop); + // Very simple observer that just emits a signal if anything happens to a node + class SignalObserver : public XML::NodeObserver + { + public: + SignalObserver(); + + // Add this observer to the SPObject and remove it from any previous object + void set(SPObject* o); + void notifyChildAdded(XML::Node&, XML::Node&, XML::Node*); + void notifyChildRemoved(XML::Node&, XML::Node&, XML::Node*); + void notifyChildOrderChanged(XML::Node&, XML::Node&, XML::Node*, XML::Node*); + void notifyContentChanged(XML::Node&, Util::ptr_shared, Util::ptr_shared); + void notifyAttributeChanged(XML::Node&, GQuark, Util::ptr_shared, Util::ptr_shared); + sigc::signal& signal_changed(); + private: + sigc::signal _signal_changed; + SPObject* _oldsel; + }; + + SignalObserver _emb_profiles_observer; Gtk::Tooltips _tt; Gtk::Notebook _notebook; @@ -103,6 +128,7 @@ protected: Glib::RefPtr _EmbeddedProfilesListStore; Gtk::TreeView _EmbeddedProfilesList; Gtk::ScrolledWindow _EmbeddedProfilesListScroller; + Gtk::Menu _EmbProfContextMenu; //--------------------------------------------------------------- Gtk::Notebook _grids_notebook; Gtk::HBox _grids_hbox_crea; diff --git a/src/verbs.cpp b/src/verbs.cpp index 4ddf58957..17fd00421 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -69,6 +69,7 @@ #include "path-chemistry.h" #include "text-chemistry.h" #include "ui/dialog/dialog-manager.h" +#include "ui/dialog/document-properties.h" #include "ui/dialog/inkscape-preferences.h" #include "interface.h" #include "preferences.h" @@ -983,6 +984,10 @@ EditVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_EDIT_NEXT_PATHEFFECT_PARAMETER: sp_selection_next_patheffect_param(dt); break; + case SP_VERB_EDIT_EMBED_COLOR_PROFILE: + break; + case SP_VERB_EDIT_REMOVE_COLOR_PROFILE: + break; default: break; } @@ -2707,6 +2712,11 @@ Verb *Verb::_base_verbs[] = { N_("Unhide all objects in the current layer"), NULL), new LockAndHideVerb(SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, "UnhideAllInAllLayers", N_("Unhide All in All Layers"), N_("Unhide all objects in all layers"), NULL), + /*Color Management*/ + new EditVerb(SP_VERB_EDIT_EMBED_COLOR_PROFILE, "EmbedColorProfile", N_("Embed Color Profile"), + N_("Embed an ICC color profile"), NULL), + new EditVerb(SP_VERB_EDIT_REMOVE_COLOR_PROFILE, "RemoveColorProfile", N_("Remove Color Profile"), + N_("Remove an embedded ICC color profile"), NULL), /* Footer */ new Verb(SP_VERB_LAST, " '\"invalid id", NULL, NULL, NULL) }; diff --git a/src/verbs.h b/src/verbs.h index 2bee018c5..a1f96ab5a 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -271,10 +271,11 @@ enum { SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS, SP_VERB_UNHIDE_ALL, SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, - /* Footer */ - SP_VERB_LAST, /* Color management */ - SP_VERB_EMBED_COLOR_PROFILE, + SP_VERB_EDIT_EMBED_COLOR_PROFILE, + SP_VERB_EDIT_REMOVE_COLOR_PROFILE, + /* Footer */ + SP_VERB_LAST }; gchar *sp_action_get_title (const SPAction *action); -- 2.30.2