Skip to content

Commit

Permalink
translate shortcuts and descriptions in settings dialog (bug #66558)
Browse files Browse the repository at this point in the history
* gui-preferences-sc.cc: use the empty constructor for all shortcut objects
  for not already adding the untranslated descritpon to the hash with all
  shortcuts;
  (init_all_shortcuts): function for later adding description, key and
  key-sequence to all shortcuts

* gui-preferences-sc.h; new function init_all_shortcuts

* gui-preferences.cc (sc_pref::def_text): use option QKeySequence::NativeText
  resulting in translated strings for a key sequence

* gui-settings.cc	(sc_value): see gui-preferences.cc (sc_pref::def_text)

* octave-qobject.cc: include gui-preferences-sc.h;
  (config_translators): call init_all_shortcuts for setting up shortcuts

* shortcuts-tree-widget.cc (keyPressEvent): use QKeySequence::NativeText;
  (shortcuts_tree_widget): sort the shortcuts with respect to their
  descritpion, not with respect to their keys
  • Loading branch information
ttl-octave committed Dec 29, 2024
1 parent 7c7df53 commit 4971f42
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 145 deletions.
468 changes: 327 additions & 141 deletions libgui/src/gui-preferences-sc.cc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libgui/src/gui-preferences-sc.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ sc_prevent_rl_conflicts ("shortcuts/prevent_readline_conflicts", QVariant (false
const gui_pref
sc_prevent_rl_conflicts_menu ("shortcuts/prevent_readline_conflicts_menu", QVariant (false));

extern void init_all_shortcuts (void);
extern QString get_shortcut_section (const QString& key);

#endif
2 changes: 1 addition & 1 deletion libgui/src/gui-preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ sc_pref::def_value () const
QString
sc_pref::def_text () const
{
return def_value ().toString ();
return def_value ().toString (QKeySequence::NativeText);
}

all_shortcut_preferences *all_shortcut_preferences::s_instance = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion libgui/src/gui-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ gui_settings::sc_value (const sc_pref& scpref) const

// Get the value from the settings where the key sequences are stored
// as strings
return value (full_settings_key, key_seq.toString ()).toString ();
return value (full_settings_key, key_seq.toString (QKeySequence::NativeText)).toString ();
}
else
return scpref.def_text ();
Expand Down
3 changes: 3 additions & 0 deletions libgui/src/octave-qobject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "documentation-dock-widget.h"
#include "files-dock-widget.h"
#include "gui-settings.h"
#include "gui-preferences-sc.h"
#include "history-dock-widget.h"
#include "interpreter-qobject.h"
#include "main-window.h"
Expand Down Expand Up @@ -403,6 +404,8 @@ base_qobject::config_translators ()
m_qapplication->installTranslator (m_qsci_tr);

m_translators_installed = true;

init_all_shortcuts (); // after translators are loaded
}

void
Expand Down
14 changes: 12 additions & 2 deletions libgui/src/shortcuts-tree-widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ enter_shortcut::keyPressEvent (QKeyEvent *e)
if (modifiers & Qt::MetaModifier)
key |= Qt::META;

setText (QKeySequence (key).toString ());
setText (QKeySequence (key).toString (QKeySequence::NativeText));
}
}

Expand Down Expand Up @@ -456,7 +456,17 @@ shortcuts_tree_widget::shortcuts_tree_widget (QWidget *parent)

QList<QString> shortcut_settings_keys
= all_shortcut_preferences::keys ();
shortcut_settings_keys.sort ();

// Sort the keys with respect to the desciption, by adding
// descriotions as keys and the settings keys as values to a map.
// Fir this, use QMultiMap since descriptions might not be unique.
QMultiMap <QString, QString> shortcut_settings_map;
for (const auto& settings_key : shortcut_settings_keys)
{
const sc_pref scpref = all_shortcut_preferences::value (settings_key);
shortcut_settings_map.insert (scpref.description (), settings_key);
}
shortcut_settings_keys = shortcut_settings_map.values ();

gui_settings settings;

Expand Down

0 comments on commit 4971f42

Please sign in to comment.