我想讓他右鍵鼠標菜單的“open in Browser”是啟動火狐瀏覽器,而不是打開默認的瀏覽器?
1 回答
慕尼黑的夜晚無繁華
TA貢獻1864條經驗 獲得超6個贊
Open In Browser 只能使用默認瀏覽器打開,你可以看看它的代碼:
Packages/Default/open_in_browser.py:
import sublime, sublime_plugin
import webbrowserclass OpenInBrowserCommand(sublime_plugin.TextCommand):
def run(self, edit): if self.view.file_name():
webbrowser.open_new_tab("file://" + self.view.file_name())
def is_visible(self):
return self.view.file_name() and (self.view.file_name()[-5:] == ".html" or
self.view.file_name()[-5:] == ".HTML" or
self.view.file_name()[-4:] == ".htm" or
self.view.file_name()[-4:] == ".HTM")你可以另外寫個插件提供相應功能。
要右鍵菜單,需要加個 Context.sublime-menu。
查考 Packages/Default/Context.sublime-menu 的實現。
關鍵代碼供你參考(從我某個插件摳出來的,不完整):
# 在OSX下使用Firefox打開瀏覽器
# browser_command = ["open", "-a", "firefox", "{url}"]
# url = "blahblahblah"browser_command = [ os.path.expandvars(arg).format(url=url) for arg in setting.browser_command
]
if os.name == 'nt':
# unicode arguments broken under windows
encoding = locale.getpreferredencoding()
browser_command = [arg.encode(encoding) for arg in browser_command]
subprocess.Popen(browser_command)添加回答
舉報
0/150
提交
取消
