[PATCH] (#2) Better temporary fix for too wide combo box in SVN/CVS commit (bug #115296)

Nicolas Goutte <[email protected]> Sun, 30 Oct 2005 14:15:13 +0100
Newsgroups gmane.comp.kde.devel.kbabel
Message-ID <[email protected]>
The attached patch is for kdesdk/kbabel/catalogmanager

This patch is a better version for fixing the too-wide combo box in the SVN 
commit (again CVS commit is not done et, ut is going to be very similar 
code).

This new patch still limits the number of characters but by using 
KStringHandlerr::csqueeze now (TODO: try to get GUI info about width of combo 
box and font info, as QWidget returns such info).

The old messages are now kept in two QStringList objects: one for the long 
messages, the other for the squeezed ones.

The "activation" of the QComboBox is now done by numbers, as it is 
non-editable.

As for replacing the combo box by a KComboBox, it is superfluous as KComboBox 
extensions compared to QComboBox are only for editable combo boxes.

Have a nice day!

_______________________________________________
kbabel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kbabel
combotoowide2.diff (text/x-diff, 4.2 KB)
Index: libsvn/svndialog.cpp
===================================================================
--- libsvn/svndialog.cpp	(Revision 475265)
+++ libsvn/svndialog.cpp	(Arbeitskopie)
@@ -52,6 +52,7 @@
 #include <kprocess.h>
 #include <ktempfile.h>
 #include <kmessagebox.h>
+#include <kstringhandler.h>
 // Project specific include files
 #include "svndialog.h"
 
@@ -113,8 +114,8 @@
     layout->addWidget( label );
     layout->addWidget( logedit );
 
-    connect( oldMessages, SIGNAL( activated( const QString& ) ),
-      logedit, SLOT( setText( const QString& ) ) );
+    connect( oldMessages, SIGNAL( activated( int ) ),
+      this, SLOT( slotComboActivated( int ) ) );
   }
 
   QHBoxLayout * buttons = new QHBoxLayout( 0, 0, 6, "BUTTON LAYOUT" );
@@ -173,6 +174,13 @@
   connect( cancelBtn, SIGNAL( clicked( ) ), this, SLOT( reject( ) ) );
 }
 
+void SVNDialog::slotComboActivated( int index )
+{
+  if ( index < 0 || index >= m_logMessages.count() )
+    return;
+  logedit->setText( m_logMessages[index] );
+}
+
 SVNDialog::~SVNDialog()
 {
     delete m_tempFile;
@@ -257,11 +265,15 @@
 
     // Update the list of log messages
     if ( !msg.isEmpty() ) {
+      const QString shortLog = KStringHandler::csqueeze( msg, 80 );
+      
+
       // Remove the message from the list if it already exists
-      if ( logMessages.findIndex( msg ) >= 0 )
-        logMessages.remove( msg );
+      m_logMessages.remove( msg );
       // Prepend the current message to the list
-      logMessages.prepend( msg );
+      m_logMessages.prepend( msg );
+
+      // At this time of the process, we do not need the combobox anymore, so we do not squeeze the changed strings.
     }
   }
 
@@ -348,15 +360,27 @@
     autoAddBox->setChecked( config->readBoolEntry( "AutoAddFiles", true ) );
 
     // Fill the combobox with old messages.
-    logMessages.clear( );
+    m_logMessages.clear();
+    m_squeezedLogMessages.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 combo box becomes too wide)
+          // ### FIXME: if the string matches the squeezed 80 chars, it might overwrite another entry
+          const QString shortLog = KStringHandler::csqueeze( logMessage );
+          m_logMessages.append( logMessage );
+          m_squeezedLogMessages.append( shortLog );
+          oldMessages->insertItem( shortLog );
+        }
+      }
 
+    // ### TODO: why is this not simply the first entry?
     // Set the last log message as the one to be used.
     if ( config->readBoolEntry( "PresetLastUsedMessage", false ) )
-      logedit->setText( logMessages.first( ) );
+      logedit->setText( m_squeezedLogMessages.first( ) );
   }
 }
 
@@ -370,8 +394,8 @@
 
     // 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 )
+    QStringList::const_iterator it;
+    for ( it = m_logMessages.constBegin( ); it != m_logMessages.constEnd( ) && cnt < 10 ; ++it, ++cnt )
       config->writeEntry( QString( "CommitLogMessage%1" ).arg( cnt ), *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( int );
 
   private:
     SVN::Command _cmd;
@@ -133,7 +135,10 @@
     QString _addCommand;
     QString _statusOutput;
 
-    QStringList logMessages;
+    /// Log messages (long version)
+    QStringList m_logMessages;
+    /// Log messages (short version)
+    QStringList m_squeezedLogMessages;
 
     /// Temporary file (for commits)
     KTempFile* m_tempFile;