Skip to content

Commit

Permalink
enhancement: show the last used key in the key dialog. Helps if you h…
Browse files Browse the repository at this point in the history
…ave long keys where only the last part changes. It should also be highlighted by default, so if you type anything, it'll be overwritten.

Signed-off-by: Sven Fuchs <svenfuchs@artweb-design.de>
  • Loading branch information
Kieran Pilkington authored and Sven Fuchs committed Mar 31, 2009
1 parent 7202ef8 commit 6efa960
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tools/Rails I18n.tmbundle/Support/lib/rails_i18n.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require File.join(File.dirname(__FILE__), 'dictionary')
require File.join(File.dirname(__FILE__), 'yaml_waml')
require 'pstore'

class Hash
def deep_merge(other)
Expand All @@ -20,8 +21,11 @@ def set(keys, value)
end
end

PREFS_FILE = "~/Library/Preferences/com.macromates.textmate.rails_i18n.pstore"

class Translate

@@prefs = PStore.new(File.expand_path(PREFS_FILE))
@@project_dir = ENV['TM_PROJECT_DIRECTORY']
@@t_path_plain = File.join(@@project_dir, 'log', 'translations')
@@t_path_yaml = File.join(@@project_dir, 'log', 'translations.yml')
Expand Down Expand Up @@ -51,7 +55,9 @@ def self.execute
end

def self.get_key
TextMate::UI.request_string :title => 'Key', :prompt => 'Key'
key = TextMate::UI.request_string :title => 'Key', :prompt => 'Key', :default => self.get_pref('last_used_key')
self.set_pref('last_used_key', key)
key
end

def self.get_type
Expand All @@ -76,4 +82,13 @@ def self.translation_method
translate_cmd = (current_file =~ /^\/app\/(controllers|helpers|views)\//) ? 't' : 'I18n.t'
end

def self.get_pref(key)
pref = @@prefs.transaction { @@prefs[key] }
(pref || '')
end

def self.set_pref(key, value)
@@prefs.transaction { @@prefs[key] = value }
end

end

0 comments on commit 6efa960

Please sign in to comment.