Permalink
Browse files

Added keys to switch tabs.

  • Loading branch information...
danlucraft committed Dec 29, 2009
1 parent 5242fe5 commit e7132d7e1164c16f02e7f5fb391d85f7b6c3d458
View
@@ -1,4 +1,11 @@
+Version 0.3.1dev (TBA)
+======================
+
+Enhancements:
+
+ * Keybindings to switch tabs.
+
Version 0.3dev (25 Dec 2009)
============================
View
@@ -23,6 +23,7 @@ The features of this release are chosen to be the minimum to make Redcar self-ho
Features:
+ * Keybindings to switch tabs (done)
* Text editing stuff:
- Undo/Redo
- Home/End
@@ -33,7 +34,6 @@ Features:
* Plugins stuff:
- can add to menus easily
- gem plugins
- * Keybindings to switch tabs
More previews to add
--------------------
@@ -62,6 +62,24 @@ def select_tab!(tab)
notify_listeners(:tab_focussed, tab)
end
+ # Focus the next tab to the right from the currently focussed tab.
+ # Does not wrap.
+ def switch_up
+ current_ix = @tabs.index(@focussed_tab)
+ unless current_ix == @tabs.length - 1
+ @tabs[current_ix+1].focus
+ end
+ end
+
+ # Focus the next tab to the left from the currently focussed tab.
+ # Does not wrap.
+ def switch_down
+ current_ix = @tabs.index(@focussed_tab)
+ unless current_ix == 0
+ @tabs[current_ix-1].focus
+ end
+ end
+
def inspect
"#<Redcar::Notebook #{object_id}>"
end
@@ -24,6 +24,15 @@
tab.edit_view.document.text = arg1
end
+When /I move (up|down) a tab/ do |type|
+ case type
+ when "down"
+ Redcar::Top::SwitchTabDownCommand.new.run
+ when "up"
+ Redcar::Top::SwitchTabUpCommand.new.run
+ end
+end
+
Then /^there should be one (.*) tab$/ do |tab_type|
# in the model
tabs = Redcar.app.windows.first.notebooks.map {|nb| nb.tabs }.flatten
@@ -61,6 +70,5 @@
end
Then /^I should see "(.*)" in the edit tab$/ do |content|
- tab = get_tab(get_tab_folder)
- tab.edit_view.document.to_s.include?(content).should be_true
+ focussed_tab.edit_view.document.to_s.include?(content).should be_true
end
@@ -15,6 +15,10 @@ def get_tab(tab_folder)
tab = Redcar.app.windows.first.notebooks.map{|n| n.tabs}.flatten.detect{|t| t.controller.item == item1}
end
+ def focussed_tab
+ Redcar.app.windows.first.focussed_notebook.focussed_tab
+ end
+
def get_tabs
display = Redcar::ApplicationSWT.display
shell = display.get_shells.to_a.first
@@ -0,0 +1,39 @@
+Feature: Switch and move tabs within a notebook
+
+ Scenario: Switch tab down
+ When I open a new edit tab
+ And I replace the contents with "Anne Boleyn"
+ And I open a new edit tab
+ And I replace the contents with "Elizabeth Woodville"
+ Then I should see "Elizabeth Woodville" in the edit tab
+ And I move down a tab
+ Then I should see "Anne Boleyn" in the edit tab
+
+ Scenario: Switch tab down too far
+ When I open a new edit tab
+ And I replace the contents with "Anne Boleyn"
+ And I open a new edit tab
+ And I replace the contents with "Elizabeth Woodville"
+ Then I should see "Elizabeth Woodville" in the edit tab
+ And I move down a tab
+ And I move down a tab
+ Then I should see "Anne Boleyn" in the edit tab
+
+ Scenario: Switch tab up
+ When I open a new edit tab
+ And I replace the contents with "Anne Boleyn"
+ And I open a new edit tab
+ And I replace the contents with "Elizabeth Woodville"
+ Then I should see "Elizabeth Woodville" in the edit tab
+ And I move down a tab
+ And I move up a tab
+ Then I should see "Elizabeth Woodville" in the edit tab
+
+ Scenario: Switch tab up too far
+ When I open a new edit tab
+ And I replace the contents with "Anne Boleyn"
+ And I open a new edit tab
+ And I replace the contents with "Elizabeth Woodville"
+ Then I should see "Elizabeth Woodville" in the edit tab
+ And I move up a tab
+ Then I should see "Elizabeth Woodville" in the edit tab
View
@@ -124,6 +124,26 @@ def execute
end
end
+ class SwitchTabDownCommand < Command
+ key :osx => "Cmd+Shift+[",
+ :linux => "Ctrl+Shift+[",
+ :windows => "Ctrl+Shift+["
+
+ def execute
+ win.focussed_notebook.switch_down
+ end
+ end
+
+ class SwitchTabUpCommand < Command
+ key :osx => "Cmd+Shift+]",
+ :linux => "Ctrl+Shift+]",
+ :windows => "Ctrl+Shift+]"
+
+ def execute
+ win.focussed_notebook.switch_up
+ end
+ end
+
def self.start
Redcar.gui = ApplicationSWT.gui
Redcar.app.controller = ApplicationSWT.new(Redcar.app)
@@ -156,6 +176,9 @@ def self.start
sub_menu "View" do
item "Rotate Notebooks", RotateNotebooksCommand
item "Move Tab To Other Notebook", MoveTabToOtherNotebookCommand
+ separator
+ item "Previous Tab", SwitchTabDownCommand
+ item "Next Tab", SwitchTabUpCommand
end
sub_menu "Help" do
item "Website", PrintHistoryCommand

0 comments on commit e7132d7

Please sign in to comment.