diff options
Diffstat (limited to 'code')
-rw-r--r-- | code/directory.rb | 15 | ||||
-rw-r--r-- | code/draw.rb | 2 | ||||
-rw-r--r-- | code/fm.rb | 16 | ||||
-rw-r--r-- | code/keys.rb | 39 |
4 files changed, 47 insertions, 25 deletions
diff --git a/code/directory.rb b/code/directory.rb index 92782907..6099d891 100644 --- a/code/directory.rb +++ b/code/directory.rb @@ -2,6 +2,7 @@ require 'code/extensions/basic' class Directory @@filter = nil + BAD_TIME = Time.at(1) def initialize(path, allow_delay=false) @path = path @@ -9,6 +10,7 @@ class Directory @files = [] @file_size = 0 @pointed_file = nil + @sort_time = BAD_TIME @width = 1000 @read = false @free_space = nil @@ -47,7 +49,7 @@ class Directory end attr_reader(:path, :files, :pos, :width, :files_raw, - :file_size, :read) + :file_size, :read, :sort_time) attr_accessor(:scheduled) def self.filter=(x) @@ -185,7 +187,7 @@ class Directory log("getting file info of #{@path}") get_file_info end - sort + sort_if_needed end def schedule() @@ -196,13 +198,19 @@ class Directory oldfile = @pointed_file read_dir get_file_info - sort + sort_if_needed if @files.include? oldfile self.pointed_file = oldfile end end + def sort_if_needed + if @sort_time < Fm.sort_time + sort + end + end + def sort_sub(x, y) case Option.sort when :ext @@ -221,6 +229,7 @@ class Directory end def sort() + @sort_time = Time.now files = @files.sort {|x,y| if Option.list_dir_first if x.dir? diff --git a/code/draw.rb b/code/draw.rb index b32c49ff..43f2b8e1 100644 --- a/code/draw.rb +++ b/code/draw.rb @@ -66,6 +66,8 @@ module Fm break if (f = d.files[lpo]) == nil + d.sort_if_needed + mycolor = if lpo == d.pos if infos Color.selected_current_row diff --git a/code/fm.rb b/code/fm.rb index a15735b7..168885d4 100644 --- a/code/fm.rb +++ b/code/fm.rb @@ -32,6 +32,7 @@ module Fm @bars_thread = nil @entering_directory = true + @sort_time = Time.now @buffer = '' @pwd = nil @@ -66,11 +67,12 @@ module Fm boot_up(pwd) end - attr_reader(:dirs, :pwd) + attr_reader(:dirs, :pwd, :sort_time) def refresh() begin @pwd.refresh + update_pointers draw rescue end @@ -201,6 +203,7 @@ module Fm oldpath = @path.dup # NOTE: @dirs[unknown] is not nil but Directory.new(unknown) + ## create @path, an array of directory objects @path = [@dirs['/']] unless dir == '/' dir.slice(0) @@ -216,27 +219,32 @@ module Fm @pwd = @path.last @pwd.pos = @pwd.pos + ## initialize directories in @pwd @pwd.files_raw.dup.each do |x| @dirs[x] if File.directory?(x) end + ## set the title reset_title() + ## ??? if @path.size < oldpath.size @pwd.pos = @pwd.files_raw.index(oldpath.last.path) || 0 end i = 0 + @entering_directory = true + Dir.chdir(@pwd.path) + end + + def update_pointers @path.each_with_index do |p, i| p.schedule unless i == @path.size - 1 p.pointed_file = @path[i+1].path end end - - @entering_directory = true - Dir.chdir(@pwd.path) end def move_to_trash!(fn) diff --git a/code/keys.rb b/code/keys.rb index 3e8c78fd..583171e8 100644 --- a/code/keys.rb +++ b/code/keys.rb @@ -435,24 +435,16 @@ module Fm ## Options {{{ - when /^S(.)$/ - Option.sort_reverse = $1.ord.between?(65, 90) + when SORT_REGEXP + how = SORT_KEYS[$1.downcase] + log how - case $1.downcase - when 'n' - Option.sort = :name - when 'e' - Option.sort = :ext - when 't' - Option.sort = :type - when 's' - Option.sort = :size - when 'm' - Option.sort = :mtime - when 'c' - Option.sort = :ctime - end - @pwd.schedule + @sort_time = Time.now + Option.sort_reverse = $1.ord.between?(65, 90) + Option.sort = how if how + @path.each do |x| x.sort end + update_pointers +# @pwd.schedule when 't!' Option.confirm ^= true @@ -544,7 +536,8 @@ module Fm @buffer = '' unless @buffer == '' or @buffer =~ key_regexp end - def self.descend + ## go down 1 directory + def descend Directory.filter = nil unless @path.size == 1 enter_dir(@buffer=='H' ? '..' : @path[-2].path) @@ -617,6 +610,16 @@ module Fm @memory["`"] = @memory["'"] = @pwd.path end + SORT_KEYS = { + 'n' => :name, + 'e' => :ext, + 't' => :type, + 's' => :size, + 'm' => :mtime, + 'c' => :ctime + } + + SORT_REGEXP = /^S (?i: ( [#{ SORT_KEYS.keys * '|' }] )) $/x def self.recalculate_key_combinations @@key_combinations = nil |