Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kurlnavigatorplacesselector.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | 80 | for (int i = 0; i < rowCount; ++i) { | |||
---|---|---|---|---|---|
116 | } | 116 | } | ||
117 | } | 117 | } | ||
118 | 118 | | |||
119 | updateTeardownAction(); | 119 | updateTeardownAction(); | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | void KUrlNavigatorPlacesSelector::updateTeardownAction() | 122 | void KUrlNavigatorPlacesSelector::updateTeardownAction() | ||
123 | { | 123 | { | ||
124 | const int rowCount = m_placesModel->rowCount(); | 124 | const QString teardownActionId = QStringLiteral("teardownAction"); | ||
125 | if (m_placesMenu->actions().size() == rowCount + 2) { | | |||
126 | // remove teardown action | | |||
127 | QAction *action = m_placesMenu->actions().at(rowCount + 1); | | |||
128 | m_placesMenu->removeAction(action); | | |||
129 | delete action; | | |||
130 | 125 | | |||
131 | // remove separator | 126 | const auto actions = m_placesMenu->actions(); | ||
132 | action = m_placesMenu->actions().at(rowCount); | 127 | for (QAction *action : actions) { | ||
133 | m_placesMenu->removeAction(action); | 128 | if (action->data() == teardownActionId) { | ||
134 | delete action; | 129 | delete action; | ||
135 | } | 130 | } | ||
131 | } | ||||
136 | 132 | | |||
137 | const QModelIndex index = m_placesModel->index(m_selectedItem, 0); | 133 | const QModelIndex index = m_placesModel->index(m_selectedItem, 0); | ||
138 | QAction *teardown = m_placesModel->teardownActionForIndex(index); | 134 | QAction *teardown = m_placesModel->teardownActionForIndex(index); | ||
139 | if (teardown != nullptr) { | 135 | if (teardown) { | ||
140 | teardown->setParent(m_placesMenu); | 136 | QAction *separator = m_placesMenu->addSeparator(); | ||
141 | teardown->setData(QStringLiteral("teardownAction")); | 137 | separator->setData(teardownActionId); | ||
142 | 138 | | |||
143 | m_placesMenu->addSeparator(); | 139 | teardown->setParent(m_placesMenu); | ||
140 | teardown->setData(teardownActionId); | ||||
144 | m_placesMenu->addAction(teardown); | 141 | m_placesMenu->addAction(teardown); | ||
145 | } | 142 | } | ||
146 | } | 143 | } | ||
147 | 144 | | |||
148 | void KUrlNavigatorPlacesSelector::updateSelection(const QUrl &url) | 145 | void KUrlNavigatorPlacesSelector::updateSelection(const QUrl &url) | ||
149 | { | 146 | { | ||
150 | const QModelIndex index = m_placesModel->closestItem(url); | 147 | const QModelIndex index = m_placesModel->closestItem(url); | ||
151 | if (index.isValid()) { | 148 | if (index.isValid()) { | ||
▲ Show 20 Lines • Show All 150 Lines • Show Last 20 Lines |