bc6297aefe4b

Add use hunks for Grid mode.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Jun 2011 21:46:11 -0400
parents d4684baf9cfe
children 2da3dbb27a42
branches/tags (none)
files plugin/threesome.py plugin/threesome.vim plugin/threesomelib/modes.py plugin/threesomelib/util/keys.py

Changes

--- a/plugin/threesome.py	Mon Jun 13 21:28:36 2011 -0400
+++ b/plugin/threesome.py	Mon Jun 13 21:46:11 2011 -0400
@@ -66,3 +66,9 @@
 def ThreesomeUse():
     threesome.modes.current_mode.key_use()
 
+def ThreesomeUse1():
+    threesome.modes.current_mode.key_use1()
+
+def ThreesomeUse2():
+    threesome.modes.current_mode.key_use2()
+
--- a/plugin/threesome.vim	Mon Jun 13 21:28:36 2011 -0400
+++ b/plugin/threesome.vim	Mon Jun 13 21:46:11 2011 -0400
@@ -155,6 +155,12 @@
 function! s:ThreesomeUse()"{{{
     python ThreesomeUse()
 endfunction"}}}
+function! s:ThreesomeUse1()"{{{
+    python ThreesomeUse1()
+endfunction"}}}
+function! s:ThreesomeUse2()"{{{
+    python ThreesomeUse2()
+endfunction"}}}
 
 "}}}
 
@@ -179,6 +185,8 @@
 command! -nargs=0 ThreesomeNext call s:ThreesomeNext()
 command! -nargs=0 ThreesomePrev call s:ThreesomePrev()
 command! -nargs=0 ThreesomeUse call s:ThreesomeUse()
+command! -nargs=0 ThreesomeUse1 call s:ThreesomeUse1()
+command! -nargs=0 ThreesomeUse2 call s:ThreesomeUse2()
 
 "}}}
 
--- a/plugin/threesomelib/modes.py	Mon Jun 13 21:28:36 2011 -0400
+++ b/plugin/threesomelib/modes.py	Mon Jun 13 21:46:11 2011 -0400
@@ -1,7 +1,7 @@
 from __future__ import with_statement
 
 import vim
-from util import buffers, windows
+from util import buffers, keys, windows
 from settings import boolsetting, setting
 
 
@@ -102,6 +102,9 @@
         self.diff(self._current_diff_mode)
         self.scrollbind(self._current_scrollbind)
 
+    def deactivate(self):
+        pass
+
 
     def key_next(self):
         self.goto_result()
@@ -314,8 +317,64 @@
             windows.focus(3)
 
 
-    def key_use(self):
-        pass
+    def _key_use_0(self, target):
+        targetwin = 3 if target == 1 else 4
+
+        with windows.remain():
+            self.diffoff()
+
+            windows.focus(5)
+            vim.command('diffthis')
+
+            windows.focus(targetwin)
+            vim.command('diffthis')
+
+    def _key_use_12(self, target):
+        targetwin = 2 if target == 1 else 4
+
+        with windows.remain():
+            self.diffoff()
+
+            windows.focus(3)
+            vim.command('diffthis')
+
+            windows.focus(targetwin)
+            vim.command('diffthis')
+
+
+    def key_use1(self):
+        current_diff = self._current_diff_mode
+
+        if self._current_layout == 0:
+            self._key_use_0(1)
+        elif self._current_layout == 1:
+            self._key_use_12(1)
+        elif self._current_layout == 2:
+            self._key_use_12(1)
+
+        if buffers.current == buffers.result:
+            vim.command('diffget')
+        elif buffers.current in (buffers.one, buffers.two):
+            vim.command('diffput')
+
+        self.diff(current_diff)
+
+    def key_use2(self):
+        current_diff = self._current_diff_mode
+
+        if self._current_layout == 0:
+            self._key_use_0(2)
+        elif self._current_layout == 1:
+            self._key_use_12(2)
+        elif self._current_layout == 2:
+            self._key_use_12(2)
+
+        if buffers.current == buffers.result:
+            vim.command('diffget')
+        elif buffers.current in (buffers.one, buffers.two):
+            vim.command('diffput')
+
+        self.diff(current_diff)
 
 
     def goto_result(self):
@@ -327,6 +386,17 @@
             windows.focus(3)
 
 
+    def activate(self):
+        keys.bind('u1', ':ThreesomeUse1<cr>')
+        keys.bind('u2', ':ThreesomeUse2<cr>')
+        return super(GridMode, self).activate()
+
+    def deactivate(self):
+        keys.unbind('u1')
+        keys.unbind('u2')
+        return super(GridMode, self).deactivate()
+
+
     def hud_diagram(self):
         if self._current_layout == 0:
             return [
--- a/plugin/threesomelib/util/keys.py	Mon Jun 13 21:28:36 2011 -0400
+++ b/plugin/threesomelib/util/keys.py	Mon Jun 13 21:46:11 2011 -0400
@@ -3,3 +3,7 @@
 
 def bind(key, to, options='', mode=None, leader='<localleader>'):
     vim.command('nnoremap %s %s%s %s' % (options, leader, key, to))
+
+def unbind(key, options='', leader='<localleader>'):
+    vim.command('unmap %s %s%s' % (options, leader, key))
+