Sha256: ea6f19e406a6c50f0de0d943eec8ee592c200a15987a915bc194713611a02e5e

Contents?: true

Size: 1.95 KB

Versions: 37

Compression:

Stored size: 1.95 KB

Contents

module Redcar
  class Project
    # Purpose of this class is to have a menu that shows the 10 most recent opened files and directories
    # This way users can quickly go to files and directories they have recently opened, or use frequently
    class Recent
      
      # Create menus for recent files and directories
      def self.storage
        @storage ||= begin
          storage = Plugin::Storage.new('recent')
          storage.set_default('list', [])
          storage.set_default('max_list_length', 100)
          storage.set_default('max_recent_menu_length', 10)
          storage
        end
      end
      
      def self.generate_menu(builder)
        recent = storage['list']
        count = 0
        recent.each do |path|
          if count >= storage['max_recent_menu_length']
            break
          end
          count = count.next
          
          if File.exist?(File.expand_path(path))
            if File.directory?(path)
              builder.item(File.basename(path) + "/") do
                Project::Manager.open_project_for_path(path)
              end
            elsif File.file?(File.expand_path(path))
              builder.item(File.basename(path)) do
                Project::Manager.open_file(path)
              end
            else
              remove_path(path)
            end
          end
        end
      end
            
      
      # Stores the given path to the text file, to appear in the recents menu.
      #
      # @param [String] path  the path of a file or directory to be saved
      def self.store_path(path)
        path = File.expand_path(path)
        storage["list"].delete(path)
        storage["list"].unshift(path)
        if storage["list"].length == storage['max_list_length'] + 1
          storage["list"].pop
        end
        storage.save
      end
      
      def self.remove_path(path)
        path = File.expand_path(path)
        storage["list"].delete(path)
        storage.save
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
redcar-0.13 plugins/project/lib/project/recent.rb
redcar-dev-0.13.5dev plugins/project/lib/project/recent.rb
redcar-dev-0.13.4dev plugins/project/lib/project/recent.rb
redcar-dev-0.13.3dev plugins/project/lib/project/recent.rb
redcar-dev-0.13.2dev plugins/project/lib/project/recent.rb
redcar-dev-0.13.1dev plugins/project/lib/project/recent.rb
redcar-0.12.1 plugins/project/lib/project/recent.rb
redcar-dev-0.13.0dev plugins/project/lib/project/recent.rb
redcar-0.12 plugins/project/lib/project/recent.rb
redcar-dev-0.12.27dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.26dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.25dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.24dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.23dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.22dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.21dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.20dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.19dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.18dev plugins/project/lib/project/recent.rb
redcar-dev-0.12.17dev plugins/project/lib/project/recent.rb