def application_openFiles_(self, app, filenames):
        for fn in filenames:
            NSLog("application:openFiles: %s" % fn)

            evt = NSAppleEventManager.sharedAppleEventManager(
            ).currentAppleEvent()

            odbserver = evt.paramDescriptorForKeyword_(fourcc(keyFileSender))
            if odbserver is not None:
                odbserver = to_fourcc(odbserver.typeCodeValue())

            odbtoken = evt.paramDescriptorForKeyword_(
                fourcc(keyFileSenderToken))
            if odbtoken is not None:
                odbtoken = odbtoken.data()

            odbtitle = evt.paramDescriptorForKeyword_(
                fourcc(keyFileCustomPath))
            if odbtitle is not None:
                odbtitle = odbtitle.stringValue()

            NSLog("ODB server %@, token %@, title %@", odbserver, odbtoken,
                  odbtitle)

            thread = EditorClientWorker.alloc().initWithODB(
                fn, 0, odbserver, odbtoken)
            thread.start()
    def application_openFiles_(self, app, filenames):
        for fn in filenames:
            NSLog("application:openFiles: %s" % fn)

            evt = NSAppleEventManager.sharedAppleEventManager().currentAppleEvent()
            
            odbserver = evt.paramDescriptorForKeyword_(fourcc(keyFileSender))
            if odbserver is not None:
                odbserver = to_fourcc(odbserver.typeCodeValue())

            odbtoken = evt.paramDescriptorForKeyword_(fourcc(keyFileSenderToken))
            if odbtoken is not None:
                odbtoken = odbtoken.data()

            odbtitle = evt.paramDescriptorForKeyword_(fourcc(keyFileCustomPath))                
            if odbtitle is not None:
                odbtitle = odbtitle.stringValue()
                
            NSLog("ODB server %@, token %@, title %@", odbserver, odbtoken, odbtitle)
                
            thread = EditorClientWorker.alloc().initWithODB(fn, 0, odbserver, odbtoken)
            thread.start()
Example #3
0
    def main(self):
        pool = NSAutoreleasePool.alloc().init()
        #NSLog(u"editing thread started for %s" % self.path)
        #NSLog("shell command: %@", EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")})

        stdin = open('/dev/null','r')
        stdout = open('/dev/null','w')
        subprocess.call(["/usr/local/bin/emacsclient", "-a", "", "+%(linenum)s" % {'linenum': self.linenum}, self.path])
            #subprocess.call(EDITOR_COMMAND % {'linenum': self.linenum, 'filename': self.path.replace("'","'\"'\"'")},
        #            shell=True, stdin=stdin, stdout=stdout, stderr=stdout)
        #os.system(EDITOR_COMMAND % {'linenum':self.linenum, 'filename':self.path})

        # Send the "file closed" ODB event.
        if self.odb_app:
            try:
                NSLog("sending file closed event to %s, %s" % (self.odb_app, type(self.odb_app)))
                target = AE.AECreateDesc(AppleEvents.typeApplSignature, self.odb_app[::-1])  # For strange endianness reasons, have to reverse this
                event = AE.AECreateAppleEvent(kODBEditorSuite, kAEClosedFile, target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)

                if self.odb_token:
                    event.AEPutParamDesc(keySenderToken, pack(self.odb_token, typeWildcard))
                #fsr = Carbon.File.FSPathMakeRef(self.path)[0]
                path_url = bytes(NSURL.fileURLWithPath_(self.path).absoluteString().dataUsingEncoding_(NSUTF8StringEncoding))
                NSLog("%s", path_url)
                #path_descriptor = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc(typeFileURL), path_url)
                event.AEPutParamDesc(AppleEvents.keyDirectObject, pack(path_url, typeFileURL))

                event.AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)

                if False:
                    descriptor = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))

                    appleEvent = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(
                        fourcc(kODBEditorSuite), fourcc(kAEClosedFile), descriptor, kAutoGenerateReturnID, kAnyTransactionID)
                    if self.odb_token:
                        evt_tok = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc('****'), self.odb_token)
                        appleEvent.setParamDescriptor_forKeyword_(evt_tok, fourcc(keySenderToken))

                    path_url = NSURL.fileURLWithPath_(self.path).absoluteString().dataUsingEncoding_(NSUTF8StringEncoding)
                    path_descriptor = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc(typeFileURL), path_url)
                    appleEvent.setParamDescriptor_forKeyword_(path_descriptor, fourcc(keyDirectObject))

                    appleEvent.aeDesc().AESend(AppleEvents.kAENoReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)
                    
            except (Exception) as e:
                import traceback
                import sys
                traceback.print_exc(file=sys.stderr)
                
                
            
                    
        

            #evt_app = NSAppleEventDescriptor.descriptorWithTypeCode_(fourcc(self.odb_app))
            #evt = NSAppleEventDescriptor.appleEventWithEventClass_eventID_targetDescriptor_returnID_transactionID_(fourcc(kODBEditorSuite),
            #                                                                                                       fourcc(kAEClosedFile),
            #                                                                                                       evt_app,
            #                                                                                                       -1, # kAutoGenerateReturnID
            #                                                                                                       0) # kAnyTransactionID
            #if self.odb_token:
            #    evt_tok = NSAppleEventDescriptor.descriptorWithDescriptorType_data_(fourcc('****'), self.odb_token)
            #    evt.setParamDescriptor_forKeyword_(evt_tok, fourcc(keySenderToken))
            #
            #fsr = objc.FSRef.from_pathname(self.path).data
            #evt_path = NSAppleEventDescriptor.descriptorWithDescriptorType_bytes_length_(fourcc('fsrf'),fsr,len(fsr))
            #evt.setParamDescriptor_forKeyword_(evt_path, fourcc('----'))

        #NSLog("editing thread finished for %s" % self.path)
        del pool