lib/mireru/command/mireru.rb in mireru-0.0.6 vs lib/mireru/command/mireru.rb in mireru-0.0.7
- old
+ new
@@ -1,8 +1,9 @@
require 'gtk3'
require "mireru/logger"
-require "mireru/widget"
+require "mireru/window"
+require "mireru/container"
module Mireru
module Command
class Mireru
USAGE = "Usage: mireru [FILE...]"
@@ -17,99 +18,71 @@
@logger = ::Mireru::Logger.new
end
def run(arguments)
if arguments.empty?
- file_container = Dir.glob("*")
+ files = Dir.glob("*")
+ file_container = ::Mireru::Container.new(files)
elsif /\A(-h|--help)\z/ =~ arguments[0]
- message = <<-EOM
-#{USAGE}
- If no argument, then search current directory.
-Keybind:
- n: next
- p: prev
- q: quit
- EOM
- @logger.info(message)
+ write_help_message
exit(true)
else
- file_container = arguments
+ files = arguments
+ file_container = ::Mireru::Container.new(files)
end
- file_container.select! {|f| support_file?(f) }
-
if file_container.empty?
- message = <<-EOM
-Warning: valid file not found.
-#{USAGE}
-Support file types: png, gif, jpeg(jpg). The others are...yet.
- EOM
- @logger.error(message)
+ write_empty_message
exit(false)
end
file = file_container.shift
- widget = ::Mireru::Widget.create(file)
- window = Gtk::Window.new
- window.title = File.basename(file)
+ window = ::Mireru::Window.new
+ window.add_from_file(file)
window.signal_connect("key_press_event") do |w, e|
case e.keyval
when Gdk::Keyval::GDK_KEY_n
- window.remove(widget)
- file_container.push(file)
- file = file_container.shift
- widget = ::Mireru::Widget.create(file)
- window.add(widget)
- window.show_all
- window.title = File.basename(file)
- window.resize(1, 1)
+ file = file_container.shift(file)
+ window.add_from_file(file)
when Gdk::Keyval::GDK_KEY_p
- window.remove(widget)
- file_container.unshift(file)
- file = file_container.pop
- widget = ::Mireru::Widget.create(file)
- window.add(widget)
- window.show_all
- window.title = File.basename(file)
- window.resize(1, 1)
+ file = file_container.pop(file)
+ window.add_from_file(file)
when Gdk::Keyval::GDK_KEY_r
- window.remove(widget)
- widget = ::Mireru::Widget.create(file)
- window.add(widget)
- window.show_all
- window.resize(1, 1)
+ window.add_from_file(file)
when Gdk::Keyval::GDK_KEY_q
Gtk.main_quit
end
end
window.signal_connect("destroy") do
Gtk.main_quit
end
- window.add(widget)
- window.show_all
-
Gtk.main
end
private
- def support_file?(file)
- unless file
- return false
- end
+ def write_help_message
+ message = <<-EOM
+#{USAGE}
+ If no argument, then search current directory.
+Keybind:
+ n: next
+ p: prev
+ q: quit
+ EOM
+ @logger.info(message)
+ end
- unless File.file?(file)
- return false
- end
-
- unless /\.(png|jpe?g|gif|txt|rb)$/i =~ file
- return false
- end
-
- true
+ def write_empty_message
+ message = <<-EOM
+Warning: valid file not found.
+#{USAGE}
+Support file types: png, gif, jpeg(jpg). The others are...yet.
+ EOM
+ @logger.error(message)
end
end
end
end