⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commands.cpp

📁 TabBars的开源源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	return S_OK;
}

// Debugger event

HRESULT CCommands::XDebuggerEvents::BreakpointHit(IDispatch* pBreakpoint)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	return S_OK;
}


/////////////////////////////////////////////////////////////////////////////
// CCommands methods
CString CCommands::GetActiveDocumentName() const
{
  CString cStr;

  cStr.Empty();

	CComPtr<IDispatch> pActiveDocument;
	m_pApplication->get_ActiveDocument(&pActiveDocument);
	if (!pActiveDocument)
	{
		return cStr;
	}

	CComQIPtr<IGenericDocument, &IID_IGenericDocument> pDoc(pActiveDocument);
	CComBSTR bStr;
	pDoc->get_FullName(&bStr);
	cStr = bStr;

	return cStr;
}

/*********************************************************************
 * Function Declare : CCommands::DoHeaderFlip
 * Explain : 当前文件如果是.h文件就将其对应的.cpp文件打开,如果是.cpp文件就打开相应的.h文件。如果不在相同目录就从逐个查找搜索路径,寻找对应的文件。
 * Parameters : 
 * CString cFullName -- 当前文件名
 * Return : 
 * void  -- 
 * Author : Orbit 
 * Time : 2002-03-12 16:28:20 
*********************************************************************/
void CCommands::DoHeaderFlip(CString cFullName) 
{
  enum { none = 0, header, source } FileType = none;

  TCHAR       cDrive[_MAX_DRIVE], cDir[_MAX_DIR];
  TCHAR       cFName[_MAX_FNAME], cExt[_MAX_EXT];
  CComBSTR    bStr;

  if (cFullName.GetLength() == 0)
    return;

  _splitpath(cFullName, cDrive, cDir, cFName, cExt);
  CString strExts;
	strExts.Format(_T("%s%s"),cDrive,cDir);
	g_strAFlipPath.SetAt(0,strExts);
	CStringArray	strAExts;
	_tcslwr(cExt);
	if(_tcsstr(g_szHeadType,cExt) != NULL)
	{
		FileType = header;
		strExts = g_szCPPType;
	}
  if (FileType == none)
  {
		if(_tcsstr(g_szCPPType,cExt) != NULL)
		{
			FileType = source;
			strExts = g_szHeadType;
		}
  }
	
	strAExts.RemoveAll();
	strExts += _T(";");
	int length = strExts.GetLength();
	int i = 0,k = 0;
	TCHAR szext[16];
	while(i < length)
	{
		if(strExts[i] != _T(';'))
		{
			szext[k++] = strExts[i];
		}
		else
		{
			szext[k] = _T('\0');
			strAExts.Add(szext);
			k = 0;
		}
		i++;
	}
    // not a header or a source...
  if (FileType == none)
  {
    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));
    AfxMessageBox(IDS_HEADERERROR, MB_OK | MB_ICONINFORMATION);
    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
    return;
  }

  CComPtr<IDispatch> pDisp;
  CComQIPtr<IGenericWindow, &IID_IGenericWindow> pActiveWindow;
  // remember which window was active
  m_pApplication->get_ActiveWindow(&pDisp);
  pActiveWindow = pDisp;
  pDisp = NULL;
  // if Workspace Utils. didn't flip for us, do it ourselves
  CComQIPtr<IDocuments, &IID_IDocuments> pDocuments;
//  CComVariant sAuto("Auto"), vFalse(VARIANT_FALSE);

  m_pApplication->get_Documents(&pDisp);
  pDocuments = pDisp;
  pDisp = NULL;

  i = 0;
	BOOL bOpen = FALSE;
	while(i < strAExts.GetSize() && !bOpen)
  {           
		k = 0;
		while(k < g_strAFlipPath.GetSize() && !bOpen)
		{
			cFullName.Format(_T("%s%s%s"),g_strAFlipPath[k],cFName,strAExts[i]);
			bStr = cFullName;
		  CComVariant sAuto("Auto"), vFalse(VARIANT_FALSE);
			pDocuments->Open(bStr, sAuto, vFalse, &pDisp);
			if (pDisp != NULL)
			{
				bOpen = TRUE;
			}
			k++;
		}
		i++;
  }

	strAExts.RemoveAll();

	if (pDisp == NULL)  // none found?
	{
		// reactivate the window that was active before
		HWND hWnd = GetHWND(pActiveWindow);
		::PostMessage(::GetParent(hWnd), WM_MDIACTIVATE,(WPARAM)hWnd, 0);
	}
}

void CCommands::DoOpenAsText(CString cFullName)
{
	if (cFullName.GetLength() == 0)
	{
		return;
	}

	CComPtr<IDispatch> pDisp;
	CComQIPtr<IDocuments, &IID_IDocuments> pDocuments;
	CComQIPtr<IGenericDocument, &IID_IGenericDocument> pDoc;
	CComBSTR bStr(cFullName);

	m_pApplication->get_Documents(&pDisp);
	pDocuments = pDisp;
	pDisp = NULL;

    // if this is a resouce, VC will automatically close it for us (and
    // will even display a nice little message box... :).  If not, we have
    // to close the current document before reopening as text...
	bool bIsResource = (cFullName.Find(_T(".rc")) >= 0);
	if (!bIsResource)
	{
		pDocuments->Item(CComVariant(cFullName), &pDisp);
		pDoc = pDisp;
		pDisp = NULL;

		DsSaveStatus iSaved;
		pDoc->Close(CComVariant((int)dsSaveChangesPrompt), &iSaved);
	}

	pDocuments->Open(bStr, CComVariant("Text"),CComVariant(VARIANT_FALSE), &pDisp);

}

void CCommands::FlashWindows(CComQIPtr<IWindows, &IID_IWindows>& pWindows, 
    int cWindows, int iWindow) const
{
	CComPtr<IDispatch>                              pDisp;
	CComQIPtr<IGenericWindow, &IID_IGenericWindow>  pWindow;
	CComVariant                                     index = iWindow + 1;
    
	pWindows->Item(index, &pDisp);
	pWindow = pDisp;
	pDisp = NULL;

	if (iWindow < (cWindows - 1))
	{
		FlashWindows(pWindows, cWindows, iWindow + 1);
	}

	pWindow->put_Active(VARIANT_TRUE);
}

void CCommands::DoSetCurrDir(CString cFullName) 
{
  CComBSTR                            bStr;
  int                                 nPos;
  long                                cWindows;
  CComPtr<IDispatch>                  pDisp;
  CComQIPtr<IWindows, &IID_IWindows>  pWindows;

  if ((nPos = cFullName.ReverseFind('\\')) < 0)
  {
    return;
  }

  cFullName = cFullName.Left(nPos);
  bStr = cFullName;
  m_pApplication->put_CurrentDirectory(bStr);

  m_pApplication->get_Windows(&pDisp);
  pWindows = pDisp;
  pDisp = NULL;
  
  pWindows->get_Count(&cWindows);

  if (cWindows > 1)
  {
		// update window titles by activating each window in turn
		pGlobalTabs->m_iLockUpdates += (2 * (cWindows - 1));
		FlashWindows(pWindows, cWindows, 0);
  }
  else
  {
      // as far as I can tell there's nothing to do if there's only
      // one open window :(


/*      Begin: Experimental stuff...


      CComQIPtr<IGenericWindow, &IID_IGenericWindow>  pActiveWindow;

      m_pApplication->get_ActiveWindow(&pDisp);
      pActiveWindow = pDisp;
      pDisp = NULL;

      pActiveWindow->put_Active(VARIANT_FALSE);
      pActiveWindow->put_Active(VARIANT_TRUE);

      
      End: Experimental stuff
*/        
  }
}

BOOL CCommands::PreaseFunctionDeclare(const CString & strFunction,CString & strFuncName,CStringArray & para,CString & strRetType)
{
	para.RemoveAll();
//Function declare must include '('	
	int idxLeft = strFunction.Find(_T('('),0);
	int idxRight = strFunction.Find(_T(')'),0);
	if(idxLeft < 0 || idxRight < 0)
		return FALSE;

	strFuncName = strFunction.Left(idxLeft);
	CString paralist = strFunction.Mid(idxLeft + 1,idxRight - idxLeft - 1);
	
	int idxBlank = strFuncName.ReverseFind(_T(' '));
	if(idxBlank < 0)
		return FALSE;

	if(strFuncName[idxBlank + 1] == _T('*') || strFuncName[idxBlank + 1] == _T('&'))
		idxBlank++;

	strRetType = strFuncName.Left(idxBlank + 1);
	strFuncName = strFuncName.Mid(idxBlank + 1);

	BOOL bIsFunction = TRUE;
	if(paralist.GetLength() > 0)//Parameter list not empty
	{
		paralist += _T(",");//set stop mark
		int idx = paralist.Find(_T(','),0);
		while(idx >= 0)
		{
			CString strPara = paralist.Left(idx);
			if(strPara.Find(_T(' '),0) < 0)
			{
				bIsFunction = FALSE;//declare parameter must include space 
				para.RemoveAll();
				break;
			}
			para.Add(strPara);
			paralist = paralist.Mid(idx + 1);
			idx = paralist.Find(_T(','),0);
		}
	}

	return bIsFunction;
}

STDMETHODIMP CCommands::OSHeaderFlip()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
  DoHeaderFlip(GetActiveDocumentName());
	return S_OK;
}

STDMETHODIMP CCommands::OSSetCurrDir()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
  DoSetCurrDir(GetActiveDocumentName());
	return S_OK;
}

STDMETHODIMP CCommands::OSOpenAsText()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
  DoOpenAsText(GetActiveDocumentName());
	return S_OK;
}

STDMETHODIMP CCommands::OSOptions()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())
#ifdef _VER_CHINESE
	COptionSheet dlg(_T("设置选项"));
#else
	COptionSheet dlg(_T("Option"));
#endif
  dlg.DoModal();
	return S_OK;
}

STDMETHODIMP CCommands::OSFuncDesc()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	CComPtr<IDispatch> pDispDoc;
	CComQIPtr<ITextDocument, &IID_ITextDocument> pDoc;

	m_pApplication->get_ActiveDocument(&pDispDoc);
	pDoc = pDispDoc;
	pDispDoc = NULL;

	if(pDoc)
	{
		CComPtr<IDispatch> pDispSel;
		CComQIPtr<ITextSelection, &IID_ITextSelection> pSel;
		CComBSTR bstr;
		CString strText;
		int nSelectLength = 0;
		HRESULT hr;

		pDoc->get_Selection(&pDispSel);
		pSel = pDispSel;
		pDispSel = NULL;
		hr = pSel->get_Text(&bstr);
		if(SUCCEEDED(hr))
		{
			nSelectLength = bstr.Length();
			if(nSelectLength > 0)
			{
				strText = bstr;
				strText.Replace(_T("\r\n"),lpszNull);
				strText.Replace(_T("\t"),_T(" "));
				while(TRUE)
				{
					int idx = strText.Find(_T("  "),0);
					if(idx < 0)
						break;
					strText.Replace(_T("  "),_T(" "));
				}
				CString strFuncName,strRetType;
				CStringArray strAPapaList;
				if(PreaseFunctionDeclare(strText,strFuncName,strAPapaList,strRetType))
				{
					CFuncParaDlg dlg;
					dlg.SetPara(strFuncName,strAPapaList,strRetType);
					if(dlg.DoModal() == IDOK)
					{
						CString strTmp;
						strText = _T("/*********************************************************************\r\n");
						strTmp.Format(_T(" * Function Declare : %s\r\n * Explain : %s\r\n * Parameters : \r\n"),strFuncName,dlg.m_strFuncDesc);
						strText += strTmp;
						for(int i = 0; i < strAPapaList.GetSize(); i++)
						{
							strTmp.Format(_T(" * %s -- %s\r\n"),strAPapaList[i],dlg.m_strARtn[i]);
							strText += strTmp;
						}
						strText += _T(" * Return : \r\n");
						strTmp.Format(_T(" * %s -- %s\r\n"),strRetType,dlg.m_strARtn[i]);
						strText += strTmp;
						strTmp.Format(_T(" * Author : %s \r\n"),dlg.m_strUserName);
						strText += strTmp;
						SYSTEMTIME st;
						::GetLocalTime(&st);
						strTmp.Format(_T(" * Time : %04d-%02d-%02d %02d:%02d:%02d \r\n"),st.wYear,st.wMonth,
							st.wDay,st.wHour,st.wMinute,st.wSecond);
						strText += strTmp;
						strText += _T("*********************************************************************/\r\n");
						strTmp = bstr;
						strText += strTmp;
						bstr = strText;
						pSel->put_Text(bstr);
						dlg.m_strARtn.RemoveAll();
					}
				}
				else
				{
					strText.LoadString(IDS_FUNC_DECLARE_ERROR);
					AfxMessageBox(strText);
				}

				strAPapaList.RemoveAll();
			}
			else
			{
				strText.LoadString(IDS_FUNC_DECLARE_ERROR);
				AfxMessageBox(strText);
			}
		}
	}
	return S_OK;
}

STDMETHODIMP CCommands::OSBlockRemark()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())

	CComPtr<IDispatch> pDispDoc;
	CComQIPtr<ITextDocument, &IID_ITextDocument> pDoc;

	m_pApplication->get_ActiveDocument(&pDispDoc);
	pDoc = pDispDoc;
	pDispDoc = NULL;

	if(pDoc)
	{
		CComPtr<IDispatch> pDispSel;
		CComQIPtr<ITextSelection, &IID_ITextSelection> pSel;
		CComBSTR bstr;
		CString strText,strTmp;
		int nSelectLength = 0;
		HRESULT hr;

		pDoc->get_Selection(&pDispSel);
		pSel = pDispSel;
		pDispSel = NULL;
		hr = pSel->get_Text(&bstr);
		if(SUCCEEDED(hr))
		{
			nSelectLength = bstr.Length();
			if(nSelectLength > 0)
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -