File: abstractnavigationcontext.h

package info (click to toggle)
kdevelop 4%3A22.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 70,096 kB
  • sloc: cpp: 284,635; javascript: 3,558; python: 3,422; sh: 1,319; ansic: 685; xml: 331; php: 95; lisp: 66; makefile: 39; sed: 12
file content (165 lines) | stat: -rw-r--r-- 5,511 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
    SPDX-FileCopyrightText: 2007 David Nolden <david.nolden.kdevelop@art-master.de>

    SPDX-License-Identifier: LGPL-2.0-only
*/

#ifndef KDEVPLATFORM_ABSTRACTNAVIGATIONCONTEXT_H
#define KDEVPLATFORM_ABSTRACTNAVIGATIONCONTEXT_H

#include <QExplicitlySharedDataPointer>

#include <language/languageexport.h>
#include "../indexeddeclaration.h"
#include "navigationaction.h"

namespace KDevelop {
class AbstractNavigationContextPrivate;

/** A helper-class for elegant colorization of html-strings .
 *
 * Initialize it with a html-color like "990000". and colorize strings
 * using operator()
 */
struct KDEVPLATFORMLANGUAGE_EXPORT Colorizer
{
    enum FormattingFlag {
        Nothing = 0x0,
        Bold = 0x1,
        Italic = 0x2,
        Fixed = 0x4
    };
    Q_DECLARE_FLAGS(Formatting, FormattingFlag)
    explicit Colorizer(const QString& color, Formatting formatting = Nothing)
        : m_color(color)
        , m_formatting(formatting)
    {
    }

    QString operator()(const QString& str) const;

    QString m_color;
    Formatting m_formatting;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(Colorizer::Formatting)

class AbstractNavigationContext;
using NavigationContextPointer = QExplicitlySharedDataPointer<AbstractNavigationContext>;

class KDEVPLATFORMLANGUAGE_EXPORT AbstractNavigationContext
    : public QObject
    , public QSharedData
{
    Q_OBJECT

public:
    explicit AbstractNavigationContext(const TopDUContextPointer& topContext = TopDUContextPointer(),
                                       AbstractNavigationContext* previousContext = nullptr);
    ~AbstractNavigationContext() override;

    int linkCount() const;
    bool nextLink();
    bool previousLink();
    bool up();
    bool down();
    void resetNavigation();

    NavigationContextPointer accept();
    NavigationContextPointer back();
    NavigationContextPointer accept(IndexedDeclaration decl);
    NavigationContextPointer acceptLink(const QString& link);
    NavigationAction currentAction() const;

    virtual QString name() const = 0;
    ///Here the context can return html to be displayed.
    ///NOTE: The DUChain must be locked while this is called.
    virtual QString html(bool shorten = false);
    ///Here the context can return a widget to be displayed.
    ///The widget stays owned by this navigation-context.
    ///The widget may have a signal "navigateDeclaration(KDevelop::IndexedDeclaration)".
    ///If that signal is emitted, the new declaration is navigated in the navigation-wdiget.
    virtual QWidget* widget() const;

    ///Whether the widget returned by widget() should take the maximum possible spsace.
    ///The default implementation returns true.
    virtual bool isWidgetMaximized() const;

    ///Returns whether this context's string has already been computed, and is up to date.
    ///After clear() was called, this returns false again.
    bool alreadyComputed() const;

    TopDUContextPointer topContext() const;
    void setTopContext(const TopDUContextPointer& context);

    void executeLink(const QString& link);
    NavigationContextPointer execute(const NavigationAction& action);

Q_SIGNALS:
    void contentsChanged();

protected:
    AbstractNavigationContext* previousContext() const;
    virtual void setPreviousContext(AbstractNavigationContext* previousContext);

    struct TextHandler
    {
        explicit TextHandler(AbstractNavigationContext* c) : context(c)
        {
        }
        void operator+=(const QString& str) const
        {
            context->addHtml(str);
        }
        AbstractNavigationContext* context;
    };

    ///Override this to execute own key-actions using NavigationAction
    virtual NavigationContextPointer executeKeyAction(const QString& key);

    ///Adds given the text to currentHtml()
    void addHtml(const QString& html);
    ///Returns the html text being built in its current state
    QString currentHtml() const;
    ///Returns a convenience object that allows writing "modifyHtml() += "Hallo";"
    TextHandler modifyHtml()
    {
        return TextHandler(this);
    }

    //Clears the computed html and links
    void clear();

    ///Creates and registers a link to the given declaration, labeled by the given name
    virtual void makeLink(const QString& name, const DeclarationPointer& declaration,
                          NavigationAction::Type actionType);

    ///Creates a link that executes the given action and adds it to the current context
    void makeLink(const QString& name, const QString& targetId, const NavigationAction& action);

    ///Creates a link that executes the given action and returns it
    QString createLink(const QString& name, const QString& targetId, const NavigationAction& action);

    NavigationContextPointer registerChild(const DeclarationPointer& /*declaration*/);
    NavigationContextPointer registerChild(AbstractNavigationContext* context);

    virtual QString declarationKind(const DeclarationPointer& decl);

    static const Colorizer typeHighlight;
    static const Colorizer errorHighlight;
    static const Colorizer labelHighlight;
    static const Colorizer codeHighlight;
    static const Colorizer propertyHighlight;
    static const Colorizer navigationHighlight;
    static const Colorizer importantHighlight;
    static const Colorizer commentHighlight;
    static const Colorizer nameHighlight;

private:
    const QScopedPointer<class AbstractNavigationContextPrivate> d_ptr;
    Q_DECLARE_PRIVATE(AbstractNavigationContext)
};

}

#endif