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

📄 filewindowproject.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	} else { // not recognized item
		is.getline(szText, 4096, '>'); // skip attributes
		is >> szText; // get next tocken
	}

	return TRUE;
}

BOOL CFileWindow::SaveWorkspaceItem(ostream & os, INT nLevel, CDocument * pDoc)
{
	CCedtDoc * pCedtDoc = (CCedtDoc *)pDoc;
	if( pCedtDoc->IsNewFileNotSaved() ) return TRUE;

	CString szContents, szIndent('\t', nLevel);

	if( pCedtDoc->IsRemoteFile() ) {
		INT nAccount = pCedtDoc->GetFtpAccountNumber();
		CString szPath = pCedtDoc->GetRemotePathName();
		LONG nFileSize = pCedtDoc->GetFileSize();

		CCedtView * pView = (CCedtView *)pCedtDoc->GetFirstView();
		INT nLineNum = pView->GetCurrentLineNumber();

		CChildFrame * pFrame = (CChildFrame *)pView->GetParentFrame();
		WINDOWPLACEMENT wndpl; pFrame->GetWindowPlacement( & wndpl );

		szContents.Format("<remotefile account=\"%d\" path=\"%s\" filesize=\"%d\" linenum=\"%d\" placement=\"%d:%d:%d:%d:%d:%d:%d:%d:%d:%d\" />",
			nAccount, szPath, nFileSize, nLineNum, (INT)wndpl.flags, (INT)wndpl.showCmd, 
			wndpl.ptMinPosition.x, wndpl.ptMinPosition.y, wndpl.ptMaxPosition.x, wndpl.ptMaxPosition.y,
			wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top, wndpl.rcNormalPosition.right, wndpl.rcNormalPosition.bottom);
		os << szIndent << szContents << endl;

	} else {
		CString szPath = pCedtDoc->GetPathName();

		CCedtView * pView = (CCedtView *)pCedtDoc->GetFirstView();
		INT nLineNum = pView->GetCurrentLineNumber();

		CChildFrame * pFrame = (CChildFrame *)pView->GetParentFrame();
		WINDOWPLACEMENT wndpl; pFrame->GetWindowPlacement( & wndpl );

		szContents.Format("<localfile path=\"%s\" linenum=\"%d\" placement=\"%d:%d:%d:%d:%d:%d:%d:%d:%d:%d\" />", 
			szPath, nLineNum, (INT)wndpl.flags, (INT)wndpl.showCmd, 
			wndpl.ptMinPosition.x, wndpl.ptMinPosition.y, wndpl.ptMaxPosition.x, wndpl.ptMaxPosition.y,
			wndpl.rcNormalPosition.left, wndpl.rcNormalPosition.top, wndpl.rcNormalPosition.right, wndpl.rcNormalPosition.bottom);
		os << szIndent << szContents << endl;
	}

	return TRUE;
}

BOOL CFileWindow::LoadWorkspaceItem(istream & is, TCHAR szText[], CWinApp * pApp)
{
	CCedtApp * pCedtApp = (CCedtApp *)pApp;
	CMapStringToString mapAttr;

	if( ! _stricmp(szText, "<remotefile") ) {
		is.getline(szText, 4096, '>'); // get attributes
		INT nLen = strlen(szText); if( szText[nLen-1] == '/' ) szText[nLen-1] = '\0';
		if( ! ParseProjectItemAttr( szText, mapAttr ) ) return FALSE;

		CString szAccount; BOOL bLookup = mapAttr.Lookup("account", szAccount);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szPath; bLookup = mapAttr.Lookup("path", szPath);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szFileSize; bLookup = mapAttr.Lookup("filesize", szFileSize);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szLineNum; bLookup = mapAttr.Lookup("linenum", szLineNum);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szPlacement; bLookup = mapAttr.Lookup("placement", szPlacement);
		if( ! bLookup ) { szPlacement = ""; }

		WINDOWPLACEMENT * pwndpl = NULL;
		if( szPlacement.GetLength() ) {
			WINDOWPLACEMENT wndpl; wndpl.length = sizeof(wndpl);
			INT nFound = 0; pwndpl = & wndpl;

			wndpl.flags = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.showCmd = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMinPosition.x = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMinPosition.y = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMaxPosition.x = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMaxPosition.y = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.left = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.top = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.right = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.bottom = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
		}

		CDocument * pDoc = pCedtApp->OpenRemoteDocumentFile(atoi(szAccount), szPath, atol(szFileSize), atoi(szLineNum), pwndpl);
		is >> szText; // get next tocken

	} else if( ! _stricmp(szText, "<localfile") ) {
		is.getline(szText, 4096, '>'); // get attributes
		INT nLen = strlen(szText); if( szText[nLen-1] == '/' ) szText[nLen-1] = '\0';
		if( ! ParseProjectItemAttr( szText, mapAttr ) ) return FALSE;

		CString szPath; BOOL bLookup = mapAttr.Lookup("path", szPath);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szLineNum; bLookup = mapAttr.Lookup("linenum", szLineNum);
		if( ! bLookup ) { AfxMessageBox(IDS_ERR_WRONG_PRJ_FILE); return FALSE; }

		CString szPlacement; bLookup = mapAttr.Lookup("placement", szPlacement);
		if( ! bLookup ) { szPlacement = ""; }

		WINDOWPLACEMENT * pwndpl = NULL;
		if( szPlacement.GetLength() ) {
			WINDOWPLACEMENT wndpl; wndpl.length = sizeof(wndpl);
			INT nFound = 0; pwndpl = & wndpl;

			wndpl.flags = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.showCmd = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMinPosition.x = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMinPosition.y = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMaxPosition.x = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.ptMaxPosition.y = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.left = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.top = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.right = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
			wndpl.rcNormalPosition.bottom = atoi( szPlacement.Mid(nFound) ); nFound = szPlacement.Find(':', nFound) + 1;
		}

		CCedtDoc * pDoc = (CCedtDoc *)pCedtApp->OpenDocumentFile(szPath, atoi(szLineNum), pwndpl);
		is >> szText; // get next tocken

	} else { // not recognized item
		is.getline(szText, 4096, '>'); // skip attributes
		is >> szText; // get next tocken
	}

	return TRUE;
}

BOOL CFileWindow::ParseProjectItemAttr(LPCTSTR lpszText, CMapStringToString & mapAttr)
{
	TCHAR * pBeg, * pEnd = (TCHAR *)lpszText;
	CString szAttrName, szAttrValue;

	mapAttr.RemoveAll();
	while( * pEnd && isspace(* pEnd) ) pEnd++;

	while( * pEnd ) {
		pBeg = pEnd; while( * pEnd && ! isspace(* pEnd) && * pEnd != '=' ) pEnd++;
		szAttrName = CString(pBeg, pEnd-pBeg);

		while( * pEnd && isspace(* pEnd) ) pEnd++;

		if( * pEnd == '=' ) { pEnd++; } 
		else { AfxMessageBox(IDS_ERR_PARSE_PRJ_ATTRIBUTE); return FALSE; }

		while( * pEnd && isspace(* pEnd) ) pEnd++;

		if( * pEnd == '"' ) { pEnd++; } 
		else { AfxMessageBox(IDS_ERR_PARSE_PRJ_ATTRIBUTE); return FALSE; }

		pBeg = pEnd; while( * pEnd && * pEnd != '"' ) pEnd++;
		szAttrValue = CString(pBeg, pEnd-pBeg);

		if( * pEnd == '"' ) { pEnd++; } 
		else { AfxMessageBox(IDS_ERR_PARSE_PRJ_ATTRIBUTE); return FALSE; }

		mapAttr.SetAt( szAttrName, szAttrValue );
		while( * pEnd && isspace(* pEnd) ) pEnd++;
	}

	return TRUE;
}

LPPROJECTITEMINFO CFileWindow::GetProjectItemInfo(HTREEITEM hItem)
{
	if( ! hItem ) return NULL;
	return (LPPROJECTITEMINFO)m_treProjectTree.GetItemData(hItem); 
}

CString CFileWindow::GetProjectItemPathName(HTREEITEM hItem)
{
	if( ! hItem ) return "";
	LPPROJECTITEMINFO lpInfo = (LPPROJECTITEMINFO)m_treProjectTree.GetItemData(hItem); 
	return lpInfo->szPathName;
}

HTREEITEM CFileWindow::GetClickedProjectItem()
{
	CPoint point; GetCursorPos( & point ); 
	m_treProjectTree.ScreenToClient( & point );

	HTREEITEM hItem; UINT nFlags;
	hItem = m_treProjectTree.HitTest( point, & nFlags );

	if( nFlags & TVHT_ONITEM ) return hItem;
	return NULL;
}

BOOL CFileWindow::EnableAllProjectButtons(BOOL bEnable)
{
	m_btnToolbarProject.EnableButton(ID_PROJECT_NEW_CATEGORY, bEnable);
	m_btnToolbarProject.EnableButton(ID_PROJECT_ADD_FILES_TO, bEnable);
	m_btnToolbarProject.EnableButton(ID_PROJECT_ADD_ACTIVE_FILE, bEnable);
	m_btnToolbarProject.EnableButton(ID_PROJECT_ADD_OPEN_FILES, bEnable);
	m_btnToolbarProject.EnableButton(ID_PROJECT_ITEM_REMOVE, bEnable);

	return TRUE;
}

INT CALLBACK CFileWindow::CompareProjectItem(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	LPPROJECTITEMINFO lpInfo1 = (LPPROJECTITEMINFO)lParam1;
	LPPROJECTITEMINFO lpInfo2 = (LPPROJECTITEMINFO)lParam2;

	if( lpInfo1->nItemType == lpInfo2->nItemType ) {
		CString szFileName1 = GetFileName( lpInfo1->szPathName );
		CString szFileName2 = GetFileName( lpInfo2->szPathName );
		return szFileName1.CompareNoCase( szFileName2 );
	} else return (lpInfo1->nItemType - lpInfo2->nItemType);
}

HTREEITEM CFileWindow::InsertProjectItem(HTREEITEM hParent, LPCTSTR lpszText, INT nType, INT nAccount, LPCTSTR lpszPathName, LONG nSize)
{
	LPPROJECTITEMINFO lpInfo = new PROJECTITEMINFO;
	lpInfo->nItemType = nType;			lpInfo->nFtpAccount = nAccount;
	lpInfo->szPathName = lpszPathName;	lpInfo->nFileSize = nSize;

	HTREEITEM hItem = m_treProjectTree.InsertItem( lpszText, nType, nType, hParent );
	BOOL bReturn = m_treProjectTree.SetItemData( hItem, (DWORD)lpInfo );

	TVSORTCB sort; sort.hParent = hParent; sort.lpfnCompare = CompareProjectItem; sort.lParam = 0L;
	BOOL bSorted = m_treProjectTree.SortChildrenCB( & sort );

//	BOOL bExpand = m_treProjectTree.Expand( hParent, TVE_EXPAND );
//	BOOL bSelect = m_treProjectTree.SelectItem( hItem );

	return hItem;
}

HTREEITEM CFileWindow::FindChildProjectItem(HTREEITEM hParent, LPCTSTR lpszText)
{
	HTREEITEM hFound = m_treProjectTree.GetChildItem(hParent);
	while( hFound ) {
		CString szText = m_treProjectTree.GetItemText( hFound );
		if( ! szText.CompareNoCase(lpszText) ) return hFound;
		hFound = m_treProjectTree.GetNextSiblingItem( hFound );
	}
	return NULL;
}

/////////////////////////////////////////////////////////////////////////////
// Handlers
void CFileWindow::OnClickProjectTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	*pResult = 0;
}

void CFileWindow::OnDblclkProjectTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HTREEITEM hItem = GetClickedProjectItem();
	if( hItem ) OpenProjectItem(hItem);
	*pResult = 0;
}

void CFileWindow::OnRclickProjectTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HTREEITEM hItem = GetClickedProjectItem();
	if( hItem ) m_treProjectTree.SelectItem(hItem);
	OpenProjectContextMenu(hItem);
	*pResult = 0;
}

void CFileWindow::OnBeginlabeleditProjectTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
	HTREEITEM hItem = pTVDispInfo->item.hItem;

	LPPROJECTITEMINFO lpInfo = GetProjectItemInfo( hItem );
	if( lpInfo->nItemType == PROJECT_ITEM_CATEGORY ) m_bLabelEditing = TRUE;

	* pResult = m_bLabelEditing ? 0 : 1;
}

void CFileWindow::OnEndlabeleditProjectTree(NMHDR* pNMHDR, LRESULT* pResult) 
{
	TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
	HTREEITEM hItem = pTVDispInfo->item.hItem;

	CString szText = m_treProjectTree.GetItemText( hItem );
	if( pTVDispInfo->item.pszText && szText.CompareNoCase(pTVDispInfo->item.pszText) ) {
		RenameProjectItem( pTVDispInfo->item.hItem, pTVDispInfo->item.pszText );
	}

	m_bLabelEditing = FALSE;
	* pResult = 0;
}


/////////////////////////////////////////////////////////////////////////////
// Action Functions
BOOL CFileWindow::OpenProjectContextMenu(HTREEITEM hItem)
{
	CPoint point; GetCursorPos( & point ); 
	CMenu * pMenu, context; context.LoadMenu(IDR_FILE_WINDOW);

	if( hItem ) {
		INT nImage, nSelectedImage; m_treProjectTree.GetItemImage(hItem, nImage, nSelectedImage);
		CCedtApp * pApp = (CCedtApp *)AfxGetApp();

		if( ! IsSelectedProjectItemRoot() ) {
			switch( nImage ) {
			case PROJECT_ITEM_LOCAL_FILE:
				pMenu = GetSubMenuByText( & context, "PRJ_LOCAL"    ); break;
			case PROJECT_ITEM_REMOTE_FILE:
				pMenu = GetSubMenuByText( & context, "PRJ_REMOTE"   ); break;
			case PROJECT_ITEM_CATEGORY:
				pMenu = GetSubMenuByText( & context, "PRJ_CATEGORY" ); break;
			default: // this should not occur !!!
				pMenu = GetSubMenuByText( & context, "PRJ_NULL"     ); break;
			}
		} else if( pApp->IsProjectLoaded() ) {
			pMenu = GetSubMenuByText( & context, "PRJ_ROOT1" );
		} else pMenu = GetSubMenuByText( & context, "PRJ_ROOT0" );
	} else pMenu = GetSubMenuByText( & context, "PRJ_NULL" );

	UINT nFlags = TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON;
	return pMenu->TrackPopupMenu(nFlags, point.x, point.y, AfxGetMainWnd());
}

BOOL CFileWindow::RemoveAllProjectItems()
{
	HTREEITEM hRoot = m_treProjectTree.GetRootItem();
	if( hRoot ) return RemoveProjectItem( hRoot );
	else return TRUE; // nothing to delete
}

BOOL CFileWindow::OpenProjectItem(HTREEITEM hItem)
{
	if( ! hItem ) return FALSE;

	LPPROJECTITEMINFO lpInfo = GetProjectItemInfo( hItem );
	if( lpInfo->nItemType == PROJECT_ITEM_REMOTE_FILE ) { // remote file
		CCedtApp * pApp = (CCedtApp *)AfxGetApp(); if( ! pApp ) return FALSE;
		return pApp->PostOpenRemoteDocumentFile( lpInfo->nFtpAccount, lpInfo->szPathName, lpInfo->nFileSize, 0 );
	} else if( lpInfo->nItemType == PROJECT_ITEM_LOCAL_FILE ) { // local file
		if( ! VerifyFilePath( lpInfo->szPathName ) ) return FALSE;
		CCedtApp * pApp = (CCedtApp *)AfxGetApp(); if( ! pApp ) return FALSE;
		return pApp->PostOpenDocumentFile( lpInfo->szPathName, 0 );
	} else return FALSE;
}

BOOL CFileWindow::ExecuteProjectItem(HTREEITEM hItem)
{
	if( ! hItem ) return FALSE;

	LPPROJECTITEMINFO lpInfo = GetProjectItemInfo( hItem );
	if( lpInfo->nItemType == PROJECT_ITEM_LOCAL_FILE ) { // local file
		if( ! VerifyFilePath( lpInfo->szPathName ) ) return FALSE;
		CWnd * pWnd = AfxGetMainWnd(); if( ! pWnd ) return FALSE;
		HINSTANCE hResult = ::ShellExecute(NULL, "open", lpInfo->szPathName, NULL, NULL, SW_SHOWNORMAL);
		return ((UINT)hResult > 32) ? TRUE : FALSE;
	} else return FALSE;
}

BOOL CFileWindow::RenameProjectItem(HTREEITEM hItem, LPCTSTR lpszNewName)
{
	return m_treProjectTree.SetItemText(hItem, lpszNewName);
}

BOOL CFileWindow::RemoveProjectItem(HTREEITEM hItem)
{
	if( ! hItem ) return FALSE;

	HTREEITEM hChild = m_treProjectTree.GetChildItem( hItem );
	while( hChild ) { // delete childrens
		if( ! RemoveProjectItem( hChild ) ) return FALSE; // recursive call
		hChild = m_treProjectTree.GetChildItem( hItem );
	}

	delete GetProjectItemInfo( hItem ); // delete item data first
	return m_treProjectTree.DeleteItem( hItem );
}

⌨️ 快捷键说明

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