forked from flavioamieiro/dojotools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdojotools-gedit.py
108 lines (83 loc) · 2.96 KB
/
dojotools-gedit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
"""
# -*- encoding: utf-8 -*-
import os
import gtk
import gedit
import gobject
from dojotoolsUi import UserInterface
from dojotoolsUi import window_configure_dialog
from dojotoolsUi import enter_callback_ui
from dojotools import Monitor, Timer
DEFAULT_TIMER = 300
class DojoToolsGeditHelper:
def __init__(self, plugin, window):
self._window = window
self._plugin = plugin
def deactivate(self):
self._window = None
self._plugin = None
def update_ui(self):
# Called whenever the window has been updated (active tab
# changed, etc.)
pass
class DojoToolsGedit(gedit.Plugin):
def __init__(self):
gedit.Plugin.__init__(self)
#Init for Ui knows itself
self.ui = None
self._instances = {}
def activate(self, window):
self._instances[window] = DojoToolsGeditHelper(self, window)
def start_plugin(self, window):
try:
timer = Timer(int(self.round_timer))
except:
timer = Timer(DEFAULT_TIMER)
if self.ui != None:
self.ui.re_initialize(timer)
else:
self.ui = UserInterface(timer, window)
def deactivate(self, window):
if self.ui is not None:
self.ui.remove_output()
self.ui.timer.pause()
self._instances[window].deactivate()
del self._instances[window]
def update_ui(self, window):
if not self.has_monitor() or not self.has_document():
self.create_monitor(window)
self._instances[window].update_ui()
def is_configurable(self):
return True
def enter_callback(self, widget, entry_commands, entry_timer):
return enter_callback_ui(self, widget, entry_commands, entry_timer, DEFAULT_TIMER)
def create_configure_dialog(self):
return window_configure_dialog(self)
def has_monitor(self):
return hasattr(self, 'monitor')
def has_document(self):
return hasattr(self, 'document')
def has_round_timer(self):
return hasattr(self, 'round_timer')
def has_commands(self):
return hasattr(self, 'commands')
def create_monitor(self, window):
self.get_attributes_to_monitor(window)
if self.has_commands() and self.has_round_timer() and self.has_document():
self.start_plugin(window)
self.monitor = Monitor(
ui = self.ui,
directory = self.directory,
commands = self.commands,
patterns_file = self.patterns_file,
commit = False,
)
return self.monitor
def get_attributes_to_monitor(self, window):
documents = window.get_documents()
for document in documents:
if document.get_uri():
self.document = document.get_uri().strip('file://')
self.directory = '/' + self.document.rpartition('/')[0] + '/'
self.patterns_file = self.directory + '.ignore'