Skip to content

Commit

Permalink
preferences dialog, emphasizing overridden keyboard shortcuts (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuspen committed Dec 11, 2023
1 parent 7094576 commit 8ed3768
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/ct/ct_menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ static void on_menu_activate(void* /*pObject*/, CtMenuAction* pAction)

const std::string& CtMenuAction::get_shortcut(CtConfig* pCtConfig) const
{
auto it = pCtConfig->customKbShortcuts.find(id);
const auto it = pCtConfig->customKbShortcuts.find(id);
return it != pCtConfig->customKbShortcuts.end() ? it->second : built_in_shortcut;
}

bool CtMenuAction::is_shortcut_overridden(CtConfig* pCtConfig) const
{
const auto it = pCtConfig->customKbShortcuts.find(id);
if (pCtConfig->customKbShortcuts.end() == it) return false;
if (it->second != built_in_shortcut) return true;
// we have a value in the map but it's just like the default => cleanup
pCtConfig->customKbShortcuts.erase(id);
return false;
}

CtMenu::CtMenu(CtMainWin* pCtMainWin)
: _pCtMainWin{pCtMainWin}
, _pCtConfig{pCtMainWin->get_ct_config()}
Expand Down
1 change: 1 addition & 0 deletions src/ct/ct_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct CtMenuAction
sigc::signal<void, bool> signal_set_visible = sigc::signal<void, bool>();

const std::string& get_shortcut(CtConfig* pCtConfig) const;
bool is_shortcut_overridden(CtConfig* pCtConfig) const;
};

class CtMenu
Expand Down
3 changes: 2 additions & 1 deletion src/ct/ct_pref_dlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class CtPrefDlg : public Gtk::Dialog
Gtk::TreeModelColumn<Glib::ustring> ext;
Gtk::TreeModelColumn<Glib::ustring> desc;
Gtk::TreeModelColumn<Glib::ustring> shortcut;
UniversalModelColumns() { add(icon); add(key); add(ext); add(desc); add(shortcut); }
Gtk::TreeModelColumn<int> colWeight;
UniversalModelColumns() { add(icon); add(key); add(ext); add(desc); add(shortcut); add(colWeight); }
};

private:
Expand Down
3 changes: 3 additions & 0 deletions src/ct/ct_pref_dlg_kb_shortcuts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Gtk::Widget* CtPrefDlg::build_tab_kb_shortcuts()
shortcut_column->set_cell_data_func(*shortcut_cell_renderer, [&](Gtk::CellRenderer* cell, const Gtk::TreeIter& iter){
((Gtk::CellRendererText*)cell)->property_markup() = " " + str::xml_escape(CtStrUtil::get_accelerator_label(iter->get_value(_shortcutModelColumns.shortcut))) + " ";
});
shortcut_column->add_attribute(shortcut_cell_renderer->property_weight(), _shortcutModelColumns.colWeight);
treeview->append_column(*shortcut_column);
// desc
treeview->append_column("", _shortcutModelColumns.desc);
Expand Down Expand Up @@ -237,5 +238,7 @@ void CtPrefDlg::fill_shortcut_model(Glib::RefPtr<Gtk::TreeStore> model)
row[_shortcutModelColumns.key] = action.id;
row[_shortcutModelColumns.desc] = action.desc;
row[_shortcutModelColumns.shortcut] = action.get_shortcut(_pCtMainWin->get_ct_config());
const bool is_overridden = action.is_shortcut_overridden(_pCtMainWin->get_ct_config());
row[_shortcutModelColumns.colWeight] = CtTreeIter::get_pango_weight_from_is_bold(is_overridden);
}
}

0 comments on commit 8ed3768

Please sign in to comment.