=== modified file 'src/ui/dialog/calligraphic-profile-rename.cpp' --- src/ui/dialog/calligraphic-profile-rename.cpp 2012-04-28 15:49:30 +0000 +++ src/ui/dialog/calligraphic-profile-rename.cpp 2012-11-03 01:45:06 +0000 @@ -30,6 +30,8 @@ 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 @@ _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 @@ { _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 @@ 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(); === modified file 'src/ui/dialog/calligraphic-profile-rename.h' --- src/ui/dialog/calligraphic-profile-rename.h 2011-12-11 23:10:01 +0000 +++ src/ui/dialog/calligraphic-profile-rename.h 2012-11-03 01:38:35 +0000 @@ -29,10 +29,13 @@ 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 @@ 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_; === modified file 'src/widgets/calligraphy-toolbar.cpp' --- src/widgets/calligraphy-toolbar.cpp 2012-06-17 07:08:03 +0000 +++ src/widgets/calligraphy-toolbar.cpp 2012-11-03 09:47:01 +0000 @@ -74,6 +74,25 @@ //######################## //## Calligraphy ## //######################## + +std::vector get_presets_list() { + + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + std::vector presets = prefs->getAllDirs("/tools/calligraphic/preset"); + + // Remove any presets with an empty name (assume they have been 'deleted') + for (std::vector::iterator i = presets.begin(); i != presets.end(); ++i) { + Glib::ustring preset_name = prefs->getString(*i + "/name"); + if (preset_name.empty()) { + presets.erase(i); + i = presets.begin(); + } + } + + return presets; +} + void update_presets_list(GObject *tbl) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -88,7 +107,7 @@ return; } - std::vector presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector presets = get_presets_list(); int ege_index = 1; for (std::vector::iterator i = presets.begin(); i != presets.end(); ++i, ++ege_index) { @@ -233,22 +252,24 @@ // iterate over all presets to populate the list Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - std::vector presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector presets = get_presets_list(); int ii=1; for (std::vector::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 +289,25 @@ return; } - CalligraphicProfileRename::show(desktop); + EgeSelectOneAction *sel = static_cast(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 +316,7 @@ 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 presets = prefs->getAllDirs("/tools/calligraphic/preset"); + std::vector 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 +324,22 @@ int temp_index = 0; for (std::vector::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) { + // Since there is no "delete pref", set name to "" and ignore everywhere + prefs->setString(save_path + "/name", ""); + 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 +367,7 @@ 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); @@ -346,6 +386,7 @@ return; } +/* gint save_presets_index = GPOINTER_TO_INT(g_object_get_data(tbl, "save_presets_index")); if (preset_index == save_presets_index) { @@ -353,14 +394,19 @@ 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 presets = prefs->getAllDirs("/tools/calligraphic/preset"); - Glib::ustring preset_path = presets.at(preset_index - 1); + std::vector 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 +437,16 @@ } } 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 +648,18 @@ 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) ); + } } } === modified file 'src/widgets/toolbox.cpp' --- src/widgets/toolbox.cpp 2012-10-20 18:19:03 +0000 +++ src/widgets/toolbox.cpp 2012-11-03 00:45:41 +0000 @@ -407,6 +407,7 @@ " " " " " " + " " " " " " " "