2 from PyObjCTools
import NibClassBuilder
, AppHelper
3 from Foundation
import *
9 NibClassBuilder
.extractClasses("MainMenu")
11 class URLHandlerClass(NibClassBuilder
.AutoBaseClass
):
12 def performDefaultImplementation(self
):
13 urlString
= self
.directParameter()
14 self
.openURL(urlString
)
17 def openURL (self
, urlString
):
18 urlString
= urllib
.unquote (urlString
)
19 m
= re
.match ("^textedit://([^:]*):?([0-9]*):?([0-9]*):?([0-9]*)$", urlString
)
21 NSLog ("URL doesn't match")
28 line
= string
.atoi (m
.group (2))
29 char
= string
.atoi (m
.group (3))
30 column
= string
.atoi (m
.group (4))
35 self
.jumpFile (path
, line
, char
)
37 def charCount (self
, str, line
, char
):
41 lines
= string
.split (str, '\n')
42 lineChars
= sum (map (lambda x
: len (x
) + 1, lines
[:line
]))
43 if line
< len (lines
):
44 lineChars
+= min (char
, len (lines
[line
]))
47 def jumpFile (self
, path
, line
, char
):
48 NSLog ("Jumping to %s %d %d\n" % (path
, line
, char
))
50 controller
= NSDocumentController
.sharedDocumentController ()
51 doc
= controller
.openDocumentWithContentsOfFile_display_ (path
, True)
52 textView
= doc
.textView
54 str = doc
.textView
.string()
55 range.location
= self
.charCount (str, line
, char
)
56 range.location
= min (range.location
, len (str))
59 textView
.setSelectedRange_ (range)
60 textView
.scrollRangeToVisible_ (range)
63 if __name__
== "__main__":
64 AppHelper
.runEventLoop()