modified files, save-as, etc

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-16 16:01:27 +00:00
parent 317955c5d8
commit 35e4611dd0
2 changed files with 14 additions and 2 deletions

View File

@ -442,7 +442,7 @@ class Application(object):
# buffer handling # buffer handling
def new_file_buffer(self, path, data, switch_to=True): def new_file_buffer(self, path, data, switch_to=True):
assert not self.has_buffer_name(path), '%r is already open' % path assert not self.has_buffer_name(path), '%r is already open' % path
assert not os.path.exists(path), '%r already exists' % path #assert not os.path.exists(path), '%r already exists' % path
# touch the file # touch the file
f = open(path, 'w') f = open(path, 'w')
f.write(data) f.write(data)

View File

@ -115,6 +115,7 @@ class SaveBufferAs(Method):
class SaveBuffer(Method): class SaveBuffer(Method):
'''Save the contents of a buffer''' '''Save the contents of a buffer'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
a = w.application
if not w.buffer.changed(): if not w.buffer.changed():
w.set_error("(No changes need to be saved)") w.set_error("(No changes need to be saved)")
return return
@ -125,7 +126,18 @@ class SaveBuffer(Method):
w.buffer.save(force=True) w.buffer.save(force=True)
w.set_error("File had disappeared! Wrote %s" % (w.buffer.path)) w.set_error("File had disappeared! Wrote %s" % (w.buffer.path))
except buffer.FileChangedError, e: except buffer.FileChangedError, e:
pass path1 = w.buffer.path
tf = tempfile.NamedTemporaryFile(delete=False)
tf.write(w.buffer.make_string())
tf.close()
path2 = tf.name
a.methods['diff'].execute(w, path1=path1, path2=path2)
w.set_error("File changed on disk; showing differences")
class ReloadBuffer(Method):
'''Reload the contents of a buffer from the filesystem'''
def _execute(self, w, **vargs):
w.buffer.reload()
w.set_error("Buffer contents reloaded from %r" % w.buffer.path)
class ToggleTabs(Method): class ToggleTabs(Method):
'''Toggle whether to write tabs out or not (defaults to false)''' '''Toggle whether to write tabs out or not (defaults to false)'''