📄 mainfrm.cpp
字号:
}
/*void CMainFrame::OnUpdateCmdUI (CCmdUI *pCmdUI)
{
// Get pointer to our document:
CTest2Doc *pDoc = (CTest2Doc *) GetActiveDocument ();
ASSERT (pDoc != NULL);
// Set flag to indicate we sould disable all items related to project
// edit functions if the docuemtn is presently locked (i.e. don't allow
// other threads to access document data while another thread has
// possession of it.)
bool bDisableProjectEditOperations = pDoc->IsLocked ();
// Processes according to the menu item we are being asked about:
switch (pCmdUI->m_nID)
{
// Disable "File|New", "File|Open", and "File|Exit" if document
// is locked:
case ID_FILE_NEW:
case ID_FILE_OPEN:
case ID_APP_EXIT:
pCmdUI->Enable (!pDoc->IsLocked ());
break;
// Always enable "Help|About":
case ID_APP_ABOUT:
pCmdUI->Enable (true);
break;
// Enable "File|Save" only if document is not locked, and is modified:
case ID_FILE_SAVE:
pCmdUI->Enable (!bDisableProjectEditOperations && ((CKDocument *) GetActiveDocument ())->IsModified ());
break;
// Enable "File|Save As" only if document is not locked and has
// server objects defined:
case ID_FILE_SAVE_AS:
pCmdUI->Enable (!bDisableProjectEditOperations && ((CKDocument *) GetActiveDocument ())->GetServerCount () > 0);
break;
// Disable "File|Most Recently Used Files" selections if document
// is locked:
case ID_FILE_MRU_FILE1:
case ID_FILE_MRU_FILE2:
case ID_FILE_MRU_FILE3:
case ID_FILE_MRU_FILE4:
case ID_FILE_MRU_FILE5:
case ID_FILE_MRU_FILE6:
case ID_FILE_MRU_FILE7:
case ID_FILE_MRU_FILE8:
case ID_FILE_MRU_FILE9:
case ID_FILE_MRU_FILE10:
case ID_FILE_MRU_FILE11:
case ID_FILE_MRU_FILE12:
case ID_FILE_MRU_FILE13:
case ID_FILE_MRU_FILE14:
case ID_FILE_MRU_FILE15:
case ID_FILE_MRU_FILE16:
if (pCmdUI->m_pMenu)
{
int iMRU;
CMenu *pMenu = pCmdUI->m_pMenu;
TRACE (_T("Deleting MRU list\n"));
// Pre-delete everything so that things don't get screwed up when
// the user makes a change
for (iMRU = ID_FILE_MRU_FILE1; iMRU <= ID_FILE_MRU_FILE16; iMRU++)
pMenu->DeleteMenu (iMRU, MF_BYCOMMAND);
cApp.OnUpdateMRUFile (pCmdUI);
// If locked, set enabled state to "GRAYED and DISABLED":
if (pDoc->IsLocked ())
{
for (iMRU = ID_FILE_MRU_FILE1; iMRU <= ID_FILE_MRU_FILE16; iMRU++)
pMenu->EnableMenuItem (iMRU, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
}
}
break;
// Enable "Edit|Copy" only if document is not locked, and appropriate
// item is slected:
/*case ID_EDIT_COPY:
{
// If document is not locked, look at what view is active and what
// sort of view items are selected:
if (!bDisableProjectEditOperations)
{
// Get pointer to the active view:
CView *pView = GetActiveView ();
// If the group view is active, enable if a server or group
// is selected:
if (pView == GetGroupView ())
{
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
}
// Else if the item view is active, enable if one or more
// items are selected:
else if (pView == GetItemView ())
{
pCmdUI->Enable (((CKItemView *)pView)->GetSelectedCount ());
}
// Otherwise disable:
else
pCmdUI->Enable (false);
}
// Disable if document is locked:
else
pCmdUI->Enable (false);
}
break;
// Enable "Edit|Cut" and "Edit|Delete" only if document is not locked
// and a group or server is selected:
case ID_EDIT_CUT:
case ID_EDIT_DELETE:
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
break;
// Disable "Edit|Paste" if document is locked. If not, enable only if
// it makes sence to paste the contents of the clipboard into the
// selected item:
/*case ID_EDIT_PASTE:
{
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
{
// Get pointer to the active view:
CView *pView = GetActiveView ();
// Get pointer to the selected server and group:
CKServer *pServer = pDoc->GetSelectedServer ();
CKGroup *pGroup = pDoc->GetSelectedGroup ();
// If group view is active:
if (pView == GetGroupView ())
{
// Can paste server if no selected object:
if (pServer == NULL && pGroup == NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_SERVER));
// Can paste group or server if a server is selected:
else if (pServer != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_SERVER) ||
IsClipboardFormatAvailable (CF_GROUP));
// Can paste item if a group is selected:
else if (pGroup != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_ITEM));
}
// Else if item view is active:
else if (pView == GetItemView ())
{
// Can paste item if a group is selected:
if (pGroup != NULL)
pCmdUI->Enable (IsClipboardFormatAvailable (CF_ITEM));
// Otherwise can't paste anything:
else
pCmdUI->Enable (false);
}
// Can't paste into any other view, so disable:
else
pCmdUI->Enable (false);
}
}
break;
// Enable "Edit|New Server Connection" if document is not locked:
case ID_EDIT_NEWSERVER:
pCmdUI->Enable (!bDisableProjectEditOperations);
break;
// Enable "Edit|New Group" if document is not locked and a server
// is selected:
case ID_EDIT_NEWGROUP:
pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedServer () != NULL);
break;
// Enable "Edit|Properties" if document is not locked and a server or
// or group is selected:
case ID_EDIT_PROPERTIES:
if (bDisableProjectEditOperations)
pCmdUI->Enable (false);
else
pCmdUI->Enable ((pDoc->GetSelectedServer () != NULL) ||
(pDoc->GetSelectedGroup () != NULL));
break;
// Enable "Edit|New Item" if document is not locked and a group
// is selected:
case ID_EDIT_NEWITEM:
pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedGroup () != NULL);
break;
// Enable "View|Clear Messages" if the event view has messages in it:
/*case ID_VIEW_CLEAR:
pCmdUI->Enable (GetEventView ()->GetEventCount ());
break;
// Always enable "View|Log Errors Only". Check if event view's
// "log errors only" flag has been set:
case ID_VIEW_ERRORONLY:
pCmdUI->Enable (true);
pCmdUI->SetCheck (GetEventView ()->LogErrorsOnly ());
break;
// Enable "Tools|Server|Connect" if document is not locked, a
// server is selected, and that server in not presently connected:
case ID_TOOLS_CONNECT:
{
CKServer *pServer = pDoc->GetSelectedServer ();
if (pServer && !bDisableProjectEditOperations)
pCmdUI->Enable (!pServer->IsConnected ());
else
pCmdUI->Enable (false);
}
break;
// Enable "Tools|Server|Disconnect", "Tools|Server|Reconnect",
// "Tools|Server|Get Error String", "Tools|Server|Get Group By Name",
// and "Tools|Server|Enumerate Groups" if document is not locked,
// a server is selected, and that server is presently connected:
case ID_TOOLS_DISCONNECT:
case ID_TOOLS_RECONNECT:
case ID_TOOLS_GET_ERROR_STRING:
case ID_TOOLS_GET_GROUP_BY_NAME:
case ID_TOOLS_ENUMERATE_GROUPS:
{
CKServer *pServer = pDoc->GetSelectedServer ();
if (pServer && !bDisableProjectEditOperations)
pCmdUI->Enable (pServer->IsConnected ());
else
pCmdUI->Enable (false);
}
break;
// Enable "Tools|Group|Clone Group" if document is not locked, a
// group is selected, and that group supports the Group State
// Management interface:
/*case ID_TOOLS_CLONE_GROUP:
{
CKGroup *pGroup = pDoc->GetSelectedGroup ();
if (pGroup && !bDisableProjectEditOperations)
{
pCmdUI->Enable (pGroup->IsIGroupStateMgtSupported ());
}
else
pCmdUI->Enable (false);
}
break;
// Enable "Tools|Group|Export CSV" and "Tools|Group|Import CSV" if
// document is not locked, and a group is selected:
case ID_TOOLS_EXPORT_CSV:
case ID_TOOLS_IMPORT_CSV:
pCmdUI->Enable (!bDisableProjectEditOperations && pDoc->GetSelectedGroup () != NULL);
break;
// Enable "Tools|Item|Set Active" and "Tools|Item|Set Inactive" if
// docuement is not locked, a group is selected, if one or more
// items in that group are currently selected, and the group
// supports the Item Management interface:
case ID_TOOLS_SET_ACTIVE:
case ID_TOOLS_SET_INACTIVE:
{
CKGroup *pGroup = pDoc->GetSelectedGroup ();
if (pGroup && !bDisableProjectEditOperations)
{
pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) &&
(pGroup->IsIItemMgtSupported ()));
}
else
pCmdUI->Enable (false);
}
break;
// Enable item sync read and write if document is not locked, a
// group is selected, if one or more items in that group are
// currently selected, and the group supports the sync IO
// interface:
/*case ID_TOOLS_SYNC_READ_CACHE:
case ID_TOOLS_SYNC_READ_DEVICE:
case ID_TOOLS_SYNC_WRITE:
{
CKGroup *pGroup = pDoc->GetSelectedGroup ();
if (pGroup && !bDisableProjectEditOperations)
{
pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) &&
(pGroup->IsISyncIOSupported ()));
}
else
pCmdUI->Enable (false);
}
break;*/
// Enable item async 1.0 read, write and refresh if document is not
// locked, a group is selected, if one or more items in that group
// are currently selected, the group supports the Async IO interface
// and the OPC_20_DATACHANGE update method:
/*case ID_TOOLS_ASYNC10_READ_CACHE:
case ID_TOOLS_ASYNC10_READ_DEVICE:
case ID_TOOLS_ASYNC10_REFRESH_CACHE:
case ID_TOOLS_ASYNC10_REFRESH_DEVICE:
case ID_TOOLS_ASYNC10_WRITE:
{
CKGroup *pGroup = pDoc->GetSelectedGroup ();
if (pGroup && !bDisableProjectEditOperations)
{
pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) &&
(pGroup->IsIAsyncIOSupported ()) &&
(pGroup->GetUpdateMethod () != OPC_20_DATACHANGE));
}
else
pCmdUI->Enable (false);
}
break;
// Enable item async 2.0 read, write and refresh if document is not
// locked, a group is selected, if one or more items in that group
// are currently selected, the group supports the Async 2.0 IO interface
// and the OPC_20_DATACHANGE update method
case ID_TOOLS_ASYNC20_READ_DEVICE:
case ID_TOOLS_ASYNC20_REFRESH_CACHE:
case ID_TOOLS_ASYNC20_REFRESH_DEVICE:
case ID_TOOLS_ASYNC20_WRITE:
{
CKGroup *pGroup = pDoc->GetSelectedGroup ();
if (pGroup && !bDisableProjectEditOperations)
{
pCmdUI->Enable ((GetItemView ()->GetSelectedCount () > 0) &&
(pGroup->IsIAsyncIO2Supported ()) &&
(pGroup->GetUpdateMethod () == OPC_20_DATACHANGE));
}
else
pCmdUI->Enable (false);
}
break;
default:
// Unexpected item ID - programmer error
TRACE (_T("OTC: Unhandled OnUpdateCmdUI case (%08X)!\r\n"), pCmdUI->m_nID);
break;
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -