diff --git a/src/actions/actions-tools.cpp b/src/actions/actions-tools.cpp index 83a2efa1e035fcd002d022d0792222c751502077..d0582440edc907b912bdfa79d96ae7be676b8080 100644 --- a/src/actions/actions-tools.cpp +++ b/src/actions/actions-tools.cpp @@ -13,6 +13,7 @@ #include "actions-tools.h" #include "actions-helper.h" +#include "desktop-style.h" #include "inkscape-application.h" #include "inkscape-window.h" @@ -163,6 +164,45 @@ tool_switch(Glib::ustring const &tool, InkscapeWindow *win) saction->change_state(tool); saction->set_enabled(true); + // Save current tool style. + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + SPCSSAttr *css = sp_desktop_get_style(dt, true); + int old_usecurrent = prefs->getInt(tool_data.at(current_tool).pref_path + "/usecurrent"); + switch (old_usecurrent) + { + case 2: + { + prefs->setStyle(tool_data.at(current_tool).pref_path + "/style", css); + break; + } + case 1: + { + prefs->setStyle("/tools/style", css); + break; + } + default: + break; + } + + // Load style of new tool. + int new_usecurrent = prefs->getInt(tool_data.at(tool).pref_path + "/usecurrent"); + switch (new_usecurrent) { + case 2: + { + SPCSSAttr *newcss = prefs->getInheritedStyle(tool_data.at(tool).pref_path + "/style"); + sp_desktop_set_style(dt, newcss, false, true, true); + break; + } + case 1: + { + SPCSSAttr *newcss = prefs->getStyle("/tools/style"); + sp_desktop_set_style(dt, newcss, false, true, true); + break; + } + default: + break; + } + // Switch to new tool. TODO: Clean this up. This should be one window function. // Setting tool via preference path is a bit strange. diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index ce09066081df53684acf4bf6e886054fdf7bf563..04eea418ecb239a2afcb65e60389f0e4c60ab81a 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -288,7 +288,7 @@ sp_desktop_get_master_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool gfloat value = 1.0; // default if nothing else found if (has_opacity) *has_opacity = false; - if (prefs->getBool(tool + "/usecurrent")) { + if (prefs->getInt(tool + "/usecurrent") != 0) { css = sp_desktop_get_style(desktop, true); } else { css = prefs->getStyle(tool + "/style"); @@ -317,7 +317,7 @@ sp_desktop_get_opacity_tool(SPDesktop *desktop, Glib::ustring const &tool, bool Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPCSSAttr *css = nullptr; gfloat value = 1.0; // default if nothing else found - if (prefs->getBool(tool + "/usecurrent")) { + if (prefs->getInt(tool + "/usecurrent") != 0) { css = sp_desktop_get_style(desktop, true); } else { css = prefs->getStyle(tool + "/style"); @@ -343,7 +343,7 @@ sp_desktop_get_color_tool(SPDesktop *desktop, Glib::ustring const &tool, bool is { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPCSSAttr *css = nullptr; - bool styleFromCurrent = prefs->getBool(tool + "/usecurrent"); + bool styleFromCurrent = prefs->getInt(tool + "/usecurrent") != 0; if (styleFromCurrent) { css = sp_desktop_get_style(desktop, true); } else { @@ -370,7 +370,7 @@ sp_desktop_apply_style_tool(SPDesktop *desktop, Inkscape::XML::Node *repr, Glib: SPCSSAttr *css_current = sp_desktop_get_style(desktop, with_text); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool(tool_path + "/usecurrent") && css_current) { + if (prefs->getInt(tool_path + "/usecurrent") != 0 && css_current) { sp_repr_css_unset_property(css_current, "shape-inside"); sp_repr_css_unset_property(css_current, "shape-subtract"); sp_repr_css_unset_property(css_current, "mix-blend-mode"); @@ -401,7 +401,7 @@ sp_desktop_get_font_size_tool(SPDesktop *desktop) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring desktop_style = prefs->getString("/desktop/style"); Glib::ustring style_str; - if ((prefs->getBool("/tools/text/usecurrent")) && !desktop_style.empty()) { + if ((prefs->getInt("/tools/text/usecurrent") != 0) && !desktop_style.empty()) { style_str = desktop_style; } else { style_str = prefs->getString("/tools/text/style"); diff --git a/src/desktop.cpp b/src/desktop.cpp index 7abd51c830883fcbfefbc9be61a2bc0a44390135..5abb1b9dec677cd86a1c82e78445231efbbb4638 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1112,7 +1112,7 @@ void SPDesktop::applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool SPCSSAttr *css_current = sp_desktop_get_style(this, with_text); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool(tool_path + "/usecurrent") && css_current) { + if (prefs->getInt(tool_path + "/usecurrent") != 0 && css_current) { obj->setCSS(css_current,"style"); } else { SPCSSAttr *css = prefs->getInheritedStyle(tool_path + "/style"); diff --git a/src/libnrtype/font-lister.cpp b/src/libnrtype/font-lister.cpp index 071b3243fdde17b480a85a1b2b53f0311cc25328..67c9b67e644a95bf08cc69818f6c62ed87281129 100644 --- a/src/libnrtype/font-lister.cpp +++ b/src/libnrtype/font-lister.cpp @@ -716,7 +716,7 @@ std::pair FontLister::selection_update() // From preferences if (fontspec.empty()) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/text/usecurrent")) { + if (prefs->getInt("/tools/text/usecurrent") != 0) { query.mergeCSS(sp_desktop_get_style(SP_ACTIVE_DESKTOP, true)); } else { query.readFromPrefs("/tools/text"); diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 0f2ec97f40b18ccf420981f7f3319e66b0b26bfc..2b6f4911393a187ac8f52db80c7a13f1773c51d1 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -119,7 +119,7 @@ static char const preferences_skeleton[] = - diff --git a/src/preferences.cpp b/src/preferences.cpp index 914a0bbb5af6b671967993cb025e5e5dd8bd2590..700cd4e82e802929fa515ecb3738026455db22c4 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -70,6 +70,7 @@ Preferences::Preferences() _loadDefaults(); _load(); + _applyMigrations(); _initialized = true; } @@ -156,6 +157,7 @@ void Preferences::_load() return; } + // XXX When will this be true? if ( migrateFromDoc ) { migrateDetails( migrateFromDoc, _prefs_doc ); } @@ -226,6 +228,19 @@ static Inkscape::XML::Document *loadImpl( std::string const& prefsFilename, Glib return prefs_read; } +/** + * Apply migrations to the preferences, and set migrate status to 1 when done. + */ +void Preferences::_applyMigrations() +{ + // 20250625: Migrate text style application to 2 (tool-specific style). + if (!getBool("/migrations/textToolOwnStyle", false)) { + setInt("/tools/text/usecurrent", 2); + setBool("/migrations/textToolOwnStyle", true); + } +} + +// XXX Are there any code path that reaches here? static void migrateDetails( Inkscape::XML::Document *from, Inkscape::XML::Document *to ) { // TODO pull in additional prefs with more granularity @@ -284,6 +299,7 @@ void Preferences::reset() _prefs_doc = nullptr; _loadDefaults(); _load(); + _applyMigrations(); save(); } diff --git a/src/preferences.h b/src/preferences.h index b98139f3da7cbbc4ea7f912becc54d235196b21f..4bd4028b58e069cfaf7da904902c190688fdcd8d 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -735,6 +735,7 @@ private: ~Preferences(); void _loadDefaults(); void _load(); + void _applyMigrations(); std::optional _getRawValue(Glib::ustring const &path); void _setRawValue(Glib::ustring const &path, Glib::ustring const &value); void _reportError(Glib::ustring const &, Glib::ustring const &); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 799500fdd32395cafe445527dcb3465383962a8c..d72cb5741ab7be097618d273d121542bc051e5df 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -867,13 +867,17 @@ void InkscapePreferences::AddNewObjectsStyle(DialogPage &p, Glib::ustring const _("Apply the style you last set on an object")); auto const own = Gtk::make_managed(); + own->init ( _("This tool's last used style"), prefs_path + "/usecurrent", 2, false, current); + p.add_line( true, "", *own, "", _("Apply the style you last set with the tool")); + + auto const fixed = Gtk::make_managed(); auto const hb = Gtk::make_managed(); - own->init ( _("This tool's own style:"), prefs_path + "/usecurrent", 0, false, current); - own->set_halign(Gtk::Align::START); - own->set_valign(Gtk::Align::START); - hb->append(*own); + fixed->init ( _("Fixed style:"), prefs_path + "/usecurrent", 0, false, current); + fixed->set_halign(Gtk::Align::START); + fixed->set_valign(Gtk::Align::START); + hb->append(*fixed); - p.set_tip( *own, _("Each tool may store its own style to apply to the newly created objects. Use the button below to set it.")); + p.set_tip( *fixed, _("Each tool may store its own style to apply to the newly created objects. Use the button below to set it.")); p.add_line( true, "", *hb, "", ""); // style swatch @@ -881,7 +885,7 @@ void InkscapePreferences::AddNewObjectsStyle(DialogPage &p, Glib::ustring const StyleSwatch *swatch = nullptr; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getInt(prefs_path + "/usecurrent")) { + if (prefs->getInt(prefs_path + "/usecurrent") != 0) { button->set_sensitive(false); } @@ -891,7 +895,7 @@ void InkscapePreferences::AddNewObjectsStyle(DialogPage &p, Glib::ustring const sp_repr_css_attr_unref(css); button->signal_clicked().connect(sigc::bind(&StyleFromSelectionToTool, prefs_path, swatch)); - own->changed_signal.connect( sigc::mem_fun(*button, &Gtk::Button::set_sensitive) ); + fixed->changed_signal.connect( sigc::mem_fun(*button, &Gtk::Button::set_sensitive) ); p.add_line( true, "", *button, "", _("Remember the style of the (first) selected object as this tool's style")); } diff --git a/src/ui/toolbar/text-toolbar.cpp b/src/ui/toolbar/text-toolbar.cpp index 3268640395d14b66b27b3c7dc13527058d6b48ee..b8db0176fbc969505e3f19d9edc053a7052b057d 100644 --- a/src/ui/toolbar/text-toolbar.cpp +++ b/src/ui/toolbar/text-toolbar.cpp @@ -1536,7 +1536,7 @@ void TextToolbar::_selectionChanged(Selection *selection) // don't bother to upd result_wmode == QUERY_STYLE_NOTHING) { // There are no texts in selection, read from preferences. - if (prefs->getBool("/tools/text/usecurrent")) { + if (prefs->getInt("/tools/text/usecurrent") != 0) { query.mergeCSS(sp_desktop_get_style(desktop, true)); } else { query.readFromPrefs("/tools/text"); diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index 65228d319a0b23195f221ea1fd4ac3af971059b0..d690dfacad63062995713fb846c0c6d3dbc9c1d7 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -457,7 +457,7 @@ void Box3dTool::drag() Glib::ustring cur_style = prefs->getString(descr); - bool use_current = prefs->getBool("/tools/shapes/3dbox/usecurrent", false); + bool use_current = prefs->getInt("/tools/shapes/3dbox/usecurrent", false) != 0; if (use_current && !cur_style.empty()) { // use last used style diff --git a/src/ui/widget/style-swatch.cpp b/src/ui/widget/style-swatch.cpp index bc8c75a7e1d4842c03d2259e80996cbeb6dc9871..c71b9f6ca656827145dd2fd84cf125da678f834d 100644 --- a/src/ui/widget/style-swatch.cpp +++ b/src/ui/widget/style-swatch.cpp @@ -64,7 +64,7 @@ void tool_obs_callback(StyleSwatch &_style_swatch, Preferences::Entry const &val Glib::ustring path; SPCSSAttr *css = nullptr; - bool usecurrent = val.getBool(); + bool usecurrent = val.getInt() != 0; if (usecurrent) { path = "/desktop/style"; css = prefs->getStyle(path);