📄 page.cpp
字号:
int sel = m_list.GetNextSelectedItem(pos);
s = m_list.GetItemText(sel,0);
return true;
}
/////////////// dictionary ////////////////////
bool CPageFS::OnDicOpen()
{
CString name;
if(!GetSelectName(name))
return false;
Dictionary* dic = fs.getCurrent()->getDic(name);
if(dic!=NULL)
{
SetView(dic);
HTREEITEM item = m_tree.GetSelectedItem();
item = m_tree.GetChildItem(item);
while(m_tree.GetItemText(item) != name&&item != NULL)
item = m_tree.GetNextItem(item,TVGN_NEXT);
if(item !=NULL)
{
m_tree.SelectItem(item);
return true;
}
}
return false;
}
void CPageFS::OnDicRename()
{
CNameDlg dlg(0,selDic->getName());
if(dlg.DoModal() == IDCANCEL||dlg.name == selDic->getName())
return;
if(!Dictionary::isValidName(dlg.name))
{
MessageBox("非法的名称!","错误",MB_ICONERROR|MB_OK);
return;
}
Dictionary*current = fs.getCurrent();
if(current->getFile(dlg.name)!=NULL||current->getDic(dlg.name)!=NULL)
{
MessageBox("文件重名!","错误",MB_ICONERROR|MB_OK);
return;
}
selDic->setName(dlg.name);
DeleteNode(m_tree.GetSelectedItem(),selDic);
InsertNode(m_tree.GetSelectedItem(),selDic);
SetView(current);
}
void CPageFS::OnDicDelete()
{
CString msg = "确实要删除文件夹\"";
msg+=selDic->getName();
msg+="\"吗?";
if(MessageBox(msg,"确认删除",MB_OKCANCEL|MB_ICONQUESTION) == IDCANCEL)
return;
Dictionary* dic = fs.getCurrent();
HTREEITEM item = m_tree.GetSelectedItem();
item = m_tree.GetChildItem(item);
while(item!=NULL)
{
if(m_tree.GetItemText(item) == selDic->getName())
{
m_tree.DeleteItem(item);
break;
}
item = m_tree.GetNextItem(item,TVGN_NEXT);
}
dic->deleteDic(selDic->getName());
SetView(dic);
}
void CPageFS::OnDicCut()
{
cDic = selDic;
cFather = fs.getCurrent();
isCut = true;
canPaste = true;
isFile = false;
}
void CPageFS::OnDicCopy()
{
cDic = selDic;
cFather = fs.getCurrent();
isCut = false;
canPaste = true;
isFile = false;
}
void CPageFS::OnDicINF()
{
CDINFDlg dlg(0,selDic->getName(),selDic->getPath(),
selDic->getFilesNum(),selDic->getDicsNum(),
selDic->getSize(),selDic->getSpace(),selDic->getBlockNum());
dlg.DoModal();
}
/////////////// file ////////////////////
bool CPageFS::OnFileOpen()
{
CString name;
if(!GetSelectName(name))
return false;
File*f = fs.getCurrent()->getFile(name);
if(f!=NULL)
{
CString txt;
int size = f->getSize();
char*buffer = NULL;
if(size != 0)
{
buffer = new char[size];
if(f->read(buffer))
txt.Append(buffer,size);
}
CEditDlg dlg(NULL,txt);
while(dlg.DoModal() == IDOK)
{
txt = dlg.string;
f->empty();
if(!f->write(txt.GetLength(),txt))
{
MessageBox("文本太长!","错误",MB_OK|MB_ICONWARNING);
f->empty();
f->write(size,buffer);
continue;
}
break;
}
if(buffer!=NULL)
delete[]buffer;
return true;
}
MessageBox("打开文件出错!","错误",MB_OK|MB_ICONWARNING);
return false;
}
void CPageFS::OnFileRun()
{
CMainDlg*dlg = (CMainDlg*)this->GetParent();
CString code = "";
int size = selFile->getSize();
if(size!=0)
{
char*c = new char[size];
selFile->read(c);
code.Append(c,size);
delete[]c;
}
dlg->SetActivePage(2);
CPageProEdit&pg = dlg->m_pgEdit;
pg.SetDlgItemText(IDC_EDIT1,code);
pg.OnBnClickedLoad();
}
void CPageFS::OnFileRename()
{
CNameDlg dlg(0,selFile->getName());
if(dlg.DoModal() == IDCANCEL||dlg.name == selFile->getName())
return;
if(!Dictionary::isValidName(dlg.name))
{
MessageBox("非法的名称!","错误",MB_ICONERROR|MB_OK);
return;
}
Dictionary*current = fs.getCurrent();
if(current->getFile(dlg.name)!=NULL||current->getDic(dlg.name)!=NULL)
{
MessageBox("文件重名!","错误",MB_ICONERROR|MB_OK);
return;
}
selFile->setName(dlg.name);
SetView(current);
}
void CPageFS::OnFileDelete()
{
CString msg = "确实要删除文件\"";
msg+=selFile->getName();
msg+="\"吗?";
if(MessageBox(msg,"确认删除",MB_OKCANCEL|MB_ICONQUESTION) == IDCANCEL)
return;
Dictionary* dic = fs.getCurrent();
dic->deleteFile(selFile->getName());
SetView(dic);
}
void CPageFS::OnFileCut()
{
cFile = selFile;
cFather = fs.getCurrent();
isCut = true;
canPaste = true;
isFile = true;
}
void CPageFS::OnFileCopy()
{
cFile = selFile;
cFather = fs.getCurrent();
isCut = false;
canPaste = true;
isFile = true;
}
void CPageFS::OnFileINF()
{
CString path = fs.getCurrent()->getPath()+fs.getCurrent()->getName()+"\\";
CFINFDlg dlg(0,selFile->getName(),path,selFile->getSize(),selFile->getSpace(),selFile->getBlockNum());
dlg.DoModal();
}
/////////////// blank ////////////////////
void CPageFS::OnFileNew()
{
Dictionary* dic = fs.getCurrent();
CNameDlg dlg;
CString name;
int msg;
File*nFile;
if(dlg.DoModal() == IDCANCEL)
return;
msg = dic->createFile(dlg.name,nFile,0,0);
switch(msg)
{
case BAD_NAME:
MessageBox("非法的名称!","错误",MB_ICONERROR|MB_OK);
break;
case NAME_EXIST:
MessageBox("文件有重名!","错误",MB_ICONERROR|MB_OK);
break;
case DICT_OUT:
MessageBox("已经达到最大文件数!","错误",MB_ICONERROR|MB_OK);
break;
default:
SetView(dic);
}
}
void CPageFS::OnDicNew()
{
Dictionary* dic = fs.getCurrent();
CNameDlg dlg;
CString name;
int msg;
Dictionary*nDic;
if(dlg.DoModal() == IDCANCEL)
return;
msg = dic->createDic(dlg.name,nDic);
switch(msg)
{
case BAD_NAME:
MessageBox("非法的名称!","错误",MB_ICONERROR|MB_OK);
break;
case NAME_EXIST:
MessageBox("文件有重名!","错误",MB_ICONERROR|MB_OK);
break;
case DICT_OUT:
MessageBox("已经达到最大文件数!","错误",MB_ICONERROR|MB_OK);
break;
default:
SetView(dic);
InsertNode(m_tree.GetSelectedItem(),nDic);
}
}
void CPageFS::OnPaste()
{
Dictionary*current = fs.getCurrent();
//cut
if(isCut)
{
canPaste = false;
//paste file
if(isFile)
{ if(cFather == fs.getCurrent())
{
cFile->getName();
return;
}
cFile->getName();
int msg = current->addFile(cFile);
if(msg == DICT_OUT)
MessageBox("粘贴失败,文件已满!","错误",MB_OK|MB_ICONERROR);
else if(msg == NAME_EXIST)
MessageBox("粘贴失败,有重名!","错误",MB_OK|MB_ICONERROR);
if(msg!=0)
{
canPaste = false;
return;
}
if(!cFather->removeFile(cFile))
MessageBox("删除源文件失败!","错误",MB_OK|MB_ICONERROR);
this->SetView(current);
}else{//paste dictionary
if(cFather == fs.getCurrent())
{
cDic->getName();
return;
}
int msg = current->addDic(cDic);
if(msg == DICT_OUT)
MessageBox("粘贴失败,文件夹已满!","错误",MB_OK|MB_ICONERROR);
else if(msg == NAME_EXIST)
MessageBox("粘贴失败,有重名!","错误",MB_OK|MB_ICONERROR);
else if(msg == PASTE_FATHER)
MessageBox("无法粘贴父目录!","错误",MB_OK|MB_ICONERROR);
if(msg!=0)
{
canPaste = false;
return;
}
if(!cFather->removeDic(cDic))
MessageBox("删除源文件失败!","错误",MB_OK|MB_ICONERROR);
DeleteNode(m_tree.GetRootItem(),cDic);
InsertNode(m_tree.GetSelectedItem(),cDic);
this->SetView(current);
}
}else{//copy
//paste file
if(isFile)
{
cFile->getName();
File*f = cFile->getCopy();
int msg = current->addFile(f);
if(msg == DICT_OUT)
MessageBox("粘贴失败,文件已满!","错误",MB_OK|MB_ICONERROR);
else if(msg == NAME_EXIST)
MessageBox("粘贴失败!","错误",MB_OK|MB_ICONERROR);
if(msg!=0)
{
canPaste = false;
return;
}
this->SetView(current);
}else{
cDic->getName();
Dictionary*d = cDic->getCopy(current);
int msg = current->addDic(d);
if(msg == DICT_OUT)
MessageBox("粘贴失败,文件已满!","错误",MB_OK|MB_ICONERROR);
else if(msg == NAME_EXIST)
MessageBox("粘贴失败!","错误",MB_OK|MB_ICONERROR);
if(msg!=0)
{
canPaste = false;
return;
}
this->InsertNode(m_tree.GetSelectedItem(),d);
this->SetView(current);
}
}
}
///////////////windows message///////////////////
LRESULT CPageFS::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message != WM_COMMAND)
return CPropertyPage::WindowProc(message, wParam, lParam);
//file
if(selFile!=NULL)
{
switch(LOWORD(wParam))
{
case ID_OPEN:
OnFileOpen();
break;
case ID_RENAME:
OnFileRename();
break;
case ID_DELETE:
OnFileDelete();
break;
case ID_CUT:
OnFileCut();
break;
case ID_COPY:
OnFileCopy();
break;
case ID_INF:
OnFileINF();
break;
case ID_RUN:
OnFileRun();
break;
}
}
//dictionary
else if(selDic!=NULL)
{
switch(LOWORD(wParam))
{
case ID_OPEN:
OnDicOpen();
break;
case ID_RENAME:
OnDicRename();
break;
case ID_DELETE:
OnDicDelete();
break;
case ID_CUT:
OnDicCut();
break;
case ID_COPY:
OnDicCopy();
break;
case ID_INF:
OnDicINF();
break;
}
}//blank
else
{
switch(LOWORD(wParam))
{
case ID_NEW_DIC:
OnDicNew();
break;
case ID_NEW_FILE:
OnFileNew();
break;
case ID_PASTE:
try{
OnPaste();
}catch(...)
{
MessageBox("读取源文件失败!","错误",MB_ICONERROR);
canPaste = false;
}
break;
}
}
return CPropertyPage::WindowProc(message, wParam, lParam);
}
void CPageFS::OnNMRclickListFs(NMHDR *pNMHDR, LRESULT *pResult)
{
selFile = NULL;
selDic = NULL;
DWORD dpos = GetMessagePos();
POINTS ps = MAKEPOINTS(dpos);
POINT p;
p.x = ps.x;
p.y = ps.y;
POSITION pos = m_list.GetFirstSelectedItemPosition();
int sel = -1;
if(pos!=NULL)
sel = m_list.GetNextSelectedItem(pos);
CMenu menu;
menu.LoadMenu(IDR_MENU_FS);
int sub = -1;
//click on blank space
if(sel == -1)
sub = 0;
else{
CString name = m_list.GetItemText(sel,0);
Dictionary*dic = fs.getCurrent();
//click on a file
selFile = dic->getFile(name);
if(selFile!=NULL)
sub = 1;
else{
selDic = dic->getDic(name);
if(selDic!=NULL)
sub = 2;
}
}
if(sub>=0)
{
CMenu*pop = menu.GetSubMenu(sub);
if(!canPaste)
pop->EnableMenuItem(ID_PASTE,TRUE);
pop->TrackPopupMenu(0,p.x,p.y,this);
}
*pResult = 0;
}
void CPageFS::OnTvnSelchangedTreeFs(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pnw = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
HTREEITEM item = m_tree.GetSelectedItem();
Dictionary*dic = (Dictionary*)(m_tree.GetItemData(item));
fs.setCurrent(dic);
SetView(dic);
*pResult = 0;
}
void CPageFS::OnNMDblclkListFs(NMHDR *pNMHDR, LRESULT *pResult)
{
if(!OnDicOpen())
OnFileOpen();
*pResult = 0;
}
void CPageFS::OnBnClickedButtonFormat()
{
int sel = MessageBox("格式化将会删除所有数据,你确定要执行该操作吗?","警告",MB_OKCANCEL|MB_ICONQUESTION);
if(sel == IDCANCEL)
return;
fs.format();
SetView(fs.getRoot());
HTREEITEM ritem = m_tree.GetRootItem();
HTREEITEM item = m_tree.GetChildItem(ritem);
while(item!=0)
{
m_tree.DeleteItem(item);
item = m_tree.GetChildItem(ritem);
}
MessageBox("格式化已完成!","完成",MB_OK);
}
void CPageFS::OnBnClickedButtonDisk()
{
Dictionary*root = fs.getRoot();
int size = root->getSize();
int free = fs.getFreeSize();
int frag = DISK_SIZE-size-free;
CDiskINFDlg dlg(0,root->getFilesNum(),root->getDicsNum()+1,BLOCK_NUM,DISK_SIZE,size,free,frag);
dlg.DoModal();
}
void CPageFS::OnBnClickedButtonUp()
{
HTREEITEM item= m_tree.GetSelectedItem();
item = m_tree.GetParentItem(item);
if(item!=NULL)
{
m_tree.SelectItem(item);
Dictionary*up = (Dictionary*)m_tree.GetItemData(item);
fs.setCurrent(up);
this->SetView(up);
}else
MessageBox("已到根目录!");
}
//void CPageFS::OnLvnEndlabeleditListFs(NMHDR *pNMHDR, LRESULT *pResult)
//{
// NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
// pResult = 0;
// return;
// CString name;
// if(!GetSelectName(name))
// {
// *pResult = 0;
// return;
// }
// Dictionary*current = fs.getCurrent();
// selFile = current->getFile(name);
// if(selFile !=NULL)
// this->OnFileRename();
// else{
// selDic = current->getDic(name);
// if(selDic !=NULL)
// {
// CString nm = pDispInfo->item.pszText;
// if(nm == selDic->getName())
// return;
// if(!Dictionary::isValidName(nm))
// {
// MessageBox("非法的名称!","错误",MB_ICONERROR|MB_OK);
// *pResult = 0;
// return;
// }
// if(current->getFile(nm)!=NULL||current->getDic(nm)!=NULL)
// {
// MessageBox("文件重名!","错误",MB_ICONERROR|MB_OK);
// *pResult = 0;
// return;
// }
// selDic->setName(nm);
// DeleteNode(m_tree.GetSelectedItem(),selDic);
// InsertNode(m_tree.GetSelectedItem(),selDic);
// SetView(current);
// }
// }
// *pResult = 0;
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -