mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-19 08:21:22 +00:00
* respect the --select startup option
* minor cleanups related to selecting items in general svn path=/trunk/KDE/kdebase/apps/; revision=1063329
This commit is contained in:
parent
d613313b06
commit
e15a9f3a8d
|
@ -72,57 +72,36 @@ void DolphinApplication::refreshMainWindows()
|
||||||
int DolphinApplication::newInstance()
|
int DolphinApplication::newInstance()
|
||||||
{
|
{
|
||||||
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
|
||||||
static bool first = true;
|
|
||||||
|
|
||||||
switch (args->count()) {
|
QList<KUrl> urls;
|
||||||
case 0:
|
const int argsCount = args->count();
|
||||||
if( !first || !isSessionRestored()) {
|
for (int i = 0; i < argsCount; ++i) {
|
||||||
openWindow(KUrl());
|
urls.append(args->url(i));
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
openWindow(args->url(0));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
openSplitWindow(args->url(0),args->url(1));
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
for (int i = 0; i < args->count(); ++i) {
|
|
||||||
openWindow(args->url(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
first = false;
|
DolphinMainWindow* win = createMainWindow();
|
||||||
|
if (urls.count() > 0) {
|
||||||
|
if (args->isSet("select")) {
|
||||||
|
win->openFiles(urls);
|
||||||
|
} else {
|
||||||
|
win->openDirectories(urls);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
win->show();
|
||||||
|
|
||||||
args->clear();
|
args->clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DolphinApplication::openWindow(const KUrl& url)
|
int DolphinApplication::openWindow(const QString& urlString)
|
||||||
{
|
{
|
||||||
DolphinMainWindow* win = createMainWindow();
|
DolphinMainWindow* win = createMainWindow();
|
||||||
if ((win->activeViewContainer() != 0) && url.isValid()) {
|
const KUrl url(urlString);
|
||||||
win->activeViewContainer()->setUrl(url);
|
if (!url.isEmpty()) {
|
||||||
|
win->openDirectories(QList<KUrl>() << url);
|
||||||
}
|
}
|
||||||
win->show();
|
win->show();
|
||||||
return win->getId();
|
return win->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
int DolphinApplication::openSplitWindow(const KUrl& leftUrl, const KUrl& rightUrl)
|
|
||||||
{
|
|
||||||
DolphinMainWindow* win = createMainWindow();
|
|
||||||
if ((win->activeViewContainer() != 0) && leftUrl.isValid()) {
|
|
||||||
win->activeViewContainer()->setUrl(leftUrl);
|
|
||||||
}
|
|
||||||
win->toggleSplitView();
|
|
||||||
if ((win->activeViewContainer() != 0) && rightUrl.isValid()){
|
|
||||||
win->activeViewContainer()->setUrl(rightUrl);
|
|
||||||
}
|
|
||||||
win->show();
|
|
||||||
return win->getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "dolphinapplication.moc"
|
#include "dolphinapplication.moc"
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#define _DOLPHIN_APPLICATION_H
|
#define _DOLPHIN_APPLICATION_H
|
||||||
|
|
||||||
#include <kuniqueapplication.h>
|
#include <kuniqueapplication.h>
|
||||||
#include <kurl.h>
|
|
||||||
|
|
||||||
class DolphinMainWindow;
|
class DolphinMainWindow;
|
||||||
class KUrl;
|
class KUrl;
|
||||||
|
@ -56,11 +55,10 @@ public:
|
||||||
/** @see KUniqueApplication::newInstance(). */
|
/** @see KUniqueApplication::newInstance(). */
|
||||||
virtual int newInstance();
|
virtual int newInstance();
|
||||||
|
|
||||||
public slots:
|
/** Interface implementation for D-Bus Interface. */
|
||||||
int openWindow(const KUrl& url);
|
int openWindow(const QString& urlString);
|
||||||
int openSplitWindow(const KUrl& leftUrl,const KUrl& rightUrl);
|
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
/** Called by the DolphinMainWindow to deregister. */
|
/** Called by the DolphinMainWindow to deregister. */
|
||||||
void removeMainWindow(DolphinMainWindow* mainWindow);
|
void removeMainWindow(DolphinMainWindow* mainWindow);
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,64 @@ DolphinMainWindow::~DolphinMainWindow()
|
||||||
DolphinApplication::app()->removeMainWindow(this);
|
DolphinApplication::app()->removeMainWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::openDirectories(const QList<KUrl>& dirs)
|
||||||
|
{
|
||||||
|
if (dirs.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int oldOpenTabsCount = m_viewTab.count();
|
||||||
|
|
||||||
|
const GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
|
||||||
|
const bool hasSplitView = generalSettings->splitView();
|
||||||
|
|
||||||
|
// Open each directory inside a new tab. If the "split view" option has been enabled,
|
||||||
|
// always show two directories within one tab.
|
||||||
|
QList<KUrl>::const_iterator it = dirs.begin();
|
||||||
|
while (it != dirs.end()) {
|
||||||
|
openNewTab(*it);
|
||||||
|
++it;
|
||||||
|
|
||||||
|
if (hasSplitView && (it != dirs.end())) {
|
||||||
|
const int tabIndex = m_viewTab.count() - 1;
|
||||||
|
m_viewTab[tabIndex].secondaryView->setUrl(*it);
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove the previously opened tabs
|
||||||
|
for (int i = 0; i < oldOpenTabsCount; ++i) {
|
||||||
|
closeTab(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DolphinMainWindow::openFiles(const QList<KUrl>& files)
|
||||||
|
{
|
||||||
|
// Get all distinct directories from 'files' and open a tab
|
||||||
|
// for each directory. If the "split view" option is enabled, two
|
||||||
|
// directories are shown inside one tab (see openDirectories()).
|
||||||
|
QList<KUrl> dirs;
|
||||||
|
foreach (const KUrl& url, files) {
|
||||||
|
const KUrl dir(url.directory());
|
||||||
|
if (!dirs.contains(dir)) {
|
||||||
|
dirs.append(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
openDirectories(dirs);
|
||||||
|
|
||||||
|
// Select the files. Although the files can be split between several
|
||||||
|
// tabs, there is no need to split 'files' accordingly, as
|
||||||
|
// the DolphinView will just ignore invalid selections.
|
||||||
|
const int tabCount = m_viewTab.count();
|
||||||
|
for (int i = 0; i < tabCount; ++i) {
|
||||||
|
m_viewTab[i].primaryView->view()->markUrlsAsSelected(files);
|
||||||
|
if (m_viewTab[i].secondaryView != 0) {
|
||||||
|
m_viewTab[i].secondaryView->view()->markUrlsAsSelected(files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DolphinMainWindow::toggleViews()
|
void DolphinMainWindow::toggleViews()
|
||||||
{
|
{
|
||||||
if (m_viewTab[m_tabIndex].primaryView == 0) {
|
if (m_viewTab[m_tabIndex].primaryView == 0) {
|
||||||
|
@ -251,11 +309,6 @@ void DolphinMainWindow::changeUrl(const KUrl& url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinMainWindow::changeSelection(const KFileItemList& selection)
|
|
||||||
{
|
|
||||||
activeViewContainer()->view()->changeSelection(selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinMainWindow::slotEditableStateChanged(bool editable)
|
void DolphinMainWindow::slotEditableStateChanged(bool editable)
|
||||||
{
|
{
|
||||||
KToggleAction* editableLocationAction =
|
KToggleAction* editableLocationAction =
|
||||||
|
@ -1406,8 +1459,6 @@ void DolphinMainWindow::setupDockWidgets()
|
||||||
foldersPanel, SLOT(setUrl(KUrl)));
|
foldersPanel, SLOT(setUrl(KUrl)));
|
||||||
connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
|
connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
|
||||||
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
|
this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
|
||||||
connect(foldersPanel, SIGNAL(changeSelection(KFileItemList)),
|
|
||||||
this, SLOT(changeSelection(KFileItemList)));
|
|
||||||
|
|
||||||
// setup "Terminal"
|
// setup "Terminal"
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
|
|
|
@ -73,6 +73,19 @@ public:
|
||||||
*/
|
*/
|
||||||
DolphinViewContainer* activeViewContainer() const;
|
DolphinViewContainer* activeViewContainer() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens each directory \p in a separate tab. If the "split view"
|
||||||
|
* option is enabled, 2 directories are collected within one tab.
|
||||||
|
*/
|
||||||
|
void openDirectories(const QList<KUrl>& dirs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the directory which contains the files \p files
|
||||||
|
* and selects all files (implements the --select option
|
||||||
|
* of Dolphin).
|
||||||
|
*/
|
||||||
|
void openFiles(const QList<KUrl>& files);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true, if the main window contains two instances
|
* Returns true, if the main window contains two instances
|
||||||
* of a view container. The active view constainer can be
|
* of a view container. The active view constainer can be
|
||||||
|
@ -123,17 +136,12 @@ public slots:
|
||||||
int getId() const;
|
int getId() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Implementation of the MainWindowAdaptor/QDBusAbstractAdaptor interface.
|
||||||
* Inform all affected dolphin components (panels, views) of an URL
|
* Inform all affected dolphin components (panels, views) of an URL
|
||||||
* change.
|
* change.
|
||||||
*/
|
*/
|
||||||
void changeUrl(const KUrl& url);
|
void changeUrl(const KUrl& url);
|
||||||
|
|
||||||
/**
|
|
||||||
* Inform all affected dolphin components that a selection change is
|
|
||||||
* requested.
|
|
||||||
*/
|
|
||||||
void changeSelection(const KFileItemList& selection);
|
|
||||||
|
|
||||||
/** Stores all settings and quits Dolphin. */
|
/** Stores all settings and quits Dolphin. */
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
|
|
@ -291,6 +291,14 @@ bool DolphinView::hasSelection() const
|
||||||
return view && view->selectionModel()->hasSelection();
|
return view && view->selectionModel()->hasSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
|
||||||
|
{
|
||||||
|
foreach (const KUrl& url, urls) {
|
||||||
|
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
|
||||||
|
m_selectedItems.append(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KFileItemList DolphinView::selectedItems() const
|
KFileItemList DolphinView::selectedItems() const
|
||||||
{
|
{
|
||||||
const QAbstractItemView* view = m_viewAccessor.itemView();
|
const QAbstractItemView* view = m_viewAccessor.itemView();
|
||||||
|
@ -441,7 +449,7 @@ void DolphinView::reload()
|
||||||
QByteArray viewState;
|
QByteArray viewState;
|
||||||
QDataStream saveStream(&viewState, QIODevice::WriteOnly);
|
QDataStream saveStream(&viewState, QIODevice::WriteOnly);
|
||||||
saveState(saveStream);
|
saveState(saveStream);
|
||||||
m_selectedItems = selectedItems();
|
m_selectedItems= selectedItems();
|
||||||
|
|
||||||
setUrl(url());
|
setUrl(url());
|
||||||
loadDirectory(url(), true);
|
loadDirectory(url(), true);
|
||||||
|
@ -598,27 +606,6 @@ void DolphinView::clearSelection()
|
||||||
m_viewAccessor.itemView()->clearSelection();
|
m_viewAccessor.itemView()->clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinView::changeSelection(const KFileItemList& selection)
|
|
||||||
{
|
|
||||||
clearSelection();
|
|
||||||
if (selection.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const KUrl& baseUrl = url();
|
|
||||||
KUrl url;
|
|
||||||
QItemSelection newSelection;
|
|
||||||
foreach(const KFileItem& item, selection) {
|
|
||||||
url = item.url().upUrl();
|
|
||||||
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
|
|
||||||
QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
|
|
||||||
newSelection.select(index, index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_viewAccessor.itemView()->selectionModel()->select(newSelection,
|
|
||||||
QItemSelectionModel::ClearAndSelect
|
|
||||||
| QItemSelectionModel::Current);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinView::renameSelectedItems()
|
void DolphinView::renameSelectedItems()
|
||||||
{
|
{
|
||||||
KFileItemList items = selectedItems();
|
KFileItemList items = selectedItems();
|
||||||
|
@ -1227,7 +1214,19 @@ void DolphinView::slotLoadingCompleted()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_selectedItems.isEmpty()) {
|
if (!m_selectedItems.isEmpty()) {
|
||||||
changeSelection(m_selectedItems);
|
const KUrl& baseUrl = url();
|
||||||
|
KUrl url;
|
||||||
|
QItemSelection newSelection;
|
||||||
|
foreach(const KFileItem& item, m_selectedItems) {
|
||||||
|
url = item.url().upUrl();
|
||||||
|
if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
|
||||||
|
QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
|
||||||
|
newSelection.select(index, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_viewAccessor.itemView()->selectionModel()->select(newSelection,
|
||||||
|
QItemSelectionModel::ClearAndSelect
|
||||||
|
| QItemSelectionModel::Current);
|
||||||
m_selectedItems.clear();
|
m_selectedItems.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,14 @@ public:
|
||||||
*/
|
*/
|
||||||
bool supportsCategorizedSorting() const;
|
bool supportsCategorizedSorting() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the items indicated by \p urls to get selected after the
|
||||||
|
* directory DolphinView::url() has been loaded. Note that nothing
|
||||||
|
* gets selected if no loading of a directory has been triggered
|
||||||
|
* by DolphinView::setUrl() or DolphinView::reload().
|
||||||
|
*/
|
||||||
|
void markUrlsAsSelected(const QList<KUrl>& urls);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the selected items. The list is empty if no item has been
|
* Returns the selected items. The list is empty if no item has been
|
||||||
* selected.
|
* selected.
|
||||||
|
@ -381,14 +389,6 @@ public slots:
|
||||||
|
|
||||||
void clearSelection();
|
void clearSelection();
|
||||||
|
|
||||||
/**
|
|
||||||
* Request of a selection change. The view will do its best to accommodate
|
|
||||||
* the request, but it is not guaranteed that all items in \a selection
|
|
||||||
* will actually get selected. The view will e.g. not select items which
|
|
||||||
* are not in the currently displayed folder.
|
|
||||||
*/
|
|
||||||
void changeSelection(const KFileItemList& selection);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers the renaming of the currently selected items, where
|
* Triggers the renaming of the currently selected items, where
|
||||||
* the user must input a new name for the items.
|
* the user must input a new name for the items.
|
||||||
|
|
|
@ -68,7 +68,14 @@ int main(int argc, char **argv)
|
||||||
KCmdLineArgs::init(argc, argv, &about);
|
KCmdLineArgs::init(argc, argv, &about);
|
||||||
|
|
||||||
KCmdLineOptions options;
|
KCmdLineOptions options;
|
||||||
options.add("+[Url]", ki18nc("@info:shell", "Document to open"));
|
|
||||||
|
// TODO KDE SC 4.5: The string freeze is valid and no new localized strings are allowed.
|
||||||
|
// To get in the --select option that was available in Konqueror 3, an already existing
|
||||||
|
// string ("Document to open") is used as workaround (the --select option will most probably
|
||||||
|
// anyhow used by applications and not by users).
|
||||||
|
const KLocalizedString& documentToOpen = ki18nc("@info:shell", "Document to open");
|
||||||
|
options.add("select", documentToOpen);
|
||||||
|
options.add("+[Url]", documentToOpen);
|
||||||
KCmdLineArgs::addCmdLineOptions(options);
|
KCmdLineArgs::addCmdLineOptions(options);
|
||||||
|
|
||||||
if (!DolphinApplication::start()) {
|
if (!DolphinApplication::start()) {
|
||||||
|
|
|
@ -185,7 +185,6 @@ void FoldersPanel::contextMenuEvent(QContextMenuEvent* event)
|
||||||
if (index.isValid()) {
|
if (index.isValid()) {
|
||||||
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
|
const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
|
||||||
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
|
item = m_dolphinModel->itemForIndex(dolphinModelIndex);
|
||||||
emit changeSelection(KFileItemList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeViewContextMenu contextMenu(this, item);
|
TreeViewContextMenu contextMenu(this, item);
|
||||||
|
|
|
@ -59,15 +59,6 @@ signals:
|
||||||
*/
|
*/
|
||||||
void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
|
void changeUrl(const KUrl& url, Qt::MouseButtons buttons);
|
||||||
|
|
||||||
/**
|
|
||||||
* This signal is emitted when the panel requests a change in the
|
|
||||||
* current selection. The file-management view recieving this signal is
|
|
||||||
* not required to select all listed files, limiting the selection to
|
|
||||||
* e.g. the current folder. The new selection will be reported via the
|
|
||||||
* setSelection slot.
|
|
||||||
*/
|
|
||||||
void changeSelection(const KFileItemList& selection);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* Changes the current selection inside the tree to \a url.
|
* Changes the current selection inside the tree to \a url.
|
||||||
|
|
Loading…
Reference in a new issue