|
|
8f91ed |
From 2315024697904bc00c01caa42e042983491f98f1 Mon Sep 17 00:00:00 2001
|
|
|
8f91ed |
From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= <mcepl@redhat.com>
|
|
|
6f95c4 |
Date: Fri, 15 May 2015 11:00:19 -0400
|
|
|
6f95c4 |
Subject: [PATCH] Switch from python3 to python2
|
|
|
6f95c4 |
|
|
|
6f95c4 |
---
|
|
|
6f95c4 |
configure.ac | 2 +-
|
|
|
6f95c4 |
gedit/gedit-plugins-engine.c | 2 +-
|
|
|
6f95c4 |
plugins/externaltools/data/send-to-fpaste.tool.in | 2 +-
|
|
|
6f95c4 |
plugins/externaltools/externaltools.plugin.desktop.in | 2 +-
|
|
|
8f91ed |
plugins/externaltools/tools/capture.py | 8 ++++++-
|
|
|
8f91ed |
plugins/externaltools/tools/library.py | 27 ++++++++++++++++------
|
|
|
6f95c4 |
plugins/pythonconsole/pythonconsole.plugin.desktop.in | 2 +-
|
|
|
6f95c4 |
plugins/quickopen/quickopen.plugin.desktop.in | 2 +-
|
|
|
8f91ed |
plugins/quickopen/quickopen/__init__.py | 5 ++--
|
|
|
6f95c4 |
plugins/snippets/snippets.plugin.desktop.in | 2 +-
|
|
|
8f91ed |
plugins/snippets/snippets/helper.py | 5 +++-
|
|
|
6f95c4 |
plugins/snippets/snippets/library.py | 3 ++-
|
|
|
6f95c4 |
plugins/snippets/snippets/shareddata.py | 3 ++-
|
|
|
6f95c4 |
plugins/snippets/snippets/signals.py | 2 +-
|
|
|
8f91ed |
14 files changed, 46 insertions(+), 21 deletions(-)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
diff --git a/configure.ac b/configure.ac
|
|
|
6f95c4 |
index cf3d734..3acee28 100644
|
|
|
6f95c4 |
--- a/configure.ac
|
|
|
6f95c4 |
+++ b/configure.ac
|
|
|
6f95c4 |
@@ -276,61 +276,61 @@ if test "x$enable_enchant" = "xyes" ; then
|
|
|
6f95c4 |
have_iso_codes=no
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
AC_MSG_RESULT([$result])
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if test "x$have_iso_codes" = "xyes"; then
|
|
|
6f95c4 |
AC_DEFINE_UNQUOTED([ISO_CODES_PREFIX],["`$PKG_CONFIG --variable=prefix iso-codes`"],[ISO codes prefix])
|
|
|
6f95c4 |
AC_DEFINE([HAVE_ISO_CODES],[1],[Define if you have the iso-codes package])
|
|
|
6f95c4 |
else
|
|
|
6f95c4 |
AC_MSG_ERROR([iso-codes is required to build the spell plugin. Use --disable-spell to build without spell plugin.])
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
else
|
|
|
6f95c4 |
enable_enchant=no
|
|
|
6f95c4 |
AC_MSG_ERROR([Enchant library not found or too old. Use --disable-spell to build without spell plugin.])
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
|
|
|
6f95c4 |
AM_CONDITIONAL(ENABLE_ENCHANT, test x"$enable_enchant" = "xyes")
|
|
|
6f95c4 |
|
|
|
6f95c4 |
AC_ARG_ENABLE([python],
|
|
|
6f95c4 |
AS_HELP_STRING([--enable-python[=@<:@no/auto/yes@:>@]],[Build with python support]),
|
|
|
6f95c4 |
[enable_python=$enableval],
|
|
|
6f95c4 |
[enable_python="auto"])
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if test "x$enable_python" = "xauto"; then
|
|
|
6f95c4 |
PKG_CHECK_EXISTS([pygobject-3.0 >= $PYGOBJECT_REQUIRED],
|
|
|
6f95c4 |
[enable_python=yes],[enable_python=no])
|
|
|
f620a9 |
fi
|
|
|
f620a9 |
|
|
|
f620a9 |
if test "x$enable_python" = "xyes"; then
|
|
|
f620a9 |
- AM_PATH_PYTHON(3.2.3)
|
|
|
f620a9 |
+ AM_PATH_PYTHON
|
|
|
f620a9 |
PKG_CHECK_MODULES(PYTHON, [pygobject-3.0 >= $PYGOBJECT_REQUIRED])
|
|
|
f620a9 |
|
|
|
6f95c4 |
pyoverridesdir="\$(pyexecdir)/gi/overrides"
|
|
|
6f95c4 |
AC_SUBST(pyoverridesdir)
|
|
|
6f95c4 |
fi
|
|
|
6f95c4 |
|
|
|
6f95c4 |
AM_CONDITIONAL(ENABLE_PYTHON, test x"$enable_python" = "xyes")
|
|
|
6f95c4 |
|
|
|
6f95c4 |
dnl ================================================================
|
|
|
6f95c4 |
dnl Start of pkg-config checks
|
|
|
6f95c4 |
dnl ================================================================
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# Dependencies
|
|
|
6f95c4 |
|
|
|
6f95c4 |
PKG_CHECK_MODULES(GEDIT, [
|
|
|
6f95c4 |
libxml-2.0 >= $LIBXML_REQUIRED
|
|
|
6f95c4 |
glib-2.0 >= $GLIB_REQUIRED
|
|
|
6f95c4 |
gio-2.0 >= $GLIB_REQUIRED
|
|
|
6f95c4 |
gmodule-2.0
|
|
|
6f95c4 |
gtk+-3.0 >= $GTK_REQUIRED
|
|
|
6f95c4 |
gtksourceview-3.0 >= $GTKSOURCEVIEW_REQUIRED
|
|
|
6f95c4 |
libpeas-1.0 >= $LIBPEAS_REQUIRED
|
|
|
6f95c4 |
libpeas-gtk-1.0 >= $LIBPEAS_REQUIRED
|
|
|
6f95c4 |
gsettings-desktop-schemas
|
|
|
6f95c4 |
])
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if test "$os_osx" = "no" &&
|
|
|
6f95c4 |
test "$os_win32" = "no"; then
|
|
|
6f95c4 |
PKG_CHECK_MODULES(X11, [
|
|
|
6f95c4 |
x11
|
|
|
6f95c4 |
diff --git a/gedit/gedit-plugins-engine.c b/gedit/gedit-plugins-engine.c
|
|
|
6f95c4 |
index 725cb3b..678809b 100644
|
|
|
6f95c4 |
--- a/gedit/gedit-plugins-engine.c
|
|
|
6f95c4 |
+++ b/gedit/gedit-plugins-engine.c
|
|
|
6f95c4 |
@@ -28,61 +28,61 @@
|
|
|
6f95c4 |
#include <string.h>
|
|
|
6f95c4 |
|
|
|
6f95c4 |
#include <glib/gi18n.h>
|
|
|
6f95c4 |
#include <girepository.h>
|
|
|
6f95c4 |
|
|
|
6f95c4 |
#include "gedit-debug.h"
|
|
|
6f95c4 |
#include "gedit-app.h"
|
|
|
6f95c4 |
#include "gedit-dirs.h"
|
|
|
6f95c4 |
#include "gedit-settings.h"
|
|
|
6f95c4 |
#include "gedit-utils.h"
|
|
|
6f95c4 |
|
|
|
6f95c4 |
struct _GeditPluginsEnginePrivate
|
|
|
6f95c4 |
{
|
|
|
6f95c4 |
GSettings *plugin_settings;
|
|
|
6f95c4 |
};
|
|
|
6f95c4 |
|
|
|
6f95c4 |
G_DEFINE_TYPE_WITH_PRIVATE (GeditPluginsEngine, gedit_plugins_engine, PEAS_TYPE_ENGINE)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
GeditPluginsEngine *default_engine = NULL;
|
|
|
6f95c4 |
|
|
|
6f95c4 |
static void
|
|
|
6f95c4 |
gedit_plugins_engine_init (GeditPluginsEngine *engine)
|
|
|
6f95c4 |
{
|
|
|
6f95c4 |
gchar *typelib_dir;
|
|
|
6f95c4 |
GError *error = NULL;
|
|
|
6f95c4 |
|
|
|
6f95c4 |
gedit_debug (DEBUG_PLUGINS);
|
|
|
6f95c4 |
|
|
|
6f95c4 |
engine->priv = gedit_plugins_engine_get_instance_private (engine);
|
|
|
f620a9 |
|
|
|
f620a9 |
- peas_engine_enable_loader (PEAS_ENGINE (engine), "python3");
|
|
|
f620a9 |
+ peas_engine_enable_loader (PEAS_ENGINE (engine), "python");
|
|
|
f620a9 |
|
|
|
f620a9 |
engine->priv->plugin_settings = g_settings_new ("org.gnome.gedit.plugins");
|
|
|
f620a9 |
|
|
|
6f95c4 |
/* Require gedit's typelib. */
|
|
|
6f95c4 |
typelib_dir = g_build_filename (gedit_dirs_get_gedit_lib_dir (),
|
|
|
6f95c4 |
"girepository-1.0",
|
|
|
6f95c4 |
NULL);
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if (!g_irepository_require_private (g_irepository_get_default (),
|
|
|
6f95c4 |
typelib_dir, "Gedit", "3.0", 0, &error))
|
|
|
6f95c4 |
{
|
|
|
6f95c4 |
g_warning ("Could not load Gedit repository: %s", error->message);
|
|
|
6f95c4 |
g_error_free (error);
|
|
|
6f95c4 |
error = NULL;
|
|
|
6f95c4 |
}
|
|
|
6f95c4 |
|
|
|
6f95c4 |
g_free (typelib_dir);
|
|
|
6f95c4 |
|
|
|
6f95c4 |
/* This should be moved to libpeas */
|
|
|
6f95c4 |
if (!g_irepository_require (g_irepository_get_default (),
|
|
|
6f95c4 |
"Peas", "1.0", 0, &error))
|
|
|
6f95c4 |
{
|
|
|
6f95c4 |
g_warning ("Could not load Peas repository: %s", error->message);
|
|
|
6f95c4 |
g_error_free (error);
|
|
|
6f95c4 |
error = NULL;
|
|
|
6f95c4 |
}
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if (!g_irepository_require (g_irepository_get_default (),
|
|
|
6f95c4 |
"PeasGtk", "1.0", 0, &error))
|
|
|
6f95c4 |
{
|
|
|
6f95c4 |
diff --git a/plugins/externaltools/data/send-to-fpaste.tool.in b/plugins/externaltools/data/send-to-fpaste.tool.in
|
|
|
6f95c4 |
index d255007..95c2d37 100755
|
|
|
6f95c4 |
--- a/plugins/externaltools/data/send-to-fpaste.tool.in
|
|
|
6f95c4 |
+++ b/plugins/externaltools/data/send-to-fpaste.tool.in
|
|
|
6f95c4 |
@@ -1,27 +1,27 @@
|
|
|
6f95c4 |
-#!/usr/bin/env python3
|
|
|
6f95c4 |
+#!/usr/bin/env python
|
|
|
6f95c4 |
|
|
|
6f95c4 |
import os, urllib, json, sys, urllib.request
|
|
|
6f95c4 |
from gi.repository import Gtk, Gdk
|
|
|
6f95c4 |
|
|
|
6f95c4 |
lang = os.getenv('GEDIT_CURRRENT_DOCUMENT_LANGUAGE')
|
|
|
6f95c4 |
if lang is None:
|
|
|
6f95c4 |
lang = "text"
|
|
|
6f95c4 |
|
|
|
6f95c4 |
current_document_path = os.getenv('GEDIT_CURRENT_DOCUMENT_PATH')
|
|
|
6f95c4 |
selected_text = os.getenv('GEDIT_SELECTED_TEXT')
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if selected_text is None:
|
|
|
6f95c4 |
selected_text = sys.stdin.read()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
url_params = urllib.parse.urlencode({'paste_data': selected_text, 'paste_lang': lang, 'mode':'json', 'api_submit':'true'})
|
|
|
6f95c4 |
openfpaste = urllib.request.urlopen("http://fpaste.org", bytes(url_params, 'utf-8')).read().decode("utf-8")
|
|
|
6f95c4 |
final_data = json.loads(openfpaste)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
paste_url = "http://fpaste.org/" + final_data['result']['id']
|
|
|
6f95c4 |
|
|
|
6f95c4 |
print(paste_url + " has been copied to clipboard.")
|
|
|
6f95c4 |
|
|
|
6f95c4 |
disp = Gdk.Display.get_default()
|
|
|
6f95c4 |
clipper = Gtk.Clipboard.get_for_display(disp, Gdk.SELECTION_CLIPBOARD)
|
|
|
6f95c4 |
clipper.set_text(paste_url, len(paste_url))
|
|
|
6f95c4 |
clipper.store()
|
|
|
6f95c4 |
diff --git a/plugins/externaltools/externaltools.plugin.desktop.in b/plugins/externaltools/externaltools.plugin.desktop.in
|
|
|
6f95c4 |
index cc7a4da..c56e4e3 100644
|
|
|
f620a9 |
--- a/plugins/externaltools/externaltools.plugin.desktop.in
|
|
|
f620a9 |
+++ b/plugins/externaltools/externaltools.plugin.desktop.in
|
|
|
6f95c4 |
@@ -1,9 +1,9 @@
|
|
|
f620a9 |
[Plugin]
|
|
|
f620a9 |
-Loader=python3
|
|
|
f620a9 |
+Loader=python
|
|
|
f620a9 |
Module=externaltools
|
|
|
f620a9 |
IAge=3
|
|
|
f620a9 |
_Name=External Tools
|
|
|
6f95c4 |
_Description=Execute external commands and shell scripts.
|
|
|
6f95c4 |
Authors=Steve Frécinaux <steve@istique.net>
|
|
|
6f95c4 |
Copyright=Copyright © 2005 Steve Frécinaux
|
|
|
6f95c4 |
Website=http://www.gedit.org
|
|
|
8f91ed |
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
|
|
|
8f91ed |
index 05fcf81..4a77e7a 100644
|
|
|
8f91ed |
--- a/plugins/externaltools/tools/capture.py
|
|
|
8f91ed |
+++ b/plugins/externaltools/tools/capture.py
|
|
|
8f91ed |
@@ -34,61 +34,67 @@ class Capture(GObject.Object):
|
|
|
8f91ed |
CAPTURE_NEEDS_SHELL = 0x04
|
|
|
8f91ed |
|
|
|
8f91ed |
WRITE_BUFFER_SIZE = 0x4000
|
|
|
8f91ed |
|
|
|
8f91ed |
__gsignals__ = {
|
|
|
8f91ed |
'stdout-line': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
|
|
|
8f91ed |
'stderr-line': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_STRING,)),
|
|
|
8f91ed |
'begin-execute': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, tuple()),
|
|
|
8f91ed |
'end-execute': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE, (GObject.TYPE_INT,))
|
|
|
8f91ed |
}
|
|
|
8f91ed |
|
|
|
8f91ed |
def __init__(self, command, cwd=None, env={}):
|
|
|
8f91ed |
GObject.GObject.__init__(self)
|
|
|
8f91ed |
self.pipe = None
|
|
|
8f91ed |
self.env = env
|
|
|
8f91ed |
self.cwd = cwd
|
|
|
8f91ed |
self.flags = self.CAPTURE_BOTH | self.CAPTURE_NEEDS_SHELL
|
|
|
8f91ed |
self.command = command
|
|
|
8f91ed |
self.input_text = None
|
|
|
8f91ed |
|
|
|
8f91ed |
def set_env(self, **values):
|
|
|
8f91ed |
self.env.update(**values)
|
|
|
8f91ed |
|
|
|
8f91ed |
def set_command(self, command):
|
|
|
8f91ed |
self.command = command
|
|
|
8f91ed |
|
|
|
8f91ed |
def set_flags(self, flags):
|
|
|
8f91ed |
self.flags = flags
|
|
|
8f91ed |
|
|
|
8f91ed |
def set_input(self, text):
|
|
|
8f91ed |
- self.input_text = text.encode("UTF-8") if text else None
|
|
|
8f91ed |
+ if text:
|
|
|
8f91ed |
+ if isinstance(text, bytes):
|
|
|
8f91ed |
+ self.input_text = text
|
|
|
8f91ed |
+ else:
|
|
|
8f91ed |
+ self.input_text = text.encode("UTF-8")
|
|
|
8f91ed |
+ else:
|
|
|
8f91ed |
+ self.input_text = None
|
|
|
8f91ed |
|
|
|
8f91ed |
def set_cwd(self, cwd):
|
|
|
8f91ed |
self.cwd = cwd
|
|
|
8f91ed |
|
|
|
8f91ed |
def execute(self):
|
|
|
8f91ed |
if self.command is None:
|
|
|
8f91ed |
return
|
|
|
8f91ed |
|
|
|
8f91ed |
# Initialize pipe
|
|
|
8f91ed |
popen_args = {
|
|
|
8f91ed |
'cwd': self.cwd,
|
|
|
8f91ed |
'shell': self.flags & self.CAPTURE_NEEDS_SHELL,
|
|
|
8f91ed |
'env': self.env
|
|
|
8f91ed |
}
|
|
|
8f91ed |
|
|
|
8f91ed |
if self.input_text is not None:
|
|
|
8f91ed |
popen_args['stdin'] = subprocess.PIPE
|
|
|
8f91ed |
if self.flags & self.CAPTURE_STDOUT:
|
|
|
8f91ed |
popen_args['stdout'] = subprocess.PIPE
|
|
|
8f91ed |
if self.flags & self.CAPTURE_STDERR:
|
|
|
8f91ed |
popen_args['stderr'] = subprocess.PIPE
|
|
|
8f91ed |
|
|
|
8f91ed |
self.tried_killing = False
|
|
|
8f91ed |
self.in_channel = None
|
|
|
8f91ed |
self.out_channel = None
|
|
|
8f91ed |
self.err_channel = None
|
|
|
8f91ed |
self.in_channel_id = 0
|
|
|
8f91ed |
self.out_channel_id = 0
|
|
|
8f91ed |
self.err_channel_id = 0
|
|
|
8f91ed |
|
|
|
6f95c4 |
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
|
|
|
8f91ed |
index adfd943..761337c 100644
|
|
|
6f95c4 |
--- a/plugins/externaltools/tools/library.py
|
|
|
6f95c4 |
+++ b/plugins/externaltools/tools/library.py
|
|
|
6f95c4 |
@@ -1,48 +1,49 @@
|
|
|
6f95c4 |
# -*- coding: utf-8 -*-
|
|
|
6f95c4 |
# Gedit External Tools plugin
|
|
|
6f95c4 |
# Copyright (C) 2006 Steve Frécinaux <code@istique.net>
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
6f95c4 |
# it under the terms of the GNU General Public License as published by
|
|
|
6f95c4 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
6f95c4 |
# (at your option) any later version.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is distributed in the hope that it will be useful,
|
|
|
6f95c4 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6f95c4 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6f95c4 |
# GNU General Public License for more details.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# You should have received a copy of the GNU General Public License
|
|
|
6f95c4 |
# along with this program; if not, write to the Free Software
|
|
|
6f95c4 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
6f95c4 |
|
|
|
6f95c4 |
+import io
|
|
|
6f95c4 |
import os
|
|
|
6f95c4 |
import re
|
|
|
6f95c4 |
import locale
|
|
|
6f95c4 |
import platform
|
|
|
6f95c4 |
from gi.repository import GLib
|
|
|
6f95c4 |
|
|
|
6f95c4 |
|
|
|
6f95c4 |
class Singleton(object):
|
|
|
6f95c4 |
_instance = None
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def __new__(cls, *args, **kwargs):
|
|
|
6f95c4 |
if not cls._instance:
|
|
|
6f95c4 |
cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
|
|
|
6f95c4 |
cls._instance.__init_once__()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
return cls._instance
|
|
|
6f95c4 |
|
|
|
6f95c4 |
|
|
|
6f95c4 |
class ToolLibrary(Singleton):
|
|
|
6f95c4 |
def __init_once__(self):
|
|
|
6f95c4 |
self.locations = []
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def set_locations(self, datadir):
|
|
|
6f95c4 |
self.locations = []
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if platform.platform() != 'Windows':
|
|
|
6f95c4 |
for d in self.get_xdg_data_dirs():
|
|
|
6f95c4 |
self.locations.append(os.path.join(d, 'gedit', 'plugins', 'externaltools', 'tools'))
|
|
|
6f95c4 |
|
|
|
6f95c4 |
self.locations.append(datadir)
|
|
|
6f95c4 |
@@ -219,61 +220,61 @@ class Tool(object):
|
|
|
6f95c4 |
self.changed = False
|
|
|
6f95c4 |
self._properties = dict()
|
|
|
6f95c4 |
self._transform = {
|
|
|
6f95c4 |
'Languages': [self._to_list, self._from_list]
|
|
|
6f95c4 |
}
|
|
|
6f95c4 |
self._load()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _to_list(self, value):
|
|
|
6f95c4 |
if value.strip() == '':
|
|
|
6f95c4 |
return []
|
|
|
6f95c4 |
else:
|
|
|
6f95c4 |
return [x.strip() for x in value.split(',')]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _from_list(self, value):
|
|
|
6f95c4 |
return ','.join(value)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _parse_value(self, key, value):
|
|
|
6f95c4 |
if key in self._transform:
|
|
|
6f95c4 |
return self._transform[key][0](value)
|
|
|
6f95c4 |
else:
|
|
|
6f95c4 |
return value
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _load(self):
|
|
|
6f95c4 |
if self.filename is None:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
|
|
|
6f95c4 |
filename = self.library.get_full_path(self.get_path())
|
|
|
6f95c4 |
if filename is None:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
|
|
|
6f95c4 |
- fp = open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
+ fp = io.open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
in_block = False
|
|
|
6f95c4 |
lang = locale.getlocale(locale.LC_MESSAGES)[0]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
for line in fp:
|
|
|
6f95c4 |
if not in_block:
|
|
|
6f95c4 |
in_block = line.startswith('# [Gedit Tool]')
|
|
|
6f95c4 |
continue
|
|
|
6f95c4 |
if line.startswith('##') or line.startswith('# #'):
|
|
|
6f95c4 |
continue
|
|
|
6f95c4 |
if not line.startswith('# '):
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
|
|
|
6f95c4 |
try:
|
|
|
6f95c4 |
(key, value) = [i.strip() for i in line[2:].split('=', 1)]
|
|
|
6f95c4 |
m = self.RE_KEY.match(key)
|
|
|
6f95c4 |
if m.group(3) is None:
|
|
|
6f95c4 |
self._properties[m.group(1)] = self._parse_value(m.group(1), value)
|
|
|
6f95c4 |
elif lang is not None and lang.startswith(m.group(3)):
|
|
|
6f95c4 |
self._properties[m.group(1)] = self._parse_value(m.group(1), value)
|
|
|
6f95c4 |
except ValueError:
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
fp.close()
|
|
|
6f95c4 |
self.changed = False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _set_property_if_changed(self, key, value):
|
|
|
6f95c4 |
if value != self._properties.get(key):
|
|
|
6f95c4 |
self._properties[key] = value
|
|
|
6f95c4 |
|
|
|
6f95c4 |
self.changed = True
|
|
|
6f95c4 |
|
|
|
8f91ed |
@@ -368,141 +369,153 @@ class Tool(object):
|
|
|
6f95c4 |
def get_save_files(self):
|
|
|
6f95c4 |
save_files = self._properties.get('Save-files')
|
|
|
6f95c4 |
if save_files:
|
|
|
6f95c4 |
return save_files
|
|
|
6f95c4 |
return 'nothing'
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def set_save_files(self, value):
|
|
|
6f95c4 |
self._set_property_if_changed('Save-files', value)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
save_files = property(get_save_files, set_save_files)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def get_languages(self):
|
|
|
6f95c4 |
languages = self._properties.get('Languages')
|
|
|
6f95c4 |
if languages:
|
|
|
6f95c4 |
return languages
|
|
|
6f95c4 |
return []
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def set_languages(self, value):
|
|
|
6f95c4 |
self._set_property_if_changed('Languages', value)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
languages = property(get_languages, set_languages)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def has_hash_bang(self):
|
|
|
6f95c4 |
if self.filename is None:
|
|
|
6f95c4 |
return True
|
|
|
6f95c4 |
|
|
|
6f95c4 |
filename = self.library.get_full_path(self.get_path())
|
|
|
6f95c4 |
if filename is None:
|
|
|
6f95c4 |
return True
|
|
|
6f95c4 |
|
|
|
6f95c4 |
- fp = open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
+ fp = io.open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
for line in fp:
|
|
|
6f95c4 |
if line.strip() == '':
|
|
|
6f95c4 |
continue
|
|
|
6f95c4 |
return line.startswith('#!')
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# There is no property for this one because this function is quite
|
|
|
6f95c4 |
# expensive to perform
|
|
|
6f95c4 |
def get_script(self):
|
|
|
6f95c4 |
if self.filename is None:
|
|
|
6f95c4 |
return ["#!/bin/sh\n"]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
filename = self.library.get_full_path(self.get_path())
|
|
|
6f95c4 |
if filename is None:
|
|
|
6f95c4 |
return ["#!/bin/sh\n"]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
- fp = open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
+ fp = io.open(filename, 'r', 1, encoding='utf-8')
|
|
|
6f95c4 |
lines = list()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# before entering the data block
|
|
|
6f95c4 |
for line in fp:
|
|
|
6f95c4 |
if line.startswith('# [Gedit Tool]'):
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
lines.append(line)
|
|
|
6f95c4 |
# in the block:
|
|
|
6f95c4 |
for line in fp:
|
|
|
6f95c4 |
if line.startswith('##'):
|
|
|
6f95c4 |
continue
|
|
|
6f95c4 |
if not (line.startswith('# ') and '=' in line):
|
|
|
6f95c4 |
# after the block: strip one emtpy line (if present)
|
|
|
6f95c4 |
if line.strip() != '':
|
|
|
6f95c4 |
lines.append(line)
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
# after the block
|
|
|
6f95c4 |
for line in fp:
|
|
|
6f95c4 |
lines.append(line)
|
|
|
6f95c4 |
fp.close()
|
|
|
6f95c4 |
return lines
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _dump_properties(self):
|
|
|
6f95c4 |
lines = ['# [Gedit Tool]']
|
|
|
6f95c4 |
for item in self._properties.items():
|
|
|
6f95c4 |
if item[0] in self._transform:
|
|
|
6f95c4 |
lines.append('# %s=%s' % (item[0], self._transform[item[0]][1](item[1])))
|
|
|
6f95c4 |
elif item[1] is not None:
|
|
|
6f95c4 |
lines.append('# %s=%s' % item)
|
|
|
6f95c4 |
return '\n'.join(lines) + '\n'
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def save_with_script(self, script):
|
|
|
6f95c4 |
filename = self.library.get_full_path(self.filename, 'w')
|
|
|
6f95c4 |
- fp = open(filename, 'w', 1, encoding='utf-8')
|
|
|
6f95c4 |
+ fp = io.open(filename, 'w', 1, encoding='utf-8')
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# Make sure to first print header (shebang, modeline), then
|
|
|
6f95c4 |
# properties, and then actual content
|
|
|
6f95c4 |
header = []
|
|
|
6f95c4 |
content = []
|
|
|
6f95c4 |
inheader = True
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# Parse
|
|
|
6f95c4 |
for line in script:
|
|
|
6f95c4 |
line = line.rstrip("\n")
|
|
|
6f95c4 |
if not inheader:
|
|
|
6f95c4 |
content.append(line)
|
|
|
6f95c4 |
elif line.startswith('#!'):
|
|
|
6f95c4 |
# Shebang (should be always present)
|
|
|
6f95c4 |
header.append(line)
|
|
|
6f95c4 |
elif line.strip().startswith('#') and ('-*-' in line or 'ex:' in line or 'vi:' in line or 'vim:' in line):
|
|
|
6f95c4 |
header.append(line)
|
|
|
6f95c4 |
else:
|
|
|
6f95c4 |
content.append(line)
|
|
|
6f95c4 |
inheader = False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
# Write out header
|
|
|
6f95c4 |
for line in header:
|
|
|
6f95c4 |
fp.write(line + "\n")
|
|
|
8f91ed |
+ if isinstance(line, bytes):
|
|
|
8f91ed |
+ line = unicode(line + "\n", 'utf8')
|
|
|
8f91ed |
+ else:
|
|
|
8f91ed |
+ line += u"\n"
|
|
|
8f91ed |
+ fp.write(line)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
- fp.write(self._dump_properties())
|
|
|
6f95c4 |
- fp.write("\n")
|
|
|
8f91ed |
+ outstr = self._dump_properties()
|
|
|
8f91ed |
+ if isinstance(outstr, bytes):
|
|
|
8f91ed |
+ outstr = unicode(outstr, 'utf8')
|
|
|
8f91ed |
+ fp.write(outstr)
|
|
|
6f95c4 |
+ fp.write(u"\n")
|
|
|
6f95c4 |
|
|
|
6f95c4 |
for line in content:
|
|
|
6f95c4 |
- fp.write(line + "\n")
|
|
|
8f91ed |
+ if isinstance(line, bytes):
|
|
|
8f91ed |
+ line = unicode(line + "\n", 'utf8')
|
|
|
8f91ed |
+ else:
|
|
|
8f91ed |
+ line += u"\n"
|
|
|
8f91ed |
+ fp.write(line)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
fp.close()
|
|
|
6f95c4 |
os.chmod(filename, 0o750)
|
|
|
6f95c4 |
self.changed = False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def save(self):
|
|
|
6f95c4 |
if self.changed:
|
|
|
6f95c4 |
self.save_with_script(self.get_script())
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def autoset_filename(self):
|
|
|
6f95c4 |
if self.filename is not None:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
dirname = self.parent.path
|
|
|
6f95c4 |
if dirname != '':
|
|
|
6f95c4 |
dirname += os.path.sep
|
|
|
6f95c4 |
|
|
|
6f95c4 |
basename = self.name.lower().replace(' ', '-').replace('/', '-')
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if self.library.get_full_path(dirname + basename):
|
|
|
6f95c4 |
i = 2
|
|
|
6f95c4 |
while self.library.get_full_path(dirname + "%s-%d" % (basename, i)):
|
|
|
6f95c4 |
i += 1
|
|
|
6f95c4 |
basename = "%s-%d" % (basename, i)
|
|
|
6f95c4 |
self.filename = basename
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if __name__ == '__main__':
|
|
|
6f95c4 |
library = ToolLibrary()
|
|
|
6f95c4 |
library.set_locations(os.path.expanduser("~/.config/gedit/tools"))
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def print_tool(t, indent):
|
|
|
6f95c4 |
diff --git a/plugins/pythonconsole/pythonconsole.plugin.desktop.in b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
|
|
|
6f95c4 |
index 21283e8..4309667 100644
|
|
|
f620a9 |
--- a/plugins/pythonconsole/pythonconsole.plugin.desktop.in
|
|
|
f620a9 |
+++ b/plugins/pythonconsole/pythonconsole.plugin.desktop.in
|
|
|
6f95c4 |
@@ -1,10 +1,10 @@
|
|
|
f620a9 |
[Plugin]
|
|
|
f620a9 |
-Loader=python3
|
|
|
f620a9 |
+Loader=python
|
|
|
f620a9 |
Module=pythonconsole
|
|
|
f620a9 |
IAge=3
|
|
|
f620a9 |
_Name=Python Console
|
|
|
6f95c4 |
_Description=Interactive Python console standing in the bottom panel
|
|
|
6f95c4 |
Icon=gnome-mime-text-x-python
|
|
|
6f95c4 |
Authors=Steve Frécinaux <steve@istique.net>
|
|
|
6f95c4 |
Copyright=Copyright © 2006 Steve Frécinaux
|
|
|
6f95c4 |
Website=http://www.gedit.org
|
|
|
6f95c4 |
diff --git a/plugins/quickopen/quickopen.plugin.desktop.in b/plugins/quickopen/quickopen.plugin.desktop.in
|
|
|
6f95c4 |
index 68b6faa..17edecc 100644
|
|
|
f620a9 |
--- a/plugins/quickopen/quickopen.plugin.desktop.in
|
|
|
f620a9 |
+++ b/plugins/quickopen/quickopen.plugin.desktop.in
|
|
|
6f95c4 |
@@ -1,10 +1,10 @@
|
|
|
f620a9 |
[Plugin]
|
|
|
f620a9 |
-Loader=python3
|
|
|
f620a9 |
+Loader=python
|
|
|
f620a9 |
Module=quickopen
|
|
|
f620a9 |
IAge=3
|
|
|
f620a9 |
_Name=Quick Open
|
|
|
6f95c4 |
_Description=Quickly open files
|
|
|
6f95c4 |
Icon=gtk-open
|
|
|
6f95c4 |
Authors=Jesse van den Kieboom <jessevdk@gnome.org>
|
|
|
6f95c4 |
Copyright=Copyright © 2009 Jesse van den Kieboom
|
|
|
6f95c4 |
Website=http://www.gedit.org
|
|
|
8f91ed |
diff --git a/plugins/quickopen/quickopen/__init__.py b/plugins/quickopen/quickopen/__init__.py
|
|
|
8f91ed |
index b8b54b0..f5e179f 100644
|
|
|
8f91ed |
--- a/plugins/quickopen/quickopen/__init__.py
|
|
|
8f91ed |
+++ b/plugins/quickopen/quickopen/__init__.py
|
|
|
8f91ed |
@@ -1,48 +1,49 @@
|
|
|
8f91ed |
# -*- coding: utf-8 -*-
|
|
|
8f91ed |
|
|
|
8f91ed |
# Copyright (C) 2009 - Jesse van den Kieboom
|
|
|
8f91ed |
#
|
|
|
8f91ed |
# This program is free software; you can redistribute it and/or modify
|
|
|
8f91ed |
# it under the terms of the GNU General Public License as published by
|
|
|
8f91ed |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
8f91ed |
# (at your option) any later version.
|
|
|
8f91ed |
#
|
|
|
8f91ed |
# This program is distributed in the hope that it will be useful,
|
|
|
8f91ed |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8f91ed |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
8f91ed |
# GNU General Public License for more details.
|
|
|
8f91ed |
#
|
|
|
8f91ed |
# You should have received a copy of the GNU General Public License
|
|
|
8f91ed |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
8f91ed |
|
|
|
8f91ed |
from .popup import Popup
|
|
|
8f91ed |
+import io
|
|
|
8f91ed |
import os
|
|
|
8f91ed |
from gi.repository import GObject, Gio, GLib, Gtk, Gedit
|
|
|
8f91ed |
from .virtualdirs import RecentDocumentsDirectory
|
|
|
8f91ed |
from .virtualdirs import CurrentDocumentsDirectory
|
|
|
8f91ed |
|
|
|
8f91ed |
|
|
|
8f91ed |
class QuickOpenAppActivatable(GObject.Object, Gedit.AppActivatable):
|
|
|
8f91ed |
app = GObject.property(type=Gedit.App)
|
|
|
8f91ed |
|
|
|
8f91ed |
def __init__(self):
|
|
|
8f91ed |
GObject.Object.__init__(self)
|
|
|
8f91ed |
|
|
|
8f91ed |
def do_activate(self):
|
|
|
8f91ed |
self.app.add_accelerator("<Primary><Alt>O", "win.quickopen", None)
|
|
|
8f91ed |
|
|
|
8f91ed |
self.menu_ext = self.extend_menu("file-section")
|
|
|
8f91ed |
item = Gio.MenuItem.new(_("Quick Open..."), "win.quickopen")
|
|
|
8f91ed |
self.menu_ext.prepend_menu_item(item)
|
|
|
8f91ed |
|
|
|
8f91ed |
def do_deactivate(self):
|
|
|
8f91ed |
self.app.remove_accelerator("win.quickopen", None)
|
|
|
8f91ed |
|
|
|
8f91ed |
|
|
|
8f91ed |
class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
|
|
|
8f91ed |
__gtype_name__ = "QuickOpenPlugin"
|
|
|
8f91ed |
|
|
|
8f91ed |
window = GObject.property(type=Gedit.Window)
|
|
|
8f91ed |
|
|
|
8f91ed |
def __init__(self):
|
|
|
8f91ed |
GObject.Object.__init__(self)
|
|
|
8f91ed |
@@ -94,88 +95,88 @@ class QuickOpenPlugin(GObject.Object, Gedit.WindowActivatable):
|
|
|
8f91ed |
|
|
|
8f91ed |
# Local bookmarks
|
|
|
8f91ed |
for path in self._local_bookmarks():
|
|
|
8f91ed |
paths.append(path)
|
|
|
8f91ed |
|
|
|
8f91ed |
# Desktop directory
|
|
|
8f91ed |
desktopdir = self._desktop_dir()
|
|
|
8f91ed |
|
|
|
8f91ed |
if desktopdir:
|
|
|
8f91ed |
paths.append(Gio.file_new_for_path(desktopdir))
|
|
|
8f91ed |
|
|
|
8f91ed |
# Home directory
|
|
|
8f91ed |
paths.append(Gio.file_new_for_path(os.path.expanduser('~')))
|
|
|
8f91ed |
|
|
|
8f91ed |
self._popup = Popup(self.window, paths, self.on_activated)
|
|
|
8f91ed |
self.window.get_group().add_window(self._popup)
|
|
|
8f91ed |
|
|
|
8f91ed |
self._popup.set_default_size(*self.get_popup_size())
|
|
|
8f91ed |
self._popup.set_transient_for(self.window)
|
|
|
8f91ed |
self._popup.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
|
|
|
8f91ed |
self._popup.connect('destroy', self.on_popup_destroy)
|
|
|
8f91ed |
|
|
|
8f91ed |
def _local_bookmarks(self):
|
|
|
8f91ed |
filename = os.path.expanduser('~/.config/gtk-3.0/bookmarks')
|
|
|
8f91ed |
|
|
|
8f91ed |
if not os.path.isfile(filename):
|
|
|
8f91ed |
return []
|
|
|
8f91ed |
|
|
|
8f91ed |
paths = []
|
|
|
8f91ed |
|
|
|
8f91ed |
- for line in open(filename, 'r', encoding='utf-8'):
|
|
|
8f91ed |
+ for line in io.open(filename, 'r', encoding='utf-8'):
|
|
|
8f91ed |
uri = line.strip().split(" ")[0]
|
|
|
8f91ed |
f = Gio.file_new_for_uri(uri)
|
|
|
8f91ed |
|
|
|
8f91ed |
if f.is_native():
|
|
|
8f91ed |
try:
|
|
|
8f91ed |
info = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
8f91ed |
Gio.FileQueryInfoFlags.NONE,
|
|
|
8f91ed |
None)
|
|
|
8f91ed |
|
|
|
8f91ed |
if info and info.get_file_type() == Gio.FileType.DIRECTORY:
|
|
|
8f91ed |
paths.append(f)
|
|
|
8f91ed |
except:
|
|
|
8f91ed |
pass
|
|
|
8f91ed |
|
|
|
8f91ed |
return paths
|
|
|
8f91ed |
|
|
|
8f91ed |
def _desktop_dir(self):
|
|
|
8f91ed |
config = os.getenv('XDG_CONFIG_HOME')
|
|
|
8f91ed |
|
|
|
8f91ed |
if not config:
|
|
|
8f91ed |
config = os.path.expanduser('~/.config')
|
|
|
8f91ed |
|
|
|
8f91ed |
config = os.path.join(config, 'user-dirs.dirs')
|
|
|
8f91ed |
desktopdir = None
|
|
|
8f91ed |
|
|
|
8f91ed |
if os.path.isfile(config):
|
|
|
8f91ed |
- for line in open(config, 'r', encoding='utf-8'):
|
|
|
8f91ed |
+ for line in io.open(config, 'r', encoding='utf-8'):
|
|
|
8f91ed |
line = line.strip()
|
|
|
8f91ed |
|
|
|
8f91ed |
if line.startswith('XDG_DESKTOP_DIR'):
|
|
|
8f91ed |
parts = line.split('=', 1)
|
|
|
8f91ed |
desktopdir = parts[1].strip('"').strip("'")
|
|
|
8f91ed |
desktopdir = os.path.expandvars(desktopdir)
|
|
|
8f91ed |
break
|
|
|
8f91ed |
|
|
|
8f91ed |
if not desktopdir:
|
|
|
8f91ed |
desktopdir = os.path.expanduser('~/Desktop')
|
|
|
8f91ed |
|
|
|
8f91ed |
return desktopdir
|
|
|
8f91ed |
|
|
|
8f91ed |
# Callbacks
|
|
|
8f91ed |
def on_quick_open_activate(self, action, parameter, user_data=None):
|
|
|
8f91ed |
if not self._popup:
|
|
|
8f91ed |
self._create_popup()
|
|
|
8f91ed |
|
|
|
8f91ed |
self._popup.show()
|
|
|
8f91ed |
|
|
|
8f91ed |
def on_popup_destroy(self, popup, user_data=None):
|
|
|
8f91ed |
self.set_popup_size(popup.get_final_size())
|
|
|
8f91ed |
|
|
|
8f91ed |
self._popup = None
|
|
|
8f91ed |
|
|
|
8f91ed |
def on_activated(self, gfile, user_data=None):
|
|
|
8f91ed |
Gedit.commands_load_location(self.window, gfile, None, -1, -1)
|
|
|
8f91ed |
return True
|
|
|
8f91ed |
|
|
|
8f91ed |
# ex:ts=4:et:
|
|
|
6f95c4 |
diff --git a/plugins/snippets/snippets.plugin.desktop.in b/plugins/snippets/snippets.plugin.desktop.in
|
|
|
6f95c4 |
index 8551b6b..f41a626 100644
|
|
|
f620a9 |
--- a/plugins/snippets/snippets.plugin.desktop.in
|
|
|
f620a9 |
+++ b/plugins/snippets/snippets.plugin.desktop.in
|
|
|
6f95c4 |
@@ -1,9 +1,9 @@
|
|
|
f620a9 |
[Plugin]
|
|
|
f620a9 |
-Loader=python3
|
|
|
f620a9 |
+Loader=python
|
|
|
f620a9 |
Module=snippets
|
|
|
f620a9 |
IAge=3
|
|
|
f620a9 |
_Name=Snippets
|
|
|
6f95c4 |
_Description=Insert often-used pieces of text in a fast way
|
|
|
6f95c4 |
Authors=Jesse van den Kieboom <jesse@icecrew.nl>
|
|
|
6f95c4 |
Copyright=Copyright © 2005 Jesse van den Kieboom
|
|
|
6f95c4 |
Website=http://www.gedit.org
|
|
|
8f91ed |
diff --git a/plugins/snippets/snippets/helper.py b/plugins/snippets/snippets/helper.py
|
|
|
8f91ed |
index 2fa3b3f..ee3f3b7 100644
|
|
|
8f91ed |
--- a/plugins/snippets/snippets/helper.py
|
|
|
8f91ed |
+++ b/plugins/snippets/snippets/helper.py
|
|
|
8f91ed |
@@ -97,62 +97,65 @@ def write_xml(node, f, cdata_nodes=()):
|
|
|
8f91ed |
|
|
|
8f91ed |
# Encoding
|
|
|
8f91ed |
f.write("\n")
|
|
|
8f91ed |
|
|
|
8f91ed |
_write_node(node, f, cdata_nodes)
|
|
|
8f91ed |
|
|
|
8f91ed |
def _write_indent(file, text, indent):
|
|
|
8f91ed |
file.write(' ' * indent + text)
|
|
|
8f91ed |
|
|
|
8f91ed |
def _write_node(node, file, cdata_nodes=(), indent=0):
|
|
|
8f91ed |
# write XML to file
|
|
|
8f91ed |
tag = node.tag
|
|
|
8f91ed |
|
|
|
8f91ed |
if node is et.Comment:
|
|
|
8f91ed |
_write_indent(file, "\n" % saxutils.escape(node.text), indent)
|
|
|
8f91ed |
elif node is et.ProcessingInstruction:
|
|
|
8f91ed |
_write_indent(file, "\n" % saxutils.escape(node.text), indent)
|
|
|
8f91ed |
else:
|
|
|
8f91ed |
items = node.items()
|
|
|
8f91ed |
|
|
|
8f91ed |
if items or node.text or len(node):
|
|
|
8f91ed |
_write_indent(file, "<" + tag, indent)
|
|
|
8f91ed |
|
|
|
8f91ed |
if items:
|
|
|
8f91ed |
items.sort() # lexical order
|
|
|
8f91ed |
for k, v in items:
|
|
|
8f91ed |
file.write(" %s=%s" % (k, saxutils.quoteattr(v)))
|
|
|
8f91ed |
if node.text or len(node):
|
|
|
8f91ed |
file.write(">")
|
|
|
8f91ed |
if node.text and node.text.strip() != "":
|
|
|
8f91ed |
+ node_txt = node.text
|
|
|
8f91ed |
+ if isinstance(node_txt, unicode):
|
|
|
8f91ed |
+ node_txt = node_txt.encode('utf8')
|
|
|
8f91ed |
if tag in cdata_nodes:
|
|
|
8f91ed |
- file.write(_cdata(node.text))
|
|
|
8f91ed |
+ file.write(_cdata(node_txt))
|
|
|
8f91ed |
else:
|
|
|
8f91ed |
file.write(saxutils.escape(node.text))
|
|
|
8f91ed |
else:
|
|
|
8f91ed |
file.write("\n")
|
|
|
8f91ed |
|
|
|
8f91ed |
for n in node:
|
|
|
8f91ed |
_write_node(n, file, cdata_nodes, indent + 1)
|
|
|
8f91ed |
|
|
|
8f91ed |
if not len(node):
|
|
|
8f91ed |
file.write("</" + tag + ">\n")
|
|
|
8f91ed |
else:
|
|
|
8f91ed |
_write_indent(file, "</" + tag + ">\n", \
|
|
|
8f91ed |
indent)
|
|
|
8f91ed |
else:
|
|
|
8f91ed |
file.write(" />\n")
|
|
|
8f91ed |
|
|
|
8f91ed |
if node.tail and node.tail.strip() != "":
|
|
|
8f91ed |
file.write(saxutils.escape(node.tail))
|
|
|
8f91ed |
|
|
|
8f91ed |
def _cdata(text):
|
|
|
8f91ed |
return '', ']]]]>') + ']]>'
|
|
|
8f91ed |
|
|
|
8f91ed |
def is_tab_trigger(w):
|
|
|
8f91ed |
if len(w) == 1 and not (w.isalnum() or w.isspace()):
|
|
|
8f91ed |
return True
|
|
|
8f91ed |
|
|
|
8f91ed |
if not is_first_tab_trigger_character(w[0]):
|
|
|
8f91ed |
return False
|
|
|
8f91ed |
|
|
|
8f91ed |
for c in w:
|
|
|
6f95c4 |
diff --git a/plugins/snippets/snippets/library.py b/plugins/snippets/snippets/library.py
|
|
|
6f95c4 |
index 455ac91..1b454f3 100644
|
|
|
6f95c4 |
--- a/plugins/snippets/snippets/library.py
|
|
|
6f95c4 |
+++ b/plugins/snippets/snippets/library.py
|
|
|
6f95c4 |
@@ -1,47 +1,48 @@
|
|
|
6f95c4 |
# Gedit snippets plugin
|
|
|
6f95c4 |
# Copyright (C) 2005-2006 Jesse van den Kieboom <jesse@icecrew.nl>
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
6f95c4 |
# it under the terms of the GNU General Public License as published by
|
|
|
6f95c4 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
6f95c4 |
# (at your option) any later version.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is distributed in the hope that it will be useful,
|
|
|
6f95c4 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6f95c4 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6f95c4 |
# GNU General Public License for more details.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# You should have received a copy of the GNU General Public License
|
|
|
6f95c4 |
# along with this program; if not, write to the Free Software
|
|
|
6f95c4 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
6f95c4 |
|
|
|
6f95c4 |
+import io
|
|
|
6f95c4 |
import os
|
|
|
6f95c4 |
import weakref
|
|
|
6f95c4 |
import sys
|
|
|
6f95c4 |
import re
|
|
|
6f95c4 |
|
|
|
6f95c4 |
from gi.repository import Gdk, Gtk
|
|
|
6f95c4 |
|
|
|
6f95c4 |
import xml.etree.ElementTree as et
|
|
|
6f95c4 |
from . import helper
|
|
|
6f95c4 |
|
|
|
6f95c4 |
class NamespacedId:
|
|
|
6f95c4 |
def __init__(self, namespace, id):
|
|
|
6f95c4 |
if not id:
|
|
|
6f95c4 |
self.id = None
|
|
|
6f95c4 |
else:
|
|
|
6f95c4 |
if namespace:
|
|
|
6f95c4 |
self.id = namespace + '-'
|
|
|
6f95c4 |
else:
|
|
|
6f95c4 |
self.id = 'global-'
|
|
|
6f95c4 |
|
|
|
6f95c4 |
self.id += id
|
|
|
6f95c4 |
|
|
|
6f95c4 |
class SnippetData:
|
|
|
6f95c4 |
PROPS = {'tag': '', 'text': '', 'description': 'New snippet',
|
|
|
6f95c4 |
'accelerator': '', 'drop-targets': ''}
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def __init__(self, node, library):
|
|
|
6f95c4 |
self.priv_id = node.attrib.get('id')
|
|
|
6f95c4 |
|
|
|
6f95c4 |
self.set_library(library)
|
|
|
6f95c4 |
@@ -426,61 +427,61 @@ class SnippetsSystemFile:
|
|
|
6f95c4 |
|
|
|
6f95c4 |
return True
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _process_element(self, element):
|
|
|
6f95c4 |
if element.tag == 'snippet':
|
|
|
6f95c4 |
self._add_snippet(element)
|
|
|
6f95c4 |
self.insnippet = False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
return True
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def ensure(self):
|
|
|
6f95c4 |
if not self.ok or self.loaded:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
|
|
|
6f95c4 |
self.load()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def parse_xml(self, readsize=16384):
|
|
|
6f95c4 |
if not self.path:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
|
|
|
6f95c4 |
elements = []
|
|
|
6f95c4 |
|
|
|
6f95c4 |
builder = SnippetsTreeBuilder( \
|
|
|
6f95c4 |
lambda node: elements.append((node, True)), \
|
|
|
6f95c4 |
lambda node: elements.append((node, False)))
|
|
|
6f95c4 |
|
|
|
6f95c4 |
parser = et.XMLParser(target=builder)
|
|
|
6f95c4 |
self.insnippet = False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
try:
|
|
|
6f95c4 |
- f = open(self.path, "r", encoding='utf-8')
|
|
|
6f95c4 |
+ f = io.open(self.path, "r", encoding='utf-8')
|
|
|
6f95c4 |
except IOError:
|
|
|
6f95c4 |
self.ok = False
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
|
|
|
6f95c4 |
while True:
|
|
|
6f95c4 |
try:
|
|
|
6f95c4 |
data = f.read(readsize)
|
|
|
6f95c4 |
except IOError:
|
|
|
6f95c4 |
self.ok = False
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if not data:
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
|
|
|
6f95c4 |
try:
|
|
|
6f95c4 |
parser.feed(data)
|
|
|
6f95c4 |
except Exception:
|
|
|
6f95c4 |
self.ok = False
|
|
|
6f95c4 |
break
|
|
|
6f95c4 |
|
|
|
6f95c4 |
for element in elements:
|
|
|
6f95c4 |
yield element
|
|
|
6f95c4 |
|
|
|
6f95c4 |
del elements[:]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
f.close()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def load(self):
|
|
|
6f95c4 |
if not self.ok:
|
|
|
6f95c4 |
return
|
|
|
6f95c4 |
diff --git a/plugins/snippets/snippets/shareddata.py b/plugins/snippets/snippets/shareddata.py
|
|
|
6f95c4 |
index be6fd14..64ffcc4 100644
|
|
|
f620a9 |
--- a/plugins/snippets/snippets/shareddata.py
|
|
|
f620a9 |
+++ b/plugins/snippets/snippets/shareddata.py
|
|
|
6f95c4 |
@@ -1,56 +1,57 @@
|
|
|
6f95c4 |
# Gedit snippets plugin
|
|
|
6f95c4 |
# Copyright (C) 2011 Jesse van den Kieboom <jessevdk@gnome.org>
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
6f95c4 |
# it under the terms of the GNU General Public License as published by
|
|
|
6f95c4 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
6f95c4 |
# (at your option) any later version.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is distributed in the hope that it will be useful,
|
|
|
6f95c4 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6f95c4 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6f95c4 |
# GNU General Public License for more details.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# You should have received a copy of the GNU General Public License
|
|
|
6f95c4 |
# along with this program; if not, write to the Free Software
|
|
|
6f95c4 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
6f95c4 |
|
|
|
6f95c4 |
from .singleton import Singleton
|
|
|
6f95c4 |
import os
|
|
|
f620a9 |
|
|
|
f620a9 |
from gi.repository import Gtk
|
|
|
f620a9 |
|
|
|
6f95c4 |
# To register the GeditSnippetsManager type
|
|
|
6f95c4 |
from .manager import Manager
|
|
|
6f95c4 |
|
|
|
f620a9 |
-class SharedData(object, metaclass=Singleton):
|
|
|
f620a9 |
+class SharedData(object):
|
|
|
f620a9 |
+ __metaclass__ = Singleton
|
|
|
f620a9 |
def __init__(self):
|
|
|
f620a9 |
self.dlg = None
|
|
|
f620a9 |
self.dlg_default_size = None
|
|
|
6f95c4 |
self.controller_registry = {}
|
|
|
6f95c4 |
self.windows = {}
|
|
|
f620a9 |
|
|
|
f620a9 |
def register_controller(self, view, controller):
|
|
|
f620a9 |
self.controller_registry[view] = controller
|
|
|
6f95c4 |
|
|
|
f620a9 |
def unregister_controller(self, view, controller):
|
|
|
f620a9 |
if self.controller_registry[view] == controller:
|
|
|
f620a9 |
del self.controller_registry[view]
|
|
|
f620a9 |
|
|
|
6f95c4 |
def register_window(self, window):
|
|
|
6f95c4 |
self.windows[window.window] = window
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def unregister_window(self, window):
|
|
|
6f95c4 |
if window.window in self.windows:
|
|
|
6f95c4 |
del self.windows[window.window]
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def update_state(self, window):
|
|
|
6f95c4 |
if window in self.windows:
|
|
|
6f95c4 |
self.windows[window].do_update_state()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def get_active_controller(self, window):
|
|
|
6f95c4 |
view = window.get_active_view()
|
|
|
6f95c4 |
|
|
|
6f95c4 |
if not view or not view in self.controller_registry:
|
|
|
6f95c4 |
return None
|
|
|
6f95c4 |
|
|
|
6f95c4 |
diff --git a/plugins/snippets/snippets/signals.py b/plugins/snippets/snippets/signals.py
|
|
|
6f95c4 |
index 647b616..9aaa95a 100644
|
|
|
6f95c4 |
--- a/plugins/snippets/snippets/signals.py
|
|
|
6f95c4 |
+++ b/plugins/snippets/snippets/signals.py
|
|
|
6f95c4 |
@@ -1,50 +1,50 @@
|
|
|
6f95c4 |
# -*- coding: utf-8 -*-
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# signals.py
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# Copyright (C) 2009 - Jesse van den Kieboom
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is free software; you can redistribute it and/or modify
|
|
|
6f95c4 |
# it under the terms of the GNU General Public License as published by
|
|
|
6f95c4 |
# the Free Software Foundation; either version 2 of the License, or
|
|
|
6f95c4 |
# (at your option) any later version.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# This program is distributed in the hope that it will be useful,
|
|
|
6f95c4 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6f95c4 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6f95c4 |
# GNU General Public License for more details.
|
|
|
6f95c4 |
#
|
|
|
6f95c4 |
# You should have received a copy of the GNU General Public License
|
|
|
6f95c4 |
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
6f95c4 |
|
|
|
6f95c4 |
-class Signals:
|
|
|
6f95c4 |
+class Signals(object):
|
|
|
6f95c4 |
def __init__(self):
|
|
|
6f95c4 |
self._signals = {}
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def _connect(self, obj, name, handler, connector):
|
|
|
6f95c4 |
ret = self._signals.setdefault(obj, {})
|
|
|
6f95c4 |
|
|
|
6f95c4 |
hid = connector(name, handler)
|
|
|
6f95c4 |
ret.setdefault(name, []).append(hid)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
return hid
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def connect_signal(self, obj, name, handler):
|
|
|
6f95c4 |
return self._connect(obj, name, handler, obj.connect)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def connect_signal_after(self, obj, name, handler):
|
|
|
6f95c4 |
return self._connect(obj, name, handler, obj.connect_after)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
def disconnect_signals(self, obj):
|
|
|
6f95c4 |
if obj not in self._signals:
|
|
|
6f95c4 |
return False
|
|
|
6f95c4 |
|
|
|
6f95c4 |
for name in self._signals[obj]:
|
|
|
6f95c4 |
for hid in self._signals[obj][name]:
|
|
|
6f95c4 |
obj.disconnect(hid)
|
|
|
6f95c4 |
|
|
|
6f95c4 |
del self._signals[obj]
|
|
|
6f95c4 |
return True
|
|
|
f620a9 |
|
|
|
6f95c4 |
def block_signal(self, obj, name):
|
|
|
6f95c4 |
if obj not in self._signals:
|
|
|
6f95c4 |
--
|
|
|
8f91ed |
2.7.4
|
|
|
f620a9 |
|