This file is indexed.

/usr/share/gEcrit/FindReplaceText.py is in gecrit 2.8.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#  Copyright (C) 2011  Groza Cristian
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.



#!/usr/bin/python
# -*- coding: utf-8 -*-

import wx


class SearchReplace:
    """
    SearchReplace

    Provied the necessary dialogs and functions for the text search
    feature.

    """


    def OnClose(self,event,widget):
        """
        OnClose

        Destroys the suplied widet.
        """
        widget.Destroy()


    def FindDocText(self, event, text_id, other_flags = 0):
        """
        FindDocText

        Creates and initializes the neccesary dialog for text searching.
        Sets up the environment and the variables that indicate the
        position in the text document.
        """
        self._ = wx.FindWindowById(text_id)._

        self.min_text_range = 0
        self.max_text_range = wx.FindWindowById(text_id).GetLength()
        #FindFrame = wx.Frame(None, -1, "Search", size=(200, 200))
        find_data = wx.FindReplaceData()
        find_dlg = wx.FindReplaceDialog(None, find_data, self._("Find"))
        find_dlg.find_data = find_data  # save a reference to it...
        find_dlg.Bind(wx.EVT_FIND_NEXT, lambda event: self.SearchWord(event,
                        text_id, find_data, other_flags))
        find_dlg.Bind(wx.EVT_FIND, lambda event: self.SearchWord(event,
                        text_id, find_data, other_flags))
        find_dlg.Show(True)
        find_dlg.Bind(wx.EVT_CLOSE,lambda event: self.OnClose(event,find_dlg))
        find_dlg.Bind(wx.EVT_FIND_CLOSE, lambda event: self.OnClose(event,find_dlg))

    def SearchWord(self, event, text_id, item, other_flags):
        """
        SearchWord

        Searches the suplied string in the current document.
        Manages highlighting and scrolling to that position.
        Returns the text position if found and -1 if not found.
        When reaches end, resets the current postion in the document to 0.
        """
        cur_doc = wx.FindWindowById(text_id)
        search_flags = item.GetFlags()
        word = item.GetFindString()
        max_pos = cur_doc.GetLength()
        if search_flags in [0, 2, 4, 6]:
            text_pos = cur_doc.FindText(self.max_text_range, self.min_text_range,
                    word, search_flags | other_flags)
            if text_pos != -1:
                start_pos = text_pos
                end_pos = start_pos + len(word)
                self.max_text_range = text_pos - len(word)
                cur_doc.GotoPos(self.max_text_range)
                cur_doc.SetSelection(end_pos, start_pos)
            elif text_pos == -1:
                cur_doc.GotoPos(1)
                self.min_text_range = 0
        else:

            text_pos = cur_doc.FindText(self.min_text_range, max_pos,
                    word, search_flags|other_flags)
            start_pos = text_pos
            end_pos = text_pos + len(word)

            if text_pos != -1:
                cur_doc.GotoPos(text_pos)
                self.min_text_range = end_pos
                cur_doc.SetSelection(start_pos, end_pos)
            elif text_pos == -1:
                cur_doc.GotoPos(1)
                self.min_text_range = 0

    def ReplaceDocText(self, event, text_id, other_flags = 0):
        """
        ReplaceDocText

        Creates and initializes the neccesary dialog for text searching
        and replaceing. Sets up the environment and the variables that indicate the
        position in the text document.
        """

        self._ = wx.FindWindowById(text_id)._

        self.max_text_range = wx.FindWindowById(text_id).GetLength()
        self.min_text_range = 1
        find_repl_frame = wx.Frame(None, -1, self._("Search and Replace"), size=(300,
                             300))
        find_repl_data = wx.FindReplaceData()
        replace_dlg = wx.Findreplace_dlg(find_repl_frame, find_repl_data,
               self._("Search and Replace"), style=wx.FR_REPLACEDIALOG)
        replace_dlg.find_repl_data = find_repl_data
        replace_dlg.Bind(wx.EVT_FIND_NEXT, lambda event: self.SearchWord(event,
                           text_id, find_repl_data, other_flags))
        replace_dlg.Bind(wx.EVT_FIND, lambda event: self.SearchWord(event,
                           text_id, find_repl_data, other_flags))

        replace_dlg.Bind(wx.EVT_FIND_REPLACE, lambda event: self.ReplaceWord(event,
                           text_id, find_repl_data, other_flags))
        replace_dlg.Bind(wx.EVT_FIND_REPLACE_ALL, lambda event: self.ReplaceAllWords(event,
                           text_id, find_repl_data, other_flags))
        replace_dlg.Show(True)
        replace_dlg.Bind(wx.EVT_CLOSE,lambda event: self.OnClose(event,replace_dlg))
        replace_dlg.Bind(wx.EVT_FIND_CLOSE, lambda event: self.OnClose(event,replace_dlg))

    def ReplaceWord(self, event, text_id, item, other_flags):
        """
        ReplaceWord

        Searches the suplied string in the current document and replaces
        it with the suplied replacement.
        Manages scrolling to that position.
        Returns the text position if found and -1 if not found.
        When reaches end, resets the current postion in the document to 0.
        """

        cur_doc = wx.FindWindowById(text_id)
        max_pos = cur_doc.GetLength()
        op_flags = item.GetFlags()

        search_word = item.GetFindString()
        replace_word = item.GetReplaceString()
        if op_flags in [0, 2, 4, 6]:
            to_pos = cur_doc.FindText(self.max_text_range, self.min_text_range,
                    search_word, op_flags|other_flags)
            from_pos = to_pos + len(search_word)
            cur_doc.SetTargetStart(to_pos)
            cur_doc.SetTargetEnd(from_pos)

            if from_pos != -1:
                cur_doc.ReplaceTarget(replace_word)
                self.max_text_range = to_pos
                cur_doc.GotoPos(to_pos)
                cur_doc.SetSelection(to_pos, from_pos)
                return to_pos
            elif from_pos == -1:

                self.max_text_range = cur_doc.GetLength()
                return -1
        else:

            from_pos = cur_doc.FindText(self.min_text_range, max_pos,
                    search_word, op_flags|other_flags)
            to_pos = from_pos + len(search_word)
            cur_doc.SetTargetStart(from_pos)
            cur_doc.SetTargetEnd(to_pos)
            if from_pos != -1:
                cur_doc.ReplaceTarget(replace_word)
                self.min_text_range = to_pos
                cur_doc.GotoPos(from_pos)
                cur_doc.SetSelection(to_pos, from_pos)
                return from_pos
            elif from_pos == -1:
                self.min_text_range = 0
                return -1

    def ReplaceAllWords(self, event, text_id, item, other_flags):
        """
        ReplaceAllWords

        Replaces all the occurences of the suplied string with the
        suplie replacement. Promps user when end of file was reached.
        """
        while self.ReplaceWord(0, text_id, item) != -1:
            self.ReplaceWord(0, text_id, item)
        EndReached = wx.MessageDialog(None,
            self._("The end of file was reached!\nNothing to replace."), "",
                style=wx.OK)
        EndReached.ShowModal()


FindRepl = SearchReplace()