~barcc/gedit-projects/trunk

« back to all changes in this revision

Viewing changes to projects/window.py

  • Committer: B. Clausius
  • Date: 2020-06-24 16:49:27 UTC
  • Revision ID: barcc@gmx.de-20200624164927-bi65ijq6bnmy16rf
basic compatibility with pluma

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from gi.repository import Gdk
28
28
from gi.repository import Gtk
29
29
from gi.repository import PeasGtk
30
 
from gi.repository import Gedit
 
30
try:
 
31
    from gi.repository import Gedit
 
32
    Activatable = Gedit.WindowActivatable
 
33
    compat = 'gedit'
 
34
except ImportError:
 
35
    from gi.repository import Peas
 
36
    from gi.repository import Pluma as Gedit
 
37
    Activatable = Peas.Activatable
 
38
    compat = 'pluma'
31
39
 
32
40
from projects.idle import IdleHelper, Priority
33
41
from projects import settings
39
47
if hasattr(Gedit.MessageBus, 'send'):
40
48
    def send_message(window, object_path, method, **kwargs):
41
49
        window.get_message_bus().send(object_path, method, **kwargs)
 
50
elif compat == 'pluma':
 
51
    def send_message(window, object_path, method, **kwargs):
 
52
        pass  #TODO: not implemented
42
53
else:
43
54
    # For installations that do not have the Gedit.py override file
44
55
    def send_message(window, object_path, method, **kwargs):
252
263
            self.app_data.do_scan_projects(projectpath)
253
264
            
254
265
        
255
 
class ProjectsWindow(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable, IdleHelper):
 
266
class ProjectsWindow(GObject.Object, Activatable, PeasGtk.Configurable, IdleHelper):
256
267
    __gtype_name__ = "ProjectsWindow"
257
 
    window = GObject.property(type=Gedit.Window)
 
268
    if compat == 'gedit':
 
269
        window = GObject.property(type=Gedit.Window)
 
270
    elif compat == 'pluma':
 
271
        object = GObject.Property(type=GObject.Object)
 
272
        window = property(lambda self: self.object)
258
273
    app_data = None
259
274
    
260
275
    def __init__(self):
294
309
        
295
310
        icon = Gtk.Image.new_from_icon_name('applications-development', Gtk.IconSize.MENU)
296
311
        panel = self.window.get_side_panel()
297
 
        panel.add_item(self.panel_helper.widget, "ProjectsSidePanel", "Projects", icon)
 
312
        if compat == 'gedit':
 
313
            panel.add_item(self.panel_helper.widget, "ProjectsSidePanel", "Projects", icon)
 
314
        elif compat == 'pluma':
 
315
            panel.add_item(self.panel_helper.widget, "ProjectsSidePanel", icon)
298
316
        
299
317
        self._connect('tab-added', self.on_window_tab_added)
300
318
        self._connect('active-tab-changed', self.on_window_tab_changed)
524
542
        location = Gio.File.new_for_uri(filename)
525
543
        tab = window.get_tab_from_location(location)
526
544
        if tab is None:
527
 
            tab = window.create_tab_from_location(location, None, 0, 0, False, jump_to)
 
545
            if compat == 'gedit':
 
546
                tab = window.create_tab_from_location(location, None, 0, 0, False, jump_to)
 
547
            else:
 
548
                tab = window.create_tab_from_uri(filename, Gedit.Encoding.get_current(), 0, False, jump_to)
528
549
        elif jump_to:
529
550
            window.set_active_tab(tab)
530
551
        if jump_to: