~ubuntu-branches/ubuntu/jaunty/pida/jaunty

« back to all changes in this revision

Viewing changes to pida/editors/mooedit.py

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-08-01 13:08:56 UTC
  • mfrom: (0.1.2 etch) (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060801130856-v92ktopgdxc8rv7q
Tags: 0.3.1-2ubuntu1
* Re-sync with Debian
* Remove bashisms from debian/rules

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) 2005 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 pida.core.service as service
 
25
import pida.pidagtk.contentview as contentview
 
26
 
 
27
import moo
 
28
 
 
29
editor_instance = moo.edit.editor_instance()
 
30
editor_instance.get_lang_mgr().add_dir('/usr/local/share/moo-1.0/syntax/')
 
31
editor_instance.get_lang_mgr().read_dirs()
 
32
 
 
33
class moo_view(contentview.content_view):
 
34
 
 
35
    HAS_TITLE = False
 
36
 
 
37
    def init(self, filename=None):
 
38
        import gtk
 
39
        self.widget.set_border_width(6)
 
40
        sw = gtk.ScrolledWindow()
 
41
        self.widget.pack_start(sw)
 
42
        self.__editor = editor_instance.create_doc(filename)
 
43
        sw.add(self.__editor)
 
44
 
 
45
    def get_editor(self):
 
46
        return self.__editor
 
47
    editor = property(get_editor)
 
48
 
 
49
class moo_config_view(contentview.content_view):
 
50
 
 
51
    def init(self):
 
52
        prefs = editor_instance.prefs_page()
 
53
        prefs.emit('init')
 
54
        self.widget.pack_start(prefs)
 
55
        self.__prefs = prefs
 
56
 
 
57
class moo_editor(service.service):
 
58
 
 
59
    NAME = 'mooedit'
 
60
 
 
61
    multi_view_type = moo_view
 
62
    multi_view_book = 'edit'
 
63
 
 
64
    single_view_type = moo_config_view
 
65
    single_view_book = 'view'
 
66
 
 
67
    def init(self):
 
68
        self.__files = {}
 
69
        self.__views = {}
 
70
 
 
71
    def cmd_edit(self, filename=None):
 
72
        if filename not in self.__files:
 
73
            self.__load_file(filename)
 
74
        self.__view_file(filename)
 
75
 
 
76
    def cmd_revert(self):
 
77
        #self.__currentview.editor.reload()
 
78
        pass
 
79
 
 
80
    def __load_file(self, filename):
 
81
        view = self.create_multi_view(filename=filename)
 
82
        self.__files[filename] = view
 
83
        self.__views[view.unique_id] = filename
 
84
 
 
85
    def __view_file(self, filename):
 
86
        self.__currentview = self.__files[filename]
 
87
        self.__files[filename].raise_page()
 
88
 
 
89
    def cmd_start(self):
 
90
        self.get_service('editormanager').events.emit('started')
 
91
 
 
92
    def cmd_goto_line(self, linenumber):
 
93
        self.__currentview.editor.move_cursor(linenumber - 1, 0, True)
 
94
 
 
95
    def cmd_save(self):
 
96
        self.__currentview.editor.save()
 
97
 
 
98
    def cmd_undo(self):
 
99
        self.__currentview.editor.undo()
 
100
 
 
101
    def cmd_redo(self):
 
102
        self.__currentview.editor.redo()
 
103
 
 
104
    def cmd_cut(self):
 
105
        self.__currentview.editor.emit('cut-clipboard')
 
106
 
 
107
    def cmd_copy(self):
 
108
        self.__currentview.editor.emit('copy-clipboard')
 
109
 
 
110
    def cmd_paste(self):
 
111
        self.__currentview.editor.emit('paste-clipboard')
 
112
 
 
113
    def act_editor_preferences(self, action):
 
114
        self.create_single_view()
 
115
 
 
116
    def cb_multiview_closed(self, view):
 
117
        if view.unique_id in self.__views:
 
118
            filename = self.__views[view.unique_id]
 
119
            self.boss.call_command('buffermanager', 'file_closed',
 
120
                                   filename=filename)
 
121
 
 
122
    def get_menu_definition(self):
 
123
        return """
 
124
        <menubar>
 
125
        <menu name="base_tools" action="base_tools_menu">
 
126
        <separator />
 
127
        <menuitem name="mooconf" action="mooedit+editor_preferences" />
 
128
        </menu>
 
129
        </menubar>
 
130
        """
 
131
 
 
132
Service = moo_editor