Skip to content

Commit d9693e8

Browse files
Michael Lyonsmichaelblyons
authored andcommitted
Add command to open front-end from CodeBehind/File
1 parent df47e78 commit d9693e8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

WebForms/WebForms.sublime-commands

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[
22
{
3-
"caption": "C# WebForms: Open CodeBehind/CodeFile",
3+
"caption": "C# WebForms: Open CodeBehind / CodeFile",
44
"command": "open_code_file_from_front_end",
55
},
6+
{
7+
"caption": "C# WebForms: Open Front End",
8+
"command": "open_front_end_from_code_file",
9+
},
610
]

webforms.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sublime
22
import sublime_plugin
3+
from re import search
4+
from os.path import isfile
35

46

57
class OpenCodeFileFromFrontEndCommand(sublime_plugin.TextCommand):
@@ -15,3 +17,19 @@ def run(self, edit):
1517
region = self.view.find_by_selector('meta.path.codefile')[0]
1618
codefile = self.view.substr(region)
1719
self.view.window().open_file(str(codefile))
20+
21+
22+
class OpenFrontEndFromCodeFileCommand(sublime_plugin.TextCommand):
23+
"""Naively open foo.ascx from foo.ascx.cs"""
24+
25+
def is_enabled(self):
26+
filename = self.view.file_name()
27+
if ((filename
28+
and self.view.match_selector(0, 'source.cs')
29+
and search(r'\.(?:as[pc]x|master)\.cs$', filename)
30+
and isfile(filename[:-3]))):
31+
return True
32+
return False
33+
34+
def run(self, edit):
35+
self.view.window().open_file(self.view.file_name()[:-3])

0 commit comments

Comments
 (0)