Home Download Buy Blog Forum Support

Open in Browser

Open in Browser

Postby T.R. on Sat Oct 24, 2009 9:18 pm

How can I enable the "Open in Browser" command for other file types, such as xml and xhtml?

My apologies in advance if this is already answered elsewhere, I haven't been able to find it.
T.R.
 
Posts: 4
Joined: Sun Oct 18, 2009 7:42 pm

Re: Open in Browser

Postby ilya on Sat Oct 24, 2009 9:25 pm

This is most likely related question: viewtopic.php?f=6&t=762

Abstracted saying — the question is how to open current file with some needed
application.
ilya
 
Posts: 122
Joined: Fri Sep 11, 2009 8:32 pm

Re: Open in Browser

Postby T.R. on Sat Oct 24, 2009 9:47 pm

Perhaps related, but I think the solutions will be quite different for the two questions. The "Open in Browser" command already exists; it is simply disabled for all file types that are not HTML. I would guess this is a setting in the file-type preferences or something. The other question regards modifying the command itself, which may involve writing a plugin. Both would certainly be useful.
T.R.
 
Posts: 4
Joined: Sun Oct 18, 2009 7:42 pm

Re: Open in Browser

Postby jps on Sat Oct 24, 2009 10:26 pm

Open in Browser is implemented by the plugin Packages/HTML/OpenInBrowser.py

If you open that up, you can see that it's hardcoded to only be enabled file names that end in .html or .htm - it would be easy to modify your local copy to use a different set of file extensions.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Open in Browser

Postby T.R. on Sat Oct 24, 2009 10:37 pm

Awesome, thanks a lot.

It seems I was wrong, and that they are related, as the script could also likely be modified to open a different browser or application.
T.R.
 
Posts: 4
Joined: Sun Oct 18, 2009 7:42 pm

Re: Open in Browser

Postby sean on Sat Oct 24, 2009 11:37 pm

OpenInBrowser.py
Code: Select all
import sublime, sublimeplugin
import webbrowser

class OpenInBrowserCommand(sublimeplugin.TextCommand):
   def run(self, view, args):
      if view.fileName():
         webbrowser.open_new_tab("file://" + view.fileName())
      
   def isEnabled(self, view, args):
      return view.fileName() and (view.fileName()[-5:] == ".html" or
         view.fileName()[-4:] == ".htm" or
         view.fileName()[-4:] == ".php")

this works, but it's sending this to the browser "file:///C:/xampp/htdocs/test.php". the problem being that my php environment needs to be accessed as simply http ://localhost/test.php. any idea on how to conditionally remove the "C:/xampp/htdocs/" from the beginning and send via "http://" if we're dealing with a php file. total python newb. :oops:

sean
sean
 
Posts: 14
Joined: Sat Oct 24, 2009 6:36 am

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 28 guests