1 /******************************************************************************
2   Copyright (C) 2006-2008 by Michel Ludwig (michel.ludwig@kdemail.net)
3                 2011-2012 by Holger Danielsson (holger.danielsson@versanet.de)
4  ******************************************************************************/
5 
6 /**************************************************************************
7 *                                                                         *
8 *   This program is free software; you can redistribute it and/or modify  *
9 *   it under the terms of the GNU General Public License as published by  *
10 *   the Free Software Foundation; either version 2 of the License, or     *
11 *   (at your option) any later version.                                   *
12 *                                                                         *
13 ***************************************************************************/
14 
15 #ifndef KILE_SCRIPT_VIEW_H
16 #define KILE_SCRIPT_VIEW_H
17 
18 #include <QObject>
19 #include <QMap>
20 #include <QScriptable>
21 
22 #include <KTextEditor/Cursor>
23 #include <KTextEditor/Range>
24 #include <KTextEditor/View>
25 #include <KActionCollection>
26 
27 #include "editorextension.h"
28 
29 namespace KileScript {
30 
31 class KileScriptView : public QObject, protected QScriptable
32 {
33     Q_OBJECT
34 
35 public:
36     KileScriptView (QObject *parent, KileDocument::EditorExtension *editor);
~KileScriptView()37     virtual ~KileScriptView() {}
38 
39     void setView(KTextEditor::View *view);
40     KTextEditor::View *view() const;
41 
42     // cursor
43     Q_INVOKABLE KTextEditor::Cursor cursorPosition ();
44     Q_INVOKABLE void setCursorPosition(int line, int column);
45     Q_INVOKABLE void setCursorPosition(const KTextEditor::Cursor& cursor);
46 
47     Q_INVOKABLE void backspace();
48 
49     Q_INVOKABLE void cursorLeft();
50     Q_INVOKABLE void cursorRight();
51     Q_INVOKABLE void cursorUp();
52     Q_INVOKABLE void cursorDown();
53 
54     Q_INVOKABLE int cursorLine();
55     Q_INVOKABLE int cursorColumn();
56     Q_INVOKABLE void setCursorLine(int l);
57     Q_INVOKABLE void setCursorColumn(int c);
58 
59     Q_INVOKABLE KTextEditor::Cursor virtualCursorPosition();
60 
61     // selection
62     Q_INVOKABLE bool hasSelection();
63     Q_INVOKABLE QString selectedText();
64     Q_INVOKABLE KTextEditor::Range selectionRange();
65     Q_INVOKABLE void setSelection(const KTextEditor::Range& range);
66     Q_INVOKABLE void selectAll();
67 
68     Q_INVOKABLE void clearSelection();
69     Q_INVOKABLE void removeSelectedText();
70 
71     // line
72     Q_INVOKABLE void selectLine();
73     Q_INVOKABLE void selectLine(int line);
74     Q_INVOKABLE void selectLines(int from, int to);
75 
76     // word
77     Q_INVOKABLE void selectWord();
78 
79     // latex command
80     Q_INVOKABLE void selectLatexCommand();
81 
82     // environment
83     Q_INVOKABLE void selectEnvironment(bool inside = false);
84 
85     // texgroup
86     Q_INVOKABLE void selectTexgroup(bool inside = true);
87 
88     // mathgroup
89     Q_INVOKABLE void selectMathgroup();
90 
91     // paragraph
92     Q_INVOKABLE void selectParagraph(bool wholeLines = true);
93 
94 private:
95     KTextEditor::View *m_view;
96     KileDocument::EditorExtension *m_editor;
97 
98 };
99 
100 }
101 
102 #endif
103