Skip to content

Commit

Permalink
format number in Debug Window
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Feb 8, 2025
1 parent eb4d512 commit 21acb1d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
44 changes: 43 additions & 1 deletion src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5065,6 +5065,48 @@ int MultiReplace::ShowDebugWindow(const std::string& message) {
isClassRegistered = true;
}

std::wstringstream formattedMessage;
std::wstringstream inputMessageStream(wMessage);
std::wstring line;

while (std::getline(inputMessageStream, line)) {
std::wistringstream iss(line);
std::wstring variable, type, value;

if (std::getline(iss, variable, L'\t') &&
std::getline(iss, type, L'\t') &&
std::getline(iss, value)) {

// Trim whitespace
type.erase(0, type.find_first_not_of(L" \t"));
type.erase(type.find_last_not_of(L" \t") + 1);
value.erase(0, value.find_first_not_of(L" \t"));
value.erase(value.find_last_not_of(L" \t") + 1);

if (type == L"Number") {
try {
double num = std::stod(value);

// If number is an integer, remove decimal places
if (num == static_cast<int>(num)) {
value = std::to_wstring(static_cast<int>(num));
}
else {
std::wstringstream numStream;
numStream << std::fixed << std::setprecision(6) << num;
value = numStream.str();
}
}
catch (...) {
// If conversion fails, retain the original value
}
}
formattedMessage << variable << L"\t" << type << L"\t" << value << L"\n";
}
}

std::wstring finalMessage = formattedMessage.str();

// Use the saved position and size if set, otherwise use default position and size
int width = debugWindowSizeSet ? debugWindowSize.cx : sx(260); // Set initial width
int height = debugWindowSizeSet ? debugWindowSize.cy : sy(400); // Set initial height
Expand All @@ -5077,7 +5119,7 @@ int MultiReplace::ShowDebugWindow(const std::string& message) {
L"Debug Information",
WS_OVERLAPPEDWINDOW,
x, y, width, height,
nppData._nppHandle, NULL, hInstance, (LPVOID)wMessage
nppData._nppHandle, NULL, hInstance, (LPVOID)finalMessage.c_str()
);

if (hwnd == NULL) {
Expand Down
24 changes: 8 additions & 16 deletions src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,25 +685,17 @@ class MultiReplace : public StaticDialog
//Find
void handleFindNextButton();
void handleFindPrevButton();
// SearchResult performSingleSearch(const std::string& findTextUtf8, int searchFlags, bool selectMatch, SelectionRange range);
SearchResult performSingleSearch(const SearchContext& context, SelectionRange range);
//SearchResult performSearchForward(const std::string& findTextUtf8, int searchFlags, bool selectMatch, LRESULT start);
SearchResult MultiReplace::performSearchForward(const SearchContext& context, LRESULT start);
//SearchResult performSearchBackward(const std::string& findTextUtf8, int searchFlags, bool selectMatch, LRESULT start);
SearchResult MultiReplace::performSearchBackward(const SearchContext& context, LRESULT start);
//SearchResult performSearchSelection(const std::string& findTextUtf8, int searchFlags, bool selectMatch, LRESULT start, bool isBackward);
SearchResult performSearchSelection(const SearchContext& context, LRESULT start, bool isBackward);
//SearchResult performSearchColumn(const std::string& findTextUtf8, int searchFlags, bool selectMatch, LRESULT start, bool isBackward);
SearchResult performSearchForward(const SearchContext& context, LRESULT start);
SearchResult performSearchBackward(const SearchContext& context, LRESULT start);
SearchResult performSearchColumn(const SearchContext& context, LRESULT start, bool isBackward);
//SearchResult performListSearchForward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex);
SearchResult MultiReplace::performListSearchForward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex, const SearchContext& context);
//SearchResult performListSearchBackward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex);
SearchResult MultiReplace::performListSearchBackward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex, const SearchContext& context);
void MultiReplace::selectListItem(size_t matchIndex);
SearchResult performSearchSelection(const SearchContext& context, LRESULT start, bool isBackward);
SearchResult performListSearchForward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex, const SearchContext& context);
SearchResult performListSearchBackward(const std::vector<ReplaceItemData>& list, LRESULT cursorPos, size_t& closestMatchIndex, const SearchContext& context);
void selectListItem(size_t matchIndex);

//Mark
void handleMarkMatchesButton();
//int markString(const std::string& findTextUtf8, int searchFlags);
int markString(const SearchContext& context);
void highlightTextRange(LRESULT pos, LRESULT len, const std::string& findTextUtf8);
int generateColorValue(const std::string& str);
Expand Down Expand Up @@ -752,8 +744,8 @@ class MultiReplace : public StaticDialog
void setSelections(bool select, bool onlySelected = false);
void updateHeaderSelection();
void updateHeaderSortDirection();
void MultiReplace::showStatusMessage(const std::wstring& messageText, COLORREF color, bool isNotFound = false);
std::wstring MultiReplace::getShortenedFilePath(const std::wstring& path, int maxLength, HDC hDC = nullptr);
void showStatusMessage(const std::wstring& messageText, COLORREF color, bool isNotFound = false);
std::wstring getShortenedFilePath(const std::wstring& path, int maxLength, HDC hDC = nullptr);
void showListFilePath();
void displayResultCentered(size_t posStart, size_t posEnd, bool isDownwards);
std::wstring getSelectedText();
Expand Down

0 comments on commit 21acb1d

Please sign in to comment.