fixed replace bug, etc

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-18 18:50:48 +00:00
parent 9090a0f44a
commit 6ca089f3b7
5 changed files with 22 additions and 11 deletions

View File

@ -231,23 +231,28 @@ class Application(object):
return self.mini_buffer
def mini_buffer_is_open(self):
return self.mini_buffer is not None
def open_mini_buffer(self, prompt, callback, method=None, tabber=None,
modename=None):
def open_mini_buffer(self, prompt, callback, method=None, tabber=None, modename=None):
if self.mini_buffer_is_open():
self.close_mini_buffer()
self.mini_prompt = prompt
self.mini_buffer = minibuffer.MiniBuffer(callback, method, tabber, modename)
window2.Window(self.mini_buffer, self, height=1, width=self.x-1-len(self.mini_prompt)-1)
self.mini_active = True
try:
window2.Window(self.mini_buffer, self, height=1,
width=self.x-1-len(self.mini_prompt)-1)
self.mini_active = True
except minibuffer.MiniBufferError:
self.mini_buffer = None
self.mini_prompt = ''
def exec_mini_buffer(self):
self.mini_buffer.callback(self.mini_buffer.make_string())
self.close_mini_buffer()
def close_mini_buffer(self):
self.mini_active = False
if self.mini_buffer_is_open():
self.mini_buffer.close()
self.mini_buffer = None
self.mini_prompt = ""
self.mini_active = False
assert not self.mini_active
def get_mini_buffer_prompt(self):
return self.mini_prompt
def set_mini_buffer_prompt(self, p):

View File

@ -171,11 +171,7 @@ class Replace(Method):
a.last_replace_before = self.before = vargs['before']
a.last_replace_after = self.after = vargs['after']
self.old_window = w
a.open_mini_buffer('I-Replace: ',
lambda x: None,
self,
None,
'replace')
a.open_mini_buffer('I-Replace: ', lambda x: None, self, None, 'replace')
# navigating between buffers
class OpenFile(Method):

View File

@ -1,5 +1,8 @@
import buffer2
class MiniBufferError(Exception):
pass
# minibuffer is a singleton
mini = None
class MiniBuffer(buffer2.Buffer):

View File

@ -1,6 +1,6 @@
import commands, os.path, sets, string, sys
import color, completer, default, mode2, lex2, method, regex
import color, completer, default, mode2, lex2, method, regex, tab2
import ctag_python
from point2 import Point

View File

@ -26,6 +26,9 @@ class Replace(mode2.Fundamental):
self.add_action_and_bindings(action, sequences)
_find_next(w, False)
if w.buffer.method.p1 is None:
w.application.set_error('%r was not found')
raise minibuffer.MiniBufferError
_set_prompt(w.buffer.method, w.buffer.method.old_window)
def name(self):
@ -62,6 +65,9 @@ class CancelReplace(method.Method):
w.application.set_error("Replace cancelled")
def _set_prompt(m, w):
if m.p1 is None:
w.application.mini_prompt = '%r was not found' % m.before
return
(x, y) = m.p1.xy()
count = 0
while y < len(w.buffer.lines):
@ -128,3 +134,4 @@ def _end(w):
w.application.clear_highlighted_ranges()
w.buffer.method.old_cursor = None
w.buffer.method.old_window = None
assert not w.application.mini_active