Skip to content

Commit

Permalink
Merge fb761e8 into 930a6bf
Browse files Browse the repository at this point in the history
  • Loading branch information
usagisita committed Mar 21, 2021
2 parents 930a6bf + fb761e8 commit 20e6618
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 117 deletions.
87 changes: 30 additions & 57 deletions sakura_core/CFileExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,100 +35,73 @@
#include "CFileExt.h"
#include "env/CDocTypeManager.h"

CFileExt::CFileExt()
{
m_puFileExtInfo = NULL;
m_nCount = 0;
m_vstrFilter.resize( 1 );
m_vstrFilter[0] = L'\0';

// //テキストエディタとして、既定でリストに載ってほしい拡張子
// AppendExt( "すべてのファイル", "*" );
// AppendExt( "テキストファイル", "txt" );
}

CFileExt::~CFileExt()
{
if( m_puFileExtInfo ) free( m_puFileExtInfo );
m_puFileExtInfo = NULL;
m_nCount = 0;
}

bool CFileExt::AppendExt( const WCHAR *pszName, const WCHAR *pszExt )
{
WCHAR szWork[_countof(m_puFileExtInfo[0].m_szExt) + 10];

if( !CDocTypeManager::ConvertTypesExtToDlgExt( pszExt, NULL, szWork ) ) return false;
return AppendExtRaw( pszName, szWork );
std::wstring workExt = CDocTypeManager::ConvertTypesExtToDlgExt(pszExt, nullptr);
if (workExt.empty()) {
return false;
}
return AppendExtRaw( pszName, workExt.c_str() );
}

bool CFileExt::AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt )
{
FileExtInfoTag *p;

if( NULL == pszName || pszName[0] == L'\0' ) return false;
if( NULL == pszExt || pszExt[0] == L'\0' ) return false;

if( NULL == m_puFileExtInfo )
{
p = (FileExtInfoTag*)malloc( sizeof( FileExtInfoTag ) * 1 );
if( NULL == p ) return false;
}
else
{
p = (FileExtInfoTag*)realloc( m_puFileExtInfo, sizeof( FileExtInfoTag ) * ( m_nCount + 1 ) );
if( NULL == p ) return false;
}
m_puFileExtInfo = p;
SFileExtInfo info;
info.m_sTypeName = pszName;
info.m_sExt = pszExt;

wcscpy( m_puFileExtInfo[m_nCount].m_szName, pszName );
wcscpy( m_puFileExtInfo[m_nCount].m_szExt, pszExt );
m_nCount++;
m_vFileExtInfo.push_back(std::move(info));

return true;
}

const WCHAR *CFileExt::GetName( int nIndex )
{
if( nIndex < 0 || nIndex >= m_nCount ) return NULL;
if( nIndex < 0 || nIndex >= GetCount() ) return nullptr;

return m_puFileExtInfo[nIndex].m_szName;
return m_vFileExtInfo[nIndex].m_sTypeName.c_str();
}

const WCHAR *CFileExt::GetExt( int nIndex )
{
if( nIndex < 0 || nIndex >= m_nCount ) return NULL;
if( nIndex < 0 || nIndex >= GetCount() ) return nullptr;

return m_puFileExtInfo[nIndex].m_szExt;
return m_vFileExtInfo[nIndex].m_sExt.c_str();
}

const WCHAR *CFileExt::GetExtFilter( void )
{
int i;
CreateExtFilter(m_vstrFilter);
return m_vstrFilter.data();
}

void CFileExt::CreateExtFilter(std::vector<WCHAR>& output) const
{
std::wstring work;

/* 拡張子フィルタの作成 */
m_vstrFilter.resize(0);
output.resize(0);

for( i = 0; i < m_nCount; i++ )
for (int i = 0; i < GetCount(); i++)
{
// "%s (%s)\0%s\0"
work = m_puFileExtInfo[i].m_szName;
work = m_vFileExtInfo[i].m_sTypeName;
work.append(L" (");
work.append(m_puFileExtInfo[i].m_szExt);
work.append(m_vFileExtInfo[i].m_sExt);
work.append(L")");
work.append(L"\0", 1);
work.append(m_puFileExtInfo[i].m_szExt);
work.append(m_vFileExtInfo[i].m_sExt);
work.append(L"\0", 1);

int i = (int)m_vstrFilter.size();
m_vstrFilter.resize( i + work.length() );
wmemcpy( &m_vstrFilter[i], &work[0], work.length() );
size_t pos = output.size();
output.resize(pos + work.length());
wmemcpy(&output[pos], &work[0], work.length());
}
if( 0 == m_nCount ){
m_vstrFilter.push_back( L'\0' );
if( 0 == GetCount() ){
output.push_back( L'\0' );
}
m_vstrFilter.push_back( L'\0' );

return &m_vstrFilter[0];
output.push_back( L'\0' );
}
17 changes: 8 additions & 9 deletions sakura_core/CFileExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
class CFileExt
{
public:
CFileExt();
~CFileExt();
CFileExt() = default;

bool AppendExt( const WCHAR *pszName, const WCHAR *pszExt );
bool AppendExtRaw( const WCHAR *pszName, const WCHAR *pszExt );
Expand All @@ -52,21 +51,21 @@ class CFileExt
//2回呼び出すと古いバッファが無効になることがあるのに注意
const WCHAR *GetExtFilter( void );

int GetCount( void ) { return m_nCount; }
[[nodiscard]] int GetCount() const { return static_cast<int>(m_vFileExtInfo.size()); }

protected:
// 2014.10.30 syat ConvertTypesExtToDlgExtをCDocTypeManagerに移動
//bool ConvertTypesExtToDlgExt( const WCHAR *pszSrcExt, WCHAR *pszDstExt );

private:
void CreateExtFilter(std::vector<WCHAR>& output) const;

typedef struct {
WCHAR m_szName[64]; //名前(64文字以下のはず→m_szTypeName)
WCHAR m_szExt[MAX_TYPES_EXTS*3+1]; //拡張子(64文字以下のはず→m_szTypeExts) なお "*." を追加するのでそれなりに必要
} FileExtInfoTag;
struct SFileExtInfo {
std::wstring m_sTypeName; //名前
std::wstring m_sExt; //拡張子
};

int m_nCount;
FileExtInfoTag *m_puFileExtInfo;
std::vector<SFileExtInfo> m_vFileExtInfo;
std::vector<WCHAR> m_vstrFilter;

DISALLOW_COPY_AND_ASSIGN(CFileExt);
Expand Down
16 changes: 7 additions & 9 deletions sakura_core/dlg/CDlgOpenFile_CommonFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct CDlgOpenFile_CommonFileDialog final : public IDlgOpenFile

DLLSHAREDATA* m_pShareData;

SFilePath m_szDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */
std::wstring m_strDefaultWildCard{ L"*.*" }; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */
SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */

std::vector<LPCWSTR> m_vMRU;
Expand Down Expand Up @@ -418,7 +418,7 @@ UINT_PTR CALLBACK OFNHookProc(
else{
switch( pData->m_pOf->nFilterIndex ){ // 選択されているファイルの種類
case 1: // ユーザー定義
pszCur = pData->m_pcDlgOpenFile->m_szDefaultWildCard;
pszCur = pData->m_pcDlgOpenFile->m_strDefaultWildCard.data();
while( *pszCur != L'.' && *pszCur != L'\0' ) // '.'まで読み飛ばす
pszCur = ::CharNext(pszCur);
i = 0;
Expand Down Expand Up @@ -667,8 +667,6 @@ CDlgOpenFile_CommonFileDialog::CDlgOpenFile_CommonFileDialog()
wcscpy( m_szInitialDir, szDrive );
wcscat( m_szInitialDir, szDir );

wcscpy( m_szDefaultWildCard, L"*.*" ); /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */

return;
}

Expand All @@ -687,7 +685,7 @@ void CDlgOpenFile_CommonFileDialog::Create(

/* ユーザー定義ワイルドカード(保存時の拡張子補完でも使用される) */
if( NULL != pszUserWildCard ){
wcscpy( m_szDefaultWildCard, pszUserWildCard );
m_strDefaultWildCard = pszUserWildCard;
}

/* 「開く」での初期フォルダ */
Expand Down Expand Up @@ -722,7 +720,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi

// 2003.05.12 MIK
CFileExt cFileExt;
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() );

switch( eAddFilter ){
case EFITER_TEXT:
Expand All @@ -740,7 +738,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
break;
}

if( 0 != wcscmp(m_szDefaultWildCard, L"*.*") ){
if (m_strDefaultWildCard != L"*.*") {
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" );
}

Expand Down Expand Up @@ -815,7 +813,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModal_GetSaveFileName( WCHAR* pszPath )

// 2003.05.12 MIK
CFileExt cFileExt;
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME2), L"*.txt" );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" );

Expand Down Expand Up @@ -979,7 +977,7 @@ bool CDlgOpenFile_CommonFileDialog::DoModalSaveDlg(

// 2003.05.12 MIK
CFileExt cFileExt;
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_szDefaultWildCard );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME1), m_strDefaultWildCard.c_str() );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME2), L"*.txt" );
cFileExt.AppendExtRaw( LS(STR_DLGOPNFL_EXTNAME3), L"*.*" );

Expand Down
19 changes: 10 additions & 9 deletions sakura_core/dlg/CDlgOpenFile_CommonItemDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct CDlgOpenFile_CommonItemDialog final

DLLSHAREDATA* m_pShareData;

SFilePath m_szDefaultWildCard; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */
std::wstring m_strDefaultWildCard{ L"*.*" }; /* 「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */
SFilePath m_szInitialDir; /* 「開く」での初期ディレクトリ */

std::vector<LPCWSTR> m_vMRU;
Expand Down Expand Up @@ -398,6 +398,7 @@ enum CtrlId {
};

CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog()
:m_strDefaultWildCard(L"*.*") //「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される)
{
m_hInstance = NULL; /* アプリケーションインスタンスのハンドル */
m_hwndParent = NULL; /* オーナーウィンドウのハンドル */
Expand All @@ -416,7 +417,6 @@ CDlgOpenFile_CommonItemDialog::CDlgOpenFile_CommonItemDialog()
wcscpy( m_szInitialDir, szDrive );
wcscat( m_szInitialDir, szDir );

wcscpy( m_szDefaultWildCard, L"*.*" ); /*「開く」での最初のワイルドカード(保存時の拡張子補完でも使用される) */

return;
}
Expand All @@ -435,7 +435,7 @@ void CDlgOpenFile_CommonItemDialog::Create(

/* ユーザー定義ワイルドカード(保存時の拡張子補完でも使用される) */
if( NULL != pszUserWildCard ){
wcscpy( m_szDefaultWildCard, pszUserWildCard );
m_strDefaultWildCard = pszUserWildCard;
}

/* 「開く」での初期フォルダ */
Expand Down Expand Up @@ -465,7 +465,7 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
strs.reserve(8);

strs.push_back(LS(STR_DLGOPNFL_EXTNAME1));
specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), m_szDefaultWildCard});
specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), m_strDefaultWildCard.c_str()});

switch( eAddFilter ){
case EFITER_TEXT:
Expand All @@ -484,7 +484,7 @@ bool CDlgOpenFile_CommonItemDialog::DoModal_GetOpenFileName( WCHAR* pszPath, EFi
break;
}

if( 0 != wcscmp(m_szDefaultWildCard, L"*.*") ){
if (m_strDefaultWildCard != L"*.*") {
strs.push_back(LS(STR_DLGOPNFL_EXTNAME3));
specs.push_back(COMDLG_FILTERSPEC{strs.back().c_str(), L"*.*"});
}
Expand Down Expand Up @@ -700,15 +700,16 @@ bool CDlgOpenFile_CommonItemDialog::DoModalOpenDlg(
specs[1].pszName = strs[1].c_str();
specs[1].pszSpec = L"*.txt";
CDocTypeManager docTypeMgr;
WCHAR szWork[_countof(STypeConfigMini::m_szTypeExts) * 3];
std::wstring worksString;
for( int i = 0; i < nTypesCount; i++ ){
const STypeConfigMini* type = NULL;
if( !docTypeMgr.GetTypeConfigMini( CTypeConfig(i), &type ) ){
continue;
}
specs[2 + i].pszName = type->m_szTypeName;
if (CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, NULL, szWork)) {
strs[2 + i] = szWork;
worksString = CDocTypeManager::ConvertTypesExtToDlgExt(type->m_szTypeExts, nullptr);
if (!worksString.empty()) {
strs[2 + i] = worksString;
specs[2 + i].pszSpec = strs[2 + i].c_str();
}
else {
Expand Down Expand Up @@ -747,7 +748,7 @@ HRESULT CDlgOpenFile_CommonItemDialog::DoModalSaveDlgImpl1(
strs[1] = LS(STR_DLGOPNFL_EXTNAME2);
strs[2] = LS(STR_DLGOPNFL_EXTNAME3);
specs[0].pszName = strs[0].c_str();
specs[0].pszSpec = m_szDefaultWildCard;
specs[0].pszSpec = m_strDefaultWildCard.c_str();
specs[1].pszName = strs[1].c_str();
specs[1].pszSpec = L"*.txt";
specs[2].pszName = strs[2].c_str();
Expand Down
18 changes: 9 additions & 9 deletions sakura_core/doc/CDocFileOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ bool CDocFileOperation::SaveFileDialog(
//拡張子指定
// 一時適用や拡張子なしの場合の拡張子をタイプ別設定から持ってくる
// 2008/6/14 大きく改造 Uchi
WCHAR szDefaultWildCard[_MAX_PATH + 10]; // ユーザー指定拡張子
std::wstring strDefaultWildCard; // ユーザー指定拡張子

{
LPCWSTR szExt;

Expand All @@ -241,28 +242,27 @@ bool CDocFileOperation::SaveFileDialog(
// 基本
if (szExt[0] == L'\0') {
// ファイルパスが無いまたは拡張子なし
wcscpy(szDefaultWildCard, L"*.txt");
strDefaultWildCard = L"*.txt";
}
else {
// 拡張子あり
wcscpy(szDefaultWildCard, L"*");
wcscat(szDefaultWildCard, szExt);
strDefaultWildCard = L"*";
strDefaultWildCard += szExt;
}
}
else {
szDefaultWildCard[0] = L'\0';
CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt, szDefaultWildCard);
strDefaultWildCard = CDocTypeManager::ConvertTypesExtToDlgExt(type.m_szTypeExts, szExt);
}

if(!this->m_pcDocRef->m_cDocFile.GetFilePathClass().IsValidPath()){
//「新規から保存時は全ファイル表示」オプション // 2008/6/15 バグフィックス Uchi
if( GetDllShareData().m_Common.m_sFile.m_bNoFilterSaveNew )
wcscat(szDefaultWildCard, L";*.*"); // 全ファイル表示
strDefaultWildCard += L";*.*"; // 全ファイル表示
}
else {
//「新規以外から保存時は全ファイル表示」オプション
if( GetDllShareData().m_Common.m_sFile.m_bNoFilterSaveFile )
wcscat(szDefaultWildCard, L";*.*"); // 全ファイル表示
strDefaultWildCard += L";*.*"; // 全ファイル表示
}
}

Expand All @@ -281,7 +281,7 @@ bool CDocFileOperation::SaveFileDialog(
cDlgOpenFile.Create(
G_AppInstance(),
CEditWnd::getInstance()->GetHwnd(),
szDefaultWildCard,
strDefaultWildCard.c_str(),
CSakuraEnvironment::GetDlgInitialDir().c_str(), // 初期フォルダ
CMRUFile().GetPathList(), // 最近のファイル
CMRUFolder().GetPathList() // 最近のフォルダ
Expand Down

0 comments on commit 20e6618

Please sign in to comment.