3
* Copyright (C) 2011-2013 by Kåre Särs <kare.sars@iki.fi>
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.
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.
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,
21
#ifndef _PLUGIN_SEARCH_H_
22
#define _PLUGIN_SEARCH_H_
24
#include <ktexteditor/mainwindow.h>
25
#include <KTextEditor/Plugin>
26
#include <ktexteditor/application.h>
27
#include <KTextEditor/Command>
28
#include <ktexteditor/sessionconfiginterface.h>
31
#include <QTreeWidget>
34
#include <KXMLGUIClient>
36
#include "ui_search.h"
37
#include "ui_results.h"
39
#include "search_open_files.h"
40
#include "SearchDiskFiles.h"
41
#include "FolderFilesList.h"
42
#include "replace_matches.h"
44
class KateSearchCommand;
45
namespace KTextEditor{
49
class Results: public QWidget, public Ui::Results
53
Results(QWidget *parent = 0);
59
// This class keeps the focus inside the S&R plugin when pressing tab/shift+tab by overriding focusNextPrevChild()
60
class ContainerWidget:public QWidget
64
ContainerWidget(QWidget *parent): QWidget(parent) {}
67
void nextFocus(QWidget *currentWidget, bool *found, bool next);
70
virtual bool focusNextPrevChild (bool next);
74
class KatePluginSearch : public KTextEditor::Plugin
79
explicit KatePluginSearch(QObject* parent = 0, const QList<QVariant>& = QList<QVariant>());
80
virtual ~KatePluginSearch();
82
QObject *createView(KTextEditor::MainWindow *mainWindow);
85
KateSearchCommand* m_searchCommand;
90
class KatePluginSearchView : public QObject, public KXMLGUIClient, public KTextEditor::SessionConfigInterface
93
Q_INTERFACES(KTextEditor::SessionConfigInterface)
96
KatePluginSearchView(KTextEditor::Plugin *plugin, KTextEditor::MainWindow *mainWindow, KTextEditor::Application* application);
97
~KatePluginSearchView();
99
void readSessionConfig (const KConfigGroup& config);
100
void writeSessionConfig (KConfigGroup& config);
104
void setSearchString(const QString &pattern);
105
void navigateFolderUp();
106
void setCurrentFolder();
107
void setSearchPlace(int place);
108
void goToNextMatch();
109
void goToPreviousMatch();
112
void openSearchView();
113
void handleEsc(QEvent *e);
114
void nextFocus(QWidget *currentWidget, bool *found, bool next);
117
void tabCloseRequested(int index);
118
void toggleOptions(bool show);
120
void searchContextMenu(const QPoint& pos);
122
void searchPlaceChanged();
123
void startSearchWhileTyping();
125
void folderFileListChanged();
127
void matchFound(const QString &url, const QString &fileName, int line, int column,
128
const QString &lineContent, int matchLen);
130
void addMatchMark(KTextEditor::Document* doc, int line, int column, int len);
133
void searchWhileTypingDone();
134
void indicateMatch(bool hasMatch);
136
void searching(const QString &file);
138
void itemSelected(QTreeWidgetItem *item);
141
void clearDocMarks(KTextEditor::Document* doc);
143
void replaceSingleMatch();
144
void replaceChecked();
148
void docViewChanged();
151
void resultTabChanged(int index);
154
* keep track if the project plugin is alive and if the project file did change
156
void slotPluginViewCreated (const QString &name, QObject *pluginView);
157
void slotPluginViewDeleted (const QString &name, QObject *pluginView);
158
void slotProjectFileNameChanged ();
161
bool eventFilter(QObject *obj, QEvent *ev);
162
void addHeaderItem();
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;
169
Ui::SearchDialog m_ui;
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;
188
* current project plugin view, if any
190
QObject *m_projectPluginView;
195
KTextEditor::MainWindow *m_mainWindow;
198
class KateSearchCommand : public KTextEditor::Command
202
KateSearchCommand(QObject *parent);
205
void setSearchPlace(int place);
206
void setCurrentFolder();
207
void setSearchString(const QString &pattern);
212
// KTextEditor::Command
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);
222
// kate: space-indent on; indent-width 4; replace-tabs on;