aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/codesnippeteditor.h
blob: 224796074e9b2a56e3d0e33ec53e1f5420026312 (plain) (blame)
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
#ifndef CODESNIPPETEDITOR_H
#define CODESNIPPETEDITOR_H

#include "mdichild.h"
#include <QWidget>

namespace Ui {
class CodeSnippetEditor;
}

class CodeSnippetEditorModel;
class QSortFilterProxyModel;
class QSyntaxHighlighter;
class QItemSelection;

CFG_KEY_LIST(CodeSnippetEditor, QObject::tr("A code snippets editor window"),
    CFG_KEY_ENTRY(COMMIT,     QKeySequence::Save,        QObject::tr("Commit the pending changes"))
    CFG_KEY_ENTRY(ROLLBACK,   QKeySequence::Cancel,      QObject::tr("Rollback the pending changes"))
)

class CodeSnippetEditor : public MdiChild
{
    Q_OBJECT

    public:
        enum Action
        {
            COMMIT,
            ROLLBACK,
            ADD,
            DELETE,
            MOVE_UP,
            MOVE_DOWN,
            HELP
        };
        Q_ENUM(Action)

        enum ToolBar
        {
            TOOLBAR
        };

        explicit CodeSnippetEditor(QWidget *parent = nullptr);
        ~CodeSnippetEditor();

        bool restoreSessionNextTime();
        bool isUncommitted() const;
        QString getQuitUncommittedConfirmMessage() const;

    protected:
        QVariant saveSession();
        bool restoreSession(const QVariant &sessionValue);
        Icon* getIconNameForMdiWindow();
        QString getTitleForMdiWindow();
        void createActions();
        void setupDefShortcuts();
        QToolBar* getToolBar(int toolbar) const;

    private:
        void init();
        int getCurrentSnippetRow() const;
        void snippetDeselected(int row);
        void snippetSelected(int row);
        void selectSnippet(int row, bool forRowMovement = false);
        void clearEdits();

        Ui::CodeSnippetEditor *ui;
        CodeSnippetEditorModel* model = nullptr;
        QSortFilterProxyModel* snippetFilterModel = nullptr;
        bool currentModified = false;
        bool updatesForSelection = false;
        bool skipModelUpdatesDuringSelection = false;

    private slots:
        void commit();
        void rollback();
        void newSnippet();
        void deleteSnippet();
        void moveSnippetUp();
        void moveSnippetDown();
        void updateModified();
        void updateCurrentSnippetState();
        void updateState();
        void snippetSelected(const QItemSelection& selected, const QItemSelection& deselected);
        void applyFilter(const QString& value);
        void changeFont(const QVariant& font);
        void clearAssistantShortcutPressed();
        void help();
};

#endif // CODESNIPPETEDITOR_H