Skip to content

Commit

Permalink
CAppSettings::RFLRemoveFromList method added. File that can't be load…
Browse files Browse the repository at this point in the history
…ed will now be removed from the RFL.

CHexerPropGridCtrl::SetRedraw method added.
Latest HexCtrl.
  • Loading branch information
jovibor committed Dec 19, 2023
1 parent 09e4d61 commit 6fb6c76
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cpp_indent_preprocessor = one_left
cpp_indent_access_specifiers = false
cpp_indent_namespace_contents = true
cpp_indent_preserve_comments = true
cpp_new_line_before_open_brace_namespace = ignore
cpp_new_line_before_open_brace_namespace = same_line
cpp_new_line_before_open_brace_type = same_line
cpp_new_line_before_open_brace_function = ignore
cpp_new_line_before_open_brace_block = same_line
Expand Down
17 changes: 17 additions & 0 deletions Hexer/AppSettings.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public:
CAppSettingsRFL() = default;
void Initialize(HMENU hMenu, int iMenuFirstID, HBITMAP hBMPDisk, int iMaxEntry);
void AddToRFL(std::wstring_view wsvPath, bool fBeginning);
void RemoveFromRFL(std::wstring_view wsvPath);
void ClearRFL();
[[nodiscard]] auto GetPathFromRFL(UINT uID)const->std::wstring;
[[nodiscard]] auto GetRFL()const->const std::vector<std::wstring>&;
Expand Down Expand Up @@ -81,6 +82,16 @@ void CAppSettingsRFL::AddToRFL(std::wstring_view wsvPath, bool fBeginning)
RebuildRFLMenu();
}

void CAppSettingsRFL::RemoveFromRFL(std::wstring_view wsvPath)
{
assert(m_fInit);
if (!m_fInit)
return;

std::erase(m_vecRFL, wsvPath);
RebuildRFLMenu();
}

void CAppSettingsRFL::ClearRFL()
{
m_vecRFL.clear();
Expand Down Expand Up @@ -157,6 +168,7 @@ public:
void RFLClear();
[[nodiscard]] auto RFLGetPathFromID(UINT uID)const->std::wstring;
void RFLInitialize(HMENU hMenu, int iIDMenuFirst, HBITMAP hBMPDisk, int iMaxEntry = 20);
void RFLRemoveFromList(std::wstring_view wsvPath);
void SaveSettings(std::wstring_view wsvKeyName);
void SetHexCtrlFont(const LOGFONTW& lf);
void SetHexCtrlColors(const HEXCTRL::HEXCOLORS& clrs);
Expand Down Expand Up @@ -345,6 +357,11 @@ void CAppSettings::RFLInitialize(HMENU hMenu, int iIDMenuFirst, HBITMAP hBMPDisk
m_stRFL.Initialize(hMenu, iIDMenuFirst, hBMPDisk, iMaxEntry);
}

void CAppSettings::RFLRemoveFromList(std::wstring_view wsvPath)
{
m_stRFL.RemoveFromRFL(wsvPath);
}

void CAppSettings::SaveSettings(std::wstring_view wsvKeyName)
{
const std::wstring wstrAppKey = std::wstring { L"SOFTWARE\\" } + std::wstring { wsvKeyName };
Expand Down
22 changes: 10 additions & 12 deletions Hexer/CHexerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ import DlgOpenDevice;
import DlgNewFile;
import DlgSettings;

using namespace Ut;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CHexerApp theApp;


//CDlgAbout.

class CDlgAbout final : public CDialogEx {
public:
explicit CDlgAbout()noexcept : CDialogEx(IDD_ABOUTBOX) {}
Expand Down Expand Up @@ -59,7 +55,6 @@ BOOL CDlgAbout::OnInitDialog()


//CHexerMDTemplate.

class CHexerMDTemplate final : public CMultiDocTemplate {
public:
CHexerMDTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass)
Expand Down Expand Up @@ -107,7 +102,6 @@ auto CHexerMDTemplate::OpenDocumentFile(const Ut::FILEOPEN& fos)->CDocument*


//CHexerDocMgr.

class CHexerDocMgr final : public CDocManager {
public:
auto OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU) -> CDocument* override;
Expand Down Expand Up @@ -250,7 +244,6 @@ auto CHexerDocMgr::OpenDocumentFile(const Ut::FILEOPEN& fos)->CDocument*


//CHexerApp.

BEGIN_MESSAGE_MAP(CHexerApp, CWinAppEx)
ON_COMMAND(ID_FILE_NEW, &CHexerApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, &CHexerApp::OnFileOpen)
Expand All @@ -268,6 +261,11 @@ void CHexerApp::AddToRFL(std::wstring_view wsvPath)
GetAppSettings().RFLAddToList(wsvPath);
}

void CHexerApp::RemoveFromRFL(std::wstring_view wsvPath)
{
GetAppSettings().RFLRemoveFromList(wsvPath);
}

auto CHexerApp::GetAppSettings()->CAppSettings&
{
return m_stAppSettings;
Expand All @@ -291,19 +289,19 @@ void CHexerApp::OnFileOpen()
pResults->GetItemAt(i, &pItem);
CComHeapPtr<wchar_t> pwstrPath;
pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwstrPath);
const auto pDoc = OpenDocumentFile(Ut::FILEOPEN {.wstrFilePath{ pwstrPath }, .fNewFile{ false } });
const auto pDoc = OpenDocumentFile(Ut::FILEOPEN { .wstrFilePath { pwstrPath }, .fNewFile { false } });
fOpened = !fOpened ? pDoc != nullptr : true;
}
return fOpened;
}
return true;
};
};

while (!lmbFOD()) { }; //If no file has been opened (in multiple selection) show the "Open File Dialog" again.
}


//Private methods.
//CHexerApp private methods.

BOOL CHexerApp::InitInstance()
{
Expand Down Expand Up @@ -395,7 +393,7 @@ void CHexerApp::OnFileOpenDevice()
{
if (CDlgOpenDevice dlg(AfxGetMainWnd()); dlg.DoModal() == IDOK) {
for (const auto& wstrPath : dlg.GetPaths()) {
OpenDocumentFile({ .wstrFilePath{ wstrPath }, .fNewFile { false } });
OpenDocumentFile({ .wstrFilePath { wstrPath }, .fNewFile { false } });
}
}
}
Expand All @@ -408,7 +406,7 @@ void CHexerApp::OnToolsSettings()

void CHexerApp::OnFileRFL(UINT uID)
{
OpenDocumentFile({ .wstrFilePath { GetAppSettings().RFLGetPathFromID(uID) }, .fNewFile{ false } });
OpenDocumentFile({ .wstrFilePath { GetAppSettings().RFLGetPathFromID(uID) }, .fNewFile { false } });
}

void CHexerApp::OnUpdateFileNew(CCmdUI* pCmdUI)
Expand Down
4 changes: 3 additions & 1 deletion Hexer/CHexerApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*******************************************************************************/
#pragma once
#include "HexCtrl.h"
#include <afxwin.h>
#include <string>
#include <vector>
import Utility;
Expand All @@ -15,7 +16,8 @@ class CHexerApp final : public CWinAppEx {
public:
afx_msg void OnFileOpen();
[[nodiscard]] auto GetAppSettings() -> CAppSettings&;
void AddToRFL(std::wstring_view wsvPath); //Add path to Recent File List.
void AddToRFL(std::wstring_view wsvPath); //Add path to the Recent File List.
void RemoveFromRFL(std::wstring_view wsvPath); //Remove path from the RFL if any.
private:
BOOL InitInstance()override;
int ExitInstance()override;
Expand Down
2 changes: 2 additions & 0 deletions Hexer/CHexerDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ bool CHexerDoc::OnOpenDocument(const Ut::FILEOPEN& fos)
m_wstrFileName = m_wstrFilePath.substr(m_wstrFilePath.find_last_of(L'\\') + 1); //Doc name with the .extension.

if (!m_stFileLoader.OpenFile(fosLocal)) {
theApp.RemoveFromRFL(m_wstrFilePath);
Ut::Log::AddLogEntryError(L"File open failed: " + m_wstrFileName);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Hexer/CMainFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace HEXCTRL { class IHexCtrl; }; //Forward declarations.
class CMainFrame final : public CMDIFrameWndEx {
public:
void AddLogEntry(const Ut::Log::LOGINFO& stData);
int& GetChildFramesCount();
[[nodiscard]] int& GetChildFramesCount();
[[nodiscard]] bool IsPaneVisible(UINT uPaneID); //Is Pane visible even if pane's window itself is tabbed and hidden atm (not active).
[[nodiscard]] bool IsPaneActive(UINT uPaneID); //Is Pane itself visible atm.
void OnChildFrameActivate();
Expand Down
39 changes: 26 additions & 13 deletions Hexer/Dialogs/DlgFileInfo.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@ import Utility;

//CHexerPropGridCtrl.
class CHexerPropGridCtrl final : public CMFCPropertyGridCtrl {
public:
void SetRedraw(bool fRedraw) {
m_fRedraw = fRedraw;
}
private:
int OnDrawProperty(CDC* pDC, CMFCPropertyGridProperty* pProp)const override {
return m_fRedraw ? CMFCPropertyGridCtrl::OnDrawProperty(pDC, pProp) : TRUE;
}
void OnSize(UINT /*f*/, int /*cx*/, int /*cy*/) {
EndEditItem();
AdjustLayout();
}
DECLARE_MESSAGE_MAP();
private:
bool m_fRedraw { true };
};

BEGIN_MESSAGE_MAP(CHexerPropGridCtrl, CMFCPropertyGridCtrl)
Expand All @@ -45,7 +54,7 @@ private:
enum class EPropName : std::uint8_t {
FILE_PATH = 0x1, FILE_NAME, FILE_SIZE, PAGE_SIZE, IS_MUTABLE
};
CHexerPropGridCtrl m_stGridFileProps;
CHexerPropGridCtrl m_gridFileProps;
std::vector<CMFCPropertyGridProperty*> m_vecPropsFileProps;
CFont m_fntFilePropsGrid;
Ut::FILEINFO m_fis { };
Expand All @@ -72,58 +81,58 @@ void CDlgFileInfo::SetGridData(const Ut::FILEINFO& fis)
void CDlgFileInfo::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FILEINFO_GRID, m_stGridFileProps);
DDX_Control(pDX, IDC_FILEINFO_GRID, m_gridFileProps);
}

BOOL CDlgFileInfo::OnInitDialog()
{
CDialogEx::OnInitDialog();

m_stGridFileProps.SetVSDotNetLook();
m_stGridFileProps.EnableHeaderCtrl(TRUE, L"Property", L"Value");
m_gridFileProps.SetVSDotNetLook();
m_gridFileProps.EnableHeaderCtrl(TRUE, L"Property", L"Value");
HDITEMW hdPropGrid { .mask = HDI_WIDTH, .cxy = 80 };
m_stGridFileProps.GetHeaderCtrl().SetItem(0, &hdPropGrid); //Property grid left column width.
m_gridFileProps.GetHeaderCtrl().SetItem(0, &hdPropGrid); //Property grid left column width.

//Set new bigger font to the property.
const auto pFont = m_stGridFileProps.GetFont();
const auto pFont = m_gridFileProps.GetFont();
LOGFONTW lf { };
pFont->GetLogFont(&lf);
const auto lFontSize = MulDiv(-lf.lfHeight, 72, Ut::GetHiDPIInfo().iLOGPIXELSY) + 2;
lf.lfHeight = -MulDiv(lFontSize, Ut::GetHiDPIInfo().iLOGPIXELSY, 72);
m_fntFilePropsGrid.CreateFontIndirectW(&lf);
m_stGridFileProps.SetFont(&m_fntFilePropsGrid);
m_gridFileProps.SetFont(&m_fntFilePropsGrid);

using enum EPropName;
const auto pFilePath = new CMFCPropertyGridProperty(L"File path:", L"");
pFilePath->SetData(static_cast<DWORD_PTR>(FILE_PATH));
pFilePath->AllowEdit(FALSE);
m_vecPropsFileProps.emplace_back(pFilePath);
m_stGridFileProps.AddProperty(pFilePath);
m_gridFileProps.AddProperty(pFilePath);

const auto pFileName = new CMFCPropertyGridProperty(L"File name:", L"");
pFileName->SetData(static_cast<DWORD_PTR>(FILE_NAME));
pFileName->AllowEdit(FALSE);
m_vecPropsFileProps.emplace_back(pFileName);
m_stGridFileProps.AddProperty(pFileName);
m_gridFileProps.AddProperty(pFileName);

const auto pFileSize = new CMFCPropertyGridProperty(L"File size:", L"");
pFileSize->SetData(static_cast<DWORD_PTR>(FILE_SIZE));
pFileSize->AllowEdit(FALSE);
m_vecPropsFileProps.emplace_back(pFileSize);
m_stGridFileProps.AddProperty(pFileSize);
m_gridFileProps.AddProperty(pFileSize);

const auto pPageSize = new CMFCPropertyGridProperty(L"Page size:", L"");
pPageSize->SetData(static_cast<DWORD_PTR>(PAGE_SIZE));
pPageSize->AllowEdit(FALSE);
m_vecPropsFileProps.emplace_back(pPageSize);
m_stGridFileProps.AddProperty(pPageSize);
m_gridFileProps.AddProperty(pPageSize);
pPageSize->Show(FALSE);

const auto pIsWritable = new CMFCPropertyGridProperty(L"Writable:", L"");
pIsWritable->SetData(static_cast<DWORD_PTR>(IS_MUTABLE));
pIsWritable->AllowEdit(FALSE);
m_vecPropsFileProps.emplace_back(pIsWritable);
m_stGridFileProps.AddProperty(pIsWritable);
m_gridFileProps.AddProperty(pIsWritable);

UpdateGridData();

Expand Down Expand Up @@ -157,6 +166,10 @@ void CDlgFileInfo::UpdateGridData()
default:
break;
}
};
};

m_gridFileProps.SetRedraw(false);
std::ranges::for_each(m_vecPropsFileProps, lmbSetValue);
m_gridFileProps.SetRedraw(true);
m_gridFileProps.RedrawWindow();
}
1 change: 0 additions & 1 deletion Hexer/Dialogs/DlgLogInfo.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
export module DlgLogInfo;

import Utility;
using namespace Ut;
namespace lex = HEXCTRL::LISTEX;

export class CDlgLogInfo final : public CDialogEx {
Expand Down
4 changes: 2 additions & 2 deletions Hexer/FileLoader.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bool CFileLoader::OpenFile(const Ut::FILEOPEN& fos)
fos.fNewFile ? CREATE_ALWAYS : OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);

if (fos.fNewFile) { //Setting the size of the new file.
if (SetFilePointerEx(m_hFile, { .QuadPart { static_cast<LONGLONG>(fos.ullFileSize)} }, nullptr, FILE_BEGIN) == FALSE) {
if (SetFilePointerEx(m_hFile, { .QuadPart { static_cast<LONGLONG>(fos.ullFileSize) } }, nullptr, FILE_BEGIN) == FALSE) {
PrintLastError(L"SetFilePointerEx");
return false;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ auto CFileLoader::ReadData(std::uint64_t ullOffset, std::uint64_t ullSize)->HEXC
}

if (ullOffset >= m_ullOffsetCurr && (ullOffset + ullSize) <= (m_ullOffsetCurr + m_ullSizeCurr)) { //Data is already in the cache.
return HEXCTRL::SpanByte { m_pCache.get() + (ullOffset - m_ullOffsetCurr), ullSize};
return HEXCTRL::SpanByte { m_pCache.get() + (ullOffset - m_ullOffsetCurr), ullSize };
}

FlushData(); //Flush current cache data if it was modified, before the ReadFile.
Expand Down
6 changes: 2 additions & 4 deletions Hexer/Utility.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ module;
#include <string>
export module Utility;

export namespace Ut
{
export namespace Ut {
constexpr auto HEXER_VERSION_MAJOR = 0;
constexpr auto HEXER_VERSION_MINOR = 9;
constexpr auto HEXER_VERSION_PATCH = 3;
Expand Down Expand Up @@ -93,8 +92,7 @@ export namespace Ut

constexpr auto WM_ADDLOGENTRY { WM_APP + 1 }; //Custom message.

namespace Log
{
namespace Log {
enum class EMsgType :std::int8_t { //Enum id-number is the icon's index in the image list.
Unknown = -1, msg_error = 0, msg_warning = 1, msg_info = 2
};
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ The Hexer License Version 1.0

Software: Hexer, https://github.com/jovibor/Hexer

Copyright (c) 2023 Jovibor, https://github.com/jovibor
Copyright (c) 2023-2024 Jovibor, https://github.com/jovibor

Permission is hereby granted, free of charge, for any use, excluding selling,
of the Software and associated documentation files.
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ Fast, fully-featured, multi-tab hexadecimal editor based on the [HexCtrl](https:
* View and edit files up to **16EB** (exabyte)
* Fully-featured **Bookmarks Manager**
* Fully-featured **Search and Replace**
* Changeable encoding for the text area
* Many options to **Copy/Paste** to/from clipboard
* Many options to **Copy/Paste** to/from the clipboard
* **Undo/Redo**
* Modify data with **Filling** and many predefined **Operations** options
* Modify data with **Filling** and many **Operations** options
* Ability to visually divide data into pages
* Powerful system of Templates

## Installation
## How To Build
1. Clone git repo with all submodules:
`git clone https://github.com/jovibor/Hexer.git --recurse-submodules`
1. Open `Hexer\Hexer.sln` solution in the **Visual Studio 2022** or newer

0 comments on commit 6fb6c76

Please sign in to comment.