Changeset View
Standalone View
src/views/dolphinview.cpp
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
| 63 | #include <QDropEvent> | 63 | #include <QDropEvent> | ||
| 64 | #include <QGraphicsSceneDragDropEvent> | 64 | #include <QGraphicsSceneDragDropEvent> | ||
| 65 | #include <QMenu> | 65 | #include <QMenu> | ||
| 66 | #include <QPixmapCache> | 66 | #include <QPixmapCache> | ||
| 67 | #include <QPointer> | 67 | #include <QPointer> | ||
| 68 | #include <QScrollBar> | 68 | #include <QScrollBar> | ||
| 69 | #include <QTimer> | 69 | #include <QTimer> | ||
| 70 | #include <QVBoxLayout> | 70 | #include <QVBoxLayout> | ||
| 71 | #include <utils/directoryfindchilditem.h> | ||||
| 71 | 72 | | |||
| 72 | DolphinView::DolphinView(const QUrl& url, QWidget* parent) : | 73 | DolphinView::DolphinView(const QUrl& url, QWidget* parent) : | ||
| 73 | QWidget(parent), | 74 | QWidget(parent), | ||
| 74 | m_active(true), | 75 | m_active(true), | ||
| 75 | m_tabsForFiles(false), | 76 | m_tabsForFiles(false), | ||
| 76 | m_assureVisibleCurrentIndex(false), | 77 | m_assureVisibleCurrentIndex(false), | ||
| 77 | m_isFolderWritable(true), | 78 | m_isFolderWritable(true), | ||
| 78 | m_dragging(false), | 79 | m_dragging(false), | ||
| ▲ Show 20 Lines • Show All 1251 Lines • ▼ Show 20 Line(s) | 1306 | if (item.isMimeTypeKnown()) { | |||
| 1330 | } | 1331 | } | ||
| 1331 | } | 1332 | } | ||
| 1332 | 1333 | | |||
| 1333 | return QUrl(); | 1334 | return QUrl(); | ||
| 1334 | } | 1335 | } | ||
| 1335 | 1336 | | |||
| 1336 | void DolphinView::observeCreatedItem(const QUrl& url) | 1337 | void DolphinView::observeCreatedItem(const QUrl& url) | ||
| 1337 | { | 1338 | { | ||
| 1338 | if (m_active) { | 1339 | if (!m_active) { | ||
| 1339 | forceUrlsSelection(url, {url}); | 1340 | return; | ||
| 1340 | } | 1341 | } | ||
| 1342 | | ||||
| 1343 | // In case url is located in a subdirectory, select its ancestor located in the current dir. | ||||
| 1344 | m_observedCreatedItem = directoryFindChildItem(m_model->directory(), url); | ||||
elvisangelaccio: Are we sure `m_model->directory()` does not already end with a slash? | |||||
From the looks of it the trailing path delimiter is stripped at KIO's KCoreDirLister, which is what KFileItemModel uses to get the url. https://cgit.kde.org/kio.git/tree/src/core/kcoredirlister.cpp#n118 emateli: From the looks of it the trailing path delimiter is stripped at KIO's KCoreDirLister, which is… | |||||
Ok. Then please let's do it like this: const QString dir = QStringLiteral("%1/").arg(m_model->directory().toString()); Also, which dir? Maybe if we call it modelDir it's a bit clearer. elvisangelaccio: Ok. Then please let's do it like this:
```lang=cpp
const QString dir = QStringLiteral("%1/"). | |||||
| 1345 | | ||||
| 1346 | forceUrlsSelection(m_observedCreatedItem, {m_observedCreatedItem}); | ||||
| 1347 | // updateViewState call is needed when the url is a directory and it already exists | ||||
name of what? Maybe we can call it ancestorName ? Also, don't use QDir::separator(), I think it might not work on Windows. From the its doc: You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators(). elvisangelaccio: name of what? Maybe we can call it `ancestorName` ?
Also, don't use `QDir::separator()`, I… | |||||
| 1348 | updateViewState(); | ||||
| 1341 | } | 1349 | } | ||
| 1342 | 1350 | | |||
| 1343 | void DolphinView::slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl) | 1351 | void DolphinView::slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl) | ||
| 1344 | { | 1352 | { | ||
| 1345 | if (oldUrl.matches(url(), QUrl::StripTrailingSlash)) { | 1353 | if (oldUrl.matches(url(), QUrl::StripTrailingSlash)) { | ||
| 1346 | emit redirection(oldUrl, newUrl); | 1354 | emit redirection(oldUrl, newUrl); | ||
| 1347 | m_url = newUrl; // #186947 | 1355 | m_url = newUrl; // #186947 | ||
| 1348 | } | 1356 | } | ||
| ▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 1497 | { | |||
| 1496 | 1504 | | |||
| 1497 | emit directoryLoadingStarted(); | 1505 | emit directoryLoadingStarted(); | ||
| 1498 | } | 1506 | } | ||
| 1499 | 1507 | | |||
| 1500 | void DolphinView::slotDirectoryLoadingCompleted() | 1508 | void DolphinView::slotDirectoryLoadingCompleted() | ||
| 1501 | { | 1509 | { | ||
| 1502 | // Update the view-state. This has to be done asynchronously | 1510 | // Update the view-state. This has to be done asynchronously | ||
| 1503 | // because the view might not be in its final state yet. | 1511 | // because the view might not be in its final state yet. | ||
| 1504 | QTimer::singleShot(0, this, &DolphinView::updateViewState); | 1512 | QTimer::singleShot(0, [this]() { | ||
| 1513 | // if a new item was created mark it as selected as soon as its found by the model | ||||
| 1514 | if (m_observedCreatedItem != QUrl()) { | ||||
| 1515 | const int index = m_model->index(m_observedCreatedItem); | ||||
| 1516 | | ||||
| 1517 | if (index) { | ||||
| 1518 | m_container->controller()->selectionManager()->setCurrentItem(index); | ||||
| 1519 | forceUrlsSelection(m_observedCreatedItem, {m_observedCreatedItem}); | ||||
| 1520 | | ||||
| 1521 | m_observedCreatedItem = QUrl(); | ||||
| 1522 | } | ||||
| 1523 | } | ||||
| 1524 | | ||||
| 1525 | updateViewState(); | ||||
| 1526 | }); | ||||
| 1505 | 1527 | | |||
| 1506 | emit directoryLoadingCompleted(); | 1528 | emit directoryLoadingCompleted(); | ||
| 1507 | 1529 | | |||
| 1508 | updateWritableState(); | 1530 | updateWritableState(); | ||
| 1509 | } | 1531 | } | ||
| 1510 | 1532 | | |||
| 1511 | void DolphinView::slotItemsChanged() | 1533 | void DolphinView::slotItemsChanged() | ||
| 1512 | { | 1534 | { | ||
| ▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Line(s) | |||||
| 1830 | } | 1852 | } | ||
| 1831 | 1853 | | |||
| 1832 | void DolphinView::forceUrlsSelection(const QUrl& current, const QList<QUrl>& selected) | 1854 | void DolphinView::forceUrlsSelection(const QUrl& current, const QList<QUrl>& selected) | ||
| 1833 | { | 1855 | { | ||
| 1834 | clearSelection(); | 1856 | clearSelection(); | ||
| 1835 | m_clearSelectionBeforeSelectingNewItems = true; | 1857 | m_clearSelectionBeforeSelectingNewItems = true; | ||
| 1836 | markUrlAsCurrent(current); | 1858 | markUrlAsCurrent(current); | ||
| 1837 | markUrlsAsSelected(selected); | 1859 | markUrlsAsSelected(selected); | ||
| 1838 | } | 1860 | } | ||
@elvisangelaccio Without this an item which already existed would not be selected(Say directory contains item a, and a/b/c is created). Not 100% sure if this is the right way to tackle this. emateli: @elvisangelaccio Without this an item which already existed would not be selected(Say directory… | |||||
No, it's not. Sadly after this change the dolphin view no longer scrolls the a newly created folder (it does select it, though). elvisangelaccio: No, it's not. Sadly after this change the dolphin view no longer scrolls the a newly created… | |||||
Are we sure m_model->directory() does not already end with a slash?