Skip to content

Commit

Permalink
Merge branch 'html_view-cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
kattrali committed Nov 8, 2010
2 parents 40a3a23 + a4b1bb0 commit 011acc4
Show file tree
Hide file tree
Showing 41 changed files with 367 additions and 255 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Enhancements:
* "Online Help" and "Submit a Bug" open the default system browser (Johannes Wollert)
* -l command line switch to jump to a file number (Johannes Wollert)
* Font and Theme dialogs now update the setting on selection change for instant feedback (Tim Felgentreff)
* Tabs now display an alert icon if the underlying file is unwritable (Delisa Mason)
* Browser bar URL field now supports project-relative paths (Delisa Mason)
* URLs can be opened in the internal browser or the OS-default based on preferences (Delisa Mason)

Bug fixes:

Expand Down
35 changes: 20 additions & 15 deletions plugins/application/lib/application/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ module Redcar
class Tab
include Redcar::Model
include Redcar::Observable

DEFAULT_ICON = :file


DEFAULT_ICON = :file
NO_WRITE_ICON = :exclamation_red
MISSING_ICON = :exclamation
CONFIG_ICON = :hammer_screwdriver
HELP_ICON = :question
WEB_ICON = :globe

attr_reader :notebook

def initialize(notebook)
@notebook = notebook
@title = "unknown"
end

# Close the tab (remove it from the Notebook).
#
# Events: close
Expand All @@ -20,8 +25,8 @@ def close
notify_listeners(:close)
end
end
# Focus the tab within the notebook, and gives the keyboard focus to the

# Focus the tab within the notebook, and gives the keyboard focus to the
# contents of the tab, if appropriate.
#
# Events: focus
Expand All @@ -39,11 +44,11 @@ def title=(title)
@title = title
notify_listeners(:changed_title, title)
end

def icon
@icon || DEFAULT_ICON
end

def icon=(value)
@icon = value
notify_listeners(:changed_icon, icon)
Expand All @@ -58,30 +63,30 @@ def set_notebook(notebook)
@notebook = notebook
end

# Moves the tab to a new position in the notebook, if said position
# Moves the tab to a new position in the notebook, if said position
# is currently occupied. Defaults to the first position, if none
# is passed.
#
#
# Events: moved (position)
def move_to_position(position = 0)
if (0..@notebook.tabs.size - 1).include?(position)
notify_listeners(:moved, position)
end
end

def edit_tab?
is_a?(EditTab)
end

# Helper method to get the edit_view's document, if applicable.
def document
edit_view.document if edit_tab?
end

# Helper method to get this tab's Mirror object for the current
# document, if applicable.
def document_mirror
document.mirror if document
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class OpenCommand < Redcar::Command

def execute
controller = Controller.new
tab = win.new_tab(HtmlTab)
tab = win.new_tab(ConfigTab)
tab.html_view.controller = controller
tab.focus
end
Expand Down
28 changes: 21 additions & 7 deletions plugins/edit_view/lib/edit_view/edit_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,31 @@ def initialize(*args)
create_edit_view
end

def update_for_file_changes
old_icon = @icon
def icon
i = DEFAULT_ICON
doc = @edit_view.document
if doc and doc.path
if File.exists?(doc.path)
@icon = :file if icon == :exclamation
else
@icon = :exclamation
unless doc.mirror.adapter.is_a?(Redcar::Project::Adapters::Remote)
if File.exists?(doc.path)
if File.writable?(doc.path)
i = DEFAULT_ICON
else
i = NO_WRITE_ICON
end
else
i = MISSING_ICON
end
end
end
notify_listeners(:changed_icon, @icon) if old_icon != @icon
i
end

def update_for_file_changes
new_icon = icon
if new_icon and new_icon != @icon
@icon = new_icon
notify_listeners(:changed_icon, @icon)
end
end

def create_edit_view
Expand Down
44 changes: 30 additions & 14 deletions plugins/help/lib/help.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

require 'help/view_controller'
require 'help/help_tab'

module Redcar
class Help
def self.menus
Expand All @@ -7,6 +10,7 @@ def self.menus
group(:priority => :first) do
item "Online Help", :command => OnlineHelpCommand
item "Submit a Bug", :command => SubmitABugCommand
item "Keyboard Shortcuts", :command => ViewShortcutsCommand
end
end
end
Expand All @@ -19,29 +23,41 @@ def self.keymaps
[map]
end

def self.toolbars
ToolBar::Builder.build do
item "Keyboard Shortcuts", :command => ViewShortcutsCommand, :icon => File.join(Redcar::ICONS_DIRECTORY, "/keyboard.png"), :barname => :help
item "Help", :command => OnlineHelpCommand, :icon => File.join(Redcar::ICONS_DIRECTORY, "/question.png"), :barname => :help
end
end

class ViewShortcutsCommand < Redcar::Command
def execute
controller = Help::ViewController.new
tab = win.new_tab(Help::HelpTab)
tab.html_view.controller = controller
tab.focus
end
end

class SubmitABugCommand < Redcar::Command
def execute
if OpenDefaultBrowserCommand.supported?
OpenDefaultBrowserCommand.new("https://redcar.lighthouseapp.com/projects/25090-redcar/tickets/new").run
else
Redcar::WebBookmarks::DisplayWebContent.new(
Redcar::HtmlView::DisplayWebContent.new(
"Submit a Bug",
"https://redcar.lighthouseapp.com/projects/25090-redcar/tickets/new"
).run
end
"https://redcar.lighthouseapp.com/projects/25090-redcar/tickets/new",
true,
Help::HelpTab
).run
end
end

class OnlineHelpCommand < Redcar::Command
def execute
if OpenDefaultBrowserCommand.supported?
OpenDefaultBrowserCommand.new("http://github.com/redcar/redcar/wiki/Users-Guide").run
else
Redcar::WebBookmarks::DisplayWebContent.new(
Redcar::HtmlView::DisplayWebContent.new(
"Online Help",
"http://github.com/redcar/redcar/wiki/Users-Guide"
).run
end
"http://github.com/redcar/redcar/wiki/Users-Guide",
true,
Help::HelpTab
).run
end
end
end
Expand Down
11 changes: 11 additions & 0 deletions plugins/help/lib/help/help_tab.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Redcar
class Help
class HelpTab < HtmlTab
DEFAULT_ICON = HELP_ICON

def icon
DEFAULT_ICON
end
end
end
end
25 changes: 25 additions & 0 deletions plugins/help/lib/help/view_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Redcar
class Help
class ViewController
include HtmlController

def title
"Shortcuts"
end

def clean_name(command)
name = command.to_s.sub("Command","")
idx = name.rindex("::")
unless idx.nil?
name = name[idx+2,name.length]
end
name = name.split(/(?=[A-Z])/).map{|w| w}.join(" ").sub("R E P L","REPL")
end

def index
rhtml = ERB.new(File.read(File.join(File.dirname(__FILE__), "..", "..", "views", "index.html.erb")))
rhtml.result(binding)
end
end
end
end
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<title>Keyboard Shortcuts</title>
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins view_shortcuts views default.css))) %>
<% redcar_css = File.expand_path(File.join(Redcar.root, %w(plugins help views default.css))) %>
<link rel="stylesheet" href="file://<%= redcar_css %>" type="text/css" media="screen">
</head>
<body>
Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Feature: Navigating web content in HtmlTabs using the browser bar

Background:
When I will choose "plugins/web_bookmarks/features/fixtures" from the "open_directory" dialog
When I will choose "plugins/html_view/features/fixtures" from the "open_directory" dialog
And I open a directory
When I open the web bookmarks tree
And I activate the "Sample" node in the tree
Then the HTML tab should say "Hello!!"
And I open the browser bar
And I type "sample.html" into the "New URL:" field in the speedbar
And I press "Go!" in the speedbar

Scenario: Refresh a tab
Given I will choose "plugins/web_bookmarks/features/fixtures/sample.html" from the "open_file" dialog
Given I will choose "plugins/html_view/features/fixtures/sample.html" from the "open_file" dialog
When I open a file
And I replace the contents with "<html>I see you!</html>"
And I save the tab
Expand All @@ -17,12 +17,12 @@ Feature: Navigating web content in HtmlTabs using the browser bar
Then the HTML tab should say "I see you!"

Scenario: Go to a new URL in a HtmlTab
When I type the fixture path of "other.html" in the "New URL:" field in the speedbar
When I type "other.html" into the "New URL:" field in the speedbar
And I press "Go!" in the speedbar
Then the HTML tab should say "Is today Tuesday?"

Scenario: Move back and forward in the browser history
When I type the fixture path of "other.html" in the "New URL:" field in the speedbar
When I type "other.html" into the "New URL:" field in the speedbar
And I press "Go!" in the speedbar
And I press "<" in the speedbar
Then the HTML tab should say "Hello!!"
Expand All @@ -34,7 +34,7 @@ Feature: Navigating web content in HtmlTabs using the browser bar
Then I should see "<html><b>Hello!!</b></html>" in the edit tab

Scenario: Add a new bookmark to a project
When I type the fixture path of "other.html" in the "New URL:" field in the speedbar
When I type "other.html" into the "New URL:" field in the speedbar
Given I would type "Other" in an input box
And I would type "" in an input box
When I press "+" in the speedbar
Expand Down
1 change: 1 addition & 0 deletions plugins/html_view/features/fixtures/other.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><b>Is today Tuesday?</b></html>
1 change: 1 addition & 0 deletions plugins/html_view/features/fixtures/sample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><b>Hello!!</b></html>
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@

html_view.controller.execute(js)
end

When /^I open the browser bar$/ do
Redcar::HtmlView::OpenBrowserBar.new.run
end

When /^I open a web preview$/ do
Redcar::HtmlView::FileWebPreview.new.run
end
26 changes: 26 additions & 0 deletions plugins/html_view/features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

def htmlview_fixtures_path
File.expand_path(File.dirname(__FILE__) + "/../fixtures")
end

def htmlview_fixtures_redcar
File.join(htmlview_fixtures_path,".redcar")
end

def reset_htmlview_fixtures
FileUtils.rm_rf(htmlview_fixtures_redcar) if File.exists?(htmlview_fixtures_redcar)
File.open(htmlview_fixtures_path + "/sample.html", "w") do |f|
f.print "<html><b>Hello!!</b></html>"
end
File.open(htmlview_fixtures_path + "/other.html", "w") do |f|
f.print "<html><b>Is today Tuesday?</b></html>"
end
end

Before do
reset_htmlview_fixtures
end

After do
reset_htmlview_fixtures
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Feature: Previewing how a file will appear in a browser
When I open a new edit tab
And I replace the contents with "<html>test 1-2-3</html>"
And I open a web preview
Then my active tab should be "Preview: (untitled)"
Then my active tab should be "Preview"
And the HTML tab should say "test 1-2-3"

Scenario: Previewing a saved file
Given I will choose "plugins/web_bookmarks/features/fixtures/sample.html" from the "open_file" dialog
Given I will choose "plugins/html_view/features/fixtures/sample.html" from the "open_file" dialog
When I open a file
And I replace the contents with "<html>test 1-2-3</html>"
And I open a web preview
Expand Down
Loading

0 comments on commit 011acc4

Please sign in to comment.