Merge pull request '1' (#11) from 陈劲宏-branch into master

lba_new
por68nab5 10 months ago
commit 8edeed63dc

@ -16,31 +16,31 @@
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//该cpp文件实现了处理崩溃的类MiniDumper.h
#include <shlwapi.h>
#include "MiniDumper.h"
//消息标题
LPCTSTR msgTitle = TEXT("Notepad++ crash analysis");
MiniDumper::MiniDumper()
{
}
bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
//写入崩溃转储的函数
bool MiniDumper::writeDump(EXCEPTION_POINTERS* pExceptionInfo)
{
TCHAR szDumpPath[MAX_PATH];
TCHAR szScratch[MAX_PATH];
LPCTSTR szResult = NULL;
bool retval = false;
//加载动态链接库
HMODULE hDll = ::LoadLibraryEx(TEXT("DBGHELP.DLL"), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); //that wont work on older windows version than XP, #care :)
if (hDll)
{
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" );
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump");
if (pDump)
{
{//获取当前模块的文件路径
::GetModuleFileName(NULL, szDumpPath, MAX_PATH);
::PathRemoveFileSpec(szDumpPath);
wcscat_s(szDumpPath, TEXT("\\NppDump.dmp"));
@ -50,10 +50,10 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
if (msgret == IDYES)
{
// create the file
HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL );
HANDLE hFile = ::CreateFile(szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile!=INVALID_HANDLE_VALUE)
if (hFile != INVALID_HANDLE_VALUE)
{
_MINIDUMP_EXCEPTION_INFORMATION ExInfo{};
@ -62,23 +62,23 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
ExInfo.ClientPointers = FALSE;
// write the dump
BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL );
BOOL bOK = pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
if (bOK)
{
wsprintf( szScratch, TEXT("Saved dump file to '%s'"), szDumpPath );
wsprintf(szScratch, TEXT("Saved dump file to '%s'"), szDumpPath);
szResult = szScratch;
retval = true;
}
else
{
wsprintf( szScratch, TEXT("Failed to save dump file to '%s' (error %d)"), szDumpPath, GetLastError() );
wsprintf(szScratch, TEXT("Failed to save dump file to '%s' (error %d)"), szDumpPath, GetLastError());
szResult = szScratch;
}
::CloseHandle(hFile);
}
else
{
wsprintf( szScratch, TEXT("Failed to create dump file '%s' (error %d)"), szDumpPath, GetLastError() );
wsprintf(szScratch, TEXT("Failed to create dump file '%s' (error %d)"), szDumpPath, GetLastError());
szResult = szScratch;
}
}
@ -93,7 +93,7 @@ bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo)
{
szResult = TEXT("Unable to load the debugging DLL,\r\nfind a recent copy of dbghelp.dll and install it.");
}
//弹出消息框显示结果
if (szResult)
::MessageBox(NULL, szResult, msgTitle, MB_OK);

@ -25,14 +25,14 @@
bool DocTabView::_hideTabBarStatus = false;
//向标签视图添加新的缓冲区,首先检查缓冲区是否有效(不是无效的缓冲区),然后检查是否已经存在相同的缓冲区。如果缓冲区有效且尚未存在,则将其添加到标签页视图中,并更新父窗口的大小。
void DocTabView::addBuffer(BufferID buffer)
{
if (buffer == BUFFER_INVALID) //valid only
return;
if (getIndexByBuffer(buffer) != -1) //no duplicates
return;
Buffer * buf = MainFileManager.getBufferByID(buffer);
Buffer* buf = MainFileManager.getBufferByID(buffer);
TCITEM tie{};
tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
@ -40,7 +40,7 @@ void DocTabView::addBuffer(BufferID buffer)
if (_hasImgLst)
index = 0;
tie.iImage = index;
tie.pszText = const_cast<TCHAR *>(buf->getFileName());
tie.pszText = const_cast<TCHAR*>(buf->getFileName());
tie.lParam = reinterpret_cast<LPARAM>(buffer);
::SendMessage(_hSelf, TCM_INSERTITEM, _nbItem++, reinterpret_cast<LPARAM>(&tie));
bufferUpdated(buf, BufferChangeMask);
@ -48,25 +48,25 @@ void DocTabView::addBuffer(BufferID buffer)
::SendMessage(_hParent, WM_SIZE, 0, 0);
}
//关闭指定的缓冲区,到要关闭的缓冲区的索引,然后从标签页视图中删除它,并通知父窗口进行调整。
void DocTabView::closeBuffer(BufferID buffer)
{
int indexToClose = getIndexByBuffer(buffer);
deletItemAt((size_t)indexToClose);
::SendMessage(_hParent, WM_SIZE, 0, 0);
}
//为特定的标签设置颜色。根据提供的缓冲区ID设置该缓冲区在标签页中的颜色。
void DocTabView::setIndividualTabColour(BufferID bufferId, int colorId)
{
bufferId->setDocColorId(colorId);
}
//获取特定标签的颜色,根据提供的标签索引,返回该标签的颜色。
int DocTabView::getIndividualTabColour(int tabIndex)
{
BufferID bufferId = getBufferByIndex(tabIndex);
return bufferId->getDocColorId();
}
//激活特定的缓冲区通过缓冲区的ID找到其索引位置并尝试激活该缓冲区如果成功则返回true否则返回false。
bool DocTabView::activateBuffer(BufferID buffer)
{
int indexToActivate = getIndexByBuffer(buffer);
@ -77,15 +77,15 @@ bool DocTabView::activateBuffer(BufferID buffer)
return true;
}
//获取当前激活的缓冲区。
BufferID DocTabView::activeBuffer()
{
int index = getCurrentTabIndex();
return getBufferByIndex(index);
}
BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not found, something else otherwise
//遍历所有标签页根据文件名查找匹配的缓冲区找到则返回其ID否则返回BUFFER_INVALID。
BufferID DocTabView::findBufferByName(const TCHAR* fullfilename) //-1 if not found, something else otherwise
{
TCITEM tie{};
tie.lParam = -1;
@ -94,7 +94,7 @@ BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not fo
{
::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast<LPARAM>(&tie));
BufferID id = reinterpret_cast<BufferID>(tie.lParam);
Buffer * buf = MainFileManager.getBufferByID(id);
Buffer* buf = MainFileManager.getBufferByID(id);
if (OrdinalIgnoreCaseCompareStrings(fullfilename, buf->getFullPathName()) == 0)
{
return id;
@ -103,7 +103,7 @@ BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) //-1 if not fo
return BUFFER_INVALID;
}
//通过缓冲区ID找到其在标签中的索引位置如果不存在则返回 - 1。
int DocTabView::getIndexByBuffer(BufferID id)
{
TCITEM tie{};
@ -118,7 +118,7 @@ int DocTabView::getIndexByBuffer(BufferID id)
return -1;
}
//通过缓冲区ID找到其在标签中的索引位置如果不存在则返回-1。
BufferID DocTabView::getBufferByIndex(size_t index)
{
TCITEM tie{};
@ -129,8 +129,8 @@ BufferID DocTabView::getBufferByIndex(size_t index)
return reinterpret_cast<BufferID>(tie.lParam);
}
void DocTabView::bufferUpdated(Buffer * buffer, int mask)
//根据mask中的标志位更新与缓冲区相关的信息例如文件名变化、只读状态变化等。
void DocTabView::bufferUpdated(Buffer* buffer, int mask)
{
int index = getIndexByBuffer(buffer->getID());
if (index == -1)
@ -143,7 +143,7 @@ void DocTabView::bufferUpdated(Buffer * buffer, int mask)
if (mask & BufferChangeReadonly || mask & BufferChangeDirty)
{
tie.mask |= TCIF_IMAGE;
tie.iImage = buffer->isDirty()?UNSAVED_IMG_INDEX:SAVED_IMG_INDEX;
tie.iImage = buffer->isDirty() ? UNSAVED_IMG_INDEX : SAVED_IMG_INDEX;
if (buffer->isMonitoringOn())
{
tie.iImage = MONITORING_IMG_INDEX;
@ -171,15 +171,15 @@ void DocTabView::bufferUpdated(Buffer * buffer, int mask)
//Tab's caption must be encoded like this because otherwise tab control would make tab too small or too big for the text.
while (*in != 0)
if (*in == '&')
{
*out++ = '&';
*out++ = '&';
while (*(++in) == '&')
if (*in == '&')
{
*out++ = '&';
}
else
*out++ = *in++;
*out++ = '&';
while (*(++in) == '&')
*out++ = '&';
}
else
*out++ = *in++;
*out = '\0';
}
}
@ -192,7 +192,7 @@ void DocTabView::bufferUpdated(Buffer * buffer, int mask)
::SendMessage(_hParent, WM_SIZE, 0, 0);
}
//根据给定的索引设置相应的缓冲区ID并更新标签显示的相关信息。
void DocTabView::setBuffer(size_t index, BufferID id)
{
if (index >= _nbItem)
@ -208,8 +208,8 @@ void DocTabView::setBuffer(size_t index, BufferID id)
::SendMessage(_hParent, WM_SIZE, 0, 0);
}
void DocTabView::reSizeTo(RECT & rc)
//根据隐藏/显示标签栏状态,调整标签页视图和文本编辑器视图的大小,并根据需要发送消息以更新可点击链接。
void DocTabView::reSizeTo(RECT& rc)
{
int borderWidth = ((NppParameters::getInstance()).getSVP())._borderWidth;
if (_hideTabBarStatus)
@ -221,9 +221,9 @@ void DocTabView::reSizeTo(RECT & rc)
else
{
TabBar::reSizeTo(rc);
rc.left += borderWidth;
rc.left += borderWidth;
rc.right -= borderWidth * 2;
rc.top += borderWidth;
rc.top += borderWidth;
rc.bottom -= (borderWidth * 2);
_pView->reSizeTo(rc);
}

@ -14,11 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//该类继承自TabBarPlus类。该类负责管理文档选项卡视图并提供一系列方法用于添加、关闭、激活缓冲区以及设置选项卡的个性化选项等功能。
#pragma once
#include "TabBar.h"
#include "Buffer.h"
// 定义一些常量用作图片索引
const int SAVED_IMG_INDEX = 0;
const int UNSAVED_IMG_INDEX = 1;
const int REDONLY_IMG_INDEX = 2;
@ -26,15 +30,15 @@ const int MONITORING_IMG_INDEX = 3;
class DocTabView : public TabBarPlus
{
public :
DocTabView():TabBarPlus(), _pView(NULL) {};
virtual ~DocTabView(){};
public:
DocTabView() :TabBarPlus(), _pView(NULL) {};
virtual ~DocTabView() {};
void destroy() override {
TabBarPlus::destroy();
};
void init(HINSTANCE hInst, HWND parent, ScintillaEditView * pView, std::vector<IconList *> pIconListVector, unsigned char indexChoice) {
//初始化函数传入实例句柄、父窗口句柄、ScintillaEditView指针、以及图片列表和选择的图片索引
void init(HINSTANCE hInst, HWND parent, ScintillaEditView* pView, std::vector<IconList*> pIconListVector, unsigned char indexChoice) {
TabBarPlus::init(hInst, parent);
_pView = pView;
@ -52,51 +56,56 @@ public :
TabBar::setImageList(_pIconListVector[_iconListIndexChoice]->getHandle());
return;
};
// 改变选中的图片列表
void changeIcons(unsigned char choice) {
if (choice >= _pIconListVector.size())
return;
_iconListIndexChoice = choice;
TabBar::setImageList(_pIconListVector[_iconListIndexChoice]->getHandle());
};
// 添加缓冲区
void addBuffer(BufferID buffer);
// 关闭缓冲区
void closeBuffer(BufferID buffer);
void bufferUpdated(Buffer * buffer, int mask);
// 缓冲区更新
void bufferUpdated(Buffer* buffer, int mask);
// 激活缓冲区
bool activateBuffer(BufferID buffer);
// 获取当前激活的缓冲区
BufferID activeBuffer();
BufferID findBufferByName(const TCHAR * fullfilename); //-1 if not found, something else otherwise
// 根据文件名查找缓冲区,返回索引值,如果未找到则返回-1
BufferID findBufferByName(const TCHAR* fullfilename); //-1 if not found, something else otherwise
// 根据缓冲区获取索引值
int getIndexByBuffer(BufferID id);
// 根据索引值获取缓冲区
BufferID getBufferByIndex(size_t index);
// 设置指定索引位置的缓冲区
void setBuffer(size_t index, BufferID id);
// 静态函数,用于设置隐藏或显示选项卡栏的状态
static bool setHideTabBarStatus(bool hideOrNot) {
bool temp = _hideTabBarStatus;
_hideTabBarStatus = hideOrNot;
return temp;
};
// 静态函数,获取隐藏或显示选项卡栏的状态
static bool getHideTabBarStatus() {
return _hideTabBarStatus;
};
void reSizeTo(RECT & rc) override;
// 重写父类的reSizeTo方法
void reSizeTo(RECT& rc) override;
// 获取ScintillaEditView指针
const ScintillaEditView* getScintillaEditView() const {
return _pView;
};
// 设置指定缓冲区的个性化选项卡颜色
void setIndividualTabColour(BufferID bufferId, int colorId);
// 获取指定索引位置的个性化选项卡颜色
int getIndividualTabColour(int tabIndex) override;
private :
ScintillaEditView *_pView = nullptr;
private:
ScintillaEditView* _pView = nullptr;
static bool _hideTabBarStatus;
std::vector<IconList *> _pIconListVector;
std::vector<IconList*> _pIconListVector;
int _iconListIndexChoice = -1;
};

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save