Class: TE2AK::Te2Ak

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

Constant Summary collapse

POSITIONS_REGEX =
/(?<!%)%\|/
CLIPBOARD_REGEX =
/(?<!%)%\(?clipboard\)?/
SPECIALCH_REGEX =
/(?<!%)%(?:[|<>]|\(?clipboard\)?)/

Instance Method Summary collapse

Constructor Details

#initializeTe2Ak

Returns a new instance of Te2Ak.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/te2ak/te2ak.rb', line 15

def initialize
  @result = {
    'folders'=>[
      {
        'folders' => [],
        'usageCount' => 0,
        'modes' => [],
        'abbreviation' => {
          'ignoreCase' => false,
          'wordChars' => '[\\w]',
          'immediate' => false,
          'abbreviation' => nil,
          'backspace' => true,
          'triggerInside' => false
        },
        'title' => 'All',
        'hotkey' => {
          'hotKey' => nil,
          'modifiers' => []
        },
        'items' => [],
        'filter' => nil,
        'type' => 'folder',
        'showInTrayMenu' => false
      }
    ],
    'toggleServiceHotkey' => {
      'hotKey' => 'k',
      'modifiers' => ['<shift>', '<super>'],
      'enabled' => true
    },
    'settings' => {
      'showTrayIcon' => true,
      'windowDefaultSize' => [600,400],
      'undoUsingBackspace' => true,
      'enableQT4Workaround' => false,
      'promptToSave' => true,
      'interfaceType' => 'XRecord',
      'showToolbar' => true,
      'serviceRunning' => true,
      'columnWidths' => [150,50,100],
      'isFirstRun' => false,
      'sortByUsageCount' => true,
      'notificationIcon' => '/usr/share/pixmaps/akicon.png',
      'hPanePosition' => 150,
      'menuTakesFocus'=> false
    },
    'userCodeDir' => nil,
    "version" => "0.71.0", 
    "showPopupHotkey" => {
      "hotKey" => nil, 
      "modifiers" => [], 
      "enabled" => false
    }, 
    "configHotkey" => {
      "hotKey" => "k", 
      "modifiers" => ["<super>"], 
      "enabled" => true
    }
  }
end

Instance Method Details

#codify(str) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/te2ak/te2ak.rb', line 77

def codify(str)
  # TODO: %< %>

  jumpback = 0
  if str =~ POSITIONS_REGEX
    # assume only one place
    # calculate position based on cleared string
    str2 = str.gsub(CLIPBOARD_REGEX, '').gsub(/%%/, '')
    jumpback = str2.length - 2 - str2.rindex(POSITIONS_REGEX)
    str.gsub!(POSITIONS_REGEX, '')
  end
  str = 'keyboard.send_keys("' + str.gsub(/(?<!\\)"/, '\"').gsub(/\n/, '<enter>').gsub(CLIPBOARD_REGEX, %!");\nkeyboard.send_keys(clipboard.get_clipboard());\nkeyboard.send_keys("!) + '");'
  if jumpback != 0
    str += %!\nkeyboard.send_keys("#{'<left>'*jumpback}");!
  end
  str.gsub(/%%/, '%')
end

#run(input, output) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/te2ak/te2ak.rb', line 95

def run(input, output)
  if File.exist?(input)
    te = Plist::parse_xml File.open(input).read
    ahk = te['snippetsTE2']

    ahk.each do |a|
      script = false
      if (a['plainText'] =~ SPECIALCH_REGEX)
        code = codify(a['plainText'])
        script = true
      end
      abbreviation = {
        'usageCount' => 0,
        'omitTrigger' => false,
        'prompt' => false,
        'description' => a['label'],
        'abbreviation' => {
          'ignoreCase' => false,
          'wordChars' => "[^ \\n]",
          'immediate' => true,
          'abbreviation' => a['abbreviation'].gsub(/%%/, '%'),
          'backspace' => true,
          'triggerInside'=> false
        },
        'hotkey' => {
          'hotKey' => nil,
          'modifiers' => []
        },
        'modes' => [1],
        "showInTrayMenu" => false,
        'matchCase' => false,
        'filter' => nil,
        'sendMode' => 'kb'
      }
      if script
        abbreviation['code'] = code
        abbreviation['type'] = 'script'
        abbreviation['store'] = {}
      else
        abbreviation['phrase'] = a['plainText'].gsub(/%%/, '%')
        abbreviation['type'] = 'phrase'
      end
      @result['folders'][0]['items'] << abbreviation
    end

    File.open(output, 'w') {|f| f.write(@result.to_json) }
  end
end