在BlockUI中,往往希望点击关闭或取消后创建的操作不会撤销,通过执行performApply()可以达到此效果,此时相当于点击了应用会重构UI,此方法不适合复杂的UI重构,因为每执行一次就会重新加载一次UI。
另一个思路,做UI的时候取消对话框上的“确定”、“应用”按钮,只保留“关闭”,就可以实现关闭或取消后保留创建的操作!但是此时对话框框架设置的撤销标记还在,只是此时关闭不会再返回对话框的Undo Mark。
怎样在关闭后直接删除该对话框创建的撤销标记呢,如:
int Test_SCHEME_CONFIG::Show()
{
try
{
theDialog->Show(BlockDialog::DialogModeEdit);
}
catch(exception& ex)
{
//---- Enter your exception handling code here -----
Test_SCHEME_CONFIG::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
return 0;
}
下图为打开对话框即创建一个方块,设置颜色为红色,关闭对话框后方块保留且所有的撤销标记已被删除!
西门子帮助文档关于BlockUI Using undo marks的说明:
In automation code, you can call NXOpen or UF APIs to undo actions.
A user can work only with the undo marks that are created using the automation code. It is expected that undo marks created in any callback must be deleted in the same callback or else the dialog framework automatically deletes that undo mark after the callback execution.
You can undo up to a mark in one of the following ways.
Explicit method
Use direct APIs which delete the undo mark such as Session.UndoToMark(). Attempts to delete the undo marks that are created by the dialog box framework result in an exception, and the dialog box remains open.
Implicit method
Some indirect APIs perform actions which result in the deletion of the undo mark.
When a user attempts to undo actions up to the undo mark created by the dialog box framework, an exception occurs, and the dialog box closes. You can use such APIs only in the OK and Apply callbacks and not in any other callbacks. For example, the UF_STD_import_stl_binary_file API imports a file and removes all undo marks that exist in the NX session.
Note | When a Block UI Styler application shows a second dialog box from the Update callback of the first dialog box, undo is unavailable. After you exit the second dialog box, there are no visible undo marks to undo operations completed in the second dialog box. |