Class: FileManager
- Inherits:
-
Object
- Object
- FileManager
- Defined in:
- lib/vimamsa/file_manager.rb
Class Method Summary collapse
Instance Method Summary collapse
- #chdir_parent ⇒ Object
- #dir_to_buf(dirpath, b = nil) ⇒ Object
- #fullp(fn) ⇒ Object
-
#initialize ⇒ FileManager
constructor
A new instance of FileManager.
- #run ⇒ Object
- #select_line ⇒ Object
- #sort_fname ⇒ Object
- #sort_mtime ⇒ Object
Constructor Details
#initialize ⇒ FileManager
Returns a new instance of FileManager.
5 6 7 |
# File 'lib/vimamsa/file_manager.rb', line 5 def initialize() @buf = nil end |
Class Method Details
.chdir_parent ⇒ Object
9 10 11 |
# File 'lib/vimamsa/file_manager.rb', line 9 def self.chdir_parent() @@cur.chdir_parent end |
.cur ⇒ Object
13 14 15 |
# File 'lib/vimamsa/file_manager.rb', line 13 def self.cur() return @@cur end |
.init ⇒ Object
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 |
# File 'lib/vimamsa/file_manager.rb', line 17 def self.init() reg_act(:start_file_selector, proc { FileManager.new.run; $kbd.set_mode(:file_exp) }, "File selector") reg_act(:fexp_chdir_parent, proc { FileManager.chdir_parent }, "File selector") reg_act(:fexp_select, proc { buf.module.select_line }, "") reg_act(:fexp_sort_mtime, proc { FileManager.cur.sort_mtime }, "Sort based on time") reg_act(:fexp_sort_fname, proc { FileManager.cur.sort_fname }, "Sort based on file name") bindkey "C , j f", :start_file_selector bindkey "C , f", :start_file_selector # bindkey "C o", :delete_state $kbd.add_minor_mode("fexp", :file_exp, :command) bindkey "fexp o m", :fexp_sort_mtime bindkey "fexp o f", :fexp_sort_fname # bindkey "fexp l", [:fexp_right, proc { debug "==fexp_right==" }, ""] bindkey "fexp h", :fexp_chdir_parent bindkey "fexp esc", [:fexp_quit, proc { $kbd.set_mode(:command) }, ""] bindkey "fexp enter", :fexp_select bindkey "fexp l", :fexp_select @sort_by = :name end |
Instance Method Details
#chdir_parent ⇒ Object
45 46 47 |
# File 'lib/vimamsa/file_manager.rb', line 45 def chdir_parent dir_to_buf(fullp("..")) end |
#dir_to_buf(dirpath, b = nil) ⇒ Object
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 |
# File 'lib/vimamsa/file_manager.rb', line 67 def dir_to_buf(dirpath, b = nil) # File.stat("testfile").mtime dirpath = File.(dirpath) @header = [] @header << "#{dirpath}" @header << "=" * 40 @ld = dirpath @dlist = Dir.children(@ld).sort @cdirs = [] @cfiles = [] for x in @dlist fpath = fullp(x) ok = true begin fstat = File.stat(fpath) rescue Errno::ENOENT # Broken link or something next end next if x[0] == "." if File.directory?(fpath) # if f.directory?(fpath) @cdirs << x else @cfiles << [x, fstat] end end # sort_by = :mtime # sort_by = :name # Ripl.start :binding => binding @cfiles.sort_by! { |x| x[1].mtime }.reverse! if @sort_by == :mtime @cfiles.sort_by! { |x| x[1].size }.reverse! if @sort_by == :size @cfiles.sort_by! { |x| x[0] } if @sort_by == :name s = "" s << @header.join("\n") s << "\n" s << "..\n" s << @cdirs.join("\n") s << "\n" s << "\n" for f in @cfiles s << "#{f[0]}\n" # s << @cfiles.join("\n") end if @buf.nil? @buf = create_new_file(nil, s) @buf.module = self @buf.active_kbd_mode = :file_exp else @buf.set_content(s) end @buf.set_line_and_column_pos(@header.size, 0) end |
#fullp(fn) ⇒ Object
124 125 126 |
# File 'lib/vimamsa/file_manager.rb', line 124 def fullp(fn) "#{@ld}/#{fn}" end |
#run ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/vimamsa/file_manager.rb', line 49 def run @@cur = self ld = buflist.get_last_dir dir_to_buf(ld) # debug "ld=#{ld}" # dlist = Dir["#{ld}/*"] end |
#select_line ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/vimamsa/file_manager.rb', line 128 def select_line return if @buf.lpos < @header.size # debug "def select_line" fn = fullp(@buf.get_current_line[0..-2]) if File.directory?(fn) debug "CHDIR: #{fn}" dir_to_buf(fn) # elsif vma.can_open_extension?(fn) # jump_to_file(fn) elsif file_is_text_file(fn) bufs.close_current_buffer jump_to_file(fn) else open_with_default_program(fn) end # debug l.inspect end |
#sort_fname ⇒ Object
62 63 64 65 |
# File 'lib/vimamsa/file_manager.rb', line 62 def sort_fname @sort_by = :name dir_to_buf(@ld) end |
#sort_mtime ⇒ Object
57 58 59 60 |
# File 'lib/vimamsa/file_manager.rb', line 57 def sort_mtime @sort_by = :mtime dir_to_buf(@ld) end |