""" This allows you to switch from controller to view and back again If the view is not there it allows you to enter a name for it """ from xpcom import components import re import os #i have no clue but i jacked it from an example wwatch = components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(components.interfaces.nsIWindowWatcher) prompt = wwatch.getNewPrompter (wwatch.activeWindow) #looking for something that starts with def if komodo.document.displayPath.find("_controller.rb")>0: def_finder=re.compile("^def") komodo.editor.lineEnd() #highlight text from back? komodo.editor.vCHomeExtend() #get the text that was just highlighted #is there a better way to get each line of text? text_line = komodo.editor.selText #error checking line count line = komodo.editor.lineFromPosition(komodo.editor.currentPos) #if len is 2 we have a def while 1==len(def_finder.split(text_line.strip())) and line>1: komodo.editor.lineUp() komodo.editor.lineEnd() komodo.editor.vCHomeExtend() text_line = komodo.editor.selText line = komodo.editor.lineFromPosition(komodo.editor.currentPos) col = komodo.editor.getColumn(komodo.editor.currentPos) line = komodo.editor.lineFromPosition(komodo.editor.currentPos ) komodo.editor.lineEnd() komodo.editor.vCHomeExtend() text_line = komodo.editor.selText #a[1] is method name method=def_finder.split(text_line.strip())[1] method=method.strip() paths= os.path.split(komodo.document.displayPath) controller_name=paths[1].replace("_controller.rb","") dir=os.path.split(paths[0])[0] view_dir=str(dir)+"/views/"+controller_name if os.path.isdir(view_dir): #only check for rhtml files maybe will expand to other formats if os.path.isfile(view_dir+"/"+method+".rhtml"): komodo.openURI("file:///"+view_dir+"/"+method+".rhtml") else: a=prompt.prompt("Create your self a view then?","You are creating a view for the contoller :"+controller_name,method+".rhtml","point less check box,I do not use the value",1) #a is a list maybe? where the value is stored in spot 1 textfile = file(view_dir+"/"+a[1],'wa') textfile.close komodo.openURI("file:///"+view_dir+"/"+a[1]) else: prompt.alert("Error", "no controller-view folder found:"+view_dir) elif komodo.document.displayPath.find(".rhtml")>0:#need to check other formats too paths = os.path.split(komodo.document.displayPath) filename=paths[1].split(".")[0] #strip out leading _ def_finder=re.compile("^\s*def\s*"+filename,re.IGNORECASE) paths=os.path.split(paths[0]) controller=paths[1]+"_controller.rb" path=paths=os.path.split(paths[0])[0]+"/controllers/" komodo.openURI("file:///"+path+controller) komodo.editor.documentEnd maxlines = komodo.editor.lineFromPosition(komodo.editor.currentPos) komodo.editor.documentStart komodo.editor.lineEnd() #highlight text from back komodo.editor.vCHomeExtend() #get the text that was just highlighted text_line = komodo.editor.selText #error checking line count col = komodo.editor.getColumn(komodo.editor.currentPos) line = komodo.editor.lineFromPosition(komodo.editor.currentPos) while def_finder.search(text_line)==None and line