Package pallavi :: Package plugins :: Module SwitchBufferActions
[hide private]
[frames] | no frames]

Source Code for Module pallavi.plugins.SwitchBufferActions

 1  # Copyright (c) 2007 Dusty Phillips 
 2   
 3  # Permission is hereby granted, free of charge, to any person obtaining a 
 4  # copy of this software and associated documentation files (the "Software"), 
 5  # to deal in the Software without restriction, including without limitation 
 6  # the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 7  # and/or sell copies of the Software, and to permit persons to whom the 
 8  # Software is furnished to do so, subject to the following conditions: 
 9   
10  # The above copyright notice and this permission notice shall be included in 
11  # all copies or substantial portions of the Software. 
12   
13  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
14  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
15  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
16  # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
17  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
18  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
19  # DEALINGS IN THE SOFTWARE. 
20   
21  '''This plugin provides actions to switch to the next or previous buffer 
22  in the buffer list, or to switch to a particular filename. Currently, 
23  the sequence is defined arbitrarily by the BufferList class in Views, 
24  but eventually either this plugin or that class should support some sort 
25  of recency list 
26   
27  This plugin provides the following actions: 
28  NextBuffer 
29          Go to the next buffer in the list. 
30  PreviousBuffer 
31          Go to the previous buffer in the list 
32  GoToBuffer 
33          Prompt for a buffer to go to.''' 
34   
35  #@TODO: Support some sort of recency list 
36  from pallavi import EventActionManager 
37  import wx 
38   
39 -def setup():
40 actions.AddAction(EventActionManager.Action("NextBuffer", NextBuffer)) 41 actions.AddAction(EventActionManager.Action("PreviousBuffer", PreviousBuffer)) 42 actions.AddAction(EventActionManager.Action("GoToBuffer", GoToBuffer))
43
44 -def PreviousBuffer(data=None):
45 pageidx = pallavi.focusedView.bufferNotebook.GetPageIndex(pallavi.focusedView.focusedTextView) 46 pageidx = pageidx - 1 47 if pageidx < 0: pageidx = pallavi.focusedView.bufferNotebook.PageCount-1 48 pallavi.focusedView.bufferNotebook.SetSelection(pageidx)
49 -def NextBuffer(data=None):
50 pageidx = pallavi.focusedView.bufferNotebook.GetPageIndex(pallavi.focusedView.focusedTextView) 51 pageidx = (pageidx + 1) % pallavi.focusedView.bufferNotebook.PageCount 52 pallavi.focusedView.bufferNotebook.SetSelection(pageidx)
53
54 -def GoToBuffer(data=None):
55 '''If data is specified, assume it is a filename to find a buffer for, 56 otherwise prompt using an ugly dialog box''' 57 if data == None: 58 dlg = wx.TextEntryDialog(pallavi.focusedView, "Switch To Buffer:", "Buffer Filename:") 59 if dlg.ShowModal() == wx.ID_OK: 60 data = dlg.GetValue() 61 dlg.Destroy() 62 63 for filename in pallavi.focusedView.textViews.keys(): 64 if filename.endswith(data): 65 pallavi.focusedView.bufferNotebook.SetSelection(pallavi.focusedView.bufferNotebook.GetPageIndex(pallavi.focusedView.textViews[filename])) 66 return
67