脏的 EditorPart 如何禁止 Eclipse 重命名其资源?

发布于 2024-12-08 11:33:43 字数 807 浏览 0 评论 0原文

假设我已经定义了自己的 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. Afterwards editor.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 some RenameParticipant ?

  • 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 its editorInput, or are documentProviders 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾听心声的旋律 2024-12-15 11:33:43

从理论上讲,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文