Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Krejsa <dan.krejsa@gmail.com>2009-02-06 21:18:44 (GMT)
committer Dan Krejsa <dan.krejsa@gmail.com>2009-02-06 21:18:44 (GMT)
commitaffd02ca955eb391d0dab720b96da7d7fc1cad84 (patch)
tree0d0108a3dc7519726f249f93086f300734b69fd9
parent91231eb6ac7f47c1b1c6dc4665baaf3369f7a6a7 (diff)
Maintain buffer-modified flag, and prevent applying 'GoodTag' or 'ErrorTag' when simply cutting-and-pasting.
-rwxr-xr-xspock.py61
1 files changed, 55 insertions, 6 deletions
diff --git a/spock.py b/spock.py
index 62ec119..1a8a785 100755
--- a/spock.py
+++ b/spock.py
@@ -202,50 +202,68 @@ class Spock:
off = self.good_offset
if off != 0:
sb = self.source_buffer
+ modified = sb.get_modified()
i1 = sb.get_iter_at_offset(0)
i2 = sb.get_iter_at_offset(off)
sb.apply_tag_by_name("GoodTag", i1, i2)
+ sb.set_modified(modified)
def clear_good(self):
off = self.good_offset
if off != 0:
sb = self.source_buffer
+ modified = sb.get_modified()
i1 = sb.get_iter_at_offset(0)
i2 = sb.get_iter_at_offset(off)
sb.remove_tag_by_name("GoodTag", i1, i2)
self.good_offset = 0
+ sb.set_modified(modified)
def tag_error(self):
sb = self.source_buffer
+ modified = sb.get_modified()
i1 = sb.get_iter_at_mark(self.error_beg)
i2 = sb.get_iter_at_mark(self.error_end)
sb.apply_tag_by_name("ErrorTag", i1, i2)
self.error_set = True
+ sb.set_modified(modified)
def clear_error(self):
if self.error_set:
sb = self.source_buffer
+ # Don't let removing the error message affect the 'modified'
+ # flag, since the error message text isn't saved.
+ # Ugh, this doesn't prevent the modified_changed signal from
+ # being emitted.
+ modified = sb.get_modified()
i1 = sb.get_iter_at_mark(self.error_beg)
i2 = sb.get_iter_at_mark(self.error_end)
sb.delete(i1, i2)
self.error_set = False
+ sb.set_modified(modified)
+
def init_error(self, i1, msg):
sb = self.source_buffer
+ modified = sb.get_modified()
sb.move_mark(self.error_end, i1)
sb.insert(i1, _("\n<--- Oops! %s\n") % msg)
i2 = sb.get_iter_at_mark(self.error_end)
sb.move_mark(self.error_end, i1)
sb.move_mark(self.error_beg, i2)
+ sb.set_modified(modified)
def add_error(self, msg):
sb = self.source_buffer
+ modified = sb.get_modified()
i1 = sb.get_iter_at_mark(self.error_end)
sb.insert(i1, msg)
sb.move_mark(self.error_end, i1)
+ sb.set_modified(modified)
def show_pip(self, pip):
sb = self.source_buffer
+ modified = sb.get_modified()
i1 = sb.get_iter_at_mark(self.error_end)
sb.insert(i1, '\n')
n = 0
@@ -260,6 +278,7 @@ class Spock:
sb.insert(i1, 'W%d: %s\n' % (n, es))
n = n + 1
sb.move_mark(self.error_end, i1)
+ sb.set_modified(modified)
def scroll_to_error(self):
sv = self.source_view
@@ -325,6 +344,22 @@ class Spock:
## print >> sys.stderr, 'i_off=', i_off, ' len=', length, ' text=', \
## text[:20]
+
+ def apply_tag_cb(self, sb, tag, start, stop):
+ start_off = start.get_offset()
+ stop_off = stop.get_offset()
+## tagname = tag.get_property('name')
+## print >> sys.stderr, 'tag=', tagname, 'start_off=', start_off, 'stop_off =', stop_off
+ if tag == self.good_tag:
+ if start_off != 0 or stop_off != self.good_offset:
+ self.source_buffer.stop_emission('apply-tag')
+ elif tag == self.error_tag:
+ sb = self.source_buffer
+ err_beg = sb.get_iter_at_mark(self.error_beg).get_offset()
+ err_end = sb.get_iter_at_mark(self.error_end).get_offset()
+ if (start_off != err_beg or stop_off != err_end):
+ self.source_buffer.stop_emission('apply-tag')
+
def create_source_view(self):
self.error_set = False
sb = gtksourceview2.Buffer()
@@ -335,8 +370,9 @@ class Spock:
pfont = pango.FontDescription("Monospace 10")
sv.modify_font(pfont)
sb.set_highlight_matching_brackets(True)
- sb.create_tag("ErrorTag", background="yellow", editable=False)
- sb.create_tag("GoodTag", background="#e0ffe0")
+ self.error_tag = sb.create_tag("ErrorTag", background="yellow",
+ editable=False)
+ self.good_tag = sb.create_tag("GoodTag", background="#e0ffe0")
# good_offset marks the point up to which the text has been validated
# correct
self.good_offset = 0
@@ -349,6 +385,8 @@ class Spock:
sb.connect('insert-text', self.insert_text_cb)
sb.connect('delete-range', self.delete_range_cb)
+ sb.connect('apply-tag', self.apply_tag_cb)
+
sv.set_editable(True) # for now
sv.set_cursor_visible(True)
# will add scrolled window
@@ -448,10 +486,18 @@ class Spock:
def write_file(self, file_path):
- # TODO: Need to check 'modified' status of file, and only save
- # it if it is modified.
+ # Check 'modified' status of file, and only save
+ # it if it is modified, or if the file path changed.
+ # (Should we also check if the file contents changed on disk,
+ # due to the action of some other context?)
- print >> sys.stderr, "in write_file, file_path is ", file_path
+ sb = self.source_buffer
+ if not sb.get_modified() and file_path == self.current_file:
+ print >> sys.stderr, "Not writing to %s, already up to date" % \
+ file_path
+ return
+
+ print >> sys.stderr, "in write_file, file_path is %s " % file_path
self.clear_error()
try:
@@ -460,11 +506,12 @@ class Spock:
print >> sys.stderr, ("Could not open '%s' to save it" % file_path)
return
- sb = self.source_buffer
# Ugh.
text = sb.get_text(sb.get_start_iter(), sb.get_end_iter())
f.write(text)
f.close()
+ sb.set_modified (False)
+ self.current_file = file_path
def read_file(self, file_path):
@@ -487,6 +534,8 @@ class Spock:
sb.set_text(string)
f.close()
+ sb.set_modified(False)
+
gh.file = file_path
print >> sys.stderr, "Spock read ", file_path