KTextEditor

katesedcmd.h
1 /*
2  SPDX-FileCopyrightText: 2003-2005 Anders Lund <[email protected]>
3  SPDX-FileCopyrightText: 2001-2010 Christoph Cullmann <[email protected]>
4  SPDX-FileCopyrightText: 2001 Charles Samuels <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef KATE_SED_CMD_H
10 #define KATE_SED_CMD_H
11 
12 #include "kateregexpsearch.h"
13 #include <KTextEditor/Command>
14 
15 #include <QSharedPointer>
16 #include <QStringList>
17 
18 namespace KTextEditor
19 {
20 class DocumentPrivate;
21 class ViewPrivate;
22 }
23 
28 namespace KateCommands
29 {
35 {
36  static SedReplace *m_instance;
37 
38 protected:
39  SedReplace()
40  : KTextEditor::Command({QStringLiteral("s"), QStringLiteral("%s"), QStringLiteral("$s")})
41  {
42  }
43 
44 public:
45  ~SedReplace() override
46  {
47  m_instance = nullptr;
48  }
49 
65  bool exec(class KTextEditor::View *view, const QString &cmd, QString &errorMsg, const KTextEditor::Range &r) override;
66 
67  bool supportsRange(const QString &) override
68  {
69  return true;
70  }
71 
73  bool help(class KTextEditor::View *, const QString &, QString &) override
74  {
75  return false;
76  }
77 
78  static SedReplace *self()
79  {
80  if (m_instance == nullptr) {
81  m_instance = new SedReplace();
82  }
83  return m_instance;
84  }
85 
93  static bool parse(const QString &sedReplaceString, QString &destDelim, int &destFindBeginPos, int &destFindEndPos, int &destReplaceBeginPos, int &destReplaceEndPos);
94 
95  class InteractiveSedReplacer
96  {
97  public:
98  InteractiveSedReplacer(KTextEditor::DocumentPrivate *doc, const QString &findPattern, const QString &replacePattern, bool caseSensitive, bool onlyOnePerLine, int startLine, int endLine);
102  KTextEditor::Range currentMatch();
103  void skipCurrentMatch();
104  void replaceCurrentMatch();
105  void replaceAllRemaining();
106  QString currentMatchReplacementConfirmationMessage();
107  QString finalStatusReportMessage();
108 
109  private:
110  const QString m_findPattern;
111  const QString m_replacePattern;
112  bool m_onlyOnePerLine;
113  int m_endLine;
114  KTextEditor::DocumentPrivate *m_doc;
115  KateRegExpSearch m_regExpSearch;
116  Qt::CaseSensitivity m_caseSensitive;
117 
118  int m_numReplacementsDone;
119  int m_numLinesTouched;
120  int m_lastChangedLineNum;
121 
122  KTextEditor::Cursor m_currentSearchPos;
123  const QVector<KTextEditor::Range> fullCurrentMatch();
124  QString replacementTextForCurrentMatch();
125  };
126 
127 protected:
128  virtual bool interactiveSedReplace(KTextEditor::ViewPrivate *kateView, QSharedPointer<InteractiveSedReplacer> interactiveSedReplace);
129 };
130 
131 } // namespace KateCommands
132 #endif
bool help(class KTextEditor::View *, const QString &, QString &) override
This command does not have help.
Definition: katesedcmd.h:73
Support vim/sed style search and replace.
Definition: katesedcmd.h:34
Object to help to search for regexp.
The Cursor represents a position in a Document.
Definition: cursor.h:71
bool supportsRange(const QString &) override
Find out if a given command can act on a range.
Definition: katesedcmd.h:67
CaseSensitivity
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
An object representing a section of text, from one Cursor to another.
An Editor command line command.
The KateCommands namespace collects subclasses of KTextEditor::Command for specific use in kate...
A text widget with KXMLGUIClient that represents a Document.
Definition: view.h:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:57:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.