Class: Rum::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/rum/hotkey_core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLayout

Returns a new instance of Layout.



25
26
27
28
29
30
31
32
33
34
# File 'lib/rum/hotkey_core.rb', line 25

def initialize
  @ids = {}
  @names = {}
  @aliases = {}
  @modifiers = []
  @core_modifiers = {}
  # Windows-specific: Modifiers that trigger actions when pressed and released.
  @action_modifiers = {}
  @translations = {}
end

Instance Attribute Details

#action_modifiersObject

Returns the value of attribute action_modifiers.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def action_modifiers
  @action_modifiers
end

#aliasesObject

Returns the value of attribute aliases.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def aliases
  @aliases
end

#core_modifiersObject

Returns the value of attribute core_modifiers.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def core_modifiers
  @core_modifiers
end

#idsObject

Returns the value of attribute ids.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def ids
  @ids
end

#modifiersObject

Returns the value of attribute modifiers.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def modifiers
  @modifiers
end

#namesObject

Returns the value of attribute names.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def names
  @names
end

#translationsObject

Returns the value of attribute translations.



22
23
24
# File 'lib/rum/hotkey_core.rb', line 22

def translations
  @translations
end

Instance Method Details

#[](attribute) ⇒ Object



44
45
46
# File 'lib/rum/hotkey_core.rb', line 44

def [] attribute
  @names[attribute] or @aliases[attribute] or @ids[attribute]
end

#action_modifier(key) ⇒ Object



99
100
101
# File 'lib/rum/hotkey_core.rb', line 99

def action_modifier key
  @action_modifiers[modifier(key)] = true
end

#add(*args, id) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rum/hotkey_core.rb', line 57

def add *args, id
  id += 2**9 if args.delete :extended # Windows-specific magic value.
                                      # An explicit implementation might follow
  name = args.shift
  aliases = args
  key = Key.new(name, aliases, id)

  @ids[id] = key
  @names[name] = key
  aliases.each { |key_alias| @aliases[key_alias] = key }
  key
end

#alias(key, key_alias) ⇒ Object



70
71
72
73
74
# File 'lib/rum/hotkey_core.rb', line 70

def alias key, key_alias
  key = self[key]
  @aliases[key_alias] = key
  key.aliases << key_alias
end

#core_modifier(key) ⇒ Object



95
96
97
# File 'lib/rum/hotkey_core.rb', line 95

def core_modifier key
  @core_modifiers[modifier(key)] = true
end

#keysObject



36
37
38
# File 'lib/rum/hotkey_core.rb', line 36

def keys
  @ids.values.uniq
end

#lookup_key(id) ⇒ Object



40
41
42
# File 'lib/rum/hotkey_core.rb', line 40

def lookup_key id
  @ids[id]
end

#modifier(key) ⇒ Object



88
89
90
91
92
93
# File 'lib/rum/hotkey_core.rb', line 88

def modifier key
  key = self[key]
  key.modifier = true
  @modifiers << key unless @modifiers.include? key
  key
end

#modifier_lookup(attribute) ⇒ Object

Modifiers can have the names of other keys as aliases. This allows for abbreviating ‘ctrl shift enter’.do to ‘c s enter’.do Lookup the alias first to avoid matching normal keys.



51
52
53
54
55
# File 'lib/rum/hotkey_core.rb', line 51

def modifier_lookup attribute
  if (key = @aliases[attribute] || @names[attribute]) and key.modifier?
    key
  end
end

#remap(*from, to) ⇒ Object



83
84
85
86
# File 'lib/rum/hotkey_core.rb', line 83

def remap *from, to
  to = self[to]
  from.each { |key| @ids[self[key].id] = to }
end

#rename(from, to) ⇒ Object



76
77
78
79
80
81
# File 'lib/rum/hotkey_core.rb', line 76

def rename from, to
  key = self[from]
  @names.delete from
  key.name = to
  @names[to] = key
end