[Konsole-devel] [Bug 58187] Bizarre sort order in Terminal Sessions Menu

Waldo Bastian bastian at kde.org
Wed May 7 21:11:54 UTC 2003


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
     
http://bugs.kde.org/show_bug.cgi?id=58187     
bastian at kde.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From bastian at kde.org  2003-05-07 23:11 -------
Subject: kdebase/kicker/menuext/konsole

CVS commit by waba: 

CCMAIL: 58187-done at bugs.kde.org
Bring kicker's konsole menu in sync with the one in konsole. (BR58187)


  M +37 -7     konsole_mnu.cpp   1.5


--- kdebase/kicker/menuext/konsole/konsole_mnu.cpp  #1.4:1.5
@@ -63,13 +63,42 @@ KonsoleMenu::~KonsoleMenu()
 }
 
+static void insertItemSorted(KPopupMenu *menu, const QIconSet &iconSet, const QString &txt, int id)
+{
+  const int defaultId = 1; // The id of the 'new' item.
+  int index = menu->indexOf(defaultId);
+  int count = menu->count();
+  if (index >= 0)
+  {
+     index++; // Skip separator
+     while(true)
+     {
+        index++;
+        if (index >= count)
+        {
+           index = -1; // Insert at end
+           break;
+        }
+        if (menu->text(menu->idAt(index)) > txt)
+           break; // Insert before this item
+     }
+  }
+  menu->insertItem(iconSet, txt, id, index);
+}
+
+
 void KonsoleMenu::initialize()
 {
     QStringList list = KGlobal::dirs()->findAllResources("data", "konsole/*.desktop", false, true);
 
-    int id = 0;
+    QString defaultShell = locate("data", "konsole/shell.desktop");
+    list.prepend(defaultShell);
+
+    int id = 1;
 
     sessionList.clear();
     for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it)
     {
+        if ((*it == defaultShell) && (id != 1))
+           continue;
         KSimpleConfig conf(*it, true /* read only */);
         conf.setDesktopGroup();
@@ -82,9 +111,5 @@ void KonsoleMenu::initialize()
         }
 
-        int pos = exec.find(' ');
-        if (pos > 0) {
-             exec = exec.left(pos);
-        }
-
+        exec = KRun::binaryName(exec, false);
         QString pexec = KGlobal::dirs()->findExe(exec);
         if (text.isEmpty() || conf.readEntry("Type") != "KonsoleApplication"
@@ -93,10 +118,14 @@ void KonsoleMenu::initialize()
             continue;
         }
-        insertItem(SmallIconSet(conf.readEntry("Icon", "konsole")), text, id++);
+        insertItemSorted(this, SmallIconSet(conf.readEntry("Icon", "openterm")), text, id++);
         QFileInfo fi(*it);
         sessionList.append(fi.baseName());
+        
+        if (id == 2)
+           insertSeparator();
     }
     bookmarkHandlerSession = new KonsoleBookmarkHandler( this, false );
     m_bookmarksSession = bookmarkHandlerSession->menu();
+    insertSeparator();
     insertItem(SmallIconSet("keditbookmarks"),
                         i18n("New Session at Bookmark"), m_bookmarksSession);
@@ -138,4 +167,5 @@ void KonsoleMenu::initialize()
 void KonsoleMenu::slotExec(int id)
 {
+    id--;
     if (id >= 0)
     {


More information about the konsole-devel mailing list