From d3cb3bf1dde8a508f94f9f3fd145204fe9df5e22 Mon Sep 17 00:00:00 2001
From: David Fairbrother <DavidFair@users.noreply.github.com>
Date: Mon, 30 Mar 2020 12:02:27 +0100
Subject: [PATCH] Re #28445 Create new tab names correctly on KDE

Creates new tab names correctly on non-GNOME enrionvments for Ubuntu.
KDE automatically binds keyboard shortcuts, which Qt represents with &x
(where x is the shortcut). This breaks the name lookup as &New != New in
"New Tab".

We now strip out these characters when looking up the names fixing the
names not incrementing correctly.
---
 docs/source/release/v5.1.0/ui.rst                     |  1 +
 .../widgets/codeeditor/multifileinterpreter.py        | 11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/docs/source/release/v5.1.0/ui.rst b/docs/source/release/v5.1.0/ui.rst
index f54c0b9bf1b..70d20e76c38 100644
--- a/docs/source/release/v5.1.0/ui.rst
+++ b/docs/source/release/v5.1.0/ui.rst
@@ -19,6 +19,7 @@ See :doc:`mantidplot`.
 
 MantidWorkbench
 ---------------
+- Fixed new tab names not incrementing correctly on KDE display environments (i.e. KUbuntu).
 
 See :doc:`mantidworkbench`.
 
diff --git a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py
index 3def7f5f9db..b3188d31646 100644
--- a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py
+++ b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py
@@ -69,7 +69,7 @@ class MultiPythonFileInterpreter(QWidget):
         if filename is None:
             title = NEW_TAB_TITLE
             i = 1
-            while title in self.tab_titles:
+            while title in self.stripped_tab_titles:
                 title = "{} ({})".format(NEW_TAB_TITLE, i)
                 i += 1
             return title, title
@@ -77,8 +77,13 @@ class MultiPythonFileInterpreter(QWidget):
             return osp.basename(filename), filename
 
     @property
-    def tab_titles(self):
-        return [self._tabs.tabText(i).rstrip('*') for i in range(self.editor_count)]
+    def stripped_tab_titles(self):
+        tab_text = [self._tabs.tabText(i) for i in range(self.editor_count)]
+        tab_text = [txt.rstrip('*') for txt in tab_text]
+        # Some DEs (such as KDE) will automatically assign keyboard shortcuts using the Qt & annotation
+        # see Qt Docs - qtabwidget#addTab
+        tab_text = [txt.replace('&', '') for txt in tab_text]
+        return tab_text
 
     def closeEvent(self, event):
         self.deleteLater()
-- 
GitLab