规范 - 使用 ctrl-S (或 cmd+s)保存文本输入
SpTextPresenter
和 SpTextInputFieldPresenter
有没有办法使用 ctrl+S (或 mac 中的 cmd+S)来保存文本输入?
旧的 pharo 组件(特别是旧规范,但这是从以前开始的,当组件构建在纯形态上时)允许通过按 来“接受”内容(并通过使用取消版本)
)。
有没有办法在当前规范中复制这种行为?
is there a way in SpTextPresenter
and SpTextInputFieldPresenter
to use ctrl+S (or cmd+S in mac) to save text entry?
Old pharo components (notably old spec but this comes since before, when components when built on plain morphic) were allowing to "accept" contents by pressing <meta+S>
(and cancelling the edition by using <meta+L>
).
Is there a way to replicate this behavior in current Spec?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
规范允许定义“默认”提交/重置事件以提供旧行为。
好的,这是一个简单的答案,但对于某些用户来说有点复杂,因为他们期望旧的行为,而这不再像以前那样工作了。
所以首先我需要解释为什么旧的行为不再可用:)
事实是,旧组件混合了不同的东西:它们是普通的 UI 小部件,同时也是具有旧 MVC(模型视图控制器)精神的模型容器。所以他们混合了模型(状态的保存)和视图(组件的显示)。因此,旧组件具有初始状态,您需要接受该状态(使用
)才能将其转移到模型部分。
这种职责组合导致了不同的解决方法,例如添加
autoAccept
属性以使组件复制其更改的值。在设计新版本的 Spec 时,我们决定不保留这种看起来很糟糕并且会导致 API 不一致的行为,因此任何想要旧行为的人都需要在自己的组件中显式地实现它。
那么,如何恢复旧行为呢?
这毕竟是个问题!
我们添加了两个方法来实现相同的功能:
whenSubmitDo:
和whenResetDo:
。这可以与whenTextChangedDo:
结合使用来标记/取消标记脏属性。这是一个示例,有点冗长,但也很容易创建您自己的具有预定义行为的组件并在您的应用程序中重用它们:
这将产生(使用 Gtk3 后端)此输出:
Spec permits to define "default" submit/reset events to provide old behavior.
Ok, this is an easy answer, but somehow complicated for some users since they expect the old behavior and this does not works like that anymore.
So first I need to explain why old behavior is no longer available :)
Thing is, old components where a mix of different things: they were plain UI widgets while also model containers in the spirit of old MVC (Model View Controller). So they mixed Model (the keep of the status) and the view (the display of the component). For this reason, old components had an initial status and you needed to accept that status (you got it, using
<meta+S>
) to make it being transferred to the model part.This mix of responsibilities lead to different workarounds, like the addition of the
autoAccept
property to make the component copy its value it change of it.When designing the new version of Spec we decided to not keep this behavior that looked hacky and was causing inconsistencies in the API and in consequence anyone wanting the old behavior need to make it explicitly in their own components.
So, how to get old behavior?
This is the question after all!
We have added two methods to allow somehow same functionality:
whenSubmitDo:
andwhenResetDo:
. This can be combined withwhenTextChangedDo:
to mark/unmark a dirty property.Here is an example, Is a little bit verbose, but is also easy to create your own components with this behavior predefined and reuse them in your application:
This will produce (with the Gtk3 backend) this output: