Class: RubyMVC::Views::BrowserView

Inherits:
PeerView show all
Defined in:
lib/ruby_mvc/views/browser_view.rb

Overview

This class is slightly different at the moment as it really should have a HypermediaContentModel instance that feeds it vs. being explicitly driven by the client. This should be addressed better in a future version.

Instance Attribute Summary

Attributes inherited from PeerView

#frame, #widget

Attributes inherited from View

#actions, #controller

Instance Method Summary collapse

Methods inherited from PeerView

create_widget, #method_missing, #peer, #signal_connect, #signal_disconnect, widget, widget_def

Methods included from Toolkit::SignalHandler::ClassMethods

#signal, #signals, #valid_signal!, #valid_signal?

Methods included from Toolkit::SignalHandler

#signal_connect, #signal_disconnect, #signal_emit

Constructor Details

#initialize(options = {}, &block) ⇒ BrowserView

Returns a new instance of BrowserView.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ruby_mvc/views/browser_view.rb', line 37

def initialize(options = {}, &block)
  super

  class << action(:back,
    :label => "Back", :icon => :stock_back, :widget => widget) do
      go_back
    end

    def sensitive
      x = @options[:widget].can_go_back?
      property_changed(:sensitive, @sensitive, x)
      @sensitive = x
    end
  end

  class << action(:forward, 
    :label => "Forward", :icon => :stock_forward, :widget => widget) do
      go_forward
    end

    def sensitive
      x = @options[:widget].can_go_forward?
      property_changed(:sensitive, @sensitive, x)
      @sensitive = x
    end
  end

  class << action(:reload,
    :label => "Reload", :icon => :stock_reload, :widget => widget) do
      reload
    end

    def sensitive
      w = @options[:widget]
      x = (!w.location.nil? && "" != w.location)
      property_changed(:sensitive, @sensitive, x)
      @sensitive = x
    end
  end

  widget.signal_connect("load-finished") do
#        puts "load-finished #{widget.location}"
    # FIXME: this is a hack, but it's the only way for now
    @actions.each { |a| a.selection(self, nil, nil); a.sensitive }
#        puts "back? #{widget.can_go_back?}"
#        puts "forward? #{widget.can_go_forward?}"
  end

  widget.signal_connect("navigation-requested") do |s, h, t|
    puts "BrowserView#navigation-requested: #{h}"
    if (c = self.controller)
      puts "forwarding to controller: #{c}"
      c.link_activated(s, h)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubyMVC::Views::PeerView

Instance Method Details

#add(view) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ruby_mvc/views/browser_view.rb', line 157

def add(view)
  if !view.is_a? WebContentView
    raise ArgumentError, "view must currently be a WebContentView instance"
  end

  append_html(view.render)

# FIXME: this should really be done, but we need to be a bit
# more sophisticated in the way we manage it
#      append_actions(view.actions)
end

#append_html(*args, &block) ⇒ Object



125
126
127
# File 'lib/ruby_mvc/views/browser_view.rb', line 125

def append_html(*args, &block)
  widget.append_html(*args, &block)
end

#go_backObject



100
101
102
103
104
# File 'lib/ruby_mvc/views/browser_view.rb', line 100

def go_back
  reset_actions
  widget.go_back
  append_actions((location || {})[:actions])
end

#go_forwardObject



94
95
96
97
98
# File 'lib/ruby_mvc/views/browser_view.rb', line 94

def go_forward
  reset_actions
  widget.go_forward
  append_actions((location || {})[:actions])
end

#load(view, uri = nil) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ruby_mvc/views/browser_view.rb', line 129

def load(view, uri = nil)
  if !view.is_a? WebContentView
    raise ArgumentError, "view must currently be a WebContentView instance"
  end

  # FIXME: need action support in the history management
  # too so that actions are appropriately added/removed
  # during forward/backward navigation requests

  load_html(view.render, uri || view.uri)
  widget.location[:view] = view

  # If our view provides a different controller, then we
  # need to defer link handling to that controller instead
  # of ours (which probably wasn't defined in the first
  # place)

  if (vc = view.controller) && vc != self.controller
    puts "assigned new controller from WebContentView: #{vc}"
    self.controller = vc
  else
    puts "no controller defined for #{view}"
  end

  # add any content actions
  append_actions(view.actions)
end

#load_html(*args) ⇒ Object



111
112
113
114
115
# File 'lib/ruby_mvc/views/browser_view.rb', line 111

def load_html(*args)
  reset_actions
#      puts "#load_html: " << args.inspect
  widget.load_html(*args)
end

#open(uri) ⇒ Object



106
107
108
109
# File 'lib/ruby_mvc/views/browser_view.rb', line 106

def open(uri)
  reset_actions
  widget.open(uri)
end

#reloadObject



117
118
119
120
121
122
123
# File 'lib/ruby_mvc/views/browser_view.rb', line 117

def reload
  if location && v = location[:view]
    load(v, location[:uri])
  else
    super
  end
end