File: shortcut-label.vala

package info (click to toggle)
peek 1.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,768 kB
  • sloc: xml: 234; sh: 85; python: 69; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 1,407 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Peek Copyright (c) 2017 by Philipp Wolfer <ph.wolfer@gmail.com>

This file is part of Peek.

This software is licensed under the GNU General Public License
(version 3 or later). See the LICENSE file in this distribution.
*/


namespace Peek.Ui {

#if ! HAS_GTK_SHORTCUT_LABEL

  // Gtk >= 3.22 does have GtkShortcutLabel, which is easier to use and
  // displays the shortcuts more nicely to the user. For older versions this
  // implements a fallback based on a normal GtkLabel with custom code for
  // displaying the shortcut keys.
  // The interface is for our purpose identical to the one of Gtk.ShortcutLabel
  class ShortcutLabel : Gtk.Label {

    private string _accelerator;
    public string accelerator {
      get {
        return _accelerator;
      }
      set {
        _accelerator = value;
        uint accelerator_key;
        Gdk.ModifierType accelerator_mods;
        Gtk.accelerator_parse (accelerator, out accelerator_key, out accelerator_mods);
        var label = Gtk.accelerator_get_label (accelerator_key, accelerator_mods);

        if (label == "") {
          label = disabled_text;
        }

        this.label = label;
      }
    }

    public string disabled_text { get; set; default = ""; }

    public ShortcutLabel (string accelerator) {
      Object ();
      this.accelerator = accelerator;

      halign = Gtk.Align.START;
      xalign = 0;
    }
  }

#endif

}