~ubuntu-branches/ubuntu/oneiric/gedit-plugins/oneiric-201109060911

« back to all changes in this revision

Viewing changes to plugins/commander/modules/find/__init__.py

  • Committer: Andrew Starr-Bochicchio
  • Date: 2010-01-25 22:15:21 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: a.starr.b@gmail.com-20100125221521-wfijztxrdmuok3d3
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import commander.commands as commands
 
2
import gedit
 
3
import re
 
4
import regex
 
5
from xml.sax import saxutils
 
6
import finder
 
7
 
 
8
__commander_module__ = True
 
9
__root__ = ['/', 'find_i', '//', 'r/', 'r//']
 
10
 
 
11
class TextFinder(finder.Finder):
 
12
        def __init__(self, entry, flags):
 
13
                finder.Finder.__init__(self, entry)
 
14
                
 
15
                self.flags = flags
 
16
 
 
17
        def do_find(self, bounds):
 
18
                buf = self.view.get_buffer()
 
19
                
 
20
                if self.findstr:
 
21
                        buf.set_search_text(self.findstr, self.flags)
 
22
                
 
23
                ret = map(lambda x: x.copy(), bounds)
 
24
                
 
25
                if buf.search_forward(bounds[0], bounds[1], ret[0], ret[1]):
 
26
                        return ret
 
27
                else:
 
28
                        return False
 
29
 
 
30
def __default__(entry, argstr):
 
31
        """Find in document: find <text>
 
32
 
 
33
Quickly find phrases in the document"""
 
34
        fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
 
35
        yield fd.find(argstr)
 
36
 
 
37
def _find_insensitive(entry, argstr):
 
38
        """Find in document (case insensitive): find-i <text>
 
39
 
 
40
Quickly find phrases in the document (case insensitive)"""
 
41
        fd = TextFinder(entry, 0)
 
42
        yield fd.find(argstr)
 
43
 
 
44
def replace(entry, findstr, replstr=None):
 
45
        """Find/replace in document: find.replace <find> [<replace>]
 
46
 
 
47
Quickly find and replace phrases in the document"""
 
48
        fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
 
49
        yield fd.replace(findstr, False, replstr)
 
50
 
 
51
def replace_i(entry, findstr, replstr=None):
 
52
        """Find/replace all in document (case insensitive): find.replace-i <find> [<replace>]
 
53
 
 
54
Quickly find and replace phrases in the document (case insensitive)"""
 
55
        fd = TextFinder(entry, 0)
 
56
        yield fd.replace(findstr, True, replstr)
 
57
 
 
58
def replace_all(entry, findstr, replstr=None):
 
59
        """Find/replace all in document: find.replace-all <find> [<replace>]
 
60
 
 
61
Quickly find and replace all phrases in the document"""
 
62
        fd = TextFinder(entry, gedit.SEARCH_CASE_SENSITIVE)
 
63
        yield fd.replace(findstr, True, replstr)
 
64
 
 
65
def replace_all_i(entry, findstr, replstr=None):
 
66
        """Find/replace all in document (case insensitive): find.replace-all-i <find> [<replace>]
 
67
 
 
68
Quickly find and replace all phrases in the document (case insensitive)"""
 
69
        fd = TextFinder(entry,0)
 
70
        yield fd.replace(findstr, True, replstr)
 
71
 
 
72
locals()['/'] = __default__
 
73
locals()['find_i'] = _find_insensitive
 
74
locals()['//'] = replace
 
75
locals()['r/'] = regex.__default__
 
76
locals()['r//'] = regex.replace