xed/plugins/snippets/snippets/__init__.py

102 lines
3.4 KiB
Python
Raw Normal View History

2011-11-07 16:52:18 -06:00
# Pluma snippets plugin
2011-11-07 13:46:58 -06:00
# Copyright (C) 2005-2006 Jesse van den Kieboom <jesse@icecrew.nl>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import sys
import os
import shutil
import gtk
2011-11-07 18:10:16 -06:00
from gtk import gdk
2011-11-07 16:52:18 -06:00
import pluma
2011-11-07 13:46:58 -06:00
import platform
from WindowHelper import WindowHelper
from Library import Library
from Manager import Manager
from Snippet import Snippet
2011-11-07 16:52:18 -06:00
class SnippetsPlugin(pluma.Plugin):
2011-11-07 13:46:58 -06:00
def __init__(self):
2011-11-07 16:52:18 -06:00
pluma.Plugin.__init__(self)
2011-11-07 13:46:58 -06:00
self.dlg = None
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
library = Library()
library.set_accelerator_callback(self.accelerator_activated)
if platform.platform() == 'Windows':
2011-11-07 16:52:18 -06:00
snippetsdir = os.path.expanduser('~/pluma/snippets')
2011-11-07 13:46:58 -06:00
else:
userdir = os.getenv('MATE22_USER_DIR')
if userdir:
2011-11-07 16:52:18 -06:00
snippetsdir = os.path.join(userdir, 'pluma/snippets')
2011-11-07 13:46:58 -06:00
else:
2011-11-07 18:10:16 -06:00
snippetsdir = os.path.expanduser('~/.config/pluma/snippets')
2011-11-07 13:46:58 -06:00
library.set_dirs(snippetsdir, self.system_dirs())
def system_dirs(self):
if platform.platform() != 'Windows':
if 'XDG_DATA_DIRS' in os.environ:
datadirs = os.environ['XDG_DATA_DIRS']
else:
datadirs = '/usr/local/share' + os.pathsep + '/usr/share'
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
dirs = []
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
for d in datadirs.split(os.pathsep):
2011-11-07 18:10:16 -06:00
d = os.path.join(d, 'pluma', 'plugins', 'snippets')
2011-11-07 13:46:58 -06:00
if os.path.isdir(d):
dirs.append(d)
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
dirs.append(self.get_data_dir())
return dirs
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
def activate(self, window):
data = WindowHelper(self)
window._snippets_plugin_data = data
data.run(window)
def deactivate(self, window):
window._snippets_plugin_data.stop()
window._snippets_plugin_data = None
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
def update_ui(self, window):
window._snippets_plugin_data.update()
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
def create_configure_dialog(self):
if not self.dlg:
self.dlg = Manager(self.get_data_dir())
else:
self.dlg.run()
2011-11-07 18:10:16 -06:00
2011-11-07 16:52:18 -06:00
window = pluma.app_get_default().get_active_window()
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
if window:
self.dlg.dlg.set_transient_for(window)
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
return self.dlg.dlg
2011-11-07 18:10:16 -06:00
2011-11-07 13:46:58 -06:00
def accelerator_activated(self, group, obj, keyval, mod):
ret = False
if hasattr(obj, '_snippets_plugin_data'):
ret = obj._snippets_plugin_data.accelerator_activated(keyval, mod)
return ret