diff --git a/gertty/view/change.py b/gertty/view/change.py index 110aee2..5beae5b 100644 --- a/gertty/view/change.py +++ b/gertty/view/change.py @@ -24,6 +24,7 @@ from gertty import mywid from gertty import sync from gertty.view import side_diff as view_side_diff from gertty.view import unified_diff as view_unified_diff +from gertty.view import mouse_scroll_decorator import gertty.view class EditTopicDialog(mywid.ButtonDialog): @@ -389,6 +390,7 @@ class CommitMessageBox(mywid.HyperText): text = commentlink.run(self.app, text) super(CommitMessageBox, self).set_text(text) +@mouse_scroll_decorator.ScrollByWheel class ChangeView(urwid.WidgetWrap): def help(self): key = self.app.config.keymap.formatKeys diff --git a/gertty/view/change_list.py b/gertty/view/change_list.py index 75ed089..447753e 100644 --- a/gertty/view/change_list.py +++ b/gertty/view/change_list.py @@ -21,6 +21,7 @@ from gertty import keymap from gertty import mywid from gertty import sync from gertty.view import change as view_change +from gertty.view import mouse_scroll_decorator import gertty.view @@ -139,6 +140,7 @@ class ChangeListHeader(urwid.WidgetWrap): for category in categories: self._w.contents.append((urwid.Text(' %s' % category[0]), self._w.options('given', 2))) +@mouse_scroll_decorator.ScrollByWheel class ChangeListView(urwid.WidgetWrap): def help(self): key = self.app.config.keymap.formatKeys diff --git a/gertty/view/diff.py b/gertty/view/diff.py index f4ee7b7..c266782 100644 --- a/gertty/view/diff.py +++ b/gertty/view/diff.py @@ -21,6 +21,7 @@ from gertty import keymap from gertty import mywid from gertty import gitrepo from gertty import sync +from gertty.view import mouse_scroll_decorator class PatchsetDialog(urwid.WidgetWrap): signals = ['ok', 'cancel'] @@ -145,6 +146,7 @@ class DiffContextButton(urwid.WidgetWrap): def next(self, button): self.view.expandChunk(self.diff, self.chunk, from_end=-10) +@mouse_scroll_decorator.ScrollByWheel class BaseDiffView(urwid.WidgetWrap): def help(self): key = self.app.config.keymap.formatKeys diff --git a/gertty/view/mouse_scroll_decorator.py b/gertty/view/mouse_scroll_decorator.py new file mode 100644 index 0000000..ffc0b0a --- /dev/null +++ b/gertty/view/mouse_scroll_decorator.py @@ -0,0 +1,33 @@ +# coding=utf8 +# +# Copyright 2014 Jan Kundrát <jkt@kde.org> +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +def mouse_event_scrolling(class_type): + def mouse_event_scrolling(self, size, event, button, col, row, focus): + if event == 'mouse press': + if button == 4: + self.keypress(size, 'up') + return True + if button == 5: + self.keypress(size, 'down') + return True + + return super(class_type, self).mouse_event(size, event, button, col, + row, focus) + return mouse_event_scrolling + +def ScrollByWheel(original_class): + original_class.mouse_event = mouse_event_scrolling(original_class) + return original_class diff --git a/gertty/view/project_list.py b/gertty/view/project_list.py index fe8fae0..abba444 100644 --- a/gertty/view/project_list.py +++ b/gertty/view/project_list.py @@ -20,6 +20,7 @@ from gertty import keymap from gertty import mywid from gertty import sync from gertty.view import change_list as view_change_list +from gertty.view import mouse_scroll_decorator class ProjectRow(urwid.Button): project_focus_map = {None: 'focused', @@ -67,6 +68,7 @@ class ProjectListHeader(urwid.WidgetWrap): (5, urwid.Text(u'Open'))] super(ProjectListHeader, self).__init__(urwid.Columns(cols)) +@mouse_scroll_decorator.ScrollByWheel class ProjectListView(urwid.WidgetWrap): def help(self): key = self.app.config.keymap.formatKeys