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

📄 c02ideview.cpp

📁 类似vc的集成开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	CCrystalTextView* m_pexpandview=NULL;	
	m_pexpandview=(CCrystalTextView*)childf->GetActiveView();
	//当前编辑控件的行数
	int linenum=m_pexpandview->GetLineCount();
	//行索引大于等于编辑控件的总行数
	if(findstringcurhang>=linenum)    
		   return 0;
	//保存 搜索字符串的列索引
	int pos=-1;    
	//保存 搜索字符串的行索引
	int curline=findstringcurhang;
	//保存 搜索字符串的列索引
	int n_pos=-1;
	//获取当前行字符数	
	int n_linelength=m_pexpandview->GetLineActualLength(curline);
	if( n_outbox==1&&(curline==linenum-1)&&findstringcurlie>n_linelength-strnextfind.GetLength()+1)
			   AfxMessageBox("have search to the end");
    //保存当前行的字符串        
    CString strcurline;
    strcurline= _T("");	
	//初始化一个保存查询结果的变量
	SearchInf * m_pfinditem=NULL;
	m_pfinditem=new SearchInf;
	//行长度
	 int	nLen=0;
	 //当前行长度小于搜索字符串的长度,则此行搜索结果返回没有搜索到
	if(n_linelength<=findstring.GetLength())
		n_pos=-1;
	//当前行长度大于搜索字符串的长度
	else
	{
		//获得当前行字符的字节数
		if(curline > linenum - 1 || curline < 0) 
			return 0;
		int	nTemp = m_pexpandview->GetLineLength(curline) * sizeof(WCHAR);
		if(nTemp<=1) 
		{
			strcurline=_T(" ");	
		}
		nTemp += 4 * sizeof(WCHAR); //尽量多留点空	
//		int nLen = myeditctrl.GetLine(i, strline.GetBuffer(nTemp), nTemp);  		
	
//		strline.ReleaseBuffer(); 
//	BOOL bRealReturn;
		strcurline=m_pexpandview->GetLineChars(curline);
//					if(nLen > strline.GetLength())
		nLen = m_pexpandview->GetLineActualLength(curline);
		if(nLen>=1 && strcurline[nLen-1]==0xd ) 
		{
			 strcurline = strcurline.Left(--nLen);  
//		bRealReturn=TRUE;
		}
		else  
		{
				strcurline = strcurline.Left(nLen);  
//		bRealReturn=FALSE;
		}

//当前行中搜索起始位置
       int liejia=findstringcurlie+1;
	   CString strte=_T("");
//去掉搜索过的字符串	   
	   strte = strcurline.Mid(liejia); 
	   if(strte.GetLength()<findstring.GetLength())
	   {
		   n_pos=-1;	   
		   pos=0;
	   }
		   else
	   {
	   //查找子串
           n_pos = strte.Find(findstring);	   
	   //计算行起始位置
         pos=n_pos+liejia;
	   //更新全局变量
       findstringcurlie=pos;
	   }
	  
	}
	  int i=0;
	  i=curline;
	  //更新全局变量
	   findstringcurhang=i;
	   findstringcurlie=pos;

	   //从下一行开始搜索的行索引
	  int beginline=curline+1;

	  int nTemp =0;
	  if(n_pos == -1)
	  {
		  //搜索当前视图的剩余行
	     for(i= beginline;i<=linenum-1;i++)

		 {
			 if(i >linenum - 1 || i < 0) 
				 return 0;
			 int	nTemp = m_pexpandview->GetLineLength(i) * sizeof(WCHAR);
			 if(nTemp<=1) 
			 {
				 strcurline=_T(" ");			 
				 continue ;
			 }	
			 nTemp += 4 * sizeof(WCHAR); //尽量多留点空
//					int nLen = myeditctrl.GetLine(i, strline.GetBuffer(nTemp), nTemp);  		
	
//					strline.ReleaseBuffer(); 
//	BOOL bRealReturn;		
			 strcurline=m_pexpandview->GetLineChars(i);
//					if(nLen > strline.GetLength())
			 nLen = m_pexpandview->GetLineActualLength(i);
	
			 if(nLen>=1 && strcurline[nLen-1]==0xd ) 
			 {
				 strcurline = strcurline.Left(--nLen);  
//		bRealReturn=TRUE;
			 }	
			 else  
			 {		
				strcurline = strcurline.Left(nLen);  
//		bRealReturn=FALSE;	
			 }
			//将多取的字符串去掉
//			strLine=strLine.Left(n_linelength);
			//如果行字符串的长度不是0
			if(strcurline .GetLength()!=0)
			{
			//查找子串
		     n_pos = strcurline.Find(findstring);	
			}
			//保存当前行的字符串 ,在函数后面需要保存查询结果时使用
 //			str_line=strcurline;
			 if(n_pos != -1)
			 {
				 //更新全局变量
				  findstringcurhang=i;
				  findstringcurlie=n_pos;
				  pos=n_pos;
				 break;		 
			 }
//			 if((n_pos != -1)&&(i==linenum-1))
//				 i++;
            nTemp=0;
		 }	

		 n_pos=-1;
	  }
	  //搜索不成功  
	  if(i>=linenum)
	   {
		  //不过需要显示对话框
		  if(n_outbox==1)
			   AfxMessageBox("have search to the end");
		 //更新全局变量
		   findstringcurhang=linenum;
		
		   findstringcurlie=0;//myeditctrl.LineLength(linenum);	
		   m_pexpandview->m_bLastSearch=FALSE;
		   // 释放指针		
		   delete m_pfinditem;
		   return 0;
	   }
	  //搜索成功
		else
	   {
		//显示搜索结果的字符串
		CString str_output=_T("");
		//当前目录名
		str_output=GetCurrentDirectory();
		//获得当前文件名
		CString str_filefind=_T("");
	    childf->GetWindowText(str_filefind);
	    str_output=str_output+"\\"+str_filefind;
	    //将当前行转化为字符串
	    CString n_hanglie;
	    n_hanglie.Format("%d",findstringcurhang);	
	    str_output=str_output+"("+n_hanglie;
	    //将当前行转化为字符串
	    n_hanglie.Format("%d",findstringcurlie);
	    str_output=str_output+","+n_hanglie+"):";
	    //将当前行字符串加入显示字符串
	    str_output=str_output+strcurline;
        //将当前窗口指针写入搜索结果
    	m_pfinditem->m_pchildf=childf;
	    //将字符串位置信息写入搜索结果
        int n_line=findstringcurhang;
		m_pfinditem->n_rowno=findstringcurlie;
     	m_pfinditem->n_lineno=n_line;
//		strLine="";
		strcurline="";
		//将文件名和字符串信息写入搜索结果	
		m_pfinditem->str_filenm=str_filefind;
		m_pfinditem->str_linetext=str_output;
		a_searchinfo.Add((CObject*)m_pfinditem);
       //设置当前选择
//	m_pexpandview->ScrollToLine(findstringcurlie);
	
		CPoint pselstart,pselend;   
		pselstart.y=findstringcurhang;    
		pselstart.x=findstringcurlie;	
		pselend.y=findstringcurhang;   
		pselend.x=findstringcurlie+findstring.GetLength();
		m_pexpandview->SetSelection(pselstart,pselend);
	   //激活子窗口
    	childf->MDIActivate();
		//将子窗口设置为最前
       childf->BringWindowToTop();
       // 将子窗口设置为焦点
       childf->SetFocus();
        return 1;
	   }


     
		
}

CString & CC02IDEView::GetCurrentDirectory()
{
    static CString strCurrentPath;

	strCurrentPath.Empty ();
	int nBytes = ::GetCurrentDirectory (0, NULL);
	char *szDir = new char [nBytes + 1];
	::GetCurrentDirectory (nBytes + 1, szDir);
	strCurrentPath = szDir;
//	delete [] szDir;
	return (strCurrentPath);
}

void CC02IDEView::OnSearchOpenedfile() 
{
	// TODO: Add your command handler code here
	

	a_searchinfo.RemoveAll();


	CFindAllOpen * myfinddlg;
//	 myfinddlg.DoModal();
 
	myfinddlg=new CFindAllOpen;
  
	myfinddlg->Create(IDD_DIALOG_FINDALLFILE);


  
	myfinddlg->ShowWindow(SW_SHOW);

}


void CC02IDEView::InsertFunc(CString mystring)
{

    //函数声明的字符串 
	CString insertshengming=mystring+_T(";")+_T("\r\n");
    //插入函数声明位置的行索引
    int shengmingline=-1;
    //要添加函数的窗口索引
   int n_addtof=0;
   n_addtof=functionadd->n_addfileno;
   //声明子窗口指针
   CMDIChildWnd *m_paddchildf;
   m_paddchildf=fileitemarray[n_addtof].m_pchildf;
   //当前活动子窗口
   m_paddchildf->MDIActivate(); 
   //设置为最前窗口
   m_paddchildf->BringWindowToTop();
   //设置为焦点
   m_paddchildf->SetFocus();	
    //取当前项目信息
	struct ProjectList * curgotopro=NULL;         
	curgotopro=new ProjectList;
	curgotopro=(ProjectList *)projectinfo.GetAt(0);	
	//项目中的文件总数
	int n_filenum=curgotopro->proinfstru.GetSize();
	//取要操作的文件信息
    FileList * m_pgotofile=NULL;
	m_pgotofile=new FileList;
	m_pgotofile=(FileList * )curgotopro->proinfstru.GetAt(n_addtof);
	//文件中的函数个数
	int n_funcnum=	m_pgotofile->oa_funcinfstru.GetSize();
	//定义一个函数信息指针
	FuncStruct* m_ptestfunc=NULL;
	m_ptestfunc=new FuncStruct;
	//访问每一个函数
	for(int j=0;j<=n_funcnum-1;j++)
		{
      	//取得第j个函数
		m_ptestfunc=(	FuncStruct*)m_pgotofile->oa_funcinfstru.GetAt(j);
		//获得所有函数声明的最大行索引
	    if(shengmingline<m_ptestfunc->n_shengming)
		   shengmingline=m_ptestfunc->n_shengming;
		}
    //获得编辑视图    
	CCrystalTextView* m_paddfuncview=NULL;	 
	m_paddfuncview=(CCrystalTextView*)m_paddchildf->GetActiveView();
    CCrystalEditView* m_paddeditview=NULL; 
	m_paddeditview=(CCrystalEditView*)m_paddchildf->GetActiveView();
    ASSERT(m_paddfuncview!=NULL);
	// 获取最后一个声明行的下一行索引 
	shengmingline++;
	//如果该文件没有任何函数声明
	if(shengmingline<=0)  
	{
		//行字符串
		CString strline=_T("");
		//编辑控件的总行数
		int n_linecal= m_paddfuncview->GetLineCount();
		//搜索每一行
		for(int ni=0;ni<=n_linecal-1;ni++)
		{
			//第ni行的首字符索引
			if(ni > n_linecal - 1 || ni < 0) 
						return ;
					int	nTemp = m_paddfuncview->GetLineLength(ni) * sizeof(WCHAR);
					if(nTemp<=1) 
					{
						strline=_T(" ");
						continue ;
					}
					nTemp += 4 * sizeof(WCHAR); //尽量多留点空
//					int nLen = myeditctrl.GetLine(i, strline.GetBuffer(nTemp), nTemp);  		
	
//					strline.ReleaseBuffer(); 
//	BOOL bRealReturn;
					strline=m_paddfuncview->GetLineChars(ni);
//					if(nLen > strline.GetLength())
		
					int	nLen = m_paddfuncview->GetLineActualLength(ni);
	
					if(nLen>=1 && strline[nLen-1]==0xd ) {
		
						strline = strline.Left(--nLen);  
//		bRealReturn=TRUE;
					}
					else 
					{
						strline = strline.Left(nLen);  
//		bRealReturn=FALSE;
					}
					if(nLen<3)
				     	continue ;
		
					//如果查找成功
			
					if(strline.Find(_T("main"))!=-1)
					{
					shengmingline=ni;
					break;
			
					}
            //行长度小于3,取下一行
			if(nLen<3)
				  	continue ;
		}	
	}
   
	//设置当前选择
	CPoint pt_sel;  
	pt_sel.x=0;  
	pt_sel.y=shengmingline;  
	m_paddfuncview->SetCursorPos(pt_sel); 
	CPoint ptCursorPos; 
	ptCursorPos = m_paddfuncview->GetCursorPos();
	int x,y;
	m_paddfuncview->m_pTextBuffer->InsertText(m_paddfuncview, ptCursorPos.y, ptCursorPos.x, insertshengming, y, x, CE_ACTION_TYPING); //	[JRT]
	ptCursorPos.x = x;
	ptCursorPos.y = y;

	m_paddfuncview->SetSelection(ptCursorPos, ptCursorPos);
	m_paddfuncview->SetAnchor(ptCursorPos);
	m_paddfuncview->SetCursorPos(ptCursorPos);
	m_paddfuncview->EnsureVisible(ptCursorPos);
   //获得编辑控件总行数
   int linecal=  m_paddfuncview->GetLineCount();
   //将光标放在编辑控件的末尾
   
   pt_sel.y=linecal-1;
   pt_sel.x=m_paddfuncview->GetLineLength(linecal-1);
   m_paddfuncview->SetCursorPos( pt_sel);
   //设置插入字符串
   CString insertfuncti=_T("\r\n")+mystring+_T("\r\n")+_T("{")+_T("\r\n")+_T("}");
   //插入字符串
//  CPoint ptCursorPos;
	ptCursorPos = m_paddfuncview->GetCursorPos();
//	int x,y;
	m_paddfuncview->m_pTextBuffer->InsertText(m_paddfuncview, ptCursorPos.y, ptCursorPos.x, insertfuncti, y, x, CE_ACTION_TYPING); //	[JRT]
	ptCursorPos.x = x;
	ptCursorPos.y = y;

	m_paddfuncview->SetSelection(ptCursorPos, ptCursorPos);
	m_paddfuncview->SetAnchor(ptCursorPos);
	m_paddfuncview->SetCursorPos(ptCursorPos);
	m_paddfuncview->EnsureVisible(ptCursorPos);
   //获得主窗口指针
   CMainFrame *nowmainframe=(CMainFrame *) (AfxGetApp()->m_pMainWnd);
   //重新获得所有文件的函数信息

   CDocument * p_activedoc=NULL;
   p_activedoc=m_paddchildf->GetActiveDocument();
   if(p_activedoc==NULL)
	  return;
   CString str_dirfull=_T("");
   str_dirfull=p_activedoc->GetPathName();
   p_activedoc->OnSaveDocument(str_dirfull);

   CompileCurFile();
   nowmainframe->ExpandAllFile();
}
int CC02IDEView::DeleteFunction(int n_delfile,int n_selfunc)
{

	//函数定义行索引初始化
	int n_defineline=0;
	 //目标函数的下一个函数定义行索引初始化
	int n_nextfuncdefineline=0;
	//函数声明行索引初始化
	int n_declareline=0;
	//要操作的文件索引   
	int n_delfileno=n_delfile;
	 //要操作的窗口指针  	

⌨️ 快捷键说明

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