lib/mireru/navigator.rb in mireru-0.9.1 vs lib/mireru/navigator.rb in mireru-0.9.2
- old
+ new
@@ -12,21 +12,24 @@
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+require "find"
require "gtk3"
require "gio2"
module Mireru
class Navigator < Gtk::ScrolledWindow
PATH_COLUMN, FILENAME_COLUMN, ICON_COLUMN = 0, 1, 2
- def initialize(window, files)
+ def initialize(window, files, options={})
super()
@window = window
@files = files
+ @regexp = options[:regexp]
+ @compact = options[:compact]
@dir_iters = {}
@icons = {}
set_policy(:automatic, :automatic)
set_size_request(200, -1)
@model = Gtk::TreeStore.new(String, String, Gdk::Pixbuf)
@@ -149,10 +152,12 @@
load_file(model, child, parent, recursive)
end
end
def load_file(model, file, parent=nil, recursive=false)
+ return if File.file?(file) and @regexp and /#{@regexp}/ !~ file
+ return if @compact and empty_dir?(file)
iter = model.append(parent)
iter.set_value(PATH_COLUMN, file)
iter.set_value(FILENAME_COLUMN, File.basename(file))
if File.directory?(file)
@dir_iters[file] = iter unless recursive
@@ -199,8 +204,16 @@
end
def guess_content_type(file)
content_type, _uncertain = Gio::ContentType.guess(file)
content_type
+ end
+
+ def empty_dir?(dir)
+ return false unless File.directory?(dir)
+ Find.find(*Dir.glob("#{dir}/*")) do |path|
+ return false if /#{@regexp}/ =~ File.basename(path)
+ end
+ true
end
end
end