[wingide-users] Feature request for HTML editing: Jumping around code.
Wingware Support
support at wingware.com
Wed Aug 29 09:50:00 MDT 2012
Me Myself wrote:
> When I edit HTML using wing, I would like to be able to jump to CSS/JS
> files when they are linked in the html. In python, "F4" works with
> wing. Can we make it work for html/css/js as well?
Wing doesn't analyze files other than Python right now but it's not hard
to write a script to open a file based on selection or click in the
editor, which maybe is enough in this case. I've appended below my
signature code that you could paste into scripts/editor_extensions.py in
your Wing installation to replace the similar code that is there in Wing
4.1.7 (it assumes the imports in that file will be available to it, so
would need those added if not in that context). This adds opening also
file names (the old code only opened urls) and will be in Wing 4.1.8.
--
Stephan Deibel
Wingware | Python IDE
Advancing Software Development
www.wingware.com
-----------------------------------------------------------------
kUrlChars = string.punctuation + string.ascii_uppercase +
string.ascii_lowercase + string.digits
kFileChars = '-_.+#/\\' + string.ascii_uppercase +
string.ascii_lowercase + string.digits
def _word_at_position(editor, pos, valid_chars):
doc = editor.GetDocument()
lineno = doc.GetLineNumberFromPosition(pos)
line_start = doc.GetLineStart(lineno)
line_end = doc.GetLineEnd(lineno)
linetxt = doc.GetCharRange(line_start, line_end)
from wingutils import textutils
return textutils.GetNearestWord(linetxt, pos - line_start, valid_chars)
def _open_url_at_position(editor, pos):
word = _word_at_position(editor, pos, kUrlChars)
if not word.startswith('http:') and not word.startswith('https:'):
print "Not a url: %s" % word
return
wingapi.gApplication.OpenURL(word)
def _open_file_at_position(editor, pos):
word = _word_at_position(editor, pos, kFileChars)
if not word:
print "Not a file name"
return
curdir = os.path.dirname(editor.GetDocument().GetFilename())
savedir = os.getcwd()
filename = word
try:
os.chdir(curdir)
filename = os.path.abspath(word)
finally:
os.chdir(savedir)
wingapi.gApplication.OpenEditor(filename)
def open_url_from_editor():
editor = wingapi.gApplication.GetActiveEditor()
if not editor:
return
pos = editor.GetSelection()[0]
_open_url_at_position(editor, pos)
def open_clicked_url_from_editor():
editor = wingapi.gApplication.GetActiveEditor()
if not editor:
return
pos = editor.GetClickLocation()
_open_url_at_position(editor, pos)
# Uncomment the next lines to add this to the editor's context menu
#open_clicked_url_from_editor.contexts = [wingapi.kContextEditor()]
#open_clicked_url_from_editor.label = _("Open Clicked URL")
def open_filename_from_editor():
editor = wingapi.gApplication.GetActiveEditor()
if not editor:
return
pos = editor.GetSelection()[0]
_open_file_at_position(editor, pos)
def open_clicked_filename_from_editor():
editor = wingapi.gApplication.GetActiveEditor()
if not editor:
return
pos = editor.GetClickLocation()
_open_file_at_position(editor, pos)
# Uncomment the next lines to add this to the editor's context menu
#open_clicked_filename_from_editor.contexts = [wingapi.kContextEditor()]
#open_clicked_filename_from_editor.label = _("Open Clicked Filename")
More information about the wingide-users
mailing list