branch : pmacs2
This commit is contained in:
moculus 2007-07-20 02:36:36 +00:00
parent d56e1f870d
commit 5feac52d26
3 changed files with 26 additions and 20 deletions

View File

@ -491,14 +491,11 @@ class DirBuffer(Buffer):
def __init__(self, path, nl='\n', name=None): def __init__(self, path, nl='\n', name=None):
Buffer.__init__(self, nl) Buffer.__init__(self, nl)
self.path = os.path.realpath(path) self.path = os.path.realpath(path)
#if name is None: def changed(self):
# self._name = os.path.basename(self.path) return False
#else:
# self._name = name
def readonly(self): def readonly(self):
return True return True
def name(self): def name(self):
#return self._name
return self.path return self.path
def path_exists(self): def path_exists(self):
return os.path.exists(self.path) return os.path.exists(self.path)

View File

@ -321,7 +321,7 @@ class Exit(Method):
return return
else: else:
self._old_window = w self._old_window = w
self._prompt = "There are buffers with unsaved changes; exit? " self._prompt = "There are buffers with unsaved changes; exit anyway? "
a.open_mini_buffer(self._prompt, self._callback) a.open_mini_buffer(self._prompt, self._callback)
def _callback(self, v): def _callback(self, v):

View File

@ -1,6 +1,7 @@
import method, mode2, os.path import method, mode2, os.path
from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule
from point2 import Point from point2 import Point
from method import Method, Argument
class PermGrammar(Grammar): class PermGrammar(Grammar):
rules = [ rules = [
@ -69,6 +70,9 @@ class Dir(mode2.Fundamental):
self.add_action(Chmod()) self.add_action(Chmod())
self.add_action(Chown()) self.add_action(Chown())
self.add_action(Chgrp()) self.add_action(Chgrp())
self.add_action(TouchPath())
self.add_action(RefreshView())
self.add_action_and_bindings(OpenPath(), ('RETURN',)) self.add_action_and_bindings(OpenPath(), ('RETURN',))
self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d')) self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d'))
def name(self): def name(self):
@ -83,47 +87,52 @@ def _resolve_path(w):
path = os.path.join(w.buffer.path, t.string) path = os.path.join(w.buffer.path, t.string)
return path return path
class Chmod(method.Method): class Chmod(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chmod not implemented') w.set_error('chmod not implemented')
class Chown(method.Method): class Chown(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chown not implemented') w.set_error('chown not implemented')
class Chgrp(method.Method): class Chgrp(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error('chgrp not implemented') w.set_error('chgrp not implemented')
class RemovePath(method.Method): class TouchPath(Method):
args = [Argument('filename', datatype="path", prompt="Touch File: ")]
def _execute(self, w, **vargs):
path = vargs['filename']
retval = os.system('touch %r' % path)
w.application.methods['refresh-view'].execute(w, filename=path)
if retval != 0:
w.set_error("touch failed with exit status %d" % retval)
class RemovePath(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
path = _resolve_path(w) path = _resolve_path(w)
w.application.methods['previous-line'].execute(w)
try: try:
os.remove(path) os.remove(path)
w.set_error("deleted %r " % path) w.set_error("deleted %r " % path)
w.application.methods['refresh-view'].execute(w, filename=path)
except: except:
w.set_error("failed to delete %r" % path) w.set_error("failed to delete %r" % path)
c = w.logical_cursor() class OpenPath(Method):
w.buffer.reload()
#w.cursor = Point(c.x, min(c.y, len(w.buffer.lines) - 1))
#w.cursor = Point(0, min(c.y, len(w.buffer.lines) - 1))
w.cursor = Point(0, 0)
class OpenPath(method.Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
path = _resolve_path(w) path = _resolve_path(w)
w.set_error("opening %r" % path) w.set_error("opening %r" % path)
w.application.methods['open-file'].execute(w, filename=path) w.application.methods['open-file'].execute(w, filename=path)
class RefreshView(method.Method): class RefreshView(Method):
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
c = w.logical_cursor() c = w.logical_cursor()
t = _resolve_token(w) t = _resolve_token(w)
s = t.string s = t.string
w.buffer.reload() w.buffer.reload()
w.cursor = Point(c.x, 0) w.goto(Point(c.x, 0))
found = False found = False
while not found and w.cursor.y < len(w.buffer.lines): while not found and w.cursor.y < len(w.buffer.lines):
t = _resolve_token(w) t = _resolve_token(w)
if t.string == s: if t.string == s:
found = True found = True
else: else:
w.cursor = Point(c.x, w.cursor.y + 1) w.goto(Point(c.x, w.cursor.y + 1))
if not found: if not found:
w.cursor = Point(0, 0) w.goto(Point(0, 0))