module BBS::Application::WindowStack
The windows of an Application: opening and closing them, the one in front, and switching between them Turbo Vision style (F6, Shift-F6, Alt-1 … Alt-9, a click on one behind).
Constants
- ALT_DIGIT
-
An Alt-digit key,
:alt_3; the group is the digit. - CYCLE_KEYS
-
The keys that cycle the windows, and which way.
Public Instance Methods
Source
# File lib/bbs/application/window_stack.rb, line 67 def close_window(window = nil) window ||= @windows.last return unless window @windows.delete(window) window.focused = false top_window&.focused = true window.on_close.call(window) if window.on_close.respond_to?(:call) end
Removes window (default: the top one) from the window stack, gives the focus to the new top window and calls the window’s on_close with it when that is callable. Returns nil when no window is open.
Source
# File lib/bbs/application/window_stack.rb, line 56 def cycle_windows(step = 1) list = switchable_windows return nil if list.size < 2 index = list.index(top_window) || 0 raise_window(list[(index + step) % list.size]) end
Brings the next (step 1, F6) or previous (step -1, Shift-F6) switchable window to the front, by number. Returns the raised window, or nil when fewer than two windows can be switched.
# File lib/bbs/application/window_stack.rb, line 23 def open_window(target, **extras) return push_window(target) if target.is_a?(Window) spec = @window_specs[target.to_sym] raise ArgumentError, "Unknown window: #{target.inspect}" unless spec spec.open(self, **extras) end
Opens a window and puts it in front with the focus.
- target
-
a Symbol or String naming a registered
BBS::WindowSpec, or aBBS::Windowto push onto the window stack as it is - extras
-
keyword arguments passed into the spec’s callback
ctx
A non-modal Window gets the lowest free number from 1 to 9 (for Alt-digit switching). Returns the opened window. Raises ArgumentError for an unknown spec name.
Source
# File lib/bbs/application/window_stack.rb, line 34 def raise_window(window) return window if window == top_window || !@windows.include?(window) top_window.focused = false @windows.delete(window) @windows << window window.focused = true window end
Brings an open window to the front and makes it the active one. Returns window; a window that is not open is left alone.
Source
# File lib/bbs/application/window_stack.rb, line 47 def switchable_windows return [] if @windows.any?(&:modal) @windows.reject(&:modal).sort_by { |w| w.number || UNNUMBERED } end
Returns the windows the caller can switch between, sorted by their number. Empty while a modal window (a dialog) is open: it keeps the front.
Source
# File lib/bbs/application/window_stack.rb, line 78 def top_window = @windows.last
The window in front, or nil when none is open.