From 5feac52d26b7a6a78e4ee091f629086453dc1046 Mon Sep 17 00:00:00 2001 From: moculus Date: Fri, 20 Jul 2007 02:36:36 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- buffer2.py | 7 ++----- method.py | 2 +- mode_dir.py | 37 +++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/buffer2.py b/buffer2.py index 4b9dcc8..88f0e77 100644 --- a/buffer2.py +++ b/buffer2.py @@ -491,14 +491,11 @@ class DirBuffer(Buffer): def __init__(self, path, nl='\n', name=None): Buffer.__init__(self, nl) self.path = os.path.realpath(path) - #if name is None: - # self._name = os.path.basename(self.path) - #else: - # self._name = name + def changed(self): + return False def readonly(self): return True def name(self): - #return self._name return self.path def path_exists(self): return os.path.exists(self.path) diff --git a/method.py b/method.py index 4033883..a210c2b 100644 --- a/method.py +++ b/method.py @@ -321,7 +321,7 @@ class Exit(Method): return else: 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) def _callback(self, v): diff --git a/mode_dir.py b/mode_dir.py index 84f64a9..b190d93 100644 --- a/mode_dir.py +++ b/mode_dir.py @@ -1,6 +1,7 @@ import method, mode2, os.path from lex3 import Grammar, PatternRule, RegionRule, PatternGroupRule from point2 import Point +from method import Method, Argument class PermGrammar(Grammar): rules = [ @@ -69,6 +70,9 @@ class Dir(mode2.Fundamental): self.add_action(Chmod()) self.add_action(Chown()) self.add_action(Chgrp()) + + self.add_action(TouchPath()) + self.add_action(RefreshView()) self.add_action_and_bindings(OpenPath(), ('RETURN',)) self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d')) def name(self): @@ -83,47 +87,52 @@ def _resolve_path(w): path = os.path.join(w.buffer.path, t.string) return path -class Chmod(method.Method): +class Chmod(Method): def _execute(self, w, **vargs): w.set_error('chmod not implemented') -class Chown(method.Method): +class Chown(Method): def _execute(self, w, **vargs): w.set_error('chown not implemented') -class Chgrp(method.Method): +class Chgrp(Method): def _execute(self, w, **vargs): 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): path = _resolve_path(w) + w.application.methods['previous-line'].execute(w) try: os.remove(path) w.set_error("deleted %r " % path) + w.application.methods['refresh-view'].execute(w, filename=path) except: w.set_error("failed to delete %r" % path) - c = w.logical_cursor() - 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): +class OpenPath(Method): def _execute(self, w, **vargs): path = _resolve_path(w) w.set_error("opening %r" % path) w.application.methods['open-file'].execute(w, filename=path) -class RefreshView(method.Method): +class RefreshView(Method): def _execute(self, w, **vargs): c = w.logical_cursor() t = _resolve_token(w) s = t.string w.buffer.reload() - w.cursor = Point(c.x, 0) + w.goto(Point(c.x, 0)) found = False while not found and w.cursor.y < len(w.buffer.lines): t = _resolve_token(w) if t.string == s: found = True else: - w.cursor = Point(c.x, w.cursor.y + 1) + w.goto(Point(c.x, w.cursor.y + 1)) if not found: - w.cursor = Point(0, 0) + w.goto(Point(0, 0))