~unity-team/unity/trunk

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/ShortcutHintPrivate.cpp

  • Committer: Tarmac
  • Author(s): Andrea Azzarone
  • Date: 2012-04-05 15:49:03 UTC
  • mfrom: (2209.6.4 fix-971332)
  • Revision ID: tarmac-20120405154903-qxf9zg000kzr496a
Use gtk_accelerator_get_label to get a translatable key binding.. Fixes: https://bugs.launchpad.net/bugs/971332. Approved by Gord Allott.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <glib/gi18n-lib.h>
 
20
#include <gtk/gtk.h>
20
21
 
21
22
#include "ShortcutHintPrivate.h"
 
23
#include "UnityCore/GLibWrapper.h"
22
24
 
23
25
#include <boost/algorithm/string/replace.hpp>
24
26
 
51
53
  return ret;
52
54
}
53
55
 
 
56
std::string GetTranslatableLabel(std::string const& scut)
 
57
{
 
58
  guint accelerator_key;
 
59
  GdkModifierType accelerator_mods;
 
60
 
 
61
  gtk_accelerator_parse(scut.c_str(),
 
62
                        &accelerator_key,
 
63
                        &accelerator_mods);
 
64
 
 
65
  std::string temp(glib::String(gtk_accelerator_get_label(accelerator_key, accelerator_mods)).Str());
 
66
 
 
67
  // gtk_accelerator_get_label adds an extra '+' at the end of the label.
 
68
  if (temp.length() > 0)
 
69
  {
 
70
    std::string::iterator it = temp.end() - 1;
 
71
    if (*it == '+')
 
72
      temp.erase(it);
 
73
  }
 
74
 
 
75
  // Adds an extra space around the '+'.
 
76
  boost::replace_all(temp, "+", " + ");
 
77
    
 
78
  return temp;
 
79
}
 
80
 
54
81
std::string FixMouseShortcut(std::string const& scut)
55
82
{
56
83
  std::string ret(scut);