mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 16:31:21 +00:00
Make --select can automatically scroll to the selected file.
REVIEW: 106209
This commit is contained in:
parent
89960b65e9
commit
864495f661
|
@ -554,7 +554,12 @@ void DolphinPart::createDirectory()
|
||||||
|
|
||||||
void DolphinPart::setFilesToSelect(const KUrl::List& files)
|
void DolphinPart::setFilesToSelect(const KUrl::List& files)
|
||||||
{
|
{
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_view->markUrlsAsSelected(files);
|
m_view->markUrlsAsSelected(files);
|
||||||
|
m_view->markUrlAsCurrent(files.at(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
|
@ -98,8 +98,8 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
|
||||||
m_toolTipManager(0),
|
m_toolTipManager(0),
|
||||||
m_selectionChangedTimer(0),
|
m_selectionChangedTimer(0),
|
||||||
m_currentItemUrl(),
|
m_currentItemUrl(),
|
||||||
|
m_scrollToCurrentItem(false),
|
||||||
m_restoredContentsPosition(),
|
m_restoredContentsPosition(),
|
||||||
m_createdItemUrl(),
|
|
||||||
m_selectedUrls(),
|
m_selectedUrls(),
|
||||||
m_versionControlObserver(0)
|
m_versionControlObserver(0)
|
||||||
{
|
{
|
||||||
|
@ -363,6 +363,7 @@ void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
|
||||||
void DolphinView::markUrlAsCurrent(const KUrl& url)
|
void DolphinView::markUrlAsCurrent(const KUrl& url)
|
||||||
{
|
{
|
||||||
m_currentItemUrl = url;
|
m_currentItemUrl = url;
|
||||||
|
m_scrollToCurrentItem = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
|
void DolphinView::selectItems(const QRegExp& pattern, bool enabled)
|
||||||
|
@ -1150,25 +1151,8 @@ QString DolphinView::viewPropertiesContext() const
|
||||||
|
|
||||||
void DolphinView::observeCreatedItem(const KUrl& url)
|
void DolphinView::observeCreatedItem(const KUrl& url)
|
||||||
{
|
{
|
||||||
m_createdItemUrl = url;
|
markUrlAsCurrent(url);
|
||||||
connect(m_model, SIGNAL(directoryLoadingCompleted()),
|
markUrlsAsSelected(QList<KUrl>() << url);
|
||||||
this, SLOT(selectAndScrollToCreatedItem()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinView::selectAndScrollToCreatedItem()
|
|
||||||
{
|
|
||||||
KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager();
|
|
||||||
const int index = m_model->index(m_createdItemUrl);
|
|
||||||
if (index != -1) {
|
|
||||||
selectionManager->setCurrentItem(index);
|
|
||||||
selectionManager->clearSelection();
|
|
||||||
selectionManager->setSelected(index);
|
|
||||||
m_view->scrollToItem(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect(m_model, SIGNAL(directoryLoadingCompleted()),
|
|
||||||
this, SLOT(selectAndScrollToCreatedItem()));
|
|
||||||
m_createdItemUrl = KUrl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
|
void DolphinView::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
|
||||||
|
@ -1186,6 +1170,12 @@ void DolphinView::updateViewState()
|
||||||
const int currentIndex = m_model->index(m_currentItemUrl);
|
const int currentIndex = m_model->index(m_currentItemUrl);
|
||||||
if (currentIndex != -1) {
|
if (currentIndex != -1) {
|
||||||
selectionManager->setCurrentItem(currentIndex);
|
selectionManager->setCurrentItem(currentIndex);
|
||||||
|
|
||||||
|
// scroll to current item and reset the state
|
||||||
|
if (m_scrollToCurrentItem) {
|
||||||
|
m_view->scrollToItem(currentIndex);
|
||||||
|
m_scrollToCurrentItem = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
selectionManager->setCurrentItem(0);
|
selectionManager->setCurrentItem(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,8 +181,8 @@ public:
|
||||||
void markUrlsAsSelected(const QList<KUrl>& urls);
|
void markUrlsAsSelected(const QList<KUrl>& urls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks the item indicated by \p url as the current item after the
|
* Marks the item indicated by \p url to be scrolled to and as the
|
||||||
* directory DolphinView::url() has been loaded.
|
* current item after directory DolphinView::url() has been loaded.
|
||||||
*/
|
*/
|
||||||
void markUrlAsCurrent(const KUrl& url);
|
void markUrlAsCurrent(const KUrl& url);
|
||||||
|
|
||||||
|
@ -640,17 +640,9 @@ private slots:
|
||||||
* Observes the item with the URL \a url. As soon as the directory
|
* Observes the item with the URL \a url. As soon as the directory
|
||||||
* model indicates that the item is available, the item will
|
* model indicates that the item is available, the item will
|
||||||
* get selected and it is assured that the item stays visible.
|
* get selected and it is assured that the item stays visible.
|
||||||
*
|
|
||||||
* @see selectAndScrollToCreatedItem()
|
|
||||||
*/
|
*/
|
||||||
void observeCreatedItem(const KUrl& url);
|
void observeCreatedItem(const KUrl& url);
|
||||||
|
|
||||||
/**
|
|
||||||
* Selects and scrolls to the item that got observed
|
|
||||||
* by observeCreatedItem().
|
|
||||||
*/
|
|
||||||
void selectAndScrollToCreatedItem();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a redirection happens.
|
* Called when a redirection happens.
|
||||||
* Testcase: fish://localhost
|
* Testcase: fish://localhost
|
||||||
|
@ -754,8 +746,8 @@ private:
|
||||||
QTimer* m_selectionChangedTimer;
|
QTimer* m_selectionChangedTimer;
|
||||||
|
|
||||||
KUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
|
KUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5
|
||||||
|
bool m_scrollToCurrentItem; // Used for marking we need to scroll to current item or not
|
||||||
QPoint m_restoredContentsPosition;
|
QPoint m_restoredContentsPosition;
|
||||||
KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
|
|
||||||
|
|
||||||
QList<KUrl> m_selectedUrls; // Used for making the view to remember selections after F5
|
QList<KUrl> m_selectedUrls; // Used for making the view to remember selections after F5
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue