Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions sakura_core/_main/CControlTray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ void CControlTray::DoGrep()
m_cDlgGrep.m_strText = m_pShareData->m_sSearchKeywords.m_aSearchKeys[0];
}
if( 0 < m_pShareData->m_sSearchKeywords.m_aGrepFiles.size() ){
wcscpy( m_cDlgGrep.m_szFile, m_pShareData->m_sSearchKeywords.m_aGrepFiles[0] ); /* 検索ファイル */
m_cDlgGrep.m_szFile = m_pShareData->m_sSearchKeywords.m_aGrepFiles[0]; /* 検索ファイル */
}
if( 0 < m_pShareData->m_sSearchKeywords.m_aGrepFolders.size() ){
wcscpy( m_cDlgGrep.m_szFolder, m_pShareData->m_sSearchKeywords.m_aGrepFolders[0] ); /* 検索フォルダー */
m_cDlgGrep.m_szFolder = m_pShareData->m_sSearchKeywords.m_aGrepFolders[0]; /* 検索フォルダー */
}
if (0 < m_pShareData->m_sSearchKeywords.m_aExcludeFiles.size()) {
wcscpy(m_cDlgGrep.m_szExcludeFile, m_pShareData->m_sSearchKeywords.m_aExcludeFiles[0]); /* 除外ファイル */
m_cDlgGrep.m_szExcludeFile = m_pShareData->m_sSearchKeywords.m_aExcludeFiles[0]; /* 除外ファイル */
}
if (0 < m_pShareData->m_sSearchKeywords.m_aExcludeFolders.size()) {
wcscpy(m_cDlgGrep.m_szExcludeFolder, m_pShareData->m_sSearchKeywords.m_aExcludeFolders[0]); /* 除外フォルダー */
m_cDlgGrep.m_szExcludeFolder = m_pShareData->m_sSearchKeywords.m_aExcludeFolders[0]; /* 除外フォルダー */
}

/* Grepダイアログの表示 */
int nRet = m_cDlgGrep.DoModal( m_hInstance, nullptr, L"" );
if( !nRet || GetTrayHwnd() == nullptr ){
if (const auto nRet = m_cDlgGrep.DoModal(m_hInstance, nullptr, L"");
!nRet || GetTrayHwnd() == nullptr ){
return;
}
m_nCurSearchKeySequence = GetDllShareData().m_Common.m_sSearch.m_nSearchKeySequence;
Expand Down Expand Up @@ -384,7 +384,6 @@ LRESULT CControlTray::DispatchEvent(

int nId;
HWND hwndWork;
LPHELPINFO lphi;

int nRowNum;
EditNode* pEditNodeArr;
Expand Down Expand Up @@ -461,7 +460,7 @@ LRESULT CControlTray::DispatchEvent(
case MYWM_HTMLHELP:
{
auto &sWorkBuffer = m_pShareData->m_sWorkBuffer;
WCHAR* pWork = sWorkBuffer.GetWorkBuffer<WCHAR>();
const auto pWork = sWorkBuffer.GetWorkBuffer<WCHAR>();

// pszHelpFile取得
const WCHAR* pszHelpFile = pWork;
Expand All @@ -470,6 +469,8 @@ LRESULT CControlTray::DispatchEvent(
// pszKeywords取得
const WCHAR* pszKeywords = &pWork[cchHelpFile + 1];

if (!*pszHelpFile) return 0L;

// Jul. 6, 2001 genta HtmlHelpの呼び出し方法変更
hwndHtmlHelp = OpenHtmlHelp(
nullptr,
Expand Down Expand Up @@ -564,13 +565,8 @@ LRESULT CControlTray::DispatchEvent(

// case WM_QUERYENDSESSION:
case WM_HELP:
lphi = (LPHELPINFO) lParam;
switch( lphi->iContextType ){
case HELPINFO_MENUITEM:
if (const auto lphi = (LPHELPINFO) lParam; lphi && HELPINFO_MENUITEM == lphi->iContextType) {
MyWinHelp( hwnd, HELP_CONTEXT, FuncID_To_HelpContextID( (EFunctionCode)lphi->iCtrlId ) );
break;
default:
break;
}
return TRUE;
case WM_COMMAND:
Expand Down Expand Up @@ -1442,24 +1438,23 @@ void CControlTray::TerminateApplication(
HWND hWndFrom //!< [in] 呼び出し元のウィンドウハンドル
)
{
DLLSHAREDATA* pShareData = &GetDllShareData(); /* 共有データ構造体のアドレスを返す */
const auto pShareData = &GetDllShareData(); /* 共有データ構造体のアドレスを返す */

/* 現在の編集ウィンドウの数を調べる */
if( pShareData->m_Common.m_sGeneral.m_bExitConfirm ){ //終了時の確認
if( 0 < CAppNodeGroupHandle(0).GetEditorWindowsNum() ){
if( IDYES != ::MYMESSAGEBOX(
if (pShareData->m_Common.m_sGeneral.m_bExitConfirm && //終了時の確認
0 < CAppNodeGroupHandle(0).GetEditorWindowsNum() &&
IDYES != ::MessageBoxF(
hWndFrom,
MB_YESNO | MB_APPLMODAL | MB_ICONQUESTION,
GSTR_APPNAME,
LS(STR_TRAY_EXITALL)
) ){
return;
}
}
}

/* 「すべてのウィンドウを閉じる」要求 */ //Oct. 7, 2000 jepro 「編集ウィンドウの全終了」という説明を左記のように変更
BOOL bCheckConfirm = (pShareData->m_Common.m_sGeneral.m_bExitConfirm)? FALSE: TRUE; // 2006.12.25 ryoji 終了確認済みならそれ以上は確認しない
if( CloseAllEditor( bCheckConfirm, hWndFrom, TRUE, 0 ) ){ // 2006.12.25, 2007.02.13 ryoji 引数追加
if (const auto bCheckConfirm = pShareData->m_Common.m_sGeneral.m_bExitConfirm; // 2006.12.25 ryoji 終了確認済みならそれ以上は確認しない
CloseAllEditor(bCheckConfirm, hWndFrom, TRUE, 0)) { // 2006.12.25, 2007.02.13 ryoji 引数追加
::PostMessageAny( pShareData->m_sHandles.m_hwndTray, WM_CLOSE, 0, 0 );
}
return;
Expand Down Expand Up @@ -1506,7 +1501,6 @@ int CControlTray::CreatePopUpMenu_L( void )
WCHAR szMenu[100 + MAX_PATH * 2]; // Jan. 19, 2001 genta
POINT po;
RECT rc;
EditInfo* pfi;

//本当はセマフォにしないとだめ
if( m_bUseTrayMenu ) return -1;
Expand Down Expand Up @@ -1568,7 +1562,7 @@ int CControlTray::CreatePopUpMenu_L( void )
if( IsSakuraMainWindow( m_pShareData->m_sNodes.m_pEditArr[i].GetHwnd() ) ){
/* トレイからエディタへの編集ファイル名要求通知 */
::SendMessage( m_pShareData->m_sNodes.m_pEditArr[i].GetHwnd(), MYWM_GETFILEINFO, 0, 0 );
pfi = (EditInfo*)&m_pShareData->m_sWorkBuffer.m_EditInfo_MYWM_GETFILEINFO;
const auto pfi = &m_pShareData->m_sWorkBuffer.m_EditInfo_MYWM_GETFILEINFO;

// メニューラベル。1からアクセスキーを振る
CFileNameManager::getInstance()->GetMenuFullLabel_WinList( szMenu, int(std::size(szMenu)), pfi, m_pShareData->m_sNodes.m_pEditArr[i].m_nId, i, dcFont.GetHDC() );
Expand Down
1 change: 1 addition & 0 deletions sakura_core/_main/CControlTray.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class CControlTray
bool OnAddTypeSetting(size_t index);
bool OnDelTypeSetting(size_t index);

public: // テストできないのでアクセス権変更
/*
|| メンバ変数
*/
Expand Down
18 changes: 7 additions & 11 deletions sakura_core/env/CFileNameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
/*
Copyright (C) 2008, kobake
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

SPDX-License-Identifier: Zlib
*/
Expand All @@ -22,15 +22,10 @@ struct EditInfo;
DLLSHAREDATA& GetDllShareData();

//!ファイル名管理
class CFileNameManager : public TSingleton<CFileNameManager>{
friend class TSingleton<CFileNameManager>;
CFileNameManager()
{
m_pShareData = &GetDllShareData();
m_nTransformFileNameCount = -1;
}

class CFileNameManager : public TSakuraSingleton<CFileNameManager> {
public:
CFileNameManager() = default;

//ファイル名関連
LPWSTR GetTransformFileNameFast( LPCWSTR, LPWSTR, int nDestLen, HDC hDC, bool bFitMode = true, int cchMaxWidth = 0 ); // 2002.11.24 Moca Add
int TransformFileName_MakeCache( void );
Expand Down Expand Up @@ -60,11 +55,12 @@ class CFileNameManager : public TSingleton<CFileNameManager>{
static WCHAR GetAccessKeyByIndex(int index, bool bZeroOrigin);

private:
DLLSHAREDATA* m_pShareData;
DLLSHAREDATA* m_pShareData = &GetDllShareData();

// ファイル名簡易表示用キャッシュ
int m_nTransformFileNameCount; // 有効数
int m_nTransformFileNameCount = -1; // 有効数
WCHAR m_szTransformFileNameFromExp[MAX_TRANSFORM_FILENAME][_MAX_PATH];
int m_nTransformFileNameOrgId[MAX_TRANSFORM_FILENAME];
};

#endif /* SAKURA_CFILENAMEMANAGER_2B89B426_470E_40D6_B62E_5321E383ECD6_H_ */
4 changes: 4 additions & 0 deletions sakura_core/env/CShareData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

#include "StdAfx.h"
#include "env/CShareData.h"

#include "env/DLLSHAREDATA.h"
#include "env/CFileNameManager.h"
#include "env/CShareData_IO.h"
#include "env/CSakuraEnvironment.h"
#include "doc/CDocListener.h" // SLoadInfo
Expand Down Expand Up @@ -73,6 +75,8 @@ CShareData::CShareData() = default;
*/
CShareData::~CShareData()
{
CFileNameManager::resetInstance();

if( m_pShareData ){
/* プロセスのアドレス空間から、 すでにマップされているファイル ビューをアンマップします */
::UnmapViewOfFile( m_pShareData );
Expand Down
62 changes: 61 additions & 1 deletion sakura_core/util/design_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
/*
Copyright (C) 2008, kobake
Copyright (C) 2018-2022, Sakura Editor Organization
Copyright (C) 2018-2026, Sakura Editor Organization

SPDX-License-Identifier: Zlib
*/
Expand All @@ -16,7 +16,10 @@
#pragma once

#include <algorithm>
#include <concepts>
#include <memory>
#include <stdexcept>
#include <type_traits>
#include <vector>

#include "debug/Debug2.h"
Expand Down Expand Up @@ -49,6 +52,63 @@ class TSingleton{
DISALLOW_COPY_AND_ASSIGN(TSingleton);
};

/*!
* @brief サクラエディタの変則Singletonパターン。
*
* TSingletonを元に作成。
* 生成したインスタンスをリセットできるようにしてある。
*/
template <class T>
class TSakuraSingleton {
private:
using Me = TSakuraSingleton<T>;

//! 生成済みインスタンス
static inline std::unique_ptr<T> gm_Instance = nullptr;

public:
/*!
* @brief インスタンスポインタを取得する
*
* @returns インスタンスポインタ
* @note インスタンスが未生成の場合は生成する
*/
[[nodiscard]]
static T* getInstance()
{
static_assert(
std::default_initializable<T> && !std::is_array_v<T>,
"T must be publicly default-initializable and must not be an array"
);

if (!gm_Instance) {
gm_Instance = std::make_unique<T>();
}

return gm_Instance.get();
}

/*!
* @brief インスタンスを破棄する
*
* @note 取得したポインタを破棄後に使用しないこと
*/
static void resetInstance()
{
gm_Instance.reset();
}

protected:
TSakuraSingleton() = default;

public:
TSakuraSingleton(const Me&) = delete;
Me& operator = (const Me&) = delete;

TSakuraSingleton(Me&&) = delete;
Me& operator = (Me&&) = delete;
};

/*!
複数インスタンスを生成しようとしたときのエラー
*/
Expand Down
3 changes: 3 additions & 0 deletions src/test/cpp/tests1/env/ShareDataTestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace env {
*/
/* static */ void ShareDataTestSuite::SetUpShareData()
{
// 言語環境を初期化する
CSelectLang::InitializeLanguageEnvironment();

pcShareData = std::make_unique<CShareData>();

EXPECT_THAT(pcShareData->InitShareData(), IsTrue());
Expand Down
26 changes: 26 additions & 0 deletions src/test/cpp/tests1/test-design_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@

#include "util/design_template.h"

/*!
* TSakuraSingletonの挙動を検証するためのクラス
*/
class CSakuraSingleton : public TSakuraSingleton<CSakuraSingleton>
{
public:
CSakuraSingleton() = default;
virtual ~CSakuraSingleton() noexcept = default;
};

/*!
* @brief TSakuraSingletonの挙動を検証するテスト
*/
TEST(CSakuraSingleton, CSakuraSingleton)
{
// いきなり呼び出してもNULLは返らない
EXPECT_THAT(CSakuraSingleton::getInstance(), NotNull());

// 何度呼び出しても同じ値が返る
const auto pInstance = CSakuraSingleton::getInstance();
EXPECT_THAT(CSakuraSingleton::getInstance(), Eq(pInstance));
EXPECT_THAT(CSakuraSingleton::getInstance(), Eq(pInstance));
EXPECT_THAT(CSakuraSingleton::getInstance(), Eq(pInstance));

CSakuraSingleton::resetInstance();
}

/*!
* TSingleInstanceの挙動を検証するためのクラス
Expand Down
Loading
Loading