2017-12-14 135 views
9

वीएस में ट्रैकिंग परिवर्तन अब एक इंटरैक्टिव विंडो के साथ आता है, लेकिन कच्चे सीएसआई.एक्सई रोज़लीन प्रक्रिया को चलाने के विपरीत, विजुअल स्टूडियो इंटेलिसेन्स और कुछ अन्य विशेषताओं को जोड़ता है जैसे वर्तमान प्रोजेक्ट में लोड करने में सक्षम होना।सी # इंटरैक्टिव विंडो

मैं एक वीएस प्लग-इन लिखना चाहता हूं जो इस विंडो में सभी टेक्स्ट एडिटर परिवर्तनों को ट्रैक करता है। क्या यह संभव है? जो मैं खोज रहा हूं वह PreviewKeyDown/PreviewTextInput डब्ल्यूपीएफ घटनाओं जैसा कुछ है। क्या मैं उन्हें सी # इंटरैक्टिव विंडो पर प्राप्त कर सकता हूं और यदि ऐसा है, तो कैसे?

यहाँ कितनी दूर मैं अब तक मिल गया है:

var dte = Shell.Instance.GetComponent<DTE>(); 
foreach (Window window in dte.MainWindow.Collection) 
{ 
    if (window.Kind.ToUpper().Contains("TOOL")) 
    { 
    if (window.Caption == "C# Interactive") 
    { 
     WpfWindow wpfWindow = (WpfWindow)HwndSource.FromHwnd((IntPtr) window.HWnd).RootVisual; 
     for (int i = 0; i < VTH.GetChildrenCount(wpfWindow); ++i) 
     { 
     // now what? 
     } 
    } 
    } 
} 
+0

मेह, * इसके अनियंत्रित * का एक अन्य मामला, सचमुच' एनवीडीटीई इंटरएक्टिव 'का उपयोग करने के लिए कोई दस्तावेज नहीं है: https://docs.microsoft। com/en-us/dotnet/api/envdte.outputwindow.dte? view = visualstudiosdk-2017 –

+0

क्या आप सी # इंटरैक्टिव विंडो के IWpfTextViewHost की तलाश में हैं? क्या यह आपके लिए ठीक रहेगा? –

+0

@SimonMourier निश्चित नहीं है। मुझे एक ठोस नियंत्रण की आवश्यकता है जो 1) मुझे अपना पूरा बफर दे सकता है और 2) किसी भी बदलाव पर सूचित करें। मूल रूप से मुझे इंटरैक्टिव विंडो में हर बदलाव को ट्रैक करने की आवश्यकता है। –

उत्तर

10

यहाँ कुछ कोड है कि सी # इंटरैक्टिव खिड़की पर एक IWpfTextViewHost संदर्भ मिल जाएगा है। वहाँ से, आप दृश्य स्टूडियो से सभी पाठ सेवाओं का उपयोग कर सकते हैं: पाठ लाइनों, पाठ बफर, आदि

// get global UI shell service from a service provider 
var shell = (IVsUIShell)ServiceProvider.GetService(typeof(SVsUIShell)); 

// try to find the C# interactive Window frame from it's package Id 
// with different Guids, it could also work for other interactive Windows (F#, VB, etc.) 
var CSharpVsInteractiveWindowPackageId = new Guid("{ca8cc5c7-0231-406a-95cd-aa5ed6ac0190}"); 

// you can use a flag here to force open it 
var flags = __VSFINDTOOLWIN.FTW_fFindFirst; 
shell.FindToolWindow((uint)flags, ref CSharpVsInteractiveWindowPackageId, out IVsWindowFrame frame); 

// available? 
if (frame != null) 
{ 
    // get its view (it's a WindowPane) 
    frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out object dv); 

    // this pane implements IVsInteractiveWindow (you need to add the Microsoft.VisualStudio.VsInteractiveWindow nuget package) 
    var iw = (IVsInteractiveWindow)dv; 

    // now get the wpf view host 
    // using an extension method from Microsoft.VisualStudio.VsInteractiveWindowExtensions class 
    IWpfTextViewHost host = iw.InteractiveWindow.GetTextViewHost(); 

    // you can get lines with this 
    var lines = host.TextView.TextViewLines; 

    // and subscribe to events in text with this 
    host.TextView.TextBuffer.Changed += TextBuffer_Changed; 
} 

private void TextBuffer_Changed(object sender, TextContentChangedEventArgs e) 
{ 
    // text has changed 
} 

नोट "माइक्रोसॉफ्ट (या आप WPF का नियंत्रण है, जो मैं सलाह नहीं देते पर सीधे हुक कर सकते हैं) .VisualStudio.VsInteractiveWindow "असेंबली विशेष रूप से प्रलेखित नहीं है लेकिन स्रोत खुला है: http://source.roslyn.io/#Microsoft.VisualStudio.VsInteractiveWindow

+0

ऐसा लगता है कि यह काम कर सकता है! त्वरित प्रश्न: मैं अंतर्निहित वीएस नियंत्रण में झुकाव के बारे में कैसे जाउंगा? कारण मैं पूछ रहा हूं कि मुझे कैरेट और चयन जानकारी भी पसंद आएगी। –

+0

सब कुछ IWpfTextViewHost से नीचे और नीचे उपलब्ध होना चाहिए। सबसे दिलचस्प सामग्री ITextView में है: कैरेट, चयन, आदि https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.itextview?view=visualstudiosdk-2017 –

+0

स्रोत है खुला, अच्छा जवाब! –

संबंधित मुद्दे