Store last activ style index into configuration
This commit is contained in:
parent
41aaa13ce7
commit
fa773f09d3
@ -25,7 +25,10 @@ EmbossStyleManager::EmbossStyleManager(const ImWchar *language_glyph_range)
|
|||||||
EmbossStyleManager::~EmbossStyleManager() {
|
EmbossStyleManager::~EmbossStyleManager() {
|
||||||
clear_imgui_font();
|
clear_imgui_font();
|
||||||
free_style_images();
|
free_style_images();
|
||||||
store_styles_to_app_config(false);
|
store_styles_to_app_config(false, false);
|
||||||
|
if (m_app_config != nullptr &&
|
||||||
|
m_last_style_index != std::numeric_limits<size_t>::max())
|
||||||
|
EmbossStylesSerializable::store_style_index(*m_app_config, m_last_style_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmbossStyleManager::init(AppConfig *app_config, const EmbossStyles &default_styles)
|
void EmbossStyleManager::init(AppConfig *app_config, const EmbossStyles &default_styles)
|
||||||
@ -68,7 +71,8 @@ void EmbossStyleManager::init(AppConfig *app_config, const EmbossStyles &default
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EmbossStyleManager::store_styles_to_app_config(bool use_modification)
|
bool EmbossStyleManager::store_styles_to_app_config(bool use_modification,
|
||||||
|
bool store_activ_index)
|
||||||
{
|
{
|
||||||
assert(m_app_config != nullptr);
|
assert(m_app_config != nullptr);
|
||||||
if (m_app_config == nullptr) return false;
|
if (m_app_config == nullptr) return false;
|
||||||
@ -80,13 +84,15 @@ bool EmbossStyleManager::store_styles_to_app_config(bool use_modification)
|
|||||||
// add new into stored list
|
// add new into stored list
|
||||||
EmbossStyle &style = m_style_cache.style;
|
EmbossStyle &style = m_style_cache.style;
|
||||||
make_unique_name(style.name);
|
make_unique_name(style.name);
|
||||||
|
m_style_cache.truncated_name.clear();
|
||||||
m_style_cache.style_index = m_style_items.size();
|
m_style_cache.style_index = m_style_items.size();
|
||||||
m_style_items.push_back({style});
|
m_style_items.push_back({style});
|
||||||
m_style_cache.stored_wx_font = m_style_cache.wx_font;
|
m_style_cache.stored_wx_font = m_style_cache.wx_font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (store_activ_index)
|
||||||
EmbossStylesSerializable::store_style_index(*m_app_config, m_style_cache.style_index);
|
EmbossStylesSerializable::store_style_index(*m_app_config, m_style_cache.style_index);
|
||||||
|
|
||||||
EmbossStyles styles;
|
EmbossStyles styles;
|
||||||
styles.reserve(m_style_items.size());
|
styles.reserve(m_style_items.size());
|
||||||
for (const Item &item : m_style_items) styles.push_back(item.style);
|
for (const Item &item : m_style_items) styles.push_back(item.style);
|
||||||
@ -118,8 +124,13 @@ void EmbossStyleManager::swap(size_t i1, size_t i2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmbossStyleManager::discard_style_changes() {
|
void EmbossStyleManager::discard_style_changes() {
|
||||||
if (exist_stored_style() && load_style(m_style_cache.style_index))
|
if (exist_stored_style()) {
|
||||||
|
if (load_style(m_style_cache.style_index))
|
||||||
return; // correct reload style
|
return; // correct reload style
|
||||||
|
} else {
|
||||||
|
if(load_style(m_last_style_index))
|
||||||
|
return; // correct load last used style
|
||||||
|
}
|
||||||
|
|
||||||
// try to save situation by load some font
|
// try to save situation by load some font
|
||||||
load_first_valid_font();
|
load_first_valid_font();
|
||||||
|
@ -44,9 +44,10 @@ public:
|
|||||||
/// Write font list into AppConfig
|
/// Write font list into AppConfig
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item_to_store">Configuration</param>
|
/// <param name="item_to_store">Configuration</param>
|
||||||
/// <param name="use_modification">Flag that store should use actual modification</param>
|
/// <param name="use_modification">When true cache state will be used for store</param>
|
||||||
|
/// <param name="use_modification">When true store activ index into configuration</param>
|
||||||
/// <returns>True on succes otherwise False.</returns>
|
/// <returns>True on succes otherwise False.</returns>
|
||||||
bool store_styles_to_app_config(bool use_modification = true);
|
bool store_styles_to_app_config(bool use_modification = true, bool store_activ_index = true);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Append actual style to style list
|
/// Append actual style to style list
|
||||||
|
Loading…
Reference in New Issue
Block a user