83d8eb7f58e8

Clean up buffer handling.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Jun 2011 20:58:58 -0400
parents 9539ae8686cd
children 0797e3cc5020
branches/tags (none)
files README.markdown plugin/threesomelib/modes.py plugin/threesomelib/util/bufferlib.py

Changes

--- a/README.markdown	Mon Jun 13 20:44:37 2011 -0400
+++ b/README.markdown	Mon Jun 13 20:58:58 2011 -0400
@@ -46,7 +46,7 @@
 Build the docs:
 
     :call pathogen#helptags()
-    
+
 Add it as a merge tool for your VCS of choice:
 
 **Mercurial:** add the following lines to `~/.hgrc`:
@@ -77,7 +77,6 @@
 TODO for v1.0.0
 ===============
 
-* Add a help/status bar at the top.
 * Add hunk-pulling functionality.
 * Add a basic test suite.
 * Remove the eat-your-data warnings in the docs.
--- a/plugin/threesomelib/modes.py	Mon Jun 13 20:44:37 2011 -0400
+++ b/plugin/threesomelib/modes.py	Mon Jun 13 20:58:58 2011 -0400
@@ -98,6 +98,10 @@
         pass
 
 
+    def key_use(self):
+        pass
+
+
     def activate(self):
         self.layout(self._current_layout)
         self.diff(self._current_diff_mode)
@@ -287,7 +291,7 @@
 
     def key_original(self):
         if self._current_layout == 0:
-            windows.focus(1)
+            windows.focus(2)
         elif self._current_layout == 1:
             return
         elif self._current_layout == 2:
@@ -295,27 +299,31 @@
 
     def key_one(self):
         if self._current_layout == 0:
-            windows.focus(2)
+            windows.focus(3)
         elif self._current_layout == 1:
-            windows.focus(1)
+            windows.focus(2)
         elif self._current_layout == 2:
-            windows.focus(1)
+            windows.focus(2)
 
     def key_two(self):
         if self._current_layout == 0:
-            windows.focus(3)
+            windows.focus(4)
+        elif self._current_layout == 1:
+            windows.focus(4)
+        elif self._current_layout == 2:
+            windows.focus(4)
+
+    def key_result(self):
+        if self._current_layout == 0:
+            windows.focus(5)
         elif self._current_layout == 1:
             windows.focus(3)
         elif self._current_layout == 2:
             windows.focus(3)
 
-    def key_result(self):
-        if self._current_layout == 0:
-            windows.focus(4)
-        elif self._current_layout == 1:
-            windows.focus(2)
-        elif self._current_layout == 2:
-            windows.focus(2)
+
+    def key_use(self):
+        pass
 
 
     def goto_result(self):
@@ -408,17 +416,16 @@
         self.redraw_hud()
 
 
+    def key_use(self):
+        pass
+
+
     def goto_result(self):
         self.key_result()
 
 
     def hud_diagram(self):
-        bufmap = { buffers.original.name: 'Original',
-                   buffers.one.name: 'One',
-                   buffers.two.name: 'Two',
-                   buffers.result.name: 'Result' }
-
-        buf = bufmap[self._current_buffer.name]
+        buf = buffers.labels[self._current_buffer.name]
 
         if self._current_layout == 0:
             return [
@@ -521,25 +528,25 @@
 
         # If file one is showing, go to it.
         windows.focus(2)
-        if buffers.current.name == buffers.one.name:
+        if buffers.current == buffers.one:
             return
 
         windows.focus(3)
-        if buffers.current.name == buffers.one.name:
+        if buffers.current == buffers.one:
             return
 
         # If both the original and result are showing, open file one in the
         # current window.
         windows.focus(2)
-        if buffers.current.name == buffers.original.name:
+        if buffers.current == buffers.original:
             windows.focus(3)
-            if buffers.current.name == buffers.result.name:
+            if buffers.current == buffers.result:
                 open_one(curwindow)
                 return
 
         # If file two is in window 1, then we open file one in window 1.
         windows.focus(2)
-        if buffers.current.name == buffers.two.name:
+        if buffers.current == buffers.two:
             open_one(2)
             return
 
@@ -562,25 +569,25 @@
 
         # If file two is showing, go to it.
         windows.focus(2)
-        if buffers.current.name == buffers.two.name:
+        if buffers.current == buffers.two:
             return
 
         windows.focus(3)
-        if buffers.current.name == buffers.two.name:
+        if buffers.current == buffers.two:
             return
 
         # If both the original and result are showing, open file two in the
         # current window.
         windows.focus(2)
-        if buffers.current.name == buffers.original.name:
+        if buffers.current == buffers.original:
             windows.focus(3)
-            if buffers.current.name == buffers.result.name:
+            if buffers.current == buffers.result:
                 open_two(curwindow)
                 return
 
         # If file one is in window 2, then we open file two in window 2.
         windows.focus(3)
-        if buffers.current.name == buffers.two.name:
+        if buffers.current == buffers.two:
             open_two(3)
             return
 
@@ -596,18 +603,17 @@
         self.redraw_hud()
 
 
+    def key_use(self):
+        pass
+
+
     def goto_result(self):
         self.key_result()
 
 
     def hud_diagram(self):
-        bufmap = { buffers.original.name: 'Original',
-                   buffers.one.name: 'One',
-                   buffers.two.name: 'Two',
-                   buffers.result.name: 'Result' }
-
-        first = bufmap[self._current_buffer_first.name]
-        second = bufmap[self._current_buffer_second.name]
+        first = buffers.labels[self._current_buffer_first.name]
+        second = buffers.labels[self._current_buffer_second.name]
 
         if self._current_layout == 0:
             return [
@@ -755,12 +761,16 @@
         windows.focus(4)
 
 
+    def key_use(self):
+        pass
+
+
     def goto_result(self):
         windows.focus(4)
 
 
     def hud_diagram(self):
-        if self._current_mid_buffer.name == buffers.one.name:
+        if self._current_mid_buffer == buffers.one:
             buf = 'One'
         else:
             buf = 'Two'
--- a/plugin/threesomelib/util/bufferlib.py	Mon Jun 13 20:44:37 2011 -0400
+++ b/plugin/threesomelib/util/bufferlib.py	Mon Jun 13 20:58:58 2011 -0400
@@ -1,7 +1,6 @@
 import os
 import vim
 import windows
-from io import error
 
 ap = os.path.abspath
 
@@ -25,6 +24,13 @@
             yield line
 
 
+    def __eq__(self, other):
+        return self.name == other.name
+
+    def __ne__(self, other):
+        return self.name != other.name
+
+
 class _BufferList(object):
     @property
     def original(self):
@@ -64,4 +70,13 @@
     def all(self):
         return [self.original, self.one, self.two, self.result]
 
+
+    @property
+    def labels(self):
+        return { buffers.original.name: 'Original',
+                 buffers.one.name: 'One',
+                 buffers.two.name: 'Two',
+                 buffers.result.name: 'Result' }
+
 buffers = _BufferList()
+