source: dev/trunk/ab5.0/abdev/ProjectEditor/History.cpp @ 475

Last change on this file since 475 was 475, checked in by dai_9181, 16 years ago

構成管理を変更中・・・(いったんコミット)

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(char *path){
19    char temporary[MAX_PATH];
20
21    char *buffer;
22    buffer=ReadBuffer_NonErrMsg(path);
23    if(buffer){
24        int i;
25        i=0;
26        while(buffer[i]){
27            //表示名
28            i=GetOneParameter(buffer,i,temporary);
29            if(temporary[0]=='\0') break;
30
31            if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
32                i+=2;
33            }
34
35            add(temporary);
36        }
37        HeapDefaultFree(buffer);
38    }
39}
40void CHistory::save(char *path){
41    char *buffer;
42    buffer=(char *)HeapAlloc(hHeap,0,iNum*MAX_PATH+1);
43    buffer[0]=0;
44
45    int i;
46    for(i=0;i<iNum;i++){
47        sprintf(buffer+lstrlen(buffer),"%s\r\n",lpszPath[i]);
48    }
49
50    WriteBuffer(path,buffer,lstrlen(buffer));
51
52    HeapDefaultFree(buffer);
53}
54void CHistory::add(char *path){
55    lpszPath[iNum]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
56    lstrcpy(lpszPath[iNum],path);
57    iNum++;
58}
59void CHistory::insert(char *path){
60    //重複チェック
61    int i;
62    for(i=0;i<iNum;i++){
63        if(lstrcmpi(path,lpszPath[i])==0) break;
64    }
65    if(i==iNum){
66        //ローテーション
67        for(i=iNum;i>0;i--){
68            lpszPath[i]=lpszPath[i-1];
69        }
70
71        if(iNum+1 == iMaxHistoryNum){
72            //一番古い情報を削除
73            HeapDefaultFree(lpszPath[iNum]);
74        }
75        else iNum++;
76    }
77    else{
78        //ローテーション
79        HeapDefaultFree(lpszPath[i]);
80
81        for(;i>0;i--){
82            lpszPath[i]=lpszPath[i-1];
83        }
84    }
85
86    lpszPath[0]=(char *)HeapAlloc(hHeap,0,lstrlen(path)+1);
87    lstrcpy(lpszPath[0],path);
88}
89
90void CHistory::ResetFileMenu(CSubMenuEx *pobj_SubMenu,BOOL bOwnerDraw){
91    //古いメニューアイテムを消去
92    while(0<pobj_SubMenu->iMenuItemNum){
93        pobj_SubMenu->RemoveItem(0);
94    }
95
96    if(iNum==0){
97        //なし
98        pobj_SubMenu->InsertItem(0,100,"なし");
99        pobj_SubMenu->EnableItem(100,MF_BYCOMMAND|MF_GRAYED);
100        return;
101    }
102
103
104    int i;
105    for(i=0;i<iNum;i++){
106        //挿入
107        pobj_SubMenu->InsertItem(i,m_BaseID+i,lpszPath[i]);
108
109        //アイコンをセット
110        if(IsExistFile(lpszPath[i])){
111            SHFILEINFO shfi;
112            SHGetFileInfo( lpszPath[i], FILE_ATTRIBUTE_ARCHIVE, &shfi, sizeof(SHFILEINFO), SHGFI_ICON | SHGFI_SMALLICON );
113
114            if(shfi.hIcon){
115                pobj_SubMenu->SetIcon(m_BaseID+i,shfi.hIcon);
116            }
117        }
118    }
119}
Note: See TracBrowser for help on using the repository browser.