Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferyto committed Oct 16, 2017
2 parents e9aca90 + dec4306 commit bb78d6a
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 53 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# editorconfig.org

root = true

[*]
charset = utf-8
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
24 changes: 15 additions & 9 deletions Changelog → Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
v0.3.0 (2017-09-04):
# Changelog

## v0.3.1 (2017-10-17)
* Show a debug message if the settings schema could not be loaded
* Fixed division by zero error

## v0.3.0 (2017-09-04)
* Added a preference to change Ctrl-Tab to tabbar order, available
in gedit 3.4 and later
* Made the tab window now sized and positioned more reliably
Expand All @@ -13,32 +19,32 @@ v0.3.0 (2017-09-04):
again in the same gedit session, and a previously existing new
document tab is replaced by an opened file, in gedit 3.14 or later
* Fixed minor error if a file icon needed to be resized in gedit 3.10 or
earlier
earlier (originally fixed by nuclearmistake in #8)
* Ensure when the tab list popup appears it is scrolled to the top
* Made compatible with gedit 3.0
* Use python-gtk-utils for some plumbing

v0.2.3 (2013-05-08):
## v0.2.3 (2013-05-08)
* Gedit 3.8 / Python 3 compatibility (#4, thanks thapar!)
* Minor tweaks

v0.2.2 (2013-05-03):
## v0.2.2 (2013-05-03)
* Fixed minor bug when the document name contains HTML tags
* Minor tweaks

v0.2.1 (2012-10-26):
## v0.2.1 (2012-10-26)
* Minor tweaks

v0.2.0 (2011-11-18):
## v0.2.0 (2011-11-18)
* Works with, and requires, gedit 3.2

v0.1.2 (2010-06-21):
## v0.1.2 (2010-06-21)
* Fixed error when an icon cannot be loaded for a tab state (e.g. when
an icon is missing from the current theme)

v0.1.1 (2010-03-03):
## v0.1.1 (2010-03-03)
* Fixed error when switching tabs after an open file has been deleted
(but the tab is still open with the file)

v0.1.0 (2010-02-25):
## v0.1.0 (2010-02-25)
* Initial release
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Control Your Tabs, a plugin for gedit #
# Control Your Tabs, a plugin for gedit

Switch between document tabs using Ctrl+Tab / Ctrl+Shift+Tab and
Ctrl+PageUp / Ctrl+PageDown
<https://github.com/jefferyto/gedit-control-your-tabs>
v0.3.0
v0.3.1

All bug reports, feature requests and miscellaneous comments are welcome
at the [project issue tracker][].

## Requirements ##
## Requirements

v0.2.0 and higher requires gedit 3. The last version compatible with
gedit 2 is [v0.1.2][].

## Installation ##
## Installation

1. Download the source code (as [zip][] or [tar.gz][]) and extract.
2. Copy the `controlyourtabs` folder and the appropriate `.plugin` file
Expand All @@ -24,15 +24,15 @@ gedit 2 is [v0.1.2][].
3. Restart gedit, then enable the plugin in the **Plugins** tab in
gedit's **Preferences** window.

## Usage ##
## Usage

* <kbd>Ctrl</kbd>+<kbd>Tab</kbd> /
<kbd>Ctrl</kbd>+<kbd>Shift</kbd >+<kbd>Tab</kbd> - Switch tabs in
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Tab</kbd> - Switch tabs in
most recently used order.
* <kbd>Ctrl</kbd>+<kbd>Page Up</kbd> /
<kbd>Ctrl</kbd>+<kbd>Page Down</kbd> - Switch tabs in tabbar order.

## Preferences ##
## Preferences

In gedit 3.4 or later, the plugin supports these preferences:

Expand All @@ -41,21 +41,21 @@ In gedit 3.4 or later, the plugin supports these preferences:
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Tab</kbd> to switch tabs in
tabbar order instead of most recently used order.

## Development ##
## Development

The code in `controlyourtabs/utils` comes from [python-gtk-utils][];
changes should ideally be contributed to that project, then pulled back
into this one with `git subtree pull`.

## Credits ##
## Credits

Inspired by:

* [TabSwitch][] by Elia Sarti
* [TabPgUpPgDown][] by Eran M.
* the gedit Documents panel

## License ##
## License

Copyright &copy; 2010-2014, 2016-2017 Jeffery To <jeffery.to@gmail.com>

Expand Down
2 changes: 1 addition & 1 deletion controlyourtabs.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Description=Switch between document tabs using Ctrl+Tab / Ctrl+Shift+Tab and Ctr
Authors=Jeffery To <jeffery.to@gmail.com>
Copyright=Copyright © 2010-2014, 2016-2017 Jeffery To
Website=https://github.com/jefferyto/gedit-control-your-tabs
Version=0.3.0
Version=0.3.1
2 changes: 1 addition & 1 deletion controlyourtabs.plugin.python2
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Description=Switch between document tabs using Ctrl+Tab / Ctrl+Shift+Tab and Ctr
Authors=Jeffery To <jeffery.to@gmail.com>
Copyright=Copyright © 2010-2014, 2016-2017 Jeffery To
Website=https://github.com/jefferyto/gedit-control-your-tabs
Version=0.3.0
Version=0.3.1
73 changes: 47 additions & 26 deletions controlyourtabs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gedit', '3.0')

import gettext
import math
import os.path
from gi.repository import GObject, Gtk, Gdk, GdkPixbuf, Gio, GtkSource, Gedit, PeasGtk
from gi.repository import GObject, GLib, Gtk, Gdk, GdkPixbuf, Gio, GtkSource, Gedit, PeasGtk
from xml.sax.saxutils import escape
from .utils import connect_handlers, disconnect_handlers

GETTEXT_PACKAGE = 'gedit-control-your-tabs'
BASE_PATH = os.path.dirname(os.path.realpath(__file__))
LOCALE_PATH = os.path.join(BASE_PATH, 'locale')

gettext.bindtextdomain(GETTEXT_PACKAGE, LOCALE_PATH)
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
try:
gettext.bindtextdomain(GETTEXT_PACKAGE, LOCALE_PATH)
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
except:
_ = lambda s: s


class ControlYourTabsPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
__gtype_name__ = 'ControlYourTabsPlugin'
Expand All @@ -40,12 +48,12 @@ class ControlYourTabsPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Con

SELECTED_TAB_COLUMN = 3

META_KEYS = ('Shift_L', 'Shift_R',
META_KEYS = ['Shift_L', 'Shift_R',
'Control_L', 'Control_R',
'Meta_L', 'Meta_R',
'Super_L', 'Super_R',
'Hyper_L', 'Hyper_R',
'Alt_L', 'Alt_R')
'Alt_L', 'Alt_R']
# Compose, Apple?

MAX_TAB_WINDOW_ROWS = 9
Expand Down Expand Up @@ -183,7 +191,7 @@ def do_activate(self):
if self._multi:
self.on_window_active_tab_changed(window, tab, notebooks, view)
else:
connect_handlers(self, window, ('tab-added',), 'window')
connect_handlers(self, window, ['tab-added'], 'window')

def do_deactivate(self):
window = self.window
Expand Down Expand Up @@ -232,8 +240,8 @@ def do_create_configure_widget(self):
if settings:
widget = Gtk.CheckButton(_("Use tabbar order for Ctrl+Tab / Ctrl+Shift+Tab"))
widget.set_active(settings.get_boolean(self.USE_TABBAR_ORDER))
connect_handlers(self, widget, ('toggled',), 'configure_check_button', settings)
connect_handlers(self, settings, ('changed::' + self.USE_TABBAR_ORDER,), 'configure_settings', widget)
connect_handlers(self, widget, ['toggled'], 'configure_check_button', settings)
connect_handlers(self, settings, ['changed::' + self.USE_TABBAR_ORDER], 'configure_settings', widget)
else:
widget = Gtk.Box()
widget.add(Gtk.Label(_("Sorry, no preferences are available for this version of gedit.")))
Expand Down Expand Up @@ -270,8 +278,8 @@ def _setup(self, window, tab, notebooks, view):
for doc in window.get_documents():
self.on_multi_notebook_notebook_added(multi, Gedit.Tab.get_from_document(doc).get_parent(), notebooks, view)

connect_handlers(self, multi, ('notebook-added', 'notebook-removed', 'tab-added', 'tab-removed'), 'multi_notebook', notebooks, view)
connect_handlers(self, window, ('tabs-reordered', 'active-tab-changed', 'key-press-event', 'key-release-event', 'focus-out-event', 'configure-event'), 'window', notebooks, view)
connect_handlers(self, multi, ['notebook-added', 'notebook-removed', 'tab-added', 'tab-removed'], 'multi_notebook', notebooks, view)
connect_handlers(self, window, ['tabs-reordered', 'active-tab-changed', 'key-press-event', 'key-release-event', 'focus-out-event', 'configure-event'], 'window', notebooks, view)

else:
try:
Expand All @@ -285,8 +293,8 @@ def _setup(self, window, tab, notebooks, view):
def on_multi_notebook_notebook_added(self, multi, notebook, notebooks, view):
if notebook not in notebooks:
model = Gtk.ListStore(GdkPixbuf.Pixbuf, str, Gedit.Tab, 'gboolean')
connect_handlers(self, model, ('row-inserted', 'row-deleted', 'row-changed'), 'model', view, view.get_selection())
notebooks[notebook] = [[], model]
connect_handlers(self, model, ['row-inserted', 'row-deleted', 'row-changed'], 'model', view, view.get_selection())
notebooks[notebook] = ([], model)

for tab in notebook.get_children():
self.on_multi_notebook_tab_added(multi, notebook, tab, notebooks, view)
Expand All @@ -297,7 +305,7 @@ def on_multi_notebook_notebook_removed(self, multi, notebook, notebooks, view):
self.on_multi_notebook_tab_removed(multi, notebook, tab, notebooks, view)

stack, model = notebooks[notebook]
if view.get_model() == model:
if view.get_model() is model:
view.set_model(None)
disconnect_handlers(self, model)
del notebooks[notebook]
Expand All @@ -306,8 +314,8 @@ def on_multi_notebook_tab_added(self, multi, notebook, tab, notebooks, view):
stack, model = notebooks[notebook]
if tab not in stack:
stack.append(tab)
model.append([self._get_tab_icon(tab), self._get_tab_name(tab), tab, False])
connect_handlers(self, tab, ('notify::name', 'notify::state'), self.on_sync_icon_and_name, notebooks)
model.append((self._get_tab_icon(tab), self._get_tab_name(tab), tab, False))
connect_handlers(self, tab, ['notify::name', 'notify::state'], self.on_sync_icon_and_name, notebooks)

def on_multi_notebook_tab_removed(self, multi, notebook, tab, notebooks, view):
stack, model = notebooks[notebook]
Expand All @@ -334,7 +342,7 @@ def on_window_active_tab_changed(self, window, tab, notebooks, view):
if not self._switching:
stack, model = notebooks[tab.get_parent()]

if view.get_model() != model:
if view.get_model() is not model:
view.set_model(model)
self._schedule_tabwin_resize()

Expand All @@ -346,7 +354,7 @@ def on_window_active_tab_changed(self, window, tab, notebooks, view):
model.move_after(model.get_iter(stack.index(tab)), None)
stack.remove(tab)
else:
model.insert(0, [self._get_tab_icon(tab), self._get_tab_name(tab), tab, False])
model.insert(0, (self._get_tab_icon(tab), self._get_tab_name(tab), tab, False))

stack.insert(0, tab)
model[0][self.SELECTED_TAB_COLUMN] = True
Expand All @@ -369,9 +377,9 @@ def on_window_key_press_event(self, window, event, notebooks, view):

is_ctrl = state == Gdk.ModifierType.CONTROL_MASK
is_ctrl_shift = state == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK
is_tab_key = key in ('ISO_Left_Tab', 'Tab')
is_page_key = key in ('Page_Up', 'Page_Down')
is_up_dir = key in ('ISO_Left_Tab', 'Page_Up')
is_tab_key = key in ['ISO_Left_Tab', 'Tab']
is_page_key = key in ['Page_Up', 'Page_Down']
is_up_dir = key in ['ISO_Left_Tab', 'Page_Up']

if not (((is_ctrl or is_ctrl_shift) and is_tab_key) or (is_ctrl and is_page_key)):
self._end_switching()
Expand Down Expand Up @@ -445,15 +453,15 @@ def _end_switching(self):
self.on_window_active_tab_changed(window, tab, self._notebooks, self._view)

def on_model_row_inserted(self, model, path, iter, view, sel):
if view.get_model() == model:
if view.get_model() is model:
self._schedule_tabwin_resize()

def on_model_row_deleted(self, model, path, view, sel):
if view.get_model() == model:
if view.get_model() is model:
self._schedule_tabwin_resize()

def on_model_row_changed(self, model, path, iter, view, sel):
if view.get_model() == model:
if view.get_model() is model:
if model[path][self.SELECTED_TAB_COLUMN]:
sel.select_path(path)
view.scroll_to_cell(path, None, True, 0.5, 0)
Expand Down Expand Up @@ -600,11 +608,17 @@ def _schedule_tabwin_resize(self):
# need to wait a little before asking the treeview for its preferred size
# maybe because treeview rendering is async?
# this feels like a giant hack
self._tabwin_resize_id = GObject.idle_add(self._do_tabwin_resize)
try:
resize_id = GLib.idle_add(self._do_tabwin_resize)
except TypeError:
# gedit 3.0
resize_id = GObject.idle_add(self._do_tabwin_resize)

self._tabwin_resize_id = resize_id

def _cancel_tabwin_resize(self):
if self._tabwin_resize_id:
GObject.source_remove(self._tabwin_resize_id)
GLib.source_remove(self._tabwin_resize_id)
self._tabwin_resize_id = None

def _do_tabwin_resize(self):
Expand All @@ -614,7 +628,7 @@ def _do_tabwin_resize(self):
view_min_size, view_nat_size = view.get_preferred_size()
view_height = max(view_min_size.height, view_nat_size.height)

num_rows = len(view.get_model())
num_rows = max(len(view.get_model()), 2)
row_height = math.ceil(view_height / num_rows)
max_rows_height = self.MAX_TAB_WINDOW_ROWS * row_height

Expand Down Expand Up @@ -643,6 +657,7 @@ def _do_tabwin_resize(self):
self._tabwin.set_size_request(tabwin_width, tabwin_height)

self._tabwin_resize_id = None
return False


# misc
Expand All @@ -665,4 +680,10 @@ def _get_settings(self):
settings = Gio.Settings.new_full(schema, None, None) if schema else None
except AttributeError:
settings = None
except:
try:
Gedit.debug_plugin_message("could not load settings schema from %s", schemas_path)
except AttributeError:
pass
settings = None
return settings
12 changes: 6 additions & 6 deletions controlyourtabs/locale/gedit-control-your-tabs.pot
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: gedit-control-your-tabs 0.3.0\n"
"POT-Creation-Date: 2017-08-26 20:26+0800\n"
"Project-Id-Version: gedit-control-your-tabs 0.3.1\n"
"POT-Creation-Date: 2017-10-17 03:56+0800\n"
"PO-Revision-Date: 2014-12-03 21:27+0800\n"
"Last-Translator: Jeffery To <jeffery.to@gmail.com>\n"
"Language-Team: \n"
Expand All @@ -16,18 +16,18 @@ msgstr ""
"X-Poedit-SearchPathExcluded-0: schemas\n"
"X-Poedit-SearchPathExcluded-1: utils\n"

#: __init__.py:129
#: __init__.py:143
msgid "Documents"
msgstr ""

#: __init__.py:205
#: __init__.py:241
msgid "Use tabbar order for Ctrl+Tab / Ctrl+Shift+Tab"
msgstr ""

#: __init__.py:211
#: __init__.py:247
msgid "Sorry, no preferences are available for this version of gedit."
msgstr ""

#: __init__.py:433
#: __init__.py:503
msgid "Read-Only"
msgstr ""

0 comments on commit bb78d6a

Please sign in to comment.