summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/action.rb31
-rw-r--r--code/entry.rb3
-rw-r--r--code/fm/keys.rb21
-rw-r--r--code/runcontext.rb47
4 files changed, 61 insertions, 41 deletions
diff --git a/code/action.rb b/code/action.rb
index 34a07242..7a0a9ac7 100644
--- a/code/action.rb
+++ b/code/action.rb
@@ -27,22 +27,13 @@ module Action
 		rc ||= RunContext.new(Fm.getfiles)
 		assert rc, RunContext
 
-		cf       = Fm.currentfile
-		
 		all      = rc.all.or true
-		files    = rc.files.or(all ? Fm.selection : [cf])
+		files    = rc.files
 		mode     = rc.mode.or 0
-		newway   = rc.newway.or false
 
-		return false if files.nil?
+		return false if files.nil? or files.empty?
 
-		if newway
-#			logpp files.first.handler
-#			rc = Fm.filehandler(files, struct)
-			handler = rc.exec
-		else
-			handler, wait = Fm.getfilehandler(*files)
-		end
+		handler = rc.exec
 
 		return false unless handler
 
@@ -52,15 +43,15 @@ module Action
 
 		log handler
 		if detach
-			run_detached(handler, new_term)
+			run_detached(handler, rc)
 		else
-			run_inside(handler, wait)
+			run_inside(handler, rc)
 		end
 		return true
 	end
 
-	def run_detached(what, new_term)
-		if new_term
+	def run_detached(what, rc)
+		if rc.new_term
 			p = fork { exec('x-terminal-emulator', '-e', 'bash', '-c', what) }
 #			Process.detach(p)
 		else
@@ -69,11 +60,11 @@ module Action
 		end
 	end
 
-	def run_inside(what, wait)
-		close_interface
+	def run_inside(what, rc)
+		close_interface unless rc.console
 		system(*what)
-		wait_for_enter if wait
-		start_interface
+		wait_for_enter if rc.wait
+		start_interface unless rc.console
 	end
 
 	def wait_for_enter
diff --git a/code/entry.rb b/code/entry.rb
index bc0d2d7b..7a17bb65 100644
--- a/code/entry.rb
+++ b/code/entry.rb
@@ -27,7 +27,6 @@ class Directory::Entry
 			@basename = File.basename(dirname)
 		end
 		@name, @ext = @basename.split_at_last_dot
-#			@ext = @basename.from_last('.') || ''
 		@movie = MOVIE_EXTENSIONS.include?(@ext)
 		@size = 0
 		@exists = false
@@ -65,7 +64,7 @@ class Directory::Entry
 
 	def handler()
 		## get_handler has to be defined in another file
-		@handler = catch(:use) do
+		@handler ||= catch(:use) do
 			get_handler
 		end
 	end
diff --git a/code/fm/keys.rb b/code/fm/keys.rb
index 4e3af766..f5854dc9 100644
--- a/code/fm/keys.rb
+++ b/code/fm/keys.rb
@@ -513,23 +513,18 @@ module Fm
 				starti
 			end
 
-		when '<cr>', 'l', ';', 'L', '<right>'
-			ascend(@buffer=='L', @buffer=='l')
-
-		# a = run all
-		# d or e = detach
-		# t = run in a terminal
-		# w = wait for <enter> after execution
-		# capital letter inverts
+		when '<cr>', 'l', 'L', '<right>'
+			if currentfile.dir?
+				enter_dir_safely(currentfile.path)
+			else
+				mode = @buffer == 'L' ? 1 : 0
+				Action.run(RunContext.new(getfiles, mode))
+			end
+
 		when /^[ri](\d*)([adetw]*)[ri]$/
 			run_context = RunContext.new(getfiles, $1, $2)
 			Action.run(run_context)
 		
-#		when 'ra'
-#			unless File.directory?(currentfile.path)
-#				Action.run(:all=>true)
-#			end
-
 		when 'ZZ', '<c-d>', ':q<cr>', 'Q'
 			exit
 			
diff --git a/code/runcontext.rb b/code/runcontext.rb
index 1e10aa8d..ce62e60f 100644
--- a/code/runcontext.rb
+++ b/code/runcontext.rb
@@ -1,7 +1,16 @@
 class RunContext
+	# mode is a number from 0 to infinity
+	#
+	# flags are a string or array containing:
+	# * a = run all
+	# * d or e = detach
+	# * t = run in a terminal
+	# * w = wait for <enter> after execution
+	# * c = run from ./ranger.rb <filename> (not usable from inside ranger)
+	# * capital letter inverts
 	## accessors {{{
 	attr_accessor( *%w[
-		all detach wait new_term
+		all detach wait new_term console
 		files handlers paths
 		mode
 		exec
@@ -26,7 +35,11 @@ class RunContext
 
 	def initialize(files, mode=0, flags='')
 		@mode = mode.to_i
-		@files = files.dup
+		if files.is_a? Array
+			@files = files.dup
+		else
+			@files = [files.dup]
+		end
 		self.flags = flags
 		
 		@files.reject! {|file|
@@ -38,7 +51,11 @@ class RunContext
 
 		@multi = (@files.size > 1 and @handlers.uniq.size == 1)
 
-		@exec = Application.send(@handler, self)
+		if @handler
+			@exec = Application.send(@handler, self)
+		else
+			@exec = nil
+		end
 	end
 
 	def has_flag? x
@@ -68,6 +85,9 @@ class RunContext
 		if has_flag? 'w'
 			@wait = true
 		end
+		if has_flag? 'c'
+			@console = true
+		end
 
 		## Negative flags
 		if has_flag? 'A'
@@ -82,10 +102,11 @@ class RunContext
 		if has_flag? 'W'
 			@wait = false
 		end
+		if has_flag? 'C'
+			@console = false
+		end
 	end
 
-	def newway() true end
-
 	def no_mode?()
 		@mode == 0
 	end
@@ -98,7 +119,21 @@ class RunContext
 		if @flagstring.empty?
 			self.flags = x
 		end
-		x
+		return x
+	end
+
+	def base_flags=(x)
+		newflags = (x.is_a? Array) ? x : x.split(//)
+
+		for flag in newflags
+			unless @flags.include? flag.upcase or
+					@flags.include? flag.downcase
+				@flags << flag
+			end
+		end
+
+		self.flags = @flags
+		return x
 	end
 
 	## set the mode and return self.