~ubuntu-branches/ubuntu/vivid/kate/vivid-proposed

« back to all changes in this revision

Viewing changes to addons/search/plugin_search.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*   Kate search plugin
 
2
 *
 
3
 * Copyright (C) 2011-2013 by Kåre Särs <kare.sars@iki.fi>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program in a file called COPYING; if not, write to
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
 * MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#ifndef _PLUGIN_SEARCH_H_
 
22
#define _PLUGIN_SEARCH_H_
 
23
 
 
24
#include <ktexteditor/mainwindow.h>
 
25
#include <KTextEditor/Plugin>
 
26
#include <ktexteditor/application.h>
 
27
#include <KTextEditor/Command>
 
28
#include <ktexteditor/sessionconfiginterface.h>
 
29
#include <QAction>
 
30
 
 
31
#include <QTreeWidget>
 
32
#include <QTimer>
 
33
 
 
34
#include <KXMLGUIClient>
 
35
 
 
36
#include "ui_search.h"
 
37
#include "ui_results.h"
 
38
 
 
39
#include "search_open_files.h"
 
40
#include "SearchDiskFiles.h"
 
41
#include "FolderFilesList.h"
 
42
#include "replace_matches.h"
 
43
 
 
44
class KateSearchCommand;
 
45
namespace KTextEditor{
 
46
    class MovingRange;
 
47
}
 
48
 
 
49
class Results: public QWidget, public Ui::Results
 
50
{
 
51
    Q_OBJECT
 
52
public:
 
53
    Results(QWidget *parent = 0);
 
54
    int     matches;
 
55
    QRegExp regExp;
 
56
    QString replace;
 
57
};
 
58
 
 
59
// This class keeps the focus inside the S&R plugin when pressing tab/shift+tab by overriding focusNextPrevChild()
 
60
class ContainerWidget:public QWidget
 
61
{
 
62
    Q_OBJECT
 
63
public:
 
64
    ContainerWidget(QWidget *parent): QWidget(parent) {}
 
65
 
 
66
Q_SIGNALS:
 
67
    void nextFocus(QWidget *currentWidget, bool *found, bool next);
 
68
 
 
69
protected:
 
70
    virtual bool focusNextPrevChild (bool next);
 
71
};
 
72
 
 
73
 
 
74
class KatePluginSearch : public KTextEditor::Plugin
 
75
{
 
76
    Q_OBJECT
 
77
 
 
78
public:
 
79
    explicit KatePluginSearch(QObject* parent = 0, const QList<QVariant>& = QList<QVariant>());
 
80
    virtual ~KatePluginSearch();
 
81
 
 
82
    QObject *createView(KTextEditor::MainWindow *mainWindow);
 
83
 
 
84
private:
 
85
    KateSearchCommand* m_searchCommand;
 
86
};
 
87
 
 
88
 
 
89
 
 
90
class KatePluginSearchView : public QObject, public KXMLGUIClient, public KTextEditor::SessionConfigInterface
 
91
{
 
92
    Q_OBJECT
 
93
    Q_INTERFACES(KTextEditor::SessionConfigInterface)
 
94
 
 
95
public:
 
96
    KatePluginSearchView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWindow, KTextEditor::Application* application);
 
97
    ~KatePluginSearchView();
 
98
 
 
99
    void readSessionConfig (const KConfigGroup& config);
 
100
    void writeSessionConfig (KConfigGroup& config);
 
101
 
 
102
public Q_SLOTS:
 
103
    void startSearch();
 
104
    void setSearchString(const QString &pattern);
 
105
    void navigateFolderUp();
 
106
    void setCurrentFolder();
 
107
    void setSearchPlace(int place);
 
108
    void goToNextMatch();
 
109
    void goToPreviousMatch();
 
110
 
 
111
private Q_SLOTS:
 
112
    void openSearchView();
 
113
    void handleEsc(QEvent *e);
 
114
    void nextFocus(QWidget *currentWidget, bool *found, bool next);
 
115
 
 
116
    void addTab();
 
117
    void tabCloseRequested(int index);
 
118
    void toggleOptions(bool show);
 
119
 
 
120
    void searchContextMenu(const QPoint& pos);
 
121
 
 
122
    void searchPlaceChanged();
 
123
    void startSearchWhileTyping();
 
124
 
 
125
    void folderFileListChanged();
 
126
 
 
127
    void matchFound(const QString &url, const QString &fileName, int line, int column,
 
128
                    const QString &lineContent, int matchLen);
 
129
 
 
130
    void addMatchMark(KTextEditor::Document* doc, int line, int column, int len);
 
131
 
 
132
    void searchDone();
 
133
    void searchWhileTypingDone();
 
134
    void indicateMatch(bool hasMatch);
 
135
 
 
136
    void searching(const QString &file);
 
137
 
 
138
    void itemSelected(QTreeWidgetItem *item);
 
139
 
 
140
    void clearMarks();
 
141
    void clearDocMarks(KTextEditor::Document* doc);
 
142
 
 
143
    void replaceSingleMatch();
 
144
    void replaceChecked();
 
145
 
 
146
    void replaceDone();
 
147
 
 
148
    void docViewChanged();
 
149
 
 
150
 
 
151
    void resultTabChanged(int index);
 
152
 
 
153
    /**
 
154
     * keep track if the project plugin is alive and if the project file did change
 
155
     */
 
156
    void slotPluginViewCreated (const QString &name, QObject *pluginView);
 
157
    void slotPluginViewDeleted (const QString &name, QObject *pluginView);
 
158
    void slotProjectFileNameChanged ();
 
159
 
 
160
protected:
 
161
    bool eventFilter(QObject *obj, QEvent *ev);
 
162
    void addHeaderItem();
 
163
 
 
164
private:
 
165
    QTreeWidgetItem *rootFileItem(const QString &url, const QString &fName);
 
166
    QStringList filterFiles(const QStringList& files) const;
 
167
    QString currentWord(const KTextEditor::Document& document, const KTextEditor::Cursor& cursor) const;
 
168
 
 
169
    Ui::SearchDialog                   m_ui;
 
170
    QWidget                           *m_toolView;
 
171
    KTextEditor::Application          *m_kateApp;
 
172
    SearchOpenFiles                    m_searchOpenFiles;
 
173
    FolderFilesList                    m_folderFilesList;
 
174
    SearchDiskFiles                    m_searchDiskFiles;
 
175
    ReplaceMatches                     m_replacer;
 
176
    QAction                           *m_matchCase;
 
177
    QAction                           *m_useRegExp;
 
178
    Results                           *m_curResults;
 
179
    bool                               m_searchJustOpened;
 
180
    bool                               m_switchToProjectModeWhenAvailable;
 
181
    bool                               m_searchDiskFilesDone;
 
182
    bool                               m_searchOpenFilesDone;
 
183
    QString                            m_resultBaseDir;
 
184
    QList<KTextEditor::MovingRange*>   m_matchRanges;
 
185
    QTimer                             m_changeTimer;
 
186
 
 
187
    /**
 
188
     * current project plugin view, if any
 
189
     */
 
190
    QObject *m_projectPluginView;
 
191
    
 
192
    /**
 
193
     * our main window
 
194
     */
 
195
    KTextEditor::MainWindow *m_mainWindow;
 
196
};
 
197
 
 
198
class KateSearchCommand : public KTextEditor::Command
 
199
{
 
200
    Q_OBJECT
 
201
public:
 
202
    KateSearchCommand(QObject *parent);
 
203
 
 
204
Q_SIGNALS:
 
205
    void setSearchPlace(int place);
 
206
    void setCurrentFolder();
 
207
    void setSearchString(const QString &pattern);
 
208
    void startSearch();
 
209
    void newTab();
 
210
 
 
211
    //
 
212
    // KTextEditor::Command
 
213
    //
 
214
public:
 
215
    bool exec (KTextEditor::View *view, const QString &cmd, QString &msg,
 
216
                      const KTextEditor::Range &range = KTextEditor::Range::invalid());
 
217
    bool help (KTextEditor::View *view, const QString &cmd, QString &msg);
 
218
};
 
219
 
 
220
#endif
 
221
 
 
222
// kate: space-indent on; indent-width 4; replace-tabs on;
 
223