Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

commit: adding format function to message popup menu

Changeset 1d88eaa01450

Parent 59968a529dd7

by Trey Roessig

Changes to one file · Browse files at 1d88eaa01450 Showing diff from parent 59968a529dd7 Diff from another changeset...

Change 1 of 3 Show Entire File hggtk/​commit.py Stacked
 
236
237
238
239
240
241
242
 
651
652
653
654
 
 
655
656
657
 
668
669
670
671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
673
674
 
236
237
238
 
239
240
241
 
650
651
652
 
653
654
655
656
657
 
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
@@ -236,7 +236,6 @@
    self.text = gtk.TextView()   self.text.connect('populate-popup', self._msg_add_to_popup) - self.text.set_wrap_mode(gtk.WRAP_WORD)   self.text.modify_font(pango.FontDescription(self.fontcomment))   scroller.add(self.text)   @@ -651,7 +650,8 @@
  def _msg_add_to_popup(self, textview, menu):   menu_items = (('----', None),   (_('Paste _Filenames'), self._msg_paste_fnames), - ) + (_('App_ly Format'), self._msg_word_wrap), + (_('C_onfigure Format'), self._msg_config))   for label, handler in menu_items:   if label == '----':   menuitem = gtk.SeparatorMenuItem() @@ -668,7 +668,66 @@
  if file[FM_CHECKED] ]   buf.delete_selection(True, True)   buf.insert_at_cursor('\n'.join(fnames)) - + + def _msg_word_wrap(self, sender): + try: + sumlen = int(self.repo.ui.config('tortoisehg', 'summarylen', 0)) + maxlen = int(self.repo.ui.config('tortoisehg', 'messagewrap', 0)) + except (TypeError, ValueError): + sumlen = 0 + maxlen = 0 + if not (sumlen or maxlen): + Prompt(_('Info required'), + _('Word wrap needs to be configured'), + self).run() + self._msg_config(None) + return + + buf = self.text.get_buffer() + lines = buf.get_text(buf.get_start_iter(), + buf.get_end_iter()).splitlines() + if not lines: + return + + if sumlen and len(lines[0].rstrip()) > sumlen: + Prompt(_('Summary Length Violation'), + _('The summary line length of %i is greater than %i' % + (len(lines[0].rstrip()), sumlen)), + self).run() + if sumlen and len(lines) > 1 and len(lines[1].strip()): + Prompt(_('Summary Separation Violation'), + _('The summary line should be followed by a blank line'), + self).run() + if not maxlen: + return + + lnum = int(sumlen > 0) + while lnum < len(lines): + lines[lnum] = lines[lnum].rstrip() + ' ' + if lines[lnum].endswith('. '): + lines[lnum] += ' ' + if len(lines[lnum].rstrip()) > maxlen: + ind = lines[lnum].rfind(' ', 0, maxlen+1) + 1 + if ind > 0: + if lnum == len(lines)-1 or not lines[lnum+1].strip(): + lines.insert(lnum+1, lines[lnum][ind:].lstrip()) + else: + lines[lnum+1] = lines[lnum][ind:].lstrip() \ + + lines[lnum+1] + lines[lnum] = lines[lnum][0:ind].rstrip() + ' ' + lnum += 1 + buf.set_text('\n'.join(lines)) + + def _msg_config(self, sender): + from thgconfig import ConfigDialog + dlg = ConfigDialog(True) + dlg.show_all() + dlg.focus_field('tortoisehg.summarylen') + dlg.run() + dlg.hide() + self.repo = hg.repository(self.ui, self.repo.root) + return +    def run(_ui, *pats, **opts):   cmdoptions = {