source: dev/trunk/ab5.0/abdev/abdev/History.cpp

Last change on this file was 829, checked in by イグトランス (egtra), 12 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 2.3 KB
Line 
1#include "stdafx.h"
2
3#include "common.h"
4
5CHistory::CHistory(int BaseID){
6 iNum=0;
7 iMaxHistoryNum=15;
8
9 m_BaseID=BaseID;
10}
11CHistory::~CHistory(){
12 int i;
13 for(i=0;i<iNum;i++){
14 HeapDefaultFree(lpszPath[i]);
15 }
16}
17
18void CHistory::load( const std::string &path )
19{
20 char temporary[MAX_PATH];
21
22 char *buffer;
23 buffer=ReadBuffer_NonErrMsg(path);
24 if(buffer){
25 int i;
26 i=0;
27 while(buffer[i]){
28 //表示名
29 i=GetOneParameter(buffer,i,temporary);
30 if(temporary[0]=='\0') break;
31
32 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
33 i+=2;
34 }
35
36 add(temporary);
37 }
38 HeapDefaultFree(buffer);
39 }
40}
41void CHistory::save( const std::string &path )
42{
43 char *buffer;
44 buffer=(char *)HeapAlloc(hHeap,0,iNum*MAX_PATH+1);
45 buffer[0]=0;
46
47 int i;
48 for(i=0;i<iNum;i++){
49 sprintf(buffer+lstrlen(buffer),"%s\r\n",lpszPath[i]);
50 }
51
52 WriteBuffer(path,buffer,lstrlen(buffer));
53
54 HeapDefaultFree(buffer);
55}
56void CHistory::add(char *path){
57 lpszPath[iNum]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
58 lstrcpy(lpszPath[iNum],path);
59 iNum++;
60}
61void CHistory::insert(const char *path){
62 //重複チェック
63 int i;
64 for(i=0;i<iNum;i++){
65 if(lstrcmpi(path,lpszPath[i])==0) break;
66 }
67 if(i==iNum){
68 //ローテーション
69 for(i=iNum;i>0;i--){
70 lpszPath[i]=lpszPath[i-1];
71 }
72
73 if(iNum+1 == iMaxHistoryNum){
74 //一番古い情報を削除
75 HeapDefaultFree(lpszPath[iNum]);
76 }
77 else iNum++;
78 }
79 else{
80 //ローテーション
81 HeapDefaultFree(lpszPath[i]);
82
83 for(;i>0;i--){
84 lpszPath[i]=lpszPath[i-1];
85 }
86 }
87
88 lpszPath[0]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
89 lstrcpy(lpszPath[0],path);
90}
91
92void CHistory::ResetFileMenu(CSubMenuEx *pobj_SubMenu,BOOL bOwnerDraw){
93 //古いメニューアイテムを消去
94 while(0<pobj_SubMenu->iMenuItemNum){
95 pobj_SubMenu->RemoveItem(0);
96 }
97
98 if(iNum==0){
99 //なし
100 pobj_SubMenu->InsertItem(0,100,"なし");
101 pobj_SubMenu->EnableItem(100,MF_BYCOMMAND|MF_GRAYED);
102 return;
103 }
104
105
106 int i;
107 for(i=0;i<iNum;i++){
108 //挿入
109 pobj_SubMenu->InsertItem(i,m_BaseID+i,lpszPath[i]);
110
111 //アイコンをセット(ネットワークドライブ内のファイルは取得に時間がかかるため、除外する)
112 if( !Jenga::Common::Path( lpszPath[i] ).IsNetworkPath() )
113 {
114 if(IsExistFile(lpszPath[i])){
115 SHFILEINFO shfi;
116 SHGetFileInfo( lpszPath[i], FILE_ATTRIBUTE_ARCHIVE, &shfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON );
117
118 if(shfi.hIcon){
119 pobj_SubMenu->SetIcon(m_BaseID+i,shfi.hIcon);
120 }
121 }
122 }
123 }
124}
Note: See TracBrowser for help on using the repository browser.