about summary refs log tree commit diff stats
path: root/code/keys.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-04 21:47:15 +0200
committerhut <hut@lavabit.com>2009-07-04 21:47:15 +0200
commitb1855df62ae954142ca7bbc5888212bc75081303 (patch)
treee77c1d24f0a58476def55d3442363267e19be054 /code/keys.rb
parentf0c18d64739e496cf943ea794fa937cff0a7916d (diff)
downloadranger-b1855df62ae954142ca7bbc5888212bc75081303.tar.gz
request a confirmation on deletion
Diffstat (limited to 'code/keys.rb')
-rw-r--r--code/keys.rb67
1 files changed, 46 insertions, 21 deletions
diff --git a/code/keys.rb b/code/keys.rb
index 5a549d5c..86a6f235 100644
--- a/code/keys.rb
+++ b/code/keys.rb
@@ -1,22 +1,39 @@
 module Fm
 	# ALL combinations of multiple keys (but without the last letter)
 	# or regexps which match combinations need to be in here!
-	COMBS = %w(
-		g dd seriouslydd y c Z delet cu
-		ter ta S ?? ?g ?f ?m ?l ?c ?o ?z
-		o m ` ' go
-
-		um
-
-		/:[^<]*/
-		/[fF/!].*/
-		/r\d*\w*[^r]/
-		/(cw|cd|mv).*/
-		/b(l(o(c(k(.*)?)?)?)?)?/
-		/m(k(d(i(r(.*)?)?)?)?)?/
-		/t(o(u(c(h(.*)?)?)?)?)?/
-		/r(e(n(a(m(e(.*)?)?)?)?)?)?/
-	)
+	def key_combinations
+		return @@key_combinations if @@key_combinations
+
+		@@key_combinations = %w[
+			g y c Z cu
+			ter ta S ?? ?g ?f ?m ?l ?c ?o ?z
+			o m ` ' go
+			deleteI\ am   ddI\ am
+
+			um
+
+			/:[^<]*/
+			/[fF/!].*/
+			/r\d*\w*[^r]/
+			/(cw|cd|mv).*/
+			/b(l(o(c(k(.*)?)?)?)?)?/
+			/m(k(d(i(r(.*)?)?)?)?)?/
+			/t(o(u(c(h(.*)?)?)?)?)?/
+			/r(e(n(a(m(e(.*)?)?)?)?)?)?/
+		]
+
+		need_confirmation = %w[
+			delete
+			dd
+		]
+
+
+		for str in need_confirmation
+			@@key_combinations << (str + Option.confirm_string).chop
+		end
+
+		return @@key_combinations
+	end
 
 	def self.press(key)
 		return if @ignore_until and Time.now < @ignore_until
@@ -95,7 +112,7 @@ module Fm
 
 		## Destructive {{{
 
-		when 'ddy'
+		when 'dd' + Option.confirm_string
 			new_path = move_to_trash(currentfile)
 			if new_path
 				new_path = Directory::Entry.new(new_path)
@@ -105,14 +122,14 @@ module Fm
 			end
 			@pwd.schedule
 
-		when 'seriouslyddy'
+		when 'dfd' + Option.confirm_string
 			cf = currrentfile
 			if cf and cf.exists?
 				cf.delete!
 				@pwd.schedule
 			end
 
-		when 'delete'
+		when 'delete' + Option.confirm_string
 			files = selection
 			@marked = []
 			for f in files
@@ -442,6 +459,9 @@ module Fm
 			end
 			@pwd.schedule
 
+		when 't!'
+			Option.confirm ^= true
+
 		when 'tw'
 			Option.wide_bar ^= true
 
@@ -560,13 +580,18 @@ module Fm
 	end
 
 
-	@@key_regexp = nil
+	def self.recalculate_key_combinations
+		@@key_combinations = nil
+		@@key_regexp = nil
+	end
+	recalculate_key_combinations
+
 	def key_regexp
 		return @@key_regexp if @@key_regexp
 
 		# Create a regular expression which detects combos
 		ary = []
-		for token in COMBS
+		for token in key_combinations
 			if token =~ /^\/(.*)\/$/
 				ary << $1
 			elsif token.size > 0