[PATCH] Temporary fix for too wide combo box in SVN/CVS commit (#115296)

Nicolas Goutte <[email protected]> Sat, 29 Oct 2005 23:41:39 +0200
Newsgroups gmane.comp.kde.devel.kbabel
Message-ID <[email protected]>
The attached patch is for kdesdk/kbabel/catalogmanager

It tries to make a temporary fix to the symptom that the combo box in the SVN/
CVS commit dialog becomes too wide if there is at least a long old log in the 
log history and therefore makes the dialog useless (as the buttons are near 
the right, out of screen). (Bug #115296)

The patch is only for SVN for now. It has a few drawback. It cuts the strings 
at 80 characters and does not care about duplicates.

I suppose that it could be committed so, until someone of us takes the time to 
make a better fix (for example cut at a certain display wide and not at a 
character number, correct handling of short duplicates that are not duplicate 
at long form.)

(A fix for CVS would be similar but I would like some feedback before porting 
to CVS.)

Have a nice day!

_______________________________________________
kbabel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kbabel
combotoowide.diff (text/x-diff, 3.7 KB)
Index: libsvn/svndialog.cpp
===================================================================
--- libsvn/svndialog.cpp	(Revision 475265)
+++ libsvn/svndialog.cpp	(Arbeitskopie)
@@ -114,7 +114,7 @@
     layout->addWidget( logedit );
 
     connect( oldMessages, SIGNAL( activated( const QString& ) ),
-      logedit, SLOT( setText( const QString& ) ) );
+      this, SLOT( slotComboActivated( const QString& ) ) );
   }
 
   QHBoxLayout * buttons = new QHBoxLayout( 0, 0, 6, "BUTTON LAYOUT" );
@@ -173,6 +173,12 @@
   connect( cancelBtn, SIGNAL( clicked( ) ), this, SLOT( reject( ) ) );
 }
 
+void SVNDialog::slotComboActivated( const QString& str )
+{
+  kdDebug() << "SLOTCOMBOACTIVATED: " << str << endl;
+  logedit->setText( m_logMap[ str ] );
+}
+
 SVNDialog::~SVNDialog()
 {
     delete m_tempFile;
@@ -257,11 +263,14 @@
 
     // Update the list of log messages
     if ( !msg.isEmpty() ) {
+      const QString shortLog = ( msg.length() <= 80 ) ? msg : ( msg.left(80) + "..." );
+      m_logMap[ shortLog ] = msg;
+
       // Remove the message from the list if it already exists
-      if ( logMessages.findIndex( msg ) >= 0 )
-        logMessages.remove( msg );
+      if ( logMessages.findIndex( shortLog ) >= 0 )
+        logMessages.remove( shortLog );
       // Prepend the current message to the list
-      logMessages.prepend( msg );
+      logMessages.prepend( shortLog );
     }
   }
 
@@ -349,10 +358,21 @@
 
     // Fill the combobox with old messages.
     logMessages.clear( );
+    m_logMap.clear();
     for ( int cnt = 0; cnt < 10; cnt++ )
       if ( config->hasKey( QString( "CommitLogMessage%1" ).arg( cnt ) ) )
-        logMessages << config->readEntry( QString( "CommitLogMessage%1" ).arg( cnt ) );
-    oldMessages->insertStringList( logMessages );
+      {
+        const QString logMessage = config->readEntry( QString( "CommitLogMessage%1" ).arg( cnt ) );
+        if ( !logMessage.isEmpty() )
+        {
+          // If the message is too long, cut it to 80 characters (or the comobo box becomes too wide)
+          // ### FIXME: if the string matches the first 80 chars, it might overwrite another entry
+          const QString shortLog = ( logMessage.length() <= 80 ) ? logMessage : ( logMessage.left(80) + "..." );
+          m_logMap[ shortLog ] = logMessage;
+          oldMessages->insertItem( shortLog );
+          logMessages.append( shortLog );
+        }
+      }
 
     // Set the last log message as the one to be used.
     if ( config->readBoolEntry( "PresetLastUsedMessage", false ) )
@@ -370,9 +390,9 @@
 
     // Write the log messages to the config file.
     int cnt = 0;
-    QStringList::Iterator it;
-    for ( it = logMessages.begin( ); it != logMessages.end( ) && cnt < 10 ; ++it, ++cnt )
-      config->writeEntry( QString( "CommitLogMessage%1" ).arg( cnt ), *it );
+    QStringList::const_iterator it;
+    for ( it = logMessages.constBegin( ); it != logMessages.constEnd( ) && cnt < 10 ; ++it, ++cnt )
+      config->writeEntry( QString( "CommitLogMessage%1" ).arg( cnt ), m_logMap[ *it ] );
   }
 }
 
Index: libsvn/svndialog.h
===================================================================
--- libsvn/svndialog.h	(Revision 475265)
+++ libsvn/svndialog.h	(Arbeitskopie)
@@ -115,6 +115,8 @@
     void slotProcessStderr( KProcess*, char * buffer, int len );
     /** Slot for post-processing after the SVN command is fninished. */
     void slotProcessExited( KProcess * p );
+    /// Slot for combox having been activated
+    void slotComboActivated( const QString& str );
 
   private:
     SVN::Command _cmd;
@@ -134,6 +136,8 @@
     QString _statusOutput;
 
     QStringList logMessages;
+    /// Mapping of shortened old log messages to the full legth ones
+    QMap<QString,QString> m_logMap;
 
     /// Temporary file (for commits)
     KTempFile* m_tempFile;