lib/scide/project.rb in scide-0.0.8 vs lib/scide/project.rb in scide-0.0.9
- old
+ new
@@ -13,10 +13,14 @@
attr_reader :options
# The GNU Screen windows of this project.
attr_reader :windows
+ # The name or index of the window that should be displayed by default for
+ # this project (defaults to the last window).
+ attr_reader :default_window
+
# Returns a project configuration.
#
# If not given in the project hash, {#path} is built by joining
# the global path and <tt>key</tt>.
#
@@ -58,10 +62,20 @@
@options[:name] = key
@options[:path] = @path
@options.merge!(contents[:options] || {})
@windows = contents[:windows].collect{ |w| Scide::Window.new self, w }
+
+ # find default window if specified
+ @default_window = if contents[:default_window].kind_of? Fixnum
+ @windows[contents[:default_window]]
+ elsif contents[:default_window].kind_of?(String) or contents[:default_window].kind_of?(Symbol)
+ @windows.find{ |w| w.name == contents[:default_window].to_s }
+ elsif !contents[:default_window].nil?
+ raise ArgumentError, "default window of project '#{key}' should be an integer, string or symbol"
+ end
+ raise ArgumentError, "default window of project '#{key}' must be the name or index of one of its windows" if !contents[:default_window].nil? and @default_window.nil?
end
# Returns a representation of this project as a GNU Screen
# configuration fragment. Returns nil if this project has
# no configured windows.
@@ -70,9 +84,10 @@
String.new.tap do |s|
@windows.each_with_index do |w,i|
s << w.to_screen(i)
s << "\n" if i != (@windows.length - 1)
end
+ s << "\nselect #{@default_window.name}" if @default_window
end
end
end
end