IVsTextManager :: GetActiveView(true,null,...)返回非焦点视图(IVsTextManager::GetActiveView(true, null, …) r

编程入门 行业动态 更新时间:2024-10-26 16:22:40
IVsTextManager :: GetActiveView(true,null,...)返回非焦点视图(IVsTextManager::GetActiveView(true, null, …) returns non-focused view)

我正在玩创建Visual Studio文本编辑命令。 我创建了一个包,绑定命令,将其放入菜单中。 但是,我不能以微软推荐的方式做的是弄清楚是否应该应用命令的活动文本视图。

我正在按照VSSDK教程中的步骤进行操作 (向下滚动到使用菜单命令添加评论装饰 )。 从菜单中选择命令后,可以调用mt命令处理程序。 但是,当执行以下确切的教程代码时,我得到的结果是不一致的。

IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); IVsTextView vTextView = null; int mustHaveFocus = 1; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);

现在,如果只有文本视图,一切都按预期工作:返回活动文本视图。 但是在图片中抛出另一个视图(我使用的是Bitmap编辑器), GetActiveView返回的视图似乎是最后一个活动的文本视图 。 例如,如果我切换选项卡以将先前活动视图的位图视图调出到fileA ,则返回fileA的相同视图。 换句话说,我无法弄清楚文本视图是否有焦点。

现在,这似乎与IVsTextManager::GetActiveView() 文档 (但是很差) 文档 IVsTextManager::GetActiveView() 。 它必须说明函数的第一个参数: 如果为true ,则返回当前的UI活动视图。 我读得对吗? 我观察到的行为看起来似乎与另一种情况相对应: 如果为false ,则返回最后一个活动视图,无论此视图当前是否处于UI活动状态。

我可以想出另一种将命令绑定到视图的方法,即通过挂钩视图创建。 这里让我担心的是,我显然无法以Microsoft推荐的方式处理命令。

I am playing with creating a Visual Studio text editing command. I got as far as creating a package, binding the command, placing it into the menu. But what I cannot do in a Microsoft-recommended way is figure out whether there is an active text view to which the command should be applied.

I am following steps in the VSSDK tutorial (scroll down to Using the Menu Command to Add the Comment Adornment). Upon selecting the command from the menu, mt command handler is called all right. however, when the following exact tutorial code is executed, the results I am getting are inconsistent.

IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); IVsTextView vTextView = null; int mustHaveFocus = 1; txtMgr.GetActiveView(mustHaveFocus, null, out vTextView);

Now, if there are only text views, everything works as you'd expect: the active text view is returned. But throw another view in the picture (I am using a Bitmap editor), and the view returned by GetActiveView appears to be the last active text view. I. e., if I switch tabs to bring up the bitmap view over previously active view to fileA, the same view for fileA is returned. In other words, I cannot figure out whether the text view is focused or not.

Now, this seems to be insconsistent with (however poor) documentation of IVsTextManager::GetActiveView(). It has to say about the first argument to the function: if true, then the current UI active view is returned. Am I reading that correctly? The behavior that I am observing seemingly corresponds to the other case: if false, then the last active view is returned, regardless of whether this view is currently UI active.

I can figure out another way of binding commands to views, namely by hooking up view creation. What worries me here is that I am apparently unable to process the command in the Microsoft-recommended way.

最满意答案

好吧,抱歉令人困惑的文档,但这个演练不是我建议你的案例(我是VS编辑团队的开发人员)。

正如您所指出的那样,通过IVsTextViewCreationListener连接命令过滤器可以更简单地处理命令,这实际上是更常见和更好的方式,请参阅演练:使用带编辑器扩展的快捷键 (这也是一种令人困惑的标题:()

Well, sorry for the confusing documentation, but this walkthrough is not something I would recommend for your case (I'm a dev on VS editor team).

As you pointed out you can handle commands much simpler by hooking up command filter via IVsTextViewCreationListener, this is actually way more common and better way, see Walkthrough: Using a Shortcut Key with an Editor Extension (that is also sort of confusing title :( )

更多推荐

本文发布于:2023-08-07 05:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459544.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   焦点   GetActiveView   IVsTextManager   true

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!