[gedit-latex/from_source: 2/4] Move code for path detection inside Resources



commit 55898208da312e5771ec317e6b06342626420e06
Author: Pietro Battiston <pbattiston src gnome org>
Date:   Sun Apr 19 13:05:27 2020 +0200

    Move code for path detection inside Resources

 latex/appactivatable.py | 17 -----------------
 latex/resources.py      | 18 ++++++++++++++++--
 2 files changed, 16 insertions(+), 19 deletions(-)
---
diff --git a/latex/appactivatable.py b/latex/appactivatable.py
index e5528a6..81ecebb 100644
--- a/latex/appactivatable.py
+++ b/latex/appactivatable.py
@@ -15,9 +15,6 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-import os.path
-import platform
-
 from gi.repository import GLib, Gedit, GObject, Gio, Gtk
 from .resources import Resources
 
@@ -34,20 +31,6 @@ class LaTeXAppActivatable(GObject.Object, Gedit.AppActivatable):
         GObject.Object.__init__(self)
 
     def do_activate(self):
-        if platform.platform() == 'Windows':
-            userdir = os.path.expanduser('~/gedit/latex')
-        else:
-            userdir = os.path.join(GLib.get_user_config_dir(), 'gedit/latex')
-
-        #check if running from srcdir and if so, prefer that for all data files
-        me = os.path.realpath(os.path.dirname(__file__))
-        if os.path.exists(os.path.join(me, "..", "configure.ac")):
-            sysdir = os.path.abspath(os.path.join(me, "..", "data"))
-        else:
-            sysdir = self.plugin_info.get_data_dir()
-
-        Resources().set_dirs(userdir, sysdir)
-        
         #The following is needed to support gedit 3.12 new menu api.
         #It adds menus and shortcuts here.
         #Actions and toolbar construction are still done in windowactivatable.py.
diff --git a/latex/resources.py b/latex/resources.py
index ac8753b..454fa7a 100644
--- a/latex/resources.py
+++ b/latex/resources.py
@@ -23,7 +23,10 @@
 resources
 """
 
+from gi.repository import GLib
+
 import logging
+import platform
 import os.path
 import errno
 from .singleton import Singleton
@@ -32,9 +35,20 @@ _log = logging.getLogger("resources")
 
 class Resources(Singleton):
     def __init_once__(self):
-        pass
+        if platform.platform() == 'Windows':
+            userdir = os.path.expanduser('~/gedit/latex')
+        else:
+            userdir = os.path.join(GLib.get_user_config_dir(), 'gedit/latex')
+
+        #check if running from srcdir and if so, prefer that for all data files
+        me = os.path.realpath(os.path.dirname(__file__))
+        if os.path.exists(os.path.join(me, "..", "meson.build")):
+            self.from_source = True
+            systemdir = os.path.abspath(os.path.join(me, "..", "data"))
+        else:
+            self.from_source = False
+            systemdir = self.plugin_info.get_data_dir()
 
-    def set_dirs(self, userdir, systemdir):
         self.userdir = userdir
         self.systemdir = systemdir
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]