# HG changeset patch
# User Trey Roessig
# Date 1240982126 25200
# Node ID 1d88eaa01450ff8b67230296a8208a61ee5dd64b
# Parent  59968a529dd7902c6aa60360dd8b64e57c755deb
commit: adding format function to message popup menu

diff -r 59968a529dd7 -r 1d88eaa01450 hggtk/commit.py
--- a/hggtk/commit.py   Tue Apr 28 22:00:27 2009 -0700
+++ b/hggtk/commit.py   Tue Apr 28 22:15:26 2009 -0700
@@ -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 = {

------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Tortoisehg-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tortoisehg-develop

Reply via email to