File: noteCommands.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (186 lines) | stat: -rw-r--r-- 6,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

from taskcoachlib import patterns
from taskcoachlib.i18n import _
from taskcoachlib.domain import note
import base


class NewNoteCommand(base.NewItemCommand):
    singular_name = _('New note')
    
    def __init__(self, *args, **kwargs):
        subject = kwargs.pop('subject', _('New note'))
        description = kwargs.pop('description', '')
        attachments = kwargs.pop('attachments', [])
        categories = kwargs.get('categories',  None)
        super(NewNoteCommand, self).__init__(*args, **kwargs)
        self.items = self.notes = [note.Note(subject=subject,
            description=description, categories=categories, 
            attachments=attachments)]
        

class NewSubNoteCommand(base.NewSubItemCommand):
    plural_name = _('New subnotes')
    singular_name = _('New subnote of "%s"')

    def __init__(self, *args, **kwargs):
        subject = kwargs.pop('subject', _('New subnote'))
        description = kwargs.pop('description', '')
        attachments = kwargs.pop('attachments', [])
        categories = kwargs.get('categories',  None)
        super(NewSubNoteCommand, self).__init__(*args, **kwargs)
        self.items = self.notes = [parent.newChild(subject=subject,
            description=description, categories=categories,
            attachments=attachments) for parent in self.items]
        self.save_modification_datetimes()
                

class DeleteNoteCommand(base.DeleteCommand):
    plural_name = _('Delete notes')
    singular_name = _('Delete note "%s"')
    
    
class DragAndDropNoteCommand(base.OrderingDragAndDropCommand):
    plural_name = _('Drag and drop notes')
    singular_name = _('Drag and drop note "%s"')


class AddNoteCommand(base.BaseCommand):
    plural_name = _('Add note')
    singular_name = _('Add note to "%s"')

    def __init__(self, *args, **kwargs):
        self.owners = []
        super(AddNoteCommand, self).__init__(*args, **kwargs)
        self.owners = self.items
        self.items = self.__notes = [note.Note(subject=_('New note')) \
                                   for dummy in self.items]
        self.save_modification_datetimes()
        
    def modified_items(self):
        return self.owners

    def name_subject(self, newNote): # pylint: disable=W0613
        # Override to use the subject of the owner of the new note instead
        # of the subject of the new note itself, which wouldn't be very
        # interesting because it's something like 'New note'.
        return self.owners[0].subject()
    
    @patterns.eventSource
    def addNotes(self, event=None):
        for owner, note in zip(self.owners, self.__notes): # pylint: disable=W0621
            owner.addNote(note, event=event)

    @patterns.eventSource
    def removeNotes(self, event=None):
        for owner, note in zip(self.owners, self.__notes): # pylint: disable=W0621
            owner.removeNote(note, event=event)
    
    def do_command(self):
        super(AddNoteCommand, self).do_command()
        self.addNotes()
        
    def undo_command(self):
        super(AddNoteCommand, self).undo_command()
        self.removeNotes()
        
    def redo_command(self):
        super(AddNoteCommand, self).redo_command()
        self.addNotes()    


class AddSubNoteCommand(base.BaseCommand):
    plural_name = _('Add subnote')
    singular_name = _('Add subnote to "%s"')
    
    def __init__(self, *args, **kwargs):
        self.__owner = kwargs.pop('owner')
        self.__parents = []
        super(AddSubNoteCommand, self).__init__(*args, **kwargs)
        self.__parents = self.items
        self.__notes = kwargs.get('notes', [note.Note(subject=_('New subnote'),
                                                      parent=parent) \
                                            for parent in self.__parents])
        self.items = self.__notes
        self.save_modification_datetimes()
        
    def modified_items(self):
        return self.__parents + [self.__owner]
    
    @patterns.eventSource
    def addNotes(self, event=None):
        for parent, subnote in zip(self.__parents, self.__notes):
            parent.addChild(subnote, event=event)
            self.__owner.addNote(subnote, event=event)

    @patterns.eventSource
    def removeNotes(self, event=None):
        for parent, subnote in zip(self.__parents, self.__notes):
            parent.removeChild(subnote, event=event)
            self.__owner.removeNote(subnote, event=event)
    
    def do_command(self):
        super(AddSubNoteCommand, self).do_command()
        self.addNotes()
        
    def undo_command(self):
        super(AddSubNoteCommand, self).undo_command()
        self.removeNotes()
        
    def redo_command(self):
        super(AddSubNoteCommand, self).redo_command()
        self.addNotes()


class RemoveNoteCommand(base.BaseCommand):
    plural_name = _('Remove note')
    singular_name = _('Remove note from "%s"')
    
    def __init__(self, *args, **kwargs):
        self.__notes = kwargs.pop('notes')
        super(RemoveNoteCommand, self).__init__(*args, **kwargs)

    @patterns.eventSource
    def addNotes(self, event=None):
        kwargs = dict(event=event)
        for item in self.items:
            item.addNotes(*self.__notes, **kwargs) # pylint: disable=W0142
        
    @patterns.eventSource
    def removeNotes(self, event=None):
        # pylint: disable=W0142
        kwargs = dict(event=event)
        for item in self.items:
            for eachNote in self.__notes:
                if eachNote.parent():
                    eachNote.parent().removeChild(eachNote, **kwargs)
            item.removeNotes(*self.__notes, **kwargs) 
                
    def do_command(self):
        super(RemoveNoteCommand, self).do_command()
        self.removeNotes()
        
    def undo_command(self):
        super(RemoveNoteCommand, self).undo_command()
        self.addNotes()

    def redo_command(self):
        super(RemoveNoteCommand, self).redo_command()
        self.removeNotes()