vimamsa 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/custom_example.rb +12 -0
- data/lib/vimamsa/ack.rb +3 -4
- data/lib/vimamsa/actions.rb +1 -2
- data/lib/vimamsa/audio.rb +25 -1
- data/lib/vimamsa/buffer.rb +116 -591
- data/lib/vimamsa/buffer_changetext.rb +272 -0
- data/lib/vimamsa/buffer_cursor.rb +303 -0
- data/lib/vimamsa/buffer_list.rb +137 -133
- data/lib/vimamsa/buffer_manager.rb +15 -15
- data/lib/vimamsa/clipboard.rb +36 -0
- data/lib/vimamsa/conf.rb +136 -5
- data/lib/vimamsa/constants.rb +0 -10
- data/lib/vimamsa/debug.rb +9 -8
- data/lib/vimamsa/editor.rb +57 -84
- data/lib/vimamsa/encrypt.rb +6 -11
- data/lib/vimamsa/file_history.rb +0 -8
- data/lib/vimamsa/file_manager.rb +142 -10
- data/lib/vimamsa/gui.rb +106 -85
- data/lib/vimamsa/gui_dialog.rb +113 -0
- data/lib/vimamsa/gui_menu.rb +5 -1
- data/lib/vimamsa/gui_sourceview.rb +46 -29
- data/lib/vimamsa/gui_sourceview_autocomplete.rb +141 -0
- data/lib/vimamsa/gui_text.rb +49 -0
- data/lib/vimamsa/hyper_plain_text.rb +19 -5
- data/lib/vimamsa/key_actions.rb +41 -202
- data/lib/vimamsa/key_binding_tree.rb +129 -41
- data/lib/vimamsa/key_bindings_vimlike.rb +58 -48
- data/lib/vimamsa/langservp.rb +23 -3
- data/lib/vimamsa/macro.rb +35 -25
- data/lib/vimamsa/main.rb +7 -10
- data/lib/vimamsa/rbvma.rb +13 -11
- data/lib/vimamsa/search.rb +1 -1
- data/lib/vimamsa/search_replace.rb +106 -160
- data/lib/vimamsa/terminal.rb +34 -0
- data/lib/vimamsa/tests.rb +122 -0
- data/lib/vimamsa/util.rb +43 -4
- data/lib/vimamsa/version.rb +1 -1
- data/vimamsa.gemspec +5 -2
- metadata +59 -9
- /data/lib/vimamsa/{form_generator.rb → gui_form_generator.rb} +0 -0
data/lib/vimamsa/debug.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "fileutils"
|
2
2
|
|
3
3
|
def debug(message, severity = 1)
|
4
|
-
if
|
4
|
+
if cnf.debug?
|
5
5
|
if severity > 1
|
6
6
|
# Add red colour and bold for attention
|
7
7
|
# https://en.wikipedia.org/wiki/ANSI_escape_code
|
@@ -18,7 +18,7 @@ def debug_print_buffer(c)
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def debug_dump_clipboard()
|
21
|
-
puts
|
21
|
+
puts vma.clipboard.inspect
|
22
22
|
end
|
23
23
|
|
24
24
|
def debug_dump_deltas()
|
@@ -41,6 +41,11 @@ def log_error(message)
|
|
41
41
|
#TODO
|
42
42
|
end
|
43
43
|
|
44
|
+
def show_caller
|
45
|
+
puts caller().join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
|
44
49
|
def crash(message, e = nil)
|
45
50
|
puts "FATAL ERROR:#{message}"
|
46
51
|
puts caller().join("\n")
|
@@ -59,8 +64,8 @@ def savedebug(message, e)
|
|
59
64
|
dbginfo["trace_str"] = dbginfo["trace"].join("\n")
|
60
65
|
dbginfo["edit_history"] = buf.edit_history
|
61
66
|
dbginfo["cnf"] = $cnf
|
62
|
-
dbginfo["register"] =
|
63
|
-
dbginfo["clipboard"] =
|
67
|
+
dbginfo["register"] = vma.register
|
68
|
+
dbginfo["clipboard"] = vma.clipboard
|
64
69
|
# dbginfo["last_event"] = $last_event
|
65
70
|
dbginfo["buffer"] = {}
|
66
71
|
dbginfo["buffer"]["str"] = buf.to_s
|
@@ -79,10 +84,6 @@ def savedebug(message, e)
|
|
79
84
|
puts save_fn_json
|
80
85
|
end
|
81
86
|
|
82
|
-
def run_tests()
|
83
|
-
run_test("01")
|
84
|
-
run_test("02")
|
85
|
-
end
|
86
87
|
|
87
88
|
def run_test(test_id)
|
88
89
|
target_results = read_file("", "tests/test_#{test_id}_output.txt")
|
data/lib/vimamsa/editor.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
1
|
require "pty"
|
2
2
|
|
3
|
-
def exec_in_terminal(cmd, autoclose = false)
|
4
|
-
# debug "CMD:#{cmd}"
|
5
|
-
|
6
|
-
# global to prevent garbage collect unlink
|
7
|
-
$initf = Tempfile.new("bashinit")
|
8
|
-
# debug $initf.path
|
9
|
-
$initf.write(cmd)
|
10
|
-
if autoclose
|
11
|
-
$initf.write("\nsleep 10; exit;\n")
|
12
|
-
$initf.write("rm #{$initf.path}\n")
|
13
|
-
else
|
14
|
-
$initf.write("rm #{$initf.path}\n")
|
15
|
-
$initf.write("\nexec bash\n")
|
16
|
-
end
|
17
|
-
$initf.close
|
18
|
-
# PTY.spawn("gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash")
|
19
|
-
# fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
|
20
|
-
# Just another execution
|
21
|
-
fork { exec "gnome-terminal", "--tab", "--", "bash", "-i", $initf.path, "-c", "exec bash" }
|
22
|
-
end
|
23
|
-
|
24
3
|
def handle_drag_and_drop(fname)
|
25
4
|
debug "EDITOR:handle_drag_and_drop"
|
26
5
|
buf.handle_drag_and_drop(fname)
|
@@ -29,7 +8,7 @@ end
|
|
29
8
|
|
30
9
|
class Editor
|
31
10
|
attr_reader :file_content_search_paths, :file_name_search_paths, :gui, :hook, :macro
|
32
|
-
attr_accessor :converters, :fh, :paint_stack, :kbd, :langsrv
|
11
|
+
attr_accessor :converters, :fh, :paint_stack, :kbd, :langsrv, :register, :cur_register, :clipboard
|
33
12
|
#attr_writer :call_func, :update_highlight
|
34
13
|
|
35
14
|
def initialize()
|
@@ -46,6 +25,19 @@ class Editor
|
|
46
25
|
@paint_stack = []
|
47
26
|
@_plugins = {}
|
48
27
|
@errors
|
28
|
+
@register = Hash.new("")
|
29
|
+
@cur_register = "a"
|
30
|
+
@clipboard = Clipboard.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_register(char)
|
34
|
+
@cur_register = char
|
35
|
+
message("Set register #{char}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def paste_register(char)
|
39
|
+
$c = @cur_register #TODO:??
|
40
|
+
message("Paste: #{$c}")
|
49
41
|
end
|
50
42
|
|
51
43
|
def open_file_listener(added)
|
@@ -73,11 +65,15 @@ class Editor
|
|
73
65
|
@hook = $hook
|
74
66
|
register_plugin(:Hook, @hook)
|
75
67
|
@macro = Macro.new
|
76
|
-
|
77
|
-
register_plugin(:Macro, $macro)
|
68
|
+
register_plugin(:Macro, @macro)
|
78
69
|
$search = Search.new
|
79
70
|
register_plugin(:Search, $search)
|
80
71
|
|
72
|
+
# build_key_bindings_tree
|
73
|
+
@kbd = KeyBindingTree.new()
|
74
|
+
$kbd = @kbd
|
75
|
+
require "vimamsa/key_bindings_vimlike"
|
76
|
+
|
81
77
|
$buffers = BufferList.new
|
82
78
|
$minibuffer = Buffer.new(">", "")
|
83
79
|
@langsrv = {}
|
@@ -85,13 +81,9 @@ class Editor
|
|
85
81
|
require "vimamsa/text_transforms"
|
86
82
|
|
87
83
|
debug "ARGV: " + ARGV.inspect
|
88
|
-
|
89
|
-
@kbd = KeyBindingTree.new()
|
90
|
-
$kbd = @kbd
|
91
|
-
require "vimamsa/key_bindings_vimlike"
|
84
|
+
|
92
85
|
sleep(0.03)
|
93
86
|
|
94
|
-
FileManager.init
|
95
87
|
BufferManager.init
|
96
88
|
|
97
89
|
@gui.init_menu
|
@@ -130,13 +122,17 @@ class Editor
|
|
130
122
|
custom_script = read_file("", custom_fn)
|
131
123
|
eval(custom_script) if custom_script
|
132
124
|
|
133
|
-
|
125
|
+
Grep.init
|
126
|
+
FileManager.init
|
127
|
+
Autocomplete.init
|
128
|
+
|
129
|
+
if cnf.lsp.enabled?
|
134
130
|
require "vimamsa/langservp"
|
135
131
|
require "vimamsa/audio" # TODO:config
|
136
132
|
@langsrv["ruby"] = LangSrv.new("ruby")
|
137
133
|
@langsrv["cpp"] = LangSrv.new("cpp")
|
138
134
|
end
|
139
|
-
|
135
|
+
|
140
136
|
# build_options
|
141
137
|
|
142
138
|
fname = nil
|
@@ -306,35 +302,28 @@ def open_file_dialog()
|
|
306
302
|
gui_open_file_dialog(File.dirname(path))
|
307
303
|
end
|
308
304
|
|
309
|
-
|
310
|
-
def
|
311
|
-
|
312
|
-
if clipboard_contents != $clipboard[-1]
|
313
|
-
#TODO: HACK
|
314
|
-
$paste_lines = false
|
305
|
+
class Clipboard
|
306
|
+
def initialize
|
307
|
+
@clipboard = []
|
315
308
|
end
|
316
|
-
$clipboard << clipboard_contents
|
317
|
-
# debug $clipboard[-1]
|
318
|
-
$clipboard = $clipboard[-([$clipboard.size, max_clipboard_items].min)..-1]
|
319
|
-
end
|
320
309
|
|
321
|
-
def
|
322
|
-
|
323
|
-
|
310
|
+
def set(s)
|
311
|
+
if !(s.class <= String) or s.size == 0
|
312
|
+
debug s.inspect
|
313
|
+
debug [s, s.class, s.size]
|
314
|
+
log_error("s.class != String or s.size == 0")
|
315
|
+
return
|
316
|
+
end
|
317
|
+
@clipboard << s
|
318
|
+
set_system_clipboard(s)
|
319
|
+
vma.register[vma.cur_register] = s
|
320
|
+
debug "SET CLIPBOARD: [#{s}]"
|
321
|
+
debug "REGISTER: #{vma.cur_register}:#{vma.register[vma.cur_register]}"
|
322
|
+
end
|
324
323
|
|
325
|
-
def
|
326
|
-
|
327
|
-
debug s.inspect
|
328
|
-
debug [s, s.class, s.size]
|
329
|
-
log_error("s.class != String or s.size == 0")
|
330
|
-
# Ripl.start :binding => binding
|
331
|
-
return
|
324
|
+
def get()
|
325
|
+
return @clipboard[-1]
|
332
326
|
end
|
333
|
-
$clipboard << s
|
334
|
-
set_system_clipboard(s)
|
335
|
-
$register[$cur_register] = s
|
336
|
-
debug "SET CLIPBOARD: [#{s}]"
|
337
|
-
debug "REGISTER: #{$cur_register}:#{$register[$cur_register]}"
|
338
327
|
end
|
339
328
|
|
340
329
|
def set_cursor_pos(new_pos)
|
@@ -459,7 +448,7 @@ def minibuffer_delete()
|
|
459
448
|
end
|
460
449
|
|
461
450
|
def error(str)
|
462
|
-
|
451
|
+
show_caller
|
463
452
|
debug "#{caller[0]} ERROR: #{str}", 2
|
464
453
|
end
|
465
454
|
|
@@ -502,7 +491,7 @@ GUESS_ENCODING_ORDER = [
|
|
502
491
|
]
|
503
492
|
|
504
493
|
def create_new_file(filename = nil, file_contents = "\n")
|
505
|
-
buffer = Buffer.new(file_contents)
|
494
|
+
buffer = Buffer.new(file_contents, filename)
|
506
495
|
|
507
496
|
debug "NEW FILE CREATED: #{buffer.id}"
|
508
497
|
vma.buffers.add(buffer)
|
@@ -558,21 +547,21 @@ def load_buffer(fname)
|
|
558
547
|
return buffer
|
559
548
|
end
|
560
549
|
|
561
|
-
def jump_to_file(filename,
|
550
|
+
def jump_to_file(filename, tnum = nil, charn = nil)
|
562
551
|
open_new_file(filename)
|
563
552
|
|
564
553
|
# Link to character position
|
565
554
|
if !charn.nil?
|
566
555
|
if charn == "c"
|
567
|
-
buf.jump_to_pos(
|
556
|
+
buf.jump_to_pos(tnum) # tnum=character position
|
568
557
|
center_on_current_line
|
569
558
|
return
|
570
559
|
end
|
571
560
|
end
|
572
561
|
|
573
562
|
# Link to line
|
574
|
-
if !
|
575
|
-
buf.jump_to_line(
|
563
|
+
if !tnum.nil?
|
564
|
+
buf.jump_to_line(tnum) # tnum=line position
|
576
565
|
center_on_current_line
|
577
566
|
return
|
578
567
|
end
|
@@ -595,6 +584,12 @@ def open_new_file(filename, file_contents = "")
|
|
595
584
|
if !is_path_writable(filename)
|
596
585
|
message("Path #{filename} cannot be written to")
|
597
586
|
return false
|
587
|
+
elsif !File.exist?(filename)
|
588
|
+
message("File #{filename} does not exist")
|
589
|
+
return false
|
590
|
+
elsif !file_is_text_file(filename)
|
591
|
+
message("File #{filename} does not contain text")
|
592
|
+
return false
|
598
593
|
end
|
599
594
|
message "New file opened: #{filename}"
|
600
595
|
fname = filename
|
@@ -633,28 +628,6 @@ def get_file_line_pointer(s)
|
|
633
628
|
return nil
|
634
629
|
end
|
635
630
|
|
636
|
-
# TODO: Implement using https://github.com/blackwinter/ruby-filemagic
|
637
|
-
def file_is_text_file(fpath)
|
638
|
-
debug "file_is_text_file(#{fpath})"
|
639
|
-
fpath = File.expand_path(fpath)
|
640
|
-
return false if !File.exist?(fpath)
|
641
|
-
r = exec_cmd("file", fpath)
|
642
|
-
debug "DEBUG:#{r}"
|
643
|
-
return true if r.match(/UTF-8.*text/)
|
644
|
-
return true if r.match(/ASCII.*text/)
|
645
|
-
return false
|
646
|
-
end
|
647
|
-
|
648
|
-
def set_register(char)
|
649
|
-
$cur_register = char
|
650
|
-
message("Set register #{char}")
|
651
|
-
end
|
652
|
-
|
653
|
-
def paste_register(char)
|
654
|
-
$c = $register[char]
|
655
|
-
message("Paste: #{$c}")
|
656
|
-
end
|
657
|
-
|
658
631
|
def find_project_dir_of_fn(fn)
|
659
632
|
pcomp = Pathname.new(fn).each_filename.to_a
|
660
633
|
parent_dirs = (0..(pcomp.size - 2)).collect { |x| "/" + pcomp[0..x].join("/") }.reverse
|
data/lib/vimamsa/encrypt.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require "openssl"
|
3
2
|
|
4
3
|
class Encrypt
|
@@ -13,16 +12,16 @@ class Encrypt
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def encrypt(text)
|
16
|
-
cipher
|
15
|
+
cipher = @enc
|
17
16
|
encrypted = cipher.update text
|
18
17
|
encrypted << cipher.final
|
19
|
-
encrypted = encrypted.unpack(
|
18
|
+
encrypted = encrypted.unpack("H*")[0].upcase
|
20
19
|
@enc.reset
|
21
20
|
return encrypted
|
22
21
|
end
|
23
22
|
|
24
23
|
def decrypt(encrypted)
|
25
|
-
cipher
|
24
|
+
cipher = @dec
|
26
25
|
encrypted = [encrypted].pack("H*").unpack("C*").pack("c*")
|
27
26
|
plain = cipher.update encrypted
|
28
27
|
plain << cipher.final
|
@@ -32,16 +31,12 @@ class Encrypt
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
def decrypt_cur_buffer(password, b = nil)
|
36
|
-
vma.buf.decrypt(password)
|
37
|
-
end
|
38
34
|
|
39
35
|
def encrypt_cur_buffer()
|
40
|
-
callback = proc{|x|encrypt_cur_buffer_callback(x)}
|
41
|
-
gui_one_input_action("Encrypt", "Password:", "Encrypt", callback,{:hide=>true})
|
36
|
+
callback = proc { |x| encrypt_cur_buffer_callback(x) }
|
37
|
+
gui_one_input_action("Encrypt", "Password:", "Encrypt", callback, { :hide => true })
|
42
38
|
end
|
43
39
|
|
44
|
-
def encrypt_cur_buffer_callback(password,b=nil)
|
40
|
+
def encrypt_cur_buffer_callback(password, b = nil)
|
45
41
|
vma.buf.set_encrypted(password)
|
46
42
|
end
|
47
|
-
|
data/lib/vimamsa/file_history.rb
CHANGED
@@ -4,9 +4,6 @@ class FileHistory
|
|
4
4
|
attr_accessor :history
|
5
5
|
|
6
6
|
def initialize()
|
7
|
-
# puts self.method("update")
|
8
|
-
# x = self.method("update")
|
9
|
-
# x.call("ASFASF")
|
10
7
|
|
11
8
|
vma.hook.register(:change_buffer, self.method("update"))
|
12
9
|
vma.hook.register(:shutdown, self.method("save"))
|
@@ -17,9 +14,6 @@ class FileHistory
|
|
17
14
|
$search_list = []
|
18
15
|
end
|
19
16
|
|
20
|
-
# def self.init()
|
21
|
-
# end
|
22
|
-
|
23
17
|
def update(buf)
|
24
18
|
debug "FileHistory.update(buf=#{buf.fname})"
|
25
19
|
return if !buf.fname
|
@@ -30,8 +24,6 @@ class FileHistory
|
|
30
24
|
@history[buf.fname] += 1
|
31
25
|
end
|
32
26
|
debug @history
|
33
|
-
|
34
|
-
# puts "FileHistory.update(buf=#{buf})"
|
35
27
|
end
|
36
28
|
|
37
29
|
def save()
|
data/lib/vimamsa/file_manager.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
1
3
|
class FileManager
|
2
4
|
@@cur
|
3
5
|
|
4
6
|
def initialize()
|
5
7
|
@buf = nil
|
8
|
+
@cut_files = []
|
9
|
+
@copied_files = []
|
6
10
|
end
|
7
11
|
|
8
12
|
def self.chdir_parent()
|
@@ -14,7 +18,7 @@ class FileManager
|
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.init()
|
17
|
-
reg_act(:start_file_selector, proc { FileManager.new.run;
|
21
|
+
reg_act(:start_file_selector, proc { FileManager.new.run; vma.kbd.set_mode(:file_exp); }, "File selector")
|
18
22
|
|
19
23
|
reg_act(:fexp_chdir_parent, proc { FileManager.chdir_parent }, "File selector")
|
20
24
|
reg_act(:fexp_select, proc { buf.module.select_line }, "")
|
@@ -32,6 +36,19 @@ class FileManager
|
|
32
36
|
bindkey "fexp o m", :fexp_sort_mtime
|
33
37
|
bindkey "fexp o f", :fexp_sort_fname
|
34
38
|
|
39
|
+
# These are not yet safe to use
|
40
|
+
if cnf.fexp.experimental?
|
41
|
+
reg_act(:fexp_cut_file, proc { FileManager.cur.cut_file }, "Cut file (to paste elsewhere)")
|
42
|
+
reg_act(:fexp_copy_file, proc { FileManager.cur.copy_file }, "Copy file (to paste elsewhere)")
|
43
|
+
reg_act(:fexp_delete_file, proc { FileManager.cur.delete_file }, "Delete current file")
|
44
|
+
reg_act(:fexp_paste_files, proc { FileManager.cur.paste_files }, "Move previously cut files here")
|
45
|
+
|
46
|
+
bindkey "fexp d d", :fexp_cut_file
|
47
|
+
bindkey "fexp y y", :fexp_copy_file
|
48
|
+
bindkey "fexp d D", :fexp_delete_file
|
49
|
+
bindkey "fexp p p", :fexp_paste_files
|
50
|
+
end
|
51
|
+
|
35
52
|
# bindkey "fexp l", [:fexp_right, proc { debug "==fexp_right==" }, ""]
|
36
53
|
bindkey "fexp h", :fexp_chdir_parent
|
37
54
|
bindkey "fexp esc", [:fexp_quit, proc { FileManager.cur.quit }, ""]
|
@@ -63,18 +80,106 @@ class FileManager
|
|
63
80
|
dir_to_buf(@ld)
|
64
81
|
end
|
65
82
|
|
83
|
+
def paste_files
|
84
|
+
if !@cut_files.empty?
|
85
|
+
message "MOVE FILES #{@cut_files.join(",")} TO #{@ld} "
|
86
|
+
# Thread.new {
|
87
|
+
for fn in @cut_files
|
88
|
+
FileUtils.move(fn, @ld)
|
89
|
+
debug "FileUtils.move(#{fn}, #{@ld})"
|
90
|
+
end
|
91
|
+
elsif !@copied_files.empty?
|
92
|
+
for fn in @copied_files
|
93
|
+
bn = File.basename(fn)
|
94
|
+
bnwe = File.basename(fn, ".*")
|
95
|
+
ext = File.extname(fn)
|
96
|
+
dst = "#{@ld}/#{bn}"
|
97
|
+
break if !File.exist?(fn)
|
98
|
+
if dst == fn #or File.exist?(dst)
|
99
|
+
i = 1
|
100
|
+
exists = true
|
101
|
+
while File.exist?(dst)
|
102
|
+
dst = "#{@ld}/#{bnwe}_copy#{i}#{ext}"
|
103
|
+
i += 1
|
104
|
+
end
|
105
|
+
elsif File.exist?(dst)
|
106
|
+
message("File #{dst} already exists")
|
107
|
+
break
|
108
|
+
#TODO: confirm if user wants to replace existing file
|
109
|
+
end
|
110
|
+
message "FileUtils.copy_entry(#{fn}, #{dst})"
|
111
|
+
FileUtils.copy_entry(fn, dst, preserve = false, dereference_root = false, remove_destination = false)
|
112
|
+
end
|
113
|
+
else
|
114
|
+
message "Nothing to paste, cut/copy some files first!"
|
115
|
+
return
|
116
|
+
end
|
117
|
+
# }
|
118
|
+
@cut_files = []
|
119
|
+
@copied_files = []
|
120
|
+
refresh
|
121
|
+
end
|
122
|
+
|
123
|
+
def cut_file
|
124
|
+
fn = cur_file
|
125
|
+
debug "CUT FILE #{fn}", 2
|
126
|
+
@cut_files << fn
|
127
|
+
@copied_files = []
|
128
|
+
end
|
129
|
+
|
130
|
+
def copy_file
|
131
|
+
fn = cur_file
|
132
|
+
debug "COPY FILE #{fn}", 2
|
133
|
+
@copied_files << fn
|
134
|
+
@cut_files = []
|
135
|
+
end
|
136
|
+
|
137
|
+
def delete_file_confirmed(*args)
|
138
|
+
debug args, 2
|
139
|
+
fn = @file_to_delete
|
140
|
+
message "Deleting file #{fn}"
|
141
|
+
# FileUtils.remove_file(fn)
|
142
|
+
FileUtils.remove_entry_secure(fn, force = false)
|
143
|
+
refresh
|
144
|
+
end
|
145
|
+
|
146
|
+
def delete_file
|
147
|
+
fn = cur_file
|
148
|
+
if File.file?(fn)
|
149
|
+
@file_to_delete = fn #TODO: set as parameter to confirm_box
|
150
|
+
Gui.confirm("Delete the file? \r #{fn}",
|
151
|
+
self.method("delete_file_confirmed"))
|
152
|
+
elsif File.directory?(fn)
|
153
|
+
@file_to_delete = fn #TODO: set as parameter to confirm_box
|
154
|
+
Gui.confirm("Delete the directory? \r #{fn}",
|
155
|
+
self.method("delete_file_confirmed"))
|
156
|
+
else
|
157
|
+
message "Can't delete #{fn}"
|
158
|
+
end
|
159
|
+
|
160
|
+
# TODO: FileUtils.remove_dir
|
161
|
+
|
162
|
+
#TODO:
|
163
|
+
end
|
164
|
+
|
66
165
|
def dir_to_buf(dirpath, b = nil)
|
67
166
|
# File.stat("testfile").mtime
|
68
167
|
|
168
|
+
debug "last file: #{vma.buffers.last_file}", 2
|
169
|
+
lastf = vma.buffers.last_file
|
170
|
+
jumpto = nil
|
171
|
+
if File.dirname(lastf) == dirpath
|
172
|
+
jumpto = File.basename(lastf)
|
173
|
+
end
|
69
174
|
vma.buffers.last_dir = dirpath
|
70
175
|
dirpath = File.expand_path(dirpath)
|
71
176
|
@header = []
|
72
177
|
@header << "#{dirpath}"
|
73
178
|
@header << "=" * 40
|
74
|
-
@ld = dirpath
|
179
|
+
@ld = dirpath # Path to current directory
|
75
180
|
@dlist = Dir.children(@ld).sort
|
76
|
-
@cdirs = []
|
77
|
-
@cfiles = []
|
181
|
+
@cdirs = [] # Dirs in current directory
|
182
|
+
@cfiles = [] # Files in current directory
|
78
183
|
for x in @dlist
|
79
184
|
fpath = fullp(x)
|
80
185
|
|
@@ -93,7 +198,6 @@ class FileManager
|
|
93
198
|
end
|
94
199
|
end
|
95
200
|
|
96
|
-
|
97
201
|
@cfiles.sort_by! { |x| x[1].mtime }.reverse! if @sort_by == :mtime
|
98
202
|
@cfiles.sort_by! { |x| x[1].size }.reverse! if @sort_by == :size
|
99
203
|
@cfiles.sort_by! { |x| x[0] } if @sort_by == :name
|
@@ -105,37 +209,65 @@ class FileManager
|
|
105
209
|
s << @cdirs.join("\n")
|
106
210
|
s << "\n"
|
107
211
|
s << "\n"
|
212
|
+
jumppos = nil
|
108
213
|
for f in @cfiles
|
214
|
+
if f[0] == jumpto
|
215
|
+
jumppos = s.size
|
216
|
+
end
|
109
217
|
s << "#{f[0]}\n"
|
110
218
|
# s << @cfiles.join("\n")
|
111
219
|
end
|
112
220
|
|
113
221
|
if @buf.nil?
|
114
|
-
@buf = create_new_buffer(s,"filemgr")
|
222
|
+
@buf = create_new_buffer(s, "filemgr")
|
223
|
+
@buf.default_mode = :file_exp
|
115
224
|
@buf.module = self
|
116
225
|
@buf.active_kbd_mode = :file_exp
|
117
226
|
else
|
118
227
|
@buf.set_content(s)
|
119
228
|
end
|
120
|
-
|
229
|
+
if jumppos
|
230
|
+
@buf.set_pos(jumppos)
|
231
|
+
else
|
232
|
+
@buf.set_line_and_column_pos(@header.size, 0)
|
233
|
+
end
|
121
234
|
end
|
122
235
|
|
123
236
|
def fullp(fn)
|
124
237
|
"#{@ld}/#{fn}"
|
125
238
|
end
|
126
239
|
|
240
|
+
def refresh
|
241
|
+
# TODO: only apply diff
|
242
|
+
lpos = @buf.lpos
|
243
|
+
# cpos = @buf.cpos
|
244
|
+
dir_to_buf(@ld)
|
245
|
+
@buf.set_line_and_column_pos(lpos, 0)
|
246
|
+
end
|
247
|
+
|
248
|
+
def cur_file
|
249
|
+
return nil if @buf.lpos < @header.size
|
250
|
+
fn = fullp(@buf.get_current_line[0..-2])
|
251
|
+
return fn
|
252
|
+
end
|
253
|
+
|
127
254
|
def select_line
|
128
|
-
return if @buf.lpos < @header.size
|
255
|
+
# return if @buf.lpos < @header.size
|
129
256
|
# debug "def select_line"
|
130
|
-
fn = fullp(@buf.get_current_line[0..-2])
|
257
|
+
# fn = fullp(@buf.get_current_line[0..-2])
|
258
|
+
fn = cur_file
|
259
|
+
return if fn.nil?
|
131
260
|
if File.directory?(fn)
|
132
261
|
debug "CHDIR: #{fn}"
|
133
262
|
dir_to_buf(fn)
|
134
263
|
# elsif vma.can_open_extension?(fn)
|
135
264
|
# jump_to_file(fn)
|
136
265
|
elsif file_is_text_file(fn)
|
137
|
-
bufs.close_current_buffer
|
266
|
+
# bufs.close_current_buffer
|
138
267
|
jump_to_file(fn)
|
268
|
+
# vma.buffers.set_current_buffer(idx)
|
269
|
+
vma.buffers.close_other_buffer(@buf.id)
|
270
|
+
|
139
271
|
else
|
140
272
|
open_with_default_program(fn)
|
141
273
|
end
|