@@ -2109,7 +2109,6 @@ void MainWindow::onToolbarContextMenuRequested(const QPoint& pos)
21092109 const std::string active_buttons_str =
21102110 Host::GetBaseStringSettingValue (" UI" , " ToolbarButtons" , DEFAULT_TOOLBAR_ACTIONS);
21112111 std::vector<std::string_view> active_buttons = StringUtil::SplitString (active_buttons_str, ' ,' );
2112- bool active_buttons_changed = false ;
21132112
21142113 QMenu* const menu = QtUtils::NewPopupMenu (this );
21152114
@@ -2160,25 +2159,22 @@ void MainWindow::onToolbarContextMenuRequested(const QPoint& pos)
21602159 QAction* menu_action = menu->addAction ((m_ui.*action_ptr)->text ());
21612160 menu_action->setCheckable (true );
21622161 menu_action->setChecked (StringUtil::IsInStringList (active_buttons, name));
2163- connect (menu_action, &QAction::toggled, this , [&active_buttons, &active_buttons_changed, name](bool checked) {
2164- if (checked)
2165- StringUtil::AddToStringList (active_buttons, name);
2166- else
2167- StringUtil::RemoveFromStringList (active_buttons, name);
2168- active_buttons_changed = true ;
2162+ connect (menu_action, &QAction::toggled, this , [this , name](bool checked) {
2163+ const std::string active_buttons_str =
2164+ Host::GetBaseStringSettingValue (" UI" , " ToolbarButtons" , DEFAULT_TOOLBAR_ACTIONS);
2165+ std::vector<std::string_view> active_buttons = StringUtil::SplitString (active_buttons_str, ' ,' );
2166+ if (checked ? StringUtil::AddToStringList (active_buttons, name) :
2167+ StringUtil::RemoveFromStringList (active_buttons, name))
2168+ {
2169+ Host::SetBaseStringSettingValue (" UI" , " ToolbarButtons" , StringUtil::JoinString (active_buttons, ' ,' ).c_str ());
2170+ Host::CommitBaseSettingChanges ();
2171+ updateToolbarActions ();
2172+ }
21692173 });
21702174 }
21712175
21722176 menu->popup (m_ui.toolBar ->mapToGlobal (pos));
2173-
2174- if (active_buttons_changed)
2175- {
2176- Host::SetBaseStringSettingValue (" UI" , " ToolbarButtons" , StringUtil::JoinString (active_buttons, ' ,' ).c_str ());
2177- Host::CommitBaseSettingChanges ();
2178- }
21792177 }
2180-
2181- updateToolbarActions ();
21822178}
21832179
21842180void MainWindow::onToolbarTopLevelChanged (bool top_level)
0 commit comments