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

📄 ulexplorerview.cpp

📁 类似Linux操作系统0.11版文件系统的文件系统设计和Windows下的操作程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ShortcutBarView.cpp : implementation of the CULExplorerView class
//

#include "stdafx.h"
#include "ULExplorer.h"

#include "ULExplorerView.h"

#include "FileViewDlg.h"
#include "NewDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CULExplorerView

IMPLEMENT_DYNCREATE(CULExplorerView, CView)

BEGIN_MESSAGE_MAP(CULExplorerView, CView)
	//{{AFX_MSG_MAP(CULExplorerView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_NOTIFY(NM_DBLCLK, IDC_FOLDERS_LIST, OnDoubleClickList)
	ON_NOTIFY(NM_RCLICK, IDC_FOLDERS_LIST, OnRightClickList)
	ON_COMMAND(ID_MENU_NEWDENTRY, OnMenuNewdentry)
	ON_COMMAND(ID_MENU_NEWFILE, OnMenuNewfile)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_FILE_CUT, OnFileCut)
	ON_COMMAND(ID_FILE_COPY, OnFileCopy)
	ON_COMMAND(ID_FILE_RENAME, OnFileRename)
	ON_COMMAND(ID_FILE_DELETE, OnFileDelete)
	ON_COMMAND(ID_MENU_IMPORT, OnMenuImport)
	ON_COMMAND(ID_Menu_OUTPORT, OnMenuOutport)
	ON_COMMAND(ID_DENTRY_OPEN, OnDentryOpen)
	ON_COMMAND(ID_DENTRY_RENAME, OnDentryRename)
	ON_COMMAND(ID_DENTRY_DELETE, OnDentryDelete)
	ON_COMMAND(ID_MENU_EXECUTE, OnMenuExecute)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CULExplorerView construction/destruction

CULExplorerView::CULExplorerView()
{
	// TODO: add construction code here

}

CULExplorerView::~CULExplorerView()
{
}

BOOL CULExplorerView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
	cs.style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CULExplorerView drawing

void CULExplorerView::OnDraw(CDC* pDC)
{
	//pDC->FillSolidRect(CXTPClientRect(this), RGB(0xFF, 0xFF, 0));
	// TODO: add draw code for native data here
	
	if (XTPPaintManager()->GetCurrentTheme() == xtpThemeOffice2003)
	{
		pDC->Draw3dRect(CXTPClientRect(this), GetXtremeColor(XPCOLOR_FRAME), GetXtremeColor(XPCOLOR_FRAME));
	}
	else
	{
		pDC->Draw3dRect(CXTPClientRect(this), GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DHIGHLIGHT));
	}
}

/////////////////////////////////////////////////////////////////////////////
// CULExplorerView diagnostics

#ifdef _DEBUG
void CULExplorerView::AssertValid() const
{
	CView::AssertValid();
}

void CULExplorerView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CULExplorerView message handlers

int CULExplorerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO: Add your specialized creation code here
	if (!m_ShellList.Create(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_VSCROLL 
		| LVS_ICON | LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_SINGLESEL,
		CRect(0,0,0,0), this, IDC_FOLDERS_LIST))
	{
		TRACE0("Failed to create list control.\n");
		return -1;
	}

	//m_Font.CreatePointFont(120, "Fixedsys");
	//m_ShellList.SetFont(&m_Font);
	
	m_ImageListIcons.Create(32, 32, ILC_COLOR32|ILC_MASK, 0, 1);

	CBitmap bmp;

	if (XTPImageManager()->IsAlphaIconsImageListSupported())
	{	
		bmp.Attach((HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_FILEICONS_ALPHA),
			IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION));

		m_ImageListIcons.Add(&bmp, (CBitmap*)NULL);	
	} else
	{
		bmp.LoadBitmap(IDB_FILEICONS_NORMAL);
		m_ImageListIcons.Add(&bmp, RGB(0, 0xFF, 0));	
	}

	m_ShellList.SetImageList(&m_ImageListIcons, LVSIL_NORMAL);
/*
	m_ShellList.InsertItem(999, "Jianglu", 0);
	m_ShellList.InsertItem(999, "Xieyue", 1);
	m_ShellList.InsertItem(999, "JiChao", 2);
*/
	return 0;
}

void CULExplorerView::OnSize(UINT nType, int cx, int cy)
{
	CView::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	if(m_ShellList.GetSafeHwnd()) 
	{
		m_ShellList.MoveWindow(1, 1, cx-2, cy-2);

		ReShowDentryList();
	}
}

void CULExplorerView::OnInitialUpdate()
{
	CView::OnInitialUpdate();
}
void CULExplorerView::ShowDentryList(CString PathName)
{
	FIND_DATA ff;
	int ret;
	CString tmp;
	CArray<FIND_DATA> array;

	m_FileArray.RemoveAll();

	m_ShellList.DeleteAllItems();

	if( (ret=theFileSys.FindFirstFile(PathName.LockBuffer(), &ff))==0 )
	{
		do 
		{
			array.Add(ff);
		} while(!findnextfile(1, &ff));
	}
	else
	{
		TRACE("目录游览失败: path=\"%s\" error=%d\n", PathName, ret);
		return;
	}

	for (int i=0; i<array.GetCount(); i++)
	{
		FIND_DATA& pff = array.ElementAt(i);

		if ( pff.ff_mode == S_IFDIR )
		{
			m_ShellList.InsertItem(9999, pff.ff_name, 0);
			m_FileArray.Add(pff);
		}
	}

	for (int i=0; i<array.GetCount(); i++)
	{
		FIND_DATA& pff = array.ElementAt(i);

		if ( pff.ff_mode != S_IFDIR )
		{
			m_ShellList.InsertItem(9999, pff.ff_name, 1);
			m_FileArray.Add(pff);
		}
	}


	((CMainFrame*)AfxGetMainWnd())->SetCurPath(PathName);
}

void CULExplorerView::ReShowDentryList(void)
{
	m_ShellList.DeleteAllItems();

	for (int i=0; i<m_FileArray.GetCount(); i++)
	{
		FIND_DATA& pff = m_FileArray.ElementAt(i);

		if ( pff.ff_mode == S_IFDIR )
		{
			m_ShellList.InsertItem(9999, pff.ff_name, 0);
		}
	}

	for (int i=0; i<m_FileArray.GetCount(); i++)
	{
		FIND_DATA& pff = m_FileArray.ElementAt(i);

		if ( pff.ff_mode != S_IFDIR )
		{
			m_ShellList.InsertItem(9999, pff.ff_name, 1);
		}
	}

}

void CULExplorerView::OnDoubleClickList(NMHDR* /*pNMHDR*/, LRESULT* pResult)
{

	*pResult = 0;

	if ( !theFileSys.IsVDiskLoaded() ) 
		return;

	POSITION pos = m_ShellList.GetFirstSelectedItemPosition();
	int idx = m_ShellList.GetNextSelectedItem(pos);
	if (idx < 0)
		return;
	CString tmp = m_ShellList.GetItemText(idx, 0);

	TRACE("CULExplorerView::OnDoubleClickList = %s\n",tmp);

	CString Path = ((CMainFrame*)AfxGetMainWnd())->GetCurPath();

	// 如果是文件夹
	if ( m_FileArray.GetAt(idx).ff_mode == S_IFDIR ) 
	{
		if ( tmp=="." ) 
		{
			return;
		}
		else if ( tmp==".." ) 
		{
			m_pPaneFolders->SelectParentItem();
			return;
		}
		else
		{
			CString str = Path + tmp + "/";
	
			m_pPaneFolders->ExpandDentryTree(str);
			TRACE("CULExplorerView::OnDoubleClickList = %s\n",Path);
		}
	}
	else
	{
		CFileViewDlg FileDlg;
		FileDlg.SetFilePath(Path+tmp);
		FileDlg.DoModal();	
	}

}

void CULExplorerView::OnRightClickList(NMHDR* pNMHDR, LRESULT* pResult)
{
	*pResult = 0;

	if ( !theFileSys.IsVDiskLoaded() ) 
		return;

	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

	int idx = pNMLV->iItem; 

	CMenu CnxtMenu;
	CMenu* pCnxtSubMenu;
	CPoint Point;

	if (idx<0)
	{
		CnxtMenu.LoadMenu(IDR_MENU_LIST);
		pCnxtSubMenu = CnxtMenu.GetSubMenu(0);
	}
	else
	{
		CString tmp;
		tmp = m_ShellList.GetItemText(idx, 0);
		// 判断Folder
		if ( m_FileArray.GetAt(idx).ff_mode == S_IFDIR ) 
		{
			CnxtMenu.LoadMenu(IDR_MENU_DENTRY);
			pCnxtSubMenu = CnxtMenu.GetSubMenu(0);
		}
		else
		{
			CnxtMenu.LoadMenu(IDR_MENU_FILE);
			pCnxtSubMenu = CnxtMenu.GetSubMenu(0);
		}
	}

	GetCursorPos(&Point);
	CXTPCommandBars::TrackPopupMenu(pCnxtSubMenu, TPM_RIGHTBUTTON , Point.x, Point.y, 
		this, 0, 0, ((CXTPFrameWnd*)AfxGetMainWnd())->GetCommandBars());
}
// 新建目录
void CULExplorerView::OnMenuNewdentry()
{
	CNewDlg Dlg;
	if (Dlg.DoModal()==IDOK)
	{
		CString Path = ((CMainFrame*)AfxGetMainWnd())->GetCurPath();
		CString NewPath = Path + Dlg.GetText();

		int Ret = theFileSys.MakeDir(NewPath, 0);
		if (Ret<0)
		{
			Waring("新建目录失败");
			return;
		}
		m_pPaneFolders->ShowDentryTree();
		m_pPaneFolders->ExpandDentryTree(Path);
	}	
}

// 新建文件
void CULExplorerView::OnMenuNewfile()
{
	CNewDlg Dlg;
	if (Dlg.DoModal()==IDOK)
	{
		CString Path = ((CMainFrame*)AfxGetMainWnd())->GetCurPath();
		if ( IsExist(Dlg.GetText()) )
		{
			Waring("已有同名文件啦");
			return;
		}

		CString NewPath = Path + Dlg.GetText();

		int hFile = theFileSys.Open(NewPath, O_CREAT|O_RDWR, 0);
		if (hFile<0)
		{
			Waring("新建文件失败");
			return;
		}
		theFileSys.Close(hFile);
		ShowDentryList(Path);
	}
}

// 文件打开
void CULExplorerView::OnFileOpen()
{
	POSITION pos = m_ShellList.GetFirstSelectedItemPosition();

⌨️ 快捷键说明

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