From b1855df62ae954142ca7bbc5888212bc75081303 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 4 Jul 2009 21:47:15 +0200 Subject: request a confirmation on deletion --- code/draw.rb | 7 ++++--- code/keys.rb | 67 +++++++++++++++++++++++++++++++++++++++++------------------- ranger.rb | 30 ++++++++++++++++----------- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/code/draw.rb b/code/draw.rb index b493c846..1b40d47d 100644 --- a/code/draw.rb +++ b/code/draw.rb @@ -281,13 +281,14 @@ module Fm btm = lines - 1 case @buffer - when 'seriouslydd', 'dd' - puti btm, "Are you serious? Please press y to confirm." + when /^delete/, /^dd/ + puti btm, "#@buffer ".rjust(cols) + puti btm, 'Are you serious? (' + Option.confirm_string + ')' when 'S' puti btm, "Sort by (n)ame (s)ize (m)time (c)time (CAPITAL:reversed)" when 't' - puti btm, "Toggle (h)idden_files (d)irs_first (f)ilepreview (p)review (w)idebar" + puti btm, "Toggle (h)idden_files (d)irs_first (f)ilepreview (p)review (w)idebar (c)d (!)confirm" else attr_set(Color.base) attr_set(Color.info) 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 diff --git a/ranger.rb b/ranger.rb index 7fbe4824..f668d053 100755 --- a/ranger.rb +++ b/ranger.rb @@ -30,20 +30,26 @@ end ## default options opt = { - :show_hidden => false, - :sort => :name, - :dir_first => true, - :sort_reverse => false, - :cd => ARGV.include?('--cd'), - :colorscheme => true, - :ascii_only => true, - :wide_bar => true, - :file_preview => true, - :preview => true, - :colorscheme => 'default' + :show_hidden => false, + :sort => :name, + :dir_first => true, + :sort_reverse => false, + :cd => ARGV.include?('--cd'), + :colorscheme => true, + :ascii_only => true, + :wide_bar => true, + :confirm_string => "yes I am!", + :confirm => true, + :file_preview => true, + :preview => true, + :colorscheme => 'default' } -Option = Struct.new(*opt.keys).new(*opt.values) +class OptionClass < Struct.new(*opt.keys) + def confirm_string; confirm ? super : "" end +end + +Option = OptionClass.new(*opt.values) opt = nil load 'ranger.conf' -- cgit 1.4.1-2-gfad0 -0800 5969' href='/akkartik/mu/commit/mu_summary?h=hlt&id=819513fb5386399dd58fbd482c621146ffab921b'>819513fb ^
924ed08a ^

819513fb ^


924ed08a ^
819513fb ^
924ed08a ^
819513fb ^
924ed08a ^
924ed08a ^


924ed08a ^





924ed08a ^





924ed08a ^





924ed08a ^





924ed08a ^


924ed08a ^












819513fb ^


7f453fe0 ^



924ed08a ^










01a28c56 ^
819513fb ^
924ed08a ^




01a28c56 ^

924ed08a ^























































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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196