Created
March 11, 2017 23:45
-
-
Save timsneath/2fd0732dc467e15d359dd265ef8025bc to your computer and use it in GitHub Desktop.
Gets the file currently being edited
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string GetCurrentFilenameFromEditor() | |
{ | |
var textManager = this.ServiceProvider.GetService(typeof(SVsTextManager)) as IVsTextManager; | |
int mustHaveFocus = 1; | |
textManager.GetActiveView(mustHaveFocus, null, out IVsTextView textView); | |
var userData = textView as IVsUserData; | |
if (userData == null) | |
{ | |
// no text view is currently open | |
return String.Empty; | |
} | |
else | |
{ | |
Guid guidViewHost = DefGuidList.guidIWpfTextViewHost; | |
userData.GetData(ref guidViewHost, out object holder); | |
IWpfTextViewHost viewHost = (IWpfTextViewHost)holder; | |
viewHost.TextView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument doc); | |
return doc.FilePath; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment