File indexing completed on 2024-05-12 04:38:07

0001 /*
0002     SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_QUICKOPENDATAPROVIDER_H
0008 #define KDEVPLATFORM_QUICKOPENDATAPROVIDER_H
0009 
0010 #include <QList>
0011 #include <QObject>
0012 #include <QSet>
0013 #include <QExplicitlySharedDataPointer>
0014 
0015 #include <language/languageexport.h>
0016 
0017 class QString;
0018 class QStringList;
0019 class QIcon;
0020 
0021 namespace KDevelop {
0022 class IndexedString;
0023 
0024 /**
0025  * Hint: When implementing a data-provider, do not forget to export it! Else it won't work.
0026  * */
0027 
0028 /**
0029  * If your plugin manages a list of files, you can use this to return that list.
0030  * The file-list can be queried by other data-providers(for example functions/methods) so they
0031  * can manipulate their content based on those file-lists. The file-list should not be filtered at all,
0032  * it should only depend on the enabled models/items
0033  *
0034  * Example: A list of files in the include-path, a list of files in the project, etc.
0035  * */
0036 class KDEVPLATFORMLANGUAGE_EXPORT QuickOpenFileSetInterface
0037 {
0038 public:
0039     virtual QSet<IndexedString> files() const = 0;
0040     virtual ~QuickOpenFileSetInterface();
0041 };
0042 /**
0043  * You can use this as additional base-class for your embedded widgets to get additional interaction
0044  * */
0045 class KDEVPLATFORMLANGUAGE_EXPORT QuickOpenEmbeddedWidgetInterface
0046 {
0047 public:
0048     virtual ~QuickOpenEmbeddedWidgetInterface();
0049     ///Is called when the keyboard-shortcut "next" is triggered on the widget, which currently is ALT+Right
0050     virtual bool next() = 0;
0051     ///Is called when the keyboard-shortcut "previous" is triggered on the widget, which currently is ALT+Left
0052     virtual bool previous() = 0;
0053     ///Is called when the keyboard-shortcut "scroll up" is triggered on the widget, which currently is ALT+Up
0054     virtual bool up() = 0;
0055     ///Is called when the keyboard-shortcut "scroll down" is triggered on the widget, which currently is ALT+Down
0056     virtual bool down() = 0;
0057     ///Is called when the keyboard-shortcut "back" is triggered on the widget, which currently is ALT+Backspace
0058     virtual void back() = 0;
0059     ///Is called when the keyboard-shortcut "accept" is triggered on the widget, which currently is ALT+Return
0060     virtual void accept() = 0;
0061     ///Reset the navigation state to the state before keyboard interaction
0062     virtual void resetNavigationState() = 0;
0063 };
0064 
0065 /**
0066  * Reimplement this to represent single entries within the quickopen list.
0067  * */
0068 class KDEVPLATFORMLANGUAGE_EXPORT QuickOpenDataBase
0069     : public QSharedData
0070 {
0071 public:
0072     virtual ~QuickOpenDataBase();
0073 
0074     ///Return the text to be shown in the list for this item
0075     virtual QString text() const = 0;
0076 
0077     virtual QString htmlDescription() const = 0;
0078 
0079     /**Can return Custom highlighting triplets as explained in
0080      * the kde header ktexteditor/codecompletionmodel.h
0081      * The default-implementation returns an empty list, which means no
0082      * special highlighting will be applied.
0083      * */
0084     virtual QList<QVariant> highlighting() const;
0085 
0086     /**
0087      * May return an icon to mark the item in the quickopen-list.
0088      * The standard-implementation returns an invalid item, which means that
0089      * no icon will be shown.
0090      * */
0091     virtual QIcon icon() const;
0092 
0093     /**
0094      * Is called when the item should be executed.
0095      *
0096      * @param filterText Current content of the quickopen-dialogs filter line-edit.
0097      *                   If this is changed, and false is returned, the content of the
0098      *                   line-edit will be changed according to the new text.
0099      * @return Whether the dialog should be closed.
0100      * */
0101     virtual bool execute(QString& filterText) = 0;
0102 
0103     /**
0104      * Return true here if this data-item should be expandable with
0105      * an own embedded widget.
0106      * The default-implementation returns false.
0107      * */
0108     virtual bool isExpandable() const;
0109 
0110     /**
0111      * This will be called if isExpandable() returns true.
0112      *
0113      * A widget should be returned that will be embedded into the quickopen-list.
0114      * The widget will be owned by the quickopen-list and will be deleted at will.
0115      *
0116      * If the widget can be dynamic_cast'ed to QuickOpenEmbeddedWidgetInterface,
0117      * the additional interaction defined there will be possible.
0118      *
0119      * The default-implementation returns 0, which means no widget will be shown.
0120      * */
0121     virtual QWidget* expandingWidget() const;
0122 };
0123 
0124 using QuickOpenDataPointer = QExplicitlySharedDataPointer<QuickOpenDataBase>;
0125 
0126 /**
0127  * Use this interface to provide custom quickopen-data to the quickopen-widget.
0128  *
0129  * If possible, you should use KDevelop::Filter (@file quickopenfilter.h )
0130  * to implement the actual filtering, so it is consistent.
0131  * */
0132 
0133 class KDEVPLATFORMLANGUAGE_EXPORT QuickOpenDataProviderBase
0134     : public QObject
0135 {
0136     Q_OBJECT
0137 
0138 public:
0139     ~QuickOpenDataProviderBase() override;
0140 
0141     /**
0142      * For efficiency, all changes to the filter-text are provided by the following 3 difference-operations.
0143      * */
0144 
0145     /**
0146      * Search-text was changed.
0147      * This is called whenever the search-text was changed, and the UI should be updated.
0148      * Store the text to track the exact difference.
0149      * */
0150     virtual void setFilterText(const QString& text) = 0;
0151 
0152     /**
0153      * Filter-text should be completely reset and the context re-computed.
0154      * */
0155     virtual void reset() = 0;
0156 
0157     /**
0158      * Returns the count of items this provider currently represents
0159      * */
0160     virtual uint itemCount() const = 0;
0161 
0162     /**
0163      * Returns the count of *unfiltered* items this provider currently represents
0164      */
0165     virtual uint unfilteredItemCount() const = 0;
0166 
0167     /**
0168      * Returns the data-item for a given row.
0169      *
0170      * Generally, the items must addressed alphabetically,
0171      * they will be displayed in the same order in the
0172      * quickopen list.
0173      *
0174      * For performance-reasons the underlying models should
0175      * create the QuickOpenDataBase items on demand, because only
0176      * those that will really be shown will be requested.
0177      *
0178      * @param row Index of item to be returned.
0179      * */
0180     virtual QuickOpenDataPointer data(uint row) const  = 0;
0181 
0182     /**
0183      * If the data-provider supports multiple different scopes/items, this will be called
0184      * with the enabled scopes/items.
0185      * If the data-provider supports only one scope/item, this can be ignored.
0186      * The lists contains all scopes/items, even those that are not supported by this provider.
0187      * */
0188     virtual void enableData(const QStringList& items, const QStringList& scopes);
0189 };
0190 
0191 /**
0192  * Try parsing string according to "path_to_file":"line number" template. "line number" may be empty.
0193  * @param from Source string
0194  * @param path Set to parsed path to file, or left unchanged if @p from doesn't match the template. May refer to the same object as @p from
0195  * @param lineNumber Set to parsed line number, zero if "line number" is empty or left unchanged if @p from doesn't match the template.
0196  * @return Whether @p from did match the expected template.
0197  * */
0198 bool KDEVPLATFORMLANGUAGE_EXPORT extractLineNumber(const QString& from, QString& path, uint& lineNumber);
0199 }
0200 
0201 Q_DECLARE_INTERFACE(KDevelop::QuickOpenFileSetInterface, "org.kdevelop.QuickOpenFileSetInterface")
0202 Q_DECLARE_INTERFACE(KDevelop::QuickOpenEmbeddedWidgetInterface, "org.kdevelop.QuickOpenEmbeddedWidgetInterface")
0203 
0204 #endif