脏的 EditorPart 如何禁止 Eclipse 重命名其资源?
假设我已经定义了自己的 TextEditorX extends TextEditor
。在典型的 Eclipse-RCP 场景(标准插件、带有 Project Explorer/Navigator 的工作台)中,当有人尝试重命名(通过 Project Explorer 或 Navigator)某个编辑器已打开的文件时,行为是:
如果编辑器不是 < code>dirty,允许重命名。之后,将调用
editor.setInput()
,并以新文件名作为参数。如果
脏
,则会抛出错误(“重命名资源”:“执行重构时发生致命错误”“发现问题:doc.txt未保存”).
我的问题:
此行为是在哪个级别定义的?我猜想涉及到包 org.eclipse.ltk.ui.refactoring.resource...但是,假设我想禁止重命名,即使编辑器不脏:可以吗行为由编辑器(或文档提供程序)中的某种方法确定,或者我应该编码/扩展一些
RenameParticipant
?重命名器如何知道资源
doc.txt
已被该编辑器实例打开?它只是检查所有打开的编辑器并询问每个编辑器的editorInput
,还是涉及documentProviders
?具体来说,假设我有一个特定的编辑器,除了“主”文件之外,它还依赖于其他资源(多文件输入),并且它希望重命名器在重命名任何输入之前询问他。您将如何处理这种情况?
Say I have defined my own TextEditorX extends TextEditor
. In the typical Eclipse-RCP scenario (standard plugins, workbench with Project Explorer/ Navigator) the behaviour when someone tries to rename (via Project Explorer or Navigator) a file that some editor has opened is:
If the editor is not
dirty
, the renaming is allowed. Afterwardseditor.setInput()
will be called, with the new filename as argument.If it's
dirty
, an error is thrown ("Rename resource" : "A fatal error occurred while performing the refactoring" "Found problems: doc.txt is unsaved").
My questions:
At which level is this behaviour defined? I guess that the package
org.eclipse.ltk.ui.refactoring.resource
is involved... But, suppose for example that I want to disallow the rename even when the editor is not dirty: could this behaviour be determined by some method in the editor (or the document provider), or should I code/extend someRenameParticipant
?How does the renamer knows that the resource
doc.txt
is opened by that editor instance? Does it just check all opened editors and ask each one for itseditorInput
, or aredocumentProviders
involved? Specifically, suppose I have a particular editor that, besides the "main" file, depends on other resources (a multi-file input), and it want the renamer to ask him before renaming any of his inputs. How would you approach this scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从理论上讲,Eclipse 没有理由阻止对修改后的文件进行重命名。其一,编辑器可以向工作区注册一个 ResourceChangeListener,并简单地更新其 IEditorInput 以响应 MOVE 通知。不确定这是否是一个好的答案,但也许是一个好的方法。
There's no theoretical reason for Eclipse to prevent a rename of a modified file. For one, the editor could register a ResourceChangeListener with the workspace, and simply update its IEditorInput in response to a MOVE notification. Not sure if that is a good answer but maybe a good approach to go.