~garyvdm/qbzr/read_commit_message_hook

« back to all changes in this revision

Viewing changes to lib/commit.py

  • Committer: Gary van der Merwe
  • Date: 2009-08-21 08:45:35 UTC
  • Revision ID: garyvdm@gmail.com-20090821084535-1pqylgvzccb0mn6w
qcommit: Try to get a message from the commit_message_template hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os.path
23
23
from PyQt4 import QtCore, QtGui
24
24
 
 
25
from bzrlib.msgeditor import generate_commit_message_template
 
26
 
25
27
from bzrlib.plugins.qbzr.lib.spellcheck import SpellCheckHighlighter, SpellChecker
26
28
from bzrlib.plugins.qbzr.lib.autocomplete import get_wordlist_builder
27
29
from bzrlib.plugins.qbzr.lib.commit_data import QBzrCommitData
404
406
                w,
405
407
                QtCore.SLOT("setDisabled(bool)"))
406
408
 
407
 
        self.restore_commit_data()
408
 
        if message:
409
 
            self.message.setText(message)
410
 
 
411
 
        # Try to be smart: if there is no saved message
412
 
        # then set focus on Edit Area; otherwise on OK button.
413
 
        if unicode(self.message.toPlainText()).strip():
414
 
            self.buttonbox.setFocus()
415
 
        else:
416
 
            self.message.setFocus()
417
 
 
418
409
    def show(self):
419
410
        # we show the bare form as soon as possible.
420
411
        SubProcessDialog.show(self)
429
420
        self.refresh_button.setDisabled(True)
430
421
        try:
431
422
            self.tree.lock_read()
 
423
            self.restore_commit_data()
 
424
            # Try to be smart: if there is no saved message
 
425
            # then set focus on Edit Area; otherwise on OK button.
 
426
            if unicode(self.message.toPlainText()).strip():
 
427
                self.buttonbox.setFocus()
 
428
            else:
 
429
                self.message.setFocus()
 
430
            
432
431
            try:
433
432
                if self.pending_merges_list:
434
433
                    self.pending_merges_list.load_branch(self.tree.branch,
522
521
            self.author.setText(self.default_author)
523
522
 
524
523
    def restore_commit_data(self):
525
 
        message = self.ci_data['message']
526
 
        if message:
527
 
            self.message.setText(message)
 
524
        message = ""
 
525
        saved_message = self.ci_data['message']
 
526
        if saved_message is not None:
 
527
            message += saved_message
 
528
        
 
529
        commit_mock_obj = MockCommitObj(self.tree,
 
530
                                        self.initial_selected_list, [])
 
531
        hook_message = generate_commit_message_template(commit_mock_obj)
 
532
        if hook_message is not None:
 
533
            message+=hook_message
 
534
        
 
535
        self.message.setText(message)
528
536
        bug = self.ci_data['bugs']
529
537
        if bug:
530
538
            self.bugs.setText(bug)
541
549
        # collect data
542
550
        ci_data = QBzrCommitData(tree=self.tree)
543
551
        message = unicode(self.message.toPlainText()).strip()
544
 
        if message:
545
 
            ci_data['message'] = message
 
552
        ci_data['message'] = message
546
553
        bug_str = ''
547
554
        if self.bugsCheckBox.isChecked():
548
555
            bug_str = unicode(self.bugs.text()).strip()
714
721
        if unversioned:
715
722
            # XXX show infobox with message that not all files shown in diff
716
723
            pass
 
724
 
 
725
class MockCommitObj (object):
 
726
    def __init__(self, work_tree, specific_files, exclude):
 
727
        self.work_tree = work_tree
 
728
        self.specific_files = specific_files
 
729
        self.exclude = exclude