forked from qt-creator/qt-creator
LocatorFilterEntry: Add Acceptor field
Add also AcceptResult structure, returned by acceptor. The Acceptor, being a member of LocatorFilterEntry, is going to be used instead of virtual ILocatorFilter::accept() method. By default, when no Acceptor is provided, the locator widget is going to call EditorManager::openEditor() with a LocatorFilterEntry instance. Change-Id: Ic9697492738d65fd1331bbd0872bc374285c4e53 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -26,6 +26,14 @@ namespace Internal { class Locator; }
|
||||
|
||||
class ILocatorFilter;
|
||||
|
||||
class AcceptResult
|
||||
{
|
||||
public:
|
||||
QString newText;
|
||||
int selectionStart = -1;
|
||||
int selectionLength = 0;
|
||||
};
|
||||
|
||||
class LocatorFilterEntry
|
||||
{
|
||||
public:
|
||||
@@ -77,6 +85,7 @@ public:
|
||||
, displayName(name)
|
||||
{}
|
||||
|
||||
using Acceptor = std::function<AcceptResult()>;
|
||||
/* backpointer to creating filter */
|
||||
ILocatorFilter *filter = nullptr;
|
||||
/* displayed string */
|
||||
@@ -87,8 +96,12 @@ public:
|
||||
QString extraInfo;
|
||||
/* additional tooltip */
|
||||
QString toolTip;
|
||||
/* called by locator widget on accept. By default, when acceptor is empty,
|
||||
EditorManager::openEditor(LocatorFilterEntry) will be used instead. */
|
||||
Acceptor acceptor;
|
||||
/* can be used by the filter to save more information about the entry */
|
||||
QVariant internalData; // DON'T USE IN NEW CODE, IT'S GOING TO BE REMOVED, SOON...
|
||||
/* Replaced by acceptor - DON'T USE IN NEW CODE, IT'S GOING TO BE REMOVED, SOON... */
|
||||
QVariant internalData;
|
||||
/* icon to display along with the entry */
|
||||
std::optional<QIcon> displayIcon;
|
||||
/* file path, if the entry is related to a file, is used e.g. for resolving a file icon */
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "locatorsearchutils.h"
|
||||
#include "../actionmanager/actionmanager.h"
|
||||
#include "../coreplugintr.h"
|
||||
#include "../editormanager/editormanager.h"
|
||||
#include "../icore.h"
|
||||
#include "../modemanager.h"
|
||||
|
||||
@@ -1003,18 +1004,22 @@ void LocatorWidget::acceptEntry(int row)
|
||||
if (!index.isValid())
|
||||
return;
|
||||
const LocatorFilterEntry entry = m_locatorModel->data(index, LocatorEntryRole).value<LocatorFilterEntry>();
|
||||
Q_ASSERT(entry.filter != nullptr);
|
||||
QString newText;
|
||||
int selectionStart = -1;
|
||||
int selectionLength = 0;
|
||||
QWidget *focusBeforeAccept = QApplication::focusWidget();
|
||||
entry.filter->accept(entry, &newText, &selectionStart, &selectionLength);
|
||||
if (newText.isEmpty()) {
|
||||
AcceptResult result;
|
||||
if (entry.acceptor) {
|
||||
result = entry.acceptor();
|
||||
} else if (entry.filter) {
|
||||
entry.filter->accept(entry, &result.newText, &result.selectionStart,
|
||||
&result.selectionLength);
|
||||
} else {
|
||||
EditorManager::openEditor(entry);
|
||||
}
|
||||
if (result.newText.isEmpty()) {
|
||||
emit hidePopup();
|
||||
if (QApplication::focusWidget() == focusBeforeAccept)
|
||||
resetFocus(m_previousFocusWidget, isInMainWindow());
|
||||
} else {
|
||||
showText(newText, selectionStart, selectionLength);
|
||||
showText(result.newText, result.selectionStart, result.selectionLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -28,8 +28,7 @@ namespace Internal {
|
||||
class LocatorModel;
|
||||
class CompletionList;
|
||||
|
||||
class LocatorWidget
|
||||
: public QWidget
|
||||
class LocatorWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
Reference in New Issue
Block a user