Method: FileManager#paste_files

Defined in:
lib/vimamsa/file_manager.rb

#paste_filesObject



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
# File 'lib/vimamsa/file_manager.rb', line 83

def paste_files
  if !@cut_files.empty?
    message "MOVE FILES #{@cut_files.join(",")} TO #{@ld} "
    # Thread.new {
    for fn in @cut_files
      FileUtils.move(fn, @ld)
      debug "FileUtils.move(#{fn}, #{@ld})"
    end
  elsif !@copied_files.empty?
    for fn in @copied_files
      bn = File.basename(fn)
      bnwe = File.basename(fn, ".*")
      ext = File.extname(fn)
      dst = "#{@ld}/#{bn}"
      break if !File.exist?(fn)
      if dst == fn #or File.exist?(dst)
        i = 1
        exists = true
        while File.exist?(dst)
          dst = "#{@ld}/#{bnwe}_copy#{i}#{ext}"
          i += 1
        end
      elsif File.exist?(dst)
        message("File #{dst} already exists")
        break
        #TODO: confirm if user wants to replace existing file
      end
      message "FileUtils.copy_entry(#{fn}, #{dst})"
      FileUtils.copy_entry(fn, dst, preserve = false, dereference_root = false, remove_destination = false)
    end
  else
    message "Nothing to paste, cut/copy some files first!"
    return
  end
  # }
  @cut_files = []
  @copied_files = []
  refresh
end