Permalink
Browse files

Close the tab under cursor on middle mouse button click

  • Loading branch information...
1 parent d60c7ff commit 34bb067e973d1987e35c29395e5f466b2c697397 @kattrali kattrali committed May 26, 2012
Showing with 28 additions and 2 deletions.
  1. +28 −2 plugins/application_swt/lib/application_swt/notebook.rb
View
30 plugins/application_swt/lib/application_swt/notebook.rb
@@ -4,7 +4,32 @@ class Notebook
include Redcar::Observable
attr_reader :tab_folder, :model
-
+
+ # Closes the tab under the cursor when the middle
+ # mouse button is released
+ class MiddleMouseListener
+ def initialize(controller)
+ @controller = controller
+ end
+
+ def mouseDown e
+ end
+
+ def mouseDoubleClick e
+ end
+
+ def mouseUp(event)
+ if event.button == 2 # middle mouse button == 2?
@mscharley
mscharley Jun 8, 2012

Historically, they were numbered numerically. For a long time, mice only ever had 2 buttons. Left was 0, right was 1. When a third was added, it became 2. Too bad it was in the middle of the mouse :(

@kattrali
kattrali Jun 8, 2012

That makes more sense than the explanation I guessed. :)

+ point = Swt::Graphics::Point.new(event.x,event.y)
+ item = @controller.tab_folder.getItem(point)
+ tab = @controller.tab_widget_to_tab_model(item)
+ unless Redcar.app.events.ignore?(:tab_close, tab)
+ Redcar.app.events.create(:tab_close, tab)
+ end
+ end
+ end
+ end
+
class CTabFolder2Listener
def initialize(controller)
@controller = controller
@@ -71,7 +96,7 @@ def create_tab_folder(sash)
@tab_folder.pack
register_tab_dnd(@tab_folder)
end
-
+
def register_tab_dnd(tab_folder)
dnd_listener = TabDragAndDropListener.new(self)
operations = (Swt::DND::DND::DROP_COPY | Swt::DND::DND::DROP_DEFAULT | Swt::DND::DND::DROP_MOVE)
@@ -104,6 +129,7 @@ def attach_model_listeners
def attach_view_listeners
@tab_folder.add_ctab_folder2_listener(CTabFolder2Listener.new(self))
@tab_folder.add_selection_listener(SelectionListener.new(self))
+ @tab_folder.addMouseListener(MiddleMouseListener.new(self))
@tab_folder.add_listener(Swt::SWT::MenuDetect) do |event|
point = ApplicationSWT.display.map(nil, @tab_folder, Swt::Graphics::Point.new(event.x, event.y))
if item = @tab_folder.getItem(point)

0 comments on commit 34bb067

Please sign in to comment.