diff options
| author | John Smith <john.smith7545@yahoo.com> | 2012-11-30 12:11:42 +0000 |
|---|---|---|
| committer | John Smith <john.smith7545@yahoo.com> | 2012-11-30 12:11:42 +0000 |
| commit | b2b5252360d16fa3a1dd8cc172a2b7a09ba716e4 (patch) | |
| tree | 3da0e10d6e335e10eaa2f3ec145b948e7efa87e2 | |
| parent | Fix for 430301 : core dump exporting to non existing folder (diff) | |
| download | inkscape-b2b5252360d16fa3a1dd8cc172a2b7a09ba716e4.tar.gz inkscape-b2b5252360d16fa3a1dd8cc172a2b7a09ba716e4.zip | |
Fix for 255792 : Calligraphy tool presets management
(bzr r11916)
| -rw-r--r-- | src/preferences.cpp | 11 | ||||
| -rw-r--r-- | src/preferences.h | 7 | ||||
| -rw-r--r-- | src/ui/dialog/calligraphic-profile-rename.cpp | 39 | ||||
| -rw-r--r-- | src/ui/dialog/calligraphic-profile-rename.h | 8 | ||||
| -rw-r--r-- | src/widgets/calligraphy-toolbar.cpp | 85 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 1 |
6 files changed, 132 insertions, 19 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp index 1f985a629..3f12c4f64 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -504,6 +504,17 @@ void Preferences::mergeStyle(Glib::ustring const &pref_path, SPCSSAttr *style) sp_repr_css_attr_unref(current); } +/** + * Remove an entry + * Make sure observers have been removed before calling + */ +void Preferences::remove(Glib::ustring const &pref_path) +{ + Inkscape::XML::Node *node = _getNode(pref_path, false); + if (node && node->parent()) { + node->parent()->removeChild(node); + } +} /** * Class that holds additional information for registered Observers. diff --git a/src/preferences.h b/src/preferences.h index 5dcf4524d..66fa11542 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -503,6 +503,13 @@ public: static void unload(bool save=true); /*@}*/ + /** + * Remove a node from prefs + * @param pref_path Path to entry + * + */ + void remove(Glib::ustring const &pref_path); + protected: /* helper methods used by Entry * This will enable using the same Entry class with different backends. diff --git a/src/ui/dialog/calligraphic-profile-rename.cpp b/src/ui/dialog/calligraphic-profile-rename.cpp index c6633df0b..77a4f4f03 100644 --- a/src/ui/dialog/calligraphic-profile-rename.cpp +++ b/src/ui/dialog/calligraphic-profile-rename.cpp @@ -30,6 +30,8 @@ namespace Dialog { CalligraphicProfileRename::CalligraphicProfileRename() : _applied(false) { + set_title(_("Edit profile")); + Gtk::Box *mainVBox = get_vbox(); _layout_table.set_spacings(4); _layout_table.resize (1, 2); @@ -49,19 +51,27 @@ CalligraphicProfileRename::CalligraphicProfileRename() : _close_button.set_label(Gtk::Stock::CANCEL.id); _close_button.set_can_default(); + _delete_button.set_use_underline(true); + _delete_button.set_label(_("Delete")); + _delete_button.set_can_default(); + _delete_button.set_visible(false); + _apply_button.set_use_underline(true); _apply_button.set_label(_("Save")); _apply_button.set_can_default(); _close_button.signal_clicked() - .connect(sigc::mem_fun(*this, &CalligraphicProfileRename::_close)); + .connect(sigc::mem_fun(*this, &CalligraphicProfileRename::_close)); + _delete_button.signal_clicked() + .connect(sigc::mem_fun(*this, &CalligraphicProfileRename::_delete)); _apply_button.signal_clicked() - .connect(sigc::mem_fun(*this, &CalligraphicProfileRename::_apply)); + .connect(sigc::mem_fun(*this, &CalligraphicProfileRename::_apply)); signal_delete_event().connect( sigc::bind_return( sigc::hide(sigc::mem_fun(*this, &CalligraphicProfileRename::_close)), true ) ); add_action_widget(_close_button, Gtk::RESPONSE_CLOSE); + add_action_widget(_delete_button, Gtk::RESPONSE_DELETE_EVENT); add_action_widget(_apply_button, Gtk::RESPONSE_APPLY); _apply_button.grab_default(); @@ -73,6 +83,15 @@ void CalligraphicProfileRename::_apply() { _profile_name = _profile_name_entry.get_text(); _applied = true; + _deleted = false; + _close(); +} + +void CalligraphicProfileRename::_delete() +{ + _profile_name = _profile_name_entry.get_text(); + _applied = true; + _deleted = true; _close(); } @@ -81,11 +100,25 @@ void CalligraphicProfileRename::_close() this->Gtk::Dialog::hide(); } -void CalligraphicProfileRename::show(SPDesktop *desktop) +void CalligraphicProfileRename::show(SPDesktop *desktop, const Glib::ustring profile_name) { CalligraphicProfileRename &dial = instance(); dial._applied=false; + dial._deleted=false; dial.set_modal(true); + + dial._profile_name = profile_name; + dial._profile_name_entry.set_text(profile_name); + + if (profile_name.empty()) { + dial.set_title(_("Add profile")); + dial._delete_button.set_visible(false); + + } else { + dial.set_title(_("Edit profile")); + dial._delete_button.set_visible(true); + } + desktop->setWindowTransient (dial.gobj()); dial.property_destroy_with_parent() = true; // dial.Gtk::Dialog::show(); diff --git a/src/ui/dialog/calligraphic-profile-rename.h b/src/ui/dialog/calligraphic-profile-rename.h index f0eb0b491..8fe82d7bb 100644 --- a/src/ui/dialog/calligraphic-profile-rename.h +++ b/src/ui/dialog/calligraphic-profile-rename.h @@ -29,10 +29,13 @@ public: return "CalligraphicProfileRename"; } - static void show(SPDesktop *desktop); + static void show(SPDesktop *desktop, const Glib::ustring profile_name); static bool applied() { return instance()._applied; } + static bool deleted() { + return instance()._deleted; + } static Glib::ustring getProfileName() { return instance()._profile_name; } @@ -40,14 +43,17 @@ public: protected: void _close(); void _apply(); + void _delete(); Gtk::Label _profile_name_label; Gtk::Entry _profile_name_entry; Gtk::Table _layout_table; Gtk::Button _close_button; + Gtk::Button _delete_button; Gtk::Button _apply_button; Glib::ustring _profile_name; bool _applied; + bool _deleted; private: static CalligraphicProfileRename &instance() { static CalligraphicProfileRename instance_; diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index 1c39cd9e5..287deb815 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -74,6 +74,16 @@ using Inkscape::UI::PrefPusher; //######################## //## Calligraphy ## //######################## + +std::vector<Glib::ustring> get_presets_list() { + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset"); + + return presets; +} + void update_presets_list(GObject *tbl) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -88,7 +98,7 @@ void update_presets_list(GObject *tbl) return; } - std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector<Glib::ustring> presets = get_presets_list(); int ege_index = 1; for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i, ++ege_index) { @@ -233,22 +243,24 @@ static void sp_dcc_build_presets_list(GObject *tbl) // iterate over all presets to populate the list Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector<Glib::ustring> presets = get_presets_list(); int ii=1; for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i) { GtkTreeIter iter; Glib::ustring preset_name = prefs->getString(*i + "/name"); - gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, _(preset_name.data()), 1, ii++, -1 ); + if (!preset_name.empty()) { + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, 0, _(preset_name.data()), 1, ii++, -1 ); + } } - { +/* { GtkTreeIter iter; gtk_list_store_append( model, &iter ); gtk_list_store_set( model, &iter, 0, _("Save..."), 1, ii, -1 ); g_object_set_data(tbl, "save_presets_index", GINT_TO_POINTER(ii)); - } + }*/ g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE)); @@ -268,15 +280,25 @@ static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl) return; } - CalligraphicProfileRename::show(desktop); + EgeSelectOneAction *sel = static_cast<EgeSelectOneAction *>(g_object_get_data(tbl, "profile_selector")); + //gint preset_index = ege_select_one_action_get_active( sel ); + Glib::ustring current_profile_name = _("No preset"); + if (ege_select_one_action_get_active_text( sel )) { + current_profile_name = ege_select_one_action_get_active_text( sel ); + } + + if (current_profile_name == _("No preset")) { + current_profile_name = ""; + } + CalligraphicProfileRename::show(desktop, current_profile_name); if ( !CalligraphicProfileRename::applied()) { // dialog cancelled update_presets_list (tbl); return; } - Glib::ustring profile_name = CalligraphicProfileRename::getProfileName(); + Glib::ustring new_profile_name = CalligraphicProfileRename::getProfileName(); - if (profile_name.empty()) { + if (new_profile_name.empty()) { // empty name entered update_presets_list (tbl); return; @@ -285,7 +307,7 @@ static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl) g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(TRUE)); // If there's a preset with the given name, find it and set save_path appropriately - std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector<Glib::ustring> presets = get_presets_list(); int total_presets = presets.size(); int new_index = -1; Glib::ustring save_path; // profile pref path without a trailing slash @@ -293,13 +315,21 @@ static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl) int temp_index = 0; for (std::vector<Glib::ustring>::iterator i = presets.begin(); i != presets.end(); ++i, ++temp_index) { Glib::ustring name = prefs->getString(*i + "/name"); - if (!name.empty() && profile_name == name) { + if (!name.empty() && (new_profile_name == name || current_profile_name == name)) { new_index = temp_index; save_path = *i; break; } } + + if ( CalligraphicProfileRename::deleted() && new_index != -1) { + prefs->remove(save_path); + g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE)); + sp_dcc_build_presets_list (tbl); + return; + } + if (new_index == -1) { // no preset with this name, create new_index = total_presets + 1; @@ -327,7 +357,7 @@ static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl) g_warning("Bad key when writing preset: %s\n", widget_name); } } - prefs->setString(save_path + "/name", profile_name); + prefs->setString(save_path + "/name", new_profile_name); g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE)); sp_dcc_build_presets_list (tbl); @@ -338,7 +368,7 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint preset_index = ege_select_one_action_get_active( act ); + guint preset_index = ege_select_one_action_get_active( act ); // This is necessary because EgeSelectOneAction spams us with GObject "changed" signal calls // even when the preset is not changed. It would be good to replace it with something more // modern. Index 0 means "No preset", so we don't do anything. @@ -346,6 +376,7 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) return; } +/* gint save_presets_index = GPOINTER_TO_INT(g_object_get_data(tbl, "save_presets_index")); if (preset_index == save_presets_index) { @@ -353,14 +384,19 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) sp_dcc_save_profile(NULL, tbl); return; } +*/ if (g_object_get_data(tbl, "presets_blocked")) { return; } // preset_index is one-based so we subtract 1 - std::vector<Glib::ustring> presets = prefs->getAllDirs("/tools/calligraphic/preset"); - Glib::ustring preset_path = presets.at(preset_index - 1); + std::vector<Glib::ustring> presets = get_presets_list(); + + Glib::ustring preset_path = ""; + if (preset_index - 1 < presets.size()) { + preset_path = presets.at(preset_index - 1); + } if (!preset_path.empty()) { g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(TRUE)); //temporarily block the selector so no one will updadte it while we're reading it @@ -391,9 +427,16 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) } } g_object_set_data(tbl, "presets_blocked", GINT_TO_POINTER(FALSE)); + } else { + ege_select_one_action_set_active(act, 0); } } +static void sp_ddc_edit_profile(GtkAction * /*act*/, GObject* tbl) +{ + sp_dcc_save_profile(NULL, tbl); +} + void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -595,6 +638,18 @@ void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions g_signal_connect(G_OBJECT(act1), "changed", G_CALLBACK(sp_ddc_change_profile), holder); gtk_action_group_add_action(mainActions, GTK_ACTION(act1)); } + + /*calligraphic profile editor */ + { + InkAction* inky = ink_action_new( "ProfileEditAction", + _("Add/Edit Profile"), + _("Add or edit calligraphic profile"), + GTK_STOCK_PROPERTIES, + Inkscape::ICON_SIZE_DECORATION ); + g_object_set( inky, "short_label", _("Edit"), NULL ); + g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_ddc_edit_profile), (GObject*)holder ); + gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); + } } } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index b758e4f0f..a5e929c7d 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -407,6 +407,7 @@ static gchar const * ui_descr = " <toolbar name='CalligraphyToolbar'>" " <separator />" " <toolitem action='SetProfileAction'/>" + " <toolitem action='ProfileEditAction'/>" " <separator />" " <toolitem action='CalligraphyWidthAction' />" " <toolitem action='PressureAction' />" |
