added prompts for kill-buffer and exit

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-19 03:06:21 +00:00
parent 327b5c52d3
commit 1133f643fb
3 changed files with 59 additions and 21 deletions

View File

@ -397,7 +397,7 @@ class Application(object):
def eval(self, s): def eval(self, s):
return eval(s) return eval(s)
# the might run-loop! # the mighty run-loop!
def run(self): def run(self):
self.done = False self.done = False
while not self.done: while not self.done:
@ -420,6 +420,13 @@ class Application(object):
if self.error_timestamp is not None and ERROR_TIMEOUT > 0 and \ if self.error_timestamp is not None and ERROR_TIMEOUT > 0 and \
time.time() - self.error_timestamp > ERROR_TIMEOUT: time.time() - self.error_timestamp > ERROR_TIMEOUT:
self.clear_error() self.clear_error()
# clear the error line; it might look confusing to the user
try:
self.win.addstr(self.y-1, 0, ' ' * self.x)
except:
pass
self.win.refresh()
return return
# highlighting # highlighting

View File

@ -229,16 +229,34 @@ class KillBuffer(Method):
default=default.current_buffer)] default=default.current_buffer)]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
name = vargs['buffername'] name = vargs['buffername']
app = w.application a = w.application
assert name in app.bufferlist.buffer_names, "Buffer %r does not exist" % name assert name in a.bufferlist.buffer_names, "Buffer %r does not exist" % name
assert name != '*Scratch*', "Can't kill scratch buffer" assert name != '*Scratch*', "Can't kill scratch buffer"
b = app.bufferlist.buffer_names[name] self._to_kill = a.bufferlist.buffer_names[name]
if not self.force: self._old_window = w
assert not b.changed(), "Buffer %r has been modified" % (name) if self.force or not self._to_kill.changed():
if app.bufferlist.is_buffer_visible(b): self._doit()
app.bufferlist.set_slot(app.active_slot, app.bufferlist.hidden_buffers[0]) else:
app.bufferlist.remove_buffer(b) self._prompt = "Buffer has unsaved changes; kill anyway? "
a.open_mini_buffer(self._prompt, self._callback)
def _doit(self):
a = self._old_window.application
b = self._to_kill
if a.bufferlist.is_buffer_visible(b):
a.bufferlist.set_slot(a.active_slot, a.bufferlist.hidden_buffers[0])
a.bufferlist.remove_buffer(b)
b.close() b.close()
def _callback(self, v):
a = self._old_window.application
if v == 'yes':
self._doit()
a.close_mini_buffer()
elif v == 'no':
a.close_mini_buffer()
else:
a.close_mini_buffer()
a.set_error('Please type "yes" or "no"')
class ForceKillBuffer(KillBuffer): class ForceKillBuffer(KillBuffer):
force=True force=True
args = [Argument('buffername', datatype="buffer", prompt="Force Kill Buffer: ", args = [Argument('buffername', datatype="buffer", prompt="Force Kill Buffer: ",
@ -297,20 +315,35 @@ class TransposeWords(Method):
'''Switch the place of the two words nearest the cursor''' '''Switch the place of the two words nearest the cursor'''
pass pass
# exit/exit2 # you wanna quit right?
class Exit(Method): class Exit(Method):
'''Exit the program, unless there are unsaved changes''' '''Exit the program, unless there are unsaved changes'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
a = w.application
assert a.mini_buffer_is_open() is False, "Recursive minibuffer antics"
changed = False
for b in w.application.bufferlist.buffers: for b in w.application.bufferlist.buffers:
if b.changed(): changed = b.changed()
s = "Buffer %s was modified" % b.name() if changed:
w.application.set_error(s) break
return if not changed:
w.application.exit() w.application.exit()
class Exit2(Method): return
'''Exit the program, discarding unsaved changes''' else:
def _execute(self, w, **vargs): self._old_window = w
w.application.exit() self._prompt = "There are buffers with unsaved changes; exit? "
a.open_mini_buffer(self._prompt, self._callback)
def _callback(self, v):
a = self._old_window.application
if v == 'yes':
a.exit()
a.close_mini_buffer()
if v == 'no':
return
a.open_mini_buffer(self._prompt, self._callback)
a.set_error('Please type "yes" or "no"')
# insert text # insert text
class InsertString(Method): class InsertString(Method):

View File

@ -127,7 +127,6 @@ class Fundamental(Handler):
self.add_bindings('replace', ('M-%',)) self.add_bindings('replace', ('M-%',))
self.add_bindings('open-file', ('C-x C-f',)) self.add_bindings('open-file', ('C-x C-f',))
self.add_bindings('kill-buffer', ('C-x k',)) self.add_bindings('kill-buffer', ('C-x k',))
self.add_bindings('force-kill-buffer', ('C-x K',))
self.add_bindings('list-buffers', ('C-x C-b',)) self.add_bindings('list-buffers', ('C-x C-b',))
self.add_bindings('meta-x', ('M-x',)) self.add_bindings('meta-x', ('M-x',))
self.add_bindings('wrap-line', ('M-q',)) self.add_bindings('wrap-line', ('M-q',))
@ -136,7 +135,6 @@ class Fundamental(Handler):
self.add_bindings('save-buffer-as', ('C-x C-w',)) self.add_bindings('save-buffer-as', ('C-x C-w',))
self.add_bindings('relex-buffer', ('M-r',)) self.add_bindings('relex-buffer', ('M-r',))
self.add_bindings('exit', ('C-x C-c',)) self.add_bindings('exit', ('C-x C-c',))
self.add_bindings('exit2', ('C-c C-c',))
self.add_bindings('split-window', ('C-x s',)) self.add_bindings('split-window', ('C-x s',))
self.add_bindings('unsplit-window', ('C-u s',)) self.add_bindings('unsplit-window', ('C-u s',))
self.add_bindings('toggle-window', ('C-x o',)) self.add_bindings('toggle-window', ('C-x o',))