mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-28 03:21:56 +00:00
Make buttons in seach bar nicer (icon, tooltip, autoselect)
Summary: The "Everywhere" button actually selects the home directory, so use an appropriate label ("Your files") and add a "user-home" icon. Pre-select the right button when entering search, depending on the location where the "Find ..." action was triggered. Add tooltips for both buttons, stating where to look for files. Most importantly, this includes the full path for "From here". Canonicalize the path correctly (always strip trailing slash), otherwise QUrl::fileName() will be an empty string, resulting in "From Here (/)" Do not hide the buttons in case the url is non-local, as it is confusing: 1. The state depends on the previous search. When the user hits "Find" when browsing e.g an SMB share, the search was probably in the home dir. 2. The current search location was hidden 3. The user may want to do a local search, give the option to do so. Reviewers: #dolphin, ngraham, elvisangelaccio Reviewed By: #dolphin, ngraham, elvisangelaccio Subscribers: loh.tar, meven, elvisangelaccio, kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D20357
This commit is contained in:
parent
93f26f799f
commit
9ce757b3d3
|
@ -87,22 +87,22 @@ void DolphinSearchBox::setSearchPath(const QUrl& url)
|
|||
QFontMetrics metrics(m_fromHereButton->font());
|
||||
const int maxWidth = metrics.height() * 8;
|
||||
|
||||
QString location = url.fileName();
|
||||
const QUrl cleanedUrl = url.adjusted(QUrl::RemoveUserInfo | QUrl::StripTrailingSlash);
|
||||
QString location = cleanedUrl.fileName();
|
||||
if (location.isEmpty()) {
|
||||
if (url.isLocalFile()) {
|
||||
location = QStringLiteral("/");
|
||||
} else {
|
||||
location = url.scheme() + QLatin1String(" - ") + url.host();
|
||||
}
|
||||
location = cleanedUrl.toString(QUrl::PreferLocalFile);
|
||||
}
|
||||
if (m_fromHereButton->isChecked() && cleanedUrl.path() == QDir::homePath()) {
|
||||
m_fromHereButton->setChecked(false);
|
||||
m_everywhereButton->setChecked(true);
|
||||
} else {
|
||||
m_fromHereButton->setChecked(true);
|
||||
m_everywhereButton->setChecked(false);
|
||||
}
|
||||
|
||||
const QString elidedLocation = metrics.elidedText(location, Qt::ElideMiddle, maxWidth);
|
||||
m_fromHereButton->setText(i18nc("action:button", "From Here (%1)", elidedLocation));
|
||||
|
||||
const bool showSearchFromButtons = url.isLocalFile();
|
||||
m_separator->setVisible(showSearchFromButtons);
|
||||
m_fromHereButton->setVisible(showSearchFromButtons);
|
||||
m_everywhereButton->setVisible(showSearchFromButtons);
|
||||
m_fromHereButton->setToolTip(i18nc("action:button", "Limit search to '%1' and its subfolders", cleanedUrl.toString(QUrl::PreferLocalFile)));
|
||||
|
||||
bool hasFacetsSupport = false;
|
||||
#ifdef HAVE_BALOO
|
||||
|
@ -138,9 +138,6 @@ QUrl DolphinSearchBox::urlForSearching() const
|
|||
|
||||
QString encodedUrl;
|
||||
if (m_everywhereButton->isChecked()) {
|
||||
// It is very unlikely, that the majority of Dolphins target users
|
||||
// mean "the whole harddisk" instead of "my home folder" when
|
||||
// selecting the "Everywhere" button.
|
||||
encodedUrl = QDir::homePath();
|
||||
} else {
|
||||
encodedUrl = m_searchPath.url();
|
||||
|
@ -402,13 +399,16 @@ void DolphinSearchBox::init()
|
|||
|
||||
m_separator = new KSeparator(Qt::Vertical, this);
|
||||
|
||||
// Create "From Here" and "Everywhere"button
|
||||
// Create "From Here" and "Your files" buttons
|
||||
m_fromHereButton = new QToolButton(this);
|
||||
m_fromHereButton->setText(i18nc("action:button", "From Here"));
|
||||
initButton(m_fromHereButton);
|
||||
|
||||
m_everywhereButton = new QToolButton(this);
|
||||
m_everywhereButton->setText(i18nc("action:button", "Everywhere"));
|
||||
m_everywhereButton->setText(i18nc("action:button", "Your files"));
|
||||
m_everywhereButton->setToolTip(i18nc("action:button", "Search in your home directory"));
|
||||
m_everywhereButton->setIcon(QIcon::fromTheme(QStringLiteral("user-home")));
|
||||
m_everywhereButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
initButton(m_everywhereButton);
|
||||
|
||||
QButtonGroup* searchLocationGroup = new QButtonGroup(this);
|
||||
|
|
Loading…
Reference in a new issue