~ubuntu-branches/ubuntu/utopic/pida/utopic

« back to all changes in this revision

Viewing changes to pida/editors/vimmultiedit.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-04-17 16:08:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070417160806-3ttlb6igf94x9i03
Tags: 0.4.4-1
* New upstream release (closes: #419129)
* Add dependency on python-glade2 (closes: #418716)
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*- 
2
 
 
3
 
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
 
#Copyright (c) 2006 Ali Afshar aafshar@gmail.com
5
 
 
6
 
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
 
#of this software and associated documentation files (the "Software"), to deal
8
 
#in the Software without restriction, including without limitation the rights
9
 
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 
#copies of the Software, and to permit persons to whom the Software is
11
 
#furnished to do so, subject to the following conditions:
12
 
 
13
 
#The above copyright notice and this permission notice shall be included in
14
 
#all copies or substantial portions of the Software.
15
 
 
16
 
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 
#SOFTWARE.
23
 
 
24
 
import gtk
25
 
import pida.utils.vim.vimcom as vimcom
26
 
import pida.utils.vim.vimeditor as vimeditor
27
 
import pida.core.service as service
28
 
import pida.pidagtk.contentview as contentview
29
 
import pida.pidagtk.icons as icons
30
 
 
31
 
 
32
 
class vim_plugin_view(gtk.HBox):
33
 
    """View holding the vim controls."""
34
 
 
35
 
    def __init__(self, service):
36
 
        self.service = service
37
 
        gtk.HBox.__init__(self, spacing=3)
38
 
        icon = icons.icons.get_image('vim')
39
 
        self.pack_start(icon, expand=False)
40
 
        self.__serverlist = gtk.combo_box_new_text()
41
 
        self.pack_start(self.__serverlist)
42
 
 
43
 
    def set_serverlist(self, serverlist):
44
 
        current = self.__serverlist.get_active_text()
45
 
        self.__serverlist.get_model().clear()
46
 
        j = 0
47
 
        for i, server in enumerate(serverlist):
48
 
            self.__serverlist.append_text(server)
49
 
            if server == current:
50
 
                self.__serverlist.set_active(i)
51
 
            j = 1
52
 
        if j == 0:
53
 
            self.__serverlist.append_text('no vim running')
54
 
            self.__serverlist.set_sensitive(False)
55
 
        else:
56
 
            self.__serverlist.set_sensitive(True)
57
 
        if self.__serverlist.get_active() == -1:
58
 
            self.__serverlist.set_active(0)
59
 
        self.__serverlist.show_all()
60
 
    
61
 
    def get_current_server(self):
62
 
        return self.__serverlist.get_active_text()
63
 
    current_server = property(get_current_server)
64
 
 
65
 
 
66
 
class vim_multi_editor(vimeditor.vim_editor, service.service):
67
 
 
68
 
    display_name = 'External Vim'
69
 
 
70
 
    def start(self):
71
 
        self.__oldservers = []
72
 
        self.view = vim_plugin_view(service=self)
73
 
        self.__cw = vimcom.communication_window(self)
74
 
        self.view.show_all()
75
 
        self.get_service('buffermanager').\
76
 
            plugin_view.widget.pack_start(self.view, expand=False)
77
 
        self.get_service('editormanager').events.emit('started')
78
 
 
79
 
    def vim_new_serverlist(self, serverlist):
80
 
        def _serverlist():
81
 
            for server in serverlist:
82
 
                if 'PIDA_EMBEDDED' not in server:
83
 
                    if server not in self.__oldservers:
84
 
                        self.__cw.init_server(server)
85
 
                    yield server
86
 
        self.view.set_serverlist(_serverlist())
87
 
        self.__oldservers = serverlist
88
 
 
89
 
    def get_server(self):
90
 
        return self.view.current_server
91
 
    server = property(get_server)
92
 
 
93
 
 
94
 
Service = vim_multi_editor
95