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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
|
# -*- coding: utf-8 -*-
'''
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.domain import task, effort, date
from taskcoachlib.i18n import _
import base
import noteCommands
class SaveTaskStateMixin(base.SaveStateMixin, base.CompositeMixin):
pass
class EffortCommand(base.BaseCommand): # pylint: disable=W0223
def stopTracking(self):
self.stoppedEfforts = [] # pylint: disable=W0201
for taskToStop in self.tasksToStopTracking():
self.stoppedEfforts.extend(taskToStop.activeEfforts())
taskToStop.stopTracking()
def startTracking(self):
for stoppedEffort in self.stoppedEfforts:
stoppedEffort.setStop(date.DateTime.max)
def tasksToStopTracking(self):
return self.list
def do_command(self):
super(EffortCommand, self).do_command()
self.stopTracking()
def undo_command(self):
super(EffortCommand, self).undo_command()
self.startTracking()
def redo_command(self):
super(EffortCommand, self).redo_command()
self.stopTracking()
class DragAndDropTaskCommand(base.OrderingDragAndDropCommand):
plural_name = _('Drag and drop tasks')
def getItemsToSave(self):
toSave = super(DragAndDropTaskCommand, self).getItemsToSave()
if self.part != 0:
toSave.extend(self.getSiblings())
return list(set(toSave)) # Because parent may have added siblings as well
def do_command(self):
if self.part == 0 or self.isOrdering():
super(DragAndDropTaskCommand, self).do_command()
else:
if self.part == -1:
# Up part. Add dropped items as prerequisites of dropped on item.
self._itemToDropOn.addPrerequisites(self.items)
self._itemToDropOn.addTaskAsDependencyOf(self.items)
else:
# Down. Add dropped on item as prerequisite of dropped items.
for item in self.items:
item.addPrerequisites([self._itemToDropOn])
item.addTaskAsDependencyOf([self._itemToDropOn])
def undo_command(self):
if self.part == 0 or self.isOrdering():
super(DragAndDropTaskCommand, self).undo_command()
elif self.part == -1:
self._itemToDropOn.removePrerequisites(self.items)
self._itemToDropOn.removeTaskAsDependencyOf(self.items)
else:
for item in self.items:
item.removePrerequisites([self._itemToDropOn])
item.removeTaskAsDependencyOf([self._itemToDropOn])
def redo_command(self):
if self.part == 0 or self.isOrdering():
super(DragAndDropTaskCommand, self).redo_command()
elif self.part == -1:
self._itemToDropOn.addPrerequisites(self.items)
self._itemToDropOn.addTaskAsDependencyOf(self.items)
else:
for item in self.items:
item.addPrerequisites([self._itemToDropOn])
item.addTaskAsDependencyOf([self._itemToDropOn])
class DeleteTaskCommand(base.DeleteCommand, EffortCommand):
plural_name = _('Delete tasks')
singular_name = _('Delete task "%s"')
def tasksToStopTracking(self):
return self.items
def do_command(self):
super(DeleteTaskCommand, self).do_command()
self.stopTracking()
self.__removePrerequisites()
def undo_command(self):
super(DeleteTaskCommand, self).undo_command()
self.startTracking()
self.__restorePrerequisites()
def redo_command(self):
super(DeleteTaskCommand, self).redo_command()
self.stopTracking()
self.__removePrerequisites()
def __removePrerequisites(self):
self.__relationsToRestore = dict() # pylint: disable=W0201
for eachTask in self.items:
prerequisites, dependencies = eachTask.prerequisites(), eachTask.dependencies()
self.__relationsToRestore[eachTask] = prerequisites, dependencies
eachTask.removeTaskAsDependencyOf(prerequisites)
eachTask.removeTaskAsPrerequisiteOf(dependencies)
eachTask.setPrerequisites([])
eachTask.setDependencies([])
def __restorePrerequisites(self):
for eachTask, (prerequisites, dependencies) in self.__relationsToRestore.items():
eachTask.addTaskAsDependencyOf(prerequisites)
eachTask.addTaskAsPrerequisiteOf(dependencies)
eachTask.setPrerequisites(prerequisites)
eachTask.setDependencies(dependencies)
class NewTaskCommand(base.NewItemCommand):
singular_name = _('New task')
def __init__(self, *args, **kwargs):
subject = kwargs.pop('subject', _('New task'))
super(NewTaskCommand, self).__init__(*args, **kwargs)
self.items = [task.Task(subject=subject, **kwargs)]
@patterns.eventSource
def do_command(self, event=None):
super(NewTaskCommand, self).do_command(event=event)
self.addDependenciesAndPrerequisites()
@patterns.eventSource
def undo_command(self, event=None):
super(NewTaskCommand, self).undo_command(event=event)
self.removeDependenciesAndPrerequisites()
@patterns.eventSource
def redo_command(self, event=None):
super(NewTaskCommand, self).redo_command(event=event)
self.addDependenciesAndPrerequisites()
def addDependenciesAndPrerequisites(self):
for eachTask in self.items:
for prerequisite in eachTask.prerequisites():
prerequisite.addDependencies([eachTask])
for dependency in eachTask.dependencies():
dependency.addPrerequisites([eachTask])
def removeDependenciesAndPrerequisites(self):
for eachTask in self.items:
for prerequisite in eachTask.prerequisites():
prerequisite.removeDependencies([eachTask])
for dependency in eachTask.dependencies():
dependency.removePrerequisites([eachTask])
class NewSubTaskCommand(base.NewSubItemCommand, SaveTaskStateMixin):
plural_name = _('New subtasks')
singular_name = _('New subtask of "%s"')
# pylint: disable=E1101
def __init__(self, *args, **kwargs):
subject = kwargs.pop('subject', _('New subtask'))
plannedStartDateTime = kwargs.pop('plannedStartDateTime', date.DateTime())
dueDateTime = kwargs.pop('dueDateTime', date.DateTime())
super(NewSubTaskCommand, self).__init__(*args, **kwargs)
self.items = [parent.newChild(subject=subject,
plannedStartDateTime=max([parent.plannedStartDateTime(), plannedStartDateTime]),
dueDateTime=min([parent.dueDateTime(), dueDateTime]),
**kwargs) for parent in self.items]
self.saveStates(self.getTasksToSave())
self.save_modification_datetimes()
def getTasksToSave(self):
# FIXME: can be simplified to: return self.getAncestors(self.items) ?
parents = [item.parent() for item in self.items if item.parent()]
return parents + self.getAncestors(parents)
@patterns.eventSource
def undo_command(self, event=None):
super(NewSubTaskCommand, self).undo_command(event=event)
self.undoStates(event=event)
@patterns.eventSource
def redo_command(self, event=None):
super(NewSubTaskCommand, self).redo_command(event=event)
self.redoStates(event=event)
class MarkCompletedCommand(base.SaveStateMixin, EffortCommand):
plural_name = _('Mark tasks completed')
singular_name = _('Mark "%s" completed')
def __init__(self, *args, **kwargs):
super(MarkCompletedCommand, self).__init__(*args, **kwargs)
self.items = [item for item in self.items if item.completionDateTime() > date.Now()]
itemsToSave = set([relative for item in self.items for relative in item.family()])
self.saveStates(itemsToSave)
def do_command(self):
super(MarkCompletedCommand, self).do_command()
for item in self.items:
item.setCompletionDateTime(task.Task.suggestedCompletionDateTime())
def undo_command(self):
self.undoStates()
super(MarkCompletedCommand, self).undo_command()
def redo_command(self):
self.redoStates()
super(MarkCompletedCommand, self).redo_command()
def tasksToStopTracking(self):
return self.items
class MarkActiveCommand(base.SaveStateMixin, base.BaseCommand):
plural_name = _('Mark task active')
singular_name = _('Mark "%s" active')
def __init__(self, *args, **kwargs):
super(MarkActiveCommand, self).__init__(*args, **kwargs)
self.items = [item for item in self.items if item.actualStartDateTime() > date.Now() or item.completionDateTime() != date.DateTime()]
itemsToSave = set([relative for item in self.items for relative in item.family()])
self.saveStates(itemsToSave)
def do_command(self):
super(MarkActiveCommand, self).do_command()
for item in self.items:
item.setActualStartDateTime(task.Task.suggestedActualStartDateTime())
item.setCompletionDateTime(date.DateTime())
def undo_command(self):
self.undoStates()
super(MarkActiveCommand, self).undo_command()
def redo_command(self):
self.redoStates()
super(MarkActiveCommand, self).redo_command()
class MarkInactiveCommand(base.SaveStateMixin, base.BaseCommand):
plural_name = _('Mark task inactive')
singular_name = _('Mark "%s" inactive')
def __init__(self, *args, **kwargs):
super(MarkInactiveCommand, self).__init__(*args, **kwargs)
self.items = [item for item in self.items if item.actualStartDateTime() != date.DateTime() or item.completionDateTime() != date.DateTime()]
itemsToSave = set([relative for item in self.items for relative in item.family()])
self.saveStates(itemsToSave)
def do_command(self):
super(MarkInactiveCommand, self).do_command()
for item in self.items:
item.setActualStartDateTime(date.DateTime())
item.setCompletionDateTime(date.DateTime())
def undo_command(self):
self.undoStates()
super(MarkInactiveCommand, self).undo_command()
def redo_command(self):
self.redoStates()
super(MarkInactiveCommand, self).redo_command()
class StartEffortCommand(EffortCommand):
plural_name = _('Start tracking')
singular_name = _('Start tracking "%s"')
def __init__(self, *args, **kwargs):
super(StartEffortCommand, self).__init__(*args, **kwargs)
start = date.DateTime.now()
self.efforts = [effort.Effort(item, start) for item in self.items]
self.actualStartDateTimes = [(item.actualStartDateTime() if start < item.actualStartDateTime() else None) for item in self.items]
def do_command(self):
super(StartEffortCommand, self).do_command()
self.addEfforts()
def undo_command(self):
self.removeEfforts()
super(StartEffortCommand, self).undo_command()
def redo_command(self):
super(StartEffortCommand, self).redo_command()
self.addEfforts()
def addEfforts(self):
for item, newEffort, currentActualStartDateTime in zip(self.items, self.efforts, self.actualStartDateTimes):
item.addEffort(newEffort)
if currentActualStartDateTime:
item.setActualStartDateTime(newEffort.getStart())
def removeEfforts(self):
for item, newEffort, previousActualStartDateTime in zip(self.items, self.efforts, self.actualStartDateTimes):
item.removeEffort(newEffort)
if previousActualStartDateTime:
item.setActualStartDateTime(previousActualStartDateTime)
class StopEffortCommand(EffortCommand):
plural_name = _('Stop tracking')
singular_name = _('Stop tracking "%s"')
def canDo(self):
return True # No selected items needed.
def tasksToStopTracking(self):
stoppable = lambda effort: effort.isBeingTracked() and not effort.isTotal()
return set([effort.task() for effort in (self.items if self.items else self.list) if stoppable(effort)]) # pylint: disable=W0621
class ExtremePriorityCommand(base.BaseCommand): # pylint: disable=W0223
delta = 'Subclass responsibility'
def __init__(self, *args, **kwargs):
super(ExtremePriorityCommand, self).__init__(*args, **kwargs)
self.oldPriorities = [item.priority() for item in self.items]
self.oldExtremePriority = self.getOldExtremePriority()
def getOldExtremePriority(self):
raise NotImplementedError # pragma: no cover
def setNewExtremePriority(self):
newExtremePriority = self.oldExtremePriority + self.delta
for item in self.items:
item.setPriority(newExtremePriority)
def restorePriorities(self):
for item, oldPriority in zip(self.items, self.oldPriorities):
item.setPriority(oldPriority)
def do_command(self):
super(ExtremePriorityCommand, self).do_command()
self.setNewExtremePriority()
def undo_command(self):
self.restorePriorities()
super(ExtremePriorityCommand, self).undo_command()
def redo_command(self):
super(ExtremePriorityCommand, self).redo_command()
self.setNewExtremePriority()
class MaxPriorityCommand(ExtremePriorityCommand):
plural_name = _('Maximize priority')
singular_name = _('Maximize priority of "%s"')
delta = +1
def getOldExtremePriority(self):
return self.list.maxPriority()
class MinPriorityCommand(ExtremePriorityCommand):
plural_name = _('Minimize priority')
singular_name = _('Minimize priority of "%s"')
delta = -1
def getOldExtremePriority(self):
return self.list.minPriority()
class ChangePriorityCommand(base.BaseCommand): # pylint: disable=W0223
delta = 'Subclass responsibility'
def changePriorities(self, delta):
for item in self.items:
item.setPriority(item.priority() + delta)
def do_command(self):
super(ChangePriorityCommand, self).do_command()
self.changePriorities(self.delta)
def undo_command(self):
self.changePriorities(-self.delta)
super(ChangePriorityCommand, self).undo_command()
def redo_command(self):
super(ChangePriorityCommand, self).redo_command()
self.changePriorities(self.delta)
class IncPriorityCommand(ChangePriorityCommand):
plural_name = _('Increase priority')
singular_name = _('Increase priority of "%s"')
delta = +1
class DecPriorityCommand(ChangePriorityCommand):
plural_name = _('Decrease priority')
singular_name = _('Decrease priority of "%s"')
delta = -1
class EditPriorityCommand(base.BaseCommand):
plural_name = _('Change priority')
singular_name = _('Change priority of "%s"')
def __init__(self, *args, **kwargs):
self.__newPriority = kwargs.pop('newValue')
super(EditPriorityCommand, self).__init__(*args, **kwargs)
self.__oldPriorities = [item.priority() for item in self.items]
def do_command(self):
super(EditPriorityCommand, self).do_command()
for item in self.items:
item.setPriority(self.__newPriority)
def undo_command(self):
super(EditPriorityCommand, self).undo_command()
for item, oldPriority in zip(self.items, self.__oldPriorities):
item.setPriority(oldPriority)
def redo_command(self):
self.do_command()
class AddTaskNoteCommand(noteCommands.AddNoteCommand):
plural_name = _('Add note to tasks')
class EditDateTimeCommand(base.BaseCommand):
def __init__(self, *args, **kwargs):
self._newDateTime = kwargs.pop('newValue')
super(EditDateTimeCommand, self).__init__(*args, **kwargs)
self.__oldDateTimes = [self.getDateTime(item) for item in self.items]
familyMembers = set()
for item in self.items:
for familyMember in item.family():
if familyMember not in self.items:
familyMembers.add(familyMember)
self.__oldFamilyMemberDateTimes = [(familyMember, self.getDateTime(familyMember)) for familyMember in familyMembers]
@staticmethod
def getDateTime(item):
raise NotImplementedError # pragma: no cover
@staticmethod
def setDateTime(item, newDateTime):
raise NotImplementedError # pragma: no cover
def do_command(self):
super(EditDateTimeCommand, self).do_command()
for item in self.items:
self.setDateTime(item, self._newDateTime)
def undo_command(self):
super(EditDateTimeCommand, self).undo_command()
for item, oldDateTime in zip(self.items, self.__oldDateTimes):
self.setDateTime(item, oldDateTime)
for familyMember, oldDateTime in self.__oldFamilyMemberDateTimes:
self.setDateTime(familyMember, oldDateTime)
def redo_command(self):
self.do_command()
class EditPeriodDateTimeCommand(EditDateTimeCommand):
''' Base for date/time commands that also may have to adjust the other
end of the period. E.g., where changing the planned start date should
also change the due date to keep the period the same length. '''
def __init__(self, *args, **kwargs):
self.__keep_delta = kwargs.pop('keep_delta', False)
super(EditPeriodDateTimeCommand, self).__init__(*args, **kwargs)
def do_command(self):
self.__adjustOtherDateTime(direction=1)
super(EditPeriodDateTimeCommand, self).do_command()
def undo_command(self):
super(EditPeriodDateTimeCommand, self).undo_command()
self.__adjustOtherDateTime(direction=-1)
def __adjustOtherDateTime(self, direction):
for item in self.items:
if self.__shouldAdjustItem(item):
delta = direction * (self._newDateTime - self.getDateTime(item))
newOtherDateTime = self.getOtherDateTime(item) + delta
self.setOtherDateTime(item, newOtherDateTime)
def __shouldAdjustItem(self, item):
''' Determine whether the other date/time of the item should be
adjusted. '''
return self.__keep_delta and date.DateTime() not in (self._newDateTime,
item.plannedStartDateTime(),
item.dueDateTime())
@staticmethod
def getOtherDateTime(item):
''' Gets the date/time that represents the other end of the period. '''
raise NotImplementedError # pragma: no cover
@staticmethod
def setOtherDateTime(item, newDateTime):
''' Set the date/time that represents the other end of the period. '''
raise NotImplementedError # pragma: no cover
class EditPlannedStartDateTimeCommand(EditPeriodDateTimeCommand):
plural_name = _('Change planned start date')
singular_name = _('Change planned start date of "%s"')
@staticmethod
def getDateTime(item):
return item.plannedStartDateTime()
@staticmethod
def setDateTime(item, dateTime):
item.setPlannedStartDateTime(dateTime)
@staticmethod
def getOtherDateTime(item):
return item.dueDateTime()
@staticmethod
def setOtherDateTime(item, dateTime):
item.setDueDateTime(dateTime)
class EditDueDateTimeCommand(EditPeriodDateTimeCommand):
plural_name = _('Change due date')
singular_name = _('Change due date of "%s"')
@staticmethod
def getDateTime(item):
return item.dueDateTime()
@staticmethod
def setDateTime(item, dateTime):
item.setDueDateTime(dateTime)
@staticmethod
def getOtherDateTime(item):
return item.plannedStartDateTime()
@staticmethod
def setOtherDateTime(item, dateTime):
item.setPlannedStartDateTime(dateTime)
class EditActualStartDateTimeCommand(EditPeriodDateTimeCommand):
plural_name = _('Change actual start date')
singular_name = _('Change actual start date of "%s"')
@staticmethod
def getDateTime(item):
return item.actualStartDateTime()
@staticmethod
def setDateTime(item, dateTime):
item.setActualStartDateTime(dateTime)
@staticmethod
def getOtherDateTime(item):
return item.completionDateTime()
@staticmethod
def setOtherDateTime(item, dateTime):
item.setCompletionDateTime(dateTime)
class EditCompletionDateTimeCommand(EditDateTimeCommand, EffortCommand):
plural_name = _('Change completion date')
singular_name = _('Change completion date of "%s"')
@staticmethod
def getDateTime(item):
return item.completionDateTime()
@staticmethod
def setDateTime(item, dateTime):
item.setCompletionDateTime(dateTime)
@staticmethod
def getOtherDateTime(item):
return item.actualStartDateTime()
@staticmethod
def setOtherDateTime(item, dateTime):
item.setActualStartDateTime(dateTime)
def tasksToStopTracking(self):
return self.items
class EditReminderDateTimeCommand(EditDateTimeCommand):
plural_name = _('Change reminder dates/times')
singular_name = _('Change reminder date/time of "%s"')
@staticmethod
def getDateTime(item):
return item.reminder()
@staticmethod
def setDateTime(item, dateTime):
item.setReminder(dateTime)
class EditRecurrenceCommand(base.BaseCommand):
plural_name = _('Change recurrences')
singular_name = _('Change recurrence of "%s"')
def __init__(self, *args, **kwargs):
self.__newRecurrence = kwargs.pop('newValue')
super(EditRecurrenceCommand, self).__init__(*args, **kwargs)
self.__oldRecurrences = [item.recurrence() for item in self.items]
def do_command(self):
super(EditRecurrenceCommand, self).do_command()
for item in self.items:
item.setRecurrence(self.__newRecurrence)
def undo_command(self):
super(EditRecurrenceCommand, self).undo_command()
for item, oldRecurrence in zip(self.items, self.__oldRecurrences):
item.setRecurrence(oldRecurrence)
def redo_command(self):
self.do_command()
class EditPercentageCompleteCommand(base.SaveStateMixin, EffortCommand):
plurar_name = ('Change percentages complete')
singular_name = _('Change percentage complete of "%s"')
def __init__(self, *args, **kwargs):
self.__newPercentage = kwargs.pop('newValue')
super(EditPercentageCompleteCommand, self).__init__(*args, **kwargs)
itemsToSave = set([relative for item in self.items for relative in item.family()])
self.saveStates(itemsToSave)
def do_command(self):
super(EditPercentageCompleteCommand, self).do_command()
for item in self.items:
item.setPercentageComplete(self.__newPercentage)
def undo_command(self):
self.undoStates()
super(EditPercentageCompleteCommand, self).undo_command()
def redo_command(self):
self.redoStates()
super(EditPercentageCompleteCommand, self).redo_command()
def tasksToStopTracking(self):
return self.items if self.__newPercentage == 100 else []
class EditShouldMarkCompletedCommand(base.BaseCommand):
plural_name = _('Change when tasks are marked completed')
singular_name = _('Change when "%s" is marked completed')
def __init__(self, *args, **kwargs):
self.__newShouldMarkCompleted = kwargs.pop('newValue')
super(EditShouldMarkCompletedCommand, self).__init__(*args, **kwargs)
self.__oldShouldMarkCompleted = [item.shouldMarkCompletedWhenAllChildrenCompleted() for item in self.items]
def do_command(self):
super(EditShouldMarkCompletedCommand, self).do_command()
for item in self.items:
item.setShouldMarkCompletedWhenAllChildrenCompleted(self.__newShouldMarkCompleted)
def undo_command(self):
super(EditShouldMarkCompletedCommand, self).undo_command()
for item, oldShouldMarkCompleted in zip(self.items, self.__oldShouldMarkCompleted):
item.setShouldMarkCompletedWhenAllChildrenCompleted(oldShouldMarkCompleted)
def redo_command(self):
self.do_command()
class EditBudgetCommand(base.BaseCommand):
plural_name = _('Change budgets')
singular_name = _('Change budget of "%s"')
def __init__(self, *args, **kwargs):
self.__newBudget = kwargs.pop('newValue')
super(EditBudgetCommand, self).__init__(*args, **kwargs)
self.__oldBudgets = [item.budget() for item in self.items]
def do_command(self):
super(EditBudgetCommand, self).do_command()
for item in self.items:
item.setBudget(self.__newBudget)
def undo_command(self):
super(EditBudgetCommand, self).undo_command()
for item, oldBudget in zip(self.items, self.__oldBudgets):
item.setBudget(oldBudget)
def redo_command(self):
self.do_command()
class EditHourlyFeeCommand(base.BaseCommand):
plural_name = _('Change hourly fees')
singular_name = _('Change hourly fee of "%s"')
def __init__(self, *args, **kwargs):
self.__newHourlyFee = kwargs.pop('newValue')
super(EditHourlyFeeCommand, self).__init__(*args, **kwargs)
self.__oldHourlyFees = [item.hourlyFee() for item in self.items]
def do_command(self):
super(EditHourlyFeeCommand, self).do_command()
for item in self.items:
item.setHourlyFee(self.__newHourlyFee)
def undo_command(self):
super(EditHourlyFeeCommand, self).undo_command()
for item, oldHourlyFee in zip(self.items, self.__oldHourlyFees):
item.setHourlyFee(oldHourlyFee)
def redo_command(self):
self.do_command()
class EditFixedFeeCommand(base.BaseCommand):
plural_name = _('Change fixed fees')
singular_name = _('Change fixed fee of "%s"')
def __init__(self, *args, **kwargs):
self.__newFixedFee = kwargs.pop('newValue')
super(EditFixedFeeCommand, self).__init__(*args, **kwargs)
self.__oldFixedFees = [item.fixedFee() for item in self.items]
def do_command(self):
super(EditFixedFeeCommand, self).do_command()
for item in self.items:
item.setFixedFee(self.__newFixedFee)
def undo_command(self):
super(EditFixedFeeCommand, self).undo_command()
for item, oldFixedFee in zip(self.items, self.__oldFixedFees):
item.setFixedFee(oldFixedFee)
def redo_command(self):
self.do_command()
class TogglePrerequisiteCommand(base.BaseCommand):
plural_name = _('Toggle prerequisite')
singular_name = _('Toggle prerequisite of "%s"')
def __init__(self, *args, **kwargs):
self.__checkedPrerequisites = set(kwargs.pop('checkedPrerequisites'))
self.__uncheckedPrerequisites = set(kwargs.pop('uncheckedPrerequisites'))
super(TogglePrerequisiteCommand, self).__init__(*args, **kwargs)
def do_command(self):
super(TogglePrerequisiteCommand, self).do_command()
for item in self.items:
item.addPrerequisites(self.__checkedPrerequisites)
item.addTaskAsDependencyOf(self.__checkedPrerequisites)
item.removePrerequisites(self.__uncheckedPrerequisites)
item.removeTaskAsDependencyOf(self.__uncheckedPrerequisites)
def undo_command(self):
super(TogglePrerequisiteCommand, self).undo_command()
for item in self.items:
item.removePrerequisites(self.__checkedPrerequisites)
item.removeTaskAsDependencyOf(self.__checkedPrerequisites)
item.addPrerequisites(self.__uncheckedPrerequisites)
item.addTaskAsDependencyOf(self.__uncheckedPrerequisites)
def redo_command(self):
self.do_command()
|