forked from qt-creator/qt-creator
Do not show empty items in editor history menus
The menus that are available from the back and forward buttons in the editor toolbar could show empty items, because some editors are not backed by files. When they are closed, they are no longer available. For example: open a file, trigger a git diff (regardless of whether that is empty), switch a fill times between file and diff to fill up some history, close the diff. Just do not show history items with empty display names. Change-Id: If7e966e55ada407ed03069027b352d12f053751f Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -534,29 +534,27 @@ void EditorView::cutForwardNavigationHistory()
|
||||
void EditorView::updateNavigatorActions()
|
||||
{
|
||||
static const int MAX_ITEMS = 20;
|
||||
FilePath last;
|
||||
QString lastDisplay;
|
||||
m_backMenu->clear();
|
||||
int count = 0;
|
||||
for (int i = m_currentNavigationHistoryPosition - 1; i >= 0; i--) {
|
||||
const EditLocation &loc = m_navigationHistory.at(i);
|
||||
if (loc.filePath != last) {
|
||||
m_backMenu->addAction(loc.displayName(), this, [this, i] { goToNavigationHistory(i); });
|
||||
last = loc.filePath;
|
||||
if (!loc.displayName().isEmpty() && loc.displayName() != lastDisplay) {
|
||||
lastDisplay = loc.displayName();
|
||||
m_backMenu->addAction(lastDisplay, this, [this, i] { goToNavigationHistory(i); });
|
||||
++count;
|
||||
if (count >= MAX_ITEMS)
|
||||
break;
|
||||
}
|
||||
}
|
||||
last = {};
|
||||
lastDisplay.clear();
|
||||
m_forwardMenu->clear();
|
||||
count = 0;
|
||||
for (int i = m_currentNavigationHistoryPosition + 1; i < m_navigationHistory.size(); i++) {
|
||||
const EditLocation &loc = m_navigationHistory.at(i);
|
||||
if (loc.filePath != last) {
|
||||
m_forwardMenu->addAction(loc.displayName(), this, [this, i] {
|
||||
goToNavigationHistory(i);
|
||||
});
|
||||
last = loc.filePath;
|
||||
if (!loc.displayName().isEmpty() && loc.displayName() != lastDisplay) {
|
||||
lastDisplay = loc.displayName();
|
||||
m_forwardMenu->addAction(lastDisplay, this, [this, i] { goToNavigationHistory(i); });
|
||||
++count;
|
||||
if (count >= MAX_ITEMS)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user