如何以编程方式为Eclipse UI命令设置初始状态?(How to programmatically set an initial state for an Eclipse UI command?)
我正在扩展
org.eclipse.ui.commands
以提供一个新的命令给我的menuContribution
,它有一个toggle
样式。现在我想设置一个初始状态,但它不应该是一个硬编码状态。 因此,提供以下状态不是一种选择:
<state class="org.eclipse.ui.handlers.RegistryToggleState:true" id="org.eclipse.ui.commands.toggleState"> </state>
国家应该在偏好页面中反映一个属性,不需要坚持任何东西。 通过调用插件
Activator
中的方法手动设置状态不起作用,因为一旦我第一次点击该命令,我就会跳入start
方法,但这已经太晚了,因为上下文菜单应该已经反映了正确的偏好属性的状态。我该如何解决这个问题?
I am extending
org.eclipse.ui.commands
to provide a new command to mymenuContribution
which has atoggle
style.Now I want to set an initial state, but it should not be a hard-coded state. Consequently, providing the following state is not an option:
<state class="org.eclipse.ui.handlers.RegistryToggleState:true" id="org.eclipse.ui.commands.toggleState"> </state>
The state should reflect a property in the preference page, there's no need to persist anything. Setting the state manually by invoking the methods in the plugin
Activator
does not work, because I will jump into thestart
method as soon as I click on the command for the first time, but that's too late since the context menu should already reflect the correct state of the preference property.How can I solve this issue?
原文:https://stackoverflow.com/questions/41806379
最满意答案
问题在于,编译器期望
FileInfo
类型的项目,但是IList包含object
。我把你的一些代码放到VS中,英文错误是...
'IList <object>'不包含'ToObservableCollection'的定义,并且最好的扩展方法重载'Extensions.ToObservableCollection <FileInfo>(IEnumerable <FileInfo>)'需要一个类型为'IEnumerable <FileInfo>'的接收器
这就是说,它能找到的最接近的扩展方法就是你写的那个,但是传递给它的类型是不正确的。 为了解决这个问题,我们只需要将你的
object
成FileInfo
。这是一种方法(假设你的对象最初是作为FileInfos创建的)。
items.Cast<FileInfo>().ToObservableCollection()
The issue lies in the fact that the compiler is expecting items of type
FileInfo
but your IList containsobject
s.I put some of your code into VS and the error in English is...
'IList<object>' does not contain a definition for 'ToObservableCollection' and the best extension method overload 'Extensions.ToObservableCollection<FileInfo>(IEnumerable<FileInfo>)' requires a receiver of type 'IEnumerable<FileInfo>'
This is saying that the closest extension method it could find is the one you wrote, but the type being passed to it is not right. To fix this we just need to cast your
object
s toFileInfo
s.Here's one way to do that (assuming your objects were originally create as FileInfos).
items.Cast<FileInfo>().ToObservableCollection()
相关问答
更多-
的确, .reduce()只会在完成时触发。 简单地用.scan()替换它,它会在每个上游事件中触发。 顺便说一下,为什么不使用Observable.timer()而不是自定义的可观察值? Indeed, .reduce() fires only on completion. Simply replace it with .scan(), and it will fire on every upstream event. And by the way, why not use Observable.time ...
-
RxJS将可观察数据追加到打字稿中的可观察数组列表中(RxJS append observable to observable array list in typescript)[2022-05-16]
您可以使用扫描来累积新闻 news$:ObservableloadMore$=new Subject () ngOnInit(){ this.news$=this.loadMore$ .switchMap((newsId)=>this.newsService.getNewNews(newsId)) .scan((acc,curr)=>{ acc.push(curr) return acc },[]).startWith(null) } addNews(n ... -
.NET Framework的ObservableCollection类在每个项目添加到集合时发送单独的通知,并且不提供AddRange类型功能的机制。 但是,您可以非常轻松地创建自己的集合来实现INotifyCollectionChanged并发送您喜欢的任何通知。 您可能遇到的问题是, INotifyCollectionChanged接口包括指定在单个消息中将多个项目添加到集合的功能,但是没有标准的.NET Framework类实际创建这些通知。 因此,一些第三方和开源控件在收到添加通知时只添加了一个项 ...
-
使列表可观察(Make a List observable)[2022-03-22]
问题在于,编译器期望FileInfo类型的项目,但是IList包含object 。 我把你的一些代码放到VS中,英文错误是... 'IList -
我认为这样做你想要的: function asyncOperation(user) { return Rx.Observable .timer(3000 * Math.random()) .map(() => { user.isModified = true; return user; }).do((x) => { console.log('async', x); }); } const users = [ { id: 1, name: 'First ...
-
它不起作用,因为observabe委托只观察变量的变化 ,而不是变量中 存储的对象。 所以当列表发生变化时,变量仍然指向相同的列表,并且可观察的委托并不知道任何变化。 为了观察,您需要一些实际观察列表内容的方法,这不是Kotlin或Java提供的开箱即用功能。 你需要一些可观察的清单。 或者,您可以使用标准列表(而不是可变的列表),并且每当您需要更改列表时,请将其替换为列表的新版本。 通过这种方式,您可以像您想要的那样聆听变化,但可能需要使用该列表调整很多其他代码。 It doesn't work beca ...
-
可观察列表角度2(observable list angular 2)[2023-06-17]
我想这就是你想要的: let users = this.af.database.list('listOfUsers/'); var profiles = users.flatMap(t => Observable.forkJoin( t.map(x => this.af.database.object('profiles/' + x.uid)) ) ); return profiles; I think this is what you ... -
jqAutoComplete插件没有设置为使用可观察的属性(虽然可以增强它,但没有太多工作)。 现在,我认为您最好的选择是创建一个计算器,它将始终返回您的选项的简单和最新版本。 self.myOptionsObs.plain = ko.computed(function() { return ko.toJS(self.myOptionsObs); }); 示例: http : //jsfiddle.net/rniemeyer/45cepL9b/ 我将尝试看一下支持可观察属性的一些观点。 不应该采取 ...
-
从事件可观察到(Observable from event)[2022-04-11]
大多数Observable运算符的工作方式与同名的Enumerable运算符的工作方式相同。 如果您有使用它们的经验,这将是有用的。 因此,为了解决这个问题,我们暂时使用一个整数数组而不是observable。 int[] data = {1, 2, 3, 4}; 这会将表达式更改为 var results = data.Select(_ => true) .StartWith(IsLoaded) .Where(l => l) ... -
绑定到可观察数组(Binding to observable array)[2021-11-14]
你可以尝试这种方法: private comments: IComment[]; private observableComments: BehaviorSubject; constructor() { this.comments = new Array ; this.observableComments = >new BehaviorSubject([]); } get comments( ...