Example #1
0
void cmdListCtrl::RunMenu(const int id,cmdListCtrl* ctrl)
{
    int item = ctrl->GetNextItem(-1,wxLIST_NEXT_ALL,wxLIST_STATE_FOCUSED);
    switch(id)
    {
    case MENU_CMD_ADD:
    {
        DlgAddNewCmd* dlg=new DlgAddNewCmd(NULL);
        if (dlg->ShowModal() == wxID_OK)
            ctrl->ReLoadCmds();
        dlg->Destroy();
    }
    break;
    case MENU_CMD_EDIT:
        if (item == -1)
            break;
        {
            DlgAddNewCmd* dlg = new DlgAddNewCmd(MENU_CMD_EDIT);
//				dlg->flags = MENU_CMD_EDIT;
            dlg->SetCmdID(ctrl->GetItemText(item,CMDLIST_COL_ID));
            dlg->cmdName->SetValue(ctrl->GetItemText(item,CMDLIST_COL_NAME));
            dlg->cmdDesc->SetValue(ctrl->GetItemText(item,CMDLIST_COL_DESC));
            dlg->cmdKey->SetValue(ctrl->GetItemText(item,CMDLIST_COL_KEY));
            dlg->cmdLine->SetValue(ctrl->GetItemText(item,CMDLIST_COL_CMD));
            if (dlg->ShowModal() == wxID_OK)
                ctrl->ReLoadCmds();
            dlg->Destroy();
        }
        break;
    case MENU_CMD_DEL:
        if (item == -1)
            break;
        if (ctrl->GetSelectedItemCount() == 1)
        {
            if (wxMessageBox(wxString::Format("真的要删除该命令吗?\n名称:%s\n命令行:%s",ctrl->GetItemText(item,CMDLIST_COL_NAME),ctrl->GetItemText(item,CMDLIST_COL_CMD))	,"删除确认",wxYES_NO | wxICON_WARNING) != wxYES)
                break;
            if (cmdListCtrl::onDelete(ctrl->GetItemText(item)))
                ctrl->DeleteItem(item);
            break;
        }
        if (wxMessageBox(wxString::Format("真的要删除所选择的[%d]个命令吗?",ctrl->GetSelectedItemCount()),"删除确认",wxYES_NO | wxICON_WARNING) == wxYES)
        {
            wxArrayLong sel;
            for(item = -1;;)
            {
                item = ctrl->GetNextItem(item,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
                if (item == -1)
                    break;
                sel.Add(item);
            }
            for(item = sel.size() - 1; item >= 0; --item)
            {
                if (cmdListCtrl::onDelete(ctrl->GetItemText(sel[item])))
                    ctrl->DeleteItem(sel[item]);
            }
            sel.Clear();
        }
        break;
    case ID_TOOL_CHECK:
        wxMessageBox("命令检测,尚未完成");
        break;
    }
//	ctrl->Refresh();
}
Example #2
0
void cmdListCtrl::RunMenu(const int id,cmdListCtrl* ctrl)
{
	int item = ctrl->GetNextItem(-1,wxLIST_NEXT_ALL,wxLIST_STATE_FOCUSED);
	long cmdID = 0;
	if (item >= 0)
		ctrl->GetItemText(item,CMDLIST_COL_ID).ToLong(&cmdID);

	switch(id)
	{
		case ID_TOOL_ADD:
			{
				DlgAddNewCmd* dlg=new DlgAddNewCmd();
				if (dlg->ShowModal() == wxID_OK)
					ctrl->ReLoadCmds();
				dlg->Destroy();
			}
			break;
		case ID_TOOL_ADD_FOLDER:
			{
				DlgAddNewDir* dlg=new DlgAddNewDir(NULL);
				if (dlg->ShowModal() == wxID_OK)
					ctrl->ReLoadCmds();
				dlg->Destroy();
			}
			break;
		case ID_TOOL_EDIT:
			if (item == -1)//没有当前激活条目
				break;
			if (cmdID >= 0)//cmdID >=0 命令
			{
				DlgAddNewCmd* dlg = new DlgAddNewCmd(ctrl->GetItemText(item,CMDLIST_COL_ID));
	//			dlg->flags = MENU_CMD_EDIT;
				//dlg->SetCmdID(ctrl->GetItemText(item,CMDLIST_COL_ID));
				//dlg->cmdName->SetValue(ctrl->GetItemText(item,CMDLIST_COL_NAME));
				//dlg->cmdDesc->SetValue(ctrl->GetItemText(item,CMDLIST_COL_DESC));
				//dlg->cmdKey->SetValue(ctrl->GetItemText(item,CMDLIST_COL_KEY));
				//dlg->cmdLine->SetValue(ctrl->GetItemText(item,CMDLIST_COL_CMD));
				//dlg->cmdPath->SetValue(ctrl->GetItemText(item,CMDLIST_COL_WORKDIR));
				if (dlg->ShowModal() == wxID_OK)
					ctrl->ReLoadCmds();
				dlg->Destroy();
			}
			else
			{
				DlgAddNewDir* dlg = new DlgAddNewDir(NULL);
				dlg->DirId = ~cmdID;
				dlg->SetMode(ADDDIR_FLAG_EDIT);
				dlg->dirInclude->SetValue(ctrl->GetItemText(item,DIRLIST_COL_INCLUDE));
				dlg->dirExclude->SetValue(ctrl->GetItemText(item,DIRLIST_COL_EXCLUDE));
				wxString name = ctrl->GetItemText(item,DIRLIST_COL_PATH);
				name.Replace("|","\n");
				dlg->dirName->SetValue(name);
				dlg->dirSub->SetValue(ctrl->GetItemText(item,DIRLIST_COL_SUB));
				if (dlg->ShowModal() == wxID_OK)
					ctrl->ReLoadCmds();
				dlg->Destroy();
			}
			break;
		case ID_TOOL_DELETE:
			if (ctrl->GetSelectedItemCount() == 0)
				break;
			if (ctrl->GetSelectedItemCount() == 1)
			{
				if (wxMessageBox(wxString::Format("真的要删除该命令吗?\n名称:%s\n命令行:%s",ctrl->GetItemText(item,CMDLIST_COL_NAME),ctrl->GetItemText(item,CMDLIST_COL_CMD))	,"删除确认",wxYES_NO | wxICON_WARNING) != wxYES)
					break;
				if (cmdListCtrl::onDelete(ctrl->GetItemText(item,CMDLIST_COL_ID)))
					ctrl->DeleteItem(item);
				break;
			}
			if (wxMessageBox(wxString::Format("真的要删除所选择的[%d]个命令吗?",ctrl->GetSelectedItemCount()),"删除确认",wxYES_NO | wxICON_WARNING) == wxYES)
			{
				wxArrayLong sel;
				for(item = -1;;)
				{
					item = ctrl->GetNextItem(item,wxLIST_NEXT_ALL,wxLIST_STATE_SELECTED);
					if (item == -1)
						break;
					sel.Add(item);
				}
				for(item = sel.size() - 1;item >= 0;--item)
				{
					if (cmdListCtrl::onDelete(ctrl->GetItemText(sel[item],CMDLIST_COL_ID)))
						ctrl->DeleteItem(sel[item]);
				}
				sel.Clear();
			}
			break;
		case ID_TOOL_IMPORT:
			{
				wxString selFile = wxFileSelector("从ALTRun配置文件ShortCutList.txt导入命令",wxEmptyString,"ShortCutList.txt",wxEmptyString,"ShortCutList.txt",0,NULL);
				if (selFile.empty())
					return;
				if (importCMD(selFile)>0)
					ctrl->ReLoadCmds();
			}
			break;
		case ID_TOOL_CHECK:
			{
				if (MessageBox(NULL,_T("校验会检测无效命令(有可能没有办法全部检测出来),并用标记这些条目,你可以直接删除或修改,如果命令比较多可能需要比较长的时间,继续吗?"),_T("提示"),MB_YESNO|MB_TOPMOST|MB_ICONQUESTION) != IDYES)
					break;
				size_t count = ctrl->GetItemCount();
				size_t n = 0;
				for(size_t i = 0;i<count;++i)
				{
					long id;
					ctrl->GetItemText(i,CMDLIST_COL_ID).ToLong(&id);
					if (id < 0 )//ID < 0 是自动扫描目录不检测
						break;
					wxString test(ParseCmd(ctrl->GetItemText(i,CMDLIST_COL_CMD)));
					long state = test.empty()?wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED:0;
					ctrl->SetItemState(i,state,wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED);
					if (state)
					{
						ctrl->SetItemBackgroundColour(i,wxColour(0x6300f8));
						++n;
					}
				}
				if (n)
					wxMessageBox(wxString::Format("列表中有%d个条目[已选定]的命令找不到,可能是无效命令,请检查或直接删除",n));
				else
					wxMessageBox("校验完成,没有发现无效命令");
			}
			break;
	}
//	ctrl->Refresh();
}